Home | History | Annotate | Download | only in common
      1 #ifndef _TCUDEFS_HPP
      2 #define _TCUDEFS_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 Basic definitions.
     24  *//*--------------------------------------------------------------------*/
     25 
     26 #include "deDefs.hpp"
     27 #include "qpTestLog.h"
     28 
     29 #include <string>
     30 #include <stdexcept>
     31 
     32 /*--------------------------------------------------------------------*//*!
     33  * \brief dEQP Common Test Framework
     34  *
     35  * Code in this namespace doesn't require support for any specific client
     36  * APIs.
     37  *//*--------------------------------------------------------------------*/
     38 namespace tcu
     39 {
     40 
     41 //! Kill program. Called when a fatal error occurs.
     42 void	die		(const char* format, ...) DE_PRINTF_FUNC_ATTR(1, 2);
     43 
     44 //! Print to debug console.
     45 void	print	(const char* format, ...) DE_PRINTF_FUNC_ATTR(1, 2);
     46 
     47 //! Base exception class for dEQP test framework.
     48 class Exception : public std::runtime_error
     49 {
     50 public:
     51 						Exception			(const char* message, const char* expr, const char* file, int line);
     52 						Exception			(const std::string& message);
     53 	virtual				~Exception			(void) throw() {}
     54 
     55 	const char*			getMessage			(void) const { return m_message.c_str(); }
     56 
     57 private:
     58 	const std::string	m_message;
     59 };
     60 
     61 //! Base exception class for test exceptions that affect test result
     62 class TestException : public Exception
     63 {
     64 public:
     65 						TestException		(const char* message, const char* expr, const char* file, int line, qpTestResult result);
     66 						TestException		(const std::string& message, qpTestResult result);
     67 	virtual				~TestException		(void) throw() {}
     68 
     69 	qpTestResult		getTestResult		(void) const { return m_result; }
     70 	virtual bool		isFatal				(void) const { return false; }
     71 
     72 private:
     73 	const qpTestResult	m_result;
     74 };
     75 
     76 //! Exception for test errors.
     77 class TestError : public TestException
     78 {
     79 public:
     80 					TestError			(const char* message, const char* expr, const char* file, int line);
     81 					TestError			(const std::string& message, const char* expr, const char* file, int line);
     82 					TestError			(const std::string& message);
     83 	virtual			~TestError			(void) throw() {}
     84 };
     85 
     86 //! Exception for internal errors.
     87 class InternalError : public TestException
     88 {
     89 public:
     90 					InternalError		(const char* message, const char* expr, const char* file, int line);
     91 					InternalError		(const std::string& message);
     92 	virtual			~InternalError		(void) throw() {}
     93 };
     94 
     95 //! Resource error. Tester will terminate if thrown out of test case.
     96 class ResourceError : public TestException
     97 {
     98 public:
     99 					ResourceError		(const char* message, const char* expr, const char* file, int line);
    100 					ResourceError		(const std::string& message);
    101 	virtual			~ResourceError		(void) throw() {}
    102 
    103 	virtual bool	isFatal				(void) const { return true; }
    104 };
    105 
    106 //! Not supported error.
    107 class NotSupportedError : public TestException
    108 {
    109 public:
    110 					NotSupportedError	(const char* message, const char* expr, const char* file, int line);
    111 					NotSupportedError	(const std::string& message);
    112 	virtual			~NotSupportedError	(void) throw() {}
    113 };
    114 
    115 } // tcu
    116 
    117 #define TCU_THROW_EXPR(ERRCLASS, MSG, EXPR)						\
    118 			throw tcu::ERRCLASS(MSG, EXPR, __FILE__, __LINE__)
    119 
    120 #define TCU_THROW(ERRCLASS, MSG)								\
    121 			TCU_THROW_EXPR(ERRCLASS, MSG, DE_NULL)
    122 
    123 #define TCU_CHECK_AND_THROW(ERRCLASS, X, MSG)					\
    124 	do {														\
    125 		if (!(!deGetFalse() && (X)))							\
    126 			TCU_THROW_EXPR(ERRCLASS, MSG, #X);					\
    127 	} while(deGetFalse())
    128 
    129 //! Throw TestError.
    130 #define TCU_FAIL(MSG)				TCU_THROW(TestError, MSG)
    131 
    132 //! Throw TestError if condition X is not satisfied.
    133 #define TCU_CHECK(X)			do { if (!(!deGetFalse() && (X))) throw tcu::TestError(DE_NULL, #X, __FILE__, __LINE__); } while(deGetFalse())
    134 
    135 //! Throw TestError if condition X is not satisfied.
    136 #define TCU_CHECK_MSG(X, MSG)	do { if (!(!deGetFalse() && (X))) throw tcu::TestError((MSG), #X, __FILE__, __LINE__); } while(deGetFalse())
    137 
    138 //! Throw InternalError if condition X is not satisfied
    139 #define	TCU_CHECK_INTERNAL(X)	do { if (!(!deGetFalse() && (X))) throw tcu::InternalError(DE_NULL, #X, __FILE__, __LINE__); } while(deGetFalse())
    140 
    141 #endif // _TCUDEFS_HPP
    142