• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "egluUtil.hpp"
26 #include "egluStrUtil.hpp"
27 #include "eglwLibrary.hpp"
28 #include "eglwEnums.hpp"
29 #include "deSTLUtil.hpp"
30 
31 namespace deqp
32 {
33 namespace egl
34 {
35 
36 using tcu::TestLog;
37 using std::vector;
38 using namespace eglw;
39 
ApiCase(EglTestContext & eglTestCtx,const char * name,const char * description)40 ApiCase::ApiCase (EglTestContext& eglTestCtx, const char* name, const char* description)
41 	: TestCase		(eglTestCtx, name, description)
42 	, CallLogWrapper(eglTestCtx.getLibrary(), eglTestCtx.getTestContext().getLog())
43 	, m_display		(EGL_NO_DISPLAY)
44 {
45 }
46 
~ApiCase(void)47 ApiCase::~ApiCase (void)
48 {
49 }
50 
init(void)51 void ApiCase::init (void)
52 {
53 	m_display				= eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
54 	m_supportedClientAPIs	= eglu::getClientAPIs(m_eglTestCtx.getLibrary(), m_display);
55 }
56 
deinit(void)57 void ApiCase::deinit (void)
58 {
59 	const Library&	egl	= m_eglTestCtx.getLibrary();
60 	egl.terminate(m_display);
61 
62 	m_display = EGL_NO_DISPLAY;
63 	m_supportedClientAPIs.clear();
64 }
65 
iterate(void)66 ApiCase::IterateResult ApiCase::iterate (void)
67 {
68 	// Initialize result to pass.
69 	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
70 
71 	// Enable call logging.
72 	enableLogging(true);
73 
74 	// Run test.
75 	test();
76 
77 	return STOP;
78 }
79 
isAPISupported(eglw::EGLenum api) const80 bool ApiCase::isAPISupported (eglw::EGLenum api) const
81 {
82 	return de::contains(m_supportedClientAPIs.begin(), m_supportedClientAPIs.end(), api);
83 }
84 
expectError(EGLenum expected)85 void ApiCase::expectError (EGLenum expected)
86 {
87 	EGLenum err = m_eglTestCtx.getLibrary().getError();
88 	if (err != expected)
89 	{
90 		m_testCtx.getLog() << TestLog::Message << "// ERROR expected: " << eglu::getErrorStr(expected) << ", Got: " << eglu::getErrorStr(err) << TestLog::EndMessage;
91 		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
92 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid error");
93 	}
94 }
95 
expectEitherError(EGLenum expectedA,EGLenum expectedB)96 void ApiCase::expectEitherError (EGLenum expectedA, EGLenum expectedB)
97 {
98 	EGLenum err = m_eglTestCtx.getLibrary().getError();
99 	if (err != expectedA && err != expectedB)
100 	{
101 		m_testCtx.getLog() << TestLog::Message << "// ERROR expected: " << eglu::getErrorStr(expectedA) << " or " << eglu::getErrorStr(expectedB) << ", Got: " << eglu::getErrorStr(err) << TestLog::EndMessage;
102 		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
103 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid error");
104 	}
105 }
106 
expectBoolean(EGLBoolean expected,EGLBoolean got)107 void ApiCase::expectBoolean (EGLBoolean expected, EGLBoolean got)
108 {
109 	if (expected != got)
110 	{
111 		m_testCtx.getLog() << TestLog::Message << "// ERROR expected: " << eglu::getBooleanStr(expected) <<  ", Got: " << eglu::getBooleanStr(got) << TestLog::EndMessage;
112 		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
113 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
114 	}
115 }
116 
expectNoContext(EGLContext got)117 void ApiCase::expectNoContext (EGLContext got)
118 {
119 	if (got != EGL_NO_CONTEXT)
120 	{
121 		m_testCtx.getLog() << TestLog::Message << "// ERROR expected: EGL_NO_CONTEXT" << TestLog::EndMessage;
122 		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
123 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
124 		eglDestroyContext(getDisplay(), got);
125 	}
126 }
127 
expectNoSurface(EGLSurface got)128 void ApiCase::expectNoSurface (EGLSurface got)
129 {
130 	if (got != EGL_NO_SURFACE)
131 	{
132 		m_testCtx.getLog() << TestLog::Message << "// ERROR expected: EGL_NO_SURFACE" << TestLog::EndMessage;
133 		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
134 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
135 		eglDestroySurface(getDisplay(), got);
136 	}
137 }
138 
expectNoDisplay(EGLDisplay got)139 void ApiCase::expectNoDisplay (EGLDisplay got)
140 {
141 	if (got != EGL_NO_DISPLAY)
142 	{
143 		m_testCtx.getLog() << TestLog::Message << "// ERROR expected: EGL_NO_DISPLAY" << TestLog::EndMessage;
144 		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
145 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
146 	}
147 }
148 
expectNull(const void * got)149 void ApiCase::expectNull (const void* got)
150 {
151 	if (got != DE_NULL)
152 	{
153 		m_testCtx.getLog() << TestLog::Message << "// ERROR expected: NULL" << TestLog::EndMessage;
154 		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
155 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
156 	}
157 }
158 
getConfig(EGLConfig * config,const eglu::FilterList & filters)159 bool ApiCase::getConfig (EGLConfig* config, const eglu::FilterList& filters)
160 {
161 	try
162 	{
163 		*config = eglu::chooseSingleConfig(m_eglTestCtx.getLibrary(), m_display, filters);
164 		return true;
165 	}
166 	catch (const tcu::NotSupportedError&)
167 	{
168 		return false;
169 	}
170 }
171 
172 } // egl
173 } // deqp
174