1e5c31af7Sopenharmony_ci/*-------------------------------------------------------------------------
2e5c31af7Sopenharmony_ci * drawElements Quality Program OpenGL ES 2.0 Module
3e5c31af7Sopenharmony_ci * -------------------------------------------------
4e5c31af7Sopenharmony_ci *
5e5c31af7Sopenharmony_ci * Copyright 2014 The Android Open Source Project
6e5c31af7Sopenharmony_ci *
7e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
8e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License.
9e5c31af7Sopenharmony_ci * You may obtain a copy of the License at
10e5c31af7Sopenharmony_ci *
11e5c31af7Sopenharmony_ci *      http://www.apache.org/licenses/LICENSE-2.0
12e5c31af7Sopenharmony_ci *
13e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
14e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
15e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and
17e5c31af7Sopenharmony_ci * limitations under the License.
18e5c31af7Sopenharmony_ci *
19e5c31af7Sopenharmony_ci *//*!
20e5c31af7Sopenharmony_ci * \file
21e5c31af7Sopenharmony_ci * \brief Buffer Object Query tests.
22e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/
23e5c31af7Sopenharmony_ci
24e5c31af7Sopenharmony_ci#include "es2fBufferObjectQueryTests.hpp"
25e5c31af7Sopenharmony_ci#include "glsStateQueryUtil.hpp"
26e5c31af7Sopenharmony_ci#include "es2fApiCase.hpp"
27e5c31af7Sopenharmony_ci#include "gluRenderContext.hpp"
28e5c31af7Sopenharmony_ci#include "glwEnums.hpp"
29e5c31af7Sopenharmony_ci#include "glwFunctions.hpp"
30e5c31af7Sopenharmony_ci#include "deRandom.hpp"
31e5c31af7Sopenharmony_ci#include "deMath.h"
32e5c31af7Sopenharmony_ci
33e5c31af7Sopenharmony_ci#include <limits>
34e5c31af7Sopenharmony_ci
35e5c31af7Sopenharmony_ciusing namespace glw; // GLint and other GL types
36e5c31af7Sopenharmony_ciusing deqp::gls::StateQueryUtil::StateQueryMemoryWriteGuard;
37e5c31af7Sopenharmony_ci
38e5c31af7Sopenharmony_ci
39e5c31af7Sopenharmony_cinamespace deqp
40e5c31af7Sopenharmony_ci{
41e5c31af7Sopenharmony_cinamespace gles2
42e5c31af7Sopenharmony_ci{
43e5c31af7Sopenharmony_cinamespace Functional
44e5c31af7Sopenharmony_ci{
45e5c31af7Sopenharmony_cinamespace BufferParamVerifiers
46e5c31af7Sopenharmony_ci{
47e5c31af7Sopenharmony_ci
48e5c31af7Sopenharmony_civoid checkIntEquals (tcu::TestContext& testCtx, GLint got, GLint expected)
49e5c31af7Sopenharmony_ci{
50e5c31af7Sopenharmony_ci	using tcu::TestLog;
51e5c31af7Sopenharmony_ci
52e5c31af7Sopenharmony_ci	if (got != expected)
53e5c31af7Sopenharmony_ci	{
54e5c31af7Sopenharmony_ci		testCtx.getLog() << TestLog::Message << "// ERROR: Expected " << expected << "; got " << got << TestLog::EndMessage;
55e5c31af7Sopenharmony_ci		if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
56e5c31af7Sopenharmony_ci			testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid value");
57e5c31af7Sopenharmony_ci	}
58e5c31af7Sopenharmony_ci}
59e5c31af7Sopenharmony_ci
60e5c31af7Sopenharmony_civoid checkPointerEquals (tcu::TestContext& testCtx, const void* got, const void* expected)
61e5c31af7Sopenharmony_ci{
62e5c31af7Sopenharmony_ci	using tcu::TestLog;
63e5c31af7Sopenharmony_ci
64e5c31af7Sopenharmony_ci	if (got != expected)
65e5c31af7Sopenharmony_ci	{
66e5c31af7Sopenharmony_ci		testCtx.getLog() << TestLog::Message << "// ERROR: Expected " << expected << "; got " << got << TestLog::EndMessage;
67e5c31af7Sopenharmony_ci		if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
68e5c31af7Sopenharmony_ci			testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid value");
69e5c31af7Sopenharmony_ci	}
70e5c31af7Sopenharmony_ci}
71e5c31af7Sopenharmony_ci
72e5c31af7Sopenharmony_ciclass BufferParamVerifier : protected glu::CallLogWrapper
73e5c31af7Sopenharmony_ci{
74e5c31af7Sopenharmony_cipublic:
75e5c31af7Sopenharmony_ci						BufferParamVerifier		(const glw::Functions& gl, tcu::TestLog& log, const char* testNamePostfix);
76e5c31af7Sopenharmony_ci	virtual				~BufferParamVerifier	(); // make GCC happy
77e5c31af7Sopenharmony_ci
78e5c31af7Sopenharmony_ci	const char*			getTestNamePostfix		(void) const;
79e5c31af7Sopenharmony_ci
80e5c31af7Sopenharmony_ci	virtual void		verifyInteger			(tcu::TestContext& testCtx, GLenum target, GLenum name, GLint reference)	= DE_NULL;
81e5c31af7Sopenharmony_ciprivate:
82e5c31af7Sopenharmony_ci	const char*	const	m_testNamePostfix;
83e5c31af7Sopenharmony_ci};
84e5c31af7Sopenharmony_ci
85e5c31af7Sopenharmony_ciBufferParamVerifier::BufferParamVerifier (const glw::Functions& gl, tcu::TestLog& log, const char* testNamePostfix)
86e5c31af7Sopenharmony_ci	: glu::CallLogWrapper	(gl, log)
87e5c31af7Sopenharmony_ci	, m_testNamePostfix		(testNamePostfix)
88e5c31af7Sopenharmony_ci{
89e5c31af7Sopenharmony_ci	enableLogging(true);
90e5c31af7Sopenharmony_ci}
91e5c31af7Sopenharmony_ci
92e5c31af7Sopenharmony_ciBufferParamVerifier::~BufferParamVerifier ()
93e5c31af7Sopenharmony_ci{
94e5c31af7Sopenharmony_ci}
95e5c31af7Sopenharmony_ci
96e5c31af7Sopenharmony_ciconst char* BufferParamVerifier::getTestNamePostfix (void) const
97e5c31af7Sopenharmony_ci{
98e5c31af7Sopenharmony_ci	return m_testNamePostfix;
99e5c31af7Sopenharmony_ci}
100e5c31af7Sopenharmony_ci
101e5c31af7Sopenharmony_ciclass GetBufferParameterIVerifier : public BufferParamVerifier
102e5c31af7Sopenharmony_ci{
103e5c31af7Sopenharmony_cipublic:
104e5c31af7Sopenharmony_ci			GetBufferParameterIVerifier					(const glw::Functions& gl, tcu::TestLog& log);
105e5c31af7Sopenharmony_ci
106e5c31af7Sopenharmony_ci	void	verifyInteger								(tcu::TestContext& testCtx, GLenum target, GLenum name, GLint reference);
107e5c31af7Sopenharmony_ci};
108e5c31af7Sopenharmony_ci
109e5c31af7Sopenharmony_ciGetBufferParameterIVerifier::GetBufferParameterIVerifier (const glw::Functions& gl, tcu::TestLog& log)
110e5c31af7Sopenharmony_ci	: BufferParamVerifier(gl, log, "_getbufferparameteri")
111e5c31af7Sopenharmony_ci{
112e5c31af7Sopenharmony_ci}
113e5c31af7Sopenharmony_ci
114e5c31af7Sopenharmony_civoid GetBufferParameterIVerifier::verifyInteger (tcu::TestContext& testCtx, GLenum target, GLenum name, GLint reference)
115e5c31af7Sopenharmony_ci{
116e5c31af7Sopenharmony_ci	using tcu::TestLog;
117e5c31af7Sopenharmony_ci
118e5c31af7Sopenharmony_ci	StateQueryMemoryWriteGuard<GLint> state;
119e5c31af7Sopenharmony_ci	glGetBufferParameteriv(target, name, &state);
120e5c31af7Sopenharmony_ci
121e5c31af7Sopenharmony_ci	if (!state.verifyValidity(testCtx))
122e5c31af7Sopenharmony_ci		return;
123e5c31af7Sopenharmony_ci
124e5c31af7Sopenharmony_ci	if (state != reference)
125e5c31af7Sopenharmony_ci	{
126e5c31af7Sopenharmony_ci		testCtx.getLog() << TestLog::Message << "// ERROR: expected " << reference << "; got " << state << TestLog::EndMessage;
127e5c31af7Sopenharmony_ci
128e5c31af7Sopenharmony_ci		if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
129e5c31af7Sopenharmony_ci			testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
130e5c31af7Sopenharmony_ci	}
131e5c31af7Sopenharmony_ci}
132e5c31af7Sopenharmony_ci
133e5c31af7Sopenharmony_ci} // BufferParamVerifiers
134e5c31af7Sopenharmony_ci
135e5c31af7Sopenharmony_cinamespace
136e5c31af7Sopenharmony_ci{
137e5c31af7Sopenharmony_ci
138e5c31af7Sopenharmony_ciusing namespace BufferParamVerifiers;
139e5c31af7Sopenharmony_ci
140e5c31af7Sopenharmony_ci// Tests
141e5c31af7Sopenharmony_ci
142e5c31af7Sopenharmony_ciclass BufferCase : public ApiCase
143e5c31af7Sopenharmony_ci{
144e5c31af7Sopenharmony_cipublic:
145e5c31af7Sopenharmony_ci	BufferCase (Context& context, BufferParamVerifier* verifier, const char* name, const char* description)
146e5c31af7Sopenharmony_ci		: ApiCase			(context, name, description)
147e5c31af7Sopenharmony_ci		, m_bufferTarget	(0)
148e5c31af7Sopenharmony_ci		, m_verifier		(verifier)
149e5c31af7Sopenharmony_ci	{
150e5c31af7Sopenharmony_ci	}
151e5c31af7Sopenharmony_ci
152e5c31af7Sopenharmony_ci	virtual void testBuffer (void) = DE_NULL;
153e5c31af7Sopenharmony_ci
154e5c31af7Sopenharmony_ci	void test (void)
155e5c31af7Sopenharmony_ci	{
156e5c31af7Sopenharmony_ci		const GLenum bufferTargets[] =
157e5c31af7Sopenharmony_ci		{
158e5c31af7Sopenharmony_ci			GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER
159e5c31af7Sopenharmony_ci		};
160e5c31af7Sopenharmony_ci		const int targets = DE_LENGTH_OF_ARRAY(bufferTargets);
161e5c31af7Sopenharmony_ci
162e5c31af7Sopenharmony_ci		for (int ndx = 0; ndx < targets; ++ndx)
163e5c31af7Sopenharmony_ci		{
164e5c31af7Sopenharmony_ci			m_bufferTarget = bufferTargets[ndx];
165e5c31af7Sopenharmony_ci
166e5c31af7Sopenharmony_ci			GLuint bufferId = 0;
167e5c31af7Sopenharmony_ci			glGenBuffers(1, &bufferId);
168e5c31af7Sopenharmony_ci			glBindBuffer(m_bufferTarget, bufferId);
169e5c31af7Sopenharmony_ci			expectError(GL_NO_ERROR);
170e5c31af7Sopenharmony_ci
171e5c31af7Sopenharmony_ci			testBuffer();
172e5c31af7Sopenharmony_ci
173e5c31af7Sopenharmony_ci			glDeleteBuffers(1, &bufferId);
174e5c31af7Sopenharmony_ci			expectError(GL_NO_ERROR);
175e5c31af7Sopenharmony_ci		}
176e5c31af7Sopenharmony_ci	}
177e5c31af7Sopenharmony_ci
178e5c31af7Sopenharmony_ciprotected:
179e5c31af7Sopenharmony_ci	GLenum					m_bufferTarget;
180e5c31af7Sopenharmony_ci	BufferParamVerifier*	m_verifier;
181e5c31af7Sopenharmony_ci};
182e5c31af7Sopenharmony_ci
183e5c31af7Sopenharmony_ciclass BufferSizeCase : public BufferCase
184e5c31af7Sopenharmony_ci{
185e5c31af7Sopenharmony_cipublic:
186e5c31af7Sopenharmony_ci	BufferSizeCase (Context& context, BufferParamVerifier* verifier, const char* name, const char* description)
187e5c31af7Sopenharmony_ci		: BufferCase(context, verifier, name, description)
188e5c31af7Sopenharmony_ci	{
189e5c31af7Sopenharmony_ci	}
190e5c31af7Sopenharmony_ci
191e5c31af7Sopenharmony_ci	void testBuffer (void)
192e5c31af7Sopenharmony_ci	{
193e5c31af7Sopenharmony_ci		const int numIteration = 16;
194e5c31af7Sopenharmony_ci		de::Random rnd(0xabcdef);
195e5c31af7Sopenharmony_ci
196e5c31af7Sopenharmony_ci		m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_SIZE, 0);
197e5c31af7Sopenharmony_ci
198e5c31af7Sopenharmony_ci		for (int i = 0; i < numIteration; ++i)
199e5c31af7Sopenharmony_ci		{
200e5c31af7Sopenharmony_ci			const GLint len = rnd.getInt(0, 1024);
201e5c31af7Sopenharmony_ci			glBufferData(m_bufferTarget, len, DE_NULL, GL_STREAM_DRAW);
202e5c31af7Sopenharmony_ci			expectError(GL_NO_ERROR);
203e5c31af7Sopenharmony_ci
204e5c31af7Sopenharmony_ci			m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_SIZE, len);
205e5c31af7Sopenharmony_ci			expectError(GL_NO_ERROR);
206e5c31af7Sopenharmony_ci		}
207e5c31af7Sopenharmony_ci	}
208e5c31af7Sopenharmony_ci};
209e5c31af7Sopenharmony_ci
210e5c31af7Sopenharmony_ciclass BufferUsageCase : public BufferCase
211e5c31af7Sopenharmony_ci{
212e5c31af7Sopenharmony_cipublic:
213e5c31af7Sopenharmony_ci	BufferUsageCase (Context& context, BufferParamVerifier* verifier, const char* name, const char* description)
214e5c31af7Sopenharmony_ci		: BufferCase(context, verifier, name, description)
215e5c31af7Sopenharmony_ci	{
216e5c31af7Sopenharmony_ci	}
217e5c31af7Sopenharmony_ci
218e5c31af7Sopenharmony_ci	void testBuffer (void)
219e5c31af7Sopenharmony_ci	{
220e5c31af7Sopenharmony_ci		const GLenum usages[] =
221e5c31af7Sopenharmony_ci		{
222e5c31af7Sopenharmony_ci			GL_STATIC_DRAW, GL_DYNAMIC_DRAW, GL_STREAM_DRAW
223e5c31af7Sopenharmony_ci		};
224e5c31af7Sopenharmony_ci
225e5c31af7Sopenharmony_ci		m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_USAGE, GL_STATIC_DRAW);
226e5c31af7Sopenharmony_ci
227e5c31af7Sopenharmony_ci		for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(usages); ++ndx)
228e5c31af7Sopenharmony_ci		{
229e5c31af7Sopenharmony_ci			glBufferData(m_bufferTarget, 16, DE_NULL, usages[ndx]);
230e5c31af7Sopenharmony_ci			expectError(GL_NO_ERROR);
231e5c31af7Sopenharmony_ci
232e5c31af7Sopenharmony_ci			m_verifier->verifyInteger(m_testCtx, m_bufferTarget, GL_BUFFER_USAGE, usages[ndx]);
233e5c31af7Sopenharmony_ci			expectError(GL_NO_ERROR);
234e5c31af7Sopenharmony_ci		}
235e5c31af7Sopenharmony_ci	}
236e5c31af7Sopenharmony_ci};
237e5c31af7Sopenharmony_ci
238e5c31af7Sopenharmony_ci} // anonymous
239e5c31af7Sopenharmony_ci
240e5c31af7Sopenharmony_ci#define FOR_EACH_VERIFIER(VERIFIERS, CODE_BLOCK)												\
241e5c31af7Sopenharmony_ci	for (int _verifierNdx = 0; _verifierNdx < DE_LENGTH_OF_ARRAY(VERIFIERS); _verifierNdx++)	\
242e5c31af7Sopenharmony_ci	{																							\
243e5c31af7Sopenharmony_ci		BufferParamVerifier* verifier = (VERIFIERS)[_verifierNdx];								\
244e5c31af7Sopenharmony_ci		CODE_BLOCK;																				\
245e5c31af7Sopenharmony_ci	}
246e5c31af7Sopenharmony_ci
247e5c31af7Sopenharmony_ciBufferObjectQueryTests::BufferObjectQueryTests (Context& context)
248e5c31af7Sopenharmony_ci	: TestCaseGroup		(context, "buffer_object", "Buffer Object Query tests")
249e5c31af7Sopenharmony_ci	, m_verifierInt		(DE_NULL)
250e5c31af7Sopenharmony_ci{
251e5c31af7Sopenharmony_ci}
252e5c31af7Sopenharmony_ci
253e5c31af7Sopenharmony_ciBufferObjectQueryTests::~BufferObjectQueryTests (void)
254e5c31af7Sopenharmony_ci{
255e5c31af7Sopenharmony_ci	deinit();
256e5c31af7Sopenharmony_ci}
257e5c31af7Sopenharmony_ci
258e5c31af7Sopenharmony_civoid BufferObjectQueryTests::init (void)
259e5c31af7Sopenharmony_ci{
260e5c31af7Sopenharmony_ci	using namespace BufferParamVerifiers;
261e5c31af7Sopenharmony_ci
262e5c31af7Sopenharmony_ci	DE_ASSERT(m_verifierInt == DE_NULL);
263e5c31af7Sopenharmony_ci
264e5c31af7Sopenharmony_ci	m_verifierInt		= new GetBufferParameterIVerifier	(m_context.getRenderContext().getFunctions(), m_context.getTestContext().getLog());
265e5c31af7Sopenharmony_ci	BufferParamVerifier* verifiers[] = {m_verifierInt};
266e5c31af7Sopenharmony_ci
267e5c31af7Sopenharmony_ci	FOR_EACH_VERIFIER(verifiers, addChild(new BufferSizeCase		(m_context, verifier,	(std::string("buffer_size")				+ verifier->getTestNamePostfix()).c_str(), "BUFFER_SIZE")))
268e5c31af7Sopenharmony_ci	FOR_EACH_VERIFIER(verifiers, addChild(new BufferUsageCase		(m_context, verifier,	(std::string("buffer_usage")			+ verifier->getTestNamePostfix()).c_str(), "BUFFER_USAGE")))
269e5c31af7Sopenharmony_ci}
270e5c31af7Sopenharmony_ci
271e5c31af7Sopenharmony_civoid BufferObjectQueryTests::deinit (void)
272e5c31af7Sopenharmony_ci{
273e5c31af7Sopenharmony_ci	if (m_verifierInt)
274e5c31af7Sopenharmony_ci	{
275e5c31af7Sopenharmony_ci		delete m_verifierInt;
276e5c31af7Sopenharmony_ci		m_verifierInt = NULL;
277e5c31af7Sopenharmony_ci	}
278e5c31af7Sopenharmony_ci
279e5c31af7Sopenharmony_ci	this->TestCaseGroup::deinit();
280e5c31af7Sopenharmony_ci}
281e5c31af7Sopenharmony_ci
282e5c31af7Sopenharmony_ci} // Functional
283e5c31af7Sopenharmony_ci} // gles2
284e5c31af7Sopenharmony_ci} // deqp
285