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 m_packageInfos.push_back(new PackageInfo(name, createFunc));
101 const std::vector<TestPackageRegistry::PackageInfo*>& TestPackageRegistry::getPackageInfos (void) const
103 return m_packageInfos;
106 TestPackageRegistry::PackageInfo* TestPackageRegistry::getPackageInfoByName (const char* packageName) const
108 for (int i = 0; i < (int)m_packageInfos.size(); i++)
110 if (m_packageInfos[i]->name == packageName)
111 return m_packageInfos[i];
117 TestPackage* TestPackageRegistry::createPackage (const char* name, TestContext& testCtx) const
119 PackageInfo* info = getPackageInfoByName(name);
120 return info ? info->createFunc(testCtx) : DE_NULL;
123 // TestPackageDescriptor
125 TestPackageDescriptor::TestPackageDescriptor (const char* name, TestPackageCreateFunc createFunc)
127 TestPackageRegistry::getSingleton()->registerPackage(name, createFunc);
130 TestPackageDescriptor::~TestPackageDescriptor (void)
132 TestPackageRegistry::destroy();
137 TestPackageRoot::TestPackageRoot (TestContext& testCtx)
138 : TestNode(testCtx, NODETYPE_ROOT, "", "")
142 TestPackageRoot::TestPackageRoot (TestContext& testCtx, const vector<TestNode*>& children)
143 : TestNode(testCtx, NODETYPE_ROOT, "", "", children)
147 TestPackageRoot::TestPackageRoot (TestContext& testCtx, const TestPackageRegistry* packageRegistry)
148 : TestNode(testCtx, NODETYPE_ROOT, "", "")
150 const vector<TestPackageRegistry::PackageInfo*>& packageInfos = packageRegistry->getPackageInfos();
152 for (int i = 0; i < (int)packageInfos.size(); i++)
153 addChild(packageInfos[i]->createFunc(testCtx));
156 TestPackageRoot::~TestPackageRoot (void)
160 TestCase::IterateResult TestPackageRoot::iterate (void)
162 DE_ASSERT(DE_FALSE); // should never be here!
163 throw InternalError("TestPackageRoot::iterate() called!", "", __FILE__, __LINE__);