xref: /aosp_15_r20/external/deqp/modules/gles2/functional/es2fApiCase.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 API test case.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "es2fApiCase.hpp"
25 #include "gluStrUtil.hpp"
26 #include "gluRenderContext.hpp"
27 
28 #include <algorithm>
29 
30 using std::string;
31 using std::vector;
32 
33 namespace deqp
34 {
35 namespace gles2
36 {
37 namespace Functional
38 {
39 
ApiCase(Context & context,const char * name,const char * description)40 ApiCase::ApiCase(Context &context, const char *name, const char *description)
41     : TestCase(context, name, description)
42     , CallLogWrapper(context.getRenderContext().getFunctions(), context.getTestContext().getLog())
43     , m_log(context.getTestContext().getLog())
44 {
45 }
46 
~ApiCase(void)47 ApiCase::~ApiCase(void)
48 {
49 }
50 
iterate(void)51 ApiCase::IterateResult ApiCase::iterate(void)
52 {
53     // Initialize result to pass.
54     m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
55 
56     // Enable call logging.
57     enableLogging(true);
58 
59     // Run test.
60     test();
61 
62     return STOP;
63 }
64 
expectError(uint32_t expected)65 void ApiCase::expectError(uint32_t expected)
66 {
67     uint32_t err = glGetError();
68     if (err != expected)
69     {
70         m_testCtx.getLog() << tcu::TestLog::Message << "// ERROR: expected " << glu::getErrorStr(expected)
71                            << tcu::TestLog::EndMessage;
72         if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
73             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid error");
74     }
75 }
76 
expectError(uint32_t expected0,uint32_t expected1)77 void ApiCase::expectError(uint32_t expected0, uint32_t expected1)
78 {
79     uint32_t err = glGetError();
80     if (err != expected0 && err != expected1)
81     {
82         m_log << tcu::TestLog::Message << "// ERROR: expected " << glu::getErrorStr(expected0) << " or "
83               << glu::getErrorStr(expected1) << tcu::TestLog::EndMessage;
84         if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
85             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid error");
86     }
87 }
88 
checkBooleans(uint8_t value,uint8_t expected)89 void ApiCase::checkBooleans(uint8_t value, uint8_t expected)
90 {
91     checkBooleans((int32_t)value, expected);
92 }
93 
checkBooleans(int32_t value,uint8_t expected)94 void ApiCase::checkBooleans(int32_t value, uint8_t expected)
95 {
96     if (value != (int32_t)expected)
97     {
98         m_log << tcu::TestLog::Message << "// ERROR: expected " << (expected ? "GL_TRUE" : "GL_FALSE")
99               << tcu::TestLog::EndMessage;
100         if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
101             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid boolean value");
102     }
103 }
104 
getSupportedExtensions(const uint32_t numSupportedValues,const uint32_t extension,std::vector<int> & values)105 void ApiCase::getSupportedExtensions(const uint32_t numSupportedValues, const uint32_t extension,
106                                      std::vector<int> &values)
107 {
108     int32_t numFormats;
109     GLU_CHECK_CALL(glGetIntegerv(numSupportedValues, &numFormats));
110     if (numFormats == 0)
111     {
112         m_testCtx.getLog() << tcu::TestLog::Message << "// No supported extensions available."
113                            << tcu::TestLog::EndMessage;
114         return;
115     }
116     values.resize(numFormats);
117     GLU_CHECK_CALL(glGetIntegerv(extension, &values[0]));
118 }
119 
120 } // namespace Functional
121 } // namespace gles2
122 } // namespace deqp
123