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_constraints_startup(void)
29 test_return_value = TET_UNDEF;
32 void utc_dali_constraints_cleanup(void)
34 test_return_value = TET_PASS;
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
41 struct PropertyInputImpl : public PropertyInput
45 static const bool BOOLEAN_VALUE;
46 static const float FLOAT_VALUE;
47 static const int INTEGER_VALUE;
48 static const Vector2 VECTOR2_VALUE;
49 static const Vector3 VECTOR3_VALUE;
50 static const Vector4 VECTOR4_VALUE;
51 static const Matrix3 MATRIX3_VALUE;
52 static const Matrix MATRIX_VALUE;
53 static const Quaternion QUATERNION_VALUE;
55 // Construction & Destruction
56 PropertyInputImpl(Property::Type type)
60 virtual ~PropertyInputImpl()
65 Property::Type GetType() const
71 virtual const bool& GetBoolean() const
75 virtual const float& GetFloat() const
79 virtual const int& GetInteger() const
83 virtual const Vector2& GetVector2() const
87 virtual const Vector3& GetVector3() const
91 virtual const Vector4& GetVector4() const
95 virtual const Matrix3& GetMatrix3() const
99 virtual const Matrix& GetMatrix() const
103 virtual const Quaternion& GetQuaternion() const
105 return QUATERNION_VALUE;
109 Property::Type mType;
112 const bool PropertyInputImpl::BOOLEAN_VALUE = true;
113 const float PropertyInputImpl::FLOAT_VALUE = 123.0f;
114 const int PropertyInputImpl::INTEGER_VALUE = 456;
115 const Vector2 PropertyInputImpl::VECTOR2_VALUE = Vector2(10.0f, 20.0f);
116 const Vector3 PropertyInputImpl::VECTOR3_VALUE = Vector3(30.0f, 40.0f, 50.0f);
117 const Vector4 PropertyInputImpl::VECTOR4_VALUE = Vector4(60.0f, 70.0f, 80.0f, 90.0f);
118 const Matrix3 PropertyInputImpl::MATRIX3_VALUE(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f);
119 const Matrix PropertyInputImpl::MATRIX_VALUE = Matrix::IDENTITY;
120 const Quaternion PropertyInputImpl::QUATERNION_VALUE(1.0f, 2.0f, 3.0f, 4.0f);
122 struct Vector3PropertyInput : public PropertyInputImpl
125 // Construction & Destruction
126 Vector3PropertyInput(Vector3& value)
127 : PropertyInputImpl(Property::VECTOR3),
132 ~Vector3PropertyInput()
136 const Vector3& GetVector3() const
145 struct QuaternionPropertyInput : public PropertyInputImpl
148 // Construction & Destruction
149 QuaternionPropertyInput(Quaternion& value)
150 : PropertyInputImpl(Property::ROTATION),
155 ~QuaternionPropertyInput()
159 const Quaternion& GetQuaternion() const
168 } // unnamed namespace
169 ///////////////////////////////////////////////////////////////////////////////
171 ///////////////////////////////////////////////////////////////////////////////
173 ///////////////////////////////////////////////////////////////////////////////
174 int UtcDaliConstraintsEqualToConstraintFloat(void)
176 PropertyInputContainer inputs;
177 PropertyInputImpl input(Property::FLOAT);
178 inputs.PushBack(&input);
181 DALI_TEST_CHECK(value != PropertyInputImpl::FLOAT_VALUE);
183 EqualToConstraint constraint;
184 constraint(value, inputs);
186 DALI_TEST_EQUALS(value, PropertyInputImpl::FLOAT_VALUE, TEST_LOCATION);
191 int UtcDaliConstraintsEqualToConstraintVector2(void)
193 PropertyInputContainer inputs;
194 PropertyInputImpl input(Property::VECTOR2);
195 inputs.PushBack(&input);
198 DALI_TEST_CHECK(value != PropertyInputImpl::VECTOR2_VALUE);
200 EqualToConstraint constraint;
201 constraint(value, inputs);
203 DALI_TEST_EQUALS(value, PropertyInputImpl::VECTOR2_VALUE, TEST_LOCATION);
208 int UtcDaliConstraintsEqualToConstraintVector3(void)
210 PropertyInputContainer inputs;
211 PropertyInputImpl input(Property::VECTOR3);
212 inputs.PushBack(&input);
215 DALI_TEST_CHECK(value != PropertyInputImpl::VECTOR3_VALUE);
217 EqualToConstraint constraint;
218 constraint(value, inputs);
220 DALI_TEST_EQUALS(value, PropertyInputImpl::VECTOR3_VALUE, TEST_LOCATION);
225 int UtcDaliConstraintsEqualToConstraintVector4(void)
227 PropertyInputContainer inputs;
228 PropertyInputImpl input(Property::VECTOR4);
229 inputs.PushBack(&input);
232 DALI_TEST_CHECK(value != PropertyInputImpl::VECTOR4_VALUE);
234 EqualToConstraint constraint;
235 constraint(value, inputs);
237 DALI_TEST_EQUALS(value, PropertyInputImpl::VECTOR4_VALUE, TEST_LOCATION);
242 int UtcDaliConstraintsEqualToConstraintQuaternion(void)
244 PropertyInputContainer inputs;
245 PropertyInputImpl input(Property::ROTATION);
246 inputs.PushBack(&input);
249 DALI_TEST_CHECK(value != PropertyInputImpl::QUATERNION_VALUE);
251 EqualToConstraint constraint;
252 constraint(value, inputs);
254 DALI_TEST_EQUALS(value, PropertyInputImpl::QUATERNION_VALUE, TEST_LOCATION);
259 int UtcDaliConstraintsEqualToConstraintMatrix3(void)
261 PropertyInputContainer inputs;
262 PropertyInputImpl input(Property::MATRIX3);
263 inputs.PushBack(&input);
266 DALI_TEST_CHECK(value != PropertyInputImpl::MATRIX3_VALUE);
268 EqualToConstraint constraint;
269 constraint(value, inputs);
271 DALI_TEST_EQUALS(value, PropertyInputImpl::MATRIX3_VALUE, 0.1f, TEST_LOCATION);
276 int UtcDaliConstraintsEqualToConstraintMatrix(void)
278 PropertyInputContainer inputs;
279 PropertyInputImpl input(Property::MATRIX);
280 inputs.PushBack(&input);
283 DALI_TEST_CHECK(value != PropertyInputImpl::MATRIX_VALUE);
285 EqualToConstraint constraint;
286 constraint(value, inputs);
288 DALI_TEST_EQUALS(value, PropertyInputImpl::MATRIX_VALUE, TEST_LOCATION);
292 ///////////////////////////////////////////////////////////////////////////////
294 ///////////////////////////////////////////////////////////////////////////////
295 // RelativeToConstraint
296 ///////////////////////////////////////////////////////////////////////////////
297 int UtcDaliConstraintsRelativeToConstraintUsingFloat(void)
299 PropertyInputContainer inputs;
300 PropertyInputImpl input(Property::VECTOR3);
301 inputs.PushBack(&input);
304 DALI_TEST_EQUALS(value, Vector3::ZERO, TEST_LOCATION);
306 const float scale(4.0f);
307 RelativeToConstraint constraint(scale);
308 constraint(value, inputs);
310 DALI_TEST_EQUALS(value, PropertyInputImpl::VECTOR3_VALUE * scale, TEST_LOCATION);
315 int UtcDaliConstraintsRelativeToConstraintUsingVector3(void)
317 PropertyInputContainer inputs;
318 PropertyInputImpl input(Property::VECTOR3);
319 inputs.PushBack(&input);
322 DALI_TEST_EQUALS(value, Vector3::ZERO, TEST_LOCATION);
324 const Vector3 scale(4.0f, 5.0f, 6.0f);
325 RelativeToConstraint constraint(scale);
326 constraint(value, inputs);
328 DALI_TEST_EQUALS(value, PropertyInputImpl::VECTOR3_VALUE * scale, TEST_LOCATION);
332 ///////////////////////////////////////////////////////////////////////////////
334 ///////////////////////////////////////////////////////////////////////////////
335 // RelativeToConstraintFloat
336 ///////////////////////////////////////////////////////////////////////////////
337 int UtcDaliConstraintsRelativeToConstraintFloat(void)
339 PropertyInputContainer inputs;
340 PropertyInputImpl input(Property::VECTOR3);
341 inputs.PushBack(&input);
343 const float scale(4.0f);
346 DALI_TEST_CHECK(value != PropertyInputImpl::FLOAT_VALUE * scale);
348 RelativeToConstraintFloat constraint(scale);
349 constraint(value, inputs);
351 DALI_TEST_EQUALS(value, PropertyInputImpl::FLOAT_VALUE * scale, TEST_LOCATION);
355 ///////////////////////////////////////////////////////////////////////////////
357 ///////////////////////////////////////////////////////////////////////////////
359 ///////////////////////////////////////////////////////////////////////////////
360 int UtcDaliConstraintsLookAt(void)
362 TestApplication application;
364 Actor actor = Actor::New();
365 DALI_TEST_EQUALS(actor.GetCurrentProperty<Quaternion>(Actor::Property::WORLD_ORIENTATION), Quaternion::IDENTITY, TEST_LOCATION);
367 Vector3 targetPosition;
368 Vector3 cameraPosition;
369 Quaternion targetOrientation;
371 Vector3PropertyInput targetPositionProperty(targetPosition);
372 Vector3PropertyInput cameraPositionProperty(cameraPosition);
373 QuaternionPropertyInput targetOrientationProperty(targetOrientation);
375 PropertyInputContainer inputs;
376 inputs.PushBack(&targetPositionProperty);
377 inputs.PushBack(&cameraPositionProperty);
378 inputs.PushBack(&targetOrientationProperty);
382 // 180 degrees round y
383 targetPosition = Vector3::ZERO;
384 cameraPosition = Vector3(0.0f, 0.0f, 1.0f);
385 targetOrientation = Quaternion::IDENTITY;
386 Quaternion lookAtOrientation(Quaternion(Radian(Math::PI), Vector3::YAXIS));
387 LookAt(current, inputs);
388 DALI_TEST_EQUALS(current, lookAtOrientation, TEST_LOCATION);
390 // 180 degrees round y * -45 degrees round x
391 targetPosition = Vector3::ZERO;
392 cameraPosition = Vector3(0.0f, -1.0f, 1.0f);
393 targetOrientation = Quaternion::IDENTITY;
394 lookAtOrientation = Quaternion(Radian(Math::PI), Vector3::YAXIS) * Quaternion(Radian(Math::PI * 0.25f), -Vector3::XAXIS);
395 LookAt(current, inputs);
396 DALI_TEST_EQUALS(current, lookAtOrientation, Math::MACHINE_EPSILON_10, TEST_LOCATION);
398 // 180 degrees round y * -45 degrees round x at different points
399 targetPosition = Vector3(0.0f, 1.0f, -1.0f);
400 cameraPosition = Vector3::ZERO;
401 targetOrientation = Quaternion::IDENTITY;
402 lookAtOrientation = Quaternion(Radian(Math::PI), Vector3::YAXIS) * Quaternion(Radian(Math::PI * 0.25f), -Vector3::XAXIS);
403 LookAt(current, inputs);
404 DALI_TEST_EQUALS(current, lookAtOrientation, Math::MACHINE_EPSILON_10, TEST_LOCATION);
406 // 225 degrees round y
407 targetPosition = Vector3(-1.0f, 0.0f, 0.0f);
408 cameraPosition = Vector3(0.0f, 0.0f, 1.0f);
409 targetOrientation = Quaternion::IDENTITY;
410 lookAtOrientation = Quaternion(Radian(Math::PI * 1.25), Vector3::YAXIS);
411 LookAt(current, inputs);
412 DALI_TEST_EQUALS(current, lookAtOrientation, Math::MACHINE_EPSILON_10, TEST_LOCATION);
414 // 180 degrees round y * -45 degrees round x, Up Vector: 180 degrees
415 targetPosition = Vector3::ZERO;
416 cameraPosition = Vector3(0.0f, -1.0f, 1.0f);
417 targetOrientation = Quaternion(Radian(Math::PI), Vector3::ZAXIS);
418 lookAtOrientation = Quaternion(Radian(Math::PI), Vector3::YAXIS) * Quaternion(Radian(Math::PI * 0.25f), -Vector3::XAXIS) * Quaternion(Radian(Math::PI), -Vector3::ZAXIS);
419 LookAt(current, inputs);
420 DALI_TEST_EQUALS(current, lookAtOrientation, Math::MACHINE_EPSILON_10, TEST_LOCATION);
424 ///////////////////////////////////////////////////////////////////////////////
426 int UtcDaliPropertyInputGetExtension(void)
428 PropertyInputImpl input(Property::BOOLEAN);
429 DALI_TEST_CHECK(input.GetExtension() == NULL);