lin
2025-08-14 dae8bad597b6607a449b32bf76c523423f7720ed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#ifndef _XETESTCASE_HPP
#define _XETESTCASE_HPP
/*-------------------------------------------------------------------------
 * drawElements Quality Program Test Executor
 * ------------------------------------------
 *
 * Copyright 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *//*!
 * \file
 * \brief Test case.
 *//*--------------------------------------------------------------------*/
 
#include "xeDefs.hpp"
 
#include <string>
#include <vector>
#include <set>
#include <map>
 
namespace xe
{
 
enum TestCaseType
{
   TESTCASETYPE_SELF_VALIDATE,
   TESTCASETYPE_CAPABILITY,
   TESTCASETYPE_ACCURACY,
   TESTCASETYPE_PERFORMANCE,
 
   TESTCASETYPE_LAST
};
 
const char* getTestCaseTypeName (TestCaseType caseType);
 
enum TestNodeType
{
   TESTNODETYPE_ROOT,
   TESTNODETYPE_GROUP,
   TESTNODETYPE_TEST_CASE,
 
   TESTNODETYPE_LAST
};
 
class TestGroup;
class TestCase;
 
class TestNode
{
public:
   virtual                ~TestNode            (void) {}
 
   TestNodeType        getNodeType            (void) const { return m_nodeType;        }
   const char*            getName                (void) const { return m_name.c_str();    }
   const TestGroup*    getParent            (void) const { return m_parent;            }
 
   void                getFullPath            (std::string& path) const;
   std::string            getFullPath            (void) const { std::string str; getFullPath(str); return str; }
 
   const TestNode*        find                (const char* path) const;
   TestNode*            find                (const char* path);
 
protected:
                       TestNode            (TestGroup* parent, TestNodeType nodeType, const char* name, const char* desc);
 
private:
                       TestNode            (const TestNode& other);
   TestNode&            operator=            (const TestNode& other);
 
   TestGroup*            m_parent;
   TestNodeType        m_nodeType;
   std::string            m_name;
   std::string            m_description;
};
 
class TestGroup : public TestNode
{
public:
                               ~TestGroup            (void);
 
   int                            getNumChildren        (void) const    { return (int)m_children.size();    }
   TestNode*                    getChild            (int ndx)        { return m_children[ndx];            }
   const TestNode*                getChild            (int ndx) const    { return m_children[ndx];            }
 
   TestNode*                    findChildNode        (const char* path);
   const TestNode*                findChildNode        (const char* path) const;
 
   TestGroup*                    createGroup            (const char* name, const char* description);
   TestCase*                    createCase            (TestCaseType caseType, const char* name, const char* description);
 
protected:
                               TestGroup            (TestGroup* parent, TestNodeType nodeType, const char* name, const char* description);
 
private:
   std::vector<TestNode*>        m_children;
   std::set<std::string>        m_childNames;        //!< Used for checking for duplicate test case names.
 
   // For adding TestCase to m_children. \todo [2012-06-15 pyry] Is the API broken perhaps?
   friend class TestNode;
};
 
class TestRoot : public TestGroup
{
public:
                               TestRoot            (void);
};
 
class TestCase : public TestNode
{
public:
                               ~TestCase            (void);
 
   TestCaseType                getCaseType            (void) const { return m_caseType; }
 
   static TestCase*            createAsChild        (TestGroup* parent, TestCaseType caseType, const char* name, const char* description);
 
protected:
                               TestCase            (TestGroup* parent, TestCaseType caseType, const char* name, const char* description);
 
private:
   TestCaseType                m_caseType;
};
 
// Helper class for efficiently constructing TestCase hierarchy from test case list.
class TestHierarchyBuilder
{
public:
                                       TestHierarchyBuilder        (TestRoot* root);
                                       ~TestHierarchyBuilder        (void);
 
   TestCase*                            createCase                    (const char* path, TestCaseType caseType);
 
private:
                                       TestHierarchyBuilder        (const TestHierarchyBuilder& other);
   TestHierarchyBuilder&                operator=                    (const TestHierarchyBuilder& other);
 
   TestRoot*                            m_root;
   std::map<std::string, TestGroup*>    m_groupMap;
};
 
// Helper class for computing and iterating test sets.
class TestSet
{
public:
                           TestSet            (void) {}
                           ~TestSet        (void) {}
 
   bool                    empty            (void) const { return m_set.empty(); }
 
   void                    add                (const TestNode* node);
   void                    addCase            (const TestCase* testCase);
   void                    addGroup        (const TestGroup* testGroup);
 
   void                    remove            (const TestNode* node);
   void                    removeCase        (const TestCase* testCase);
   void                    removeGroup        (const TestGroup* testGroup);
 
   bool                    hasNode            (const TestNode* node) const { return m_set.find(node) != m_set.end(); }
 
private:
   std::set<const TestNode*> m_set;
};
 
class ConstTestNodeIterator
{
public:
   static ConstTestNodeIterator    begin                    (const TestNode* root);
   static ConstTestNodeIterator    end                        (const TestNode* root);
 
   ConstTestNodeIterator&            operator++                (void);
   ConstTestNodeIterator            operator++                (int);
 
   const TestNode*                    operator*                (void) const;
 
   bool                            operator!=                (const ConstTestNodeIterator& other) const;
 
protected:
                                   ConstTestNodeIterator    (const TestNode* root);
 
private:
   struct GroupState
   {
       GroupState (const TestGroup* group_) : group(group_), childNdx(0) {}
 
       const TestGroup*    group;
       int                    childNdx;
 
       bool operator!= (const GroupState& other) const
       {
           return group != other.group || childNdx != other.childNdx;
       }
 
       bool operator== (const GroupState& other) const
       {
           return group == other.group && childNdx == other.childNdx;
       }
   };
 
   const TestNode*                    m_root;
   std::vector<GroupState>            m_iterStack;
};
 
// \todo [2012-06-19 pyry] Implement following iterators:
//  - TestNodeIterator
//  - ConstTestSetIterator
//  - TestSetIterator
 
} // xe
 
#endif // _XETESTCASE_HPP