2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "dali-test-suite-utils.h"
24 #include <dali/public-api/dali-core.h>
28 int test_return_value = TET_UNDEF;
30 void tet_result(int value)
32 // First TET_PASS should set to zero
33 // first TET_FAIL should prevent any further TET_PASS from setting back to zero
34 // Any TET_FAIL should set to fail or leave as fail
35 if( test_return_value != 1 )
36 test_return_value = value;
40 return ((test_return_value>0)?1:0)
43 void tet_infoline(const char* str)
45 fprintf(stderr, "%s\n", str);
48 void tet_printf(const char *format, ...)
51 va_start(arg, format);
52 vfprintf(stderr, format, arg);
57 * DALI_TEST_CHECK is a wrapper for tet_result.
58 * If the condition evaluates to false, then the function & line number is printed.
59 * @param[in] The boolean expression to check
61 #define DALI_TEST_CHECK(condition) \
64 tet_result(TET_PASS); \
68 fprintf(stderr, "%s Failed in %s at line %d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); \
69 tet_result(TET_FAIL); \
72 bool operator==(TimePeriod a, TimePeriod b)
74 return Equals(a.durationSeconds, b.durationSeconds) && Equals(a.delaySeconds, b.delaySeconds) ;
77 std::ostream& operator<< (std::ostream& ostream, const TimePeriod value)
79 return ostream << "( Duration:" << value.durationSeconds << " Delay:" << value.delaySeconds << ")";
82 std::ostream& operator<<( std::ostream& ostream, Radian angle )
84 ostream << angle.radian;
88 std::ostream& operator<<( std::ostream& ostream, Degree angle )
90 ostream << angle.degree;
94 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, const char* location)
96 const float* m1 = matrix1.AsFloat();
97 const float* m2 = matrix2.AsFloat();
98 bool equivalent = true;
100 for (int i=0;i<9;++i)
102 equivalent &= (m1[i] != m2[i]);
107 fprintf(stderr, "%s, checking\n"
108 "(%f, %f, %f) (%f, %f, %f)\n"
109 "(%f, %f, %f) == (%f, %f, %f)\n"
110 "(%f, %f, %f) (%f, %f, %f)\n",
112 m1[0], m1[1], m1[2], m2[0], m2[1], m2[2],
113 m1[3], m1[4], m1[5], m2[3], m2[4], m2[5],
114 m1[6], m1[7], m1[8], m2[6], m2[7], m2[8]);
116 tet_result(TET_FAIL);
120 tet_result(TET_PASS);
124 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, float epsilon, const char* location)
126 const float* m1 = matrix1.AsFloat();
127 const float* m2 = matrix2.AsFloat();
128 bool equivalent = true;
130 for (int i=0;i<9;++i)
132 equivalent &= (fabsf(m1[i] - m2[i])<epsilon);
137 fprintf(stderr, "%s, checking\n"
138 "(%f, %f, %f) (%f, %f, %f)\n"
139 "(%f, %f, %f) == (%f, %f, %f)\n"
140 "(%f, %f, %f) (%f, %f, %f)\n",
142 m1[0], m1[1], m1[2], m2[0], m2[1], m2[2],
143 m1[3], m1[4], m1[5], m2[3], m2[4], m2[5],
144 m1[6], m1[7], m1[8], m2[6], m2[7], m2[8]);
146 tet_result(TET_FAIL);
150 tet_result(TET_PASS);
154 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, const char* location)
156 const float* m1 = matrix1.AsFloat();
157 const float* m2 = matrix2.AsFloat();
158 bool identical = true;
172 fprintf(stderr, "%s, checking\n"
173 "(%f, %f, %f, %f) (%f, %f, %f, %f)\n"
174 "(%f, %f, %f, %f) == (%f, %f, %f, %f)\n"
175 "(%f, %f, %f, %f) (%f, %f, %f, %f)\n"
176 "(%f, %f, %f, %f) (%f, %f, %f, %f)\n", location,
177 m1[0], m1[1], m1[2], m1[3], m2[0], m2[1], m2[2], m2[3],
178 m1[4], m1[5], m1[6], m1[7], m2[4], m2[5], m2[6], m2[7],
179 m1[8], m1[9], m1[10], m1[11], m2[8], m2[9], m2[10], m2[11],
180 m1[12], m1[13], m1[14], m1[15], m2[12], m2[13], m2[14], m2[15]);
182 tet_result(TET_FAIL);
186 tet_result(TET_PASS);
190 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, float epsilon, const char* location)
192 const float* m1 = matrix1.AsFloat();
193 const float* m2 = matrix2.AsFloat();
194 bool equivalent = true;
196 for (int i=0;i<16;++i)
198 equivalent &= (fabsf(m1[i] - m2[i])<epsilon);
203 fprintf(stderr, "%s, checking\n"
204 "(%f, %f, %f, %f) (%f, %f, %f, %f)\n"
205 "(%f, %f, %f, %f) == (%f, %f, %f, %f)\n"
206 "(%f, %f, %f, %f) (%f, %f, %f, %f)\n"
207 "(%f, %f, %f, %f) (%f, %f, %f, %f)\n", location,
208 m1[0], m1[1], m1[2], m1[3], m2[0], m2[1], m2[2], m2[3],
209 m1[4], m1[5], m1[6], m1[7], m2[4], m2[5], m2[6], m2[7],
210 m1[8], m1[9], m1[10], m1[11], m2[8], m2[9], m2[10], m2[11],
211 m1[12], m1[13], m1[14], m1[15], m2[12], m2[13], m2[14], m2[15]);
213 tet_result(TET_FAIL);
217 tet_result(TET_PASS);
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
228 void DALI_TEST_EQUALS( const std::string &str1, const char* str2, const char* location)
230 DALI_TEST_EQUALS(str1.c_str(), str2, location);
234 * Test whether two strings are equal.
235 * @param[in] str1 The first string
236 * @param[in] str2 The second string
237 * @param[in] location The TEST_LOCATION macro should be used here
239 void DALI_TEST_EQUALS( const char* str1, const std::string &str2, const char* location)
241 DALI_TEST_EQUALS(str1, str2.c_str(), location);
246 * Test whether one unsigned integer value is greater than another.
247 * Test succeeds if value1 > value2
248 * @param[in] value1 The first value
249 * @param[in] value2 The second value
250 * @param[in] location The TEST_LOCATION macro should be used here
252 void DALI_TEST_GREATER(unsigned int value1, unsigned int value2, const char* location)
254 if (!(value1 > value2))
256 fprintf(stderr, "%s, checking %d > %d\n", location, value1, value2);
257 tet_result(TET_FAIL);
261 tet_result(TET_PASS);
266 * Test whether one float value is greater than another.
267 * Test succeeds if value1 > value2
268 * @param[in] value1 The first value
269 * @param[in] value2 The second value
270 * @param[in] location The TEST_LOCATION macro should be used here
272 void DALI_TEST_GREATER( float value1, float value2, const char* location)
274 if (!(value1 > value2))
276 fprintf(stderr, "%s, checking %f > %f\n", location, value1, value2);
277 tet_result(TET_FAIL);
281 tet_result(TET_PASS);
285 void DALI_TEST_ASSERT( DaliException& e, std::string conditionSubString, const char* location )
287 if( NULL == strstr( e.condition, conditionSubString.c_str() ) )
289 fprintf(stderr, "Expected substring '%s' : actual exception string '%s' : location %s\n", conditionSubString.c_str(), e.condition, location );
290 tet_result(TET_FAIL);
294 tet_result(TET_PASS);
298 // Functor to test whether an Applied signal is emitted
299 ConstraintAppliedCheck::ConstraintAppliedCheck( bool& signalReceived )
300 : mSignalReceived( signalReceived )
304 void ConstraintAppliedCheck::operator()( Constraint& constraint )
306 mSignalReceived = true;
309 void ConstraintAppliedCheck::Reset()
311 mSignalReceived = false;
314 void ConstraintAppliedCheck::CheckSignalReceived()
316 if ( !mSignalReceived )
318 fprintf(stderr, "Expected Applied signal was not received\n" );
319 tet_result( TET_FAIL );
323 tet_result( TET_PASS );
327 void ConstraintAppliedCheck::CheckSignalNotReceived()
329 if ( mSignalReceived )
331 fprintf(stderr, "Unexpected Applied signal was received\n" );
332 tet_result( TET_FAIL );
336 tet_result( TET_PASS );
340 BufferImage CreateBufferImage(int width, int height, const Vector4& color)
342 BufferImage image = BufferImage::New(width, height, Pixel::RGBA8888);
344 PixelBuffer* pixbuf = image.GetBuffer();
346 // Using a 4x4 image gives a better blend with the GL implementation
348 for(size_t i=0; i<16; i++)
350 pixbuf[i*4+0] = color.r*255;
351 pixbuf[i*4+1] = color.g*255;
352 pixbuf[i*4+2] = color.b*255;
353 pixbuf[i*4+3] = color.a*255;
359 BufferImage CreateBufferImage()
361 return CreateBufferImage(4, 4, Color::WHITE);