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.
18 #include <dali-test-suite-utils.h>
19 #include <dali/public-api/dali-core.h>
26 ///////////////////////////////////////////////////////////////////////////////
27 void utc_dali_constraint_function_startup(void)
29 test_return_value = TET_UNDEF;
32 void utc_dali_constraint_function_cleanup(void)
34 test_return_value = TET_PASS;
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
41 bool gFunctionCalled = false;
44 void TestCallbackFunction(T& /* current*/, const PropertyInputContainer& /* inputs */)
46 gFunctionCalled = true;
50 struct TestCallbackFunctor
52 TestCallbackFunctor(bool& functorCalled)
53 : mFunctorCalled(functorCalled)
57 void operator()(T& /* current*/, const PropertyInputContainer& /* inputs */)
59 mFunctorCalled = true;
66 struct TestFunctorMethod
68 TestFunctorMethod(bool& functorCalled)
69 : mFunctorCalled(functorCalled)
73 void Method(T& /* current*/, const PropertyInputContainer& /* inputs */)
75 mFunctorCalled = true;
81 } // unnamed namespace
82 ///////////////////////////////////////////////////////////////////////////////
84 ///////////////////////////////////////////////////////////////////////////////
85 // Constraint::Function::Function( void( *function )( P&, const PropertyInputContainer& ) )
86 ///////////////////////////////////////////////////////////////////////////////
90 void TestFunctionConstructor()
92 gFunctionCalled = false;
93 Constraint::Function<T> function(&TestCallbackFunction<T>);
95 PropertyInputContainer inputs;
97 DALI_TEST_EQUALS(gFunctionCalled, false, TEST_LOCATION);
98 CallbackBase::Execute<T&, const PropertyInputContainer&>(function, current, inputs);
99 DALI_TEST_EQUALS(gFunctionCalled, true, TEST_LOCATION);
101 } // unnamed namespace
103 int UtcDaliConstraintFunctionWithFunction(void)
105 TestFunctionConstructor<bool>();
106 TestFunctionConstructor<int>();
107 TestFunctionConstructor<unsigned int>();
108 TestFunctionConstructor<float>();
109 TestFunctionConstructor<Vector2>();
110 TestFunctionConstructor<Vector3>();
111 TestFunctionConstructor<Vector4>();
112 TestFunctionConstructor<Quaternion>();
113 TestFunctionConstructor<Matrix>();
114 TestFunctionConstructor<Matrix3>();
117 ///////////////////////////////////////////////////////////////////////////////
119 ///////////////////////////////////////////////////////////////////////////////
120 // Constraint::Function::Function( const T& object )
121 ///////////////////////////////////////////////////////////////////////////////
125 void TestFunctorConstructor()
128 TestCallbackFunctor<T> functor(called);
129 Constraint::Function<T> callback(functor);
131 PropertyInputContainer inputs;
133 DALI_TEST_EQUALS(called, false, TEST_LOCATION);
134 CallbackBase::Execute<T&, const PropertyInputContainer&>(callback, current, inputs);
135 DALI_TEST_EQUALS(called, true, TEST_LOCATION);
137 } // unnamed namespace
139 int UtcDaliConstraintFunctionWithFunctor(void)
141 TestFunctorConstructor<bool>();
142 TestFunctorConstructor<int>();
143 TestFunctorConstructor<unsigned int>();
144 TestFunctorConstructor<float>();
145 TestFunctorConstructor<Vector2>();
146 TestFunctorConstructor<Vector3>();
147 TestFunctorConstructor<Vector4>();
148 TestFunctorConstructor<Quaternion>();
149 TestFunctorConstructor<Matrix>();
150 TestFunctorConstructor<Matrix3>();
153 ///////////////////////////////////////////////////////////////////////////////
155 ///////////////////////////////////////////////////////////////////////////////
156 // Constraint::Function::Function( const T& object, void ( T::*memberFunction ) ( P&, const PropertyInputContainer& ) )
157 ///////////////////////////////////////////////////////////////////////////////
161 void TestFunctorMethodConstructor()
164 TestFunctorMethod<T> functor(called);
165 Constraint::Function<T> callback(functor, &TestFunctorMethod<T>::Method);
167 PropertyInputContainer inputs;
169 DALI_TEST_EQUALS(called, false, TEST_LOCATION);
170 CallbackBase::Execute<T&, const PropertyInputContainer&>(callback, current, inputs);
171 DALI_TEST_EQUALS(called, true, TEST_LOCATION);
173 } // unnamed namespace
175 int UtcDaliConstraintFunctionWithMethodFunctor(void)
177 TestFunctorMethodConstructor<bool>();
178 TestFunctorMethodConstructor<int>();
179 TestFunctorMethodConstructor<unsigned int>();
180 TestFunctorMethodConstructor<float>();
181 TestFunctorMethodConstructor<Vector2>();
182 TestFunctorMethodConstructor<Vector3>();
183 TestFunctorMethodConstructor<Vector4>();
184 TestFunctorMethodConstructor<Quaternion>();
185 TestFunctorMethodConstructor<Matrix>();
186 TestFunctorMethodConstructor<Matrix3>();
189 ///////////////////////////////////////////////////////////////////////////////
191 ///////////////////////////////////////////////////////////////////////////////
192 // Constraint::Function::Clone
193 ///////////////////////////////////////////////////////////////////////////////
197 void TestFunctionClone()
199 gFunctionCalled = false;
200 Constraint::Function<T> callback(&TestCallbackFunction<T>);
201 CallbackBase* clone = callback.Clone();
204 PropertyInputContainer inputs;
206 DALI_TEST_EQUALS(gFunctionCalled, false, TEST_LOCATION);
207 CallbackBase::Execute<T&, const PropertyInputContainer&>(*clone, current, inputs);
208 DALI_TEST_EQUALS(gFunctionCalled, true, TEST_LOCATION);
213 void TestFunctorClone()
216 TestCallbackFunctor<T> functor(called);
217 Constraint::Function<T> callback(functor);
218 CallbackBase* clone = callback.Clone();
221 PropertyInputContainer inputs;
223 DALI_TEST_EQUALS(called, false, TEST_LOCATION);
224 CallbackBase::Execute<T&, const PropertyInputContainer&>(*clone, current, inputs);
225 DALI_TEST_EQUALS(called, true, TEST_LOCATION);
230 void TestMethodFunctorClone()
233 TestFunctorMethod<T> functor(called);
234 Constraint::Function<T> callback(functor, &TestFunctorMethod<T>::Method);
235 CallbackBase* clone = callback.Clone();
238 PropertyInputContainer inputs;
240 DALI_TEST_EQUALS(called, false, TEST_LOCATION);
241 CallbackBase::Execute<T&, const PropertyInputContainer&>(*clone, current, inputs);
242 DALI_TEST_EQUALS(called, true, TEST_LOCATION);
246 } // unnamed namespace
248 int UtcDaliConstraintFunctionFunctionClone(void)
250 TestFunctionClone<bool>();
251 TestFunctionClone<int>();
252 TestFunctionClone<unsigned int>();
253 TestFunctionClone<float>();
254 TestFunctionClone<Vector2>();
255 TestFunctionClone<Vector3>();
256 TestFunctionClone<Vector4>();
257 TestFunctionClone<Quaternion>();
258 TestFunctionClone<Matrix>();
259 TestFunctionClone<Matrix3>();
263 int UtcDaliConstraintFunctionFunctorClone(void)
265 TestFunctorClone<bool>();
266 TestFunctorClone<int>();
267 TestFunctorClone<unsigned int>();
268 TestFunctorClone<float>();
269 TestFunctorClone<Vector2>();
270 TestFunctorClone<Vector3>();
271 TestFunctorClone<Vector4>();
272 TestFunctorClone<Quaternion>();
273 TestFunctorClone<Matrix>();
274 TestFunctorClone<Matrix3>();
278 int UtcDaliConstraintFunctionMethodFunctorClone(void)
280 TestMethodFunctorClone<bool>();
281 TestMethodFunctorClone<int>();
282 TestMethodFunctorClone<unsigned int>();
283 TestMethodFunctorClone<float>();
284 TestMethodFunctorClone<Vector2>();
285 TestMethodFunctorClone<Vector3>();
286 TestMethodFunctorClone<Vector4>();
287 TestMethodFunctorClone<Quaternion>();
288 TestMethodFunctorClone<Matrix>();
289 TestMethodFunctorClone<Matrix3>();
292 ///////////////////////////////////////////////////////////////////////////////
294 ///////////////////////////////////////////////////////////////////////////////
299 CountFunctor(int& count)
305 CountFunctor(const CountFunctor& other)
306 : mCount(other.mCount)
311 CountFunctor& operator=(const CountFunctor& other)
313 this->mCount = other.mCount;
323 void operator()(bool& /* current*/, const PropertyInputContainer& /* inputs */)
329 } // unnamed namespace
331 int UtcDaliConstraintFunctionEnsureMemoryCleanup(void)
333 // Functors are new'd in Constraint::Function, so check that all memory is released at the end
338 CountFunctor functor(count);
339 Constraint::Function<bool> callback1(functor);
340 Constraint::Function<bool> callback2(functor);
341 Constraint::Function<bool> callback3(functor);
342 Constraint::Function<bool> callback4(functor);
343 Constraint::Function<bool> callback5(functor);
344 Constraint::Function<bool> callback6(functor);
345 Constraint::Function<bool> callback7(functor);
346 Constraint::Function<bool> callback8(functor);
347 Constraint::Function<bool> callback9(functor);
348 DALI_TEST_EQUALS(count, 10, TEST_LOCATION);
351 DALI_TEST_EQUALS(count, 0, TEST_LOCATION);
355 ///////////////////////////////////////////////////////////////////////////////