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.
19 #include "dali-test-suite-utils.h"
25 #include <dali/public-api/dali-core.h>
29 int test_return_value = TET_UNDEF;
31 void tet_result(int value)
33 // First TET_PASS should set to zero
34 // first TET_FAIL should prevent any further TET_PASS from setting back to zero
35 // Any TET_FAIL should set to fail or leave as fail
36 if( test_return_value != 1 )
37 test_return_value = value;
41 return ((test_return_value>0)?1:0)
44 void tet_infoline(const char* str)
46 fprintf(stderr, "%s\n", str);
49 void tet_printf(const char *format, ...)
52 va_start(arg, format);
53 vfprintf(stderr, format, arg);
57 bool operator==(TimePeriod a, TimePeriod b)
59 return Equals(a.durationSeconds, b.durationSeconds) && Equals(a.delaySeconds, b.delaySeconds) ;
62 std::ostream& operator<<( std::ostream& ostream, TimePeriod value )
64 return ostream << "( Duration:" << value.durationSeconds << " Delay:" << value.delaySeconds << ")";
67 std::ostream& operator<<( std::ostream& ostream, Radian angle )
69 ostream << angle.radian;
73 std::ostream& operator<<( std::ostream& ostream, Degree angle )
75 ostream << angle.degree;
79 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, const char* location)
81 const float* m1 = matrix1.AsFloat();
82 const float* m2 = matrix2.AsFloat();
83 bool equivalent = true;
87 equivalent &= (m1[i] != m2[i]);
92 fprintf(stderr, "%s, checking\n"
93 "(%f, %f, %f) (%f, %f, %f)\n"
94 "(%f, %f, %f) == (%f, %f, %f)\n"
95 "(%f, %f, %f) (%f, %f, %f)\n",
97 m1[0], m1[1], m1[2], m2[0], m2[1], m2[2],
98 m1[3], m1[4], m1[5], m2[3], m2[4], m2[5],
99 m1[6], m1[7], m1[8], m2[6], m2[7], m2[8]);
101 tet_result(TET_FAIL);
105 tet_result(TET_PASS);
109 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, float epsilon, const char* location)
111 const float* m1 = matrix1.AsFloat();
112 const float* m2 = matrix2.AsFloat();
113 bool equivalent = true;
115 for (int i=0;i<9;++i)
117 equivalent &= (fabsf(m1[i] - m2[i])<epsilon);
122 fprintf(stderr, "%s, checking\n"
123 "(%f, %f, %f) (%f, %f, %f)\n"
124 "(%f, %f, %f) == (%f, %f, %f)\n"
125 "(%f, %f, %f) (%f, %f, %f)\n",
127 m1[0], m1[1], m1[2], m2[0], m2[1], m2[2],
128 m1[3], m1[4], m1[5], m2[3], m2[4], m2[5],
129 m1[6], m1[7], m1[8], m2[6], m2[7], m2[8]);
131 tet_result(TET_FAIL);
135 tet_result(TET_PASS);
139 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, const char* location)
141 const float* m1 = matrix1.AsFloat();
142 const float* m2 = matrix2.AsFloat();
143 bool identical = true;
157 fprintf(stderr, "%s, checking\n"
158 "(%f, %f, %f, %f) (%f, %f, %f, %f)\n"
159 "(%f, %f, %f, %f) == (%f, %f, %f, %f)\n"
160 "(%f, %f, %f, %f) (%f, %f, %f, %f)\n"
161 "(%f, %f, %f, %f) (%f, %f, %f, %f)\n", location,
162 m1[0], m1[1], m1[2], m1[3], m2[0], m2[1], m2[2], m2[3],
163 m1[4], m1[5], m1[6], m1[7], m2[4], m2[5], m2[6], m2[7],
164 m1[8], m1[9], m1[10], m1[11], m2[8], m2[9], m2[10], m2[11],
165 m1[12], m1[13], m1[14], m1[15], m2[12], m2[13], m2[14], m2[15]);
167 tet_result(TET_FAIL);
171 tet_result(TET_PASS);
175 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, float epsilon, const char* location)
177 const float* m1 = matrix1.AsFloat();
178 const float* m2 = matrix2.AsFloat();
179 bool equivalent = true;
181 for (int i=0;i<16;++i)
183 equivalent &= (fabsf(m1[i] - m2[i])<epsilon);
188 fprintf(stderr, "%s, checking\n"
189 "(%f, %f, %f, %f) (%f, %f, %f, %f)\n"
190 "(%f, %f, %f, %f) == (%f, %f, %f, %f)\n"
191 "(%f, %f, %f, %f) (%f, %f, %f, %f)\n"
192 "(%f, %f, %f, %f) (%f, %f, %f, %f)\n", location,
193 m1[0], m1[1], m1[2], m1[3], m2[0], m2[1], m2[2], m2[3],
194 m1[4], m1[5], m1[6], m1[7], m2[4], m2[5], m2[6], m2[7],
195 m1[8], m1[9], m1[10], m1[11], m2[8], m2[9], m2[10], m2[11],
196 m1[12], m1[13], m1[14], m1[15], m2[12], m2[13], m2[14], m2[15]);
198 tet_result(TET_FAIL);
202 tet_result(TET_PASS);
208 * Test whether two strings are equal.
209 * @param[in] str1 The first string
210 * @param[in] str2 The second string
211 * @param[in] location The TEST_LOCATION macro should be used here
213 void DALI_TEST_EQUALS( const std::string &str1, const char* str2, const char* location)
215 DALI_TEST_EQUALS(str1.c_str(), str2, location);
219 * Test whether two strings are equal.
220 * @param[in] str1 The first string
221 * @param[in] str2 The second string
222 * @param[in] location The TEST_LOCATION macro should be used here
224 void DALI_TEST_EQUALS( const char* str1, const std::string &str2, const char* location)
226 DALI_TEST_EQUALS(str1, str2.c_str(), location);
231 * Test whether one unsigned integer value is greater than another.
232 * Test succeeds if value1 > value2
233 * @param[in] value1 The first value
234 * @param[in] value2 The second value
235 * @param[in] location The TEST_LOCATION macro should be used here
237 void DALI_TEST_GREATER(unsigned int value1, unsigned int value2, const char* location)
239 if (!(value1 > value2))
241 fprintf(stderr, "%s, checking %d > %d\n", location, value1, value2);
242 tet_result(TET_FAIL);
246 tet_result(TET_PASS);
251 * Test whether one float value is greater than another.
252 * Test succeeds if value1 > value2
253 * @param[in] value1 The first value
254 * @param[in] value2 The second value
255 * @param[in] location The TEST_LOCATION macro should be used here
257 void DALI_TEST_GREATER( float value1, float value2, const char* location)
259 if (!(value1 > value2))
261 fprintf(stderr, "%s, checking %f > %f\n", location, value1, value2);
262 tet_result(TET_FAIL);
266 tet_result(TET_PASS);
270 void DALI_TEST_ASSERT( DaliException& e, std::string conditionSubString, const char* location )
272 if( NULL == strstr( e.condition, conditionSubString.c_str() ) )
274 fprintf(stderr, "Expected substring '%s' : actual exception string '%s' : location %s\n", conditionSubString.c_str(), e.condition, location );
275 tet_result(TET_FAIL);
279 tet_result(TET_PASS);
283 // Functor to test whether an Applied signal is emitted
284 ConstraintAppliedCheck::ConstraintAppliedCheck( bool& signalReceived )
285 : mSignalReceived( signalReceived )
289 void ConstraintAppliedCheck::operator()( Constraint& constraint )
291 mSignalReceived = true;
294 void ConstraintAppliedCheck::Reset()
296 mSignalReceived = false;
299 void ConstraintAppliedCheck::CheckSignalReceived()
301 if ( !mSignalReceived )
303 fprintf(stderr, "Expected Applied signal was not received\n" );
304 tet_result( TET_FAIL );
308 tet_result( TET_PASS );
312 void ConstraintAppliedCheck::CheckSignalNotReceived()
314 if ( mSignalReceived )
316 fprintf(stderr, "Unexpected Applied signal was received\n" );
317 tet_result( TET_FAIL );
321 tet_result( TET_PASS );
325 BufferImage CreateBufferImage()
327 BufferImage image = BufferImage::New(4,4,Pixel::RGBA8888);
329 PixelBuffer* pixbuf = image.GetBuffer();
331 // Using a 4x4 image gives a better blend with the GL implementation
333 for(size_t i=0; i<16; i++)
335 pixbuf[i*4+0] = 0xFF;
336 pixbuf[i*4+1] = 0xFF;
337 pixbuf[i*4+2] = 0xFF;
338 pixbuf[i*4+3] = 0xFF;