Home | History | Annotate | Download | only in common
      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 	 */
     67 ExposedExtensionsTest::ExposedExtensionsTest(deqp::Context& context, std::string notAllowedSubstring,
     68 											 const std::vector<std::string>* allowedExceptions)
     69 	: deqp::TestCase(context, "validate_extensions", "Test verifies if extensions with "
     70 													 "specified phrase are not exposed.")
     71 	, m_notAllowedSubstring(notAllowedSubstring)
     72 {
     73 	if (allowedExceptions)
     74 	{
     75 		m_allowedExceptions = *allowedExceptions;
     76 	}
     77 }
     78 
     79 ExposedExtensionsTest::~ExposedExtensionsTest(void)
     80 {
     81 }
     82 
     83 /** Tears down any GL objects set up to run the test. */
     84 void ExposedExtensionsTest::deinit(void)
     85 {
     86 }
     87 
     88 /** Stub init method */
     89 void ExposedExtensionsTest::init(void)
     90 {
     91 }
     92 
     93 /** Executes test iteration.
     94 	 *
     95 	 *  @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
     96 	 */
     97 tcu::TestNode::IterateResult ExposedExtensionsTest::iterate(void)
     98 {
     99 	typedef std::vector<std::string> string_vector;
    100 	const string_vector&			 extensions			   = m_context.getContextInfo().getExtensions();
    101 	string_vector::const_iterator	currExtension		   = extensions.begin();
    102 	bool							 allExceptionsAreValid = true;
    103 
    104 	while (currExtension != extensions.end())
    105 	{
    106 		// If the current extension does not contain not allowed substring then continue
    107 		if (currExtension->find(m_notAllowedSubstring) == std::string::npos)
    108 		{
    109 			++currExtension;
    110 			continue;
    111 		}
    112 
    113 		// Check if current extension is one of allowed exceptions
    114 		bool						  currExtensionIsNotAnException = true;
    115 		string_vector::const_iterator exception						= m_allowedExceptions.begin();
    116 		while (exception != m_allowedExceptions.end())
    117 		{
    118 			if ((*exception).compare(*currExtension) == 0)
    119 			{
    120 				currExtensionIsNotAnException = false;
    121 				break;
    122 			}
    123 			++exception;
    124 		}
    125 
    126 		// Current exception is not on allowed exceptions list, test will fail
    127 		// but other exceptions will be checked to log all not allowed extensions
    128 		if (currExtensionIsNotAnException)
    129 		{
    130 			m_testCtx.getLog() << tcu::TestLog::Message << "Implementations should not expose " << *currExtension
    131 							   << tcu::TestLog::EndMessage;
    132 			allExceptionsAreValid = false;
    133 		}
    134 
    135 		++currExtension;
    136 	}
    137 
    138 	if (allExceptionsAreValid)
    139 	{
    140 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
    141 		return STOP;
    142 	}
    143 
    144 	m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
    145 	return STOP;
    146 }
    147 
    148 ExposedExtensionsTests::ExposedExtensionsTests(deqp::Context& context)
    149 	: TestCaseGroup(context, "exposed_extensions", "Verifies exposed extensions")
    150 {
    151 }
    152 
    153 void ExposedExtensionsTests::init(void)
    154 {
    155 	if (isContextTypeES(m_context.getRenderContext().getType()))
    156 	{
    157 		addChild(new ExposedExtensionsTest(m_context, "ARB"));
    158 	}
    159 	else
    160 	{
    161 		std::vector<std::string> allowedExtensions(1, "GL_OES_EGL_image");
    162 		addChild(new glcts::ExposedExtensionsTest(getContext(), "OES", &allowedExtensions));
    163 	}
    164 }
    165 
    166 } /* glcts namespace */
    167