teglApiCase.cpp revision 3c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4
13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program EGL Module
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ---------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief API test case.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "teglApiCase.hpp"
253c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos#include "egluUtil.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluStrUtil.hpp"
273c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos#include "eglwLibrary.hpp"
283c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos#include "eglwEnums.hpp"
293c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos#include "deSTLUtil.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace egl
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
363c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing tcu::TestLog;
373c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing std::vector;
383c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing namespace eglw;
393c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
403c827367444ee418f129b2c238299f49d3264554Jarkko PoyryApiCase::ApiCase (EglTestContext& eglTestCtx, const char* name, const char* description)
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase		(eglTestCtx, name, description)
423c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	, CallLogWrapper(eglTestCtx.getLibrary(), eglTestCtx.getTestContext().getLog())
433c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	, m_display		(EGL_NO_DISPLAY)
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
473c827367444ee418f129b2c238299f49d3264554Jarkko PoyryApiCase::~ApiCase (void)
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
513c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosvoid ApiCase::init (void)
523c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos{
533c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	m_display				= eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
543c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	m_supportedClientAPIs	= eglu::getClientAPIs(m_eglTestCtx.getLibrary(), m_display);
553c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos}
563c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
573c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosvoid ApiCase::deinit (void)
583c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos{
593c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const Library&	egl	= m_eglTestCtx.getLibrary();
603c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	egl.terminate(m_display);
613c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
623c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	m_display = EGL_NO_DISPLAY;
633c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	m_supportedClientAPIs.clear();
643c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos}
653c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
663c827367444ee418f129b2c238299f49d3264554Jarkko PoyryApiCase::IterateResult ApiCase::iterate (void)
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Initialize result to pass.
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Enable call logging.
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enableLogging(true);
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Run test.
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	test();
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
803c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosbool ApiCase::isAPISupported (eglw::EGLenum api) const
813c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos{
823c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	return de::contains(m_supportedClientAPIs.begin(), m_supportedClientAPIs.end(), api);
833c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos}
843c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ApiCase::expectError (EGLenum expected)
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
873c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLenum err = m_eglTestCtx.getLibrary().getError();
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (err != expected)
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << "// ERROR: expected " << eglu::getErrorStr(expected) << TestLog::EndMessage;
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid error");
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ApiCase::expectBoolean (EGLBoolean expected, EGLBoolean got)
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (expected != got)
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << "// ERROR: expected " << (expected ? "EGL_TRUE" : "EGL_FALSE") << TestLog::EndMessage;
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ApiCase::expectNoContext (EGLContext got)
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (got != EGL_NO_CONTEXT)
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << "// ERROR: expected EGL_NO_CONTEXT" << TestLog::EndMessage;
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		eglDestroyContext(getDisplay(), got);
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ApiCase::expectNoSurface (EGLSurface got)
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (got != EGL_NO_CONTEXT)
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << "// ERROR: expected EGL_NO_SURFACE" << TestLog::EndMessage;
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		eglDestroySurface(getDisplay(), got);
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ApiCase::expectNoDisplay (EGLDisplay got)
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (got != EGL_NO_CONTEXT)
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << "// ERROR: expected EGL_NO_DISPLAY" << TestLog::EndMessage;
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ApiCase::expectNull (const void* got)
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (got != EGL_NO_CONTEXT)
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << "// ERROR: expected NULL" << TestLog::EndMessage;
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1483c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosbool ApiCase::getConfig (EGLConfig* config, const eglu::FilterList& filters)
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1503c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	try
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1523c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		*config = eglu::chooseSingleConfig(m_eglTestCtx.getLibrary(), m_display, filters);
1533c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		return true;
1543c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	}
1553c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	catch (const tcu::NotSupportedError&)
1563c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	{
1573c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		return false;
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // egl
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
163