Added mechanism for registering child properties on arbitrary actor
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Handle.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
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"
26
27 #include <mesh-builder.h>
28
29 using namespace Dali;
30
31 void handle_test_startup(void)
32 {
33   test_return_value = TET_UNDEF;
34 }
35
36 void handle_test_cleanup(void)
37 {
38   test_return_value = TET_PASS;
39 }
40
41 namespace
42 {
43
44 /// Allows the creation of a BaseObject
45 class BaseObjectType : public BaseObject
46 {
47 public:
48   BaseObjectType()
49   {
50   }
51 };
52
53 Handle ImplicitCopyConstructor(Handle passedByValue)
54 {
55   // object + copy + passedByValue, ref count == 3
56   DALI_TEST_CHECK(passedByValue);
57   if (passedByValue)
58   {
59     DALI_TEST_EQUALS(3, passedByValue.GetBaseObject().ReferenceCount(), TEST_LOCATION);
60   }
61
62   return passedByValue;
63 }
64
65 } // anon namespace
66
67
68 int UtcDaliHandleConstructorVoid(void)
69 {
70   TestApplication application;
71   tet_infoline("Testing Dali::Handle::Handle()");
72
73   Handle object;
74
75   DALI_TEST_CHECK(!object);
76
77   END_TEST;
78 }
79
80 int UtcDaliHandleCopyConstructor(void)
81 {
82   TestApplication application;
83   tet_infoline("Testing Dali::Handle::Handle(const Handle&)");
84
85   // Initialize an object, ref count == 1
86   Handle object = Actor::New();
87
88   DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
89
90   // Copy the object, ref count == 2
91   Handle copy(object);
92   DALI_TEST_CHECK(copy);
93   if (copy)
94   {
95     DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
96   }
97
98   {
99     // Pass by value, and return another copy, ref count == 3
100     Handle anotherCopy = ImplicitCopyConstructor(copy);
101
102     DALI_TEST_CHECK(anotherCopy);
103     if (anotherCopy)
104     {
105       DALI_TEST_EQUALS(3, anotherCopy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
106     }
107   }
108
109   // anotherCopy out of scope, ref count == 2
110   DALI_TEST_CHECK(copy);
111   if (copy)
112   {
113     DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
114   }
115   END_TEST;
116 }
117
118 int UtcDaliHandleAssignmentOperator(void)
119 {
120   TestApplication application;
121   tet_infoline("Testing Dali::Handle::operator=");
122
123   Handle object = Actor::New();
124
125   DALI_TEST_CHECK(object);
126   DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
127
128   Handle copy;
129   DALI_TEST_CHECK(!copy);
130
131   copy = object;
132   DALI_TEST_CHECK(copy);
133   DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
134   DALI_TEST_CHECK(&(copy.GetBaseObject()) == &(object.GetBaseObject()));
135   END_TEST;
136 }
137
138 int UtcDaliHandleSupports(void)
139 {
140   tet_infoline("Positive Test Dali::Handle::Supports()");
141   TestApplication application;
142
143   Actor actor = Actor::New();
144   DALI_TEST_CHECK( true == actor.Supports( Handle::DYNAMIC_PROPERTIES ) );
145   END_TEST;
146 }
147
148 int UtcDaliHandleGetPropertyCount(void)
149 {
150   tet_infoline("Positive Test Dali::Handle::GetPropertyCount()");
151   TestApplication application;
152
153   Actor actor = Actor::New();
154   int defaultPropertyCount( actor.GetPropertyCount() );
155
156   // Register a dynamic property
157   actor.RegisterProperty( "testProperty",  float(123.0f) );
158   DALI_TEST_CHECK( (defaultPropertyCount + 1u) == actor.GetPropertyCount() );
159   END_TEST;
160 }
161
162 int UtcDaliHandleGetPropertyName(void)
163 {
164   tet_infoline("Positive Test Dali::Handle::GetPropertyName()");
165   TestApplication application;
166
167   Actor actor = Actor::New();
168   DALI_TEST_CHECK( "parentOrigin" == actor.GetPropertyName( Actor::Property::PARENT_ORIGIN ) );
169
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 ) );
174
175   END_TEST;
176 }
177
178 int UtcDaliHandleGetPropertyIndex01(void)
179 {
180   tet_infoline("Positive Test Dali::Handle::GetPropertyIndex()");
181   TestApplication application;
182
183   Actor actor = Actor::New();
184   DALI_TEST_CHECK( Actor::Property::PARENT_ORIGIN == actor.GetPropertyIndex("parentOrigin") );
185
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 ) );
190   END_TEST;
191 }
192
193 int UtcDaliHandleGetPropertyIndex02(void)
194 {
195   tet_infoline("Positive Test Dali::Handle::GetPropertyIndex() int key");
196   TestApplication application;
197
198   Stage stage = Stage::GetCurrent();
199
200   Actor actor = Actor::New();
201   stage.Add( actor );
202
203   const unsigned int defaultPropertyCount = actor.GetPropertyCount();
204
205   application.SendNotification();
206   application.Render();
207
208   Property::Index key1 = CORE_PROPERTY_MAX_INDEX+1;
209   Property::Index key2 = CORE_PROPERTY_MAX_INDEX+2;
210
211   const Vector4 testColor(0.5f, 0.2f, 0.9f, 1.0f);
212   const float withFlake(99.f);
213
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 );
219
220   application.SendNotification();
221   application.Render();
222
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 );
226
227   DALI_TEST_EQUALS( index2, testIndex1, TEST_LOCATION );
228   DALI_TEST_EQUALS( index4, testIndex2, TEST_LOCATION );
229
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);
241
242   DALI_TEST_EQUALS(defaultPropertyCount+5, actor.GetPropertyCount(), TEST_LOCATION);
243   END_TEST;
244 }
245
246 int UtcDaliHandleGetPropertyIndex03(void)
247 {
248   TestApplication application;
249
250   Actor actor = Actor::New();
251
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 );
256
257   DALI_TEST_EQUALS( myIndex, DevelHandle::GetPropertyIndex( actor, intKey ), TEST_LOCATION );
258
259   Property::Key key1(myName);
260   Property::Key key2(intKey);
261
262   DALI_TEST_EQUALS( myIndex, DevelHandle::GetPropertyIndex( actor, key1 ), TEST_LOCATION );
263   DALI_TEST_EQUALS( myIndex, DevelHandle::GetPropertyIndex( actor, key2 ), TEST_LOCATION );
264   END_TEST;
265 }
266
267
268 int UtcDaliHandleIsPropertyWritable(void)
269 {
270   tet_infoline("Positive Test Dali::Handle::IsPropertyWritable()");
271   TestApplication application;
272
273   Actor actor = Actor::New();
274
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 ) );
304
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 ) );
313
314   END_TEST;
315 }
316
317 int UtcDaliHandleIsPropertyAnimatable(void)
318 {
319   tet_infoline("Positive Test Dali::Handle::IsPropertyAnimatable()");
320   TestApplication application;
321
322   Actor actor = Actor::New();
323
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 ) );
353
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 ) );
362
363   END_TEST;
364 }
365
366 int UtcDaliHandleIsPropertyAConstraintInput(void)
367 {
368   TestApplication application;
369
370   Actor actor = Actor::New();
371
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 ) );
408
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 ) );
419
420   END_TEST;
421 }
422
423
424 int UtcDaliHandleGetPropertyType(void)
425 {
426   tet_infoline("Positive Test Dali::Handle::GetPropertyType()");
427   TestApplication application;
428
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 ) );
438
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) );
447
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 ) );
455
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);
464
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 );
472
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 ) );
480
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 ) );
488
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 );
496
497   END_TEST;
498 }
499
500 int UtcDaliHandleNonAnimatableProperties(void)
501 {
502   tet_infoline("Test Non Animatable Properties");
503   TestApplication application;
504
505   Actor actor = Actor::New();
506
507   Property::Index nonAnimStringIndex = actor.RegisterProperty( "manFromDelmonte", std::string("no"), Property::READ_WRITE);
508
509   //// modify writable?
510   actor.SetProperty( nonAnimStringIndex, Property::Value("yes") );
511
512   DALI_TEST_CHECK( "yes"  == actor.GetProperty( nonAnimStringIndex ).Get<std::string>() );
513
514   //// cannot modify read only?
515   Property::Index readonly = actor.RegisterProperty( "float", 0.f, Property::READ_ONLY);
516
517   DALI_TEST_CHECK(!actor.IsPropertyAnimatable(readonly));
518   DALI_TEST_CHECK(!actor.IsPropertyWritable(readonly));
519
520   actor.SetProperty( readonly, Property::Value(1.f) );
521   // trying to set a read-only property is a no-op
522
523   DALI_TEST_EQUALS( 0.f, actor.GetProperty( readonly ).Get<float>(), TEST_LOCATION );
524
525   /// animatable can be set
526   Property::Index write_anim = actor.RegisterProperty( "write_float", 0.f, Property::ANIMATABLE);
527
528   DALI_TEST_CHECK(actor.IsPropertyAnimatable(write_anim));
529   DALI_TEST_CHECK(actor.IsPropertyWritable(write_anim));
530
531   actor.SetProperty( write_anim, Property::Value(1.f) );
532
533   //// animate a non animatable property throws
534   float durationSeconds(2.0f);
535   Animation animation = Animation::New(durationSeconds);
536   bool relativeValue(true);
537   try
538   {
539     animation.AnimateBy(Property(actor, nonAnimStringIndex), relativeValue, AlphaFunction::EASE_IN);
540   }
541   catch ( Dali::DaliException& e )
542   {
543     DALI_TEST_ASSERT( e, "Animated value and Property type don't match", TEST_LOCATION );
544   }
545
546   DALI_TEST_EQUALS( "yes", actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
547
548   END_TEST;
549 }
550
551 int UtcDaliHandleNonAnimtableCompositeProperties(void)
552 {
553   tet_infoline("Test Non Animatable Composite Properties");
554   TestApplication application;
555
556   Actor actor = Actor::New();
557
558   Property::Value value(Property::ARRAY);
559   Property::Array* array = value.GetArray();
560   DALI_TEST_CHECK( array );
561
562   array->PushBack( Property::Value( 0.1f ) );
563   array->PushBack( "a string" );
564   array->PushBack( Property::Value( Vector3(1,2,3) ) );
565
566   DALI_TEST_EQUALS( 3u, array->Count(), TEST_LOCATION );
567
568   Property::Index propertyIndex = actor.RegisterProperty( "composite", value, Property::READ_WRITE );
569
570   Property::Value out = actor.GetProperty( propertyIndex );
571   Property::Array* outArray = out.GetArray();
572   DALI_TEST_CHECK( outArray != NULL );
573
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());
577
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);
581
582   // composite types not animatable
583   bool exception = false;
584   try
585   {
586     actor.RegisterProperty( "compositemap", value, Property::ANIMATABLE);
587   }
588   catch (Dali::DaliException& e)
589   {
590     exception = true;
591     DALI_TEST_PRINT_ASSERT( e );
592   }
593
594   DALI_TEST_EQUALS(exception, true, TEST_LOCATION);
595
596   // Map of maps
597   Property::Value mapOfMaps(Property::MAP);
598   Property::Map* map = mapOfMaps.GetMap();
599
600   map->Insert( "key", Property::Value(Property::MAP) );
601   map->Insert( "2key", "a string" );
602
603   DALI_TEST_EQUALS( "a string",  (*map)["2key"].Get<std::string>(),  TEST_LOCATION);
604
605   Property::Map* innerMap = map->Find("key")->GetMap();
606   innerMap->Insert( "subkey", 5.f );
607
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);
610   END_TEST;
611 }
612
613 int UtcDaliHandleSetProperty01(void)
614 {
615   tet_infoline("Positive Test Dali::Handle::SetProperty()");
616   TestApplication application;
617
618   Actor actor = Actor::New();
619   DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
620
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>() );
626   END_TEST;
627 }
628
629 int UtcDaliHandleSetProperty02(void)
630 {
631   tet_infoline("Positive Test Dali::Handle::SetProperty()");
632   TestApplication application;
633
634   Actor actor = Actor::New();
635
636   DALI_TEST_CHECK( !actor.IsPropertyWritable( Actor::Property::WORLD_POSITION ) );
637
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) );
640
641   END_TEST;
642 }
643
644 int UtcDaliHandleRegisterProperty01(void)
645 {
646   tet_infoline("Positive Test Dali::Handle::RegisterProperty()");
647   TestApplication application;
648
649   Stage stage = Stage::GetCurrent();
650
651   Actor actor = Actor::New();
652   stage.Add( actor );
653
654   const unsigned int defaultPropertyCount = actor.GetPropertyCount();
655
656   application.SendNotification();
657   application.Render();
658
659   Property::Index index1 = actor.RegisterProperty( "MyProperty", Vector3::ONE );
660
661   application.SendNotification();
662   application.Render();
663
664   DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 1, TEST_LOCATION );
665   DALI_TEST_EQUALS( actor.GetProperty< Vector3 >( index1 ), Vector3::ONE, TEST_LOCATION );
666
667   // No new property should be registered when we call the below function
668   Property::Index index2 = actor.RegisterProperty( "MyProperty", Vector3::ZAXIS );
669
670   application.SendNotification();
671   application.Render();
672
673
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
677
678   END_TEST;
679 }
680
681 int UtcDaliHandleRegisterProperty02(void)
682 {
683   tet_infoline("Positive Test Dali::Handle::RegisterProperty() int key");
684   TestApplication application;
685
686   Stage stage = Stage::GetCurrent();
687
688   Actor actor = Actor::New();
689   stage.Add( actor );
690
691   const unsigned int defaultPropertyCount = actor.GetPropertyCount();
692
693   application.SendNotification();
694   application.Render();
695
696   Property::Index key1 = CORE_PROPERTY_MAX_INDEX+1;
697   Property::Index key2 = CORE_PROPERTY_MAX_INDEX+2;
698
699   const Vector4 testColor(0.5f, 0.2f, 0.9f, 1.0f);
700   const float withFlake(99.f);
701
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 );
705
706   application.SendNotification();
707   application.Render();
708
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 );
713
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();
719
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 );
725
726   END_TEST;
727 }
728
729
730
731 int UtcDaliHandleGetProperty(void)
732 {
733   tet_infoline("Positive Test Dali::Handle::GetProperty()");
734   TestApplication application;
735
736   Actor actor = Actor::New();
737
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>() );
745   END_TEST;
746 }
747
748 int UtcDaliHandleDownCast(void)
749 {
750   TestApplication application;
751   tet_infoline("Testing Dali::Handle::DownCast()");
752
753   Actor actor = Actor::New();
754
755   BaseHandle baseHandle = actor;
756
757   Handle handle = Handle::DownCast(baseHandle);
758
759   DALI_TEST_CHECK( handle );
760
761   baseHandle = BaseHandle();
762
763   handle = Handle::DownCast(baseHandle);
764
765   DALI_TEST_CHECK( !handle );
766
767   END_TEST;
768 }
769
770 int UtcDaliHandleDownCastNegative(void)
771 {
772   TestApplication application;
773
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 );
778
779   // A DownCast on an empty handle will also fail
780   Handle empty;
781   Handle customHandle2 = Handle::DownCast( empty );
782   DALI_TEST_CHECK( ! customHandle2 );
783   END_TEST;
784 }
785
786 int UtcDaliHandleGetPropertyIndices(void)
787 {
788   TestApplication application;
789   Property::IndexContainer indices;
790
791   // Actor
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 );
797
798   const Vector4 testColor(0.5f, 0.2f, 0.9f, 1.0f);
799   const float withFlake(99.f);
800
801   Property::Index key1 = CORE_PROPERTY_MAX_INDEX+1;
802   Property::Index key2 = CORE_PROPERTY_MAX_INDEX+2;
803
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) );
809
810   actor.GetPropertyIndices( indices );
811
812   DALI_TEST_EQUALS( indices.Size(), numDefaultProperties + 5, TEST_LOCATION );
813   DALI_TEST_EQUALS( indices[indices.Size()-2], index4, TEST_LOCATION );
814
815   END_TEST;
816 }
817
818 int UtcDaliHandleRegisterPropertyTypes(void)
819 {
820   TestApplication application;
821
822   struct PropertyTypeAnimatable
823   {
824     const char * name;
825     Property::Value value;
826     bool animatable;
827   };
828
829   Property::Array array;
830   Property::Map map;
831
832   PropertyTypeAnimatable properties[] =
833   {
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 },
847   };
848
849   unsigned int numOfProperties( sizeof( properties ) / sizeof( properties[0] ) );
850
851   for ( unsigned int i = 0; i < numOfProperties; ++i )
852   {
853     tet_printf( "Testing: %s\n", properties[i].name );
854
855     bool exception = false;
856     try
857     {
858       Actor actor = Actor::New();
859       actor.RegisterProperty( "manFromDelmonte",   properties[i].value );
860     }
861     catch (Dali::DaliException& e)
862     {
863       exception = true;
864     }
865
866     DALI_TEST_CHECK( properties[i].animatable != exception );
867   }
868   END_TEST;
869 }
870
871 int UtcDaliHandleCustomProperty(void)
872 {
873   TestApplication application;
874
875   Handle handle = Handle::New();
876
877   float startValue(1.0f);
878   Property::Index index = handle.RegisterProperty( "testProperty",  startValue );
879   DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
880
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 );
886
887   handle.SetProperty( index, 5.0f );
888
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 );
894   END_TEST;
895 }
896
897 int UtcDaliHandleWeightNew(void)
898 {
899   TestApplication application;
900
901   Handle handle = WeightObject::New();
902   DALI_TEST_CHECK( handle.GetProperty<float>(WeightObject::WEIGHT) == 0.0f );
903
904   // process the message so scene object is added to update manager
905   application.SendNotification();
906   application.Render(0);
907
908   // no message to release scene object in this scenario
909
910   END_TEST;
911 }
912
913 int UtcDaliHandleWeightNew2(void)
914 {
915   TestApplication application;
916
917   // scope for the weight object
918   {
919     Handle handle = WeightObject::New();
920     DALI_TEST_CHECK( handle.GetProperty<float>(WeightObject::WEIGHT) == 0.0f );
921
922     // process the message so scene object is added to update manager
923     application.SendNotification();
924     application.Render(0);
925   }
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);
930
931   END_TEST;
932 }
933
934 int UtcDaliHandleSetTypeInfo(void)
935 {
936   TestApplication application;
937   TypeRegistry typeRegistry = TypeRegistry::Get();
938
939   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
940   DALI_TEST_CHECK( typeInfo );
941
942   Actor actor = Actor::DownCast(typeInfo.CreateInstance());
943   DALI_TEST_CHECK( actor );
944
945   DevelHandle::SetTypeInfo(actor, typeInfo);
946
947   TypeInfo newTypeInfo;
948   bool success = actor.GetTypeInfo( newTypeInfo );
949   DALI_TEST_CHECK( success );
950
951   DALI_TEST_CHECK(typeInfo.GetName() == newTypeInfo.GetName());
952   DALI_TEST_CHECK(typeInfo.GetBaseName() == newTypeInfo.GetBaseName());
953
954   END_TEST;
955 }
956
957 int UtcDaliHandleCustomPropertySynchronousGetSet(void)
958 {
959   TestApplication application;
960
961   tet_infoline( "Create a custom property and set the value ensuring it can be retrieved synchronously" );
962
963   Actor actor = Actor::New();
964   Stage::GetCurrent().Add( actor );
965
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 );
970
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 );
975
976   tet_infoline( "Render and retrieve values again" );
977   application.SendNotification();
978   application.Render(0);
979
980   DALI_TEST_EQUALS( actor.GetProperty< float >( index ), 5.0f, TEST_LOCATION );
981   DALI_TEST_EQUALS( actor.GetCurrentProperty< float >( index ), 5.0f, TEST_LOCATION );
982
983   END_TEST;
984 }
985
986 int UtcDaliHandleCustomPropertyGetType(void)
987 {
988   TestApplication application;
989
990   tet_infoline( "Create a custom property and retrieve its type" );
991
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 );
995
996   END_TEST;
997 }
998
999 int UtcDaliHandleCustomPropertyAccessMode(void)
1000 {
1001   TestApplication application;
1002
1003   tet_infoline( "Create a custom property and retrieve whether it's animatable etc." );
1004
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 );
1009
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 );
1013
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 );
1017
1018   END_TEST;
1019 }
1020
1021 int UtcDaliHandleGetCurrentProperty(void)
1022 {
1023   TestApplication application;
1024
1025   tet_infoline( "Get a default and non-animatable custom property using the GetCurrentProperty API" );
1026
1027   Actor actor = Actor::New();
1028   Stage::GetCurrent().Add( actor );
1029   DALI_TEST_EQUALS( actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ), true, TEST_LOCATION );
1030
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 );
1034
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 );
1038
1039   END_TEST;
1040 }
1041
1042 int UtcDaliHandleDoesCustomPropertyExistP1(void)
1043 {
1044   TestApplication application; // Needs type registry
1045
1046   tet_infoline( "Test if a registered custom property exists on object" );
1047
1048   Actor actor = Actor::New();
1049   auto propertyIndex = actor.RegisterProperty("customProperty1", 1.0f);
1050
1051   DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( actor, propertyIndex ), true, TEST_LOCATION );
1052   END_TEST;
1053 }
1054
1055 int UtcDaliHandleDoesCustomPropertyExistN1(void)
1056 {
1057   TestApplication application; // Needs type registry
1058
1059   tet_infoline( "Test if a registered custom property does not exist on object" );
1060
1061   Actor actor = Actor::New();
1062   auto propertyIndex = actor.RegisterProperty("customProperty1", 1.0f);
1063
1064   DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( actor, propertyIndex+1 ), false, TEST_LOCATION );
1065   END_TEST;
1066 }
1067
1068 int UtcDaliHandleDoesCustomPropertyExistN2(void)
1069 {
1070   TestApplication application; // Needs type registry
1071
1072   tet_infoline( "Test that a default property does not show as a custom property on object" );
1073
1074   Actor actor = Actor::New();
1075   DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( actor, Actor::Property::POSITION ), false, TEST_LOCATION );
1076   END_TEST;
1077 }
1078
1079 int UtcDaliHandleDoesCustomPropertyExistN3(void)
1080 {
1081   TestApplication application; // Needs type registry
1082
1083   tet_infoline( "Test that a child property does not exist on actor after parenting to container" );
1084   TypeRegistry typeRegistry = TypeRegistry::Get();
1085
1086   auto customActorTypeInfo = typeRegistry.GetTypeInfo( typeid(Test::TestCustomActor) );
1087
1088   const Property::Index CHILD_PROPERTY( CHILD_PROPERTY_REGISTRATION_START_INDEX );
1089   const char* CHILD_PROPERTY_NAME( "childProperty" );
1090
1091   ChildPropertyRegistration( customActorTypeInfo.GetName(), CHILD_PROPERTY_NAME, CHILD_PROPERTY, Property::INTEGER );
1092
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)
1097
1098   DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), false, TEST_LOCATION );
1099   END_TEST;
1100 }
1101
1102 int UtcDaliHandleDoesCustomPropertyExistP2(void)
1103 {
1104   TestApplication application; // Needs type registry
1105
1106   tet_infoline( "Test that a child property exists after being set" );
1107   TypeRegistry typeRegistry = TypeRegistry::Get();
1108
1109   auto customActorTypeInfo = typeRegistry.GetTypeInfo( typeid(Test::TestCustomActor) );
1110
1111   const Property::Index CHILD_PROPERTY( CHILD_PROPERTY_REGISTRATION_START_INDEX );
1112   const char* CHILD_PROPERTY_NAME( "childProperty" );
1113
1114   ChildPropertyRegistration( customActorTypeInfo.GetName(), CHILD_PROPERTY_NAME, CHILD_PROPERTY, Property::INTEGER );
1115
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 );
1121
1122   DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), true, TEST_LOCATION );
1123   DALI_TEST_EQUALS( child.GetProperty<int>( CHILD_PROPERTY ), 2, TEST_LOCATION );
1124   END_TEST;
1125 }
1126
1127 int UtcDaliHandleDoesCustomPropertyExistP3(void)
1128 {
1129   TestApplication application; // Needs type registry
1130
1131   tet_infoline( "Test that a child property is re-indexed after registration, and that it exists" );
1132   TypeRegistry typeRegistry = TypeRegistry::Get();
1133
1134   auto customActorTypeInfo = typeRegistry.GetTypeInfo( typeid(Test::TestCustomActor) );
1135
1136   const Property::Index CHILD_PROPERTY( CHILD_PROPERTY_REGISTRATION_START_INDEX );
1137   const char* CHILD_PROPERTY_NAME( "childProperty" );
1138
1139   ChildPropertyRegistration( customActorTypeInfo.GetName(), CHILD_PROPERTY_NAME, CHILD_PROPERTY, Property::INTEGER );
1140
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)
1146
1147   DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), true, TEST_LOCATION );
1148   DALI_TEST_EQUALS( child.GetProperty<int>( CHILD_PROPERTY ), 3, TEST_LOCATION );
1149   END_TEST;
1150 }
1151
1152 namespace
1153 {
1154
1155 struct PropertySetSignalCheck
1156 {
1157   PropertySetSignalCheck(bool& signalReceived, Property::Value& value)
1158   : mSignalReceived(signalReceived),
1159     mValue(value)
1160   {
1161   }
1162
1163   void operator()(Handle& handle, Property::Index index, Property::Value value)
1164   {
1165     mSignalReceived = true;
1166     mValue = value;
1167   }
1168
1169   void Reset()
1170   {
1171     mSignalReceived = false;
1172   }
1173
1174   void CheckSignalReceived()
1175   {
1176     if (!mSignalReceived)
1177     {
1178       tet_printf("Expected Property Set signal was not received\n");
1179       tet_result(TET_FAIL);
1180     }
1181     else
1182     {
1183       tet_result(TET_PASS);
1184     }
1185   }
1186
1187   bool& mSignalReceived; // owned by individual tests
1188   Property::Value& mValue;
1189 };
1190
1191 } // anon namespace
1192
1193 int UtcDaliHandlePropertySetSignal01(void)
1194 {
1195   TestApplication app;
1196
1197   bool signalReceived(false);
1198   Property::Value value;
1199   PropertySetSignalCheck propertySetCheck(signalReceived, value);
1200
1201   tet_infoline( "Test that setting a default property triggers a signal" );
1202
1203   auto actor = Actor::New();
1204   DevelHandle::PropertySetSignal(actor).Connect(&app, propertySetCheck);
1205
1206   actor.SetProperty( Actor::Property::POSITION, Vector3::XAXIS );
1207   propertySetCheck.CheckSignalReceived();
1208
1209   END_TEST;
1210 }
1211
1212
1213 int UtcDaliHandlePropertySetSignal02(void)
1214 {
1215   TestApplication app;
1216
1217   bool signalReceived(false);
1218   Property::Value value;
1219   PropertySetSignalCheck propertySetCheck(signalReceived, value);
1220
1221   tet_infoline( "Test that setting a custom property triggers a signal" );
1222
1223   auto actor = Actor::New();
1224   DevelHandle::PropertySetSignal(actor).Connect(&app, propertySetCheck);
1225
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 );
1230
1231   END_TEST;
1232 }
1233
1234 int UtcDaliHandlePropertySetSignal03(void)
1235 {
1236   TestApplication app;
1237   TypeRegistry typeRegistry = TypeRegistry::Get();
1238
1239   bool signalReceived(false);
1240   Property::Value value;
1241   PropertySetSignalCheck propertySetCheck(signalReceived, value);
1242
1243   tet_infoline( "Test that setting a child property triggers a signal" );
1244
1245   auto customActorTypeInfo = typeRegistry.GetTypeInfo( typeid(Test::TestCustomActor) );
1246
1247   const Property::Index CHILD_PROPERTY( CHILD_PROPERTY_REGISTRATION_START_INDEX );
1248   const char* CHILD_PROPERTY_NAME( "childProperty" );
1249
1250   ChildPropertyRegistration( customActorTypeInfo.GetName(), CHILD_PROPERTY_NAME, CHILD_PROPERTY, Property::INTEGER );
1251
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)
1258
1259   DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), true, TEST_LOCATION );
1260   DALI_TEST_EQUALS( child.GetProperty<int>( CHILD_PROPERTY ), 3, TEST_LOCATION );
1261
1262   child.SetProperty( CHILD_PROPERTY, 29 );
1263   propertySetCheck.CheckSignalReceived();
1264   DALI_TEST_EQUALS( propertySetCheck.mValue, Property::Value( 29 ), TEST_LOCATION );
1265   END_TEST;
1266 }