1#ifndef _TCUTESTPACKAGE_HPP
2#define _TCUTESTPACKAGE_HPP
3/*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
5 * ----------------------------------------
6 *
7 * Copyright 2014 The Android Open Source Project
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 *//*!
22 * \file
23 * \brief Base class for a test case.
24 *//*--------------------------------------------------------------------*/
25
26#include "tcuDefs.hpp"
27#include "tcuTestCase.hpp"
28
29namespace tcu
30{
31
32/*--------------------------------------------------------------------*//*!
33 * \brief Test case execution interface.
34 *
35 * TestCaseExecutor provides package-specific resources & initialization
36 * for test cases.
37 *
38 * \todo [2015-03-18 pyry] Replace with following API:
39 *
40 * class TestInstance
41 * {
42 * public:
43 *     TestInstance (TestContext& testCtx);
44 *     tcu::TestResult iterate (void);
45 * };
46 *
47 * class TestInstanceFactory (???)
48 * {
49 * public:
50 *     TestInstance* createInstance (const TestCase* testCase, const std::string& path);
51 * };
52 *//*--------------------------------------------------------------------*/
53class TestCaseExecutor
54{
55public:
56	virtual								~TestCaseExecutor	(void) {}
57
58	virtual void						init				(TestCase* testCase, const std::string& path) = 0;
59	virtual void						deinit				(TestCase* testCase) = 0;
60	virtual TestNode::IterateResult		iterate				(TestCase* testCase) = 0;
61};
62
63/*--------------------------------------------------------------------*//*!
64 * \brief Base class for test packages.
65 *
66 * Test packages are root-level test groups. They also provide package-
67 * specific test case executor, see TestCaseExecutor.
68 *//*--------------------------------------------------------------------*/
69class TestPackage : public TestNode
70{
71public:
72									TestPackage			(TestContext& testCtx, const char* name, const char* description);
73	virtual							~TestPackage		(void);
74
75	virtual TestCaseExecutor*		createExecutor		(void) const = 0;
76
77	// Deprecated
78	virtual Archive*				getArchive			(void) { return DE_NULL; }
79
80	virtual IterateResult			iterate				(void);
81};
82
83// TestPackageRegistry
84
85typedef TestPackage* (*TestPackageCreateFunc)	(TestContext& testCtx);
86
87class TestPackageRegistry
88{
89public:
90	struct PackageInfo
91	{
92		PackageInfo (std::string name_, TestPackageCreateFunc createFunc_) : name(name_), createFunc(createFunc_) {}
93
94		std::string				name;
95		TestPackageCreateFunc	createFunc;
96	};
97
98	static TestPackageRegistry*			getSingleton			(void);
99	static void							destroy					(void);
100
101	void								registerPackage			(const char* name, TestPackageCreateFunc createFunc);
102	const std::vector<PackageInfo*>&	getPackageInfos			(void) const;
103	PackageInfo*						getPackageInfoByName	(const char* name) const;
104	TestPackage*						createPackage			(const char* name, TestContext& testCtx) const;
105
106private:
107										TestPackageRegistry		(void);
108										~TestPackageRegistry	(void);
109
110	static TestPackageRegistry*			getOrDestroy			(bool isCreate);
111
112	// Member variables.
113	std::vector<PackageInfo*>			m_packageInfos;
114};
115
116// TestPackageDescriptor
117
118class TestPackageDescriptor
119{
120public:
121						TestPackageDescriptor		(const char* name, TestPackageCreateFunc createFunc);
122						~TestPackageDescriptor		(void);
123};
124
125// TestPackageRoot
126
127class TestPackageRoot : public TestNode
128{
129public:
130							TestPackageRoot		(TestContext& testCtx);
131							TestPackageRoot		(TestContext& testCtx, const std::vector<TestNode*>& children);
132							TestPackageRoot		(TestContext& testCtx, const TestPackageRegistry* packageRegistry);
133	virtual					~TestPackageRoot	(void);
134
135	virtual IterateResult	iterate				(void);
136};
137
138} // tcu
139
140#endif // _TCUTESTPACKAGE_HPP
141