1/*-------------------------------------------------------------------------
2 * drawElements Quality Program EGL 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 "teglApiCase.hpp"
25#include "egluStrUtil.hpp"
26
27using tcu::TestLog;
28
29namespace deqp
30{
31namespace egl
32{
33
34ApiCase::ApiCase (EglTestContext& eglTestCtx, const char* name, const char* description)
35	: TestCase		(eglTestCtx, name, description)
36	, CallLogWrapper(eglTestCtx.getTestContext().getLog())
37{
38}
39
40ApiCase::~ApiCase (void)
41{
42}
43
44ApiCase::IterateResult ApiCase::iterate (void)
45{
46	// Initialize result to pass.
47	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
48
49	// Enable call logging.
50	enableLogging(true);
51
52	// Run test.
53	test();
54
55	return STOP;
56}
57
58void ApiCase::expectError (EGLenum expected)
59{
60	EGLenum err = eglGetError();
61	if (err != expected)
62	{
63		m_testCtx.getLog() << TestLog::Message << "// ERROR: expected " << eglu::getErrorStr(expected) << TestLog::EndMessage;
64		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
65			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid error");
66	}
67}
68
69void ApiCase::expectBoolean (EGLBoolean expected, EGLBoolean got)
70{
71	if (expected != got)
72	{
73		m_testCtx.getLog() << TestLog::Message << "// ERROR: expected " << (expected ? "EGL_TRUE" : "EGL_FALSE") << TestLog::EndMessage;
74		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
75			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
76	}
77}
78
79void ApiCase::expectNoContext (EGLContext got)
80{
81	if (got != EGL_NO_CONTEXT)
82	{
83		m_testCtx.getLog() << TestLog::Message << "// ERROR: expected EGL_NO_CONTEXT" << TestLog::EndMessage;
84		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
85			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
86		eglDestroyContext(getDisplay(), got);
87	}
88}
89
90void ApiCase::expectNoSurface (EGLSurface got)
91{
92	if (got != EGL_NO_CONTEXT)
93	{
94		m_testCtx.getLog() << TestLog::Message << "// ERROR: expected EGL_NO_SURFACE" << TestLog::EndMessage;
95		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
96			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
97		eglDestroySurface(getDisplay(), got);
98	}
99}
100
101void ApiCase::expectNoDisplay (EGLDisplay got)
102{
103	if (got != EGL_NO_CONTEXT)
104	{
105		m_testCtx.getLog() << TestLog::Message << "// ERROR: expected EGL_NO_DISPLAY" << TestLog::EndMessage;
106		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
107			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
108	}
109}
110
111void ApiCase::expectNull (const void* got)
112{
113	if (got != EGL_NO_CONTEXT)
114	{
115		m_testCtx.getLog() << TestLog::Message << "// ERROR: expected NULL" << TestLog::EndMessage;
116		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
117			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
118	}
119}
120
121bool ApiCase::getConfig (EGLConfig* config,const eglu::FilterList& filters)
122{
123	for (std::vector<eglu::ConfigInfo>::const_iterator cfgIter = m_eglTestCtx.getConfigs().begin(); cfgIter != m_eglTestCtx.getConfigs().end(); ++cfgIter)
124	{
125		if (filters.match(*cfgIter))
126		{
127			EGLint		numCfgs;
128			EGLBoolean	ok;
129			EGLint		attribs[] =
130			{
131				EGL_CONFIG_ID,			cfgIter->configId,
132				EGL_TRANSPARENT_TYPE,	EGL_DONT_CARE,
133				EGL_COLOR_BUFFER_TYPE,	EGL_DONT_CARE,
134				EGL_RENDERABLE_TYPE,	EGL_DONT_CARE,
135				EGL_SURFACE_TYPE,		EGL_DONT_CARE,
136				EGL_NONE
137			};
138
139			ok = eglChooseConfig(getDisplay(), &attribs[0], config, 1, &numCfgs);
140			expectTrue(ok);
141
142			if (ok && numCfgs >= 1)
143				return true;
144			else
145			{
146				m_testCtx.getLog() << TestLog::Message << "// ERROR: expected at least one config with id " << cfgIter->configId << TestLog::EndMessage;
147				if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
148					m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
149				return 0;
150			}
151		}
152	}
153
154	return DE_NULL;
155}
156
157} // egl
158} // deqp
159