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/devel-api/object/handle-devel.h>
23 #include "dali-test-suite-utils/dali-test-suite-utils.h"
24 #include <mesh-builder.h>
28 void handle_test_startup(void)
30 test_return_value = TET_UNDEF;
33 void handle_test_cleanup(void)
35 test_return_value = TET_PASS;
41 /// Allows the creation of a BaseObject
42 class BaseObjectType : public BaseObject
50 Handle ImplicitCopyConstructor(Handle passedByValue)
52 // object + copy + passedByValue, ref count == 3
53 DALI_TEST_CHECK(passedByValue);
56 DALI_TEST_EQUALS(3, passedByValue.GetBaseObject().ReferenceCount(), TEST_LOCATION);
65 int UtcDaliHandleConstructorVoid(void)
67 TestApplication application;
68 tet_infoline("Testing Dali::Handle::Handle()");
72 DALI_TEST_CHECK(!object);
77 int UtcDaliHandleCopyConstructor(void)
79 TestApplication application;
80 tet_infoline("Testing Dali::Handle::Handle(const Handle&)");
82 // Initialize an object, ref count == 1
83 Handle object = Actor::New();
85 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
87 // Copy the object, ref count == 2
89 DALI_TEST_CHECK(copy);
92 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
96 // Pass by value, and return another copy, ref count == 3
97 Handle anotherCopy = ImplicitCopyConstructor(copy);
99 DALI_TEST_CHECK(anotherCopy);
102 DALI_TEST_EQUALS(3, anotherCopy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
106 // anotherCopy out of scope, ref count == 2
107 DALI_TEST_CHECK(copy);
110 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
115 int UtcDaliHandleAssignmentOperator(void)
117 TestApplication application;
118 tet_infoline("Testing Dali::Handle::operator=");
120 Handle object = Actor::New();
122 DALI_TEST_CHECK(object);
123 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
126 DALI_TEST_CHECK(!copy);
129 DALI_TEST_CHECK(copy);
130 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
131 DALI_TEST_CHECK(&(copy.GetBaseObject()) == &(object.GetBaseObject()));
135 int UtcDaliHandleSupports(void)
137 tet_infoline("Positive Test Dali::Handle::Supports()");
138 TestApplication application;
140 Actor actor = Actor::New();
141 DALI_TEST_CHECK( true == actor.Supports( Handle::DYNAMIC_PROPERTIES ) );
145 int UtcDaliHandleGetPropertyCount(void)
147 tet_infoline("Positive Test Dali::Handle::GetPropertyCount()");
148 TestApplication application;
150 Actor actor = Actor::New();
151 int defaultPropertyCount( actor.GetPropertyCount() );
153 // Register a dynamic property
154 actor.RegisterProperty( "testProperty", float(123.0f) );
155 DALI_TEST_CHECK( (defaultPropertyCount + 1u) == actor.GetPropertyCount() );
159 int UtcDaliHandleGetPropertyName(void)
161 tet_infoline("Positive Test Dali::Handle::GetPropertyName()");
162 TestApplication application;
164 Actor actor = Actor::New();
165 DALI_TEST_CHECK( "parentOrigin" == actor.GetPropertyName( Actor::Property::PARENT_ORIGIN ) );
167 // Register a dynamic property
168 std::string name("thisNameShouldMatch");
169 Property::Index index = actor.RegisterProperty( name, float(123.0f) );
170 DALI_TEST_CHECK( name == actor.GetPropertyName( index ) );
175 int UtcDaliHandleGetPropertyIndex01(void)
177 tet_infoline("Positive Test Dali::Handle::GetPropertyIndex()");
178 TestApplication application;
180 Actor actor = Actor::New();
181 DALI_TEST_CHECK( Actor::Property::PARENT_ORIGIN == actor.GetPropertyIndex("parentOrigin") );
183 // Register a dynamic property
184 std::string name("thisNameShouldMatch");
185 Property::Index index = actor.RegisterProperty( name, float(123.0f) );
186 DALI_TEST_CHECK( index == actor.GetPropertyIndex( name ) );
190 int UtcDaliHandleGetPropertyIndex02(void)
192 tet_infoline("Positive Test Dali::Handle::GetPropertyIndex() int key");
193 TestApplication application;
195 Stage stage = Stage::GetCurrent();
197 Actor actor = Actor::New();
200 const unsigned int defaultPropertyCount = actor.GetPropertyCount();
202 application.SendNotification();
203 application.Render();
205 Property::Index key1 = CORE_PROPERTY_MAX_INDEX+1;
206 Property::Index key2 = CORE_PROPERTY_MAX_INDEX+2;
208 const Vector4 testColor(0.5f, 0.2f, 0.9f, 1.0f);
209 const float withFlake(99.f);
211 Property::Index index1 = actor.RegisterProperty( "MyPropertyOne", Vector3::ONE );
212 Property::Index index2 = DevelHandle::RegisterProperty( actor, key1, "sideColor", testColor);
213 Property::Index index3 = actor.RegisterProperty( "MyPropertyTwo", Vector3::ONE );
214 Property::Index index4 = DevelHandle::RegisterProperty( actor, key2, "iceCream", withFlake );
215 Property::Index index5 = actor.RegisterProperty( "MyPropertyThree", Vector3::ONE );
217 application.SendNotification();
218 application.Render();
220 // Test that we can get the property index from the integer key
221 Property::Index testIndex1 = DevelHandle::GetPropertyIndex( actor, key1 );
222 Property::Index testIndex2 = DevelHandle::GetPropertyIndex( actor, key2 );
224 DALI_TEST_EQUALS( index2, testIndex1, TEST_LOCATION );
225 DALI_TEST_EQUALS( index4, testIndex2, TEST_LOCATION );
227 // Test that we keep the same indices on the named properties
228 Property::Index testIndex = actor.GetPropertyIndex("MyPropertyOne");
229 DALI_TEST_EQUALS(testIndex, index1, TEST_LOCATION);
230 testIndex = actor.GetPropertyIndex("MyPropertyTwo");
231 DALI_TEST_EQUALS(testIndex, index3, TEST_LOCATION);
232 testIndex = actor.GetPropertyIndex("MyPropertyThree");
233 DALI_TEST_EQUALS(testIndex, index5, TEST_LOCATION);
234 testIndex = actor.GetPropertyIndex("sideColor");
235 DALI_TEST_EQUALS(testIndex, index2, TEST_LOCATION);
236 testIndex = actor.GetPropertyIndex("iceCream");
237 DALI_TEST_EQUALS(testIndex, index4, TEST_LOCATION);
239 DALI_TEST_EQUALS(defaultPropertyCount+5, actor.GetPropertyCount(), TEST_LOCATION);
243 int UtcDaliHandleGetPropertyIndex03(void)
245 TestApplication application;
247 Actor actor = Actor::New();
249 std::string myName("croydon");
250 Property::Index intKey = CORE_PROPERTY_MAX_INDEX+1;
251 Property::Value value( Color::GREEN );
252 Property::Index myIndex = DevelHandle::RegisterProperty( actor, intKey, myName, value );
254 DALI_TEST_EQUALS( myIndex, DevelHandle::GetPropertyIndex( actor, intKey ), TEST_LOCATION );
256 Property::Key key1(myName);
257 Property::Key key2(intKey);
259 DALI_TEST_EQUALS( myIndex, DevelHandle::GetPropertyIndex( actor, key1 ), TEST_LOCATION );
260 DALI_TEST_EQUALS( myIndex, DevelHandle::GetPropertyIndex( actor, key2 ), TEST_LOCATION );
265 int UtcDaliHandleIsPropertyWritable(void)
267 tet_infoline("Positive Test Dali::Handle::IsPropertyWritable()");
268 TestApplication application;
270 Actor actor = Actor::New();
272 // Actor properties which are writable:
273 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN ) );
274 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN_X ) );
275 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN_Y ) );
276 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN_Z ) );
277 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT ) );
278 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT_X ) );
279 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT_Y ) );
280 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT_Z ) );
281 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE ) );
282 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE_WIDTH ) );
283 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE_HEIGHT ) );
284 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE_DEPTH ) );
285 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION ) );
286 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION_X ) );
287 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION_Y ) );
288 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION_Z ) );
289 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ORIENTATION ) );
290 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE ) );
291 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE_X ) );
292 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE_Y ) );
293 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE_Z ) );
294 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::VISIBLE ) );
295 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR ) );
296 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_RED ) );
297 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_GREEN ) );
298 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_BLUE ) );
299 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_ALPHA ) );
301 // World-properties are not writable:
302 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION ) );
303 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_ORIENTATION ) );
304 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_SCALE ) );
305 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_COLOR ) );
306 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION_X ) );
307 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION_Y ) );
308 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION_Z ) );
313 int UtcDaliHandleIsPropertyAnimatable(void)
315 tet_infoline("Positive Test Dali::Handle::IsPropertyAnimatable()");
316 TestApplication application;
318 Actor actor = Actor::New();
320 // Actor properties which are animatable:
321 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN ) );
322 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN_X ) );
323 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN_Y ) );
324 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN_Z ) );
325 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT ) );
326 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT_X ) );
327 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT_Y ) );
328 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT_Z ) );
329 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE ) );
330 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE_WIDTH ) );
331 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE_HEIGHT ) );
332 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE_DEPTH ) );
333 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION ) );
334 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION_X ) );
335 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION_Y ) );
336 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION_Z ) );
337 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::ORIENTATION ) );
338 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE ) );
339 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE_X ) );
340 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE_Y ) );
341 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE_Z ) );
342 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::VISIBLE ) );
343 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR ) );
344 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_RED ) );
345 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_GREEN ) );
346 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_BLUE ) );
347 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_ALPHA ) );
349 // World-properties can not be animated
350 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION ) );
351 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_ORIENTATION ) );
352 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_SCALE ) );
353 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_COLOR ) );
354 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION_X ) );
355 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION_Y ) );
356 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION_Z ) );
361 int UtcDaliHandleIsPropertyAConstraintInput(void)
363 TestApplication application;
365 Actor actor = Actor::New();
367 // Actor properties which can be used as a constraint input:
368 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN ) );
369 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN_X ) );
370 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN_Y ) );
371 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN_Z ) );
372 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT ) );
373 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT_X ) );
374 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT_Y ) );
375 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT_Z ) );
376 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE ) );
377 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_WIDTH ) );
378 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_HEIGHT ) );
379 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_DEPTH ) );
380 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION ) );
381 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_X ) );
382 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_Y ) );
383 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_Z ) );
384 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ORIENTATION ) );
385 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE ) );
386 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE_X ) );
387 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE_Y ) );
388 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE_Z ) );
389 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::VISIBLE ) );
390 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR ) );
391 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_RED ) );
392 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_GREEN ) );
393 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_BLUE ) );
394 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_ALPHA ) );
395 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION ) );
396 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_ORIENTATION ) );
397 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_SCALE ) );
398 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_COLOR ) );
399 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION_X ) );
400 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION_Y ) );
401 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION_Z ) );
403 // Actor properties that cannot be used as a constraint input
404 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::NAME ) );
405 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::SENSITIVE ) );
406 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::LEAVE_REQUIRED ) );
407 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::INHERIT_ORIENTATION ) );
408 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::INHERIT_SCALE ) );
409 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_MODE ) );
410 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_INHERITANCE ) );
411 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::DRAW_MODE ) );
412 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_MODE_FACTOR ) );
418 int UtcDaliHandleGetPropertyType(void)
420 tet_infoline("Positive Test Dali::Handle::GetPropertyType()");
421 TestApplication application;
423 Actor actor = Actor::New();
424 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::PARENT_ORIGIN ) );
425 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::ANCHOR_POINT ) );
426 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::SIZE ) );
427 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::POSITION ) );
428 DALI_TEST_CHECK( Property::ROTATION == actor.GetPropertyType( Actor::Property::ORIENTATION ) );
429 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::SCALE ) );
430 DALI_TEST_CHECK( Property::BOOLEAN == actor.GetPropertyType( Actor::Property::VISIBLE ) );
431 DALI_TEST_CHECK( Property::VECTOR4 == actor.GetPropertyType( Actor::Property::COLOR ) );
433 // Register some dynamic properties
434 Property::Index boolIndex = actor.RegisterProperty( "boolProperty", bool(true) );
435 Property::Index floatIndex = actor.RegisterProperty( "floatProperty", float(123.0f) );
436 Property::Index intIndex = actor.RegisterProperty( "intProperty", 123 );
437 Property::Index vector2Index = actor.RegisterProperty( "vector2Property", Vector2(1.0f, 2.0f) );
438 Property::Index vector3Index = actor.RegisterProperty( "vector3Property", Vector3(1.0f, 2.0f, 3.0f) );
439 Property::Index vector4Index = actor.RegisterProperty( "vector4Property", Vector4(1.0f, 2.0f, 3.0f, 4.0f) );
440 Property::Index rotationIndex = actor.RegisterProperty( "rotationProperty", AngleAxis(Degree(180.0f), Vector3::YAXIS) );
442 DALI_TEST_CHECK( Property::BOOLEAN == actor.GetPropertyType( boolIndex ) );
443 DALI_TEST_CHECK( Property::FLOAT == actor.GetPropertyType( floatIndex ) );
444 DALI_TEST_CHECK( Property::INTEGER == actor.GetPropertyType( intIndex ) );
445 DALI_TEST_CHECK( Property::VECTOR2 == actor.GetPropertyType( vector2Index ) );
446 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( vector3Index ) );
447 DALI_TEST_CHECK( Property::VECTOR4 == actor.GetPropertyType( vector4Index ) );
448 DALI_TEST_CHECK( Property::ROTATION == actor.GetPropertyType( rotationIndex ) );
450 // Non animatable properties
451 Property::Index nonAnimStringIndex = actor.RegisterProperty( "manFromDelmonte", std::string("yes"), Property::READ_WRITE);
452 Property::Index nonAnimV2Index = actor.RegisterProperty( "v2", Vector2(1.f, 2.f), Property::READ_WRITE);
453 Property::Index nonAnimV3Index = actor.RegisterProperty( "v3", Vector3(1.f, 2.f, 3.f), Property::READ_WRITE);
454 Property::Index nonAnimV4Index = actor.RegisterProperty( "v4", Vector4(1.f, 2.f, 3.f, 4.f), Property::READ_WRITE);
455 Property::Index nonAnimBooleanIndex = actor.RegisterProperty( "bool", true, Property::READ_WRITE);
456 Property::Index nonAnimFloatIndex = actor.RegisterProperty( "float", 0.f, Property::READ_WRITE);
457 Property::Index nonAnimIntegerIndex = actor.RegisterProperty( "int", 0, Property::READ_WRITE);
459 DALI_TEST_CHECK( nonAnimStringIndex != Property::INVALID_INDEX );
460 DALI_TEST_CHECK( nonAnimV2Index != Property::INVALID_INDEX );
461 DALI_TEST_CHECK( nonAnimV3Index != Property::INVALID_INDEX );
462 DALI_TEST_CHECK( nonAnimV4Index != Property::INVALID_INDEX );
463 DALI_TEST_CHECK( nonAnimBooleanIndex != Property::INVALID_INDEX );
464 DALI_TEST_CHECK( nonAnimFloatIndex != Property::INVALID_INDEX );
465 DALI_TEST_CHECK( nonAnimIntegerIndex != Property::INVALID_INDEX );
467 DALI_TEST_CHECK( Property::STRING == actor.GetPropertyType( nonAnimStringIndex ) );
468 DALI_TEST_CHECK( Property::VECTOR2 == actor.GetPropertyType( nonAnimV2Index ) );
469 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( nonAnimV3Index ) );
470 DALI_TEST_CHECK( Property::VECTOR4 == actor.GetPropertyType( nonAnimV4Index ) );
471 DALI_TEST_CHECK( Property::BOOLEAN == actor.GetPropertyType( nonAnimBooleanIndex ) );
472 DALI_TEST_CHECK( Property::FLOAT == actor.GetPropertyType( nonAnimFloatIndex ) );
473 DALI_TEST_CHECK( Property::INTEGER == actor.GetPropertyType( nonAnimIntegerIndex ) );
475 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimStringIndex ) );
476 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV2Index ) );
477 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV3Index ) );
478 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV4Index ) );
479 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimBooleanIndex ) );
480 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimFloatIndex ) );
481 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimIntegerIndex ) );
483 DALI_TEST_EQUALS( "yes" , actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
484 DALI_TEST_EQUALS( Vector2(1.f, 2.f) , actor.GetProperty( nonAnimV2Index ).Get<Vector2>(), TEST_LOCATION );
485 DALI_TEST_EQUALS( Vector3(1.f, 2.f, 3.f) , actor.GetProperty( nonAnimV3Index ).Get<Vector3>(), TEST_LOCATION );
486 DALI_TEST_EQUALS( Vector4(1.f, 2.f, 3.f, 4.f) , actor.GetProperty( nonAnimV4Index ).Get<Vector4>(), TEST_LOCATION );
487 DALI_TEST_EQUALS( true, actor.GetProperty( nonAnimBooleanIndex ).Get<bool>(), TEST_LOCATION );
488 DALI_TEST_EQUALS( 0.f, actor.GetProperty( nonAnimFloatIndex ).Get<float>(), TEST_LOCATION );
489 DALI_TEST_EQUALS( 0, actor.GetProperty( nonAnimIntegerIndex ).Get<int>(), TEST_LOCATION );
494 int UtcDaliHandleNonAnimatableProperties(void)
496 tet_infoline("Test Non Animatable Properties");
497 TestApplication application;
499 Actor actor = Actor::New();
501 Property::Index nonAnimStringIndex = actor.RegisterProperty( "manFromDelmonte", std::string("no"), Property::READ_WRITE);
503 //// modify writable?
504 actor.SetProperty( nonAnimStringIndex, Property::Value("yes") );
506 DALI_TEST_CHECK( "yes" == actor.GetProperty( nonAnimStringIndex ).Get<std::string>() );
508 //// cannot modify read only?
509 Property::Index readonly = actor.RegisterProperty( "float", 0.f, Property::READ_ONLY);
511 DALI_TEST_CHECK(!actor.IsPropertyAnimatable(readonly));
512 DALI_TEST_CHECK(!actor.IsPropertyWritable(readonly));
514 actor.SetProperty( readonly, Property::Value(1.f) );
515 // trying to set a read-only property is a no-op
517 DALI_TEST_EQUALS( 0.f, actor.GetProperty( readonly ).Get<float>(), TEST_LOCATION );
519 /// animatable can be set
520 Property::Index write_anim = actor.RegisterProperty( "write_float", 0.f, Property::ANIMATABLE);
522 DALI_TEST_CHECK(actor.IsPropertyAnimatable(write_anim));
523 DALI_TEST_CHECK(actor.IsPropertyWritable(write_anim));
525 actor.SetProperty( write_anim, Property::Value(1.f) );
527 //// animate a non animatable property throws
528 float durationSeconds(2.0f);
529 Animation animation = Animation::New(durationSeconds);
530 bool relativeValue(true);
533 animation.AnimateBy(Property(actor, nonAnimStringIndex), relativeValue, AlphaFunction::EASE_IN);
535 catch ( Dali::DaliException& e )
537 DALI_TEST_ASSERT( e, "Animated value and Property type don't match", TEST_LOCATION );
540 DALI_TEST_EQUALS( "yes", actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
545 int UtcDaliHandleNonAnimtableCompositeProperties(void)
547 tet_infoline("Test Non Animatable Composite Properties");
548 TestApplication application;
550 Actor actor = Actor::New();
552 Property::Value value(Property::ARRAY);
553 Property::Array* array = value.GetArray();
554 DALI_TEST_CHECK( array );
556 array->PushBack( Property::Value( 0.1f ) );
557 array->PushBack( "a string" );
558 array->PushBack( Property::Value( Vector3(1,2,3) ) );
560 DALI_TEST_EQUALS( 3u, array->Count(), TEST_LOCATION );
562 Property::Index propertyIndex = actor.RegisterProperty( "composite", value, Property::READ_WRITE );
564 Property::Value out = actor.GetProperty( propertyIndex );
565 Property::Array* outArray = out.GetArray();
566 DALI_TEST_CHECK( outArray != NULL );
568 DALI_TEST_CHECK( Property::FLOAT == outArray->GetElementAt(0).GetType());
569 DALI_TEST_CHECK( Property::STRING == outArray->GetElementAt(1).GetType());
570 DALI_TEST_CHECK( Property::VECTOR3 == outArray->GetElementAt(2).GetType());
572 DALI_TEST_EQUALS( 0.1f, outArray->GetElementAt(0).Get<float>(), TEST_LOCATION);
573 DALI_TEST_EQUALS( "a string", outArray->GetElementAt(1).Get<std::string>(), TEST_LOCATION);
574 DALI_TEST_EQUALS( Vector3(1,2,3), outArray->GetElementAt(2).Get<Vector3>(), TEST_LOCATION);
576 // composite types not animatable
577 bool exception = false;
580 actor.RegisterProperty( "compositemap", value, Property::ANIMATABLE);
582 catch (Dali::DaliException& e)
585 DALI_TEST_PRINT_ASSERT( e );
588 DALI_TEST_EQUALS(exception, true, TEST_LOCATION);
591 Property::Value mapOfMaps(Property::MAP);
592 Property::Map* map = mapOfMaps.GetMap();
594 map->Insert( "key", Property::Value(Property::MAP) );
595 map->Insert( "2key", "a string" );
597 DALI_TEST_EQUALS( "a string", (*map)["2key"].Get<std::string>(), TEST_LOCATION);
599 Property::Map* innerMap = map->Find("key")->GetMap();
600 innerMap->Insert( "subkey", 5.f );
602 DALI_TEST_CHECK( NULL != map->Find("key")->GetMap()->Find("subkey") );
603 DALI_TEST_EQUALS( 5.f, map->Find("key")->GetMap()->Find("subkey")->Get<float>(), TEST_LOCATION);
607 int UtcDaliHandleSetProperty01(void)
609 tet_infoline("Positive Test Dali::Handle::SetProperty()");
610 TestApplication application;
612 Actor actor = Actor::New();
613 DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
615 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
616 // flush the queue and render once
617 application.SendNotification();
618 application.Render();
619 DALI_TEST_CHECK( ParentOrigin::CENTER == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
623 int UtcDaliHandleSetProperty02(void)
625 tet_infoline("Positive Test Dali::Handle::SetProperty()");
626 TestApplication application;
628 Actor actor = Actor::New();
630 DALI_TEST_CHECK( !actor.IsPropertyWritable( Actor::Property::WORLD_POSITION ) );
632 // World position is not writable so this is a no-op and should not crash
633 actor.SetProperty( Actor::Property::WORLD_POSITION, Vector3(1,2,3) );
638 int UtcDaliHandleRegisterProperty01(void)
640 tet_infoline("Positive Test Dali::Handle::RegisterProperty()");
641 TestApplication application;
643 Stage stage = Stage::GetCurrent();
645 Actor actor = Actor::New();
648 const unsigned int defaultPropertyCount = actor.GetPropertyCount();
650 application.SendNotification();
651 application.Render();
653 Property::Index index1 = actor.RegisterProperty( "MyProperty", Vector3::ONE );
655 application.SendNotification();
656 application.Render();
658 DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 1, TEST_LOCATION );
659 DALI_TEST_EQUALS( actor.GetProperty< Vector3 >( index1 ), Vector3::ONE, TEST_LOCATION );
661 // No new property should be registered when we call the below function
662 Property::Index index2 = actor.RegisterProperty( "MyProperty", Vector3::ZAXIS );
664 application.SendNotification();
665 application.Render();
668 DALI_TEST_EQUALS( index1, index2, TEST_LOCATION ); // We should have the same index as per the first registration
669 DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 1, TEST_LOCATION ); // Property count should be the same
670 DALI_TEST_EQUALS( actor.GetProperty< Vector3 >( index2 ), Vector3::ZAXIS, TEST_LOCATION ); // Value should be what we sent on second RegisterProperty call
675 int UtcDaliHandleRegisterProperty02(void)
677 tet_infoline("Positive Test Dali::Handle::RegisterProperty() int key");
678 TestApplication application;
680 Stage stage = Stage::GetCurrent();
682 Actor actor = Actor::New();
685 const unsigned int defaultPropertyCount = actor.GetPropertyCount();
687 application.SendNotification();
688 application.Render();
690 Property::Index key1 = CORE_PROPERTY_MAX_INDEX+1;
691 Property::Index key2 = CORE_PROPERTY_MAX_INDEX+2;
693 const Vector4 testColor(0.5f, 0.2f, 0.9f, 1.0f);
694 const float withFlake(99.f);
696 Property::Index index1 = actor.RegisterProperty( "MyPropertyOne", Vector3::ONE );
697 Property::Index index2 = DevelHandle::RegisterProperty( actor, key1, "sideColor", testColor);
698 Property::Index index3 = DevelHandle::RegisterProperty( actor, key2, "iceCream", withFlake );
700 application.SendNotification();
701 application.Render();
703 DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 3, TEST_LOCATION );
704 DALI_TEST_EQUALS( actor.GetProperty< Vector3 >( index1 ), Vector3::ONE, TEST_LOCATION );
705 DALI_TEST_EQUALS( actor.GetProperty< Vector4 >( index2 ), testColor, TEST_LOCATION );
706 DALI_TEST_EQUALS( actor.GetProperty< float >( index3 ), withFlake, TEST_LOCATION );
708 // No new property should be registered when we call the below functions
709 Property::Index testIndex2 = actor.RegisterProperty( "iceCream", 2200.f );
710 Property::Index testIndex1 = actor.RegisterProperty( "sideColor", Color::BLACK );
711 application.SendNotification();
712 application.Render();
714 DALI_TEST_EQUALS( index2, testIndex1, TEST_LOCATION ); // We should have the same index as per the first registration
715 DALI_TEST_EQUALS( index3, testIndex2, TEST_LOCATION ); // We should have the same index as per the first registration
716 DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 3, TEST_LOCATION ); // Property count should be the same
717 DALI_TEST_EQUALS( actor.GetProperty< Vector4 >( index2 ), Color::BLACK, TEST_LOCATION ); // Value should be what we sent on second RegisterProperty call
718 DALI_TEST_EQUALS( actor.GetProperty< float >( index3 ), 2200.f, TEST_LOCATION );
725 int UtcDaliHandleGetProperty(void)
727 tet_infoline("Positive Test Dali::Handle::GetProperty()");
728 TestApplication application;
730 Actor actor = Actor::New();
732 DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
733 DALI_TEST_CHECK( AnchorPoint::CENTER == actor.GetProperty( Actor::Property::ANCHOR_POINT ).Get<Vector3>() );
734 DALI_TEST_CHECK( Vector3::ZERO == actor.GetProperty( Actor::Property::SIZE ).Get<Vector3>() );
735 DALI_TEST_CHECK( Vector3::ZERO == actor.GetProperty( Actor::Property::POSITION ).Get<Vector3>() );
736 DALI_TEST_CHECK( Vector3::ONE == actor.GetProperty( Actor::Property::SCALE ).Get<Vector3>() );
737 DALI_TEST_CHECK( true == actor.GetProperty( Actor::Property::VISIBLE ).Get<bool>() );
738 DALI_TEST_CHECK( Color::WHITE == actor.GetProperty( Actor::Property::COLOR ).Get<Vector4>() );
742 int UtcDaliHandleDownCast(void)
744 TestApplication application;
745 tet_infoline("Testing Dali::Handle::DownCast()");
747 Actor actor = Actor::New();
749 BaseHandle baseHandle = actor;
751 Handle handle = Handle::DownCast(baseHandle);
753 DALI_TEST_CHECK( handle );
755 baseHandle = BaseHandle();
757 handle = Handle::DownCast(baseHandle);
759 DALI_TEST_CHECK( !handle );
764 int UtcDaliHandleDownCastNegative(void)
766 TestApplication application;
768 // BaseObject is NOT an Object, so this DownCast should fail
769 BaseHandle handle( new BaseObjectType );
770 Handle customHandle1 = Handle::DownCast( handle );
771 DALI_TEST_CHECK( ! customHandle1 );
773 // A DownCast on an empty handle will also fail
775 Handle customHandle2 = Handle::DownCast( empty );
776 DALI_TEST_CHECK( ! customHandle2 );
780 int UtcDaliHandleGetPropertyIndices(void)
782 TestApplication application;
783 Property::IndexContainer indices;
786 Actor actor = Actor::New();
787 actor.GetPropertyIndices( indices );
788 int numDefaultProperties = indices.Size();
789 DALI_TEST_CHECK( numDefaultProperties > 0 );
790 DALI_TEST_EQUALS( numDefaultProperties, actor.GetPropertyCount(), TEST_LOCATION );
792 const Vector4 testColor(0.5f, 0.2f, 0.9f, 1.0f);
793 const float withFlake(99.f);
795 Property::Index key1 = CORE_PROPERTY_MAX_INDEX+1;
796 Property::Index key2 = CORE_PROPERTY_MAX_INDEX+2;
798 actor.RegisterProperty( "MyPropertyOne", Vector3::ONE );
799 DevelHandle::RegisterProperty( actor, key1, "sideColor", testColor);
800 actor.RegisterProperty( "MyPropertyTwo", 1234 );
801 Property::Index index4 = DevelHandle::RegisterProperty( actor, key2, "iceCream", withFlake );
802 actor.RegisterProperty( "MyPropertyThree", Vector2(.2f,.7f) );
804 actor.GetPropertyIndices( indices );
806 DALI_TEST_EQUALS( indices.Size(), numDefaultProperties + 5, TEST_LOCATION );
807 DALI_TEST_EQUALS( indices[indices.Size()-2], index4, TEST_LOCATION );
812 int UtcDaliHandleRegisterPropertyTypes(void)
814 TestApplication application;
816 struct PropertyTypeAnimatable
819 Property::Value value;
823 Property::Array array;
826 PropertyTypeAnimatable properties[] =
828 { "Property::BOOLEAN", true, true },
829 { "Property::FLOAT", 1.0f, true },
830 { "Property::INTEGER", 1, true },
831 { "Property::VECTOR2", Vector2::ONE, true },
832 { "Property::VECTOR3", Vector3::ONE, true },
833 { "Property::VECTOR4", Vector4::ONE, true },
834 { "Property::MATRIX3", Matrix3::IDENTITY, true },
835 { "Property::MATRIX", Matrix::IDENTITY, true },
836 { "Property::RECTANGLE", Rect<int>(), false },
837 { "Property::ROTATION", AngleAxis(), true },
838 { "Property::STRING", std::string("Me"), false },
839 { "Property::ARRAY", array, false },
840 { "Property::MAP", map, false },
843 unsigned int numOfProperties( sizeof( properties ) / sizeof( properties[0] ) );
845 for ( unsigned int i = 0; i < numOfProperties; ++i )
847 tet_printf( "Testing: %s\n", properties[i].name );
849 bool exception = false;
852 Actor actor = Actor::New();
853 actor.RegisterProperty( "manFromDelmonte", properties[i].value );
855 catch (Dali::DaliException& e)
860 DALI_TEST_CHECK( properties[i].animatable != exception );
865 int UtcDaliHandleCustomProperty(void)
867 TestApplication application;
869 Handle handle = Handle::New();
871 float startValue(1.0f);
872 Property::Index index = handle.RegisterProperty( "testProperty", startValue );
873 DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
875 application.SendNotification();
876 application.Render(0);
877 DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
878 application.Render(0);
879 DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
881 handle.SetProperty( index, 5.0f );
883 application.SendNotification();
884 application.Render(0);
885 DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );
886 application.Render(0);
887 DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );
891 int UtcDaliHandleWeightNew(void)
893 TestApplication application;
895 Handle handle = WeightObject::New();;
896 DALI_TEST_CHECK( handle.GetProperty<float>(WeightObject::WEIGHT) == 0.0f );