Fix texture/sampler mapping in sRGB tests am: c8efb45ead am: 984445983d am: bd25f07ba0
[platform/upstream/VK-GL-CTS.git] / framework / common / tcuTestPackage.cpp
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         DE_ASSERT(getPackageInfoByName(name) == DE_NULL);
99         m_packageInfos.push_back(new PackageInfo(name, createFunc));
100 }
101
102 const std::vector<TestPackageRegistry::PackageInfo*>& TestPackageRegistry::getPackageInfos (void) const
103 {
104         return m_packageInfos;
105 }
106
107 TestPackageRegistry::PackageInfo* TestPackageRegistry::getPackageInfoByName (const char* packageName) const
108 {
109         for (int i = 0; i < (int)m_packageInfos.size(); i++)
110         {
111                 if (m_packageInfos[i]->name == packageName)
112                         return m_packageInfos[i];
113         }
114
115         return DE_NULL;
116 }
117
118 TestPackage* TestPackageRegistry::createPackage (const char* name, TestContext& testCtx) const
119 {
120         PackageInfo* info = getPackageInfoByName(name);
121         return info ? info->createFunc(testCtx) : DE_NULL;
122 }
123
124 // TestPackageDescriptor
125
126 TestPackageDescriptor::TestPackageDescriptor (const char* name, TestPackageCreateFunc createFunc)
127 {
128         TestPackageRegistry::getSingleton()->registerPackage(name, createFunc);
129 }
130
131 TestPackageDescriptor::~TestPackageDescriptor (void)
132 {
133         TestPackageRegistry::destroy();
134 }
135
136 // TestPackageRoot
137
138 TestPackageRoot::TestPackageRoot (TestContext& testCtx)
139         : TestNode(testCtx, NODETYPE_ROOT, "", "")
140 {
141 }
142
143 TestPackageRoot::TestPackageRoot (TestContext& testCtx, const vector<TestNode*>& children)
144         : TestNode(testCtx, NODETYPE_ROOT, "", "", children)
145 {
146 }
147
148 TestPackageRoot::TestPackageRoot (TestContext& testCtx, const TestPackageRegistry* packageRegistry)
149         : TestNode(testCtx, NODETYPE_ROOT, "", "")
150 {
151         const vector<TestPackageRegistry::PackageInfo*>&        packageInfos    = packageRegistry->getPackageInfos();
152
153         for (int i = 0; i < (int)packageInfos.size(); i++)
154                 addChild(packageInfos[i]->createFunc(testCtx));
155 }
156
157 TestPackageRoot::~TestPackageRoot (void)
158 {
159 }
160
161 TestCase::IterateResult TestPackageRoot::iterate (void)
162 {
163         DE_ASSERT(DE_FALSE); // should never be here!
164         throw InternalError("TestPackageRoot::iterate() called!", "", __FILE__, __LINE__);
165 }
166
167
168 } // tcu