xref: /aosp_15_r20/external/deqp/modules/gles3/functional/es3fStringQueryTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES 3.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 "es3fStringQueryTests.hpp"
25 #include "es3fApiCase.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 gles3
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     ES3F_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     ES3F_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     ES3F_ADD_API_CASE(version, "VERSION", {
67         bool isES = glu::isContextTypeES(m_context.getRenderContext().getType());
68 
69         const char *string          = (const char *)glGetString(GL_VERSION);
70         const char *referenceString = isES ? "OpenGL ES 3." : "4.";
71 
72         if (string == NULL)
73             TCU_FAIL("Got invalid string");
74 
75         if (!deStringBeginsWith(string, referenceString))
76             TCU_FAIL("Got invalid string prefix");
77 
78         {
79             std::string tmpString;
80             char versionDelimiter;
81             int glMajor             = 0;
82             int glMinor             = 0;
83             GLint stateVersionMinor = 0;
84 
85             std::istringstream versionStream(string);
86 
87             if (isES)
88             {
89                 versionStream >> tmpString; // OpenGL
90                 versionStream >> tmpString; // ES
91             }
92 
93             versionStream >> glMajor; // 3
94             versionStream >> std::noskipws;
95             versionStream >> versionDelimiter; // .
96             versionStream >> glMinor;          // x
97 
98             if (!versionStream)
99                 TCU_FAIL("Got invalid string format");
100 
101             glGetIntegerv(GL_MINOR_VERSION, &stateVersionMinor);
102             if (glMinor != stateVersionMinor)
103             {
104                 m_testCtx.getLog() << TestLog::Message << "// ERROR: MINOR_VERSION is " << stateVersionMinor
105                                    << TestLog::EndMessage;
106                 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid version.");
107                 return;
108             }
109         }
110     });
111     ES3F_ADD_API_CASE(shading_language_version, "SHADING_LANGUAGE_VERSION", {
112         bool isES = glu::isContextTypeES(m_context.getRenderContext().getType());
113 
114         const char *string          = (const char *)glGetString(GL_SHADING_LANGUAGE_VERSION);
115         const char *referenceString = isES ? "OpenGL ES GLSL ES " : "4.";
116 
117         if (string == NULL)
118             TCU_FAIL("Got invalid string");
119 
120         if (!deStringBeginsWith(string, referenceString))
121             TCU_FAIL("Got invalid string prefix");
122 
123         {
124             std::string tmpString;
125             char versionDelimiter;
126             int glslMajor        = 0;
127             char glslMinorDigit1 = 0;
128             char glslMinorDigit2 = 0;
129             bool digitsAreValid;
130 
131             std::istringstream versionStream(string);
132 
133             if (isES)
134             {
135                 versionStream >> tmpString; // OpenGL
136                 versionStream >> tmpString; // ES
137                 versionStream >> tmpString; // GLSL
138                 versionStream >> tmpString; // ES
139             }
140 
141             versionStream >> glslMajor; // x
142             versionStream >> std::noskipws;
143             versionStream >> versionDelimiter; // .
144             versionStream >> glslMinorDigit1;  // x
145             versionStream >> glslMinorDigit2;  // x
146 
147             digitsAreValid =
148                 glslMinorDigit1 >= '0' && glslMinorDigit1 <= '9' && glslMinorDigit2 >= '0' && glslMinorDigit2 <= '9';
149 
150             if (!versionStream || !digitsAreValid)
151                 TCU_FAIL("Got invalid string format");
152         }
153     });
154     ES3F_ADD_API_CASE(extensions, "EXTENSIONS", {
155         const char *extensions_cstring = (const char *)glGetString(GL_EXTENSIONS);
156         if (extensions_cstring == NULL)
157         {
158             bool isES = glu::isContextTypeES(m_context.getRenderContext().getType());
159 
160             // GL_EXTENSIONS has been deprecated on desktop GL
161             if (!isES)
162             {
163                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Got NULL string for deprecated enum");
164                 expectError(GL_INVALID_ENUM);
165                 return;
166             }
167 
168             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid string");
169             return;
170         }
171 
172         // split extensions_string at ' '
173 
174         std::istringstream extensionStream((std::string)(extensions_cstring));
175         std::vector<std::string> extensions;
176 
177         for (;;)
178         {
179             std::string extension;
180             if (std::getline(extensionStream, extension, ' '))
181                 extensions.push_back(extension);
182             else
183                 break;
184         }
185 
186         GLint numExtensions = 0;
187         glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
188         expectError(GL_NO_ERROR);
189 
190         if (extensions.size() != (size_t)numExtensions)
191         {
192             m_testCtx.getLog() << TestLog::Message << "// ERROR:  NUM_EXTENSIONS is " << numExtensions << "; got "
193                                << extensions.size() << " extensions" << TestLog::EndMessage;
194             if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
195                 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got non-consistent number of extensions");
196         }
197 
198         // all in glGetStringi(GL_EXTENSIONS) in must be in glGetString
199 
200         for (int i = 0; i < numExtensions; ++i)
201         {
202             std::string extension((const char *)glGetStringi(GL_EXTENSIONS, i));
203 
204             if (std::find(extensions.begin(), extensions.end(), extension) == extensions.end())
205             {
206                 m_testCtx.getLog() << TestLog::Message << "// ERROR: extension " << extension
207                                    << " found with GetStringi was not found in glGetString(GL_EXTENSIONS)"
208                                    << TestLog::EndMessage;
209                 if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
210                     m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Extension query methods are not consistent.");
211             }
212         }
213 
214         // only elements in glGetStringi(GL_EXTENSIONS) can be in glGetString
215 
216         for (int i = 0; i < numExtensions; ++i)
217         {
218             std::string extension((const char *)glGetStringi(GL_EXTENSIONS, i));
219 
220             std::vector<std::string>::iterator it = std::find(extensions.begin(), extensions.end(), extension);
221             if (it != extensions.end())
222                 extensions.erase(it);
223         }
224 
225         if (!extensions.empty())
226         {
227             for (size_t ndx = 0; ndx < extensions.size(); ++ndx)
228                 m_testCtx.getLog() << TestLog::Message << "// ERROR: extension \"" << extensions[ndx]
229                                    << "\" found with GetString was not found with GetStringi(GL_EXTENSIONS, ind)"
230                                    << TestLog::EndMessage;
231 
232             if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
233                 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Extension query methods are not consistent.");
234         }
235     });
236 }
237 
238 } // namespace Functional
239 } // namespace gles3
240 } // namespace deqp
241