am e8ffce34: Make r10c toolchain compile flags more Android-ish automerge: fed851d
[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 isValidCaseName (const char* name)
37 {
38         for (const char* p = name; *p != '\0'; p++)
39         {
40                 if (!isValidTestCaseNameChar(*p))
41                         return false;
42         }
43         return true;
44 }
45
46 TestNode::TestNode (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description)
47         : m_testCtx             (testCtx)
48         , m_nodeType    (nodeType)
49         , m_name                (name)
50         , m_description (description)
51 {
52         DE_ASSERT(isValidCaseName(name));
53 }
54
55 TestNode::TestNode (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description, const vector<TestNode*>& children)
56         : m_testCtx             (testCtx)
57         , m_nodeType    (nodeType)
58         , m_name                (name)
59         , m_description (description)
60 {
61         DE_ASSERT(isValidCaseName(name));
62         for (int i = 0; i < (int)children.size(); i++)
63                 addChild(children[i]);
64 }
65
66 TestNode::~TestNode (void)
67 {
68         TestNode::deinit();
69 }
70
71 void TestNode::getChildren (vector<TestNode*>& res) const
72 {
73         res.clear();
74         for (int i = 0; i < (int)m_children.size(); i++)
75                 res.push_back(m_children[i]);
76 }
77
78 void TestNode::addChild (TestNode* node)
79 {
80         // Child names must be unique!
81         // \todo [petri] O(n^2) algorithm, but shouldn't really matter..
82 #if defined(DE_DEBUG)
83         for (int i = 0; i < (int)m_children.size(); i++)
84         {
85                 if (deStringEqual(node->getName(), m_children[i]->getName()))
86                         throw tcu::InternalError(std::string("Test case with non-unique name '") + node->getName() + "' added to group '" + getName() + "'.");
87         }
88 #endif
89
90         m_children.push_back(node);
91 }
92
93 void TestNode::init (void)
94 {
95 }
96
97 void TestNode::deinit (void)
98 {
99         for (int i = 0; i < (int)m_children.size(); i++)
100                 delete m_children[i];
101         m_children.clear();
102 }
103
104 // TestCaseGroup
105
106 TestCaseGroup::TestCaseGroup (TestContext& testCtx, const char* name, const char* description)
107         : TestNode(testCtx, NODETYPE_GROUP, name, description)
108 {
109 }
110
111 TestCaseGroup::TestCaseGroup (TestContext& testCtx, const char* name, const char* description, const vector<TestNode*>& children)
112         : TestNode(testCtx, NODETYPE_GROUP, name, description, children)
113 {
114 }
115
116 TestCaseGroup::~TestCaseGroup (void)
117 {
118 }
119
120 TestCase::IterateResult TestCaseGroup::iterate (void)
121 {
122         DE_ASSERT(DE_FALSE); // should never be here!
123         throw InternalError("TestCaseGroup::iterate() called!", "", __FILE__, __LINE__);
124 }
125
126 // TestCase
127
128 TestCase::TestCase (TestContext& testCtx, const char* name, const char* description)
129         : TestNode(testCtx, NODETYPE_SELF_VALIDATE, name, description)
130 {
131 }
132
133 TestCase::TestCase (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description)
134         : TestNode(testCtx, nodeType, name, description)
135 {
136         DE_ASSERT(isTestNodeTypeExecutable(nodeType));
137 }
138
139 TestCase::~TestCase (void)
140 {
141 }
142
143 } // tcu