1cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com#ifndef _TCUTESTCONTEXT_HPP
2cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com#define _TCUTESTCONTEXT_HPP
3cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com/*-------------------------------------------------------------------------
4cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com * drawElements Quality Program Tester Core
5cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com * ----------------------------------------
6cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com *
7cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com * Copyright 2014 The Android Open Source Project
8cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com *
9cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com * Licensed under the Apache License, Version 2.0 (the "License");
108cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * you may not use this file except in compliance with the License.
118cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * You may obtain a copy of the License at
128cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com *
138cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com *      http://www.apache.org/licenses/LICENSE-2.0
148cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com *
158cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * Unless required by applicable law or agreed to in writing, software
168cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * distributed under the License is distributed on an "AS IS" BASIS,
178cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
188cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * See the License for the specific language governing permissions and
198cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * limitations under the License.
208cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com *
218cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com *//*!
228cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * \file
238cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * \brief Context shared between test cases.
248cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com *//*--------------------------------------------------------------------*/
258cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
268cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "tcuDefs.hpp"
278cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "qpWatchDog.h"
288cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "qpTestLog.h"
298cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
308cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include <string>
318cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
328cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comnamespace tcu
338cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com{
348cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
358cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass Archive;
368cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass Platform;
378cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass CommandLine;
388cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass TestLog;
398cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
408cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com/*--------------------------------------------------------------------*//*!
418cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * \brief Test context
428cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com *
438cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * Test context holds common resources that are available to test cases.
448cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * This includes test log and resource archive.
458cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com *
468cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * Test case can write to test log and must set test result to test context.
478cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com *//*--------------------------------------------------------------------*/
488cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass TestContext
498cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com{
508cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.compublic:
518cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com							TestContext			(Platform& platform, Archive& rootArchive, TestLog& log, const CommandLine& cmdLine, qpWatchDog* watchDog);
528cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com							~TestContext		(void) {}
538cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
548cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	// API for test cases
558cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	TestLog&				getLog				(void)			{ return m_log;			}
568cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	Archive&				getArchive			(void)			{ return *m_curArchive;	} //!< \note Do not access in TestNode constructors.
578cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	Platform&				getPlatform			(void)			{ return m_platform;	}
588cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	void					setTestResult		(qpTestResult result, const char* description);
598cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	void					touchWatchdog		(void);
608cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	const CommandLine&		getCommandLine		(void) const	{ return m_cmdLine;		}
618cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
628cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	// API for test framework
638cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	qpTestResult			getTestResult		(void) const	{ return m_testResult;				}
648cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	const char*				getTestResultDesc	(void) const	{ return m_testResultDesc.c_str();	}
658cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	qpWatchDog*				getWatchDog			(void)			{ return m_watchDog;				}
668cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
678cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	Archive&				getRootArchive		(void) const		{ return m_rootArchive;		}
688cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	void					setCurrentArchive	(Archive& archive)	{ m_curArchive = &archive;	}
698cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
708cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	void					setTerminateAfter	(bool terminate)	{ m_terminateAfter = terminate;	}
718cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	bool					getTerminateAfter	(void) const		{ return m_terminateAfter; 		}
728cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comprotected:
738cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	Platform&				m_platform;			//!< Platform port implementation.
748cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	Archive&				m_rootArchive;		//!< Root archive.
758cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	TestLog&				m_log;				//!< Test log.
768cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	const CommandLine&		m_cmdLine;			//!< Command line.
778cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	qpWatchDog*				m_watchDog;			//!< Watchdog (can be null).
788cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
798cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	Archive*				m_curArchive;		//!< Current archive for test cases.
808cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	qpTestResult			m_testResult;		//!< Latest test result.
818cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	std::string				m_testResultDesc;	//!< Latest test result description.
828cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	bool					m_terminateAfter;	//!< Should tester terminate after execution of the current test
838cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com};
848cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
858cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com/*--------------------------------------------------------------------*//*!
868cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * \brief Test result collector
878cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com *
888cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * This utility class collects test results with associated messages,
898cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * optionally logs them, and finally sets the test result of a TestContext to
908cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * the most severe collected result. This allows multiple problems to be
918cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * easily reported from a single test run.
928cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com *//*--------------------------------------------------------------------*/
938cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass ResultCollector
948cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com{
958cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.compublic:
968cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com					ResultCollector			(void);
978cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com					ResultCollector			(TestLog& log, const std::string& prefix = "");
988cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
998cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	qpTestResult	getResult				(void) const  { return m_result; }
1008cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1018cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	void			fail					(const std::string& msg);
1028cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	bool			check					(bool condition, const std::string& msg);
1038cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1048cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	void			addResult				(qpTestResult result, const std::string& msg);
1058cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	bool			checkResult				(bool condition, qpTestResult result, const std::string& msg);
1068cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1078cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	void			setTestContextResult	(TestContext& testCtx);
1088cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1098cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comprivate:
1108cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	TestLog*		m_log;
1118cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	std::string		m_prefix;
1128cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	qpTestResult	m_result;
1138cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com	std::string		m_message;
1148cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com};
1158cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1168cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com} // tcu
1178cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1188cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#endif // _TCUTESTCONTEXT_HPP
1198cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com