xref: /aosp_15_r20/external/deqp/modules/gles2/functional/es2fStringQueryTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES 2.0 Module
3  * -------------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief String Query tests.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "es2fStringQueryTests.hpp"
25 #include "es2fApiCase.hpp"
26 #include "gluRenderContext.hpp"
27 #include "glwEnums.hpp"
28 #include "glwFunctions.hpp"
29 #include "deString.h"
30 
31 #include <algorithm>
32 #include <sstream>
33 #include <string>
34 
35 using namespace glw; // GLint and other GL types
36 
37 namespace deqp
38 {
39 namespace gles2
40 {
41 namespace Functional
42 {
43 
StringQueryTests(Context & context)44 StringQueryTests::StringQueryTests(Context &context) : TestCaseGroup(context, "string", "String Query tests")
45 {
46 }
47 
~StringQueryTests(void)48 StringQueryTests::~StringQueryTests(void)
49 {
50 }
51 
init(void)52 void StringQueryTests::init(void)
53 {
54     using tcu::TestLog;
55 
56     ES2F_ADD_API_CASE(renderer, "RENDERER", {
57         const GLubyte *string = glGetString(GL_RENDERER);
58         if (string == NULL)
59             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid string");
60     });
61     ES2F_ADD_API_CASE(vendor, "VENDOR", {
62         const GLubyte *string = glGetString(GL_VENDOR);
63         if (string == NULL)
64             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid string");
65     });
66     ES2F_ADD_API_CASE(version, "VERSION", {
67         const char *string           = (const char *)glGetString(GL_VERSION);
68         const char referenceString[] = "OpenGL ES ";
69 
70         if (string == NULL)
71             TCU_FAIL("Got invalid string");
72 
73         if (!deStringBeginsWith(string, referenceString))
74             TCU_FAIL("Got invalid string prefix");
75 
76         {
77             std::string tmpString;
78             char versionDelimiter;
79             int glMajor = 0;
80             int glMinor = 0;
81 
82             std::istringstream versionStream(string);
83             versionStream >> tmpString; // OpenGL
84             versionStream >> tmpString; // ES
85             versionStream >> glMajor;   // x
86             versionStream >> std::noskipws;
87             versionStream >> versionDelimiter; // .
88             versionStream >> glMinor;          // x
89 
90             if (!versionStream)
91                 TCU_FAIL("Got invalid string format");
92         }
93     });
94     ES2F_ADD_API_CASE(shading_language_version, "SHADING_LANGUAGE_VERSION", {
95         const char *string           = (const char *)glGetString(GL_SHADING_LANGUAGE_VERSION);
96         const char referenceString[] = "OpenGL ES GLSL ES ";
97 
98         if (string == NULL)
99             TCU_FAIL("Got invalid string");
100 
101         if (!deStringBeginsWith(string, referenceString))
102             TCU_FAIL("Got invalid string prefix");
103 
104         {
105             std::string tmpString;
106             char versionDelimiter;
107             int glslMajor = 0;
108             int glslMinor = 0;
109 
110             std::istringstream versionStream(string);
111             versionStream >> tmpString; // OpenGL
112             versionStream >> tmpString; // ES
113             versionStream >> tmpString; // GLSL
114             versionStream >> tmpString; // ES
115             versionStream >> glslMajor; // x
116             versionStream >> std::noskipws;
117             versionStream >> versionDelimiter; // .
118             versionStream >> glslMinor;        // x
119 
120             if (!versionStream)
121                 TCU_FAIL("Got invalid string format");
122         }
123     });
124     ES2F_ADD_API_CASE(extensions, "EXTENSIONS", {
125         const char *extensions_cstring = (const char *)glGetString(GL_EXTENSIONS);
126         if (extensions_cstring == NULL)
127             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid string");
128     });
129 }
130 
131 } // namespace Functional
132 } // namespace gles2
133 } // namespace deqp
134