13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _TCUTESTCASE_HPP 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _TCUTESTCASE_HPP 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Tester Core 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ---------------------------------------- 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Base class for a test case. 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuDefs.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestContext.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string> 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector> 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace tcu 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum TestNodeType 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry NODETYPE_ROOT = 0, //!< Root for all test packages. 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry NODETYPE_PACKAGE, //!< Test case package -- same as group, but is omitted from XML dump. 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry NODETYPE_GROUP, //!< Test case container -- cannot be executed. 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry NODETYPE_SELF_VALIDATE, //!< Self-validating test case -- can be executed 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry NODETYPE_PERFORMANCE, //!< Performace test case -- can be executed 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry NODETYPE_CAPABILITY, //!< Capability score case -- can be executed 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry NODETYPE_ACCURACY //!< Accuracy test case -- can be executed 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline bool isTestNodeTypeExecutable (TestNodeType type) 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return type == NODETYPE_SELF_VALIDATE || 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry type == NODETYPE_PERFORMANCE || 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry type == NODETYPE_CAPABILITY || 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry type == NODETYPE_ACCURACY; 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5489659d2685195bf9e34ff7a2e321e6ce471c8462Pyry Haulosinline bool isValidTestCaseNameChar (char c) 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return de::inRange(c, 'a', 'z') || 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::inRange(c, 'A', 'Z') || 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::inRange(c, '0', '9') || 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry c == '_' || c == '-'; 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Test case hierarchy node 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Test node forms the backbone of the test case hierarchy. All objects 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * in the hierarchy are derived from this class. 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Each test node has a type and all except the root node have name and 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * description. Root and test group nodes have a list of children. 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * During test execution TestExecutor iterates the hierarchy. Upon entering 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * the node (both groups and test cases) init() is called. When exiting the 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * node deinit() is called respectively. 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TestNode 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum IterateResult 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STOP = 0, 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CONTINUE = 1 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Methods. 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestNode (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description); 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestNode (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description, const std::vector<TestNode*>& children); 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~TestNode (void); 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestNodeType getNodeType (void) const { return m_nodeType; } 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestContext& getTestContext (void) const { return m_testCtx; } 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* getName (void) const { return m_name.c_str(); } 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* getDescription (void) const { return m_description.c_str(); } 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void getChildren (std::vector<TestNode*>& children) const; 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void addChild (TestNode* node); 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual void init (void); 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual void deinit (void); 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual IterateResult iterate (void) = 0; 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected: 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestContext& m_testCtx; 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestNodeType m_nodeType; 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string m_name; 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string m_description; 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<TestNode*> m_children; 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Test case group node 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Test case group implementations must inherit this class. To save resources 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * during test execution the group must delay creation of any child groups 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * until init() is called. 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Default deinit() for test group will destroy all child nodes. 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TestCaseGroup : public TestNode 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestCaseGroup (TestContext& testCtx, const char* name, const char* description); 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestCaseGroup (TestContext& testCtx, const char* name, const char* description, const std::vector<TestNode*>& children); 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~TestCaseGroup (void); 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual IterateResult iterate (void); 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Test case class 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Test case implementations must inherit this class. 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Test case objects are usually constructed when TestExecutor enters parent 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * group. Allocating any non-parameter resources, especially target API objects 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * must be delayed to init(). 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Upon entering the test case TestExecutor calls init(). If initialization 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * is successful (no exception is thrown) the executor will then call iterate() 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * until test case returns STOP. After that deinit() will be called. 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Before exiting the execution phase (i.e. at returning STOP from iterate()) 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * the test case must set valid status code to test context (m_testCtx). 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Test case can also signal error condition by throwing an exception. In 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * that case the framework will set result code and details based on the 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * exception. 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TestCase : public TestNode 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestCase (TestContext& testCtx, const char* name, const char* description); 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestCase (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description); 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~TestCase (void); 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // tcu 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _TCUTESTCASE_HPP 160