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
printError(const char * format,...)50 void printError(const char *format, ...)
51 {
52 va_list args;
53 va_start(args, format);
54 qpPrintErrorv(format, args);
55 va_end(args);
56 }
57
formatError(const char * message,const char * expr,const char * file,int line)58 static std::string formatError(const char *message, const char *expr, const char *file, int line)
59 {
60 std::ostringstream msg;
61 msg << (message ? message : "Runtime check failed");
62
63 if (expr)
64 msg << ": '" << expr << '\'';
65
66 if (file)
67 msg << " at " << de::FilePath(file).getBaseName() << ":" << line;
68
69 return msg.str();
70 }
71
Exception(const char * message,const char * expr,const char * file,int line)72 Exception::Exception(const char *message, const char *expr, const char *file, int line)
73 : std::runtime_error(formatError(message, expr, file, line))
74 , m_message(message ? message : "Runtime check failed")
75 {
76 }
77
Exception(const std::string & message)78 Exception::Exception(const std::string &message) : std::runtime_error(message), m_message(message)
79 {
80 }
81
TestException(const char * message,const char * expr,const char * file,int line,qpTestResult result)82 TestException::TestException(const char *message, const char *expr, const char *file, int line, qpTestResult result)
83 : Exception(formatError(message, expr, file, line))
84 , m_result(result)
85 {
86 }
87
TestException(const std::string & message,qpTestResult result)88 TestException::TestException(const std::string &message, qpTestResult result) : Exception(message), m_result(result)
89 {
90 }
91
TestError(const char * message,const char * expr,const char * file,int line,qpTestResult result)92 TestError::TestError(const char *message, const char *expr, const char *file, int line, qpTestResult result)
93 : TestException(message, expr, file, line, result)
94 {
95 }
96
TestError(const char * message,const char * expr,const char * file,int line)97 TestError::TestError(const char *message, const char *expr, const char *file, int line)
98 : TestException(message, expr, file, line, QP_TEST_RESULT_FAIL)
99 {
100 }
TestError(const std::string & message,const char * expr,const char * file,int line)101 TestError::TestError(const std::string &message, const char *expr, const char *file, int line)
102 : TestException(message.c_str(), expr, file, line, QP_TEST_RESULT_FAIL)
103 {
104 }
105
TestError(const std::string & message)106 TestError::TestError(const std::string &message) : TestException(message, QP_TEST_RESULT_FAIL)
107 {
108 }
109
InternalError(const char * message,const char * expr,const char * file,int line)110 InternalError::InternalError(const char *message, const char *expr, const char *file, int line)
111 : TestException(message, expr, file, line, QP_TEST_RESULT_INTERNAL_ERROR)
112 {
113 }
114
InternalError(const std::string & message,const char * expr,const char * file,int line)115 InternalError::InternalError(const std::string &message, const char *expr, const char *file, int line)
116 : TestException(message.c_str(), expr, file, line, QP_TEST_RESULT_INTERNAL_ERROR)
117 {
118 }
119
InternalError(const std::string & message)120 InternalError::InternalError(const std::string &message) : TestException(message, QP_TEST_RESULT_INTERNAL_ERROR)
121 {
122 }
123
ResourceError(const char * message,const char * expr,const char * file,int line)124 ResourceError::ResourceError(const char *message, const char *expr, const char *file, int line)
125 : TestException(message, expr, file, line, QP_TEST_RESULT_RESOURCE_ERROR)
126 {
127 }
128
ResourceError(const std::string & message)129 ResourceError::ResourceError(const std::string &message) : TestException(message, QP_TEST_RESULT_RESOURCE_ERROR)
130 {
131 }
132
NotSupportedError(const char * message,const char * expr,const char * file,int line)133 NotSupportedError::NotSupportedError(const char *message, const char *expr, const char *file, int line)
134 : TestException(message, expr, file, line, QP_TEST_RESULT_NOT_SUPPORTED)
135 {
136 }
137
NotSupportedError(const std::string & message,const char * expr,const char * file,int line)138 NotSupportedError::NotSupportedError(const std::string &message, const char *expr, const char *file, int line)
139 : TestException(message.c_str(), expr, file, line, QP_TEST_RESULT_NOT_SUPPORTED)
140 {
141 }
142
NotSupportedError(const std::string & message)143 NotSupportedError::NotSupportedError(const std::string &message) : TestException(message, QP_TEST_RESULT_NOT_SUPPORTED)
144 {
145 }
146
QualityWarning(const char * message,const char * expr,const char * file,int line)147 QualityWarning::QualityWarning(const char *message, const char *expr, const char *file, int line)
148 : TestException(message, expr, file, line, QP_TEST_RESULT_QUALITY_WARNING)
149 {
150 }
151
QualityWarning(const std::string & message,const char * expr,const char * file,int line)152 QualityWarning::QualityWarning(const std::string &message, const char *expr, const char *file, int line)
153 : TestException(message.c_str(), expr, file, line, QP_TEST_RESULT_QUALITY_WARNING)
154 {
155 }
156
QualityWarning(const std::string & message)157 QualityWarning::QualityWarning(const std::string &message) : TestException(message, QP_TEST_RESULT_QUALITY_WARNING)
158 {
159 }
160
161 } // namespace tcu
162