2 * Copyright (c) 2018 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/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/object/handle-devel.h>
24 #include "dali-test-suite-utils/dali-test-suite-utils.h"
25 #include "dali-test-suite-utils/test-custom-actor.h"
27 #include <mesh-builder.h>
31 void handle_test_startup(void)
33 test_return_value = TET_UNDEF;
36 void handle_test_cleanup(void)
38 test_return_value = TET_PASS;
44 /// Allows the creation of a BaseObject
45 class BaseObjectType : public BaseObject
53 Handle ImplicitCopyConstructor(Handle passedByValue)
55 // object + copy + passedByValue, ref count == 3
56 DALI_TEST_CHECK(passedByValue);
59 DALI_TEST_EQUALS(3, passedByValue.GetBaseObject().ReferenceCount(), TEST_LOCATION);
68 int UtcDaliHandleConstructorVoid(void)
70 TestApplication application;
71 tet_infoline("Testing Dali::Handle::Handle()");
75 DALI_TEST_CHECK(!object);
80 int UtcDaliHandleCopyConstructor(void)
82 TestApplication application;
83 tet_infoline("Testing Dali::Handle::Handle(const Handle&)");
85 // Initialize an object, ref count == 1
86 Handle object = Actor::New();
88 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
90 // Copy the object, ref count == 2
92 DALI_TEST_CHECK(copy);
95 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
99 // Pass by value, and return another copy, ref count == 3
100 Handle anotherCopy = ImplicitCopyConstructor(copy);
102 DALI_TEST_CHECK(anotherCopy);
105 DALI_TEST_EQUALS(3, anotherCopy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
109 // anotherCopy out of scope, ref count == 2
110 DALI_TEST_CHECK(copy);
113 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
118 int UtcDaliHandleAssignmentOperator(void)
120 TestApplication application;
121 tet_infoline("Testing Dali::Handle::operator=");
123 Handle object = Actor::New();
125 DALI_TEST_CHECK(object);
126 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
129 DALI_TEST_CHECK(!copy);
132 DALI_TEST_CHECK(copy);
133 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
134 DALI_TEST_CHECK(&(copy.GetBaseObject()) == &(object.GetBaseObject()));
138 int UtcDaliHandleSupports(void)
140 tet_infoline("Positive Test Dali::Handle::Supports()");
141 TestApplication application;
143 Actor actor = Actor::New();
144 DALI_TEST_CHECK( true == actor.Supports( Handle::DYNAMIC_PROPERTIES ) );
148 int UtcDaliHandleGetPropertyCount(void)
150 tet_infoline("Positive Test Dali::Handle::GetPropertyCount()");
151 TestApplication application;
153 Actor actor = Actor::New();
154 int defaultPropertyCount( actor.GetPropertyCount() );
156 // Register a dynamic property
157 actor.RegisterProperty( "testProperty", float(123.0f) );
158 DALI_TEST_CHECK( (defaultPropertyCount + 1u) == actor.GetPropertyCount() );
162 int UtcDaliHandleGetPropertyName(void)
164 tet_infoline("Positive Test Dali::Handle::GetPropertyName()");
165 TestApplication application;
167 Actor actor = Actor::New();
168 DALI_TEST_CHECK( "parentOrigin" == actor.GetPropertyName( Actor::Property::PARENT_ORIGIN ) );
170 // Register a dynamic property
171 std::string name("thisNameShouldMatch");
172 Property::Index index = actor.RegisterProperty( name, float(123.0f) );
173 DALI_TEST_CHECK( name == actor.GetPropertyName( index ) );
178 int UtcDaliHandleGetPropertyIndex01(void)
180 tet_infoline("Positive Test Dali::Handle::GetPropertyIndex()");
181 TestApplication application;
183 Actor actor = Actor::New();
184 DALI_TEST_CHECK( Actor::Property::PARENT_ORIGIN == actor.GetPropertyIndex("parentOrigin") );
186 // Register a dynamic property
187 std::string name("thisNameShouldMatch");
188 Property::Index index = actor.RegisterProperty( name, float(123.0f) );
189 DALI_TEST_CHECK( index == actor.GetPropertyIndex( name ) );
193 int UtcDaliHandleGetPropertyIndex02(void)
195 tet_infoline("Positive Test Dali::Handle::GetPropertyIndex() int key");
196 TestApplication application;
198 Stage stage = Stage::GetCurrent();
200 Actor actor = Actor::New();
203 const unsigned int defaultPropertyCount = actor.GetPropertyCount();
205 application.SendNotification();
206 application.Render();
208 Property::Index key1 = CORE_PROPERTY_MAX_INDEX+1;
209 Property::Index key2 = CORE_PROPERTY_MAX_INDEX+2;
211 const Vector4 testColor(0.5f, 0.2f, 0.9f, 1.0f);
212 const float withFlake(99.f);
214 Property::Index index1 = actor.RegisterProperty( "MyPropertyOne", Vector3::ONE );
215 Property::Index index2 = DevelHandle::RegisterProperty( actor, key1, "sideColor", testColor);
216 Property::Index index3 = actor.RegisterProperty( "MyPropertyTwo", Vector3::ONE );
217 Property::Index index4 = DevelHandle::RegisterProperty( actor, key2, "iceCream", withFlake );
218 Property::Index index5 = actor.RegisterProperty( "MyPropertyThree", Vector3::ONE );
220 application.SendNotification();
221 application.Render();
223 // Test that we can get the property index from the integer key
224 Property::Index testIndex1 = DevelHandle::GetPropertyIndex( actor, key1 );
225 Property::Index testIndex2 = DevelHandle::GetPropertyIndex( actor, key2 );
227 DALI_TEST_EQUALS( index2, testIndex1, TEST_LOCATION );
228 DALI_TEST_EQUALS( index4, testIndex2, TEST_LOCATION );
230 // Test that we keep the same indices on the named properties
231 Property::Index testIndex = actor.GetPropertyIndex("MyPropertyOne");
232 DALI_TEST_EQUALS(testIndex, index1, TEST_LOCATION);
233 testIndex = actor.GetPropertyIndex("MyPropertyTwo");
234 DALI_TEST_EQUALS(testIndex, index3, TEST_LOCATION);
235 testIndex = actor.GetPropertyIndex("MyPropertyThree");
236 DALI_TEST_EQUALS(testIndex, index5, TEST_LOCATION);
237 testIndex = actor.GetPropertyIndex("sideColor");
238 DALI_TEST_EQUALS(testIndex, index2, TEST_LOCATION);
239 testIndex = actor.GetPropertyIndex("iceCream");
240 DALI_TEST_EQUALS(testIndex, index4, TEST_LOCATION);
242 DALI_TEST_EQUALS(defaultPropertyCount+5, actor.GetPropertyCount(), TEST_LOCATION);
246 int UtcDaliHandleGetPropertyIndex03(void)
248 TestApplication application;
250 Actor actor = Actor::New();
252 std::string myName("croydon");
253 Property::Index intKey = CORE_PROPERTY_MAX_INDEX+1;
254 Property::Value value( Color::GREEN );
255 Property::Index myIndex = DevelHandle::RegisterProperty( actor, intKey, myName, value );
257 DALI_TEST_EQUALS( myIndex, DevelHandle::GetPropertyIndex( actor, intKey ), TEST_LOCATION );
259 Property::Key key1(myName);
260 Property::Key key2(intKey);
262 DALI_TEST_EQUALS( myIndex, DevelHandle::GetPropertyIndex( actor, key1 ), TEST_LOCATION );
263 DALI_TEST_EQUALS( myIndex, DevelHandle::GetPropertyIndex( actor, key2 ), TEST_LOCATION );
268 int UtcDaliHandleIsPropertyWritable(void)
270 tet_infoline("Positive Test Dali::Handle::IsPropertyWritable()");
271 TestApplication application;
273 Actor actor = Actor::New();
275 // Actor properties which are writable:
276 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN ) );
277 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN_X ) );
278 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN_Y ) );
279 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN_Z ) );
280 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT ) );
281 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT_X ) );
282 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT_Y ) );
283 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT_Z ) );
284 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE ) );
285 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE_WIDTH ) );
286 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE_HEIGHT ) );
287 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE_DEPTH ) );
288 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION ) );
289 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION_X ) );
290 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION_Y ) );
291 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION_Z ) );
292 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ORIENTATION ) );
293 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE ) );
294 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE_X ) );
295 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE_Y ) );
296 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE_Z ) );
297 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::VISIBLE ) );
298 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR ) );
299 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_RED ) );
300 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_GREEN ) );
301 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_BLUE ) );
302 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_ALPHA ) );
303 DALI_TEST_CHECK( true == actor.IsPropertyWritable( DevelActor::Property::OPACITY ) );
305 // World-properties are not writable:
306 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION ) );
307 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_ORIENTATION ) );
308 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_SCALE ) );
309 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_COLOR ) );
310 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION_X ) );
311 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION_Y ) );
312 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION_Z ) );
317 int UtcDaliHandleIsPropertyAnimatable(void)
319 tet_infoline("Positive Test Dali::Handle::IsPropertyAnimatable()");
320 TestApplication application;
322 Actor actor = Actor::New();
324 // Actor properties which are animatable:
325 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN ) );
326 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN_X ) );
327 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN_Y ) );
328 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN_Z ) );
329 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT ) );
330 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT_X ) );
331 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT_Y ) );
332 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT_Z ) );
333 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE ) );
334 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE_WIDTH ) );
335 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE_HEIGHT ) );
336 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE_DEPTH ) );
337 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION ) );
338 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION_X ) );
339 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION_Y ) );
340 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION_Z ) );
341 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::ORIENTATION ) );
342 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE ) );
343 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE_X ) );
344 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE_Y ) );
345 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE_Z ) );
346 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::VISIBLE ) );
347 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR ) );
348 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_RED ) );
349 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_GREEN ) );
350 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_BLUE ) );
351 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_ALPHA ) );
352 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( DevelActor::Property::OPACITY ) );
354 // World-properties can not be animated
355 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION ) );
356 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_ORIENTATION ) );
357 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_SCALE ) );
358 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_COLOR ) );
359 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION_X ) );
360 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION_Y ) );
361 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION_Z ) );
366 int UtcDaliHandleIsPropertyAConstraintInput(void)
368 TestApplication application;
370 Actor actor = Actor::New();
372 // Actor properties which can be used as a constraint input:
373 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN ) );
374 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN_X ) );
375 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN_Y ) );
376 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN_Z ) );
377 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT ) );
378 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT_X ) );
379 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT_Y ) );
380 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT_Z ) );
381 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE ) );
382 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_WIDTH ) );
383 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_HEIGHT ) );
384 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_DEPTH ) );
385 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION ) );
386 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_X ) );
387 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_Y ) );
388 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_Z ) );
389 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ORIENTATION ) );
390 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE ) );
391 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE_X ) );
392 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE_Y ) );
393 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE_Z ) );
394 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::VISIBLE ) );
395 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR ) );
396 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_RED ) );
397 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_GREEN ) );
398 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_BLUE ) );
399 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_ALPHA ) );
400 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( DevelActor::Property::OPACITY ) );
401 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION ) );
402 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_ORIENTATION ) );
403 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_SCALE ) );
404 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_COLOR ) );
405 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION_X ) );
406 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION_Y ) );
407 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION_Z ) );
409 // Actor properties that cannot be used as a constraint input
410 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::NAME ) );
411 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::SENSITIVE ) );
412 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::LEAVE_REQUIRED ) );
413 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::INHERIT_ORIENTATION ) );
414 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::INHERIT_SCALE ) );
415 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_MODE ) );
416 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_INHERITANCE ) );
417 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::DRAW_MODE ) );
418 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_MODE_FACTOR ) );
424 int UtcDaliHandleGetPropertyType(void)
426 tet_infoline("Positive Test Dali::Handle::GetPropertyType()");
427 TestApplication application;
429 Actor actor = Actor::New();
430 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::PARENT_ORIGIN ) );
431 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::ANCHOR_POINT ) );
432 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::SIZE ) );
433 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::POSITION ) );
434 DALI_TEST_CHECK( Property::ROTATION == actor.GetPropertyType( Actor::Property::ORIENTATION ) );
435 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::SCALE ) );
436 DALI_TEST_CHECK( Property::BOOLEAN == actor.GetPropertyType( Actor::Property::VISIBLE ) );
437 DALI_TEST_CHECK( Property::VECTOR4 == actor.GetPropertyType( Actor::Property::COLOR ) );
439 // Register some dynamic properties
440 Property::Index boolIndex = actor.RegisterProperty( "boolProperty", bool(true) );
441 Property::Index floatIndex = actor.RegisterProperty( "floatProperty", float(123.0f) );
442 Property::Index intIndex = actor.RegisterProperty( "intProperty", 123 );
443 Property::Index vector2Index = actor.RegisterProperty( "vector2Property", Vector2(1.0f, 2.0f) );
444 Property::Index vector3Index = actor.RegisterProperty( "vector3Property", Vector3(1.0f, 2.0f, 3.0f) );
445 Property::Index vector4Index = actor.RegisterProperty( "vector4Property", Vector4(1.0f, 2.0f, 3.0f, 4.0f) );
446 Property::Index rotationIndex = actor.RegisterProperty( "rotationProperty", AngleAxis(Degree(180.0f), Vector3::YAXIS) );
448 DALI_TEST_CHECK( Property::BOOLEAN == actor.GetPropertyType( boolIndex ) );
449 DALI_TEST_CHECK( Property::FLOAT == actor.GetPropertyType( floatIndex ) );
450 DALI_TEST_CHECK( Property::INTEGER == actor.GetPropertyType( intIndex ) );
451 DALI_TEST_CHECK( Property::VECTOR2 == actor.GetPropertyType( vector2Index ) );
452 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( vector3Index ) );
453 DALI_TEST_CHECK( Property::VECTOR4 == actor.GetPropertyType( vector4Index ) );
454 DALI_TEST_CHECK( Property::ROTATION == actor.GetPropertyType( rotationIndex ) );
456 // Non animatable properties
457 Property::Index nonAnimStringIndex = actor.RegisterProperty( "manFromDelmonte", std::string("yes"), Property::READ_WRITE);
458 Property::Index nonAnimV2Index = actor.RegisterProperty( "v2", Vector2(1.f, 2.f), Property::READ_WRITE);
459 Property::Index nonAnimV3Index = actor.RegisterProperty( "v3", Vector3(1.f, 2.f, 3.f), Property::READ_WRITE);
460 Property::Index nonAnimV4Index = actor.RegisterProperty( "v4", Vector4(1.f, 2.f, 3.f, 4.f), Property::READ_WRITE);
461 Property::Index nonAnimBooleanIndex = actor.RegisterProperty( "bool", true, Property::READ_WRITE);
462 Property::Index nonAnimFloatIndex = actor.RegisterProperty( "float", 0.f, Property::READ_WRITE);
463 Property::Index nonAnimIntegerIndex = actor.RegisterProperty( "int", 0, Property::READ_WRITE);
465 DALI_TEST_CHECK( nonAnimStringIndex != Property::INVALID_INDEX );
466 DALI_TEST_CHECK( nonAnimV2Index != Property::INVALID_INDEX );
467 DALI_TEST_CHECK( nonAnimV3Index != Property::INVALID_INDEX );
468 DALI_TEST_CHECK( nonAnimV4Index != Property::INVALID_INDEX );
469 DALI_TEST_CHECK( nonAnimBooleanIndex != Property::INVALID_INDEX );
470 DALI_TEST_CHECK( nonAnimFloatIndex != Property::INVALID_INDEX );
471 DALI_TEST_CHECK( nonAnimIntegerIndex != Property::INVALID_INDEX );
473 DALI_TEST_CHECK( Property::STRING == actor.GetPropertyType( nonAnimStringIndex ) );
474 DALI_TEST_CHECK( Property::VECTOR2 == actor.GetPropertyType( nonAnimV2Index ) );
475 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( nonAnimV3Index ) );
476 DALI_TEST_CHECK( Property::VECTOR4 == actor.GetPropertyType( nonAnimV4Index ) );
477 DALI_TEST_CHECK( Property::BOOLEAN == actor.GetPropertyType( nonAnimBooleanIndex ) );
478 DALI_TEST_CHECK( Property::FLOAT == actor.GetPropertyType( nonAnimFloatIndex ) );
479 DALI_TEST_CHECK( Property::INTEGER == actor.GetPropertyType( nonAnimIntegerIndex ) );
481 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimStringIndex ) );
482 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV2Index ) );
483 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV3Index ) );
484 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV4Index ) );
485 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimBooleanIndex ) );
486 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimFloatIndex ) );
487 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimIntegerIndex ) );
489 DALI_TEST_EQUALS( "yes" , actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
490 DALI_TEST_EQUALS( Vector2(1.f, 2.f) , actor.GetProperty( nonAnimV2Index ).Get<Vector2>(), TEST_LOCATION );
491 DALI_TEST_EQUALS( Vector3(1.f, 2.f, 3.f) , actor.GetProperty( nonAnimV3Index ).Get<Vector3>(), TEST_LOCATION );
492 DALI_TEST_EQUALS( Vector4(1.f, 2.f, 3.f, 4.f) , actor.GetProperty( nonAnimV4Index ).Get<Vector4>(), TEST_LOCATION );
493 DALI_TEST_EQUALS( true, actor.GetProperty( nonAnimBooleanIndex ).Get<bool>(), TEST_LOCATION );
494 DALI_TEST_EQUALS( 0.f, actor.GetProperty( nonAnimFloatIndex ).Get<float>(), TEST_LOCATION );
495 DALI_TEST_EQUALS( 0, actor.GetProperty( nonAnimIntegerIndex ).Get<int>(), TEST_LOCATION );
500 int UtcDaliHandleNonAnimatableProperties(void)
502 tet_infoline("Test Non Animatable Properties");
503 TestApplication application;
505 Actor actor = Actor::New();
507 Property::Index nonAnimStringIndex = actor.RegisterProperty( "manFromDelmonte", std::string("no"), Property::READ_WRITE);
509 //// modify writable?
510 actor.SetProperty( nonAnimStringIndex, Property::Value("yes") );
512 DALI_TEST_CHECK( "yes" == actor.GetProperty( nonAnimStringIndex ).Get<std::string>() );
514 //// cannot modify read only?
515 Property::Index readonly = actor.RegisterProperty( "float", 0.f, Property::READ_ONLY);
517 DALI_TEST_CHECK(!actor.IsPropertyAnimatable(readonly));
518 DALI_TEST_CHECK(!actor.IsPropertyWritable(readonly));
520 actor.SetProperty( readonly, Property::Value(1.f) );
521 // trying to set a read-only property is a no-op
523 DALI_TEST_EQUALS( 0.f, actor.GetProperty( readonly ).Get<float>(), TEST_LOCATION );
525 /// animatable can be set
526 Property::Index write_anim = actor.RegisterProperty( "write_float", 0.f, Property::ANIMATABLE);
528 DALI_TEST_CHECK(actor.IsPropertyAnimatable(write_anim));
529 DALI_TEST_CHECK(actor.IsPropertyWritable(write_anim));
531 actor.SetProperty( write_anim, Property::Value(1.f) );
533 //// animate a non animatable property throws
534 float durationSeconds(2.0f);
535 Animation animation = Animation::New(durationSeconds);
536 bool relativeValue(true);
539 animation.AnimateBy(Property(actor, nonAnimStringIndex), relativeValue, AlphaFunction::EASE_IN);
541 catch ( Dali::DaliException& e )
543 DALI_TEST_ASSERT( e, "Animated value and Property type don't match", TEST_LOCATION );
546 DALI_TEST_EQUALS( "yes", actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
551 int UtcDaliHandleNonAnimtableCompositeProperties(void)
553 tet_infoline("Test Non Animatable Composite Properties");
554 TestApplication application;
556 Actor actor = Actor::New();
558 Property::Value value(Property::ARRAY);
559 Property::Array* array = value.GetArray();
560 DALI_TEST_CHECK( array );
562 array->PushBack( Property::Value( 0.1f ) );
563 array->PushBack( "a string" );
564 array->PushBack( Property::Value( Vector3(1,2,3) ) );
566 DALI_TEST_EQUALS( 3u, array->Count(), TEST_LOCATION );
568 Property::Index propertyIndex = actor.RegisterProperty( "composite", value, Property::READ_WRITE );
570 Property::Value out = actor.GetProperty( propertyIndex );
571 Property::Array* outArray = out.GetArray();
572 DALI_TEST_CHECK( outArray != NULL );
574 DALI_TEST_CHECK( Property::FLOAT == outArray->GetElementAt(0).GetType());
575 DALI_TEST_CHECK( Property::STRING == outArray->GetElementAt(1).GetType());
576 DALI_TEST_CHECK( Property::VECTOR3 == outArray->GetElementAt(2).GetType());
578 DALI_TEST_EQUALS( 0.1f, outArray->GetElementAt(0).Get<float>(), TEST_LOCATION);
579 DALI_TEST_EQUALS( "a string", outArray->GetElementAt(1).Get<std::string>(), TEST_LOCATION);
580 DALI_TEST_EQUALS( Vector3(1,2,3), outArray->GetElementAt(2).Get<Vector3>(), TEST_LOCATION);
582 // composite types not animatable
583 bool exception = false;
586 actor.RegisterProperty( "compositemap", value, Property::ANIMATABLE);
588 catch (Dali::DaliException& e)
591 DALI_TEST_PRINT_ASSERT( e );
594 DALI_TEST_EQUALS(exception, true, TEST_LOCATION);
597 Property::Value mapOfMaps(Property::MAP);
598 Property::Map* map = mapOfMaps.GetMap();
600 map->Insert( "key", Property::Value(Property::MAP) );
601 map->Insert( "2key", "a string" );
603 DALI_TEST_EQUALS( "a string", (*map)["2key"].Get<std::string>(), TEST_LOCATION);
605 Property::Map* innerMap = map->Find("key")->GetMap();
606 innerMap->Insert( "subkey", 5.f );
608 DALI_TEST_CHECK( NULL != map->Find("key")->GetMap()->Find("subkey") );
609 DALI_TEST_EQUALS( 5.f, map->Find("key")->GetMap()->Find("subkey")->Get<float>(), TEST_LOCATION);
613 int UtcDaliHandleSetProperty01(void)
615 tet_infoline("Positive Test Dali::Handle::SetProperty()");
616 TestApplication application;
618 Actor actor = Actor::New();
619 DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
621 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
622 // flush the queue and render once
623 application.SendNotification();
624 application.Render();
625 DALI_TEST_CHECK( ParentOrigin::CENTER == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
629 int UtcDaliHandleSetProperty02(void)
631 tet_infoline("Positive Test Dali::Handle::SetProperty()");
632 TestApplication application;
634 Actor actor = Actor::New();
636 DALI_TEST_CHECK( !actor.IsPropertyWritable( Actor::Property::WORLD_POSITION ) );
638 // World position is not writable so this is a no-op and should not crash
639 actor.SetProperty( Actor::Property::WORLD_POSITION, Vector3(1,2,3) );
644 int UtcDaliHandleRegisterProperty01(void)
646 tet_infoline("Positive Test Dali::Handle::RegisterProperty()");
647 TestApplication application;
649 Stage stage = Stage::GetCurrent();
651 Actor actor = Actor::New();
654 const unsigned int defaultPropertyCount = actor.GetPropertyCount();
656 application.SendNotification();
657 application.Render();
659 Property::Index index1 = actor.RegisterProperty( "MyProperty", Vector3::ONE );
661 application.SendNotification();
662 application.Render();
664 DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 1, TEST_LOCATION );
665 DALI_TEST_EQUALS( actor.GetProperty< Vector3 >( index1 ), Vector3::ONE, TEST_LOCATION );
667 // No new property should be registered when we call the below function
668 Property::Index index2 = actor.RegisterProperty( "MyProperty", Vector3::ZAXIS );
670 application.SendNotification();
671 application.Render();
674 DALI_TEST_EQUALS( index1, index2, TEST_LOCATION ); // We should have the same index as per the first registration
675 DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 1, TEST_LOCATION ); // Property count should be the same
676 DALI_TEST_EQUALS( actor.GetProperty< Vector3 >( index2 ), Vector3::ZAXIS, TEST_LOCATION ); // Value should be what we sent on second RegisterProperty call
681 int UtcDaliHandleRegisterProperty02(void)
683 tet_infoline("Positive Test Dali::Handle::RegisterProperty() int key");
684 TestApplication application;
686 Stage stage = Stage::GetCurrent();
688 Actor actor = Actor::New();
691 const unsigned int defaultPropertyCount = actor.GetPropertyCount();
693 application.SendNotification();
694 application.Render();
696 Property::Index key1 = CORE_PROPERTY_MAX_INDEX+1;
697 Property::Index key2 = CORE_PROPERTY_MAX_INDEX+2;
699 const Vector4 testColor(0.5f, 0.2f, 0.9f, 1.0f);
700 const float withFlake(99.f);
702 Property::Index index1 = actor.RegisterProperty( "MyPropertyOne", Vector3::ONE );
703 Property::Index index2 = DevelHandle::RegisterProperty( actor, key1, "sideColor", testColor);
704 Property::Index index3 = DevelHandle::RegisterProperty( actor, key2, "iceCream", withFlake );
706 application.SendNotification();
707 application.Render();
709 DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 3, TEST_LOCATION );
710 DALI_TEST_EQUALS( actor.GetProperty< Vector3 >( index1 ), Vector3::ONE, TEST_LOCATION );
711 DALI_TEST_EQUALS( actor.GetProperty< Vector4 >( index2 ), testColor, TEST_LOCATION );
712 DALI_TEST_EQUALS( actor.GetProperty< float >( index3 ), withFlake, TEST_LOCATION );
714 // No new property should be registered when we call the below functions
715 Property::Index testIndex2 = actor.RegisterProperty( "iceCream", 2200.f );
716 Property::Index testIndex1 = actor.RegisterProperty( "sideColor", Color::BLACK );
717 application.SendNotification();
718 application.Render();
720 DALI_TEST_EQUALS( index2, testIndex1, TEST_LOCATION ); // We should have the same index as per the first registration
721 DALI_TEST_EQUALS( index3, testIndex2, TEST_LOCATION ); // We should have the same index as per the first registration
722 DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 3, TEST_LOCATION ); // Property count should be the same
723 DALI_TEST_EQUALS( actor.GetProperty< Vector4 >( index2 ), Color::BLACK, TEST_LOCATION ); // Value should be what we sent on second RegisterProperty call
724 DALI_TEST_EQUALS( actor.GetProperty< float >( index3 ), 2200.f, TEST_LOCATION );
731 int UtcDaliHandleGetProperty(void)
733 tet_infoline("Positive Test Dali::Handle::GetProperty()");
734 TestApplication application;
736 Actor actor = Actor::New();
738 DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
739 DALI_TEST_CHECK( AnchorPoint::CENTER == actor.GetProperty( Actor::Property::ANCHOR_POINT ).Get<Vector3>() );
740 DALI_TEST_CHECK( Vector3::ZERO == actor.GetProperty( Actor::Property::SIZE ).Get<Vector3>() );
741 DALI_TEST_CHECK( Vector3::ZERO == actor.GetProperty( Actor::Property::POSITION ).Get<Vector3>() );
742 DALI_TEST_CHECK( Vector3::ONE == actor.GetProperty( Actor::Property::SCALE ).Get<Vector3>() );
743 DALI_TEST_CHECK( true == actor.GetProperty( Actor::Property::VISIBLE ).Get<bool>() );
744 DALI_TEST_CHECK( Color::WHITE == actor.GetProperty( Actor::Property::COLOR ).Get<Vector4>() );
748 int UtcDaliHandleDownCast(void)
750 TestApplication application;
751 tet_infoline("Testing Dali::Handle::DownCast()");
753 Actor actor = Actor::New();
755 BaseHandle baseHandle = actor;
757 Handle handle = Handle::DownCast(baseHandle);
759 DALI_TEST_CHECK( handle );
761 baseHandle = BaseHandle();
763 handle = Handle::DownCast(baseHandle);
765 DALI_TEST_CHECK( !handle );
770 int UtcDaliHandleDownCastNegative(void)
772 TestApplication application;
774 // BaseObject is NOT an Object, so this DownCast should fail
775 BaseHandle handle( new BaseObjectType );
776 Handle customHandle1 = Handle::DownCast( handle );
777 DALI_TEST_CHECK( ! customHandle1 );
779 // A DownCast on an empty handle will also fail
781 Handle customHandle2 = Handle::DownCast( empty );
782 DALI_TEST_CHECK( ! customHandle2 );
786 int UtcDaliHandleGetPropertyIndices(void)
788 TestApplication application;
789 Property::IndexContainer indices;
792 Actor actor = Actor::New();
793 actor.GetPropertyIndices( indices );
794 int numDefaultProperties = indices.Size();
795 DALI_TEST_CHECK( numDefaultProperties > 0 );
796 DALI_TEST_EQUALS( numDefaultProperties, actor.GetPropertyCount(), TEST_LOCATION );
798 const Vector4 testColor(0.5f, 0.2f, 0.9f, 1.0f);
799 const float withFlake(99.f);
801 Property::Index key1 = CORE_PROPERTY_MAX_INDEX+1;
802 Property::Index key2 = CORE_PROPERTY_MAX_INDEX+2;
804 actor.RegisterProperty( "MyPropertyOne", Vector3::ONE );
805 DevelHandle::RegisterProperty( actor, key1, "sideColor", testColor);
806 actor.RegisterProperty( "MyPropertyTwo", 1234 );
807 Property::Index index4 = DevelHandle::RegisterProperty( actor, key2, "iceCream", withFlake );
808 actor.RegisterProperty( "MyPropertyThree", Vector2(.2f,.7f) );
810 actor.GetPropertyIndices( indices );
812 DALI_TEST_EQUALS( indices.Size(), numDefaultProperties + 5, TEST_LOCATION );
813 DALI_TEST_EQUALS( indices[indices.Size()-2], index4, TEST_LOCATION );
818 int UtcDaliHandleRegisterPropertyTypes(void)
820 TestApplication application;
822 struct PropertyTypeAnimatable
825 Property::Value value;
829 Property::Array array;
832 PropertyTypeAnimatable properties[] =
834 { "Property::BOOLEAN", true, true },
835 { "Property::FLOAT", 1.0f, true },
836 { "Property::INTEGER", 1, true },
837 { "Property::VECTOR2", Vector2::ONE, true },
838 { "Property::VECTOR3", Vector3::ONE, true },
839 { "Property::VECTOR4", Vector4::ONE, true },
840 { "Property::MATRIX3", Matrix3::IDENTITY, true },
841 { "Property::MATRIX", Matrix::IDENTITY, true },
842 { "Property::RECTANGLE", Rect<int>(), false },
843 { "Property::ROTATION", AngleAxis(), true },
844 { "Property::STRING", std::string("Me"), false },
845 { "Property::ARRAY", array, false },
846 { "Property::MAP", map, false },
849 unsigned int numOfProperties( sizeof( properties ) / sizeof( properties[0] ) );
851 for ( unsigned int i = 0; i < numOfProperties; ++i )
853 tet_printf( "Testing: %s\n", properties[i].name );
855 bool exception = false;
858 Actor actor = Actor::New();
859 actor.RegisterProperty( "manFromDelmonte", properties[i].value );
861 catch (Dali::DaliException& e)
866 DALI_TEST_CHECK( properties[i].animatable != exception );
871 int UtcDaliHandleCustomProperty(void)
873 TestApplication application;
875 Handle handle = Handle::New();
877 float startValue(1.0f);
878 Property::Index index = handle.RegisterProperty( "testProperty", startValue );
879 DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
881 application.SendNotification();
882 application.Render(0);
883 DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
884 application.Render(0);
885 DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
887 handle.SetProperty( index, 5.0f );
889 application.SendNotification();
890 application.Render(0);
891 DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );
892 application.Render(0);
893 DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );
897 int UtcDaliHandleWeightNew(void)
899 TestApplication application;
901 Handle handle = WeightObject::New();
902 DALI_TEST_CHECK( handle.GetProperty<float>(WeightObject::WEIGHT) == 0.0f );
904 // process the message so scene object is added to update manager
905 application.SendNotification();
906 application.Render(0);
908 // no message to release scene object in this scenario
913 int UtcDaliHandleWeightNew2(void)
915 TestApplication application;
917 // scope for the weight object
919 Handle handle = WeightObject::New();
920 DALI_TEST_CHECK( handle.GetProperty<float>(WeightObject::WEIGHT) == 0.0f );
922 // process the message so scene object is added to update manager
923 application.SendNotification();
924 application.Render(0);
926 // handle out of scope so object gets destroyed
927 // process the message so update manager destroys the scene object
928 application.SendNotification();
929 application.Render(0);
934 int UtcDaliHandleSetTypeInfo(void)
936 TestApplication application;
937 TypeRegistry typeRegistry = TypeRegistry::Get();
939 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
940 DALI_TEST_CHECK( typeInfo );
942 Actor actor = Actor::DownCast(typeInfo.CreateInstance());
943 DALI_TEST_CHECK( actor );
945 DevelHandle::SetTypeInfo(actor, typeInfo);
947 TypeInfo newTypeInfo;
948 bool success = actor.GetTypeInfo( newTypeInfo );
949 DALI_TEST_CHECK( success );
951 DALI_TEST_CHECK(typeInfo.GetName() == newTypeInfo.GetName());
952 DALI_TEST_CHECK(typeInfo.GetBaseName() == newTypeInfo.GetBaseName());
957 int UtcDaliHandleCustomPropertySynchronousGetSet(void)
959 TestApplication application;
961 tet_infoline( "Create a custom property and set the value ensuring it can be retrieved synchronously" );
963 Actor actor = Actor::New();
964 Stage::GetCurrent().Add( actor );
966 tet_infoline( "Create the custom property with an initial value" );
967 float startValue(1.0f);
968 Property::Index index = actor.RegisterProperty( "testProperty", startValue );
969 DALI_TEST_EQUALS( actor.GetProperty< float >( index ), startValue, TEST_LOCATION );
971 tet_infoline( "Set the value, retrieve it and ensure both the synchronous and the async version work" );
972 actor.SetProperty( index, 5.0f );
973 DALI_TEST_EQUALS( actor.GetProperty< float >( index ), 5.0f, TEST_LOCATION );
974 DALI_TEST_EQUALS( actor.GetCurrentProperty< float >( index ), startValue, TEST_LOCATION );
976 tet_infoline( "Render and retrieve values again" );
977 application.SendNotification();
978 application.Render(0);
980 DALI_TEST_EQUALS( actor.GetProperty< float >( index ), 5.0f, TEST_LOCATION );
981 DALI_TEST_EQUALS( actor.GetCurrentProperty< float >( index ), 5.0f, TEST_LOCATION );
986 int UtcDaliHandleCustomPropertyGetType(void)
988 TestApplication application;
990 tet_infoline( "Create a custom property and retrieve its type" );
992 Handle handle = Handle::New();
993 Property::Index index = handle.RegisterProperty( "testProperty", 1.0f );
994 DALI_TEST_EQUALS( handle.GetPropertyType( index ), Property::FLOAT, TEST_LOCATION );
999 int UtcDaliHandleCustomPropertyAccessMode(void)
1001 TestApplication application;
1003 tet_infoline( "Create a custom property and retrieve whether it's animatable etc." );
1005 Handle handle = Handle::New();
1006 Property::Index index = handle.RegisterProperty( "testProperty", 1.0f );
1007 DALI_TEST_EQUALS( handle.IsPropertyAnimatable( index ), true, TEST_LOCATION );
1008 DALI_TEST_EQUALS( handle.IsPropertyWritable( index ), true, TEST_LOCATION );
1010 index = handle.RegisterProperty( "testProperty2", 1.0f, Property::READ_ONLY );
1011 DALI_TEST_EQUALS( handle.IsPropertyAnimatable( index ), false, TEST_LOCATION );
1012 DALI_TEST_EQUALS( handle.IsPropertyWritable( index ), false, TEST_LOCATION );
1014 index = handle.RegisterProperty( "testProperty3", 1.0f, Property::READ_WRITE );
1015 DALI_TEST_EQUALS( handle.IsPropertyAnimatable( index ), false, TEST_LOCATION );
1016 DALI_TEST_EQUALS( handle.IsPropertyWritable( index ), true, TEST_LOCATION );
1021 int UtcDaliHandleGetCurrentProperty(void)
1023 TestApplication application;
1025 tet_infoline( "Get a default and non-animatable custom property using the GetCurrentProperty API" );
1027 Actor actor = Actor::New();
1028 Stage::GetCurrent().Add( actor );
1029 DALI_TEST_EQUALS( actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ), true, TEST_LOCATION );
1031 Property::Index index = actor.RegisterProperty( "testProperty3", 1.0f, Property::READ_WRITE );
1032 DALI_TEST_EQUALS( actor.GetProperty< float >( index ), 1.0f, TEST_LOCATION );
1033 DALI_TEST_EQUALS( actor.GetCurrentProperty< float >( index ), 1.0f, TEST_LOCATION );
1035 actor.SetProperty( index, 2.0f );
1036 DALI_TEST_EQUALS( actor.GetProperty< float >( index ), 2.0f, TEST_LOCATION );
1037 DALI_TEST_EQUALS( actor.GetCurrentProperty< float >( index ), 2.0f, TEST_LOCATION );
1042 int UtcDaliHandleDoesCustomPropertyExistP1(void)
1044 TestApplication application; // Needs type registry
1046 tet_infoline( "Test if a registered custom property exists on object" );
1048 Actor actor = Actor::New();
1049 auto propertyIndex = actor.RegisterProperty("customProperty1", 1.0f);
1051 DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( actor, propertyIndex ), true, TEST_LOCATION );
1055 int UtcDaliHandleDoesCustomPropertyExistN1(void)
1057 TestApplication application; // Needs type registry
1059 tet_infoline( "Test if a registered custom property does not exist on object" );
1061 Actor actor = Actor::New();
1062 auto propertyIndex = actor.RegisterProperty("customProperty1", 1.0f);
1064 DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( actor, propertyIndex+1 ), false, TEST_LOCATION );
1068 int UtcDaliHandleDoesCustomPropertyExistN2(void)
1070 TestApplication application; // Needs type registry
1072 tet_infoline( "Test that a default property does not show as a custom property on object" );
1074 Actor actor = Actor::New();
1075 DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( actor, Actor::Property::POSITION ), false, TEST_LOCATION );
1079 int UtcDaliHandleDoesCustomPropertyExistN3(void)
1081 TestApplication application; // Needs type registry
1083 tet_infoline( "Test that a child property does not exist on actor after parenting to container" );
1084 TypeRegistry typeRegistry = TypeRegistry::Get();
1086 auto customActorTypeInfo = typeRegistry.GetTypeInfo( typeid(Test::TestCustomActor) );
1088 const Property::Index CHILD_PROPERTY( CHILD_PROPERTY_REGISTRATION_START_INDEX );
1089 const char* CHILD_PROPERTY_NAME( "childProperty" );
1091 ChildPropertyRegistration( customActorTypeInfo.GetName(), CHILD_PROPERTY_NAME, CHILD_PROPERTY, Property::INTEGER );
1093 auto container = Test::TestCustomActor::New();
1094 Stage::GetCurrent().Add( container );
1095 auto child = Actor::New();
1096 container.Add( child ); // Resolve child properties (if any)
1098 DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), false, TEST_LOCATION );
1102 int UtcDaliHandleDoesCustomPropertyExistP2(void)
1104 TestApplication application; // Needs type registry
1106 tet_infoline( "Test that a child property exists after being set" );
1107 TypeRegistry typeRegistry = TypeRegistry::Get();
1109 auto customActorTypeInfo = typeRegistry.GetTypeInfo( typeid(Test::TestCustomActor) );
1111 const Property::Index CHILD_PROPERTY( CHILD_PROPERTY_REGISTRATION_START_INDEX );
1112 const char* CHILD_PROPERTY_NAME( "childProperty" );
1114 ChildPropertyRegistration( customActorTypeInfo.GetName(), CHILD_PROPERTY_NAME, CHILD_PROPERTY, Property::INTEGER );
1116 auto container = Test::TestCustomActor::New();
1117 Stage::GetCurrent().Add( container );
1118 auto child = Actor::New();
1119 container.Add( child ); // Resolve child properties (if any)
1120 child.SetProperty( CHILD_PROPERTY, 2 );
1122 DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), true, TEST_LOCATION );
1123 DALI_TEST_EQUALS( child.GetProperty<int>( CHILD_PROPERTY ), 2, TEST_LOCATION );
1127 int UtcDaliHandleDoesCustomPropertyExistP3(void)
1129 TestApplication application; // Needs type registry
1131 tet_infoline( "Test that a child property is re-indexed after registration, and that it exists" );
1132 TypeRegistry typeRegistry = TypeRegistry::Get();
1134 auto customActorTypeInfo = typeRegistry.GetTypeInfo( typeid(Test::TestCustomActor) );
1136 const Property::Index CHILD_PROPERTY( CHILD_PROPERTY_REGISTRATION_START_INDEX );
1137 const char* CHILD_PROPERTY_NAME( "childProperty" );
1139 ChildPropertyRegistration( customActorTypeInfo.GetName(), CHILD_PROPERTY_NAME, CHILD_PROPERTY, Property::INTEGER );
1141 auto container = Test::TestCustomActor::New();
1142 Stage::GetCurrent().Add( container );
1143 auto child = Actor::New();
1144 child.RegisterProperty( CHILD_PROPERTY_NAME, Property::Value(3) );
1145 container.Add( child ); // Resolve child properties (if any)
1147 DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), true, TEST_LOCATION );
1148 DALI_TEST_EQUALS( child.GetProperty<int>( CHILD_PROPERTY ), 3, TEST_LOCATION );
1155 struct PropertySetSignalCheck
1157 PropertySetSignalCheck(bool& signalReceived, Property::Value& value)
1158 : mSignalReceived(signalReceived),
1163 void operator()(Handle& handle, Property::Index index, Property::Value value)
1165 mSignalReceived = true;
1171 mSignalReceived = false;
1174 void CheckSignalReceived()
1176 if (!mSignalReceived)
1178 tet_printf("Expected Property Set signal was not received\n");
1179 tet_result(TET_FAIL);
1183 tet_result(TET_PASS);
1187 bool& mSignalReceived; // owned by individual tests
1188 Property::Value& mValue;
1193 int UtcDaliHandlePropertySetSignal01(void)
1195 TestApplication app;
1197 bool signalReceived(false);
1198 Property::Value value;
1199 PropertySetSignalCheck propertySetCheck(signalReceived, value);
1201 tet_infoline( "Test that setting a default property triggers a signal" );
1203 auto actor = Actor::New();
1204 DevelHandle::PropertySetSignal(actor).Connect(&app, propertySetCheck);
1206 actor.SetProperty( Actor::Property::POSITION, Vector3::XAXIS );
1207 propertySetCheck.CheckSignalReceived();
1213 int UtcDaliHandlePropertySetSignal02(void)
1215 TestApplication app;
1217 bool signalReceived(false);
1218 Property::Value value;
1219 PropertySetSignalCheck propertySetCheck(signalReceived, value);
1221 tet_infoline( "Test that setting a custom property triggers a signal" );
1223 auto actor = Actor::New();
1224 DevelHandle::PropertySetSignal(actor).Connect(&app, propertySetCheck);
1226 auto propertyIndex = actor.RegisterProperty("propName", 3.0f);
1227 actor.SetProperty( propertyIndex, 5.0f );
1228 propertySetCheck.CheckSignalReceived();
1229 DALI_TEST_EQUALS( propertySetCheck.mValue, Property::Value( 5.0f ), 0.001f, TEST_LOCATION );
1234 int UtcDaliHandlePropertySetSignal03(void)
1236 TestApplication app;
1237 TypeRegistry typeRegistry = TypeRegistry::Get();
1239 bool signalReceived(false);
1240 Property::Value value;
1241 PropertySetSignalCheck propertySetCheck(signalReceived, value);
1243 tet_infoline( "Test that setting a child property triggers a signal" );
1245 auto customActorTypeInfo = typeRegistry.GetTypeInfo( typeid(Test::TestCustomActor) );
1247 const Property::Index CHILD_PROPERTY( CHILD_PROPERTY_REGISTRATION_START_INDEX );
1248 const char* CHILD_PROPERTY_NAME( "childProperty" );
1250 ChildPropertyRegistration( customActorTypeInfo.GetName(), CHILD_PROPERTY_NAME, CHILD_PROPERTY, Property::INTEGER );
1252 auto container = Test::TestCustomActor::New();
1253 Stage::GetCurrent().Add( container );
1254 auto child = Actor::New();
1255 child.RegisterProperty( CHILD_PROPERTY_NAME, Property::Value(3) );
1256 DevelHandle::PropertySetSignal(child).Connect(&app, propertySetCheck);
1257 container.Add( child ); // Resolve child properties (if any)
1259 DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), true, TEST_LOCATION );
1260 DALI_TEST_EQUALS( child.GetProperty<int>( CHILD_PROPERTY ), 3, TEST_LOCATION );
1262 child.SetProperty( CHILD_PROPERTY, 29 );
1263 propertySetCheck.CheckSignalReceived();
1264 DALI_TEST_EQUALS( propertySetCheck.mValue, Property::Value( 29 ), TEST_LOCATION );