2 * Copyright (c) 2020 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 int32_t test_return_value = TET_UNDEF;
31 void tet_result(int32_t 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)
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 bool operator==(TimePeriod a, TimePeriod b)
61 return Equals(a.durationSeconds, b.durationSeconds) && Equals(a.delaySeconds, b.delaySeconds);
64 std::ostream& operator<<(std::ostream& ostream, TimePeriod value)
66 return ostream << "( Duration:" << value.durationSeconds << " Delay:" << value.delaySeconds << ")";
69 std::ostream& operator<<(std::ostream& ostream, Radian angle)
71 ostream << angle.radian;
75 std::ostream& operator<<(std::ostream& ostream, Degree angle)
77 ostream << angle.degree;
81 std::ostream& operator<<(std::ostream& ostream, BaseHandle handle)
83 return ostream << static_cast<void*>(handle.GetObjectPtr());
86 void DALI_TEST_EQUALS(const BaseHandle& baseHandle1, const BaseHandle& baseHandle2, const char* location)
88 DALI_TEST_EQUALS<const BaseHandle&>(baseHandle1, baseHandle2, location);
91 void DALI_TEST_EQUALS(const size_t value1, const uint32_t value2, const char* location)
93 DALI_TEST_EQUALS<uint32_t>((uint32_t)(value1), value2, location);
96 void DALI_TEST_EQUALS(const uint32_t value1, const size_t value2, const char* location)
98 DALI_TEST_EQUALS<uint32_t>(value1, (uint32_t)(value2), location);
101 void DALI_TEST_EQUALS(const Matrix3& matrix1, const Matrix3& matrix2, const char* location)
103 const float* m1 = matrix1.AsFloat();
104 const float* m2 = matrix2.AsFloat();
105 bool equivalent = true;
107 for(int32_t i = 0; i < 9; ++i)
109 if(!(fabsf(m1[i] - m2[i]) < GetRangedEpsilon(m1[i], m2[i])))
117 // Align each float to 1234.67, i.e. 3.6 will be " 3.60"
119 fprintf(stderr, "%s, checking\n"
120 "%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n"
121 "%7.2f %7.2f %7.2f == %7.2f %7.2f %7.2f\n"
122 "%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n",
124 m1[0],m1[3],m1[6],m2[0],m2[3],m2[6],
125 m1[1],m1[4],m1[7],m2[1],m2[4],m2[7],
126 m1[2],m1[5],m1[8],m2[2],m2[5],m2[8]);
129 tet_result(TET_FAIL);
134 tet_result(TET_PASS);
138 void DALI_TEST_EQUALS(const Matrix3& matrix1, const Matrix3& matrix2, float epsilon, const char* location)
140 const float* m1 = matrix1.AsFloat();
141 const float* m2 = matrix2.AsFloat();
142 bool equivalent = true;
144 for(int32_t i = 0; i < 9; ++i)
146 equivalent &= (fabsf(m1[i] - m2[i]) < epsilon);
151 // Align each float to 1234.67, i.e. 3.6 will be " 3.60"
153 fprintf(stderr, "%s, checking\n"
154 "%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n"
155 "%7.2f %7.2f %7.2f == %7.2f %7.2f %7.2f\n"
156 "%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n",
158 m1[0],m1[3],m1[6],m2[0],m2[3],m2[6],
159 m1[1],m1[4],m1[7],m2[1],m2[4],m2[7],
160 m1[2],m1[5],m1[8],m2[2],m2[5],m2[8]);
163 tet_result(TET_FAIL);
168 tet_result(TET_PASS);
172 void DALI_TEST_EQUALS(const Matrix& matrix1, const Matrix& matrix2, const char* location)
174 const float* m1 = matrix1.AsFloat();
175 const float* m2 = matrix2.AsFloat();
176 bool identical = true;
179 for(i = 0; i < 16; ++i)
190 // Align each float to 1234.67, i.e. 3.6 will be " 3.60"
192 fprintf(stderr, "%s, checking\n"
193 "%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n"
194 "%7.2f %7.2f %7.2f %7.2f == %7.2f %7.2f %7.2f %7.2f\n"
195 "%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n"
196 "%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n",
198 m1[0],m1[4],m1[8],m1[12],m2[0],m2[4],m2[8],m2[12],
199 m1[1],m1[5],m1[9],m1[13],m2[1],m2[5],m2[9],m2[13],
200 m1[2],m1[6],m1[10],m1[14],m2[2],m2[6],m2[10],m2[14],
201 m1[3],m1[7],m1[11],m1[15],m2[3],m2[7],m2[11],m2[15]);
204 tet_result(TET_FAIL);
209 tet_result(TET_PASS);
213 void DALI_TEST_EQUALS(const Matrix& matrix1, const Matrix& matrix2, float epsilon, const char* location)
215 const float* m1 = matrix1.AsFloat();
216 const float* m2 = matrix2.AsFloat();
217 bool equivalent = true;
219 for(int32_t i = 0; i < 16; ++i)
221 equivalent &= (fabsf(m1[i] - m2[i]) < epsilon);
226 // Align each float to 1234.67, i.e. 3.6 will be " 3.60"
228 fprintf(stderr, "%s, checking\n"
229 "%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n"
230 "%7.2f %7.2f %7.2f %7.2f == %7.2f %7.2f %7.2f %7.2f\n"
231 "%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n"
232 "%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n",
234 m1[0],m1[4],m1[8],m1[12],m2[0],m2[4],m2[8],m2[12],
235 m1[1],m1[5],m1[9],m1[13],m2[1],m2[5],m2[9],m2[13],
236 m1[2],m1[6],m1[10],m1[14],m2[2],m2[6],m2[10],m2[14],
237 m1[3],m1[7],m1[11],m1[15],m2[3],m2[7],m2[11],m2[15]);
240 tet_result(TET_FAIL);
245 tet_result(TET_PASS);
250 * Test whether two strings are equal.
251 * @param[in] str1 The first string
252 * @param[in] str2 The second string
253 * @param[in] location The TEST_LOCATION macro should be used here
255 void DALI_TEST_EQUALS(const std::string& str1, const char* str2, const char* location)
257 DALI_TEST_EQUALS(str1.c_str(), str2, location);
260 void DALI_TEST_EQUALS(Property::Value& str1, const char* str2, const char* location)
264 if(str1.GetType() == Property::STRING)
268 result = !string.compare(str2);
273 tet_result(TET_PASS);
277 tet_result(TET_FAIL);
282 void DALI_TEST_EQUALS(const char* str1, const std::string& str2, const char* location)
284 DALI_TEST_EQUALS(str1, str2.c_str(), location);
287 void DALI_TEST_ASSERT(DaliException& e, std::string conditionSubString, const char* location)
289 if(NULL == strstr(e.condition, conditionSubString.c_str()))
291 fprintf(stderr, "Expected substring '%s' : actual exception string '%s' : location %s\n", conditionSubString.c_str(), e.condition, location);
292 tet_result(TET_FAIL);
297 tet_result(TET_PASS);
301 // Functor to test whether an Applied signal is emitted
302 ConstraintAppliedCheck::ConstraintAppliedCheck(bool& signalReceived)
303 : mSignalReceived(signalReceived)
307 void ConstraintAppliedCheck::operator()(Constraint& constraint)
309 mSignalReceived = true;
312 void ConstraintAppliedCheck::Reset()
314 mSignalReceived = false;
317 void ConstraintAppliedCheck::CheckSignalReceived()
321 fprintf(stderr, "Expected Applied signal was not received\n");
322 tet_result(TET_FAIL);
327 tet_result(TET_PASS);
331 void ConstraintAppliedCheck::CheckSignalNotReceived()
335 fprintf(stderr, "Unexpected Applied signal was received\n");
336 tet_result(TET_FAIL);
341 tet_result(TET_PASS);
347 struct ObjectDestructionFunctor
349 // Create a ObjectDestructionFunctor passing in a Dali::RefObject* to be monitored and a bool variable.
350 // Create ObjectRegistry instance and connect to the ObjectDestroyedSignal passing in the above functor for the callback.
351 // Get the ObjectPointer (Actor::GetObjectPtr) of the Actor to be checked for destruction and assign it to the Dali::RefObject*
352 // Check the bool variable which would be true when object destroyed.
353 ObjectDestructionFunctor(Dali::RefObject* objectPtr, bool& refObjectDestroyed)
354 : refObjectPointerToCheck(objectPtr),
355 refObjectDestroyedBoolean(refObjectDestroyed)
357 refObjectDestroyed = false;
360 void operator()(const Dali::RefObject* objectPointer)
362 if(refObjectPointerToCheck == objectPointer)
364 refObjectDestroyedBoolean = true;
368 Dali::RefObject* refObjectPointerToCheck;
369 bool& refObjectDestroyedBoolean;
372 ObjectDestructionTracker::ObjectDestructionTracker(ObjectRegistry objectRegistry)
373 : mObjectRegistry(objectRegistry),
374 mRefObjectDestroyed(false)
378 void ObjectDestructionTracker::Start(Actor actor)
380 ObjectDestructionFunctor destructionFunctor(actor.GetObjectPtr(), mRefObjectDestroyed);
381 mObjectRegistry.ObjectDestroyedSignal().Connect(this, destructionFunctor);
384 bool ObjectDestructionTracker::IsDestroyed()
386 return mRefObjectDestroyed;