Home | History | Annotate | Download | only in common
      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 
     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 
     54 /*--------------------------------------------------------------------*//*!
     55  * \brief Test case hierarchy node
     56  *
     57  * Test node forms the backbone of the test case hierarchy. All objects
     58  * in the hierarchy are derived from this class.
     59  *
     60  * Each test node has a type and all except the root node have name and
     61  * description. Root and test group nodes have a list of children.
     62  *
     63  * During test execution TestExecutor iterates the hierarchy. Upon entering
     64  * the node (both groups and test cases) init() is called. When exiting the
     65  * node deinit() is called respectively.
     66  *//*--------------------------------------------------------------------*/
     67 class TestNode
     68 {
     69 public:
     70 	enum IterateResult
     71 	{
     72 		STOP		= 0,
     73 		CONTINUE	= 1
     74 	};
     75 
     76 	// Methods.
     77 							TestNode		(TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description);
     78 							TestNode		(TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description, const std::vector<TestNode*>& children);
     79 	virtual					~TestNode		(void);
     80 
     81 	TestNodeType			getNodeType		(void) const	{ return m_nodeType;			}
     82 	TestContext&			getTestContext	(void) const	{ return m_testCtx;				}
     83 	const char*				getName			(void) const	{ return m_name.c_str();		}
     84 	const char*				getDescription	(void) const	{ return m_description.c_str(); }
     85 	void					getChildren		(std::vector<TestNode*>& children) const;
     86 	void					addChild		(TestNode* node);
     87 
     88 	virtual void			init			(void);
     89 	virtual void			deinit			(void);
     90 	virtual IterateResult	iterate			(void) = 0;
     91 
     92 protected:
     93 	TestContext&			m_testCtx;
     94 	TestNodeType			m_nodeType;
     95 	std::string				m_name;
     96 	std::string				m_description;
     97 
     98 private:
     99 	std::vector<TestNode*>	m_children;
    100 };
    101 
    102 /*--------------------------------------------------------------------*//*!
    103  * \brief Test case group node
    104  *
    105  * Test case group implementations must inherit this class. To save resources
    106  * during test execution the group must delay creation of any child groups
    107  * until init() is called.
    108  *
    109  * Default deinit() for test group will destroy all child nodes.
    110  *//*--------------------------------------------------------------------*/
    111 class TestCaseGroup : public TestNode
    112 {
    113 public:
    114 							TestCaseGroup	(TestContext& testCtx, const char* name, const char* description);
    115 							TestCaseGroup	(TestContext& testCtx, const char* name, const char* description, const std::vector<TestNode*>& children);
    116 	virtual					~TestCaseGroup	(void);
    117 
    118 	virtual IterateResult	iterate			(void);
    119 };
    120 
    121 /*--------------------------------------------------------------------*//*!
    122  * \brief Test case class
    123  *
    124  * Test case implementations must inherit this class.
    125  *
    126  * Test case objects are usually constructed when TestExecutor enters parent
    127  * group. Allocating any non-parameter resources, especially target API objects
    128  * must be delayed to init().
    129  *
    130  * Upon entering the test case TestExecutor calls init(). If initialization
    131  * is successful (no exception is thrown) the executor will then call iterate()
    132  * until test case returns STOP. After that deinit() will be called.
    133  *
    134  * Before exiting the execution phase (i.e. at returning STOP from iterate())
    135  * the test case must set valid status code to test context (m_testCtx).
    136  *
    137  * Test case can also signal error condition by throwing an exception. In
    138  * that case the framework will set result code and details based on the
    139  * exception.
    140  *//*--------------------------------------------------------------------*/
    141 class TestCase : public TestNode
    142 {
    143 public:
    144 					TestCase			(TestContext& testCtx, const char* name, const char* description);
    145 					TestCase			(TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description);
    146 	virtual			~TestCase			(void);
    147 };
    148 
    149 } // tcu
    150 
    151 #endif // _TCUTESTCASE_HPP
    152