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_constraints_startup(void)
29 test_return_value = TET_UNDEF;
32 void utc_dali_constraints_cleanup(void)
34 test_return_value = TET_PASS;
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
42 struct PropertyInputImpl : public PropertyInput
47 static const bool BOOLEAN_VALUE;
48 static const float FLOAT_VALUE;
49 static const int INTEGER_VALUE;
50 static const Vector2 VECTOR2_VALUE;
51 static const Vector3 VECTOR3_VALUE;
52 static const Vector4 VECTOR4_VALUE;
53 static const Matrix3 MATRIX3_VALUE;
54 static const Matrix MATRIX_VALUE;
55 static const Quaternion QUATERNION_VALUE;
57 // Construction & Destruction
58 PropertyInputImpl( Property::Type type ) : mType( type ) { }
59 virtual ~PropertyInputImpl() { }
62 Property::Type GetType() const { return mType; }
65 virtual const bool& GetBoolean() const { return BOOLEAN_VALUE; }
66 virtual const float& GetFloat() const { return FLOAT_VALUE; }
67 virtual const int& GetInteger() const { return INTEGER_VALUE; }
68 virtual const Vector2& GetVector2() const { return VECTOR2_VALUE; }
69 virtual const Vector3& GetVector3() const { return VECTOR3_VALUE; }
70 virtual const Vector4& GetVector4() const { return VECTOR4_VALUE; }
71 virtual const Matrix3& GetMatrix3() const { return MATRIX3_VALUE; }
72 virtual const Matrix& GetMatrix() const { return MATRIX_VALUE; }
73 virtual const Quaternion& GetQuaternion() const { return QUATERNION_VALUE; }
79 const bool PropertyInputImpl::BOOLEAN_VALUE = true;
80 const float PropertyInputImpl::FLOAT_VALUE = 123.0f;
81 const int PropertyInputImpl::INTEGER_VALUE = 456;
82 const Vector2 PropertyInputImpl::VECTOR2_VALUE = Vector2( 10.0f, 20.0f );
83 const Vector3 PropertyInputImpl::VECTOR3_VALUE = Vector3( 30.0f, 40.0f, 50.0f );
84 const Vector4 PropertyInputImpl::VECTOR4_VALUE = Vector4( 60.0f, 70.0f, 80.0f, 90.0f );
85 const Matrix3 PropertyInputImpl::MATRIX3_VALUE ( 1.0f, 2.0f, 3.0f,
88 const Matrix PropertyInputImpl::MATRIX_VALUE = Matrix::IDENTITY;
89 const Quaternion PropertyInputImpl::QUATERNION_VALUE ( 1.0f, 2.0f, 3.0f, 4.0f );
91 struct Vector3PropertyInput : public PropertyInputImpl
95 // Construction & Destruction
96 Vector3PropertyInput( Vector3& value )
97 : PropertyInputImpl( Property::VECTOR3 ),
102 ~Vector3PropertyInput()
106 const Vector3& GetVector3() const
115 struct QuaternionPropertyInput : public PropertyInputImpl
119 // Construction & Destruction
120 QuaternionPropertyInput( Quaternion& value )
121 : PropertyInputImpl( Property::ROTATION ),
126 ~QuaternionPropertyInput()
130 const Quaternion& GetQuaternion() const
139 } // unnamed namespace
140 ///////////////////////////////////////////////////////////////////////////////
142 ///////////////////////////////////////////////////////////////////////////////
144 ///////////////////////////////////////////////////////////////////////////////
145 int UtcDaliConstraintsEqualToConstraintFloat(void)
147 PropertyInputContainer inputs;
148 PropertyInputImpl input( Property::FLOAT );
149 inputs.PushBack( &input );
152 DALI_TEST_CHECK( value != PropertyInputImpl::FLOAT_VALUE );
154 EqualToConstraint constraint;
155 constraint( value, inputs );
157 DALI_TEST_EQUALS( value, PropertyInputImpl::FLOAT_VALUE, TEST_LOCATION );
162 int UtcDaliConstraintsEqualToConstraintVector2(void)
164 PropertyInputContainer inputs;
165 PropertyInputImpl input( Property::VECTOR2 );
166 inputs.PushBack( &input );
169 DALI_TEST_CHECK( value != PropertyInputImpl::VECTOR2_VALUE );
171 EqualToConstraint constraint;
172 constraint( value, inputs );
174 DALI_TEST_EQUALS( value, PropertyInputImpl::VECTOR2_VALUE, TEST_LOCATION );
179 int UtcDaliConstraintsEqualToConstraintVector3(void)
181 PropertyInputContainer inputs;
182 PropertyInputImpl input( Property::VECTOR3 );
183 inputs.PushBack( &input );
186 DALI_TEST_CHECK( value != PropertyInputImpl::VECTOR3_VALUE );
188 EqualToConstraint constraint;
189 constraint( value, inputs );
191 DALI_TEST_EQUALS( value, PropertyInputImpl::VECTOR3_VALUE, TEST_LOCATION );
196 int UtcDaliConstraintsEqualToConstraintVector4(void)
198 PropertyInputContainer inputs;
199 PropertyInputImpl input( Property::VECTOR4 );
200 inputs.PushBack( &input );
203 DALI_TEST_CHECK( value != PropertyInputImpl::VECTOR4_VALUE );
205 EqualToConstraint constraint;
206 constraint( value, inputs );
208 DALI_TEST_EQUALS( value, PropertyInputImpl::VECTOR4_VALUE, TEST_LOCATION );
213 int UtcDaliConstraintsEqualToConstraintQuaternion(void)
215 PropertyInputContainer inputs;
216 PropertyInputImpl input( Property::ROTATION );
217 inputs.PushBack( &input );
220 DALI_TEST_CHECK( value != PropertyInputImpl::QUATERNION_VALUE );
222 EqualToConstraint constraint;
223 constraint( value, inputs );
225 DALI_TEST_EQUALS( value, PropertyInputImpl::QUATERNION_VALUE, TEST_LOCATION );
230 int UtcDaliConstraintsEqualToConstraintMatrix3(void)
232 PropertyInputContainer inputs;
233 PropertyInputImpl input( Property::MATRIX3 );
234 inputs.PushBack( &input );
237 DALI_TEST_CHECK( value != PropertyInputImpl::MATRIX3_VALUE );
239 EqualToConstraint constraint;
240 constraint( value, inputs );
242 DALI_TEST_EQUALS( value, PropertyInputImpl::MATRIX3_VALUE, 0.1f, TEST_LOCATION);
247 int UtcDaliConstraintsEqualToConstraintMatrix(void)
249 PropertyInputContainer inputs;
250 PropertyInputImpl input( Property::MATRIX );
251 inputs.PushBack( &input );
254 DALI_TEST_CHECK( value != PropertyInputImpl::MATRIX_VALUE );
256 EqualToConstraint constraint;
257 constraint( value, inputs );
259 DALI_TEST_EQUALS( value, PropertyInputImpl::MATRIX_VALUE, TEST_LOCATION );
263 ///////////////////////////////////////////////////////////////////////////////
265 ///////////////////////////////////////////////////////////////////////////////
266 // RelativeToConstraint
267 ///////////////////////////////////////////////////////////////////////////////
268 int UtcDaliConstraintsRelativeToConstraintUsingFloat(void)
270 PropertyInputContainer inputs;
271 PropertyInputImpl input( Property::VECTOR3 );
272 inputs.PushBack( &input );
275 DALI_TEST_EQUALS( value, Vector3::ZERO, TEST_LOCATION );
277 const float scale( 4.0f );
278 RelativeToConstraint constraint( scale );
279 constraint( value, inputs );
281 DALI_TEST_EQUALS( value, PropertyInputImpl::VECTOR3_VALUE * scale, TEST_LOCATION );
286 int UtcDaliConstraintsRelativeToConstraintUsingVector3(void)
288 PropertyInputContainer inputs;
289 PropertyInputImpl input( Property::VECTOR3 );
290 inputs.PushBack( &input );
293 DALI_TEST_EQUALS( value, Vector3::ZERO, TEST_LOCATION );
295 const Vector3 scale( 4.0f, 5.0f, 6.0f );
296 RelativeToConstraint constraint( scale );
297 constraint( value, inputs );
299 DALI_TEST_EQUALS( value, PropertyInputImpl::VECTOR3_VALUE * scale, TEST_LOCATION );
303 ///////////////////////////////////////////////////////////////////////////////
305 ///////////////////////////////////////////////////////////////////////////////
306 // RelativeToConstraintFloat
307 ///////////////////////////////////////////////////////////////////////////////
308 int UtcDaliConstraintsRelativeToConstraintFloat(void)
310 PropertyInputContainer inputs;
311 PropertyInputImpl input( Property::VECTOR3 );
312 inputs.PushBack( &input );
314 const float scale( 4.0f );
317 DALI_TEST_CHECK( value != PropertyInputImpl::FLOAT_VALUE * scale );
319 RelativeToConstraintFloat constraint( scale );
320 constraint( value, inputs );
322 DALI_TEST_EQUALS( value, PropertyInputImpl::FLOAT_VALUE * scale, TEST_LOCATION );
326 ///////////////////////////////////////////////////////////////////////////////
328 ///////////////////////////////////////////////////////////////////////////////
330 ///////////////////////////////////////////////////////////////////////////////
331 int UtcDaliConstraintsLookAt(void)
333 TestApplication application;
335 Actor actor = Actor::New();
336 DALI_TEST_EQUALS( actor.GetCurrentWorldOrientation(), Quaternion::IDENTITY, TEST_LOCATION );
338 Vector3 targetPosition;
339 Vector3 cameraPosition;
340 Quaternion targetOrientation;
342 Vector3PropertyInput targetPositionProperty( targetPosition );
343 Vector3PropertyInput cameraPositionProperty( cameraPosition );
344 QuaternionPropertyInput targetOrientationProperty( targetOrientation );
346 PropertyInputContainer inputs;
347 inputs.PushBack( &targetPositionProperty );
348 inputs.PushBack( &cameraPositionProperty );
349 inputs.PushBack( &targetOrientationProperty );
353 // 180 degrees round y
354 targetPosition = Vector3::ZERO;
355 cameraPosition = Vector3( 0.0f, 0.0f, 1.0f );
356 targetOrientation = Quaternion::IDENTITY;
357 Quaternion lookAtOrientation( Quaternion( Radian( Math::PI ), Vector3::YAXIS ) );
358 LookAt( current, inputs );
359 DALI_TEST_EQUALS( current, lookAtOrientation, TEST_LOCATION );
361 // 180 degrees round y * -45 degrees round x
362 targetPosition = Vector3::ZERO;
363 cameraPosition = Vector3( 0.0f, -1.0f, 1.0f );
364 targetOrientation = Quaternion::IDENTITY;
365 lookAtOrientation = Quaternion( Radian( Math::PI ), Vector3::YAXIS ) * Quaternion( Radian( Math::PI * 0.25f ), -Vector3::XAXIS );
366 LookAt( current, inputs );
367 DALI_TEST_EQUALS( current, lookAtOrientation, Math::MACHINE_EPSILON_10, TEST_LOCATION );
369 // 180 degrees round y * -45 degrees round x at different points
370 targetPosition = Vector3( 0.0f, 1.0f, -1.0f );
371 cameraPosition = Vector3::ZERO;
372 targetOrientation = Quaternion::IDENTITY;
373 lookAtOrientation = Quaternion( Radian( Math::PI ), Vector3::YAXIS ) * Quaternion( Radian( Math::PI * 0.25f ), -Vector3::XAXIS );
374 LookAt( current, inputs );
375 DALI_TEST_EQUALS( current, lookAtOrientation, Math::MACHINE_EPSILON_10, TEST_LOCATION );
377 // 225 degrees round y
378 targetPosition = Vector3( -1.0f, 0.0f, 0.0f );
379 cameraPosition = Vector3( 0.0f, 0.0f, 1.0f );
380 targetOrientation = Quaternion::IDENTITY;
381 lookAtOrientation = Quaternion( Radian( Math::PI * 1.25), Vector3::YAXIS );
382 LookAt( current, inputs );
383 DALI_TEST_EQUALS( current, lookAtOrientation, Math::MACHINE_EPSILON_10, TEST_LOCATION );
385 // 180 degrees round y * -45 degrees round x, Up Vector: 180 degrees
386 targetPosition = Vector3::ZERO;
387 cameraPosition = Vector3( 0.0f, -1.0f, 1.0f );
388 targetOrientation = Quaternion( Radian( Math::PI ), Vector3::ZAXIS );
389 lookAtOrientation = Quaternion( Radian( Math::PI ), Vector3::YAXIS ) * Quaternion( Radian( Math::PI * 0.25f ), -Vector3::XAXIS ) * Quaternion( Radian( Math::PI ), -Vector3::ZAXIS );
390 LookAt( current, inputs );
391 DALI_TEST_EQUALS( current, lookAtOrientation, Math::MACHINE_EPSILON_10, TEST_LOCATION );
395 ///////////////////////////////////////////////////////////////////////////////
397 int UtcDaliPropertyInputGetExtension(void)
399 PropertyInputImpl input( Property::BOOLEAN );
400 DALI_TEST_CHECK( input.GetExtension() == NULL );