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 unsigned int UNSIGNED_INTEGER_VALUE;
51 static const Vector2 VECTOR2_VALUE;
52 static const Vector3 VECTOR3_VALUE;
53 static const Vector4 VECTOR4_VALUE;
54 static const Matrix3 MATRIX3_VALUE;
55 static const Matrix MATRIX_VALUE;
56 static const Quaternion QUATERNION_VALUE;
58 // Construction & Destruction
59 PropertyInputImpl( Property::Type type ) : mType( type ) { }
60 virtual ~PropertyInputImpl() { }
63 Property::Type GetType() const { return mType; }
66 virtual const bool& GetBoolean() const { return BOOLEAN_VALUE; }
67 virtual const float& GetFloat() const { return FLOAT_VALUE; }
68 virtual const int& GetInteger() const { return INTEGER_VALUE; }
69 virtual const unsigned int& GetUnsignedInteger() const { return UNSIGNED_INTEGER_VALUE; }
70 virtual const Vector2& GetVector2() const { return VECTOR2_VALUE; }
71 virtual const Vector3& GetVector3() const { return VECTOR3_VALUE; }
72 virtual const Vector4& GetVector4() const { return VECTOR4_VALUE; }
73 virtual const Matrix3& GetMatrix3() const { return MATRIX3_VALUE; }
74 virtual const Matrix& GetMatrix() const { return MATRIX_VALUE; }
75 virtual const Quaternion& GetQuaternion() const { return QUATERNION_VALUE; }
81 const bool PropertyInputImpl::BOOLEAN_VALUE = true;
82 const float PropertyInputImpl::FLOAT_VALUE = 123.0f;
83 const int PropertyInputImpl::INTEGER_VALUE = 456;
84 const unsigned int PropertyInputImpl::UNSIGNED_INTEGER_VALUE = 789u;
85 const Vector2 PropertyInputImpl::VECTOR2_VALUE = Vector2( 10.0f, 20.0f );
86 const Vector3 PropertyInputImpl::VECTOR3_VALUE = Vector3( 30.0f, 40.0f, 50.0f );
87 const Vector4 PropertyInputImpl::VECTOR4_VALUE = Vector4( 60.0f, 70.0f, 80.0f, 90.0f );
88 const Matrix3 PropertyInputImpl::MATRIX3_VALUE ( 1.0f, 2.0f, 3.0f,
91 const Matrix PropertyInputImpl::MATRIX_VALUE = Matrix::IDENTITY;
92 const Quaternion PropertyInputImpl::QUATERNION_VALUE ( 1.0f, 2.0f, 3.0f, 4.0f );
94 struct Vector3PropertyInput : public PropertyInputImpl
98 // Construction & Destruction
99 Vector3PropertyInput( Vector3& value )
100 : PropertyInputImpl( Property::VECTOR3 ),
105 ~Vector3PropertyInput()
109 const Vector3& GetVector3() const
118 struct QuaternionPropertyInput : public PropertyInputImpl
122 // Construction & Destruction
123 QuaternionPropertyInput( Quaternion& value )
124 : PropertyInputImpl( Property::ROTATION ),
129 ~QuaternionPropertyInput()
133 const Quaternion& GetQuaternion() const
142 } // unnamed namespace
143 ///////////////////////////////////////////////////////////////////////////////
145 ///////////////////////////////////////////////////////////////////////////////
147 ///////////////////////////////////////////////////////////////////////////////
148 int UtcDaliConstraintsEqualToConstraintFloat(void)
150 PropertyInputContainer inputs;
151 PropertyInputImpl input( Property::FLOAT );
152 inputs.PushBack( &input );
155 DALI_TEST_CHECK( value != PropertyInputImpl::FLOAT_VALUE );
157 EqualToConstraint constraint;
158 constraint( value, inputs );
160 DALI_TEST_EQUALS( value, PropertyInputImpl::FLOAT_VALUE, TEST_LOCATION );
165 int UtcDaliConstraintsEqualToConstraintVector2(void)
167 PropertyInputContainer inputs;
168 PropertyInputImpl input( Property::VECTOR2 );
169 inputs.PushBack( &input );
172 DALI_TEST_CHECK( value != PropertyInputImpl::VECTOR2_VALUE );
174 EqualToConstraint constraint;
175 constraint( value, inputs );
177 DALI_TEST_EQUALS( value, PropertyInputImpl::VECTOR2_VALUE, TEST_LOCATION );
182 int UtcDaliConstraintsEqualToConstraintVector3(void)
184 PropertyInputContainer inputs;
185 PropertyInputImpl input( Property::VECTOR3 );
186 inputs.PushBack( &input );
189 DALI_TEST_CHECK( value != PropertyInputImpl::VECTOR3_VALUE );
191 EqualToConstraint constraint;
192 constraint( value, inputs );
194 DALI_TEST_EQUALS( value, PropertyInputImpl::VECTOR3_VALUE, TEST_LOCATION );
199 int UtcDaliConstraintsEqualToConstraintVector4(void)
201 PropertyInputContainer inputs;
202 PropertyInputImpl input( Property::VECTOR4 );
203 inputs.PushBack( &input );
206 DALI_TEST_CHECK( value != PropertyInputImpl::VECTOR4_VALUE );
208 EqualToConstraint constraint;
209 constraint( value, inputs );
211 DALI_TEST_EQUALS( value, PropertyInputImpl::VECTOR4_VALUE, TEST_LOCATION );
216 int UtcDaliConstraintsEqualToConstraintQuaternion(void)
218 PropertyInputContainer inputs;
219 PropertyInputImpl input( Property::ROTATION );
220 inputs.PushBack( &input );
223 DALI_TEST_CHECK( value != PropertyInputImpl::QUATERNION_VALUE );
225 EqualToConstraint constraint;
226 constraint( value, inputs );
228 DALI_TEST_EQUALS( value, PropertyInputImpl::QUATERNION_VALUE, TEST_LOCATION );
233 int UtcDaliConstraintsEqualToConstraintMatrix3(void)
235 PropertyInputContainer inputs;
236 PropertyInputImpl input( Property::MATRIX3 );
237 inputs.PushBack( &input );
240 DALI_TEST_CHECK( value != PropertyInputImpl::MATRIX3_VALUE );
242 EqualToConstraint constraint;
243 constraint( value, inputs );
245 DALI_TEST_EQUALS( value, PropertyInputImpl::MATRIX3_VALUE, 0.1f, TEST_LOCATION);
250 int UtcDaliConstraintsEqualToConstraintMatrix(void)
252 PropertyInputContainer inputs;
253 PropertyInputImpl input( Property::MATRIX );
254 inputs.PushBack( &input );
257 DALI_TEST_CHECK( value != PropertyInputImpl::MATRIX_VALUE );
259 EqualToConstraint constraint;
260 constraint( value, inputs );
262 DALI_TEST_EQUALS( value, PropertyInputImpl::MATRIX_VALUE, TEST_LOCATION );
266 ///////////////////////////////////////////////////////////////////////////////
268 ///////////////////////////////////////////////////////////////////////////////
269 // RelativeToConstraint
270 ///////////////////////////////////////////////////////////////////////////////
271 int UtcDaliConstraintsRelativeToConstraintUsingFloat(void)
273 PropertyInputContainer inputs;
274 PropertyInputImpl input( Property::VECTOR3 );
275 inputs.PushBack( &input );
278 DALI_TEST_EQUALS( value, Vector3::ZERO, TEST_LOCATION );
280 const float scale( 4.0f );
281 RelativeToConstraint constraint( scale );
282 constraint( value, inputs );
284 DALI_TEST_EQUALS( value, PropertyInputImpl::VECTOR3_VALUE * scale, TEST_LOCATION );
289 int UtcDaliConstraintsRelativeToConstraintUsingVector3(void)
291 PropertyInputContainer inputs;
292 PropertyInputImpl input( Property::VECTOR3 );
293 inputs.PushBack( &input );
296 DALI_TEST_EQUALS( value, Vector3::ZERO, TEST_LOCATION );
298 const Vector3 scale( 4.0f, 5.0f, 6.0f );
299 RelativeToConstraint constraint( scale );
300 constraint( value, inputs );
302 DALI_TEST_EQUALS( value, PropertyInputImpl::VECTOR3_VALUE * scale, TEST_LOCATION );
306 ///////////////////////////////////////////////////////////////////////////////
308 ///////////////////////////////////////////////////////////////////////////////
309 // RelativeToConstraintFloat
310 ///////////////////////////////////////////////////////////////////////////////
311 int UtcDaliConstraintsRelativeToConstraintFloat(void)
313 PropertyInputContainer inputs;
314 PropertyInputImpl input( Property::VECTOR3 );
315 inputs.PushBack( &input );
317 const float scale( 4.0f );
320 DALI_TEST_CHECK( value != PropertyInputImpl::FLOAT_VALUE * scale );
322 RelativeToConstraintFloat constraint( scale );
323 constraint( value, inputs );
325 DALI_TEST_EQUALS( value, PropertyInputImpl::FLOAT_VALUE * scale, TEST_LOCATION );
329 ///////////////////////////////////////////////////////////////////////////////
331 ///////////////////////////////////////////////////////////////////////////////
333 ///////////////////////////////////////////////////////////////////////////////
334 int UtcDaliConstraintsLookAt(void)
336 TestApplication application;
338 Actor actor = Actor::New();
339 DALI_TEST_EQUALS( actor.GetCurrentWorldOrientation(), Quaternion::IDENTITY, TEST_LOCATION );
341 Vector3 targetPosition;
342 Vector3 cameraPosition;
343 Quaternion targetOrientation;
345 Vector3PropertyInput targetPositionProperty( targetPosition );
346 Vector3PropertyInput cameraPositionProperty( cameraPosition );
347 QuaternionPropertyInput targetOrientationProperty( targetOrientation );
349 PropertyInputContainer inputs;
350 inputs.PushBack( &targetPositionProperty );
351 inputs.PushBack( &cameraPositionProperty );
352 inputs.PushBack( &targetOrientationProperty );
356 // 180 degrees round y
357 targetPosition = Vector3::ZERO;
358 cameraPosition = Vector3( 0.0f, 0.0f, 1.0f );
359 targetOrientation = Quaternion::IDENTITY;
360 Quaternion lookAtOrientation( Quaternion( Radian( Math::PI ), Vector3::YAXIS ) );
361 LookAt( current, inputs );
362 DALI_TEST_EQUALS( current, lookAtOrientation, TEST_LOCATION );
364 // 180 degrees round y * -45 degrees round x
365 targetPosition = Vector3::ZERO;
366 cameraPosition = Vector3( 0.0f, -1.0f, 1.0f );
367 targetOrientation = Quaternion::IDENTITY;
368 lookAtOrientation = Quaternion( Radian( Math::PI ), Vector3::YAXIS ) * Quaternion( Radian( Math::PI * 0.25f ), -Vector3::XAXIS );
369 LookAt( current, inputs );
370 DALI_TEST_EQUALS( current, lookAtOrientation, Math::MACHINE_EPSILON_10, TEST_LOCATION );
372 // 180 degrees round y * -45 degrees round x at different points
373 targetPosition = Vector3( 0.0f, 1.0f, -1.0f );
374 cameraPosition = Vector3::ZERO;
375 targetOrientation = Quaternion::IDENTITY;
376 lookAtOrientation = Quaternion( Radian( Math::PI ), Vector3::YAXIS ) * Quaternion( Radian( Math::PI * 0.25f ), -Vector3::XAXIS );
377 LookAt( current, inputs );
378 DALI_TEST_EQUALS( current, lookAtOrientation, Math::MACHINE_EPSILON_10, TEST_LOCATION );
380 // 225 degrees round y
381 targetPosition = Vector3( -1.0f, 0.0f, 0.0f );
382 cameraPosition = Vector3( 0.0f, 0.0f, 1.0f );
383 targetOrientation = Quaternion::IDENTITY;
384 lookAtOrientation = Quaternion( Radian( Math::PI * 1.25), Vector3::YAXIS );
385 LookAt( current, inputs );
386 DALI_TEST_EQUALS( current, lookAtOrientation, Math::MACHINE_EPSILON_10, TEST_LOCATION );
388 // 180 degrees round y * -45 degrees round x, Up Vector: 180 degrees
389 targetPosition = Vector3::ZERO;
390 cameraPosition = Vector3( 0.0f, -1.0f, 1.0f );
391 targetOrientation = Quaternion( Radian( Math::PI ), Vector3::ZAXIS );
392 lookAtOrientation = Quaternion( Radian( Math::PI ), Vector3::YAXIS ) * Quaternion( Radian( Math::PI * 0.25f ), -Vector3::XAXIS ) * Quaternion( Radian( Math::PI ), -Vector3::ZAXIS );
393 LookAt( current, inputs );
394 DALI_TEST_EQUALS( current, lookAtOrientation, Math::MACHINE_EPSILON_10, TEST_LOCATION );
398 ///////////////////////////////////////////////////////////////////////////////
400 int UtcDaliPropertyInputGetExtension(void)
402 PropertyInputImpl input( Property::BOOLEAN );
403 DALI_TEST_CHECK( input.GetExtension() == NULL );