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 "tcuTestCase.hpp"
25 #include "tcuPlatform.hpp"
36 inline bool isValidCaseName (const char* name)
38 for (const char* p = name; *p != '\0'; p++)
40 if (!isValidTestCaseNameChar(*p))
46 TestNode::TestNode (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description)
49 , m_description (description)
50 , m_nodeType (nodeType)
52 DE_ASSERT(isValidCaseName(name));
55 TestNode::TestNode (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description, const vector<TestNode*>& children)
58 , m_description (description)
59 , m_nodeType (nodeType)
61 DE_ASSERT(isValidCaseName(name));
62 for (int i = 0; i < (int)children.size(); i++)
63 addChild(children[i]);
66 TestNode::~TestNode (void)
71 void TestNode::getChildren (vector<TestNode*>& res)
74 for (int i = 0; i < (int)m_children.size(); i++)
75 res.push_back(m_children[i]);
78 void TestNode::addChild (TestNode* node)
80 // Child names must be unique!
81 // \todo [petri] O(n^2) algorithm, but shouldn't really matter..
83 for (int i = 0; i < (int)m_children.size(); i++)
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() + "'.");
90 // children only in group nodes
91 DE_ASSERT(getTestNodeTypeClass(m_nodeType) == NODECLASS_GROUP);
93 // children must have the same class
94 if (!m_children.empty())
95 DE_ASSERT(getTestNodeTypeClass(m_children.front()->getNodeType()) == getTestNodeTypeClass(node->getNodeType()));
97 m_children.push_back(node);
100 void TestNode::init (void)
104 void TestNode::deinit (void)
106 for (int i = 0; i < (int)m_children.size(); i++)
107 delete m_children[i];
113 TestCaseGroup::TestCaseGroup (TestContext& testCtx, const char* name, const char* description)
114 : TestNode(testCtx, NODETYPE_GROUP, name, description)
118 TestCaseGroup::TestCaseGroup (TestContext& testCtx, const char* name, const char* description, const vector<TestNode*>& children)
119 : TestNode(testCtx, NODETYPE_GROUP, name, description, children)
123 TestCaseGroup::~TestCaseGroup (void)
127 TestCase::IterateResult TestCaseGroup::iterate (void)
129 DE_ASSERT(DE_FALSE); // should never be here!
130 throw InternalError("TestCaseGroup::iterate() called!", "", __FILE__, __LINE__);
135 TestCase::TestCase (TestContext& testCtx, const char* name, const char* description)
136 : TestNode(testCtx, NODETYPE_SELF_VALIDATE, name, description)
140 TestCase::TestCase (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description)
141 : TestNode(testCtx, nodeType, name, description)
143 DE_ASSERT(isTestNodeTypeExecutable(nodeType));
146 TestCase::~TestCase (void)