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