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"
32 #include "test-actor-utils.h"
36 #define STRINGIZE_I(text) #text
37 #define STRINGIZE(text) STRINGIZE_I(text)
39 // the following is the other compilers way of token pasting, gcc seems to just concatenate strings automatically
40 //#define TOKENPASTE(x,y) x ## y
41 #define TOKENPASTE(x,y) x y
42 #define TOKENPASTE2(x,y) TOKENPASTE( x, y )
43 #define TEST_LOCATION TOKENPASTE2( "Test failed in ", TOKENPASTE2( __FILE__, TOKENPASTE2( ", line ", STRINGIZE(__LINE__) ) ) )
49 extern int test_return_value;
51 void tet_result(int value);
54 return ((test_return_value>0)?1:0)
56 void tet_infoline(const char* str);
57 void tet_printf(const char *format, ...);
60 * DALI_TEST_CHECK is a wrapper for tet_result.
61 * If the condition evaluates to false, the test is stopped.
62 * @param[in] The boolean expression to check
64 #define DALI_TEST_CHECK(condition) \
67 tet_result(TET_PASS); \
71 fprintf(stderr, "%s Failed in %s at line %d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); \
72 tet_result(TET_FAIL); \
76 template <typename Type>
77 inline bool CompareType(Type value1, Type value2, float epsilon);
80 * A helper for fuzzy-comparing Vector2 objects
81 * @param[in] vector1 the first object
82 * @param[in] vector2 the second object
83 * @param[in] epsilon difference threshold
84 * @returns true if difference is smaller than epsilon threshold, false otherwise
87 inline bool CompareType<float>(float value1, float value2, float epsilon)
89 return fabsf(value1 - value2) < epsilon;
93 * A helper for fuzzy-comparing Vector2 objects
94 * @param[in] vector1 the first object
95 * @param[in] vector2 the second object
96 * @param[in] epsilon difference threshold
97 * @returns true if difference is smaller than epsilon threshold, false otherwise
100 inline bool CompareType<Vector2>(Vector2 vector1, Vector2 vector2, float epsilon)
102 return fabsf(vector1.x - vector2.x)<epsilon && fabsf(vector1.y - vector2.y)<epsilon;
106 * A helper for fuzzy-comparing Vector3 objects
107 * @param[in] vector1 the first object
108 * @param[in] vector2 the second object
109 * @param[in] epsilon difference threshold
110 * @returns true if difference is smaller than epsilon threshold, false otherwise
113 inline bool CompareType<Vector3>(Vector3 vector1, Vector3 vector2, float epsilon)
115 return fabsf(vector1.x - vector2.x)<epsilon &&
116 fabsf(vector1.y - vector2.y)<epsilon &&
117 fabsf(vector1.z - vector2.z)<epsilon;
122 * A helper for fuzzy-comparing Vector4 objects
123 * @param[in] vector1 the first object
124 * @param[in] vector2 the second object
125 * @param[in] epsilon difference threshold
126 * @returns true if difference is smaller than epsilon threshold, false otherwise
129 inline bool CompareType<Vector4>(Vector4 vector1, Vector4 vector2, float epsilon)
131 return fabsf(vector1.x - vector2.x)<epsilon &&
132 fabsf(vector1.y - vector2.y)<epsilon &&
133 fabsf(vector1.z - vector2.z)<epsilon &&
134 fabsf(vector1.w - vector2.w)<epsilon;
138 inline bool CompareType<Quaternion>(Quaternion q1, Quaternion q2, float epsilon)
140 Quaternion q2N = -q2; // These quaternions represent the same rotation
141 return CompareType<Vector4>(q1.mVector, q2.mVector, epsilon) || CompareType<Vector4>(q1.mVector, q2N.mVector, epsilon);
145 inline bool CompareType<Radian>(Radian q1, Radian q2, float epsilon)
147 return CompareType<float>(q1.radian, q2.radian, epsilon);
151 inline bool CompareType<Degree>(Degree q1, Degree q2, float epsilon)
153 return CompareType<float>(q1.degree, q2.degree, epsilon);
156 bool operator==(TimePeriod a, TimePeriod b);
157 std::ostream& operator<<( std::ostream& ostream, TimePeriod value );
158 std::ostream& operator<<( std::ostream& ostream, Radian angle );
159 std::ostream& operator<<( std::ostream& ostream, Degree angle );
162 * Test whether two values are equal.
163 * @param[in] value1 The first value
164 * @param[in] value2 The second value
165 * @param[in] location The TEST_LOCATION macro should be used here
167 template<typename Type>
168 inline void DALI_TEST_EQUALS(Type value1, Type value2, const char* location)
170 if (!(value1 == value2))
172 std::ostringstream o;
173 o << value1 << " == " << value2 << std::endl;
174 fprintf(stderr, "%s, checking %s", location, o.str().c_str());
175 tet_result(TET_FAIL);
179 tet_result(TET_PASS);
183 template<typename Type>
184 inline void DALI_TEST_EQUALS(Type value1, Type value2, float epsilon, const char* location)
186 if( !CompareType<Type>(value1, value2, epsilon) )
188 std::ostringstream o;
189 o << value1 << " == " << value2 << std::endl;
190 fprintf(stderr, "%s, checking %s", location, o.str().c_str());
191 tet_result(TET_FAIL);
195 tet_result(TET_PASS);
200 * Test whether two TimePeriods are within a certain distance of each other.
201 * @param[in] value1 The first value
202 * @param[in] value2 The second value
203 * @param[in] epsilon The values must be within this distance of each other
204 * @param[in] location The TEST_LOCATION macro should be used here
207 inline void DALI_TEST_EQUALS<TimePeriod>( TimePeriod value1, TimePeriod value2, float epsilon, const char* location)
209 if ((fabs(value1.durationSeconds - value2.durationSeconds) > epsilon))
211 fprintf(stderr, "%s, checking durations %f == %f, epsilon %f\n", location, value1.durationSeconds, value2.durationSeconds, epsilon);
212 tet_result(TET_FAIL);
214 else if ((fabs(value1.delaySeconds - value2.delaySeconds) > epsilon))
216 fprintf(stderr, "%s, checking delays %f == %f, epsilon %f\n", location, value1.delaySeconds, value2.delaySeconds, epsilon);
217 tet_result(TET_FAIL);
221 tet_result(TET_PASS);
226 * Test whether two base handles are equal.
227 * @param[in] baseHandle1 The first value
228 * @param[in] baseHandle2 The second value
229 * @param[in] location The TEST_LOCATION macro should be used here
231 void DALI_TEST_EQUALS( const BaseHandle& baseHandle1, const BaseHandle& baseHandle2, const char* location );
234 * Test whether a size_t value and an unsigned int are equal.
235 * @param[in] value1 The first value
236 * @param[in] value2 The second value
237 * @param[in] location The TEST_LOCATION macro should be used here
239 void DALI_TEST_EQUALS( const size_t value1, const unsigned int value2, const char* location );
242 * Test whether an unsigned int and a size_t value and are equal.
243 * @param[in] value1 The first value
244 * @param[in] value2 The second value
245 * @param[in] location The TEST_LOCATION macro should be used here
247 void DALI_TEST_EQUALS( const unsigned int value1, const size_t value2, const char* location );
250 * Test whether two Matrix3 objects are equal.
251 * @param[in] matrix1 The first object
252 * @param[in] matrix2 The second object
253 * @param[in] location The TEST_LOCATION macro should be used here
255 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, const char* location);
257 /** Test whether two Matrix3 objects are equal (fuzzy compare).
258 * @param[in] matrix1 The first object
259 * @param[in] matrix2 The second object
260 * @param[in] epsilon The epsilon to use for comparison
261 * @param[in] location The TEST_LOCATION macro should be used here
263 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, float epsilon, const char* location);
266 * Test whether two Matrix objects are equal.
267 * @param[in] matrix1 The first object
268 * @param[in] matrix2 The second object
269 * @param[in] location The TEST_LOCATION macro should be used here
271 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, const char* location);
274 * Test whether two Matrix objects are equal (fuzzy-compare).
275 * @param[in] matrix1 The first object
276 * @param[in] matrix2 The second object
277 * @param[in] location The TEST_LOCATION macro should be used here
279 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, float epsilon, const char* location);
282 * Test whether two strings are equal.
283 * @param[in] str1 The first string
284 * @param[in] str2 The second string
285 * @param[in] location The TEST_LOCATION macro should be used here
288 inline void DALI_TEST_EQUALS<const char*>( const char* str1, const char* str2, const char* location)
290 if (strcmp(str1, str2))
292 fprintf(stderr, "%s, checking '%s' == '%s'\n", location, str1, str2);
293 tet_result(TET_FAIL);
297 tet_result(TET_PASS);
302 * Test whether two strings are equal.
303 * @param[in] str1 The first string
304 * @param[in] str2 The second string
305 * @param[in] location The TEST_LOCATION macro should be used here
308 inline void DALI_TEST_EQUALS<const std::string&>( const std::string &str1, const std::string &str2, const char* location)
310 DALI_TEST_EQUALS(str1.c_str(), str2.c_str(), location);
314 * Test whether two strings are equal.
315 * @param[in] str1 The first string
316 * @param[in] str2 The second string
317 * @param[in] location The TEST_LOCATION macro should be used here
319 void DALI_TEST_EQUALS( const std::string &str1, const char* str2, const char* location);
322 * Test whether two strings are equal.
323 * @param[in] str1 The first string
324 * @param[in] str2 The second string
325 * @param[in] location The TEST_LOCATION macro should be used here
327 void DALI_TEST_EQUALS( const char* str1, const std::string &str2, const char* location);
330 * Test whether one unsigned integer value is greater than another.
331 * Test succeeds if value1 > value2
332 * @param[in] value1 The first value
333 * @param[in] value2 The second value
334 * @param[in] location The TEST_LOCATION macro should be used here
336 template< typename T >
337 void DALI_TEST_GREATER( T value1, T value2, const char* location)
339 if (!(value1 > value2))
341 std::cerr << location << ", checking " << value1 <<" > " << value2 << "\n";
342 tet_result(TET_FAIL);
346 tet_result(TET_PASS);
351 * Test whether the assertion condition that failed and thus triggered the
352 * exception \b e contained a given substring.
353 * @param[in] e The exception that we expect was fired by a runtime assertion failure.
354 * @param[in] conditionSubString The text that we expect to be present in an
355 * assertion which triggered the exception.
356 * @param[in] location The TEST_LOCATION macro should be used here.
358 void DALI_TEST_ASSERT( DaliException& e, std::string conditionSubString, const char* location );
362 * @param[in] e The exception that we expect was fired by a runtime assertion failure.
364 inline void DALI_TEST_PRINT_ASSERT( DaliException& e )
366 tet_printf("Assertion %s failed at %s\n", e.condition, e.location );
369 // Functor to test whether an Applied signal is emitted
370 struct ConstraintAppliedCheck
372 ConstraintAppliedCheck( bool& signalReceived );
373 void operator()( Constraint& constraint );
375 void CheckSignalReceived();
376 void CheckSignalNotReceived();
377 bool& mSignalReceived; // owned by individual tests
381 * A Helper to test default functions
383 template <typename T>
384 struct DefaultFunctionCoverage
386 DefaultFunctionCoverage()
397 // Helper to Create buffer image
398 BufferImage CreateBufferImage();
399 BufferImage CreateBufferImage(int width, int height, const Vector4& color);
401 #endif // __DALI_TEST_SUITE_UTILS_H__