1 #ifndef _XETESTCASE_HPP 2 #define _XETESTCASE_HPP 3 /*------------------------------------------------------------------------- 4 * drawElements Quality Program Test Executor 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 Test case. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "xeDefs.hpp" 27 28 #include <string> 29 #include <vector> 30 #include <set> 31 #include <map> 32 33 namespace xe 34 { 35 36 enum TestCaseType 37 { 38 TESTCASETYPE_SELF_VALIDATE, 39 TESTCASETYPE_CAPABILITY, 40 TESTCASETYPE_ACCURACY, 41 TESTCASETYPE_PERFORMANCE, 42 43 TESTCASETYPE_LAST 44 }; 45 46 const char *getTestCaseTypeName(TestCaseType caseType); 47 48 enum TestNodeType 49 { 50 TESTNODETYPE_ROOT, 51 TESTNODETYPE_GROUP, 52 TESTNODETYPE_TEST_CASE, 53 54 TESTNODETYPE_LAST 55 }; 56 57 class TestGroup; 58 class TestCase; 59 60 class TestNode 61 { 62 public: ~TestNode(void)63 virtual ~TestNode(void) 64 { 65 } 66 getNodeType(void) const67 TestNodeType getNodeType(void) const 68 { 69 return m_nodeType; 70 } getName(void) const71 const char *getName(void) const 72 { 73 return m_name.c_str(); 74 } getParent(void) const75 const TestGroup *getParent(void) const 76 { 77 return m_parent; 78 } 79 80 void getFullPath(std::string &path) const; getFullPath(void) const81 std::string getFullPath(void) const 82 { 83 std::string str; 84 getFullPath(str); 85 return str; 86 } 87 88 const TestNode *find(const char *path) const; 89 TestNode *find(const char *path); 90 91 protected: 92 TestNode(TestGroup *parent, TestNodeType nodeType, const char *name); 93 94 private: 95 TestNode(const TestNode &other); 96 TestNode &operator=(const TestNode &other); 97 98 TestGroup *m_parent; 99 TestNodeType m_nodeType; 100 std::string m_name; 101 std::string m_description; 102 }; 103 104 class TestGroup : public TestNode 105 { 106 public: 107 ~TestGroup(void); 108 getNumChildren(void) const109 int getNumChildren(void) const 110 { 111 return (int)m_children.size(); 112 } getChild(int ndx)113 TestNode *getChild(int ndx) 114 { 115 return m_children[ndx]; 116 } getChild(int ndx) const117 const TestNode *getChild(int ndx) const 118 { 119 return m_children[ndx]; 120 } 121 122 TestNode *findChildNode(const char *path); 123 const TestNode *findChildNode(const char *path) const; 124 125 TestGroup *createGroup(const char *name); 126 TestCase *createCase(TestCaseType caseType, const char *name); 127 128 protected: 129 TestGroup(TestGroup *parent, TestNodeType nodeType, const char *name); 130 131 private: 132 std::vector<TestNode *> m_children; 133 std::set<std::string> m_childNames; //!< Used for checking for duplicate test case names. 134 135 // For adding TestCase to m_children. \todo [2012-06-15 pyry] Is the API broken perhaps? 136 friend class TestNode; 137 }; 138 139 class TestRoot : public TestGroup 140 { 141 public: 142 TestRoot(void); 143 }; 144 145 class TestCase : public TestNode 146 { 147 public: 148 ~TestCase(void); 149 getCaseType(void) const150 TestCaseType getCaseType(void) const 151 { 152 return m_caseType; 153 } 154 155 static TestCase *createAsChild(TestGroup *parent, TestCaseType caseType, const char *name); 156 157 protected: 158 TestCase(TestGroup *parent, TestCaseType caseType, const char *name); 159 160 private: 161 TestCaseType m_caseType; 162 }; 163 164 // Helper class for efficiently constructing TestCase hierarchy from test case list. 165 class TestHierarchyBuilder 166 { 167 public: 168 TestHierarchyBuilder(TestRoot *root); 169 ~TestHierarchyBuilder(void); 170 171 TestCase *createCase(const char *path, TestCaseType caseType); 172 173 private: 174 TestHierarchyBuilder(const TestHierarchyBuilder &other); 175 TestHierarchyBuilder &operator=(const TestHierarchyBuilder &other); 176 177 TestRoot *m_root; 178 std::map<std::string, TestGroup *> m_groupMap; 179 }; 180 181 // Helper class for computing and iterating test sets. 182 class TestSet 183 { 184 public: TestSet(void)185 TestSet(void) 186 { 187 } ~TestSet(void)188 ~TestSet(void) 189 { 190 } 191 empty(void) const192 bool empty(void) const 193 { 194 return m_set.empty(); 195 } 196 197 void add(const TestNode *node); 198 void addCase(const TestCase *testCase); 199 void addGroup(const TestGroup *testGroup); 200 201 void remove(const TestNode *node); 202 void removeCase(const TestCase *testCase); 203 void removeGroup(const TestGroup *testGroup); 204 hasNode(const TestNode * node) const205 bool hasNode(const TestNode *node) const 206 { 207 return m_set.find(node) != m_set.end(); 208 } 209 210 private: 211 std::set<const TestNode *> m_set; 212 }; 213 214 class ConstTestNodeIterator 215 { 216 public: 217 static ConstTestNodeIterator begin(const TestNode *root); 218 static ConstTestNodeIterator end(const TestNode *root); 219 220 ConstTestNodeIterator &operator++(void); 221 ConstTestNodeIterator operator++(int); 222 223 const TestNode *operator*(void) const; 224 225 bool operator!=(const ConstTestNodeIterator &other) const; 226 227 protected: 228 ConstTestNodeIterator(const TestNode *root); 229 230 private: 231 struct GroupState 232 { GroupStatexe::ConstTestNodeIterator::GroupState233 GroupState(const TestGroup *group_) : group(group_), childNdx(0) 234 { 235 } 236 237 const TestGroup *group; 238 int childNdx; 239 operator !=xe::ConstTestNodeIterator::GroupState240 bool operator!=(const GroupState &other) const 241 { 242 return group != other.group || childNdx != other.childNdx; 243 } 244 operator ==xe::ConstTestNodeIterator::GroupState245 bool operator==(const GroupState &other) const 246 { 247 return group == other.group && childNdx == other.childNdx; 248 } 249 }; 250 251 const TestNode *m_root; 252 std::vector<GroupState> m_iterStack; 253 }; 254 255 // \todo [2012-06-19 pyry] Implement following iterators: 256 // - TestNodeIterator 257 // - ConstTestSetIterator 258 // - TestSetIterator 259 260 } // namespace xe 261 262 #endif // _XETESTCASE_HPP 263