1 /*-------------------------------------------------------------------------
2 * OpenGL Conformance Test Suite
3 * -----------------------------
4 *
5 * Copyright (c) 2017 The Khronos Group Inc.
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 glcExtensionsExposeTests.cpp
21 * \brief Test that check if specified substring is not in extension name.
22 */ /*--------------------------------------------------------------------*/
23
24 #include "glcExposedExtensionsTests.hpp"
25 #include "gluContextInfo.hpp"
26 #include "gluDefs.hpp"
27 #include "glwEnums.hpp"
28 #include "glwFunctions.hpp"
29 #include "tcuCommandLine.hpp"
30 #include "tcuTestLog.hpp"
31 #include <string>
32 #include <vector>
33
34 using namespace glu;
35
36 namespace glcts
37 {
38
39 class ExposedExtensionsTest : public deqp::TestCase
40 {
41 public:
42 /* Public methods */
43 ExposedExtensionsTest(deqp::Context &context, std::string notAllowedSubstring,
44 const std::vector<std::string> *allowedExceptions = NULL);
45
46 virtual ~ExposedExtensionsTest(void);
47
48 void deinit(void);
49 void init(void);
50 tcu::TestNode::IterateResult iterate(void);
51
52 private:
53 /* Private members */
54 std::string m_notAllowedSubstring;
55 std::vector<std::string> m_allowedExceptions;
56 };
57
58 /** Constructor.
59 *
60 * @param context Rendering context
61 * @param name Test name
62 * @param description Test description
63 * @param notAllowedSubstring Substring that should not be found in extension name.
64 * @param allowedExceptions List of exceptions that are allowed even despite
65 * containing notAllowedFraze.
66 */
ExposedExtensionsTest(deqp::Context & context,std::string notAllowedSubstring,const std::vector<std::string> * allowedExceptions)67 ExposedExtensionsTest::ExposedExtensionsTest(deqp::Context &context, std::string notAllowedSubstring,
68 const std::vector<std::string> *allowedExceptions)
69 : deqp::TestCase(context, "validate_extensions",
70 "Test verifies if extensions with "
71 "specified phrase are not exposed.")
72 , m_notAllowedSubstring(notAllowedSubstring)
73 {
74 if (allowedExceptions)
75 {
76 m_allowedExceptions = *allowedExceptions;
77 }
78 }
79
~ExposedExtensionsTest(void)80 ExposedExtensionsTest::~ExposedExtensionsTest(void)
81 {
82 }
83
84 /** Tears down any GL objects set up to run the test. */
deinit(void)85 void ExposedExtensionsTest::deinit(void)
86 {
87 }
88
89 /** Stub init method */
init(void)90 void ExposedExtensionsTest::init(void)
91 {
92 }
93
94 /** Executes test iteration.
95 *
96 * @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
97 */
iterate(void)98 tcu::TestNode::IterateResult ExposedExtensionsTest::iterate(void)
99 {
100 typedef std::vector<std::string> string_vector;
101 const string_vector &extensions = m_context.getContextInfo().getExtensions();
102 string_vector::const_iterator currExtension = extensions.begin();
103 bool allExceptionsAreValid = true;
104
105 while (currExtension != extensions.end())
106 {
107 // If the current extension does not contain not allowed substring then continue
108 if (currExtension->find(m_notAllowedSubstring) == std::string::npos)
109 {
110 ++currExtension;
111 continue;
112 }
113
114 // Check if current extension is one of allowed exceptions
115 bool currExtensionIsNotAnException = true;
116 string_vector::const_iterator exception = m_allowedExceptions.begin();
117 while (exception != m_allowedExceptions.end())
118 {
119 if ((*exception).compare(*currExtension) == 0)
120 {
121 currExtensionIsNotAnException = false;
122 break;
123 }
124 ++exception;
125 }
126
127 // Current exception is not on allowed exceptions list, test will fail
128 // but other exceptions will be checked to log all not allowed extensions
129 if (currExtensionIsNotAnException)
130 {
131 m_testCtx.getLog() << tcu::TestLog::Message << "Implementations should not expose " << *currExtension
132 << tcu::TestLog::EndMessage;
133 allExceptionsAreValid = false;
134 }
135
136 ++currExtension;
137 }
138
139 if (allExceptionsAreValid)
140 {
141 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
142 return STOP;
143 }
144
145 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
146 return STOP;
147 }
148
ExposedExtensionsTests(deqp::Context & context)149 ExposedExtensionsTests::ExposedExtensionsTests(deqp::Context &context)
150 : TestCaseGroup(context, "exposed_extensions", "Verifies exposed extensions")
151 {
152 }
153
init(void)154 void ExposedExtensionsTests::init(void)
155 {
156 if (isContextTypeES(m_context.getRenderContext().getType()))
157 {
158 addChild(new ExposedExtensionsTest(m_context, "ARB"));
159 }
160 else
161 {
162 std::vector<std::string> allowedExtensions(1, "GL_OES_EGL_image");
163 addChild(new glcts::ExposedExtensionsTest(getContext(), "OES", &allowedExtensions));
164 }
165 }
166
167 } // namespace glcts
168