1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Base class for a test case.
22 *//*--------------------------------------------------------------------*/
24 #include "tcuTestPackage.hpp"
25 #include "tcuPlatform.hpp"
36 TestPackage::TestPackage (TestContext& testCtx, const char* name, const char* description)
37 : TestNode(testCtx, NODETYPE_PACKAGE, name, description)
41 TestPackage::~TestPackage (void)
45 TestNode::IterateResult TestPackage::iterate (void)
47 DE_ASSERT(DE_FALSE); // should never be here!
48 throw InternalError("TestPackage::iterate() called!", "", __FILE__, __LINE__);
51 // TestPackageRegistry
53 TestPackageRegistry::TestPackageRegistry (void)
57 TestPackageRegistry::~TestPackageRegistry (void)
59 for (int i = 0; i < (int)m_packageInfos.size(); i++)
60 delete m_packageInfos[i];
63 TestPackageRegistry* TestPackageRegistry::getSingleton (void)
65 return TestPackageRegistry::getOrDestroy(true);
68 void TestPackageRegistry::destroy (void)
70 TestPackageRegistry::getOrDestroy(false);
73 TestPackageRegistry* TestPackageRegistry::getOrDestroy (bool isCreate)
75 static TestPackageRegistry* s_ptr = DE_NULL;
80 s_ptr = new TestPackageRegistry();
96 void TestPackageRegistry::registerPackage (const char* name, TestPackageCreateFunc createFunc)
98 DE_ASSERT(getPackageInfoByName(name) == DE_NULL);
99 m_packageInfos.push_back(new PackageInfo(name, createFunc));
102 const std::vector<TestPackageRegistry::PackageInfo*>& TestPackageRegistry::getPackageInfos (void) const
104 return m_packageInfos;
107 TestPackageRegistry::PackageInfo* TestPackageRegistry::getPackageInfoByName (const char* packageName) const
109 for (int i = 0; i < (int)m_packageInfos.size(); i++)
111 if (m_packageInfos[i]->name == packageName)
112 return m_packageInfos[i];
118 TestPackage* TestPackageRegistry::createPackage (const char* name, TestContext& testCtx) const
120 PackageInfo* info = getPackageInfoByName(name);
121 return info ? info->createFunc(testCtx) : DE_NULL;
124 // TestPackageDescriptor
126 TestPackageDescriptor::TestPackageDescriptor (const char* name, TestPackageCreateFunc createFunc)
128 TestPackageRegistry::getSingleton()->registerPackage(name, createFunc);
131 TestPackageDescriptor::~TestPackageDescriptor (void)
133 TestPackageRegistry::destroy();
138 TestPackageRoot::TestPackageRoot (TestContext& testCtx)
139 : TestNode(testCtx, NODETYPE_ROOT, "", "")
143 TestPackageRoot::TestPackageRoot (TestContext& testCtx, const vector<TestNode*>& children)
144 : TestNode(testCtx, NODETYPE_ROOT, "", "", children)
148 TestPackageRoot::TestPackageRoot (TestContext& testCtx, const TestPackageRegistry* packageRegistry)
149 : TestNode(testCtx, NODETYPE_ROOT, "", "")
151 const vector<TestPackageRegistry::PackageInfo*>& packageInfos = packageRegistry->getPackageInfos();
153 for (int i = 0; i < (int)packageInfos.size(); i++)
154 addChild(packageInfos[i]->createFunc(testCtx));
157 TestPackageRoot::~TestPackageRoot (void)
161 TestCase::IterateResult TestPackageRoot::iterate (void)
163 DE_ASSERT(DE_FALSE); // should never be here!
164 throw InternalError("TestPackageRoot::iterate() called!", "", __FILE__, __LINE__);