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/public-api/dali-core.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);
54 bool operator==(TimePeriod a, TimePeriod b)
56 return Equals(a.durationSeconds, b.durationSeconds) && Equals(a.delaySeconds, b.delaySeconds) ;
59 std::ostream& operator<< (std::ostream& o, const TimePeriod value)
61 return o << "( Duration:" << value.durationSeconds << " Delay:" << value.delaySeconds << ")";
64 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, const char* location)
66 const float* m1 = matrix1.AsFloat();
67 const float* m2 = matrix2.AsFloat();
68 bool equivalent = true;
72 equivalent &= (m1[i] != m2[i]);
77 fprintf(stderr, "%s, checking\n"
78 "(%f, %f, %f) (%f, %f, %f)\n"
79 "(%f, %f, %f) == (%f, %f, %f)\n"
80 "(%f, %f, %f) (%f, %f, %f)\n",
82 m1[0], m1[1], m1[2], m2[0], m2[1], m2[2],
83 m1[3], m1[4], m1[5], m2[3], m2[4], m2[5],
84 m1[6], m1[7], m1[8], m2[6], m2[7], m2[8]);
94 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, float epsilon, 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 &= (fabsf(m1[i] - m2[i])<epsilon);
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 Matrix& matrix1, const Matrix& matrix2, const char* location)
126 const float* m1 = matrix1.AsFloat();
127 const float* m2 = matrix2.AsFloat();
128 bool identical = true;
142 fprintf(stderr, "%s, checking\n"
143 "(%f, %f, %f, %f) (%f, %f, %f, %f)\n"
144 "(%f, %f, %f, %f) == (%f, %f, %f, %f)\n"
145 "(%f, %f, %f, %f) (%f, %f, %f, %f)\n"
146 "(%f, %f, %f, %f) (%f, %f, %f, %f)\n", location,
147 m1[0], m1[1], m1[2], m1[3], m2[0], m2[1], m2[2], m2[3],
148 m1[4], m1[5], m1[6], m1[7], m2[4], m2[5], m2[6], m2[7],
149 m1[8], m1[9], m1[10], m1[11], m2[8], m2[9], m2[10], m2[11],
150 m1[12], m1[13], m1[14], m1[15], m2[12], m2[13], m2[14], m2[15]);
152 tet_result(TET_FAIL);
156 tet_result(TET_PASS);
160 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, float epsilon, const char* location)
162 const float* m1 = matrix1.AsFloat();
163 const float* m2 = matrix2.AsFloat();
164 bool equivalent = true;
166 for (int i=0;i<16;++i)
168 equivalent &= (fabsf(m1[i] - m2[i])<epsilon);
173 fprintf(stderr, "%s, checking\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"
177 "(%f, %f, %f, %f) (%f, %f, %f, %f)\n", location,
178 m1[0], m1[1], m1[2], m1[3], m2[0], m2[1], m2[2], m2[3],
179 m1[4], m1[5], m1[6], m1[7], m2[4], m2[5], m2[6], m2[7],
180 m1[8], m1[9], m1[10], m1[11], m2[8], m2[9], m2[10], m2[11],
181 m1[12], m1[13], m1[14], m1[15], m2[12], m2[13], m2[14], m2[15]);
183 tet_result(TET_FAIL);
187 tet_result(TET_PASS);
193 * Test whether two strings are equal.
194 * @param[in] str1 The first string
195 * @param[in] str2 The second string
196 * @param[in] location The TEST_LOCATION macro should be used here
198 void DALI_TEST_EQUALS( const std::string &str1, const char* str2, const char* location)
200 DALI_TEST_EQUALS(str1.c_str(), str2, location);
204 * Test whether two strings are equal.
205 * @param[in] str1 The first string
206 * @param[in] str2 The second string
207 * @param[in] location The TEST_LOCATION macro should be used here
209 void DALI_TEST_EQUALS( const char* str1, const std::string &str2, const char* location)
211 DALI_TEST_EQUALS(str1, str2.c_str(), location);
216 * Test whether one unsigned integer value is greater than another.
217 * Test succeeds if value1 > value2
218 * @param[in] value1 The first value
219 * @param[in] value2 The second value
220 * @param[in] location The TEST_LOCATION macro should be used here
222 void DALI_TEST_GREATER(unsigned int value1, unsigned int value2, const char* location)
224 if (!(value1 > value2))
226 fprintf(stderr, "%s, checking %d > %d\n", location, value1, value2);
227 tet_result(TET_FAIL);
231 tet_result(TET_PASS);
236 * Test whether one float value is greater than another.
237 * Test succeeds if value1 > value2
238 * @param[in] value1 The first value
239 * @param[in] value2 The second value
240 * @param[in] location The TEST_LOCATION macro should be used here
242 void DALI_TEST_GREATER( float value1, float value2, const char* location)
244 if (!(value1 > value2))
246 fprintf(stderr, "%s, checking %f > %f\n", location, value1, value2);
247 tet_result(TET_FAIL);
251 tet_result(TET_PASS);
255 void DALI_TEST_ASSERT( DaliException& e, std::string conditionSubString, const char* location )
257 if( NULL == strstr( e.condition, conditionSubString.c_str() ) )
259 fprintf(stderr, "Expected substring '%s' : actual exception string '%s' : location %s\n", conditionSubString.c_str(), e.condition, location );
260 tet_result(TET_FAIL);
264 tet_result(TET_PASS);
268 // Functor to test whether an Applied signal is emitted
269 ConstraintAppliedCheck::ConstraintAppliedCheck( bool& signalReceived )
270 : mSignalReceived( signalReceived )
274 void ConstraintAppliedCheck::operator()( ActiveConstraint& constraint )
276 mSignalReceived = true;
279 void ConstraintAppliedCheck::Reset()
281 mSignalReceived = false;
284 void ConstraintAppliedCheck::CheckSignalReceived()
286 if ( !mSignalReceived )
288 fprintf(stderr, "Expected Applied signal was not received\n" );
289 tet_result( TET_FAIL );
293 tet_result( TET_PASS );
297 void ConstraintAppliedCheck::CheckSignalNotReceived()
299 if ( mSignalReceived )
301 fprintf(stderr, "Unexpected Applied signal was received\n" );
302 tet_result( TET_FAIL );
306 tet_result( TET_PASS );
310 BufferImage CreateBufferImage()
312 BufferImage image = BufferImage::New(4,4,Pixel::RGBA8888);
314 PixelBuffer* pixbuf = image.GetBuffer();
316 // Using a 4x4 image gives a better blend with the GL implementation
318 for(size_t i=0; i<16; i++)
320 pixbuf[i*4+0] = 0xFF;
321 pixbuf[i*4+1] = 0xFF;
322 pixbuf[i*4+2] = 0xFF;
323 pixbuf[i*4+3] = 0xFF;