1 #ifndef __DALI_TEST_SUITE_UTILS_H__
2 #define __DALI_TEST_SUITE_UTILS_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
26 #include <dali/public-api/dali-core.h>
28 void tet_infoline(const char*str);
29 void tet_printf(const char *format, ...);
31 #include "test-application.h"
35 #define STRINGIZE_I(text) #text
36 #define STRINGIZE(text) STRINGIZE_I(text)
38 // the following is the other compilers way of token pasting, gcc seems to just concatenate strings automatically
39 //#define TOKENPASTE(x,y) x ## y
40 #define TOKENPASTE(x,y) x y
41 #define TOKENPASTE2(x,y) TOKENPASTE( x, y )
42 #define TEST_LOCATION TOKENPASTE2( "Test failed in ", TOKENPASTE2( __FILE__, TOKENPASTE2( ", line ", STRINGIZE(__LINE__) ) ) )
48 extern int test_return_value;
50 void tet_result(int value);
53 return ((test_return_value>0)?1:0)
55 void tet_infoline(const char* str);
56 void tet_printf(const char *format, ...);
59 * DALI_TEST_CHECK is a wrapper for tet_result.
60 * If the condition evaluates to false, the test is stopped.
61 * @param[in] The boolean expression to check
63 #define DALI_TEST_CHECK(condition) \
66 tet_result(TET_PASS); \
70 fprintf(stderr, "%s Failed in %s at line %d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); \
71 tet_result(TET_FAIL); \
75 template <typename Type>
76 inline bool CompareType(Type value1, Type value2, float epsilon);
79 * A helper for fuzzy-comparing Vector2 objects
80 * @param[in] vector1 the first object
81 * @param[in] vector2 the second object
82 * @param[in] epsilon difference threshold
83 * @returns true if difference is smaller than epsilon threshold, false otherwise
86 inline bool CompareType<float>(float value1, float value2, float epsilon)
88 return fabsf(value1 - value2) < epsilon;
92 * A helper for fuzzy-comparing Vector2 objects
93 * @param[in] vector1 the first object
94 * @param[in] vector2 the second object
95 * @param[in] epsilon difference threshold
96 * @returns true if difference is smaller than epsilon threshold, false otherwise
99 inline bool CompareType<Vector2>(Vector2 vector1, Vector2 vector2, float epsilon)
101 return fabsf(vector1.x - vector2.x)<epsilon && fabsf(vector1.y - vector2.y)<epsilon;
105 * A helper for fuzzy-comparing Vector3 objects
106 * @param[in] vector1 the first object
107 * @param[in] vector2 the second object
108 * @param[in] epsilon difference threshold
109 * @returns true if difference is smaller than epsilon threshold, false otherwise
112 inline bool CompareType<Vector3>(Vector3 vector1, Vector3 vector2, float epsilon)
114 return fabsf(vector1.x - vector2.x)<epsilon &&
115 fabsf(vector1.y - vector2.y)<epsilon &&
116 fabsf(vector1.z - vector2.z)<epsilon;
121 * A helper for fuzzy-comparing Vector4 objects
122 * @param[in] vector1 the first object
123 * @param[in] vector2 the second object
124 * @param[in] epsilon difference threshold
125 * @returns true if difference is smaller than epsilon threshold, false otherwise
128 inline bool CompareType<Vector4>(Vector4 vector1, Vector4 vector2, float epsilon)
130 return fabsf(vector1.x - vector2.x)<epsilon &&
131 fabsf(vector1.y - vector2.y)<epsilon &&
132 fabsf(vector1.z - vector2.z)<epsilon &&
133 fabsf(vector1.w - vector2.w)<epsilon;
137 inline bool CompareType<Quaternion>(Quaternion q1, Quaternion q2, float epsilon)
139 Quaternion q2N = -q2; // These quaternions represent the same rotation
140 return CompareType<Vector4>(q1.mVector, q2.mVector, epsilon) || CompareType<Vector4>(q1.mVector, q2N.mVector, epsilon);
144 inline bool CompareType<Radian>(Radian q1, Radian q2, float epsilon)
146 return CompareType<float>(q1.radian, q2.radian, epsilon);
150 inline bool CompareType<Degree>(Degree q1, Degree q2, float epsilon)
152 return CompareType<float>(q1.degree, q2.degree, epsilon);
155 bool operator==(TimePeriod a, TimePeriod b);
156 std::ostream& operator<<( std::ostream& ostream, TimePeriod value );
157 std::ostream& operator<<( std::ostream& ostream, Radian angle );
158 std::ostream& operator<<( std::ostream& ostream, Degree angle );
161 * Test whether two values are equal.
162 * @param[in] value1 The first value
163 * @param[in] value2 The second value
164 * @param[in] location The TEST_LOCATION macro should be used here
166 template<typename Type>
167 inline void DALI_TEST_EQUALS(Type value1, Type value2, const char* location)
169 if (!(value1 == value2))
171 std::ostringstream o;
172 o << value1 << " == " << value2 << std::endl;
173 fprintf(stderr, "%s, checking %s", location, o.str().c_str());
174 tet_result(TET_FAIL);
178 tet_result(TET_PASS);
182 template<typename Type>
183 inline void DALI_TEST_EQUALS(Type value1, Type value2, float epsilon, const char* location)
185 if( !CompareType<Type>(value1, value2, epsilon) )
187 std::ostringstream o;
188 o << value1 << " == " << value2 << std::endl;
189 fprintf(stderr, "%s, checking %s", location, o.str().c_str());
190 tet_result(TET_FAIL);
194 tet_result(TET_PASS);
199 * Test whether two TimePeriods are within a certain distance of each other.
200 * @param[in] value1 The first value
201 * @param[in] value2 The second value
202 * @param[in] epsilon The values must be within this distance of each other
203 * @param[in] location The TEST_LOCATION macro should be used here
206 inline void DALI_TEST_EQUALS<TimePeriod>( TimePeriod value1, TimePeriod value2, float epsilon, const char* location)
208 if ((fabs(value1.durationSeconds - value2.durationSeconds) > epsilon))
210 fprintf(stderr, "%s, checking durations %f == %f, epsilon %f\n", location, value1.durationSeconds, value2.durationSeconds, epsilon);
211 tet_result(TET_FAIL);
213 else if ((fabs(value1.delaySeconds - value2.delaySeconds) > epsilon))
215 fprintf(stderr, "%s, checking delays %f == %f, epsilon %f\n", location, value1.delaySeconds, value2.delaySeconds, epsilon);
216 tet_result(TET_FAIL);
220 tet_result(TET_PASS);
225 * Test whether two base handles are equal.
226 * @param[in] baseHandle1 The first value
227 * @param[in] baseHandle2 The second value
228 * @param[in] location The TEST_LOCATION macro should be used here
230 void DALI_TEST_EQUALS( const BaseHandle& baseHandle1, const BaseHandle& baseHandle2, const char* location );
233 * Test whether a size_t value and an unsigned int are equal.
234 * @param[in] value1 The first value
235 * @param[in] value2 The second value
236 * @param[in] location The TEST_LOCATION macro should be used here
238 void DALI_TEST_EQUALS( const size_t value1, const unsigned int value2, const char* location );
241 * Test whether an unsigned int and a size_t value and are equal.
242 * @param[in] value1 The first value
243 * @param[in] value2 The second value
244 * @param[in] location The TEST_LOCATION macro should be used here
246 void DALI_TEST_EQUALS( const unsigned int value1, const size_t value2, const char* location );
249 * Test whether two Matrix3 objects are equal.
250 * @param[in] matrix1 The first object
251 * @param[in] matrix2 The second object
252 * @param[in] location The TEST_LOCATION macro should be used here
254 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, const char* location);
256 /** Test whether two Matrix3 objects are equal (fuzzy compare).
257 * @param[in] matrix1 The first object
258 * @param[in] matrix2 The second object
259 * @param[in] epsilon The epsilon to use for comparison
260 * @param[in] location The TEST_LOCATION macro should be used here
262 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, float epsilon, const char* location);
265 * Test whether two Matrix objects are equal.
266 * @param[in] matrix1 The first object
267 * @param[in] matrix2 The second object
268 * @param[in] location The TEST_LOCATION macro should be used here
270 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, const char* location);
273 * Test whether two Matrix objects are equal (fuzzy-compare).
274 * @param[in] matrix1 The first object
275 * @param[in] matrix2 The second object
276 * @param[in] location The TEST_LOCATION macro should be used here
278 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, float epsilon, const char* location);
281 * Test whether two strings are equal.
282 * @param[in] str1 The first string
283 * @param[in] str2 The second string
284 * @param[in] location The TEST_LOCATION macro should be used here
287 inline void DALI_TEST_EQUALS<const char*>( const char* str1, const char* str2, const char* location)
289 if (strcmp(str1, str2))
291 fprintf(stderr, "%s, checking '%s' == '%s'\n", location, str1, str2);
292 tet_result(TET_FAIL);
296 tet_result(TET_PASS);
301 * Test whether two strings are equal.
302 * @param[in] str1 The first string
303 * @param[in] str2 The second string
304 * @param[in] location The TEST_LOCATION macro should be used here
307 inline void DALI_TEST_EQUALS<const std::string&>( const std::string &str1, const std::string &str2, const char* location)
309 DALI_TEST_EQUALS(str1.c_str(), str2.c_str(), location);
313 * Test whether two strings are equal.
314 * @param[in] str1 The first string
315 * @param[in] str2 The second string
316 * @param[in] location The TEST_LOCATION macro should be used here
318 void DALI_TEST_EQUALS( const std::string &str1, const char* str2, const char* location);
321 * Test whether two strings are equal.
322 * @param[in] str1 The first string
323 * @param[in] str2 The second string
324 * @param[in] location The TEST_LOCATION macro should be used here
326 void DALI_TEST_EQUALS( const char* str1, const std::string &str2, const char* location);
329 * Test whether one unsigned integer value is greater than another.
330 * Test succeeds if value1 > value2
331 * @param[in] value1 The first value
332 * @param[in] value2 The second value
333 * @param[in] location The TEST_LOCATION macro should be used here
335 template< typename T >
336 void DALI_TEST_GREATER( T value1, T value2, const char* location)
338 if (!(value1 > value2))
340 std::cerr << location << ", checking " << value1 <<" > " << value2 << "\n";
341 tet_result(TET_FAIL);
345 tet_result(TET_PASS);
350 * Test whether the assertion condition that failed and thus triggered the
351 * exception \b e contained a given substring.
352 * @param[in] e The exception that we expect was fired by a runtime assertion failure.
353 * @param[in] conditionSubString The text that we expect to be present in an
354 * assertion which triggered the exception.
355 * @param[in] location The TEST_LOCATION macro should be used here.
357 void DALI_TEST_ASSERT( DaliException& e, std::string conditionSubString, const char* location );
361 * @param[in] e The exception that we expect was fired by a runtime assertion failure.
363 inline void DALI_TEST_PRINT_ASSERT( DaliException& e )
365 tet_printf("Assertion %s failed at %s\n", e.condition, e.location );
368 // Functor to test whether an Applied signal is emitted
369 struct ConstraintAppliedCheck
371 ConstraintAppliedCheck( bool& signalReceived );
372 void operator()( Constraint& constraint );
374 void CheckSignalReceived();
375 void CheckSignalNotReceived();
376 bool& mSignalReceived; // owned by individual tests
380 * A Helper to test default functions
382 template <typename T>
383 struct DefaultFunctionCoverage
385 DefaultFunctionCoverage()
396 // Helper to Create buffer image
397 BufferImage CreateBufferImage();
399 #endif // __DALI_TEST_SUITE_UTILS_H__