1/*-------------------------------------------------------------------------
2 * OpenGL Conformance Test Suite
3 * -----------------------------
4 *
5 * Copyright (c) 2016 Google Inc.
6 * Copyright (c) 2016 The Khronos Group Inc.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 *      http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 */ /*!
21 * \file
22 * \brief OpenGL ES 2 Test Package.
23 */ /*-------------------------------------------------------------------*/
24
25#include "es2cTestPackage.hpp"
26#include "glcInfoTests.hpp"
27#include "glcShaderNegativeTests.hpp"
28#include "gluRenderContext.hpp"
29#include "gluStateReset.hpp"
30#include "glwEnums.hpp"
31#include "glwFunctions.hpp"
32#include "tcuTestLog.hpp"
33
34namespace es2cts
35{
36
37class TestCaseWrapper : public tcu::TestCaseExecutor
38{
39public:
40	TestCaseWrapper(TestPackage& package);
41	~TestCaseWrapper(void);
42
43	void init(tcu::TestCase* testCase, const std::string& path);
44	void deinit(tcu::TestCase* testCase);
45	tcu::TestNode::IterateResult iterate(tcu::TestCase* testCase);
46
47private:
48	es2cts::TestPackage& m_testPackage;
49};
50
51TestCaseWrapper::TestCaseWrapper(TestPackage& package) : m_testPackage(package)
52{
53}
54
55TestCaseWrapper::~TestCaseWrapper(void)
56{
57}
58
59void TestCaseWrapper::init(tcu::TestCase* testCase, const std::string&)
60{
61	glu::resetState(m_testPackage.getContext().getRenderContext(), m_testPackage.getContext().getContextInfo());
62
63	testCase->init();
64}
65
66void TestCaseWrapper::deinit(tcu::TestCase* testCase)
67{
68	testCase->deinit();
69
70	glu::resetState(m_testPackage.getContext().getRenderContext(), m_testPackage.getContext().getContextInfo());
71}
72
73tcu::TestNode::IterateResult TestCaseWrapper::iterate(tcu::TestCase* testCase)
74{
75	tcu::TestContext&			 testCtx   = m_testPackage.getContext().getTestContext();
76	glu::RenderContext&			 renderCtx = m_testPackage.getContext().getRenderContext();
77	tcu::TestCase::IterateResult result;
78
79	// Clear to black
80	{
81		const glw::Functions& gl = renderCtx.getFunctions();
82		gl.clearColor(0.0f, 0.0f, 0.0f, 1.f);
83		gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
84	}
85
86	result = testCase->iterate();
87
88	// Call implementation specific post-iterate routine (usually handles native events and swaps buffers)
89	try
90	{
91		renderCtx.postIterate();
92		return result;
93	}
94	catch (const tcu::ResourceError& e)
95	{
96		testCtx.getLog() << e;
97		testCtx.setTestResult(QP_TEST_RESULT_RESOURCE_ERROR, "Resource error in context post-iteration routine");
98		testCtx.setTerminateAfter(true);
99		return tcu::TestNode::STOP;
100	}
101	catch (const std::exception& e)
102	{
103		testCtx.getLog() << e;
104		testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Error in context post-iteration routine");
105		return tcu::TestNode::STOP;
106	}
107}
108
109class ShaderTests : public deqp::TestCaseGroup
110{
111public:
112	ShaderTests(deqp::Context& context) : TestCaseGroup(context, "shaders", "Shading Language Tests")
113	{
114	}
115
116	void init(void)
117	{
118		addChild(new deqp::ShaderNegativeTests(m_context, glu::GLSL_VERSION_100_ES));
119	}
120};
121
122TestPackage::TestPackage(tcu::TestContext& testCtx, const char* packageName)
123	: deqp::TestPackage(testCtx, packageName, "OpenGL ES 2 Conformance Tests", glu::ContextType(glu::ApiType::es(2, 0)),
124						"gl_cts/data/gles2/")
125{
126}
127
128TestPackage::~TestPackage(void)
129{
130}
131
132void TestPackage::init(void)
133{
134	// Call init() in parent - this creates context.
135	deqp::TestPackage::init();
136
137	try
138	{
139		addChild(new ShaderTests(getContext()));
140	}
141	catch (...)
142	{
143		// Destroy context.
144		deqp::TestPackage::deinit();
145		throw;
146	}
147}
148
149tcu::TestCaseExecutor* TestPackage::createExecutor(void) const
150{
151	return new TestCaseWrapper(const_cast<TestPackage&>(*this));
152}
153
154} // es2cts
155