1 #ifndef _TCUTESTCASE_HPP
2 #define _TCUTESTCASE_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
5 * ----------------------------------------
6 *
7 * Copyright 2014 The Android Open Source Project
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 *//*!
22 * \file
23 * \brief Base class for a test case.
24 *//*--------------------------------------------------------------------*/
25
26 #include "tcuDefs.hpp"
27 #include "tcuTestContext.hpp"
28
29 #include <string>
30 #include <vector>
31
32 namespace tcu
33 {
34
35 enum TestNodeType
36 {
37 NODETYPE_ROOT = 0, //!< Root for all test packages.
38 NODETYPE_PACKAGE, //!< Test case package -- same as group, but is omitted from XML dump.
39 NODETYPE_GROUP, //!< Test case container -- cannot be executed.
40 NODETYPE_SELF_VALIDATE, //!< Self-validating test case -- can be executed
41 NODETYPE_PERFORMANCE, //!< Performace test case -- can be executed
42 NODETYPE_CAPABILITY, //!< Capability score case -- can be executed
43 NODETYPE_ACCURACY //!< Accuracy test case -- can be executed
44 };
45
isTestNodeTypeExecutable(TestNodeType type)46 inline bool isTestNodeTypeExecutable (TestNodeType type)
47 {
48 return type == NODETYPE_SELF_VALIDATE ||
49 type == NODETYPE_PERFORMANCE ||
50 type == NODETYPE_CAPABILITY ||
51 type == NODETYPE_ACCURACY;
52 }
53
isValidTestCaseNameChar(char c)54 inline bool isValidTestCaseNameChar (char c)
55 {
56 return de::inRange(c, 'a', 'z') ||
57 de::inRange(c, 'A', 'Z') ||
58 de::inRange(c, '0', '9') ||
59 c == '_' || c == '-';
60 }
61
62 /*--------------------------------------------------------------------*//*!
63 * \brief Test case hierarchy node
64 *
65 * Test node forms the backbone of the test case hierarchy. All objects
66 * in the hierarchy are derived from this class.
67 *
68 * Each test node has a type and all except the root node have name and
69 * description. Root and test group nodes have a list of children.
70 *
71 * During test execution TestExecutor iterates the hierarchy. Upon entering
72 * the node (both groups and test cases) init() is called. When exiting the
73 * node deinit() is called respectively.
74 *//*--------------------------------------------------------------------*/
75 class TestNode
76 {
77 public:
78 enum IterateResult
79 {
80 STOP = 0,
81 CONTINUE = 1
82 };
83
84 // Methods.
85 TestNode (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description);
86 TestNode (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description, const std::vector<TestNode*>& children);
87 virtual ~TestNode (void);
88
getNodeType(void) const89 TestNodeType getNodeType (void) const { return m_nodeType; }
getTestContext(void) const90 TestContext& getTestContext (void) const { return m_testCtx; }
getName(void) const91 const char* getName (void) const { return m_name.c_str(); }
getDescription(void) const92 const char* getDescription (void) const { return m_description.c_str(); }
93 void getChildren (std::vector<TestNode*>& children) const;
94 void addChild (TestNode* node);
95
96 virtual void init (void);
97 virtual void deinit (void);
98 virtual IterateResult iterate (void) = 0;
99
100 protected:
101 TestContext& m_testCtx;
102 TestNodeType m_nodeType;
103 std::string m_name;
104 std::string m_description;
105
106 private:
107 std::vector<TestNode*> m_children;
108 };
109
110 /*--------------------------------------------------------------------*//*!
111 * \brief Test case group node
112 *
113 * Test case group implementations must inherit this class. To save resources
114 * during test execution the group must delay creation of any child groups
115 * until init() is called.
116 *
117 * Default deinit() for test group will destroy all child nodes.
118 *//*--------------------------------------------------------------------*/
119 class TestCaseGroup : public TestNode
120 {
121 public:
122 TestCaseGroup (TestContext& testCtx, const char* name, const char* description);
123 TestCaseGroup (TestContext& testCtx, const char* name, const char* description, const std::vector<TestNode*>& children);
124 virtual ~TestCaseGroup (void);
125
126 virtual IterateResult iterate (void);
127 };
128
129 /*--------------------------------------------------------------------*//*!
130 * \brief Test case class
131 *
132 * Test case implementations must inherit this class.
133 *
134 * Test case objects are usually constructed when TestExecutor enters parent
135 * group. Allocating any non-parameter resources, especially target API objects
136 * must be delayed to init().
137 *
138 * Upon entering the test case TestExecutor calls init(). If initialization
139 * is successful (no exception is thrown) the executor will then call iterate()
140 * until test case returns STOP. After that deinit() will be called.
141 *
142 * Before exiting the execution phase (i.e. at returning STOP from iterate())
143 * the test case must set valid status code to test context (m_testCtx).
144 *
145 * Test case can also signal error condition by throwing an exception. In
146 * that case the framework will set result code and details based on the
147 * exception.
148 *//*--------------------------------------------------------------------*/
149 class TestCase : public TestNode
150 {
151 public:
152 TestCase (TestContext& testCtx, const char* name, const char* description);
153 TestCase (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description);
154 virtual ~TestCase (void);
155 };
156
157 } // tcu
158
159 #endif // _TCUTESTCASE_HPP
160