1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Test Executor
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 Test case list parser.
22 *//*--------------------------------------------------------------------*/
24 #include "xeTestCaseListParser.hpp"
33 static TestCaseType getTestCaseType (const char* caseType)
35 // \todo [2012-06-11 pyry] Use hashes for speedup.
39 TestCaseType caseType;
42 { "SelfValidate", TESTCASETYPE_SELF_VALIDATE },
43 { "Capability", TESTCASETYPE_CAPABILITY },
44 { "Accuracy", TESTCASETYPE_ACCURACY },
45 { "Performance", TESTCASETYPE_PERFORMANCE }
48 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_caseTypeMap); ndx++)
50 if (deStringEqual(caseType, s_caseTypeMap[ndx].name))
51 return s_caseTypeMap[ndx].caseType;
54 XE_FAIL((string("Unknown test case type '") + caseType + "'").c_str());
57 TestCaseListParser::TestCaseListParser (void)
62 TestCaseListParser::~TestCaseListParser (void)
66 void TestCaseListParser::clear (void)
73 void TestCaseListParser::init (TestGroup* rootGroup)
79 void TestCaseListParser::parse (const deUint8* bytes, int numBytes)
82 m_xmlParser.feed(bytes, numBytes);
86 xml::Element element = m_xmlParser.getElement();
88 if (element == xml::ELEMENT_INCOMPLETE ||
89 element == xml::ELEMENT_END_OF_STRING)
92 if (element == xml::ELEMENT_START || element == xml::ELEMENT_END)
94 bool isStart = element == xml::ELEMENT_START;
95 const char* elemName = m_xmlParser.getElementName();
97 if (deStringEqual(elemName, "TestCase"))
101 XE_CHECK_MSG(!m_nodeStack.empty(), "<TestCase> outside of <TestCaseList>");
103 TestNode* parent = m_nodeStack.back();
104 const char* name = m_xmlParser.hasAttribute("Name") ? m_xmlParser.getAttribute("Name") : DE_NULL;
105 const char* description = m_xmlParser.hasAttribute("Description") ? m_xmlParser.getAttribute("Description") : DE_NULL;
106 const char* caseType = m_xmlParser.hasAttribute("CaseType") ? m_xmlParser.getAttribute("CaseType") : DE_NULL;
108 XE_CHECK_MSG(name && description && caseType, "Missing attribute in <TestCase>");
109 XE_CHECK_MSG(parent->getNodeType() == TESTNODETYPE_GROUP, "Only TestGroups are allowed to have child nodes");
111 bool isGroup = deStringEqual(caseType, "TestGroup") == DE_TRUE;
112 TestNode* node = isGroup ? static_cast<TestNode*>(static_cast<TestGroup*>(parent)->createGroup(name, description))
113 : static_cast<TestNode*>(static_cast<TestGroup*>(parent)->createCase(getTestCaseType(caseType), name, description));
115 m_nodeStack.push_back(node);
119 XE_CHECK_MSG(m_nodeStack.size() >= 2, "Unexpected </TestCase>");
120 m_nodeStack.pop_back();
123 else if (deStringEqual(elemName, "TestCaseList"))
127 XE_CHECK_MSG(m_nodeStack.empty(), "Unexpected <TestCaseList>");
128 m_nodeStack.push_back(m_root);
132 XE_CHECK_MSG(m_nodeStack.size() == 1, "Unexpected </TestCaseList>");
133 m_nodeStack.pop_back();
137 XE_FAIL((string("Unexpected <") + elemName + ">").c_str());
139 else if (element != xml::ELEMENT_DATA)
140 DE_ASSERT(false); // \note Data elements are just ignored, they should be whitespace anyway.
142 m_xmlParser.advance();