1/*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 2.0 Module
3 * -------------------------------------------------
4 *
5 * Copyright 2014 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 API test case.
22 *//*--------------------------------------------------------------------*/
23
24#include "es2fApiCase.hpp"
25#include "gluStrUtil.hpp"
26#include "gluRenderContext.hpp"
27
28#include <algorithm>
29
30using std::string;
31using std::vector;
32
33namespace deqp
34{
35namespace gles2
36{
37namespace Functional
38{
39
40ApiCase::ApiCase (Context& context, const char* name, const char* description)
41	: TestCase		(context, name, description)
42	, CallLogWrapper(context.getRenderContext().getFunctions(), context.getTestContext().getLog())
43	, m_log			(context.getTestContext().getLog())
44{
45}
46
47ApiCase::~ApiCase (void)
48{
49}
50
51ApiCase::IterateResult ApiCase::iterate (void)
52{
53	// Initialize result to pass.
54	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
55
56	// Enable call logging.
57	enableLogging(true);
58
59	// Run test.
60	test();
61
62	return STOP;
63}
64
65void ApiCase::expectError (deUint32 expected)
66{
67	deUint32 err = glGetError();
68	if (err != expected)
69	{
70		m_testCtx.getLog() << tcu::TestLog::Message << "// ERROR: expected " << glu::getErrorStr(expected) << tcu::TestLog::EndMessage;
71		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
72			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid error");
73	}
74}
75
76void ApiCase::expectError (deUint32 expected0, deUint32 expected1)
77{
78	deUint32 err = glGetError();
79	if (err != expected0 && err != expected1)
80	{
81		m_log << tcu::TestLog::Message << "// ERROR: expected " << glu::getErrorStr(expected0) << " or " << glu::getErrorStr(expected1) << tcu::TestLog::EndMessage;
82		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
83			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid error");
84	}
85}
86
87void ApiCase::checkBooleans (deUint8 value, deUint8 expected)
88{
89	if (value != expected)
90	{
91		m_log << tcu::TestLog::Message << "// ERROR: expected " << (expected	? "GL_TRUE" : "GL_FALSE") << tcu::TestLog::EndMessage;
92		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
93			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid boolean value");
94	}
95}
96
97void ApiCase::getSupportedExtensions (const deUint32 numSupportedValues, const deUint32 extension, std::vector<int>& values)
98{
99	deInt32 numFormats;
100	GLU_CHECK_CALL(glGetIntegerv(numSupportedValues, &numFormats));
101	if (numFormats == 0)
102	{
103		m_testCtx.getLog() << tcu::TestLog::Message << "// No supported extensions available." << tcu::TestLog::EndMessage;
104		return;
105	}
106	values.resize(numFormats);
107	GLU_CHECK_CALL(glGetIntegerv(extension, &values[0]));
108}
109
110} // Functional
111} // gles2
112} // deqp
113