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"
26 #include <dali/public-api/dali-core.h>
30 int test_return_value = TET_UNDEF;
32 void tet_result(int value)
34 // First TET_PASS should set to zero
35 // first TET_FAIL should prevent any further TET_PASS from setting back to zero
36 // Any TET_FAIL should set to fail or leave as fail
37 if( test_return_value != 1 )
38 test_return_value = value;
42 return ((test_return_value>0)?1:0)
45 void tet_infoline(const char* str)
47 fprintf(stderr, "%s\n", str);
50 void tet_printf(const char *format, ...)
53 va_start(arg, format);
54 vfprintf(stderr, format, arg);
59 * DALI_TEST_CHECK is a wrapper for tet_result.
60 * If the condition evaluates to false, then the function & line number is printed.
61 * @param[in] The boolean expression to check
63 #define DALI_TEST_CHECK(condition) \
66 tet_result(TET_PASS); \
70 fprintf(stderr, "%s Failed in %s at line %d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); \
71 tet_result(TET_FAIL); \
74 bool operator==(TimePeriod a, TimePeriod b)
76 return Equals(a.durationSeconds, b.durationSeconds) && Equals(a.delaySeconds, b.delaySeconds) ;
79 std::ostream& operator<<( std::ostream& ostream, TimePeriod value )
81 return ostream << "( Duration:" << value.durationSeconds << " Delay:" << value.delaySeconds << ")";
84 std::ostream& operator<<( std::ostream& ostream, Radian angle )
86 ostream << angle.radian;
90 std::ostream& operator<<( std::ostream& ostream, Degree angle )
92 ostream << angle.degree;
96 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, const char* location)
98 const float* m1 = matrix1.AsFloat();
99 const float* m2 = matrix2.AsFloat();
100 bool equivalent = true;
102 for (int i=0;i<9;++i)
104 equivalent &= (fabsf(m1[i] - m2[i])< GetRangedEpsilon(m1[i], m2[i]));
109 fprintf(stderr, "%s, checking\n"
110 "(%f, %f, %f) (%f, %f, %f)\n"
111 "(%f, %f, %f) == (%f, %f, %f)\n"
112 "(%f, %f, %f) (%f, %f, %f)\n",
114 m1[0], m1[1], m1[2], m2[0], m2[1], m2[2],
115 m1[3], m1[4], m1[5], m2[3], m2[4], m2[5],
116 m1[6], m1[7], m1[8], m2[6], m2[7], m2[8]);
118 tet_result(TET_FAIL);
122 tet_result(TET_PASS);
126 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, float epsilon, const char* location)
128 const float* m1 = matrix1.AsFloat();
129 const float* m2 = matrix2.AsFloat();
130 bool equivalent = true;
132 for (int i=0;i<9;++i)
134 equivalent &= (fabsf(m1[i] - m2[i])<epsilon);
139 fprintf(stderr, "%s, checking\n"
140 "(%f, %f, %f) (%f, %f, %f)\n"
141 "(%f, %f, %f) == (%f, %f, %f)\n"
142 "(%f, %f, %f) (%f, %f, %f)\n",
144 m1[0], m1[1], m1[2], m2[0], m2[1], m2[2],
145 m1[3], m1[4], m1[5], m2[3], m2[4], m2[5],
146 m1[6], m1[7], m1[8], m2[6], m2[7], m2[8]);
148 tet_result(TET_FAIL);
152 tet_result(TET_PASS);
156 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, const char* location)
158 const float* m1 = matrix1.AsFloat();
159 const float* m2 = matrix2.AsFloat();
160 bool identical = true;
174 fprintf(stderr, "%s, checking\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"
178 "(%f, %f, %f, %f) == (%f, %f, %f, %f)\n", location,
179 m1[0], m1[1], m1[2], m1[3], m2[0], m2[1], m2[2], m2[3],
180 m1[4], m1[5], m1[6], m1[7], m2[4], m2[5], m2[6], m2[7],
181 m1[8], m1[9], m1[10], m1[11], m2[8], m2[9], m2[10], m2[11],
182 m1[12], m1[13], m1[14], m1[15], m2[12], m2[13], m2[14], m2[15]);
184 tet_result(TET_FAIL);
188 tet_result(TET_PASS);
192 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, float epsilon, const char* location)
194 const float* m1 = matrix1.AsFloat();
195 const float* m2 = matrix2.AsFloat();
196 bool equivalent = true;
198 for (int i=0;i<16;++i)
200 equivalent &= (fabsf(m1[i] - m2[i])<epsilon);
205 fprintf(stderr, "%s, checking\n"
206 "(%f, %f, %f, %f) == (%f, %f, %f, %f)\n"
207 "(%f, %f, %f, %f) == (%f, %f, %f, %f)\n"
208 "(%f, %f, %f, %f) == (%f, %f, %f, %f)\n"
209 "(%f, %f, %f, %f) == (%f, %f, %f, %f)\n", location,
210 m1[0], m1[1], m1[2], m1[3], m2[0], m2[1], m2[2], m2[3],
211 m1[4], m1[5], m1[6], m1[7], m2[4], m2[5], m2[6], m2[7],
212 m1[8], m1[9], m1[10], m1[11], m2[8], m2[9], m2[10], m2[11],
213 m1[12], m1[13], m1[14], m1[15], m2[12], m2[13], m2[14], m2[15]);
215 tet_result(TET_FAIL);
219 tet_result(TET_PASS);
225 * Test whether two strings are equal.
226 * @param[in] str1 The first string
227 * @param[in] str2 The second string
228 * @param[in] location The TEST_LOCATION macro should be used here
230 void DALI_TEST_EQUALS( const std::string &str1, const char* str2, const char* location)
232 DALI_TEST_EQUALS(str1.c_str(), str2, location);
236 * Test whether two strings are equal.
237 * @param[in] str1 The first string
238 * @param[in] str2 The second string
239 * @param[in] location The TEST_LOCATION macro should be used here
241 void DALI_TEST_EQUALS( const char* str1, const std::string &str2, const char* location)
243 DALI_TEST_EQUALS(str1, str2.c_str(), location);
246 void DALI_TEST_ASSERT( DaliException& e, std::string conditionSubString, const char* location )
248 if( NULL == strstr( e.condition, conditionSubString.c_str() ) )
250 fprintf(stderr, "Expected substring '%s' : actual exception string '%s' : location %s\n", conditionSubString.c_str(), e.condition, location );
251 tet_result(TET_FAIL);
255 tet_result(TET_PASS);
259 // Functor to test whether an Applied signal is emitted
260 ConstraintAppliedCheck::ConstraintAppliedCheck( bool& signalReceived )
261 : mSignalReceived( signalReceived )
265 void ConstraintAppliedCheck::operator()( Constraint& constraint )
267 mSignalReceived = true;
270 void ConstraintAppliedCheck::Reset()
272 mSignalReceived = false;
275 void ConstraintAppliedCheck::CheckSignalReceived()
277 if ( !mSignalReceived )
279 fprintf(stderr, "Expected Applied signal was not received\n" );
280 tet_result( TET_FAIL );
284 tet_result( TET_PASS );
288 void ConstraintAppliedCheck::CheckSignalNotReceived()
290 if ( mSignalReceived )
292 fprintf(stderr, "Unexpected Applied signal was received\n" );
293 tet_result( TET_FAIL );
297 tet_result( TET_PASS );
301 BufferImage CreateBufferImage()
303 BufferImage image = BufferImage::New(4,4,Pixel::RGBA8888);
305 PixelBuffer* pixbuf = image.GetBuffer();
307 // Using a 4x4 image gives a better blend with the GL implementation
309 for(size_t i=0; i<16; i++)
311 pixbuf[i*4+0] = 0xFF;
312 pixbuf[i*4+1] = 0xFF;
313 pixbuf[i*4+2] = 0xFF;
314 pixbuf[i*4+3] = 0xFF;