3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
5 * ----------------------------------------
7 * Copyright 2014 The Android Open Source Project
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * \brief Basic definitions.
24 *//*--------------------------------------------------------------------*/
27 #include "qpTestLog.h"
32 /*--------------------------------------------------------------------*//*!
33 * \brief dEQP Common Test Framework
35 * Code in this namespace doesn't require support for any specific client
37 *//*--------------------------------------------------------------------*/
41 //! Kill program. Called when a fatal error occurs.
42 void die (const char* format, ...) DE_PRINTF_FUNC_ATTR(1, 2);
44 //! Print to debug console.
45 void print (const char* format, ...) DE_PRINTF_FUNC_ATTR(1, 2);
47 //! Print nonfatal error.
48 void printError (const char* format, ...) DE_PRINTF_FUNC_ATTR(1, 2);
50 //! Base exception class for dEQP test framework.
51 class Exception : public std::runtime_error
54 Exception (const char* message, const char* expr, const char* file, int line);
55 Exception (const std::string& message);
56 virtual ~Exception (void) throw() {}
58 const char* getMessage (void) const { return m_message.what(); }
61 // std::runtime_error is used here as an immutable ref-counted string.
62 // This allows the copy constructor in the class to be noexcept.
63 const std::runtime_error m_message;
66 //! Base exception class for test exceptions that affect test result
67 class TestException : public Exception
70 TestException (const char* message, const char* expr, const char* file, int line, qpTestResult result);
71 TestException (const std::string& message, qpTestResult result);
72 virtual ~TestException (void) throw() {}
74 qpTestResult getTestResult (void) const { return m_result; }
75 virtual bool isFatal (void) const { return false; }
78 const qpTestResult m_result;
81 //! Exception for test errors.
82 class TestError : public TestException
85 TestError (const char* message, const char* expr, const char* file, int line);
86 TestError (const std::string& message, const char* expr, const char* file, int line);
87 TestError (const std::string& message);
88 virtual ~TestError (void) throw() {}
91 //! Exception for internal errors.
92 class InternalError : public TestException
95 InternalError (const char* message, const char* expr, const char* file, int line);
96 InternalError (const std::string& message, const char* expr, const char* file, int line);
97 InternalError (const std::string& message);
98 virtual ~InternalError (void) throw() {}
101 //! Resource error. Tester will terminate if thrown out of test case.
102 class ResourceError : public TestException
105 ResourceError (const char* message, const char* expr, const char* file, int line);
106 ResourceError (const std::string& message);
107 virtual ~ResourceError (void) throw() {}
109 virtual bool isFatal (void) const { return true; }
112 //! Not supported error.
113 class NotSupportedError : public TestException
116 NotSupportedError (const char* message, const char* expr, const char* file, int line);
117 NotSupportedError (const std::string& message, const char* expr, const char* file, int line);
118 NotSupportedError (const std::string& message);
119 virtual ~NotSupportedError (void) throw() {}
124 #define TCU_THROW_EXPR(ERRCLASS, MSG, EXPR) \
125 throw tcu::ERRCLASS(MSG, EXPR, __FILE__, __LINE__)
127 #define TCU_THROW(ERRCLASS, MSG) \
128 TCU_THROW_EXPR(ERRCLASS, MSG, DE_NULL)
130 #define TCU_CHECK_AND_THROW(ERRCLASS, X, MSG) \
132 if (!(!deGetFalse() && (X))) \
133 TCU_THROW_EXPR(ERRCLASS, MSG, #X); \
134 } while(deGetFalse())
137 #define TCU_FAIL(MSG) TCU_THROW(TestError, MSG)
139 //! Throw TestError if condition X is not satisfied.
140 #define TCU_CHECK(X) do { if (!(!deGetFalse() && (X))) throw tcu::TestError(DE_NULL, #X, __FILE__, __LINE__); } while(deGetFalse())
142 //! Throw TestError if condition X is not satisfied.
143 #define TCU_CHECK_MSG(X, MSG) do { if (!(!deGetFalse() && (X))) throw tcu::TestError((MSG), #X, __FILE__, __LINE__); } while(deGetFalse())
145 //! Throw InternalError if condition X is not satisfied
146 #define TCU_CHECK_INTERNAL(X) do { if (!(!deGetFalse() && (X))) throw tcu::InternalError(DE_NULL, #X, __FILE__, __LINE__); } while(deGetFalse())
148 #endif // _TCUDEFS_HPP