2 * Copyright (c) 2014 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/dali.h>
22 #include "dali-test-suite-utils.h"
26 int test_return_value = TET_UNDEF;
28 void tet_result(int value)
30 // First TET_PASS should set to zero
31 // first TET_FAIL should prevent any further TET_PASS from setting back to zero
32 // Any TET_FAIL should set to fail or leave as fail
33 if( test_return_value != 1 )
34 test_return_value = value;
38 return ((test_return_value>0)?1:0)
41 void tet_infoline(const char* str)
43 fprintf(stderr, "%s\n", str);
46 void tet_printf(const char *format, ...)
49 va_start(arg, format);
50 vfprintf(stderr, format, arg);
55 * DALI_TEST_CHECK is a wrapper for tet_result.
56 * If the condition evaluates to false, then the function & line number is printed.
57 * @param[in] The boolean expression to check
59 #define DALI_TEST_CHECK(condition) \
62 tet_result(TET_PASS); \
66 fprintf(stderr, "%s Failed in %s at line %d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); \
67 tet_result(TET_FAIL); \
70 bool operator==(TimePeriod a, TimePeriod b)
72 return Equals(a.durationSeconds, b.durationSeconds) && Equals(a.delaySeconds, b.delaySeconds) ;
75 std::ostream& operator<< (std::ostream& o, const TimePeriod value)
77 return o << "( Duration:" << value.durationSeconds << " Delay:" << value.delaySeconds << ")";
80 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, const char* location)
82 const float* m1 = matrix1.AsFloat();
83 const float* m2 = matrix2.AsFloat();
84 bool equivalent = true;
88 equivalent &= (m1[i] != m2[i]);
93 fprintf(stderr, "%s, checking\n"
94 "(%f, %f, %f) (%f, %f, %f)\n"
95 "(%f, %f, %f) == (%f, %f, %f)\n"
96 "(%f, %f, %f) (%f, %f, %f)\n",
98 m1[0], m1[1], m1[2], m2[0], m2[1], m2[2],
99 m1[3], m1[4], m1[5], m2[3], m2[4], m2[5],
100 m1[6], m1[7], m1[8], m2[6], m2[7], m2[8]);
102 tet_result(TET_FAIL);
106 tet_result(TET_PASS);
110 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, float epsilon, const char* location)
112 const float* m1 = matrix1.AsFloat();
113 const float* m2 = matrix2.AsFloat();
114 bool equivalent = true;
116 for (int i=0;i<9;++i)
118 equivalent &= (fabsf(m1[i] - m2[i])<epsilon);
123 fprintf(stderr, "%s, checking\n"
124 "(%f, %f, %f) (%f, %f, %f)\n"
125 "(%f, %f, %f) == (%f, %f, %f)\n"
126 "(%f, %f, %f) (%f, %f, %f)\n",
128 m1[0], m1[1], m1[2], m2[0], m2[1], m2[2],
129 m1[3], m1[4], m1[5], m2[3], m2[4], m2[5],
130 m1[6], m1[7], m1[8], m2[6], m2[7], m2[8]);
132 tet_result(TET_FAIL);
136 tet_result(TET_PASS);
140 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, const char* location)
142 const float* m1 = matrix1.AsFloat();
143 const float* m2 = matrix2.AsFloat();
144 bool identical = true;
158 fprintf(stderr, "%s, checking\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"
162 "(%f, %f, %f, %f) (%f, %f, %f, %f)\n", location,
163 m1[0], m1[1], m1[2], m1[3], m2[0], m2[1], m2[2], m2[3],
164 m1[4], m1[5], m1[6], m1[7], m2[4], m2[5], m2[6], m2[7],
165 m1[8], m1[9], m1[10], m1[11], m2[8], m2[9], m2[10], m2[11],
166 m1[12], m1[13], m1[14], m1[15], m2[12], m2[13], m2[14], m2[15]);
168 tet_result(TET_FAIL);
172 tet_result(TET_PASS);
176 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, float epsilon, const char* location)
178 const float* m1 = matrix1.AsFloat();
179 const float* m2 = matrix2.AsFloat();
180 bool equivalent = true;
182 for (int i=0;i<16;++i)
184 equivalent &= (fabsf(m1[i] - m2[i])<epsilon);
189 fprintf(stderr, "%s, checking\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"
193 "(%f, %f, %f, %f) (%f, %f, %f, %f)\n", location,
194 m1[0], m1[1], m1[2], m1[3], m2[0], m2[1], m2[2], m2[3],
195 m1[4], m1[5], m1[6], m1[7], m2[4], m2[5], m2[6], m2[7],
196 m1[8], m1[9], m1[10], m1[11], m2[8], m2[9], m2[10], m2[11],
197 m1[12], m1[13], m1[14], m1[15], m2[12], m2[13], m2[14], m2[15]);
199 tet_result(TET_FAIL);
203 tet_result(TET_PASS);
209 * Test whether two strings are equal.
210 * @param[in] str1 The first string
211 * @param[in] str2 The second string
212 * @param[in] location The TEST_LOCATION macro should be used here
214 void DALI_TEST_EQUALS( const std::string &str1, const char* str2, const char* location)
216 DALI_TEST_EQUALS(str1.c_str(), str2, location);
220 * Test whether two strings are equal.
221 * @param[in] str1 The first string
222 * @param[in] str2 The second string
223 * @param[in] location The TEST_LOCATION macro should be used here
225 void DALI_TEST_EQUALS( const char* str1, const std::string &str2, const char* location)
227 DALI_TEST_EQUALS(str1, str2.c_str(), location);
232 * Test whether one unsigned integer value is greater than another.
233 * Test succeeds if value1 > value2
234 * @param[in] value1 The first value
235 * @param[in] value2 The second value
236 * @param[in] location The TEST_LOCATION macro should be used here
238 void DALI_TEST_GREATER(unsigned int value1, unsigned int value2, const char* location)
240 if (!(value1 > value2))
242 fprintf(stderr, "%s, checking %d > %d\n", location, value1, value2);
243 tet_result(TET_FAIL);
247 tet_result(TET_PASS);
252 * Test whether one float value is greater than another.
253 * Test succeeds if value1 > value2
254 * @param[in] value1 The first value
255 * @param[in] value2 The second value
256 * @param[in] location The TEST_LOCATION macro should be used here
258 void DALI_TEST_GREATER( float value1, float value2, const char* location)
260 if (!(value1 > value2))
262 fprintf(stderr, "%s, checking %f > %f\n", location, value1, value2);
263 tet_result(TET_FAIL);
267 tet_result(TET_PASS);
272 * Test whether the assertion condition that failed and thus triggered the
273 * exception \b e contained a given substring at the start of its literal text.
274 * @param[in] e The exception that we expect was fired by a runtime assertion
276 * @param[in] conditionSubString The text that we expect to be present in an
277 * assertion which triggered the exception.
278 * @param[in] location The TEST_LOCATION macro should be used here.
280 * @remark **Side-effects:** The result of the tet test is set to TET_PASS if
281 * the substring is at the start of the exception's condition and
282 * TET_FAIL if it isn't. Note, if the result of a test is set multiple
283 * times, a TET_FAIL will override any number of TET_PASSes.
285 void DALI_TEST_ASSERT( DaliException& e, std::string conditionSubString, const char* location )
287 if( 0u != e.mCondition.find( conditionSubString ))
289 fprintf(stderr, "Assertion %s failed at %s\n", conditionSubString.c_str(), location);
290 tet_result(TET_FAIL);
294 tet_result(TET_PASS);
298 /** Self-documenting wrapper for DALI_TEST_ASSERT.
299 * @copydoc DALI_TEST_ASSERT()
301 void DALI_TEST_ASSERT_CONDITION_STARTS_WITH_SUBSTRING( DaliException& exceptionFromAssertion, std::string conditionSubString, const char* location )
303 DALI_TEST_ASSERT(exceptionFromAssertion, conditionSubString, location);
306 // Functor to test whether an Applied signal is emitted
307 ConstraintAppliedCheck::ConstraintAppliedCheck( bool& signalReceived )
308 : mSignalReceived( signalReceived )
312 void ConstraintAppliedCheck::operator()( ActiveConstraint& constraint )
314 mSignalReceived = true;
317 void ConstraintAppliedCheck::Reset()
319 mSignalReceived = false;
322 void ConstraintAppliedCheck::CheckSignalReceived()
324 if ( !mSignalReceived )
326 fprintf(stderr, "Expected Applied signal was not received\n" );
327 tet_result( TET_FAIL );
331 tet_result( TET_PASS );
335 void ConstraintAppliedCheck::CheckSignalNotReceived()
337 if ( mSignalReceived )
339 fprintf(stderr, "Unexpected Applied signal was received\n" );
340 tet_result( TET_FAIL );
344 tet_result( TET_PASS );
349 BitmapImage CreateBitmapImage(int width, int height, const Vector4& color)
351 BitmapImage image = BitmapImage::New(width, height, Pixel::RGBA8888);
353 PixelBuffer* pixbuf = image.GetBuffer();
355 // Using a 4x4 image gives a better blend with the GL implementation
357 for(size_t i=0; i<16; i++)
359 pixbuf[i*4+0] = color.r*255;
360 pixbuf[i*4+1] = color.g*255;
361 pixbuf[i*4+2] = color.b*255;
362 pixbuf[i*4+3] = color.a*255;
368 BitmapImage CreateBitmapImage()
370 return CreateBitmapImage(4, 4, Color::WHITE);