1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES 3.1 Module
3  * -------------------------------------------------
4  *
5  * Copyright 2015 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 Boolean State Query tests.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "es31fBooleanStateQueryTests.hpp"
25 #include "glsStateQueryUtil.hpp"
26 #include "gluRenderContext.hpp"
27 #include "gluCallLogWrapper.hpp"
28 #include "tcuRenderTarget.hpp"
29 #include "glwFunctions.hpp"
30 #include "glwEnums.hpp"
31 
32 namespace deqp
33 {
34 namespace gles31
35 {
36 namespace Functional
37 {
38 namespace
39 {
40 
41 using namespace gls::StateQueryUtil;
42 
getVerifierSuffix(QueryType type)43 static const char* getVerifierSuffix (QueryType type)
44 {
45 	switch (type)
46 	{
47 		case QUERY_ISENABLED:	return "isenabled";
48 		case QUERY_BOOLEAN:		return "getboolean";
49 		case QUERY_INTEGER:		return "getinteger";
50 		case QUERY_INTEGER64:	return "getinteger64";
51 		case QUERY_FLOAT:		return "getfloat";
52 		default:
53 			DE_ASSERT(DE_FALSE);
54 			return DE_NULL;
55 	}
56 }
57 
58 class IsEnabledStateTestCase : public TestCase, private glu::CallLogWrapper
59 {
60 public:
IsEnabledStateTestCase(Context & context,QueryType verifier,const char * name,const char * description,glw::GLenum targetName,bool initial)61 	IsEnabledStateTestCase (Context& context, QueryType verifier, const char* name, const char* description, glw::GLenum targetName, bool initial)
62 		: TestCase				(context, name, description)
63 		, glu::CallLogWrapper	(context.getRenderContext().getFunctions(), context.getTestContext().getLog())
64 		, m_targetName			(targetName)
65 		, m_initial				(initial)
66 		, m_verifier			(verifier)
67 	{
68 	}
69 
iterate(void)70 	IterateResult iterate (void)
71 	{
72 		tcu::ResultCollector result(m_testCtx.getLog(), " // ERROR: ");
73 		enableLogging(true);
74 
75 		// check inital value
76 		verifyStateBoolean(result, *this, m_targetName, m_initial, m_verifier);
77 
78 		// check toggle
79 
80 		GLU_CHECK_CALL(glEnable(m_targetName));
81 
82 		verifyStateBoolean(result, *this, m_targetName, true, m_verifier);
83 
84 		GLU_CHECK_CALL(glDisable(m_targetName));
85 
86 		verifyStateBoolean(result, *this, m_targetName, false, m_verifier);
87 
88 		result.setTestContextResult(m_testCtx);
89 		return STOP;
90 	}
91 
92 private:
93 	const glw::GLenum		m_targetName;
94 	const bool				m_initial;
95 	const QueryType			m_verifier;
96 };
97 
98 } // anonymous
99 
BooleanStateQueryTests(Context & context)100 BooleanStateQueryTests::BooleanStateQueryTests (Context& context)
101 	: TestCaseGroup(context, "boolean", "Boolean State Query tests")
102 {
103 }
104 
~BooleanStateQueryTests(void)105 BooleanStateQueryTests::~BooleanStateQueryTests (void)
106 {
107 }
108 
init(void)109 void BooleanStateQueryTests::init (void)
110 {
111 	static const QueryType isEnabledVerifiers[] =
112 	{
113 		QUERY_ISENABLED,
114 		QUERY_BOOLEAN,
115 		QUERY_INTEGER,
116 		QUERY_INTEGER64,
117 		QUERY_FLOAT
118 	};
119 
120 #define FOR_EACH_VERIFIER(VERIFIERS, X) \
121 	for (int verifierNdx = 0; verifierNdx < DE_LENGTH_OF_ARRAY(VERIFIERS); ++verifierNdx)	\
122 	{																						\
123 		const char* verifierSuffix = getVerifierSuffix(VERIFIERS[verifierNdx]);				\
124 		const QueryType verifier = VERIFIERS[verifierNdx];									\
125 		this->addChild(X);																	\
126 	}
127 
128 	struct StateBoolean
129 	{
130 		const char*		name;
131 		const char*		description;
132 		glw::GLenum		targetName;
133 		bool			value;
134 	};
135 	const StateBoolean isEnableds[] =
136 	{
137 		{ "sample_mask",	"SAMPLE_MASK",	GL_SAMPLE_MASK,	false},
138 	};
139 
140 	for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(isEnableds); testNdx++)
141 	{
142 		FOR_EACH_VERIFIER(isEnabledVerifiers, new IsEnabledStateTestCase(m_context, verifier, (std::string(isEnableds[testNdx].name) + "_" + verifierSuffix).c_str(), isEnableds[testNdx].description, isEnableds[testNdx].targetName, isEnableds[testNdx].value));
143 	}
144 
145 #undef FOR_EACH_VERIFIER
146 }
147 
148 } // Functional
149 } // gles31
150 } // deqp
151