1 #ifndef __DALI_TEST_SUITE_UTILS_H__
2 #define __DALI_TEST_SUITE_UTILS_H__
5 * Copyright (c) 2017 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.
29 #include <dali/public-api/dali-core.h>
30 #include <test-compare-types.h>
32 void tet_infoline(const char*str);
33 void tet_printf(const char *format, ...);
35 #include "test-application.h"
36 #include "test-actor-utils.h"
40 #define STRINGIZE_I(text) #text
41 #define STRINGIZE(text) STRINGIZE_I(text)
43 // the following is the other compilers way of token pasting, gcc seems to just concatenate strings automatically
44 //#define TOKENPASTE(x,y) x ## y
45 #define TOKENPASTE(x,y) x y
46 #define TOKENPASTE2(x,y) TOKENPASTE( x, y )
47 #define TEST_LOCATION TOKENPASTE2( "Test failed in ", TOKENPASTE2( __FILE__, TOKENPASTE2( ", line ", STRINGIZE(__LINE__) ) ) )
48 #define TEST_INNER_LOCATION(x) ( std::string(x) + " (" + STRINGIZE(__LINE__) + ")" ).c_str()
54 extern int test_return_value;
56 void tet_result(int value);
59 return ((test_return_value>0)?1:0)
61 void tet_infoline(const char* str);
62 void tet_printf(const char *format, ...);
65 * DALI_TEST_CHECK is a wrapper for tet_result.
66 * If the condition evaluates to false, the test is stopped.
67 * @param[in] The boolean expression to check
69 #define DALI_TEST_CHECK(condition) \
72 tet_result(TET_PASS); \
76 fprintf(stderr, "%s Failed in %s at line %d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); \
77 tet_result(TET_FAIL); \
82 bool operator==(TimePeriod a, TimePeriod b);
83 std::ostream& operator<<( std::ostream& ostream, TimePeriod value );
84 std::ostream& operator<<( std::ostream& ostream, Radian angle );
85 std::ostream& operator<<( std::ostream& ostream, Degree angle );
88 * Test whether two values are equal.
89 * @param[in] value1 The first value
90 * @param[in] value2 The second value
91 * @param[in] location The TEST_LOCATION macro should be used here
93 template<typename Type>
94 inline void DALI_TEST_EQUALS(Type value1, Type value2, const char* location)
96 if( !CompareType<Type>(value1, value2, 0.01f) )
99 o << value1 << " == " << value2 << std::endl;
100 fprintf(stderr, "%s, checking %s", location, o.str().c_str());
101 tet_result(TET_FAIL);
105 tet_result(TET_PASS);
109 template<typename Type>
110 inline void DALI_TEST_EQUALS(Type value1, Type value2, float epsilon, const char* location)
112 if( !CompareType<Type>(value1, value2, epsilon) )
114 std::ostringstream o;
115 o << value1 << " == " << value2 << std::endl;
116 fprintf(stderr, "%s, checking %s", location, o.str().c_str());
117 tet_result(TET_FAIL);
121 tet_result(TET_PASS);
125 template<typename Type>
126 inline void DALI_TEST_NOT_EQUALS(Type value1, Type value2, float epsilon, const char* location)
128 if( CompareType<Type>(value1, value2, epsilon) )
130 std::ostringstream o;
131 o << value1 << " != " << value2 << std::endl;
132 fprintf(stderr, "%s, checking %s", location, o.str().c_str());
133 tet_result(TET_FAIL);
137 tet_result(TET_PASS);
143 * Test whether two TimePeriods are within a certain distance of each other.
144 * @param[in] value1 The first value
145 * @param[in] value2 The second value
146 * @param[in] epsilon The values must be within this distance of each other
147 * @param[in] location The TEST_LOCATION macro should be used here
150 inline void DALI_TEST_EQUALS<TimePeriod>( TimePeriod value1, TimePeriod value2, float epsilon, const char* location)
152 if ((fabs(value1.durationSeconds - value2.durationSeconds) > epsilon))
154 fprintf(stderr, "%s, checking durations %f == %f, epsilon %f\n", location, value1.durationSeconds, value2.durationSeconds, epsilon);
155 tet_result(TET_FAIL);
157 else if ((fabs(value1.delaySeconds - value2.delaySeconds) > epsilon))
159 fprintf(stderr, "%s, checking delays %f == %f, epsilon %f\n", location, value1.delaySeconds, value2.delaySeconds, epsilon);
160 tet_result(TET_FAIL);
164 tet_result(TET_PASS);
169 * Test whether two base handles are equal.
170 * @param[in] baseHandle1 The first value
171 * @param[in] baseHandle2 The second value
172 * @param[in] location The TEST_LOCATION macro should be used here
174 void DALI_TEST_EQUALS( const BaseHandle& baseHandle1, const BaseHandle& baseHandle2, const char* location );
177 * Test whether a size_t value and an unsigned int are equal.
178 * @param[in] value1 The first value
179 * @param[in] value2 The second value
180 * @param[in] location The TEST_LOCATION macro should be used here
182 void DALI_TEST_EQUALS( const size_t value1, const unsigned int value2, const char* location );
185 * Test whether an unsigned int and a size_t value and are equal.
186 * @param[in] value1 The first value
187 * @param[in] value2 The second value
188 * @param[in] location The TEST_LOCATION macro should be used here
190 void DALI_TEST_EQUALS( const unsigned int value1, const size_t value2, const char* location );
193 * Test whether two Matrix3 objects are equal.
194 * @param[in] matrix1 The first object
195 * @param[in] matrix2 The second object
196 * @param[in] location The TEST_LOCATION macro should be used here
198 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, const char* location);
200 /** Test whether two Matrix3 objects are equal (fuzzy compare).
201 * @param[in] matrix1 The first object
202 * @param[in] matrix2 The second object
203 * @param[in] epsilon The epsilon to use for comparison
204 * @param[in] location The TEST_LOCATION macro should be used here
206 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, float epsilon, const char* location);
209 * Test whether two Matrix objects are equal.
210 * @param[in] matrix1 The first object
211 * @param[in] matrix2 The second object
212 * @param[in] location The TEST_LOCATION macro should be used here
214 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, const char* location);
217 * Test whether two Matrix objects are equal (fuzzy-compare).
218 * @param[in] matrix1 The first object
219 * @param[in] matrix2 The second object
220 * @param[in] location The TEST_LOCATION macro should be used here
222 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, float epsilon, const char* location);
225 * Test whether two strings are equal.
226 * @param[in] str1 The first string
227 * @param[in] str2 The second string
228 * @param[in] location The TEST_LOCATION macro should be used here
231 inline void DALI_TEST_EQUALS<const char*>( const char* str1, const char* str2, const char* location)
233 if (strcmp(str1, str2))
235 fprintf(stderr, "%s, checking '%s' == '%s'\n", location, str1, str2);
236 tet_result(TET_FAIL);
240 tet_result(TET_PASS);
245 * Test whether two strings are equal.
246 * @param[in] str1 The first string
247 * @param[in] str2 The second string
248 * @param[in] location The TEST_LOCATION macro should be used here
251 inline void DALI_TEST_EQUALS<const std::string&>( const std::string &str1, const std::string &str2, const char* location)
253 DALI_TEST_EQUALS(str1.c_str(), str2.c_str(), location);
257 * Test whether two strings are equal.
258 * @param[in] str1 The first string
259 * @param[in] str2 The second string
260 * @param[in] location The TEST_LOCATION macro should be used here
262 void DALI_TEST_EQUALS( Property::Value& str1, const char* str2, const char* location);
265 * Test whether two strings are equal.
266 * @param[in] str1 The first string
267 * @param[in] str2 The second string
268 * @param[in] location The TEST_LOCATION macro should be used here
270 void DALI_TEST_EQUALS( const std::string &str1, const char* str2, const char* location);
273 * Test whether two strings are equal.
274 * @param[in] str1 The first string
275 * @param[in] str2 The second string
276 * @param[in] location The TEST_LOCATION macro should be used here
278 void DALI_TEST_EQUALS( const char* str1, const std::string &str2, const char* location);
281 * Test whether one unsigned integer value is greater than another.
282 * Test succeeds if value1 > value2
283 * @param[in] value1 The first value
284 * @param[in] value2 The second value
285 * @param[in] location The TEST_LOCATION macro should be used here
287 template< typename T >
288 void DALI_TEST_GREATER( T value1, T value2, const char* location)
290 if (!(value1 > value2))
292 std::cerr << location << ", checking " << value1 <<" > " << value2 << "\n";
293 tet_result(TET_FAIL);
297 tet_result(TET_PASS);
302 * Test whether the assertion condition that failed and thus triggered the
303 * exception \b e contained a given substring.
304 * @param[in] e The exception that we expect was fired by a runtime assertion failure.
305 * @param[in] conditionSubString The text that we expect to be present in an
306 * assertion which triggered the exception.
307 * @param[in] location The TEST_LOCATION macro should be used here.
309 void DALI_TEST_ASSERT( DaliException& e, std::string conditionSubString, const char* location );
313 * @param[in] e The exception that we expect was fired by a runtime assertion failure.
315 inline void DALI_TEST_PRINT_ASSERT( DaliException& e )
317 tet_printf("Assertion %s failed at %s\n", e.condition, e.location );
320 // Functor to test whether an Applied signal is emitted
321 struct ConstraintAppliedCheck
323 ConstraintAppliedCheck( bool& signalReceived );
324 void operator()( Constraint& constraint );
326 void CheckSignalReceived();
327 void CheckSignalNotReceived();
328 bool& mSignalReceived; // owned by individual tests
332 * A Helper to test default functions
334 template <typename T>
335 struct DefaultFunctionCoverage
337 DefaultFunctionCoverage()
348 // Helper to Create buffer image
349 BufferImage CreateBufferImage();
350 BufferImage CreateBufferImage(int width, int height, const Vector4& color);
353 // Prepare a resource image to be loaded. Should be called before creating the ResourceImage
354 void PrepareResourceImage( TestApplication& application, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat );
356 // Test namespace to prevent pollution of Dali namespace, add Test helper functions here
362 * Helper to check object destruction occurred
363 * 1) In main part of code create an ObjectDestructionTracker
364 * 2) Within sub section of main create object Actor test and call Start with Actor to test for destruction
365 * 3) Perform code which is expected to destroy Actor
366 * 4) Back in main part of code use IsDestroyed() to test if Actor was destroyed
368 class ObjectDestructionTracker : public ConnectionTracker
373 * @brief Call in main part of code
375 ObjectDestructionTracker();
378 * @brief Call in sub bock of code where the Actor being checked is still alive.
380 * @param[in] actor Actor to be checked for destruction
382 void Start( Actor actor );
385 * @brief Call to check if Actor alive or destroyed.
387 * @return bool true if Actor was destroyed
392 bool mRefObjectDestroyed;
397 #endif // __DALI_TEST_SUITE_UTILS_H__