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.
28 #include <dali/public-api/dali-core.h>
29 #include <test-compare-types.h>
31 void tet_infoline(const char*str);
32 void tet_printf(const char *format, ...);
34 #include "test-application.h"
35 #include "test-actor-utils.h"
39 #define STRINGIZE_I(text) #text
40 #define STRINGIZE(text) STRINGIZE_I(text)
42 // the following is the other compilers way of token pasting, gcc seems to just concatenate strings automatically
43 //#define TOKENPASTE(x,y) x ## y
44 #define TOKENPASTE(x,y) x y
45 #define TOKENPASTE2(x,y) TOKENPASTE( x, y )
46 #define TEST_LOCATION TOKENPASTE2( "Test failed in ", TOKENPASTE2( __FILE__, TOKENPASTE2( ", line ", STRINGIZE(__LINE__) ) ) )
52 extern int test_return_value;
54 void tet_result(int value);
57 return ((test_return_value>0)?1:0)
59 void tet_infoline(const char* str);
60 void tet_printf(const char *format, ...);
63 * DALI_TEST_CHECK is a wrapper for tet_result.
64 * If the condition evaluates to false, the test is stopped.
65 * @param[in] The boolean expression to check
67 #define DALI_TEST_CHECK(condition) \
70 tet_result(TET_PASS); \
74 fprintf(stderr, "%s Failed in %s at line %d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); \
75 tet_result(TET_FAIL); \
80 bool operator==(TimePeriod a, TimePeriod b);
81 std::ostream& operator<<( std::ostream& ostream, TimePeriod value );
82 std::ostream& operator<<( std::ostream& ostream, Radian angle );
83 std::ostream& operator<<( std::ostream& ostream, Degree angle );
86 * Test whether two values are equal.
87 * @param[in] value1 The first value
88 * @param[in] value2 The second value
89 * @param[in] location The TEST_LOCATION macro should be used here
91 template<typename Type>
92 inline void DALI_TEST_EQUALS(Type value1, Type value2, const char* location)
94 if( !CompareType<Type>(value1, value2, 0.01f) )
97 o << value1 << " == " << value2 << std::endl;
98 fprintf(stderr, "%s, checking %s", location, o.str().c_str());
103 tet_result(TET_PASS);
107 template<typename Type>
108 inline void DALI_TEST_EQUALS(Type value1, Type value2, float epsilon, const char* location)
110 if( !CompareType<Type>(value1, value2, epsilon) )
112 std::ostringstream o;
113 o << value1 << " == " << value2 << std::endl;
114 fprintf(stderr, "%s, checking %s", location, o.str().c_str());
115 tet_result(TET_FAIL);
119 tet_result(TET_PASS);
123 template<typename Type>
124 inline void DALI_TEST_NOT_EQUALS(Type value1, Type value2, float epsilon, const char* location)
126 if( CompareType<Type>(value1, value2, epsilon) )
128 std::ostringstream o;
129 o << value1 << " != " << value2 << std::endl;
130 fprintf(stderr, "%s, checking %s", location, o.str().c_str());
131 tet_result(TET_FAIL);
135 tet_result(TET_PASS);
141 * Test whether two TimePeriods are within a certain distance of each other.
142 * @param[in] value1 The first value
143 * @param[in] value2 The second value
144 * @param[in] epsilon The values must be within this distance of each other
145 * @param[in] location The TEST_LOCATION macro should be used here
148 inline void DALI_TEST_EQUALS<TimePeriod>( TimePeriod value1, TimePeriod value2, float epsilon, const char* location)
150 if ((fabs(value1.durationSeconds - value2.durationSeconds) > epsilon))
152 fprintf(stderr, "%s, checking durations %f == %f, epsilon %f\n", location, value1.durationSeconds, value2.durationSeconds, epsilon);
153 tet_result(TET_FAIL);
155 else if ((fabs(value1.delaySeconds - value2.delaySeconds) > epsilon))
157 fprintf(stderr, "%s, checking delays %f == %f, epsilon %f\n", location, value1.delaySeconds, value2.delaySeconds, epsilon);
158 tet_result(TET_FAIL);
162 tet_result(TET_PASS);
167 * Test whether two base handles are equal.
168 * @param[in] baseHandle1 The first value
169 * @param[in] baseHandle2 The second value
170 * @param[in] location The TEST_LOCATION macro should be used here
172 void DALI_TEST_EQUALS( const BaseHandle& baseHandle1, const BaseHandle& baseHandle2, const char* location );
175 * Test whether a size_t value and an unsigned int are equal.
176 * @param[in] value1 The first value
177 * @param[in] value2 The second value
178 * @param[in] location The TEST_LOCATION macro should be used here
180 void DALI_TEST_EQUALS( const size_t value1, const unsigned int value2, const char* location );
183 * Test whether an unsigned int and a size_t value and are equal.
184 * @param[in] value1 The first value
185 * @param[in] value2 The second value
186 * @param[in] location The TEST_LOCATION macro should be used here
188 void DALI_TEST_EQUALS( const unsigned int value1, const size_t value2, const char* location );
191 * Test whether two Matrix3 objects are equal.
192 * @param[in] matrix1 The first object
193 * @param[in] matrix2 The second object
194 * @param[in] location The TEST_LOCATION macro should be used here
196 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, const char* location);
198 /** Test whether two Matrix3 objects are equal (fuzzy compare).
199 * @param[in] matrix1 The first object
200 * @param[in] matrix2 The second object
201 * @param[in] epsilon The epsilon to use for comparison
202 * @param[in] location The TEST_LOCATION macro should be used here
204 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, float epsilon, const char* location);
207 * Test whether two Matrix objects are equal.
208 * @param[in] matrix1 The first object
209 * @param[in] matrix2 The second object
210 * @param[in] location The TEST_LOCATION macro should be used here
212 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, const char* location);
215 * Test whether two Matrix objects are equal (fuzzy-compare).
216 * @param[in] matrix1 The first object
217 * @param[in] matrix2 The second object
218 * @param[in] location The TEST_LOCATION macro should be used here
220 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, float epsilon, const char* location);
223 * Test whether two strings are equal.
224 * @param[in] str1 The first string
225 * @param[in] str2 The second string
226 * @param[in] location The TEST_LOCATION macro should be used here
229 inline void DALI_TEST_EQUALS<const char*>( const char* str1, const char* str2, const char* location)
231 if (strcmp(str1, str2))
233 fprintf(stderr, "%s, checking '%s' == '%s'\n", location, str1, str2);
234 tet_result(TET_FAIL);
238 tet_result(TET_PASS);
243 * Test whether two strings are equal.
244 * @param[in] str1 The first string
245 * @param[in] str2 The second string
246 * @param[in] location The TEST_LOCATION macro should be used here
249 inline void DALI_TEST_EQUALS<const std::string&>( const std::string &str1, const std::string &str2, const char* location)
251 DALI_TEST_EQUALS(str1.c_str(), str2.c_str(), location);
255 * Test whether two strings are equal.
256 * @param[in] str1 The first string
257 * @param[in] str2 The second string
258 * @param[in] location The TEST_LOCATION macro should be used here
260 void DALI_TEST_EQUALS( Property::Value& str1, const char* str2, const char* location);
263 * Test whether two strings are equal.
264 * @param[in] str1 The first string
265 * @param[in] str2 The second string
266 * @param[in] location The TEST_LOCATION macro should be used here
268 void DALI_TEST_EQUALS( const std::string &str1, const char* str2, const char* location);
271 * Test whether two strings are equal.
272 * @param[in] str1 The first string
273 * @param[in] str2 The second string
274 * @param[in] location The TEST_LOCATION macro should be used here
276 void DALI_TEST_EQUALS( const char* str1, const std::string &str2, const char* location);
279 * Test whether one unsigned integer value is greater than another.
280 * Test succeeds if value1 > value2
281 * @param[in] value1 The first value
282 * @param[in] value2 The second value
283 * @param[in] location The TEST_LOCATION macro should be used here
285 template< typename T >
286 void DALI_TEST_GREATER( T value1, T value2, const char* location)
288 if (!(value1 > value2))
290 std::cerr << location << ", checking " << value1 <<" > " << value2 << "\n";
291 tet_result(TET_FAIL);
295 tet_result(TET_PASS);
300 * Test whether the assertion condition that failed and thus triggered the
301 * exception \b e contained a given substring.
302 * @param[in] e The exception that we expect was fired by a runtime assertion failure.
303 * @param[in] conditionSubString The text that we expect to be present in an
304 * assertion which triggered the exception.
305 * @param[in] location The TEST_LOCATION macro should be used here.
307 void DALI_TEST_ASSERT( DaliException& e, std::string conditionSubString, const char* location );
311 * @param[in] e The exception that we expect was fired by a runtime assertion failure.
313 inline void DALI_TEST_PRINT_ASSERT( DaliException& e )
315 tet_printf("Assertion %s failed at %s\n", e.condition, e.location );
318 // Functor to test whether an Applied signal is emitted
319 struct ConstraintAppliedCheck
321 ConstraintAppliedCheck( bool& signalReceived );
322 void operator()( Constraint& constraint );
324 void CheckSignalReceived();
325 void CheckSignalNotReceived();
326 bool& mSignalReceived; // owned by individual tests
330 * A Helper to test default functions
332 template <typename T>
333 struct DefaultFunctionCoverage
335 DefaultFunctionCoverage()
346 // Helper to Create buffer image
347 BufferImage CreateBufferImage();
348 BufferImage CreateBufferImage(int width, int height, const Vector4& color);
351 // Prepare a resource image to be loaded. Should be called before creating the ResourceImage
352 void PrepareResourceImage( TestApplication& application, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat );
354 // Test namespace to prevent pollution of Dali namespace, add Test helper functions here
360 * Helper to check object destruction occurred
361 * 1) In main part of code create an ObjectDestructionTracker
362 * 2) Within sub section of main create object Actor test and call Start with Actor to test for destruction
363 * 3) Perform code which is expected to destroy Actor
364 * 4) Back in main part of code use IsDestroyed() to test if Actor was destroyed
366 class ObjectDestructionTracker : public ConnectionTracker
371 * @brief Call in main part of code
373 ObjectDestructionTracker();
376 * @brief Call in sub bock of code where the Actor being checked is still alive.
378 * @param[in] actor Actor to be checked for destruction
380 void Start( Actor actor );
383 * @brief Call to check if Actor alive or destroyed.
385 * @return bool true if Actor was destroyed
390 bool mRefObjectDestroyed;
395 #endif // __DALI_TEST_SUITE_UTILS_H__