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