Size negotiation patch 1: Remove actor SetPreferredSize
[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 vector2Index  = actor.RegisterProperty( "vector2-property",  Vector2(1.0f, 2.0f) );
361   Property::Index vector3Index  = actor.RegisterProperty( "vector3-property",  Vector3(1.0f, 2.0f, 3.0f) );
362   Property::Index vector4Index  = actor.RegisterProperty( "vector4-property",  Vector4(1.0f, 2.0f, 3.0f, 4.0f) );
363   Property::Index rotationIndex = actor.RegisterProperty( "rotation-property", AngleAxis(Degree(180.0f), Vector3::YAXIS) );
364
365   DALI_TEST_CHECK( Property::BOOLEAN  == actor.GetPropertyType( boolIndex ) );
366   DALI_TEST_CHECK( Property::FLOAT    == actor.GetPropertyType( floatIndex ) );
367   DALI_TEST_CHECK( Property::INTEGER  == actor.GetPropertyType( intIndex ) );
368   DALI_TEST_CHECK( Property::VECTOR2  == actor.GetPropertyType( vector2Index ) );
369   DALI_TEST_CHECK( Property::VECTOR3  == actor.GetPropertyType( vector3Index ) );
370   DALI_TEST_CHECK( Property::VECTOR4  == actor.GetPropertyType( vector4Index ) );
371   DALI_TEST_CHECK( Property::ROTATION == actor.GetPropertyType( rotationIndex ) );
372
373   // Non animatable properties
374   Property::Index nonAnimStringIndex = actor.RegisterProperty( "man-from-delmonte", std::string("yes"), Property::READ_WRITE);
375   Property::Index nonAnimV2Index = actor.RegisterProperty( "v2", Vector2(1.f, 2.f), Property::READ_WRITE);
376   Property::Index nonAnimV3Index = actor.RegisterProperty( "v3", Vector3(1.f, 2.f, 3.f), Property::READ_WRITE);
377   Property::Index nonAnimV4Index = actor.RegisterProperty( "v4", Vector4(1.f, 2.f, 3.f, 4.f), Property::READ_WRITE);
378   Property::Index nonAnimBooleanIndex = actor.RegisterProperty( "bool", true, Property::READ_WRITE);
379   Property::Index nonAnimFloatIndex = actor.RegisterProperty( "float", 0.f, Property::READ_WRITE);
380   Property::Index nonAnimIntegerIndex = actor.RegisterProperty( "int", 0, Property::READ_WRITE);
381   Property::Index nonAnimUnsignedIntIndex = actor.RegisterProperty( "unsinged-int", unsingedIntTest, Property::READ_WRITE);
382
383   DALI_TEST_CHECK( nonAnimStringIndex  != Property::INVALID_INDEX );
384   DALI_TEST_CHECK( nonAnimV2Index      != Property::INVALID_INDEX );
385   DALI_TEST_CHECK( nonAnimV3Index      != Property::INVALID_INDEX );
386   DALI_TEST_CHECK( nonAnimV4Index      != Property::INVALID_INDEX );
387   DALI_TEST_CHECK( nonAnimBooleanIndex != Property::INVALID_INDEX );
388   DALI_TEST_CHECK( nonAnimFloatIndex   != Property::INVALID_INDEX );
389   DALI_TEST_CHECK( nonAnimIntegerIndex != Property::INVALID_INDEX );
390   DALI_TEST_CHECK( nonAnimUnsignedIntIndex != Property::INVALID_INDEX );
391
392   DALI_TEST_CHECK( Property::STRING   == actor.GetPropertyType( nonAnimStringIndex ) );
393   DALI_TEST_CHECK( Property::VECTOR2  == actor.GetPropertyType( nonAnimV2Index ) );
394   DALI_TEST_CHECK( Property::VECTOR3  == actor.GetPropertyType( nonAnimV3Index ) );
395   DALI_TEST_CHECK( Property::VECTOR4  == actor.GetPropertyType( nonAnimV4Index ) );
396   DALI_TEST_CHECK( Property::BOOLEAN  == actor.GetPropertyType( nonAnimBooleanIndex ) );
397   DALI_TEST_CHECK( Property::FLOAT    == actor.GetPropertyType( nonAnimFloatIndex ) );
398   DALI_TEST_CHECK( Property::INTEGER  == actor.GetPropertyType( nonAnimIntegerIndex ) );
399   DALI_TEST_CHECK( Property::UNSIGNED_INTEGER == actor.GetPropertyType( nonAnimUnsignedIntIndex ) );
400
401   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimStringIndex ) );
402   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV2Index ) );
403   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV3Index ) );
404   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV4Index ) );
405   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimBooleanIndex ) );
406   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimFloatIndex ) );
407   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimIntegerIndex ) );
408   DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimUnsignedIntIndex ) );
409
410   DALI_TEST_EQUALS( "yes" , actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
411   DALI_TEST_EQUALS( Vector2(1.f, 2.f) , actor.GetProperty( nonAnimV2Index ).Get<Vector2>(), TEST_LOCATION );
412   DALI_TEST_EQUALS( Vector3(1.f, 2.f, 3.f) , actor.GetProperty( nonAnimV3Index ).Get<Vector3>(), TEST_LOCATION );
413   DALI_TEST_EQUALS( Vector4(1.f, 2.f, 3.f, 4.f) , actor.GetProperty( nonAnimV4Index ).Get<Vector4>(), TEST_LOCATION );
414   DALI_TEST_EQUALS( true, actor.GetProperty( nonAnimBooleanIndex ).Get<bool>(), TEST_LOCATION );
415   DALI_TEST_EQUALS( 0.f, actor.GetProperty( nonAnimFloatIndex ).Get<float>(), TEST_LOCATION );
416   DALI_TEST_EQUALS( 0, actor.GetProperty( nonAnimIntegerIndex ).Get<int>(), TEST_LOCATION );
417   DALI_TEST_EQUALS( unsingedIntTest, actor.GetProperty( nonAnimUnsignedIntIndex ).Get<unsigned int>(), TEST_LOCATION );
418
419   END_TEST;
420 }
421
422 int UtcDaliHandleNonAnimtableProperties(void)
423 {
424   tet_infoline("Test Non Animatable Properties");
425   TestApplication application;
426
427   Actor actor = Actor::New();
428
429   Property::Index nonAnimStringIndex = actor.RegisterProperty( "man-from-delmonte", std::string("no"), Property::READ_WRITE);
430
431   //// modify writable?
432   try
433   {
434     actor.SetProperty( nonAnimStringIndex, Property::Value("yes") );
435   }
436   catch (Dali::DaliException& e)
437   {
438     DALI_TEST_CHECK(!"exception");
439   }
440
441   DALI_TEST_CHECK( "yes"  == actor.GetProperty( nonAnimStringIndex ).Get<std::string>() );
442
443   //// cannot modify read only?
444   Property::Index readonly = actor.RegisterProperty( "float", 0.f, Property::READ_ONLY);
445
446   DALI_TEST_CHECK(!actor.IsPropertyAnimatable(readonly));
447   DALI_TEST_CHECK(!actor.IsPropertyWritable(readonly));
448
449   bool exception = false;
450   try
451   {
452     actor.SetProperty( readonly, Property::Value(1.f) );
453   }
454   catch (Dali::DaliException& e)
455   {
456     exception = true;
457   }
458
459   DALI_TEST_CHECK(!exception);// trying to set a read-only property is a no-op
460
461   DALI_TEST_EQUALS( 0.f, actor.GetProperty( readonly ).Get<float>(), TEST_LOCATION );
462
463   /// animatable can be set
464   Property::Index write_anim = actor.RegisterProperty( "write_float", 0.f, Property::ANIMATABLE);
465
466   DALI_TEST_CHECK(actor.IsPropertyAnimatable(write_anim));
467   DALI_TEST_CHECK(actor.IsPropertyWritable(write_anim));
468
469   exception = false;
470   try
471   {
472     actor.SetProperty( write_anim, Property::Value(1.f) );
473   }
474   catch (Dali::DaliException& e)
475   {
476     exception = true;
477   }
478
479   DALI_TEST_CHECK(!exception);
480
481   //// animate a non animatable property is a noop?
482   float durationSeconds(2.0f);
483   Animation animation = Animation::New(durationSeconds);
484   bool relativeValue(true);
485
486   exception = false;
487
488   try
489   {
490     animation.AnimateBy(Property(actor, nonAnimStringIndex), relativeValue, AlphaFunctions::EaseIn);
491     animation.Play();
492     application.SendNotification();
493     application.Render(static_cast<unsigned int>(durationSeconds*0100.0f)/* some progress */);
494   }
495   catch (Dali::DaliException& e)
496   {
497     exception = true;
498   }
499
500   DALI_TEST_CHECK(!exception);
501   DALI_TEST_EQUALS( "yes", actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
502
503   END_TEST;
504 }
505
506 int UtcDaliHandleNonAnimtableCompositeProperties(void)
507 {
508   tet_infoline("Test Non Animatable Composite Properties");
509   TestApplication application;
510
511   Actor actor = Actor::New();
512
513   Property::Value value(Property::ARRAY);
514   Property::Array anArray;
515   DALI_TEST_CHECK( Property::Value(anArray).GetType() == Property::ARRAY ); // 2nd constructor
516
517   value.AppendItem( Property::Value( 0.f ) );
518   value.AppendItem( "a string" );
519   value.SetItem(0, Property::Value( 5.f )); // exercise SetItem
520
521   int index = value.AppendItem( Vector3(1,2,3) );
522
523   DALI_TEST_EQUALS( 2, index, TEST_LOCATION);
524   DALI_TEST_EQUALS( 3, value.GetSize(), TEST_LOCATION);
525
526   Property::Index propertyIndex = actor.RegisterProperty( "composite", value, Property::READ_WRITE);
527
528   Property::Value out = actor.GetProperty( propertyIndex );
529
530   DALI_TEST_CHECK( Property::FLOAT     == out.GetItem(0).GetType());
531   DALI_TEST_CHECK( Property::STRING    == out.GetItem(1).GetType());
532   DALI_TEST_CHECK( Property::VECTOR3   == out.GetItem(2).GetType());
533
534   DALI_TEST_EQUALS( 5.f,            out.GetItem(0).Get<float>(),        TEST_LOCATION);
535   DALI_TEST_EQUALS( "a string",     out.GetItem(1).Get<std::string>(),  TEST_LOCATION);
536   DALI_TEST_EQUALS( Vector3(1,2,3), out.GetItem(2).Get<Vector3>(),      TEST_LOCATION);
537
538   // Property Maps
539   Property::Value valueMap(Property::MAP);
540   Property::Map aKindofMap;
541   DALI_TEST_CHECK( Property::Value(aKindofMap).GetType() == Property::MAP ); // 2nd constructor
542
543   valueMap.SetValue("key", 5.f);
544   valueMap.SetValue("2key", "a string");
545
546   DALI_TEST_EQUALS( true, valueMap.HasKey("key"),        TEST_LOCATION);
547   DALI_TEST_EQUALS( "key", valueMap.GetKey(0),           TEST_LOCATION);
548
549   DALI_TEST_EQUALS( true, valueMap.HasKey("2key"),       TEST_LOCATION);
550   DALI_TEST_EQUALS( "2key", valueMap.GetKey(1),          TEST_LOCATION);
551
552   DALI_TEST_EQUALS( 5.f,         valueMap.GetValue("key").Get<float>(),         TEST_LOCATION);
553   DALI_TEST_EQUALS( "a string",  valueMap.GetValue("2key").Get<std::string>(),  TEST_LOCATION);
554
555   valueMap.SetItem(0, Property::Value("a string"));
556   valueMap.SetItem(1, Property::Value(5.f));
557
558   DALI_TEST_EQUALS( 5.f,         valueMap.GetValue("2key").Get<float>(),        TEST_LOCATION);
559   DALI_TEST_EQUALS( "a string",  valueMap.GetValue("key").Get<std::string>(),   TEST_LOCATION);
560
561   // ordered map
562   valueMap = Property::Value(Property::MAP);
563
564   valueMap.SetValue("key", 5.f);
565   valueMap.SetValue("2key", "a string");
566
567   DALI_TEST_EQUALS( 5.f,         valueMap.GetItem(0).Get<float>(),         TEST_LOCATION);
568   DALI_TEST_EQUALS( "a string",  valueMap.GetItem(1).Get<std::string>(),   TEST_LOCATION);
569
570   DALI_TEST_EQUALS( 2, valueMap.GetSize(), TEST_LOCATION);
571
572   // composite types not animatable
573   bool exception = false;
574   try
575   {
576     /* Property::Index mapPropertyIndex = */ actor.RegisterProperty( "compositemap", value, Property::ANIMATABLE);
577   }
578   catch (Dali::DaliException& e)
579   {
580     exception = true;
581     DALI_TEST_PRINT_ASSERT( e );
582   }
583
584   DALI_TEST_EQUALS(exception, true, TEST_LOCATION);
585
586   // Map of maps
587   Property::Value mapOfMaps(Property::MAP);
588
589   mapOfMaps.SetValue( "key", Property::Value(Property::MAP) );
590   mapOfMaps.SetValue( "2key", "a string" );
591
592   DALI_TEST_EQUALS( "a string",  mapOfMaps.GetValue("2key").Get<std::string>(),  TEST_LOCATION);
593
594   mapOfMaps.GetValue("key").SetValue("subkey", 5.f);
595
596   DALI_TEST_EQUALS( true, mapOfMaps.GetValue("key").HasKey("subkey"), TEST_LOCATION);
597   DALI_TEST_EQUALS( 5.f, mapOfMaps.GetValue("key").GetValue("subkey").Get<float>(), TEST_LOCATION);
598
599   // list of maps
600   Property::Value listOfMaps(Property::ARRAY);
601
602   listOfMaps.AppendItem( Property::Value(Property::MAP) );
603   listOfMaps.AppendItem( Property::Value(Property::MAP) );
604
605   listOfMaps.GetItem(0).SetValue("key", 5.f);
606   listOfMaps.GetItem(1).SetValue("key",10.f);
607
608   DALI_TEST_EQUALS( 5.f, listOfMaps.GetItem(0).GetValue("key").Get<float>(), TEST_LOCATION );
609   DALI_TEST_EQUALS( 10.f, listOfMaps.GetItem(1).GetValue("key").Get<float>(), TEST_LOCATION );
610
611   END_TEST;
612 }
613
614 int UtcDaliHandleSetProperty01(void)
615 {
616   tet_infoline("Positive Test Dali::Handle::SetProperty()");
617   TestApplication application;
618
619   Actor actor = Actor::New();
620   DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
621
622   actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
623   // flush the queue and render once
624   application.SendNotification();
625   application.Render();
626   DALI_TEST_CHECK( ParentOrigin::CENTER == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
627   END_TEST;
628 }
629
630 int UtcDaliHandleSetProperty02(void)
631 {
632   tet_infoline("Positive Test Dali::Handle::SetProperty()");
633   TestApplication application;
634
635   Actor actor = Actor::New();
636
637   DALI_TEST_CHECK( !actor.IsPropertyWritable( Actor::Property::WORLD_POSITION ) );
638
639   // World position is not writable so this is a no-op and should not crash
640   actor.SetProperty( Actor::Property::WORLD_POSITION, Vector3(1,2,3) );
641
642   END_TEST;
643 }
644
645 int UtcDaliHandleRegisterProperty(void)
646 {
647   tet_infoline("Positive Test Dali::Handle::RegisterProperty()");
648   TestApplication application;
649
650   Actor actor = Actor::New();
651   DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
652
653   END_TEST;
654 }
655
656 int UtcDaliHandleGetProperty(void)
657 {
658   tet_infoline("Positive Test Dali::Handle::GetProperty()");
659   TestApplication application;
660
661   Actor actor = Actor::New();
662
663   DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN   ).Get<Vector3>() );
664   DALI_TEST_CHECK( AnchorPoint::CENTER    == actor.GetProperty( Actor::Property::ANCHOR_POINT    ).Get<Vector3>() );
665   DALI_TEST_CHECK( Vector3::ZERO          == actor.GetProperty( Actor::Property::SIZE            ).Get<Vector3>() );
666   DALI_TEST_CHECK( Vector3::ZERO          == actor.GetProperty( Actor::Property::POSITION        ).Get<Vector3>() );
667   DALI_TEST_CHECK( Vector3::ONE           == actor.GetProperty( Actor::Property::SCALE           ).Get<Vector3>() );
668   DALI_TEST_CHECK( true                   == actor.GetProperty( Actor::Property::VISIBLE         ).Get<bool>() );
669   DALI_TEST_CHECK( Color::WHITE           == actor.GetProperty( Actor::Property::COLOR           ).Get<Vector4>() );
670   END_TEST;
671 }
672
673 int UtcDaliHandleDownCast(void)
674 {
675   TestApplication application;
676   tet_infoline("Testing Dali::Handle::DownCast()");
677
678   Actor actor = Actor::New();
679
680   BaseHandle baseHandle = actor;
681
682   Handle handle = Handle::DownCast(baseHandle);
683
684   DALI_TEST_CHECK( handle );
685
686   baseHandle = BaseHandle();
687
688   handle = Handle::DownCast(baseHandle);
689
690   DALI_TEST_CHECK( !handle );
691
692   END_TEST;
693 }
694
695 int UtcDaliHandleDownCastNegative(void)
696 {
697   TestApplication application;
698
699   // BaseObject is NOT an Object, so this DownCast should fail
700   BaseHandle handle( new BaseObjectType );
701   Handle customHandle1 = Handle::DownCast( handle );
702   DALI_TEST_CHECK( ! customHandle1 );
703
704   // A DownCast on an empty handle will also fail
705   Handle empty;
706   Handle customHandle2 = Handle::DownCast( empty );
707   DALI_TEST_CHECK( ! customHandle2 );
708   END_TEST;
709 }
710
711 int UtcDaliHandleGetPropertyIndices(void)
712 {
713   TestApplication application;
714   Property::IndexContainer indices;
715
716   // Actor
717   Actor actor = Actor::New();
718   actor.GetPropertyIndices( indices );
719   DALI_TEST_CHECK( ! indices.empty() );
720   DALI_TEST_EQUALS( indices.size(), actor.GetPropertyCount(), TEST_LOCATION );
721   END_TEST;
722 }
723
724 int UtcDaliHandleRegisterPropertyTypes(void)
725 {
726   TestApplication application;
727
728   struct PropertyTypeAnimatable
729   {
730     const char * name;
731     Property::Value value;
732     bool animatable;
733   };
734
735   Property::Array array;
736   Property::Map map;
737
738   PropertyTypeAnimatable properties[] =
739   {
740     { "Property::BOOLEAN",          true,              true  },
741     { "Property::FLOAT",            1.0f,              true  },
742     { "Property::INTEGER",          1,                 true  },
743     { "Property::UNSIGNED_INTEGER", 1u,                false },
744     { "Property::VECTOR2",          Vector2::ONE,      true  },
745     { "Property::VECTOR3",          Vector3::ONE,      true  },
746     { "Property::VECTOR4",          Vector4::ONE,      true  },
747     { "Property::MATRIX3",          Matrix3::IDENTITY, true  },
748     { "Property::MATRIX",           Matrix::IDENTITY,  true  },
749     { "Property::RECTANGLE",        Rect<int>(),       false },
750     { "Property::ROTATION",         AngleAxis(),       true  },
751     { "Property::STRING",           std::string("Me"), false },
752     { "Property::ARRAY",            array,             false },
753     { "Property::MAP",              map,               false },
754   };
755   unsigned int numOfProperties( sizeof( properties ) / sizeof( properties[0] ) );
756
757   for ( unsigned int i = 0; i < numOfProperties; ++i )
758   {
759     tet_printf( "Testing: %s\n", properties[i].name );
760
761     bool exception = false;
762     try
763     {
764       Actor actor = Actor::New();
765       actor.RegisterProperty( "man-from-delmonte", properties[i].value );
766     }
767     catch (Dali::DaliException& e)
768     {
769       exception = true;
770     }
771
772     DALI_TEST_CHECK( properties[i].animatable != exception );
773   }
774   END_TEST;
775 }
776
777 int UtcDaliHandleCustomProperty(void)
778 {
779   TestApplication application;
780
781   Handle handle = Handle::New();
782
783   float startValue(1.0f);
784   Property::Index index = handle.RegisterProperty( "test-property", startValue );
785   DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
786
787   application.SendNotification();
788   application.Render(0);
789   DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
790   application.Render(0);
791   DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
792
793   handle.SetProperty( index, 5.0f );
794
795   application.SendNotification();
796   application.Render(0);
797   DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );
798   application.Render(0);
799   DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );
800   END_TEST;
801 }