1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program Tester Core
3*35238bceSAndroid Build Coastguard Worker * ----------------------------------------
4*35238bceSAndroid Build Coastguard Worker *
5*35238bceSAndroid Build Coastguard Worker * Copyright 2014 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker *
7*35238bceSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker *
11*35238bceSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker *
13*35238bceSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker *
19*35238bceSAndroid Build Coastguard Worker *//*!
20*35238bceSAndroid Build Coastguard Worker * \file
21*35238bceSAndroid Build Coastguard Worker * \brief Base class for a test case.
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker
24*35238bceSAndroid Build Coastguard Worker #include "tcuTestCase.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "tcuPlatform.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "tcuCommandLine.hpp"
27*35238bceSAndroid Build Coastguard Worker
28*35238bceSAndroid Build Coastguard Worker #include "deString.h"
29*35238bceSAndroid Build Coastguard Worker
30*35238bceSAndroid Build Coastguard Worker namespace tcu
31*35238bceSAndroid Build Coastguard Worker {
32*35238bceSAndroid Build Coastguard Worker
33*35238bceSAndroid Build Coastguard Worker using namespace std;
34*35238bceSAndroid Build Coastguard Worker
35*35238bceSAndroid Build Coastguard Worker // TestNode.
36*35238bceSAndroid Build Coastguard Worker
isValidCaseName(const char * name)37*35238bceSAndroid Build Coastguard Worker inline bool isValidCaseName(const char *name)
38*35238bceSAndroid Build Coastguard Worker {
39*35238bceSAndroid Build Coastguard Worker for (const char *p = name; *p != '\0'; p++)
40*35238bceSAndroid Build Coastguard Worker {
41*35238bceSAndroid Build Coastguard Worker if (!isValidTestCaseNameChar(*p))
42*35238bceSAndroid Build Coastguard Worker return false;
43*35238bceSAndroid Build Coastguard Worker }
44*35238bceSAndroid Build Coastguard Worker return true;
45*35238bceSAndroid Build Coastguard Worker }
46*35238bceSAndroid Build Coastguard Worker
TestNode(TestContext & testCtx,TestNodeType nodeType,const char * name)47*35238bceSAndroid Build Coastguard Worker TestNode::TestNode(TestContext &testCtx, TestNodeType nodeType, const char *name)
48*35238bceSAndroid Build Coastguard Worker : m_testCtx(testCtx)
49*35238bceSAndroid Build Coastguard Worker , m_name(name)
50*35238bceSAndroid Build Coastguard Worker , m_nodeType(nodeType)
51*35238bceSAndroid Build Coastguard Worker {
52*35238bceSAndroid Build Coastguard Worker DE_ASSERT(isValidCaseName(name));
53*35238bceSAndroid Build Coastguard Worker }
54*35238bceSAndroid Build Coastguard Worker
TestNode(TestContext & testCtx,TestNodeType nodeType,const char * name,const vector<TestNode * > & children)55*35238bceSAndroid Build Coastguard Worker TestNode::TestNode(TestContext &testCtx, TestNodeType nodeType, const char *name, const vector<TestNode *> &children)
56*35238bceSAndroid Build Coastguard Worker : m_testCtx(testCtx)
57*35238bceSAndroid Build Coastguard Worker , m_name(name)
58*35238bceSAndroid Build Coastguard Worker , m_nodeType(nodeType)
59*35238bceSAndroid Build Coastguard Worker {
60*35238bceSAndroid Build Coastguard Worker DE_ASSERT(isValidCaseName(name));
61*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)children.size(); i++)
62*35238bceSAndroid Build Coastguard Worker addChild(children[i]);
63*35238bceSAndroid Build Coastguard Worker }
64*35238bceSAndroid Build Coastguard Worker
~TestNode(void)65*35238bceSAndroid Build Coastguard Worker TestNode::~TestNode(void)
66*35238bceSAndroid Build Coastguard Worker {
67*35238bceSAndroid Build Coastguard Worker TestNode::deinit();
68*35238bceSAndroid Build Coastguard Worker }
69*35238bceSAndroid Build Coastguard Worker
getChildren(vector<TestNode * > & res) const70*35238bceSAndroid Build Coastguard Worker void TestNode::getChildren(vector<TestNode *> &res) const
71*35238bceSAndroid Build Coastguard Worker {
72*35238bceSAndroid Build Coastguard Worker res.clear();
73*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)m_children.size(); i++)
74*35238bceSAndroid Build Coastguard Worker res.push_back(m_children[i]);
75*35238bceSAndroid Build Coastguard Worker }
76*35238bceSAndroid Build Coastguard Worker
addRootChild(const std::string & groupName,const CaseListFilter * caseListFilter,TestCaseGroup * (* createTestGroup)(tcu::TestContext & testCtx,const std::string & name))77*35238bceSAndroid Build Coastguard Worker void TestNode::addRootChild(const std::string &groupName, const CaseListFilter *caseListFilter,
78*35238bceSAndroid Build Coastguard Worker TestCaseGroup *(*createTestGroup)(tcu::TestContext &testCtx, const std::string &name))
79*35238bceSAndroid Build Coastguard Worker {
80*35238bceSAndroid Build Coastguard Worker // Skip tests not in case list
81*35238bceSAndroid Build Coastguard Worker if (caseListFilter && !caseListFilter->checkTestGroupName((m_name + "." + groupName).c_str()))
82*35238bceSAndroid Build Coastguard Worker return;
83*35238bceSAndroid Build Coastguard Worker
84*35238bceSAndroid Build Coastguard Worker return addChild(createTestGroup(m_testCtx, groupName));
85*35238bceSAndroid Build Coastguard Worker }
86*35238bceSAndroid Build Coastguard Worker
addChild(TestNode * node)87*35238bceSAndroid Build Coastguard Worker void TestNode::addChild(TestNode *node)
88*35238bceSAndroid Build Coastguard Worker {
89*35238bceSAndroid Build Coastguard Worker // Child names must be unique!
90*35238bceSAndroid Build Coastguard Worker // \todo [petri] O(n^2) algorithm, but shouldn't really matter..
91*35238bceSAndroid Build Coastguard Worker #if defined(DE_DEBUG)
92*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)m_children.size(); i++)
93*35238bceSAndroid Build Coastguard Worker {
94*35238bceSAndroid Build Coastguard Worker if (deStringEqual(node->getName(), m_children[i]->getName()))
95*35238bceSAndroid Build Coastguard Worker throw tcu::InternalError(std::string("Test case with non-unique name '") + node->getName() +
96*35238bceSAndroid Build Coastguard Worker "' added to group '" + getName() + "'.");
97*35238bceSAndroid Build Coastguard Worker }
98*35238bceSAndroid Build Coastguard Worker #endif
99*35238bceSAndroid Build Coastguard Worker
100*35238bceSAndroid Build Coastguard Worker // children only in group nodes
101*35238bceSAndroid Build Coastguard Worker DE_ASSERT(getTestNodeTypeClass(m_nodeType) == NODECLASS_GROUP);
102*35238bceSAndroid Build Coastguard Worker
103*35238bceSAndroid Build Coastguard Worker // children must have the same class
104*35238bceSAndroid Build Coastguard Worker if (!m_children.empty())
105*35238bceSAndroid Build Coastguard Worker DE_ASSERT(getTestNodeTypeClass(m_children.front()->getNodeType()) == getTestNodeTypeClass(node->getNodeType()));
106*35238bceSAndroid Build Coastguard Worker
107*35238bceSAndroid Build Coastguard Worker m_children.push_back(node);
108*35238bceSAndroid Build Coastguard Worker }
109*35238bceSAndroid Build Coastguard Worker
init(void)110*35238bceSAndroid Build Coastguard Worker void TestNode::init(void)
111*35238bceSAndroid Build Coastguard Worker {
112*35238bceSAndroid Build Coastguard Worker }
113*35238bceSAndroid Build Coastguard Worker
deinit(void)114*35238bceSAndroid Build Coastguard Worker void TestNode::deinit(void)
115*35238bceSAndroid Build Coastguard Worker {
116*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)m_children.size(); i++)
117*35238bceSAndroid Build Coastguard Worker delete m_children[i];
118*35238bceSAndroid Build Coastguard Worker m_children.clear();
119*35238bceSAndroid Build Coastguard Worker }
120*35238bceSAndroid Build Coastguard Worker
121*35238bceSAndroid Build Coastguard Worker // TestCaseGroup
122*35238bceSAndroid Build Coastguard Worker
TestCaseGroup(TestContext & testCtx,const char * name)123*35238bceSAndroid Build Coastguard Worker TestCaseGroup::TestCaseGroup(TestContext &testCtx, const char *name) : TestNode(testCtx, NODETYPE_GROUP, name)
124*35238bceSAndroid Build Coastguard Worker {
125*35238bceSAndroid Build Coastguard Worker }
126*35238bceSAndroid Build Coastguard Worker
TestCaseGroup(TestContext & testCtx,const char * name,const vector<TestNode * > & children)127*35238bceSAndroid Build Coastguard Worker TestCaseGroup::TestCaseGroup(TestContext &testCtx, const char *name, const vector<TestNode *> &children)
128*35238bceSAndroid Build Coastguard Worker : TestNode(testCtx, NODETYPE_GROUP, name, children)
129*35238bceSAndroid Build Coastguard Worker {
130*35238bceSAndroid Build Coastguard Worker }
131*35238bceSAndroid Build Coastguard Worker
132*35238bceSAndroid Build Coastguard Worker // Deprecated constructor with an ignored description argument. These shouldn't really be used
133*35238bceSAndroid Build Coastguard Worker // in new code but are retained to avoid changing every test group construction at once.
TestCaseGroup(TestContext & testCtx,const char * name,const char * description)134*35238bceSAndroid Build Coastguard Worker TestCaseGroup::TestCaseGroup(TestContext &testCtx, const char *name, const char *description)
135*35238bceSAndroid Build Coastguard Worker : TestCaseGroup(testCtx, name)
136*35238bceSAndroid Build Coastguard Worker {
137*35238bceSAndroid Build Coastguard Worker DE_UNREF(description);
138*35238bceSAndroid Build Coastguard Worker }
139*35238bceSAndroid Build Coastguard Worker
TestCaseGroup(TestContext & testCtx,const char * name,const char * description,const vector<TestNode * > & children)140*35238bceSAndroid Build Coastguard Worker TestCaseGroup::TestCaseGroup(TestContext &testCtx, const char *name, const char *description,
141*35238bceSAndroid Build Coastguard Worker const vector<TestNode *> &children)
142*35238bceSAndroid Build Coastguard Worker : TestCaseGroup(testCtx, name, children)
143*35238bceSAndroid Build Coastguard Worker {
144*35238bceSAndroid Build Coastguard Worker DE_UNREF(description);
145*35238bceSAndroid Build Coastguard Worker }
146*35238bceSAndroid Build Coastguard Worker
~TestCaseGroup(void)147*35238bceSAndroid Build Coastguard Worker TestCaseGroup::~TestCaseGroup(void)
148*35238bceSAndroid Build Coastguard Worker {
149*35238bceSAndroid Build Coastguard Worker }
150*35238bceSAndroid Build Coastguard Worker
iterate(void)151*35238bceSAndroid Build Coastguard Worker TestCase::IterateResult TestCaseGroup::iterate(void)
152*35238bceSAndroid Build Coastguard Worker {
153*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false); // should never be here!
154*35238bceSAndroid Build Coastguard Worker throw InternalError("TestCaseGroup::iterate() called!", "", __FILE__, __LINE__);
155*35238bceSAndroid Build Coastguard Worker }
156*35238bceSAndroid Build Coastguard Worker
157*35238bceSAndroid Build Coastguard Worker // TestCase
158*35238bceSAndroid Build Coastguard Worker
TestCase(TestContext & testCtx,const char * name)159*35238bceSAndroid Build Coastguard Worker TestCase::TestCase(TestContext &testCtx, const char *name) : TestNode(testCtx, NODETYPE_SELF_VALIDATE, name)
160*35238bceSAndroid Build Coastguard Worker {
161*35238bceSAndroid Build Coastguard Worker }
162*35238bceSAndroid Build Coastguard Worker
TestCase(TestContext & testCtx,TestNodeType nodeType,const char * name)163*35238bceSAndroid Build Coastguard Worker TestCase::TestCase(TestContext &testCtx, TestNodeType nodeType, const char *name) : TestNode(testCtx, nodeType, name)
164*35238bceSAndroid Build Coastguard Worker {
165*35238bceSAndroid Build Coastguard Worker DE_ASSERT(isTestNodeTypeExecutable(nodeType));
166*35238bceSAndroid Build Coastguard Worker }
167*35238bceSAndroid Build Coastguard Worker
168*35238bceSAndroid Build Coastguard Worker // Deprecated constructor with an ignored description argument. These shouldn't really be used
169*35238bceSAndroid Build Coastguard Worker // in new code but are retained to avoid changing every test case construction at once.
TestCase(TestContext & testCtx,const char * name,const char * description)170*35238bceSAndroid Build Coastguard Worker TestCase::TestCase(TestContext &testCtx, const char *name, const char *description) : TestCase(testCtx, name)
171*35238bceSAndroid Build Coastguard Worker {
172*35238bceSAndroid Build Coastguard Worker DE_UNREF(description);
173*35238bceSAndroid Build Coastguard Worker }
174*35238bceSAndroid Build Coastguard Worker
TestCase(TestContext & testCtx,TestNodeType nodeType,const char * name,const char * description)175*35238bceSAndroid Build Coastguard Worker TestCase::TestCase(TestContext &testCtx, TestNodeType nodeType, const char *name, const char *description)
176*35238bceSAndroid Build Coastguard Worker : TestCase(testCtx, nodeType, name)
177*35238bceSAndroid Build Coastguard Worker {
178*35238bceSAndroid Build Coastguard Worker DE_UNREF(description);
179*35238bceSAndroid Build Coastguard Worker }
180*35238bceSAndroid Build Coastguard Worker
~TestCase(void)181*35238bceSAndroid Build Coastguard Worker TestCase::~TestCase(void)
182*35238bceSAndroid Build Coastguard Worker {
183*35238bceSAndroid Build Coastguard Worker }
184*35238bceSAndroid Build Coastguard Worker
185*35238bceSAndroid Build Coastguard Worker } // namespace tcu
186