1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 2.0 Module
3 * -------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Buffer Object Query tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es2fBufferObjectQueryTests.hpp"
25 #include "glsStateQueryUtil.hpp"
26 #include "es2fApiCase.hpp"
27 #include "gluRenderContext.hpp"
28 #include "glwEnums.hpp"
29 #include "glwFunctions.hpp"
30 #include "deRandom.hpp"
35 using namespace glw; // GLint and other GL types
36 using deqp::gls::StateQueryUtil::StateQueryMemoryWriteGuard;
45 namespace BufferParamVerifiers
48 void checkIntEquals (tcu::TestContext& testCtx, GLint got, GLint expected)
54 testCtx.getLog() << TestLog::Message << "// ERROR: Expected " << expected << "; got " << got << TestLog::EndMessage;
55 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
56 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid value");
60 void checkPointerEquals (tcu::TestContext& testCtx, const void* got, const void* expected)
66 testCtx.getLog() << TestLog::Message << "// ERROR: Expected " << expected << "; got " << got << TestLog::EndMessage;
67 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
68 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid value");
72 class BufferParamVerifier : protected glu::CallLogWrapper
75 BufferParamVerifier (const glw::Functions& gl, tcu::TestLog& log, const char* testNamePostfix);
76 virtual ~BufferParamVerifier (); // make GCC happy
78 const char* getTestNamePostfix (void) const;
80 virtual void verifyInteger (tcu::TestContext& testCtx, GLenum target, GLenum name, GLint reference) = DE_NULL;
82 const char* const m_testNamePostfix;
85 BufferParamVerifier::BufferParamVerifier (const glw::Functions& gl, tcu::TestLog& log, const char* testNamePostfix)
86 : glu::CallLogWrapper (gl, log)
87 , m_testNamePostfix (testNamePostfix)
92 BufferParamVerifier::~BufferParamVerifier ()
96 const char* BufferParamVerifier::getTestNamePostfix (void) const
98 return m_testNamePostfix;
101 class GetBufferParameterIVerifier : public BufferParamVerifier
104 GetBufferParameterIVerifier (const glw::Functions& gl, tcu::TestLog& log);
106 void verifyInteger (tcu::TestContext& testCtx, GLenum target, GLenum name, GLint reference);
109 GetBufferParameterIVerifier::GetBufferParameterIVerifier (const glw::Functions& gl, tcu::TestLog& log)
110 : BufferParamVerifier(gl, log, "_getbufferparameteri")
114 void GetBufferParameterIVerifier::verifyInteger (tcu::TestContext& testCtx, GLenum target, GLenum name, GLint reference)
118 StateQueryMemoryWriteGuard<GLint> state;
119 glGetBufferParameteriv(target, name, &state);
121 if (!state.verifyValidity(testCtx))
124 if (state != reference)
126 testCtx.getLog() << TestLog::Message << "// ERROR: expected " << reference << "; got " << state << TestLog::EndMessage;
128 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
129 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
133 } // BufferParamVerifiers
138 using namespace BufferParamVerifiers;
142 class BufferCase : public ApiCase
145 BufferCase (Context& context, BufferParamVerifier* verifier, const char* name, const char* description)
146 : ApiCase (context, name, description)
148 , m_verifier (verifier)
152 virtual void testBuffer (void) = DE_NULL;
156 const GLenum bufferTargets[] =
158 GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER
160 const int targets = DE_LENGTH_OF_ARRAY(bufferTargets);
162 for (int ndx = 0; ndx < targets; ++ndx)
164 m_bufferTarget = bufferTargets[ndx];
167 glGenBuffers(1, &bufferId);
168 glBindBuffer(m_bufferTarget, bufferId);
169 expectError(GL_NO_ERROR);
173 glDeleteBuffers(1, &bufferId);
174 expectError(GL_NO_ERROR);
179 GLenum m_bufferTarget;
180 BufferParamVerifier* m_verifier;
183 class BufferSizeCase : public BufferCase
186 BufferSizeCase (Context& context, BufferParamVerifier* verifier, const char* name, const char* description)
187 : BufferCase(context, verifier, name, description)
191 void testBuffer (void)
193 const int numIteration = 16;
194 de::Random rnd(0xabcdef);
196 m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_SIZE, 0);
198 for (int i = 0; i < numIteration; ++i)
200 const GLint len = rnd.getInt(0, 1024);
201 glBufferData(m_bufferTarget, len, DE_NULL, GL_STREAM_DRAW);
202 expectError(GL_NO_ERROR);
204 m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_SIZE, len);
205 expectError(GL_NO_ERROR);
210 class BufferUsageCase : public BufferCase
213 BufferUsageCase (Context& context, BufferParamVerifier* verifier, const char* name, const char* description)
214 : BufferCase(context, verifier, name, description)
218 void testBuffer (void)
220 const GLenum usages[] =
222 GL_STATIC_DRAW, GL_DYNAMIC_DRAW, GL_STREAM_DRAW
225 m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_USAGE, GL_STATIC_DRAW);
227 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(usages); ++ndx)
229 glBufferData(m_bufferTarget, 16, DE_NULL, usages[ndx]);
230 expectError(GL_NO_ERROR);
232 m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_USAGE, usages[ndx]);
233 expectError(GL_NO_ERROR);
240 #define FOR_EACH_VERIFIER(VERIFIERS, CODE_BLOCK) \
241 for (int _verifierNdx = 0; _verifierNdx < DE_LENGTH_OF_ARRAY(VERIFIERS); _verifierNdx++) \
243 BufferParamVerifier* verifier = (VERIFIERS)[_verifierNdx]; \
247 BufferObjectQueryTests::BufferObjectQueryTests (Context& context)
248 : TestCaseGroup (context, "buffer_object", "Buffer Object Query tests")
249 , m_verifierInt (DE_NULL)
253 BufferObjectQueryTests::~BufferObjectQueryTests (void)
258 void BufferObjectQueryTests::init (void)
260 using namespace BufferParamVerifiers;
262 DE_ASSERT(m_verifierInt == DE_NULL);
264 m_verifierInt = new GetBufferParameterIVerifier (m_context.getRenderContext().getFunctions(), m_context.getTestContext().getLog());
265 BufferParamVerifier* verifiers[] = {m_verifierInt};
267 FOR_EACH_VERIFIER(verifiers, addChild(new BufferSizeCase (m_context, verifier, (std::string("buffer_size") + verifier->getTestNamePostfix()).c_str(), "BUFFER_SIZE")));
268 FOR_EACH_VERIFIER(verifiers, addChild(new BufferUsageCase (m_context, verifier, (std::string("buffer_usage") + verifier->getTestNamePostfix()).c_str(), "BUFFER_USAGE")));
271 void BufferObjectQueryTests::deinit (void)
275 delete m_verifierInt;
276 m_verifierInt = NULL;
279 this->TestCaseGroup::deinit();