2 * Copyright (c) 2015 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>
29 void CheckTypeName(const Property::Type& type)
35 DALI_TEST_CHECK( "NONE" == std::string(PropertyTypes::GetName( type ) ) );
38 case Property::BOOLEAN:
40 DALI_TEST_CHECK( "BOOLEAN" == std::string(PropertyTypes::GetName( type ) ) );
45 DALI_TEST_CHECK( "FLOAT" == std::string(PropertyTypes::GetName( type ) ) );
48 case Property::INTEGER:
50 DALI_TEST_CHECK( "INTEGER" == std::string(PropertyTypes::GetName( type ) ) );
53 case Property::UNSIGNED_INTEGER:
55 DALI_TEST_CHECK( "UNSIGNED_INTEGER" == std::string(PropertyTypes::GetName( type ) ) );
58 case Property::VECTOR2:
60 DALI_TEST_CHECK( "VECTOR2" == std::string(PropertyTypes::GetName( type ) ) );
63 case Property::VECTOR3:
65 DALI_TEST_CHECK( "VECTOR3" == std::string(PropertyTypes::GetName( type ) ) );
68 case Property::VECTOR4:
70 DALI_TEST_CHECK( "VECTOR4" == std::string(PropertyTypes::GetName( type ) ) );
73 case Property::MATRIX3:
75 DALI_TEST_CHECK( "MATRIX3" == std::string(PropertyTypes::GetName( type ) ) );
78 case Property::MATRIX:
80 DALI_TEST_CHECK( "MATRIX" == std::string(PropertyTypes::GetName( type ) ) );
83 case Property::RECTANGLE:
85 DALI_TEST_CHECK( "RECTANGLE" == std::string(PropertyTypes::GetName( type ) ) );
88 case Property::ROTATION:
90 DALI_TEST_CHECK( "ROTATION" == std::string(PropertyTypes::GetName( type ) ) );
93 case Property::STRING:
95 DALI_TEST_CHECK( "STRING" == std::string(PropertyTypes::GetName( type ) ) );
100 DALI_TEST_CHECK( "ARRAY" == std::string(PropertyTypes::GetName( type ) ) );
105 DALI_TEST_CHECK( "MAP" == std::string(PropertyTypes::GetName( type ) ) );
108 case Property::TYPE_COUNT:
110 DALI_TEST_CHECK( "NONE" == std::string(PropertyTypes::GetName( type ) ) );
117 } // unnamed namespace
119 void utc_dali_property_value_startup(void)
121 test_return_value = TET_UNDEF;
124 void utc_dali_property_value_cleanup(void)
126 test_return_value = TET_PASS;
129 int UtcDaliPropertyValueConstructors01(void)
131 // Testing PropertyValue construction using Property::Type
132 // also testing the PropertyTypes::GetName is correct for each type
134 TestApplication application;
135 tet_infoline("Testing Property::Value construction using Property::Type");
137 Property::Value value;
138 DALI_TEST_CHECK( value.GetType() == Property::NONE );
140 Property::Type type = Property::NONE;
142 // Value(Value&) ctor and Value(Type&) ctor
143 DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type );
144 DALI_TEST_CHECK( Property::NONE == type );
147 type = Property::BOOLEAN;
149 DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type );
150 DALI_TEST_CHECK( PropertyTypes::Get<bool>() == type );
152 type = Property::FLOAT;
154 DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type );
155 DALI_TEST_CHECK( PropertyTypes::Get<float>() == type );
157 type = Property::INTEGER;
159 DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type );
160 DALI_TEST_CHECK( PropertyTypes::Get<int>() == type );
162 type = Property::UNSIGNED_INTEGER;
164 DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type );
165 DALI_TEST_CHECK( PropertyTypes::Get<unsigned int>() == type );
167 type = Property::VECTOR2;
169 DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type );
170 DALI_TEST_CHECK( PropertyTypes::Get<Vector2>() == type );
172 type = Property::VECTOR3;
174 DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type );
175 DALI_TEST_CHECK( PropertyTypes::Get<Vector3>() == type );
177 type = Property::VECTOR4;
179 DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type );
180 DALI_TEST_CHECK( PropertyTypes::Get<Vector4>() == type );
182 type = Property::MATRIX3;
184 DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type );
185 DALI_TEST_CHECK( PropertyTypes::Get<Matrix3>() == type );
187 type = Property::MATRIX;
189 DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type );
190 DALI_TEST_CHECK( PropertyTypes::Get<Matrix>() == type );
192 typedef Dali::Rect<int> Rectangle;
193 type = Property::RECTANGLE;
195 DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type );
196 DALI_TEST_CHECK( PropertyTypes::Get<Rectangle>() == type );
198 type = Property::ROTATION;
200 DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type );
201 DALI_TEST_CHECK( PropertyTypes::Get<Quaternion>() == type );
203 type = Property::ROTATION;
205 DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type );
206 DALI_TEST_CHECK( PropertyTypes::Get<AngleAxis>() == type );
208 type = Property::STRING;
210 DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type );
211 DALI_TEST_CHECK( PropertyTypes::Get<std::string>() == type );
213 type = Property::ARRAY;
215 DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type );
216 DALI_TEST_CHECK( PropertyTypes::Get<Property::Array>() == type );
218 type = Property::MAP;
220 DALI_TEST_CHECK( Property::Value(Property::Value(type)).GetType() == type );
221 DALI_TEST_CHECK( PropertyTypes::Get<Property::Map>() == type );
226 int UtcDaliPropertyValueConstructors02(void)
228 // Testing PropertyValue construction using value / reference types
229 // also testing the PropertyTypes::Get return same value as constructed
231 TestApplication application;
232 tet_infoline("Testing Property::Value construction using values / references");
234 Property::Value value;
237 value = Property::Value(true);
239 DALI_TEST_CHECK( true == b );
242 value = Property::Value(10.f);
244 DALI_TEST_CHECK( Dali::Equals(10.f, f) );
247 value = Property::Value(10);
249 DALI_TEST_CHECK( 10 == i );
252 value = Property::Value(10U);
254 DALI_TEST_CHECK( 10 == ui );
256 Vector2 v2 = Vector2(0,0);
257 value = Property::Value( Vector2(1,1) );
259 DALI_TEST_CHECK( Vector2(1,1) == v2 );
261 Vector3 v3 = Vector3(0.f,0.f,0.f);
262 value = Property::Value( Vector3(1.f,1.f,1.f) );
264 DALI_TEST_CHECK( Vector3(1.f,1.f,1.f) == v3 );
266 Vector4 v4 = Vector4(0,0,0,0);
267 value = Property::Value( Vector4(1,1,1,1) );
269 DALI_TEST_CHECK( Vector4(1,1,1,1) == v4 );
271 Matrix3 m3 = Matrix3(0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f);
272 value = Property::Value( Matrix3::IDENTITY );
274 DALI_TEST_CHECK( Matrix3::IDENTITY == m3 );
276 Matrix m = Matrix(true);
277 value = Property::Value( Matrix::IDENTITY );
279 DALI_TEST_CHECK( Matrix::IDENTITY == m );
281 typedef Dali::Rect<int> Rectangle;
282 Rectangle r = Rectangle(0,0,0,0);
283 value = Property::Value( Rectangle(1,1,1,1) );
285 DALI_TEST_CHECK( Rectangle(1,1,1,1) == r );
287 Quaternion q = Quaternion(0,0,0,0);
288 value = Property::Value( Quaternion(1,1,1,1) );
290 DALI_TEST_CHECK( Quaternion(1,1,1,1) == q );
292 AngleAxis aa = AngleAxis( Degree(0), Vector3(0.f,0.f,0.f) );
293 value = Property::Value( AngleAxis( Radian(Math::PI_2), Vector3::XAXIS ));
295 Quaternion r8(Radian(Degree(aa.angle)), aa.axis);
296 DALI_TEST_EQUALS(r8, Quaternion(Math::PI_2, Vector3::XAXIS), 0.001, TEST_LOCATION);
298 std::string s = "no";
299 value = Property::Value("yes");
301 DALI_TEST_CHECK( "yes" == s );
303 Property::Array array;
304 value = Property::Value(Property::ARRAY);
305 value.AppendItem(10);
308 array[0].Get(getItem);
309 DALI_TEST_CHECK( getItem == 10 );
312 value = Property::Value(Property::MAP);
313 value.SetValue("key", "value");
315 DALI_TEST_CHECK( map.GetKey(0) == "key" );
321 int UtcDaliPropertyValueCopyConstructors01(void)
323 TestApplication application;
324 tet_infoline("Testing Property::Value copy construction using values / references");
326 Property::Value value;
328 value = Property::Value(true);
330 Property::Value copy( value );
331 DALI_TEST_CHECK( true == copy.Get<bool>() );
334 value = Property::Value(10.f);
336 Property::Value copy( value );
337 DALI_TEST_CHECK( Dali::Equals(10.f, copy.Get<float>() ) );
340 value = Property::Value(10);
342 Property::Value copy( value );
343 DALI_TEST_CHECK( 10 == copy.Get<int>() );
346 value = Property::Value(10U);
348 Property::Value copy( value );
349 DALI_TEST_CHECK( 10 == copy.Get< unsigned int>() );
352 value = Property::Value( Vector2(1,1) );
354 Property::Value copy( value );
355 DALI_TEST_CHECK( Vector2(1,1) == copy.Get<Vector2>() );
358 value = Property::Value( Vector3(1.f,1.f,1.f) );
360 Property::Value copy( value );
361 DALI_TEST_CHECK( Vector3(1.f,1.f,1.f) == copy.Get<Vector3>() );
364 value = Property::Value( Vector4(1,1,1,1) );
366 Property::Value copy( value );
367 DALI_TEST_CHECK( Vector4(1,1,1,1) == copy.Get<Vector4>() );
370 value = Property::Value( Matrix3::IDENTITY );
372 Property::Value copy( value );
373 DALI_TEST_CHECK( Matrix3::IDENTITY == copy.Get<Matrix3>() );
376 value = Property::Value( Matrix::IDENTITY );
378 Property::Value copy( value );
379 DALI_TEST_CHECK( Matrix::IDENTITY == copy.Get<Matrix>() );
382 typedef Dali::Rect<int> Rectangle;
384 value = Property::Value( Rectangle(1,1,1,1) );
386 Property::Value copy( value );
389 DALI_TEST_CHECK( Rectangle(1,1,1,1) == copyRect);
392 value = Property::Value( Quaternion(1,1,1,1) );
394 Property::Value copy( value );
395 DALI_TEST_CHECK( Quaternion(1,1,1,1) == copy.Get<Quaternion>() );
398 value = Property::Value( AngleAxis( Radian(Math::PI_2), Vector3::XAXIS ));
400 Property::Value copy( value );
401 DALI_TEST_CHECK( value.Get<AngleAxis>().axis == copy.Get<AngleAxis>().axis );
402 DALI_TEST_CHECK( value.Get<AngleAxis>().angle == copy.Get<AngleAxis>().angle );
405 value = Property::Value("yes");
407 Property::Value copy( value );
408 DALI_TEST_CHECK( "yes" == copy.Get<std::string>() );
411 Property::Array array;
412 value = Property::Value(Property::ARRAY);
413 value.AppendItem(10);
415 Property::Value copy( value );
418 array[0].Get( getItem );
419 DALI_TEST_CHECK( getItem == 10 );
422 value = Property::Value(Property::MAP);
423 value.SetValue("key", "value");
425 Property::Value copy( value );
427 DALI_TEST_CHECK( map.GetKey(0) == "key" );
434 int UtcDaliPropertyValueAssignmentOperator01(void)
436 // Testing Property Value assignment
437 TestApplication application;
438 tet_infoline("Testing Property::Value assignment operator");
440 Property::Value value;
443 value = Property::Value(true);
445 Property::Value copy( false );
447 DALI_TEST_CHECK( true == copy.Get<bool>() );
450 value = Property::Value(10.f);
452 Property::Value copy(false);
454 DALI_TEST_CHECK( Dali::Equals(10.f, copy.Get<float>() ) );
457 value = Property::Value(10);
459 Property::Value copy(false);
461 DALI_TEST_CHECK( 10 == copy.Get<int>() );
464 value = Property::Value(10U);
466 Property::Value copy(false);
468 DALI_TEST_CHECK( 10 == copy.Get< unsigned int>() );
471 value = Property::Value( Vector2(1,1) );
473 Property::Value copy(false);
475 DALI_TEST_CHECK( Vector2(1,1) == copy.Get<Vector2>() );
478 value = Property::Value( Vector3(1.f,1.f,1.f) );
480 Property::Value copy(false);
482 DALI_TEST_CHECK( Vector3(1.f,1.f,1.f) == copy.Get<Vector3>() );
485 value = Property::Value( Vector4(1,1,1,1) );
487 Property::Value copy(false);
489 DALI_TEST_CHECK( Vector4(1,1,1,1) == copy.Get<Vector4>() );
492 value = Property::Value( Matrix3::IDENTITY );
494 Property::Value copy(false);
496 DALI_TEST_CHECK( Matrix3::IDENTITY == copy.Get<Matrix3>() );
499 value = Property::Value( Matrix::IDENTITY );
501 Property::Value copy(false);
503 DALI_TEST_CHECK( Matrix::IDENTITY == copy.Get<Matrix>() );
506 typedef Dali::Rect<int> Rectangle;
508 value = Property::Value( Rectangle(1,1,1,1) );
510 Property::Value copy(false);
514 DALI_TEST_CHECK( Rectangle(1,1,1,1) == copyRect);
517 value = Property::Value( Quaternion(1,1,1,1) );
519 Property::Value copy(false);
521 DALI_TEST_CHECK( Quaternion(1,1,1,1) == copy.Get<Quaternion>() );
524 value = Property::Value( AngleAxis( Radian(Math::PI_2), Vector3::XAXIS ));
526 Property::Value copy(false);
528 DALI_TEST_CHECK( value.Get<AngleAxis>().axis == copy.Get<AngleAxis>().axis );
529 DALI_TEST_CHECK( value.Get<AngleAxis>().angle == copy.Get<AngleAxis>().angle );
532 value = Property::Value("yes");
534 Property::Value copy(false);
536 DALI_TEST_CHECK( "yes" == copy.Get<std::string>() );
539 Property::Array array;
540 value = Property::Value(Property::ARRAY);
541 value.AppendItem(10);
543 Property::Value copy(false);
547 array[0].Get( getItem );
548 DALI_TEST_CHECK( getItem == 10 );
551 value = Property::Value(Property::MAP);
552 value.SetValue("key", "value");
554 Property::Value copy(false);
557 DALI_TEST_CHECK( map.GetKey(0) == "key" );
564 int UtcDaliPropertyValueOutputStream(void)
566 TestApplication application;
567 tet_infoline("Testing Property::Value output stream");
568 typedef Dali::Rect<int> Rectangle;
570 Property::Value value(true);
572 std::ostringstream stream;
574 DALI_TEST_CHECK( stream.str() == "1")
578 value = Property::Value(20.2f);
579 std::ostringstream stream;
581 DALI_TEST_CHECK( stream.str() == "20.2")
585 value = Property::Value(-25);
586 std::ostringstream stream;
588 DALI_TEST_CHECK( stream.str() == "-25")
592 value = Property::Value(25U);
593 std::ostringstream stream;
595 DALI_TEST_CHECK( stream.str() == "25")
599 value = Property::Value( Vector2(1.f,1.f) );
600 std::ostringstream stream;
602 DALI_TEST_CHECK( stream.str() == "[1, 1]");
606 value = Property::Value( Vector3(1.f,1.f,1.f) );
607 std::ostringstream stream;
609 DALI_TEST_CHECK( stream.str() == "[1, 1, 1]");
613 value = Property::Value( Matrix3::IDENTITY );
614 std::ostringstream stream;
616 DALI_TEST_CHECK( stream.str() == "[ [1, 0, 0], [0, 1, 0], [0, 0, 1] ]");
620 value = Property::Value( Matrix::IDENTITY );
621 std::ostringstream stream;
623 DALI_TEST_CHECK( stream.str() == "[ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ]");
627 value = Property::Value( Rectangle(1,2,3,4) );
628 std::ostringstream stream;
630 DALI_TEST_CHECK( stream.str() == "[1, 2, 3, 4]");
634 value = Property::Value( AngleAxis( Radian(1.2f), Vector3::XAXIS ));
635 std::ostringstream stream;
637 tet_printf("angle axis = %s \n", stream.str().c_str() );
638 DALI_TEST_CHECK( stream.str() == "[1.2, -0, 0, 0]");
641 // Maps and arrays currently not supported, we just check a message is output
644 value = Property::Value( map );
645 std::ostringstream stream;
647 DALI_TEST_CHECK( !stream.str().empty() );
650 Property::Array array;
651 value = Property::Value( array );
652 std::ostringstream stream;
654 DALI_TEST_CHECK( !stream.str().empty() );