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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.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;
43 template< typename T >
44 void TestCallbackFunction( T& /* current*/ , const PropertyInputContainer& /* inputs */ )
46 gFunctionCalled = true;
49 template< typename T >
50 struct TestCallbackFunctor
52 TestCallbackFunctor( bool& functorCalled ) : mFunctorCalled( functorCalled ) { }
54 void operator()( T& /* current*/ , const PropertyInputContainer& /* inputs */ )
56 mFunctorCalled = true;
62 template< typename T >
63 struct TestFunctorMethod
65 TestFunctorMethod( bool& functorCalled ) : mFunctorCalled( functorCalled ) { }
67 void Method( T& /* current*/ , const PropertyInputContainer& /* inputs */ )
69 mFunctorCalled = true;
75 } // unnamed namespace
76 ///////////////////////////////////////////////////////////////////////////////
78 ///////////////////////////////////////////////////////////////////////////////
79 // Constraint::Function::Function( void( *function )( P&, const PropertyInputContainer& ) )
80 ///////////////////////////////////////////////////////////////////////////////
83 template< typename T >
84 void TestFunctionConstructor()
86 gFunctionCalled = false;
87 Constraint::Function< T > function( &TestCallbackFunction< T > );
89 PropertyInputContainer inputs;
91 DALI_TEST_EQUALS( gFunctionCalled, false, TEST_LOCATION );
92 CallbackBase::Execute< T&, const PropertyInputContainer& >( function, current, inputs );
93 DALI_TEST_EQUALS( gFunctionCalled, true, TEST_LOCATION );
95 } // unnamed namespace
97 int UtcDaliConstraintFunctionWithFunction(void)
99 TestFunctionConstructor< bool >();
100 TestFunctionConstructor< int >();
101 TestFunctionConstructor< unsigned int >();
102 TestFunctionConstructor< float >();
103 TestFunctionConstructor< Vector2 >();
104 TestFunctionConstructor< Vector3 >();
105 TestFunctionConstructor< Vector4 >();
106 TestFunctionConstructor< Quaternion >();
107 TestFunctionConstructor< Matrix >();
108 TestFunctionConstructor< Matrix3 >();
111 ///////////////////////////////////////////////////////////////////////////////
113 ///////////////////////////////////////////////////////////////////////////////
114 // Constraint::Function::Function( const T& object )
115 ///////////////////////////////////////////////////////////////////////////////
118 template< typename T >
119 void TestFunctorConstructor()
122 TestCallbackFunctor< T > functor( called );
123 Constraint::Function< T > callback( functor );
125 PropertyInputContainer inputs;
127 DALI_TEST_EQUALS( called, false, TEST_LOCATION );
128 CallbackBase::Execute< T&, const PropertyInputContainer& >( callback, current, inputs );
129 DALI_TEST_EQUALS( called, true, TEST_LOCATION );
131 } // unnamed namespace
133 int UtcDaliConstraintFunctionWithFunctor(void)
135 TestFunctorConstructor< bool >();
136 TestFunctorConstructor< int >();
137 TestFunctorConstructor< unsigned int >();
138 TestFunctorConstructor< float >();
139 TestFunctorConstructor< Vector2 >();
140 TestFunctorConstructor< Vector3 >();
141 TestFunctorConstructor< Vector4 >();
142 TestFunctorConstructor< Quaternion >();
143 TestFunctorConstructor< Matrix >();
144 TestFunctorConstructor< Matrix3 >();
147 ///////////////////////////////////////////////////////////////////////////////
149 ///////////////////////////////////////////////////////////////////////////////
150 // Constraint::Function::Function( const T& object, void ( T::*memberFunction ) ( P&, const PropertyInputContainer& ) )
151 ///////////////////////////////////////////////////////////////////////////////
154 template< typename T >
155 void TestFunctorMethodConstructor()
158 TestFunctorMethod< T > functor( called );
159 Constraint::Function< T > callback( functor, &TestFunctorMethod< T >::Method );
161 PropertyInputContainer inputs;
163 DALI_TEST_EQUALS( called, false, TEST_LOCATION );
164 CallbackBase::Execute< T&, const PropertyInputContainer& >( callback, current, inputs );
165 DALI_TEST_EQUALS( called, true, TEST_LOCATION );
167 } // unnamed namespace
169 int UtcDaliConstraintFunctionWithMethodFunctor(void)
171 TestFunctorMethodConstructor< bool >();
172 TestFunctorMethodConstructor< int >();
173 TestFunctorMethodConstructor< unsigned int >();
174 TestFunctorMethodConstructor< float >();
175 TestFunctorMethodConstructor< Vector2 >();
176 TestFunctorMethodConstructor< Vector3 >();
177 TestFunctorMethodConstructor< Vector4 >();
178 TestFunctorMethodConstructor< Quaternion >();
179 TestFunctorMethodConstructor< Matrix >();
180 TestFunctorMethodConstructor< Matrix3 >();
183 ///////////////////////////////////////////////////////////////////////////////
185 ///////////////////////////////////////////////////////////////////////////////
186 // Constraint::Function::Clone
187 ///////////////////////////////////////////////////////////////////////////////
190 template< typename T >
191 void TestFunctionClone()
193 gFunctionCalled = false;
194 Constraint::Function< T > callback( &TestCallbackFunction< T > );
195 CallbackBase* clone = callback.Clone();
198 PropertyInputContainer inputs;
200 DALI_TEST_EQUALS( gFunctionCalled, false, TEST_LOCATION );
201 CallbackBase::Execute< T&, const PropertyInputContainer& >( *clone, current, inputs );
202 DALI_TEST_EQUALS( gFunctionCalled, true, TEST_LOCATION );
206 template< typename T >
207 void TestFunctorClone()
210 TestCallbackFunctor< T > functor( called );
211 Constraint::Function< T > callback( functor );
212 CallbackBase* clone = callback.Clone();
215 PropertyInputContainer inputs;
217 DALI_TEST_EQUALS( called, false, TEST_LOCATION );
218 CallbackBase::Execute< T&, const PropertyInputContainer& >( *clone, current, inputs );
219 DALI_TEST_EQUALS( called, true, TEST_LOCATION );
223 template< typename T >
224 void TestMethodFunctorClone()
227 TestFunctorMethod< T > functor( called );
228 Constraint::Function< T > callback( functor, &TestFunctorMethod< T >::Method );
229 CallbackBase* clone = callback.Clone();
232 PropertyInputContainer inputs;
234 DALI_TEST_EQUALS( called, false, TEST_LOCATION );
235 CallbackBase::Execute< T&, const PropertyInputContainer& >( *clone, current, inputs );
236 DALI_TEST_EQUALS( called, true, TEST_LOCATION );
240 } // unnamed namespace
242 int UtcDaliConstraintFunctionFunctionClone(void)
244 TestFunctionClone< bool >();
245 TestFunctionClone< int >();
246 TestFunctionClone< unsigned int >();
247 TestFunctionClone< float >();
248 TestFunctionClone< Vector2 >();
249 TestFunctionClone< Vector3 >();
250 TestFunctionClone< Vector4 >();
251 TestFunctionClone< Quaternion >();
252 TestFunctionClone< Matrix >();
253 TestFunctionClone< Matrix3 >();
257 int UtcDaliConstraintFunctionFunctorClone(void)
259 TestFunctorClone< bool >();
260 TestFunctorClone< int >();
261 TestFunctorClone< unsigned int >();
262 TestFunctorClone< float >();
263 TestFunctorClone< Vector2 >();
264 TestFunctorClone< Vector3 >();
265 TestFunctorClone< Vector4 >();
266 TestFunctorClone< Quaternion >();
267 TestFunctorClone< Matrix >();
268 TestFunctorClone< Matrix3 >();
272 int UtcDaliConstraintFunctionMethodFunctorClone(void)
274 TestMethodFunctorClone< bool >();
275 TestMethodFunctorClone< int >();
276 TestMethodFunctorClone< unsigned int >();
277 TestMethodFunctorClone< float >();
278 TestMethodFunctorClone< Vector2 >();
279 TestMethodFunctorClone< Vector3 >();
280 TestMethodFunctorClone< Vector4 >();
281 TestMethodFunctorClone< Quaternion >();
282 TestMethodFunctorClone< Matrix >();
283 TestMethodFunctorClone< Matrix3 >();
286 ///////////////////////////////////////////////////////////////////////////////
288 ///////////////////////////////////////////////////////////////////////////////
293 CountFunctor( int& count )
299 CountFunctor( const CountFunctor& other )
300 : mCount( other.mCount )
305 CountFunctor& operator=( const CountFunctor& other )
307 this->mCount = other.mCount;
317 void operator()( bool& /* current*/ , const PropertyInputContainer& /* inputs */ )
323 } // unnamed namespace
325 int UtcDaliConstraintFunctionEnsureMemoryCleanup(void)
327 // Functors are new'd in Constraint::Function, so check that all memory is released at the end
332 CountFunctor functor( count );
333 Constraint::Function< bool > callback1( functor );
334 Constraint::Function< bool > callback2( functor );
335 Constraint::Function< bool > callback3( functor );
336 Constraint::Function< bool > callback4( functor );
337 Constraint::Function< bool > callback5( functor );
338 Constraint::Function< bool > callback6( functor );
339 Constraint::Function< bool > callback7( functor );
340 Constraint::Function< bool > callback8( functor );
341 Constraint::Function< bool > callback9( functor );
342 DALI_TEST_EQUALS( count, 10, TEST_LOCATION );
345 DALI_TEST_EQUALS( count, 0, TEST_LOCATION );
349 ///////////////////////////////////////////////////////////////////////////////