1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
4 *
5 * Copyright 2014 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief Basic definitions.
22 *//*--------------------------------------------------------------------*/
23
24 #include "tcuDefs.hpp"
25 #include "deFilePath.hpp"
26 #include "qpDebugOut.h"
27
28 #include <sstream>
29 #include <stdarg.h>
30
31 namespace tcu
32 {
33
die(const char * format,...)34 void die (const char* format, ...)
35 {
36 va_list args;
37 va_start(args, format);
38 qpDiev(format, args);
39 va_end(args);
40 }
41
print(const char * format,...)42 void print (const char* format, ...)
43 {
44 va_list args;
45 va_start(args, format);
46 qpPrintv(format, args);
47 va_end(args);
48 }
49
formatError(const char * message,const char * expr,const char * file,int line)50 static std::string formatError (const char* message, const char* expr, const char* file, int line)
51 {
52 std::ostringstream msg;
53 msg << (message ? message : "Runtime check failed");
54
55 if (expr)
56 msg << ": '" << expr << '\'';
57
58 if (file)
59 msg << " at " << de::FilePath(file).getBaseName() << ":" << line;
60
61 return msg.str();
62 }
63
Exception(const char * message,const char * expr,const char * file,int line)64 Exception::Exception (const char* message, const char* expr, const char* file, int line)
65 : std::runtime_error(formatError(message, expr, file, line))
66 , m_message (message ? message : "Runtime check failed")
67 {
68 }
69
Exception(const std::string & message)70 Exception::Exception (const std::string& message)
71 : std::runtime_error(message)
72 , m_message (message)
73 {
74 }
75
TestException(const char * message,const char * expr,const char * file,int line,qpTestResult result)76 TestException::TestException (const char* message, const char* expr, const char* file, int line, qpTestResult result)
77 : Exception (formatError(message, expr, file, line))
78 , m_result (result)
79 {
80 }
81
TestException(const std::string & message,qpTestResult result)82 TestException::TestException (const std::string& message, qpTestResult result)
83 : Exception (message)
84 , m_result (result)
85 {
86 }
87
TestError(const char * message,const char * expr,const char * file,int line)88 TestError::TestError (const char* message, const char* expr, const char* file, int line)
89 : TestException(message, expr, file, line, QP_TEST_RESULT_FAIL)
90 {
91 }
92
TestError(const std::string & message)93 TestError::TestError (const std::string& message)
94 : TestException(message, QP_TEST_RESULT_FAIL)
95 {
96 }
97
InternalError(const char * message,const char * expr,const char * file,int line)98 InternalError::InternalError (const char* message, const char* expr, const char* file, int line)
99 : TestException(message, expr, file, line, QP_TEST_RESULT_INTERNAL_ERROR)
100 {
101 }
102
InternalError(const std::string & message)103 InternalError::InternalError (const std::string& message)
104 : TestException(message, QP_TEST_RESULT_INTERNAL_ERROR)
105 {
106 }
107
ResourceError(const char * message,const char * expr,const char * file,int line)108 ResourceError::ResourceError (const char* message, const char* expr, const char* file, int line)
109 : TestException(message, expr, file, line, QP_TEST_RESULT_RESOURCE_ERROR)
110 {
111 }
112
ResourceError(const std::string & message)113 ResourceError::ResourceError (const std::string& message)
114 : TestException(message, QP_TEST_RESULT_RESOURCE_ERROR)
115 {
116 }
117
NotSupportedError(const char * message,const char * expr,const char * file,int line)118 NotSupportedError::NotSupportedError (const char* message, const char* expr, const char* file, int line)
119 : TestException(message, expr, file, line, QP_TEST_RESULT_NOT_SUPPORTED)
120 {
121 }
122
NotSupportedError(const std::string & message)123 NotSupportedError::NotSupportedError (const std::string& message)
124 : TestException(message, QP_TEST_RESULT_NOT_SUPPORTED)
125 {
126 }
127
128 } // namespace tcu
129