Merge "Added animation and constraint support for UNSIGNED_INTEGER property type...
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Handle.cpp
1 /*
2  * Copyright (c) 2014 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-test-suite-utils/dali-test-suite-utils.h"
23
24 using namespace Dali;
25
26 void handle_test_startup(void)
27 {
28   test_return_value = TET_UNDEF;
29 }
30
31 void handle_test_cleanup(void)
32 {
33   test_return_value = TET_PASS;
34 }
35
36 namespace
37 {
38
39 /// Allows the creation of a BaseObject
40 class BaseObjectType : public BaseObject
41 {
42 public:
43   BaseObjectType()
44   {
45   }
46 };
47
48 Handle ImplicitCopyConstructor(Handle passedByValue)
49 {
50   // object + copy + passedByValue, ref count == 3
51   DALI_TEST_CHECK(passedByValue);
52   if (passedByValue)
53   {
54     DALI_TEST_EQUALS(3, passedByValue.GetBaseObject().ReferenceCount(), TEST_LOCATION);
55   }
56
57   return passedByValue;
58 }
59
60 } // anon namespace
61
62
63 int UtcDaliHandleConstructorVoid(void)
64 {
65   TestApplication application;
66   tet_infoline("Testing Dali::Handle::Handle()");
67
68   Handle object;
69
70   DALI_TEST_CHECK(!object);
71   END_TEST;
72 }
73
74 int UtcDaliHandleCopyConstructor(void)
75 {
76   TestApplication application;
77   tet_infoline("Testing Dali::Handle::Handle(const Handle&)");
78
79   // Initialize an object, ref count == 1
80   Handle object = Actor::New();
81
82   DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
83
84   // Copy the object, ref count == 2
85   Handle copy(object);
86   DALI_TEST_CHECK(copy);
87   if (copy)
88   {
89     DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
90   }
91
92   {
93     // Pass by value, and return another copy, ref count == 3
94     Handle anotherCopy = ImplicitCopyConstructor(copy);
95
96     DALI_TEST_CHECK(anotherCopy);
97     if (anotherCopy)
98     {
99       DALI_TEST_EQUALS(3, anotherCopy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
100     }
101   }
102
103   // anotherCopy out of scope, ref count == 2
104   DALI_TEST_CHECK(copy);
105   if (copy)
106   {
107     DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
108   }
109   END_TEST;
110 }
111
112 int UtcDaliHandleAssignmentOperator(void)
113 {
114   TestApplication application;
115   tet_infoline("Testing Dali::Handle::operator=");
116
117   Handle object = Actor::New();
118
119   DALI_TEST_CHECK(object);
120   DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
121
122   Handle copy;
123   DALI_TEST_CHECK(!copy);
124
125   copy = object;
126   DALI_TEST_CHECK(copy);
127   DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
128   DALI_TEST_CHECK(&(copy.GetBaseObject()) == &(object.GetBaseObject()));
129   END_TEST;
130 }
131
132 int UtcDaliHandleSupports(void)
133 {
134   tet_infoline("Positive Test Dali::Handle::Supports()");
135   TestApplication application;
136
137   Actor actor = Actor::New();
138   DALI_TEST_CHECK( true == actor.Supports( Handle::DYNAMIC_PROPERTIES ) );
139   END_TEST;
140 }
141
142 int UtcDaliHandleGetPropertyCount(void)
143 {
144   tet_infoline("Positive Test Dali::Handle::GetPropertyCount()");
145   TestApplication application;
146
147   Actor actor = Actor::New();
148   int defaultPropertyCount( actor.GetPropertyCount() );
149
150   // Register a dynamic property
151   actor.RegisterProperty( "test-property", float(123.0f) );
152   DALI_TEST_CHECK( (defaultPropertyCount + 1u) == actor.GetPropertyCount() );
153   END_TEST;
154 }
155
156 int UtcDaliHandleGetPropertyName(void)
157 {
158   tet_infoline("Positive Test Dali::Handle::GetPropertyName()");
159   TestApplication application;
160
161   Actor actor = Actor::New();
162   DALI_TEST_CHECK( "parent-origin" == actor.GetPropertyName( Actor::Property::PARENT_ORIGIN ) );
163
164   // Register a dynamic property
165   std::string name("this-name-should-match");
166   Property::Index index = actor.RegisterProperty( name, float(123.0f) );
167   DALI_TEST_CHECK( name == actor.GetPropertyName( index ) );
168
169   END_TEST;
170 }
171
172 int UtcDaliHandleGetPropertyIndex(void)
173 {
174   tet_infoline("Positive Test Dali::Handle::GetPropertyIndex()");
175   TestApplication application;
176
177   Actor actor = Actor::New();
178   DALI_TEST_CHECK( Actor::Property::PARENT_ORIGIN == actor.GetPropertyIndex("parent-origin") );
179
180   // Register a dynamic property
181   std::string name("this-name-should-match");
182   Property::Index index = actor.RegisterProperty( name, float(123.0f) );
183   DALI_TEST_CHECK( index == actor.GetPropertyIndex( name ) );
184   END_TEST;
185 }
186
187 int UtcDaliHandleIsPropertyWritable(void)
188 {
189   tet_infoline("Positive Test Dali::Handle::IsPropertyWritable()");
190   TestApplication application;
191
192   Actor actor = Actor::New();
193
194   // Actor properties which are writable:
195   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN ) );
196   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN_X ) );
197   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN_Y ) );
198   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN_Z ) );
199   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT ) );
200   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT_X ) );
201   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT_Y ) );
202   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT_Z ) );
203   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE ) );
204   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE_WIDTH  ) );
205   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE_HEIGHT ) );
206   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE_DEPTH  ) );
207   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION ) );
208   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION_X ) );
209   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION_Y ) );
210   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION_Z ) );
211   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ORIENTATION ) );
212   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE ) );
213   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE_X ) );
214   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE_Y ) );
215   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE_Z ) );
216   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::VISIBLE ) );
217   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR ) );
218   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_RED ) );
219   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_GREEN ) );
220   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_BLUE ) );
221   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_ALPHA ) );
222
223   // World-properties are not writable:
224   DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION ) );
225   DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_ORIENTATION ) );
226   DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_SCALE ) );
227   DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_COLOR ) );
228   DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION_X ) );
229   DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION_Y ) );
230   DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION_Z ) );
231
232   END_TEST;
233 }
234
235 int UtcDaliHandleIsPropertyAnimatable(void)
236 {
237   tet_infoline("Positive Test Dali::Handle::IsPropertyAnimatable()");
238   TestApplication application;
239
240   Actor actor = Actor::New();
241
242   // Actor properties which are animatable:
243   DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN ) );
244   DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN_X ) );
245   DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN_Y ) );
246   DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN_Z ) );
247   DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT ) );
248   DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT_X ) );
249   DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT_Y ) );
250   DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT_Z ) );
251   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE ) );
252   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE_WIDTH  ) );
253   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE_HEIGHT ) );
254   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE_DEPTH  ) );
255   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION ) );
256   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION_X ) );
257   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION_Y ) );
258   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION_Z ) );
259   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::ORIENTATION ) );
260   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE ) );
261   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE_X ) );
262   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE_Y ) );
263   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE_Z ) );
264   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::VISIBLE ) );
265   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR ) );
266   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_RED ) );
267   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_GREEN ) );
268   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_BLUE ) );
269   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_ALPHA ) );
270
271   // World-properties can not be animated
272   DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION ) );
273   DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_ORIENTATION ) );
274   DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_SCALE ) );
275   DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_COLOR ) );
276   DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION_X ) );
277   DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION_Y ) );
278   DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION_Z ) );
279
280   END_TEST;
281 }
282
283 int UtcDaliHandleIsPropertyAConstraintInput(void)
284 {
285   TestApplication application;
286
287   Actor actor = Actor::New();
288
289   // Actor properties which can be used as a constraint input:
290   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN ) );
291   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN_X ) );
292   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN_Y ) );
293   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN_Z ) );
294   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT ) );
295   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT_X ) );
296   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT_Y ) );
297   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT_Z ) );
298   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE ) );
299   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_WIDTH  ) );
300   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_HEIGHT ) );
301   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_DEPTH  ) );
302   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION ) );
303   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_X ) );
304   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_Y ) );
305   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_Z ) );
306   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ORIENTATION ) );
307   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE ) );
308   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE_X ) );
309   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE_Y ) );
310   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE_Z ) );
311   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::VISIBLE ) );
312   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR ) );
313   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_RED ) );
314   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_GREEN ) );
315   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_BLUE ) );
316   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_ALPHA ) );
317   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION ) );
318   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_ORIENTATION ) );
319   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_SCALE ) );
320   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_COLOR ) );
321   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION_X ) );
322   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION_Y ) );
323   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION_Z ) );
324
325   // Actor properties that cannot be used as a constraint input
326   DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::NAME ) );
327   DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::SENSITIVE ) );
328   DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::LEAVE_REQUIRED ) );
329   DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::INHERIT_ORIENTATION ) );
330   DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::INHERIT_SCALE ) );
331   DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_MODE ) );
332   DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_INHERITANCE ) );
333   DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::DRAW_MODE ) );
334   DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_MODE_FACTOR ) );
335
336   END_TEST;
337 }
338
339
340 int UtcDaliHandleGetPropertyType(void)
341 {
342   tet_infoline("Positive Test Dali::Handle::GetPropertyType()");
343   TestApplication application;
344   unsigned int unsingedIntTest = 33;
345
346   Actor actor = Actor::New();
347   DALI_TEST_CHECK( Property::VECTOR3  == actor.GetPropertyType( Actor::Property::PARENT_ORIGIN ) );
348   DALI_TEST_CHECK( Property::VECTOR3  == actor.GetPropertyType( Actor::Property::ANCHOR_POINT ) );
349   DALI_TEST_CHECK( Property::VECTOR3  == actor.GetPropertyType( Actor::Property::SIZE ) );
350   DALI_TEST_CHECK( Property::VECTOR3  == actor.GetPropertyType( Actor::Property::POSITION ) );
351   DALI_TEST_CHECK( Property::ROTATION == actor.GetPropertyType( Actor::Property::ORIENTATION ) );
352   DALI_TEST_CHECK( Property::VECTOR3  == actor.GetPropertyType( Actor::Property::SCALE ) );
353   DALI_TEST_CHECK( Property::BOOLEAN  == actor.GetPropertyType( Actor::Property::VISIBLE ) );
354   DALI_TEST_CHECK( Property::VECTOR4  == actor.GetPropertyType( Actor::Property::COLOR ) );
355
356   // Register some dynamic properties
357   Property::Index boolIndex     = actor.RegisterProperty( "bool-property",     bool(true) );
358   Property::Index floatIndex    = actor.RegisterProperty( "float-property",    float(123.0f) );
359   Property::Index intIndex      = actor.RegisterProperty( "int-property",      123 );
360   Property::Index unsignedIntIndex = actor.RegisterProperty( "unsigned-int-property", 456u );
361   Property::Index vector2Index  = actor.RegisterProperty( "vector2-property",  Vector2(1.0f, 2.0f) );
362   Property::Index vector3Index  = actor.RegisterProperty( "vector3-property",  Vector3(1.0f, 2.0f, 3.0f) );
363   Property::Index vector4Index  = actor.RegisterProperty( "vector4-property",  Vector4(1.0f, 2.0f, 3.0f, 4.0f) );
364   Property::Index rotationIndex = actor.RegisterProperty( "rotation-property", AngleAxis(Degree(180.0f), Vector3::YAXIS) );
365
366   DALI_TEST_CHECK( Property::BOOLEAN  == actor.GetPropertyType( boolIndex ) );
367   DALI_TEST_CHECK( Property::FLOAT    == actor.GetPropertyType( floatIndex ) );
368   DALI_TEST_CHECK( Property::INTEGER  == actor.GetPropertyType( intIndex ) );
369   DALI_TEST_CHECK( Property::UNSIGNED_INTEGER  == actor.GetPropertyType( unsignedIntIndex ) );
370   DALI_TEST_CHECK( Property::VECTOR2  == actor.GetPropertyType( vector2Index ) );
371   DALI_TEST_CHECK( Property::VECTOR3  == actor.GetPropertyType( vector3Index ) );
372   DALI_TEST_CHECK( Property::VECTOR4  == actor.GetPropertyType( vector4Index ) );
373   DALI_TEST_CHECK( Property::ROTATION == actor.GetPropertyType( rotationIndex ) );
374
375   // Non animatable properties
376   Property::Index nonAnimStringIndex = actor.RegisterProperty( "man-from-delmonte", std::string("yes"), Property::READ_WRITE);
377   Property::Index nonAnimV2Index = actor.RegisterProperty( "v2", Vector2(1.f, 2.f), Property::READ_WRITE);
378   Property::Index nonAnimV3Index = actor.RegisterProperty( "v3", Vector3(1.f, 2.f, 3.f), Property::READ_WRITE);
379   Property::Index nonAnimV4Index = actor.RegisterProperty( "v4", Vector4(1.f, 2.f, 3.f, 4.f), Property::READ_WRITE);
380   Property::Index nonAnimBooleanIndex = actor.RegisterProperty( "bool", true, Property::READ_WRITE);
381   Property::Index nonAnimFloatIndex = actor.RegisterProperty( "float", 0.f, Property::READ_WRITE);
382   Property::Index nonAnimIntegerIndex = actor.RegisterProperty( "int", 0, Property::READ_WRITE);
383   Property::Index nonAnimUnsignedIntIndex = actor.RegisterProperty( "unsinged-int", unsingedIntTest, Property::READ_WRITE);
384
385   DALI_TEST_CHECK( nonAnimStringIndex  != Property::INVALID_INDEX );
386   DALI_TEST_CHECK( nonAnimV2Index      != Property::INVALID_INDEX );
387   DALI_TEST_CHECK( nonAnimV3Index      != Property::INVALID_INDEX );
388   DALI_TEST_CHECK( nonAnimV4Index      != Property::INVALID_INDEX );
389   DALI_TEST_CHECK( nonAnimBooleanIndex != Property::INVALID_INDEX );
390   DALI_TEST_CHECK( nonAnimFloatIndex   != Property::INVALID_INDEX );
391   DALI_TEST_CHECK( nonAnimIntegerIndex != Property::INVALID_INDEX );
392   DALI_TEST_CHECK( nonAnimUnsignedIntIndex != Property::INVALID_INDEX );
393
394   DALI_TEST_CHECK( Property::STRING   == actor.GetPropertyType( nonAnimStringIndex ) );
395   DALI_TEST_CHECK( Property::VECTOR2  == actor.GetPropertyType( nonAnimV2Index ) );
396   DALI_TEST_CHECK( Property::VECTOR3  == actor.GetPropertyType( nonAnimV3Index ) );
397   DALI_TEST_CHECK( Property::VECTOR4  == actor.GetPropertyType( nonAnimV4Index ) );
398   DALI_TEST_CHECK( Property::BOOLEAN  == actor.GetPropertyType( nonAnimBooleanIndex ) );
399   DALI_TEST_CHECK( Property::FLOAT    == actor.GetPropertyType( nonAnimFloatIndex ) );
400   DALI_TEST_CHECK( Property::INTEGER  == actor.GetPropertyType( nonAnimIntegerIndex ) );
401   DALI_TEST_CHECK( Property::UNSIGNED_INTEGER == actor.GetPropertyType( nonAnimUnsignedIntIndex ) );
402
403   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimStringIndex ) );
404   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV2Index ) );
405   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV3Index ) );
406   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV4Index ) );
407   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimBooleanIndex ) );
408   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimFloatIndex ) );
409   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimIntegerIndex ) );
410   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimUnsignedIntIndex ) );
411
412   DALI_TEST_EQUALS( "yes" , actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
413   DALI_TEST_EQUALS( Vector2(1.f, 2.f) , actor.GetProperty( nonAnimV2Index ).Get<Vector2>(), TEST_LOCATION );
414   DALI_TEST_EQUALS( Vector3(1.f, 2.f, 3.f) , actor.GetProperty( nonAnimV3Index ).Get<Vector3>(), TEST_LOCATION );
415   DALI_TEST_EQUALS( Vector4(1.f, 2.f, 3.f, 4.f) , actor.GetProperty( nonAnimV4Index ).Get<Vector4>(), TEST_LOCATION );
416   DALI_TEST_EQUALS( true, actor.GetProperty( nonAnimBooleanIndex ).Get<bool>(), TEST_LOCATION );
417   DALI_TEST_EQUALS( 0.f, actor.GetProperty( nonAnimFloatIndex ).Get<float>(), TEST_LOCATION );
418   DALI_TEST_EQUALS( 0, actor.GetProperty( nonAnimIntegerIndex ).Get<int>(), TEST_LOCATION );
419   DALI_TEST_EQUALS( unsingedIntTest, actor.GetProperty( nonAnimUnsignedIntIndex ).Get<unsigned int>(), TEST_LOCATION );
420
421   END_TEST;
422 }
423
424 int UtcDaliHandleNonAnimtableProperties(void)
425 {
426   tet_infoline("Test Non Animatable Properties");
427   TestApplication application;
428
429   Actor actor = Actor::New();
430
431   Property::Index nonAnimStringIndex = actor.RegisterProperty( "man-from-delmonte", std::string("no"), Property::READ_WRITE);
432
433   //// modify writable?
434   try
435   {
436     actor.SetProperty( nonAnimStringIndex, Property::Value("yes") );
437   }
438   catch (Dali::DaliException& e)
439   {
440     DALI_TEST_CHECK(!"exception");
441   }
442
443   DALI_TEST_CHECK( "yes"  == actor.GetProperty( nonAnimStringIndex ).Get<std::string>() );
444
445   //// cannot modify read only?
446   Property::Index readonly = actor.RegisterProperty( "float", 0.f, Property::READ_ONLY);
447
448   DALI_TEST_CHECK(!actor.IsPropertyAnimatable(readonly));
449   DALI_TEST_CHECK(!actor.IsPropertyWritable(readonly));
450
451   bool exception = false;
452   try
453   {
454     actor.SetProperty( readonly, Property::Value(1.f) );
455   }
456   catch (Dali::DaliException& e)
457   {
458     exception = true;
459   }
460
461   DALI_TEST_CHECK(!exception);// trying to set a read-only property is a no-op
462
463   DALI_TEST_EQUALS( 0.f, actor.GetProperty( readonly ).Get<float>(), TEST_LOCATION );
464
465   /// animatable can be set
466   Property::Index write_anim = actor.RegisterProperty( "write_float", 0.f, Property::ANIMATABLE);
467
468   DALI_TEST_CHECK(actor.IsPropertyAnimatable(write_anim));
469   DALI_TEST_CHECK(actor.IsPropertyWritable(write_anim));
470
471   exception = false;
472   try
473   {
474     actor.SetProperty( write_anim, Property::Value(1.f) );
475   }
476   catch (Dali::DaliException& e)
477   {
478     exception = true;
479   }
480
481   DALI_TEST_CHECK(!exception);
482
483   //// animate a non animatable property is a noop?
484   float durationSeconds(2.0f);
485   Animation animation = Animation::New(durationSeconds);
486   bool relativeValue(true);
487
488   exception = false;
489
490   try
491   {
492     animation.AnimateBy(Property(actor, nonAnimStringIndex), relativeValue, AlphaFunctions::EaseIn);
493     animation.Play();
494     application.SendNotification();
495     application.Render(static_cast<unsigned int>(durationSeconds*0100.0f)/* some progress */);
496   }
497   catch (Dali::DaliException& e)
498   {
499     exception = true;
500   }
501
502   DALI_TEST_CHECK(!exception);
503   DALI_TEST_EQUALS( "yes", actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
504
505   END_TEST;
506 }
507
508 int UtcDaliHandleNonAnimtableCompositeProperties(void)
509 {
510   tet_infoline("Test Non Animatable Composite Properties");
511   TestApplication application;
512
513   Actor actor = Actor::New();
514
515   Property::Value value(Property::ARRAY);
516   Property::Array anArray;
517   DALI_TEST_CHECK( Property::Value(anArray).GetType() == Property::ARRAY ); // 2nd constructor
518
519   value.AppendItem( Property::Value( 0.f ) );
520   value.AppendItem( "a string" );
521   value.SetItem(0, Property::Value( 5.f )); // exercise SetItem
522
523   int index = value.AppendItem( Vector3(1,2,3) );
524
525   DALI_TEST_EQUALS( 2, index, TEST_LOCATION);
526   DALI_TEST_EQUALS( 3, value.GetSize(), TEST_LOCATION);
527
528   Property::Index propertyIndex = actor.RegisterProperty( "composite", value, Property::READ_WRITE);
529
530   Property::Value out = actor.GetProperty( propertyIndex );
531
532   DALI_TEST_CHECK( Property::FLOAT     == out.GetItem(0).GetType());
533   DALI_TEST_CHECK( Property::STRING    == out.GetItem(1).GetType());
534   DALI_TEST_CHECK( Property::VECTOR3   == out.GetItem(2).GetType());
535
536   DALI_TEST_EQUALS( 5.f,            out.GetItem(0).Get<float>(),        TEST_LOCATION);
537   DALI_TEST_EQUALS( "a string",     out.GetItem(1).Get<std::string>(),  TEST_LOCATION);
538   DALI_TEST_EQUALS( Vector3(1,2,3), out.GetItem(2).Get<Vector3>(),      TEST_LOCATION);
539
540   // Property Maps
541   Property::Value valueMap(Property::MAP);
542   Property::Map aKindofMap;
543   DALI_TEST_CHECK( Property::Value(aKindofMap).GetType() == Property::MAP ); // 2nd constructor
544
545   valueMap.SetValue("key", 5.f);
546   valueMap.SetValue("2key", "a string");
547
548   DALI_TEST_EQUALS( true, valueMap.HasKey("key"),        TEST_LOCATION);
549   DALI_TEST_EQUALS( "key", valueMap.GetKey(0),           TEST_LOCATION);
550
551   DALI_TEST_EQUALS( true, valueMap.HasKey("2key"),       TEST_LOCATION);
552   DALI_TEST_EQUALS( "2key", valueMap.GetKey(1),          TEST_LOCATION);
553
554   DALI_TEST_EQUALS( 5.f,         valueMap.GetValue("key").Get<float>(),         TEST_LOCATION);
555   DALI_TEST_EQUALS( "a string",  valueMap.GetValue("2key").Get<std::string>(),  TEST_LOCATION);
556
557   valueMap.SetItem(0, Property::Value("a string"));
558   valueMap.SetItem(1, Property::Value(5.f));
559
560   DALI_TEST_EQUALS( 5.f,         valueMap.GetValue("2key").Get<float>(),        TEST_LOCATION);
561   DALI_TEST_EQUALS( "a string",  valueMap.GetValue("key").Get<std::string>(),   TEST_LOCATION);
562
563   // ordered map
564   valueMap = Property::Value(Property::MAP);
565
566   valueMap.SetValue("key", 5.f);
567   valueMap.SetValue("2key", "a string");
568
569   DALI_TEST_EQUALS( 5.f,         valueMap.GetItem(0).Get<float>(),         TEST_LOCATION);
570   DALI_TEST_EQUALS( "a string",  valueMap.GetItem(1).Get<std::string>(),   TEST_LOCATION);
571
572   DALI_TEST_EQUALS( 2, valueMap.GetSize(), TEST_LOCATION);
573
574   // composite types not animatable
575   bool exception = false;
576   try
577   {
578     /* Property::Index mapPropertyIndex = */ actor.RegisterProperty( "compositemap", value, Property::ANIMATABLE);
579   }
580   catch (Dali::DaliException& e)
581   {
582     exception = true;
583     DALI_TEST_PRINT_ASSERT( e );
584   }
585
586   DALI_TEST_EQUALS(exception, true, TEST_LOCATION);
587
588   // Map of maps
589   Property::Value mapOfMaps(Property::MAP);
590
591   mapOfMaps.SetValue( "key", Property::Value(Property::MAP) );
592   mapOfMaps.SetValue( "2key", "a string" );
593
594   DALI_TEST_EQUALS( "a string",  mapOfMaps.GetValue("2key").Get<std::string>(),  TEST_LOCATION);
595
596   mapOfMaps.GetValue("key").SetValue("subkey", 5.f);
597
598   DALI_TEST_EQUALS( true, mapOfMaps.GetValue("key").HasKey("subkey"), TEST_LOCATION);
599   DALI_TEST_EQUALS( 5.f, mapOfMaps.GetValue("key").GetValue("subkey").Get<float>(), TEST_LOCATION);
600
601   // list of maps
602   Property::Value listOfMaps(Property::ARRAY);
603
604   listOfMaps.AppendItem( Property::Value(Property::MAP) );
605   listOfMaps.AppendItem( Property::Value(Property::MAP) );
606
607   listOfMaps.GetItem(0).SetValue("key", 5.f);
608   listOfMaps.GetItem(1).SetValue("key",10.f);
609
610   DALI_TEST_EQUALS( 5.f, listOfMaps.GetItem(0).GetValue("key").Get<float>(), TEST_LOCATION );
611   DALI_TEST_EQUALS( 10.f, listOfMaps.GetItem(1).GetValue("key").Get<float>(), TEST_LOCATION );
612
613   END_TEST;
614 }
615
616 int UtcDaliHandleSetProperty01(void)
617 {
618   tet_infoline("Positive Test Dali::Handle::SetProperty()");
619   TestApplication application;
620
621   Actor actor = Actor::New();
622   DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
623
624   actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
625   // flush the queue and render once
626   application.SendNotification();
627   application.Render();
628   DALI_TEST_CHECK( ParentOrigin::CENTER == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
629   END_TEST;
630 }
631
632 int UtcDaliHandleSetProperty02(void)
633 {
634   tet_infoline("Positive Test Dali::Handle::SetProperty()");
635   TestApplication application;
636
637   Actor actor = Actor::New();
638
639   DALI_TEST_CHECK( !actor.IsPropertyWritable( Actor::Property::WORLD_POSITION ) );
640
641   // World position is not writable so this is a no-op and should not crash
642   actor.SetProperty( Actor::Property::WORLD_POSITION, Vector3(1,2,3) );
643
644   END_TEST;
645 }
646
647 int UtcDaliHandleRegisterProperty(void)
648 {
649   tet_infoline("Positive Test Dali::Handle::RegisterProperty()");
650   TestApplication application;
651
652   Actor actor = Actor::New();
653   DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
654
655   END_TEST;
656 }
657
658 int UtcDaliHandleGetProperty(void)
659 {
660   tet_infoline("Positive Test Dali::Handle::GetProperty()");
661   TestApplication application;
662
663   Actor actor = Actor::New();
664
665   DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN   ).Get<Vector3>() );
666   DALI_TEST_CHECK( AnchorPoint::CENTER    == actor.GetProperty( Actor::Property::ANCHOR_POINT    ).Get<Vector3>() );
667   DALI_TEST_CHECK( Vector3::ZERO          == actor.GetProperty( Actor::Property::SIZE            ).Get<Vector3>() );
668   DALI_TEST_CHECK( Vector3::ZERO          == actor.GetProperty( Actor::Property::POSITION        ).Get<Vector3>() );
669   DALI_TEST_CHECK( Vector3::ONE           == actor.GetProperty( Actor::Property::SCALE           ).Get<Vector3>() );
670   DALI_TEST_CHECK( true                   == actor.GetProperty( Actor::Property::VISIBLE         ).Get<bool>() );
671   DALI_TEST_CHECK( Color::WHITE           == actor.GetProperty( Actor::Property::COLOR           ).Get<Vector4>() );
672   END_TEST;
673 }
674
675 int UtcDaliHandleDownCast(void)
676 {
677   TestApplication application;
678   tet_infoline("Testing Dali::Handle::DownCast()");
679
680   Actor actor = Actor::New();
681
682   BaseHandle baseHandle = actor;
683
684   Handle handle = Handle::DownCast(baseHandle);
685
686   DALI_TEST_CHECK( handle );
687
688   baseHandle = BaseHandle();
689
690   handle = Handle::DownCast(baseHandle);
691
692   DALI_TEST_CHECK( !handle );
693
694   END_TEST;
695 }
696
697 int UtcDaliHandleDownCastNegative(void)
698 {
699   TestApplication application;
700
701   // BaseObject is NOT an Object, so this DownCast should fail
702   BaseHandle handle( new BaseObjectType );
703   Handle customHandle1 = Handle::DownCast( handle );
704   DALI_TEST_CHECK( ! customHandle1 );
705
706   // A DownCast on an empty handle will also fail
707   Handle empty;
708   Handle customHandle2 = Handle::DownCast( empty );
709   DALI_TEST_CHECK( ! customHandle2 );
710   END_TEST;
711 }
712
713 int UtcDaliHandleGetPropertyIndices(void)
714 {
715   TestApplication application;
716   Property::IndexContainer indices;
717
718   // Actor
719   Actor actor = Actor::New();
720   actor.GetPropertyIndices( indices );
721   DALI_TEST_CHECK( ! indices.empty() );
722   DALI_TEST_EQUALS( indices.size(), actor.GetPropertyCount(), TEST_LOCATION );
723   END_TEST;
724 }
725
726 int UtcDaliHandleRegisterPropertyTypes(void)
727 {
728   TestApplication application;
729
730   struct PropertyTypeAnimatable
731   {
732     const char * name;
733     Property::Value value;
734     bool animatable;
735   };
736
737   Property::Array array;
738   Property::Map map;
739
740   PropertyTypeAnimatable properties[] =
741   {
742     { "Property::BOOLEAN",          true,              true  },
743     { "Property::FLOAT",            1.0f,              true  },
744     { "Property::INTEGER",          1,                 true  },
745     { "Property::UNSIGNED_INTEGER", 1u,                true  },
746     { "Property::VECTOR2",          Vector2::ONE,      true  },
747     { "Property::VECTOR3",          Vector3::ONE,      true  },
748     { "Property::VECTOR4",          Vector4::ONE,      true  },
749     { "Property::MATRIX3",          Matrix3::IDENTITY, true  },
750     { "Property::MATRIX",           Matrix::IDENTITY,  true  },
751     { "Property::RECTANGLE",        Rect<int>(),       false },
752     { "Property::ROTATION",         AngleAxis(),       true  },
753     { "Property::STRING",           std::string("Me"), false },
754     { "Property::ARRAY",            array,             false },
755     { "Property::MAP",              map,               false },
756   };
757
758   unsigned int numOfProperties( sizeof( properties ) / sizeof( properties[0] ) );
759
760   for ( unsigned int i = 0; i < numOfProperties; ++i )
761   {
762     tet_printf( "Testing: %s\n", properties[i].name );
763
764     bool exception = false;
765     try
766     {
767       Actor actor = Actor::New();
768       actor.RegisterProperty( "man-from-delmonte", properties[i].value );
769     }
770     catch (Dali::DaliException& e)
771     {
772       exception = true;
773     }
774
775     DALI_TEST_CHECK( properties[i].animatable != exception );
776   }
777   END_TEST;
778 }
779
780 int UtcDaliHandleCustomProperty(void)
781 {
782   TestApplication application;
783
784   Handle handle = Handle::New();
785
786   float startValue(1.0f);
787   Property::Index index = handle.RegisterProperty( "test-property", startValue );
788   DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
789
790   application.SendNotification();
791   application.Render(0);
792   DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
793   application.Render(0);
794   DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
795
796   handle.SetProperty( index, 5.0f );
797
798   application.SendNotification();
799   application.Render(0);
800   DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );
801   application.Render(0);
802   DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );
803   END_TEST;
804 }