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)
38 , m_caseListFilter(nullptr)
39 {
40 DE_UNREF(description);
41 }
42
~TestPackage(void)43 TestPackage::~TestPackage (void)
44 {
45 }
46
setCaseListFilter(const CaseListFilter * caseListFilter)47 void TestPackage::setCaseListFilter (const CaseListFilter* caseListFilter)
48 {
49 m_caseListFilter = caseListFilter;
50 }
51
iterate(void)52 TestNode::IterateResult TestPackage::iterate (void)
53 {
54 DE_ASSERT(DE_FALSE); // should never be here!
55 throw InternalError("TestPackage::iterate() called!", "", __FILE__, __LINE__);
56 }
57
58 // TestPackageRegistry
59
TestPackageRegistry(void)60 TestPackageRegistry::TestPackageRegistry (void)
61 {
62 }
63
~TestPackageRegistry(void)64 TestPackageRegistry::~TestPackageRegistry (void)
65 {
66 for (int i = 0; i < (int)m_packageInfos.size(); i++)
67 delete m_packageInfos[i];
68 }
69
getSingleton(void)70 TestPackageRegistry* TestPackageRegistry::getSingleton (void)
71 {
72 return TestPackageRegistry::getOrDestroy(true);
73 }
74
destroy(void)75 void TestPackageRegistry::destroy (void)
76 {
77 TestPackageRegistry::getOrDestroy(false);
78 }
79
getOrDestroy(bool isCreate)80 TestPackageRegistry* TestPackageRegistry::getOrDestroy (bool isCreate)
81 {
82 static TestPackageRegistry* s_ptr = DE_NULL;
83
84 if (isCreate)
85 {
86 if (!s_ptr)
87 s_ptr = new TestPackageRegistry();
88
89 return s_ptr;
90 }
91 else
92 {
93 if (s_ptr)
94 {
95 delete s_ptr;
96 s_ptr = DE_NULL;
97 }
98
99 return DE_NULL;
100 }
101 }
102
registerPackage(const char * name,TestPackageCreateFunc createFunc)103 void TestPackageRegistry::registerPackage (const char* name, TestPackageCreateFunc createFunc)
104 {
105 DE_ASSERT(getPackageInfoByName(name) == DE_NULL);
106 m_packageInfos.push_back(new PackageInfo(name, createFunc));
107 }
108
getPackageInfos(void) const109 const std::vector<TestPackageRegistry::PackageInfo*>& TestPackageRegistry::getPackageInfos (void) const
110 {
111 return m_packageInfos;
112 }
113
getPackageInfoByName(const char * packageName) const114 TestPackageRegistry::PackageInfo* TestPackageRegistry::getPackageInfoByName (const char* packageName) const
115 {
116 for (int i = 0; i < (int)m_packageInfos.size(); i++)
117 {
118 if (m_packageInfos[i]->name == packageName)
119 return m_packageInfos[i];
120 }
121
122 return DE_NULL;
123 }
124
createPackage(const char * name,TestContext & testCtx) const125 TestPackage* TestPackageRegistry::createPackage (const char* name, TestContext& testCtx) const
126 {
127 PackageInfo* info = getPackageInfoByName(name);
128 return info ? info->createFunc(testCtx) : DE_NULL;
129 }
130
131 // TestPackageDescriptor
132
TestPackageDescriptor(const char * name,TestPackageCreateFunc createFunc)133 TestPackageDescriptor::TestPackageDescriptor (const char* name, TestPackageCreateFunc createFunc)
134 {
135 TestPackageRegistry::getSingleton()->registerPackage(name, createFunc);
136 }
137
~TestPackageDescriptor(void)138 TestPackageDescriptor::~TestPackageDescriptor (void)
139 {
140 TestPackageRegistry::destroy();
141 }
142
143 // TestPackageRoot
144
TestPackageRoot(TestContext & testCtx)145 TestPackageRoot::TestPackageRoot (TestContext& testCtx)
146 : TestNode(testCtx, NODETYPE_ROOT, "")
147 {
148 }
149
TestPackageRoot(TestContext & testCtx,const vector<TestNode * > & children)150 TestPackageRoot::TestPackageRoot (TestContext& testCtx, const vector<TestNode*>& children)
151 : TestNode(testCtx, NODETYPE_ROOT, "", children)
152 {
153 }
154
TestPackageRoot(TestContext & testCtx,const TestPackageRegistry * packageRegistry)155 TestPackageRoot::TestPackageRoot (TestContext& testCtx, const TestPackageRegistry* packageRegistry)
156 : TestNode(testCtx, NODETYPE_ROOT, "")
157 {
158 const vector<TestPackageRegistry::PackageInfo*>& packageInfos = packageRegistry->getPackageInfos();
159
160 for (int i = 0; i < (int)packageInfos.size(); i++)
161 addChild(packageInfos[i]->createFunc(testCtx));
162 }
163
~TestPackageRoot(void)164 TestPackageRoot::~TestPackageRoot (void)
165 {
166 }
167
iterate(void)168 TestCase::IterateResult TestPackageRoot::iterate (void)
169 {
170 DE_ASSERT(DE_FALSE); // should never be here!
171 throw InternalError("TestPackageRoot::iterate() called!", "", __FILE__, __LINE__);
172 }
173
174
175 } // tcu
176