Import dEQP.
[platform/upstream/VK-GL-CTS.git] / framework / common / tcuTestCase.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 "tcuTestCase.hpp"
25 #include "tcuPlatform.hpp"
26
27 #include "deString.h"
28
29 namespace tcu
30 {
31
32 using namespace std;
33
34 // TestNode.
35
36 inline bool isValidCaseNameChar (char c)
37 {
38         return de::inRange(c, 'a', 'z') ||
39                    de::inRange(c, 'A', 'Z') ||
40                    de::inRange(c, '0', '9') ||
41                    c == '_' || c == '-';
42 }
43
44 inline bool isValidCaseName (const char* name)
45 {
46         for (const char* p = name; *p != '\0'; p++)
47         {
48                 if (!isValidCaseNameChar(*p))
49                         return false;
50         }
51         return true;
52 }
53
54 TestNode::TestNode (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description)
55         : m_testCtx             (testCtx)
56         , m_nodeType    (nodeType)
57         , m_name                (name)
58         , m_description (description)
59 {
60         DE_ASSERT(isValidCaseName(name));
61 }
62
63 TestNode::TestNode (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description, const vector<TestNode*>& children)
64         : m_testCtx             (testCtx)
65         , m_nodeType    (nodeType)
66         , m_name                (name)
67         , m_description (description)
68 {
69         DE_ASSERT(isValidCaseName(name));
70         for (int i = 0; i < (int)children.size(); i++)
71                 addChild(children[i]);
72 }
73
74 TestNode::~TestNode (void)
75 {
76         TestNode::deinit();
77 }
78
79 void TestNode::getChildren (vector<TestNode*>& res) const
80 {
81         res.clear();
82         for (int i = 0; i < (int)m_children.size(); i++)
83                 res.push_back(m_children[i]);
84 }
85
86 void TestNode::addChild (TestNode* node)
87 {
88         // Child names must be unique!
89         // \todo [petri] O(n^2) algorithm, but shouldn't really matter..
90 #if defined(DE_DEBUG)
91         for (int i = 0; i < (int)m_children.size(); i++)
92         {
93                 if (deStringEqual(node->getName(), m_children[i]->getName()))
94                         throw tcu::InternalError(std::string("Test case with non-unique name '") + node->getName() + "' added to group '" + getName() + "'.");
95         }
96 #endif
97
98         m_children.push_back(node);
99 }
100
101 void TestNode::init (void)
102 {
103 }
104
105 void TestNode::deinit (void)
106 {
107         for (int i = 0; i < (int)m_children.size(); i++)
108                 delete m_children[i];
109         m_children.clear();
110 }
111
112 // TestCaseGroup
113
114 TestCaseGroup::TestCaseGroup (TestContext& testCtx, const char* name, const char* description)
115         : TestNode(testCtx, NODETYPE_GROUP, name, description)
116 {
117 }
118
119 TestCaseGroup::TestCaseGroup (TestContext& testCtx, const char* name, const char* description, const vector<TestNode*>& children)
120         : TestNode(testCtx, NODETYPE_GROUP, name, description, children)
121 {
122 }
123
124 TestCaseGroup::~TestCaseGroup (void)
125 {
126 }
127
128 TestCase::IterateResult TestCaseGroup::iterate (void)
129 {
130         DE_ASSERT(DE_FALSE); // should never be here!
131         throw InternalError("TestCaseGroup::iterate() called!", "", __FILE__, __LINE__);
132 }
133
134 // TestCase
135
136 TestCase::TestCase (TestContext& testCtx, const char* name, const char* description)
137         : TestNode(testCtx, NODETYPE_SELF_VALIDATE, name, description)
138 {
139 }
140
141 TestCase::TestCase (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description)
142         : TestNode(testCtx, nodeType, name, description)
143 {
144         DE_ASSERT(isTestNodeTypeExecutable(nodeType));
145 }
146
147 TestCase::~TestCase (void)
148 {
149 }
150
151 } // tcu