• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program Tester Core
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 Base class for a test case.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "tcuTestPackage.hpp"
25 #include "tcuPlatform.hpp"
26 
27 #include "deString.h"
28 
29 using std::vector;
30 
31 namespace tcu
32 {
33 
34 // TestPackage
35 
TestPackage(TestContext & testCtx,const char * name,const char * description)36 TestPackage::TestPackage (TestContext& testCtx, const char* name, const char* description)
37 	: TestNode(testCtx, NODETYPE_PACKAGE, name, description)
38 {
39 }
40 
~TestPackage(void)41 TestPackage::~TestPackage (void)
42 {
43 }
44 
iterate(void)45 TestNode::IterateResult TestPackage::iterate (void)
46 {
47 	DE_ASSERT(DE_FALSE); // should never be here!
48 	throw InternalError("TestPackage::iterate() called!", "", __FILE__, __LINE__);
49 }
50 
51 // TestPackageRegistry
52 
TestPackageRegistry(void)53 TestPackageRegistry::TestPackageRegistry (void)
54 {
55 }
56 
~TestPackageRegistry(void)57 TestPackageRegistry::~TestPackageRegistry (void)
58 {
59 	for (int i = 0; i < (int)m_packageInfos.size(); i++)
60 		delete m_packageInfos[i];
61 }
62 
getSingleton(void)63 TestPackageRegistry* TestPackageRegistry::getSingleton (void)
64 {
65 	return TestPackageRegistry::getOrDestroy(true);
66 }
67 
destroy(void)68 void TestPackageRegistry::destroy (void)
69 {
70 	TestPackageRegistry::getOrDestroy(false);
71 }
72 
getOrDestroy(bool isCreate)73 TestPackageRegistry* TestPackageRegistry::getOrDestroy (bool isCreate)
74 {
75 	static TestPackageRegistry* s_ptr = DE_NULL;
76 
77 	if (isCreate)
78 	{
79 		if (!s_ptr)
80 			s_ptr = new TestPackageRegistry();
81 
82 		return s_ptr;
83 	}
84 	else
85 	{
86 		if (s_ptr)
87 		{
88 			delete s_ptr;
89 			s_ptr = DE_NULL;
90 		}
91 
92 		return DE_NULL;
93 	}
94 }
95 
registerPackage(const char * name,TestPackageCreateFunc createFunc)96 void TestPackageRegistry::registerPackage (const char* name, TestPackageCreateFunc createFunc)
97 {
98 	m_packageInfos.push_back(new PackageInfo(name, createFunc));
99 }
100 
getPackageInfos(void) const101 const std::vector<TestPackageRegistry::PackageInfo*>& TestPackageRegistry::getPackageInfos (void) const
102 {
103 	return m_packageInfos;
104 }
105 
getPackageInfoByName(const char * packageName) const106 TestPackageRegistry::PackageInfo* TestPackageRegistry::getPackageInfoByName (const char* packageName) const
107 {
108 	for (int i = 0; i < (int)m_packageInfos.size(); i++)
109 	{
110 		if (m_packageInfos[i]->name == packageName)
111 			return m_packageInfos[i];
112 	}
113 
114 	return DE_NULL;
115 }
116 
createPackage(const char * name,TestContext & testCtx) const117 TestPackage* TestPackageRegistry::createPackage (const char* name, TestContext& testCtx) const
118 {
119 	PackageInfo* info = getPackageInfoByName(name);
120 	return info ? info->createFunc(testCtx) : DE_NULL;
121 }
122 
123 // TestPackageDescriptor
124 
TestPackageDescriptor(const char * name,TestPackageCreateFunc createFunc)125 TestPackageDescriptor::TestPackageDescriptor (const char* name, TestPackageCreateFunc createFunc)
126 {
127 	TestPackageRegistry::getSingleton()->registerPackage(name, createFunc);
128 }
129 
~TestPackageDescriptor(void)130 TestPackageDescriptor::~TestPackageDescriptor (void)
131 {
132 	TestPackageRegistry::destroy();
133 }
134 
135 // TestPackageRoot
136 
TestPackageRoot(TestContext & testCtx)137 TestPackageRoot::TestPackageRoot (TestContext& testCtx)
138 	: TestNode(testCtx, NODETYPE_ROOT, "", "")
139 {
140 }
141 
TestPackageRoot(TestContext & testCtx,const vector<TestNode * > & children)142 TestPackageRoot::TestPackageRoot (TestContext& testCtx, const vector<TestNode*>& children)
143 	: TestNode(testCtx, NODETYPE_ROOT, "", "", children)
144 {
145 }
146 
TestPackageRoot(TestContext & testCtx,const TestPackageRegistry * packageRegistry)147 TestPackageRoot::TestPackageRoot (TestContext& testCtx, const TestPackageRegistry* packageRegistry)
148 	: TestNode(testCtx, NODETYPE_ROOT, "", "")
149 {
150 	const vector<TestPackageRegistry::PackageInfo*>&	packageInfos	= packageRegistry->getPackageInfos();
151 
152 	for (int i = 0; i < (int)packageInfos.size(); i++)
153 		addChild(packageInfos[i]->createFunc(testCtx));
154 }
155 
~TestPackageRoot(void)156 TestPackageRoot::~TestPackageRoot (void)
157 {
158 }
159 
iterate(void)160 TestCase::IterateResult TestPackageRoot::iterate (void)
161 {
162 	DE_ASSERT(DE_FALSE); // should never be here!
163 	throw InternalError("TestPackageRoot::iterate() called!", "", __FILE__, __LINE__);
164 }
165 
166 
167 } // tcu
168