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 36 TestPackage::TestPackage (TestContext& testCtx, const char* name, const char* description) 37 : TestNode(testCtx, NODETYPE_PACKAGE, name, description) 38 { 39 } 40 41 TestPackage::~TestPackage (void) 42 { 43 } 44 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 53 TestPackageRegistry::TestPackageRegistry (void) 54 { 55 } 56 57 TestPackageRegistry::~TestPackageRegistry (void) 58 { 59 for (int i = 0; i < (int)m_packageInfos.size(); i++) 60 delete m_packageInfos[i]; 61 } 62 63 TestPackageRegistry* TestPackageRegistry::getSingleton (void) 64 { 65 return TestPackageRegistry::getOrDestroy(true); 66 } 67 68 void TestPackageRegistry::destroy (void) 69 { 70 TestPackageRegistry::getOrDestroy(false); 71 } 72 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 96 void TestPackageRegistry::registerPackage (const char* name, TestPackageCreateFunc createFunc) 97 { 98 m_packageInfos.push_back(new PackageInfo(name, createFunc)); 99 } 100 101 const std::vector<TestPackageRegistry::PackageInfo*>& TestPackageRegistry::getPackageInfos (void) const 102 { 103 return m_packageInfos; 104 } 105 106 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 117 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 125 TestPackageDescriptor::TestPackageDescriptor (const char* name, TestPackageCreateFunc createFunc) 126 { 127 TestPackageRegistry::getSingleton()->registerPackage(name, createFunc); 128 } 129 130 TestPackageDescriptor::~TestPackageDescriptor (void) 131 { 132 TestPackageRegistry::destroy(); 133 } 134 135 // TestPackageRoot 136 137 TestPackageRoot::TestPackageRoot (TestContext& testCtx) 138 : TestNode(testCtx, NODETYPE_ROOT, "", "") 139 { 140 } 141 142 TestPackageRoot::TestPackageRoot (TestContext& testCtx, const vector<TestNode*>& children) 143 : TestNode(testCtx, NODETYPE_ROOT, "", "", children) 144 { 145 } 146 147 TestPackageRoot::~TestPackageRoot (void) 148 { 149 } 150 151 TestCase::IterateResult TestPackageRoot::iterate (void) 152 { 153 DE_ASSERT(DE_FALSE); // should never be here! 154 throw InternalError("TestPackageRoot::iterate() called!", "", __FILE__, __LINE__); 155 } 156 157 158 } // tcu 159