2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali/public-api/dali-core.h>
22 #include "dali-test-suite-utils/dali-test-suite-utils.h"
23 #include <mesh-builder.h>
27 void handle_test_startup(void)
29 test_return_value = TET_UNDEF;
32 void handle_test_cleanup(void)
34 test_return_value = TET_PASS;
40 /// Allows the creation of a BaseObject
41 class BaseObjectType : public BaseObject
49 Handle ImplicitCopyConstructor(Handle passedByValue)
51 // object + copy + passedByValue, ref count == 3
52 DALI_TEST_CHECK(passedByValue);
55 DALI_TEST_EQUALS(3, passedByValue.GetBaseObject().ReferenceCount(), TEST_LOCATION);
64 int UtcDaliHandleConstructorVoid(void)
66 TestApplication application;
67 tet_infoline("Testing Dali::Handle::Handle()");
71 DALI_TEST_CHECK(!object);
76 int UtcDaliHandleCopyConstructor(void)
78 TestApplication application;
79 tet_infoline("Testing Dali::Handle::Handle(const Handle&)");
81 // Initialize an object, ref count == 1
82 Handle object = Actor::New();
84 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
86 // Copy the object, ref count == 2
88 DALI_TEST_CHECK(copy);
91 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
95 // Pass by value, and return another copy, ref count == 3
96 Handle anotherCopy = ImplicitCopyConstructor(copy);
98 DALI_TEST_CHECK(anotherCopy);
101 DALI_TEST_EQUALS(3, anotherCopy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
105 // anotherCopy out of scope, ref count == 2
106 DALI_TEST_CHECK(copy);
109 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
114 int UtcDaliHandleAssignmentOperator(void)
116 TestApplication application;
117 tet_infoline("Testing Dali::Handle::operator=");
119 Handle object = Actor::New();
121 DALI_TEST_CHECK(object);
122 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
125 DALI_TEST_CHECK(!copy);
128 DALI_TEST_CHECK(copy);
129 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
130 DALI_TEST_CHECK(&(copy.GetBaseObject()) == &(object.GetBaseObject()));
134 int UtcDaliHandleSupports(void)
136 tet_infoline("Positive Test Dali::Handle::Supports()");
137 TestApplication application;
139 Actor actor = Actor::New();
140 DALI_TEST_CHECK( true == actor.Supports( Handle::DYNAMIC_PROPERTIES ) );
144 int UtcDaliHandleGetPropertyCount(void)
146 tet_infoline("Positive Test Dali::Handle::GetPropertyCount()");
147 TestApplication application;
149 Actor actor = Actor::New();
150 int defaultPropertyCount( actor.GetPropertyCount() );
152 // Register a dynamic property
153 actor.RegisterProperty( "testProperty", float(123.0f) );
154 DALI_TEST_CHECK( (defaultPropertyCount + 1u) == actor.GetPropertyCount() );
158 int UtcDaliHandleGetPropertyName(void)
160 tet_infoline("Positive Test Dali::Handle::GetPropertyName()");
161 TestApplication application;
163 Actor actor = Actor::New();
164 DALI_TEST_CHECK( "parentOrigin" == actor.GetPropertyName( Actor::Property::PARENT_ORIGIN ) );
166 // Register a dynamic property
167 std::string name("thisNameShouldMatch");
168 Property::Index index = actor.RegisterProperty( name, float(123.0f) );
169 DALI_TEST_CHECK( name == actor.GetPropertyName( index ) );
174 int UtcDaliHandleGetPropertyIndex(void)
176 tet_infoline("Positive Test Dali::Handle::GetPropertyIndex()");
177 TestApplication application;
179 Actor actor = Actor::New();
180 DALI_TEST_CHECK( Actor::Property::PARENT_ORIGIN == actor.GetPropertyIndex("parentOrigin") );
182 // Register a dynamic property
183 std::string name("thisNameShouldMatch");
184 Property::Index index = actor.RegisterProperty( name, float(123.0f) );
185 DALI_TEST_CHECK( index == actor.GetPropertyIndex( name ) );
189 int UtcDaliHandleIsPropertyWritable(void)
191 tet_infoline("Positive Test Dali::Handle::IsPropertyWritable()");
192 TestApplication application;
194 Actor actor = Actor::New();
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 ) );
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 ) );
237 int UtcDaliHandleIsPropertyAnimatable(void)
239 tet_infoline("Positive Test Dali::Handle::IsPropertyAnimatable()");
240 TestApplication application;
242 Actor actor = Actor::New();
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 ) );
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 ) );
285 int UtcDaliHandleIsPropertyAConstraintInput(void)
287 TestApplication application;
289 Actor actor = Actor::New();
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 ) );
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 ) );
342 int UtcDaliHandleGetPropertyType(void)
344 tet_infoline("Positive Test Dali::Handle::GetPropertyType()");
345 TestApplication application;
347 Actor actor = Actor::New();
348 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::PARENT_ORIGIN ) );
349 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::ANCHOR_POINT ) );
350 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::SIZE ) );
351 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::POSITION ) );
352 DALI_TEST_CHECK( Property::ROTATION == actor.GetPropertyType( Actor::Property::ORIENTATION ) );
353 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::SCALE ) );
354 DALI_TEST_CHECK( Property::BOOLEAN == actor.GetPropertyType( Actor::Property::VISIBLE ) );
355 DALI_TEST_CHECK( Property::VECTOR4 == actor.GetPropertyType( Actor::Property::COLOR ) );
357 // Register some dynamic properties
358 Property::Index boolIndex = actor.RegisterProperty( "boolProperty", bool(true) );
359 Property::Index floatIndex = actor.RegisterProperty( "floatProperty", float(123.0f) );
360 Property::Index intIndex = actor.RegisterProperty( "intProperty", 123 );
361 Property::Index vector2Index = actor.RegisterProperty( "vector2Property", Vector2(1.0f, 2.0f) );
362 Property::Index vector3Index = actor.RegisterProperty( "vector3Property", Vector3(1.0f, 2.0f, 3.0f) );
363 Property::Index vector4Index = actor.RegisterProperty( "vector4Property", Vector4(1.0f, 2.0f, 3.0f, 4.0f) );
364 Property::Index rotationIndex = actor.RegisterProperty( "rotationProperty", AngleAxis(Degree(180.0f), Vector3::YAXIS) );
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::VECTOR2 == actor.GetPropertyType( vector2Index ) );
370 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( vector3Index ) );
371 DALI_TEST_CHECK( Property::VECTOR4 == actor.GetPropertyType( vector4Index ) );
372 DALI_TEST_CHECK( Property::ROTATION == actor.GetPropertyType( rotationIndex ) );
374 // Non animatable properties
375 Property::Index nonAnimStringIndex = actor.RegisterProperty( "manFromDelmonte", std::string("yes"), Property::READ_WRITE);
376 Property::Index nonAnimV2Index = actor.RegisterProperty( "v2", Vector2(1.f, 2.f), Property::READ_WRITE);
377 Property::Index nonAnimV3Index = actor.RegisterProperty( "v3", Vector3(1.f, 2.f, 3.f), Property::READ_WRITE);
378 Property::Index nonAnimV4Index = actor.RegisterProperty( "v4", Vector4(1.f, 2.f, 3.f, 4.f), Property::READ_WRITE);
379 Property::Index nonAnimBooleanIndex = actor.RegisterProperty( "bool", true, Property::READ_WRITE);
380 Property::Index nonAnimFloatIndex = actor.RegisterProperty( "float", 0.f, Property::READ_WRITE);
381 Property::Index nonAnimIntegerIndex = actor.RegisterProperty( "int", 0, Property::READ_WRITE);
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 );
391 DALI_TEST_CHECK( Property::STRING == actor.GetPropertyType( nonAnimStringIndex ) );
392 DALI_TEST_CHECK( Property::VECTOR2 == actor.GetPropertyType( nonAnimV2Index ) );
393 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( nonAnimV3Index ) );
394 DALI_TEST_CHECK( Property::VECTOR4 == actor.GetPropertyType( nonAnimV4Index ) );
395 DALI_TEST_CHECK( Property::BOOLEAN == actor.GetPropertyType( nonAnimBooleanIndex ) );
396 DALI_TEST_CHECK( Property::FLOAT == actor.GetPropertyType( nonAnimFloatIndex ) );
397 DALI_TEST_CHECK( Property::INTEGER == actor.GetPropertyType( nonAnimIntegerIndex ) );
399 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimStringIndex ) );
400 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV2Index ) );
401 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV3Index ) );
402 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV4Index ) );
403 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimBooleanIndex ) );
404 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimFloatIndex ) );
405 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimIntegerIndex ) );
407 DALI_TEST_EQUALS( "yes" , actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
408 DALI_TEST_EQUALS( Vector2(1.f, 2.f) , actor.GetProperty( nonAnimV2Index ).Get<Vector2>(), TEST_LOCATION );
409 DALI_TEST_EQUALS( Vector3(1.f, 2.f, 3.f) , actor.GetProperty( nonAnimV3Index ).Get<Vector3>(), TEST_LOCATION );
410 DALI_TEST_EQUALS( Vector4(1.f, 2.f, 3.f, 4.f) , actor.GetProperty( nonAnimV4Index ).Get<Vector4>(), TEST_LOCATION );
411 DALI_TEST_EQUALS( true, actor.GetProperty( nonAnimBooleanIndex ).Get<bool>(), TEST_LOCATION );
412 DALI_TEST_EQUALS( 0.f, actor.GetProperty( nonAnimFloatIndex ).Get<float>(), TEST_LOCATION );
413 DALI_TEST_EQUALS( 0, actor.GetProperty( nonAnimIntegerIndex ).Get<int>(), TEST_LOCATION );
418 int UtcDaliHandleNonAnimtableProperties(void)
420 tet_infoline("Test Non Animatable Properties");
421 TestApplication application;
423 Actor actor = Actor::New();
425 Property::Index nonAnimStringIndex = actor.RegisterProperty( "manFromDelmonte", std::string("no"), Property::READ_WRITE);
427 //// modify writable?
430 actor.SetProperty( nonAnimStringIndex, Property::Value("yes") );
432 catch (Dali::DaliException& e)
434 DALI_TEST_CHECK(!"exception");
437 DALI_TEST_CHECK( "yes" == actor.GetProperty( nonAnimStringIndex ).Get<std::string>() );
439 //// cannot modify read only?
440 Property::Index readonly = actor.RegisterProperty( "float", 0.f, Property::READ_ONLY);
442 DALI_TEST_CHECK(!actor.IsPropertyAnimatable(readonly));
443 DALI_TEST_CHECK(!actor.IsPropertyWritable(readonly));
445 bool exception = false;
448 actor.SetProperty( readonly, Property::Value(1.f) );
450 catch (Dali::DaliException& e)
455 DALI_TEST_CHECK(!exception);// trying to set a read-only property is a no-op
457 DALI_TEST_EQUALS( 0.f, actor.GetProperty( readonly ).Get<float>(), TEST_LOCATION );
459 /// animatable can be set
460 Property::Index write_anim = actor.RegisterProperty( "write_float", 0.f, Property::ANIMATABLE);
462 DALI_TEST_CHECK(actor.IsPropertyAnimatable(write_anim));
463 DALI_TEST_CHECK(actor.IsPropertyWritable(write_anim));
468 actor.SetProperty( write_anim, Property::Value(1.f) );
470 catch (Dali::DaliException& e)
475 DALI_TEST_CHECK(!exception);
477 //// animate a non animatable property is a noop?
478 float durationSeconds(2.0f);
479 Animation animation = Animation::New(durationSeconds);
480 bool relativeValue(true);
486 animation.AnimateBy(Property(actor, nonAnimStringIndex), relativeValue, AlphaFunction::EASE_IN);
488 application.SendNotification();
489 application.Render(static_cast<unsigned int>(durationSeconds*0100.0f)/* some progress */);
491 catch (Dali::DaliException& e)
496 DALI_TEST_CHECK(!exception);
497 DALI_TEST_EQUALS( "yes", actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
502 int UtcDaliHandleNonAnimtableCompositeProperties(void)
504 tet_infoline("Test Non Animatable Composite Properties");
505 TestApplication application;
507 Actor actor = Actor::New();
509 Property::Value value(Property::ARRAY);
510 Property::Array* array = value.GetArray();
511 DALI_TEST_CHECK( array );
513 array->PushBack( Property::Value( 0.1f ) );
514 array->PushBack( "a string" );
515 array->PushBack( Property::Value( Vector3(1,2,3) ) );
517 DALI_TEST_EQUALS( 3u, array->Count(), TEST_LOCATION );
519 Property::Index propertyIndex = actor.RegisterProperty( "composite", value, Property::READ_WRITE );
521 Property::Value out = actor.GetProperty( propertyIndex );
522 Property::Array* outArray = out.GetArray();
523 DALI_TEST_CHECK( outArray != NULL );
525 DALI_TEST_CHECK( Property::FLOAT == outArray->GetElementAt(0).GetType());
526 DALI_TEST_CHECK( Property::STRING == outArray->GetElementAt(1).GetType());
527 DALI_TEST_CHECK( Property::VECTOR3 == outArray->GetElementAt(2).GetType());
529 DALI_TEST_EQUALS( 0.1f, outArray->GetElementAt(0).Get<float>(), TEST_LOCATION);
530 DALI_TEST_EQUALS( "a string", outArray->GetElementAt(1).Get<std::string>(), TEST_LOCATION);
531 DALI_TEST_EQUALS( Vector3(1,2,3), outArray->GetElementAt(2).Get<Vector3>(), TEST_LOCATION);
533 // composite types not animatable
534 bool exception = false;
537 actor.RegisterProperty( "compositemap", value, Property::ANIMATABLE);
539 catch (Dali::DaliException& e)
542 DALI_TEST_PRINT_ASSERT( e );
545 DALI_TEST_EQUALS(exception, true, TEST_LOCATION);
548 Property::Value mapOfMaps(Property::MAP);
549 Property::Map* map = mapOfMaps.GetMap();
551 map->Insert( "key", Property::Value(Property::MAP) );
552 map->Insert( "2key", "a string" );
554 DALI_TEST_EQUALS( "a string", (*map)["2key"].Get<std::string>(), TEST_LOCATION);
556 Property::Map* innerMap = map->Find("key")->GetMap();
557 innerMap->Insert( "subkey", 5.f );
559 DALI_TEST_CHECK( NULL != map->Find("key")->GetMap()->Find("subkey") );
560 DALI_TEST_EQUALS( 5.f, map->Find("key")->GetMap()->Find("subkey")->Get<float>(), TEST_LOCATION);
564 int UtcDaliHandleSetProperty01(void)
566 tet_infoline("Positive Test Dali::Handle::SetProperty()");
567 TestApplication application;
569 Actor actor = Actor::New();
570 DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
572 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
573 // flush the queue and render once
574 application.SendNotification();
575 application.Render();
576 DALI_TEST_CHECK( ParentOrigin::CENTER == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
580 int UtcDaliHandleSetProperty02(void)
582 tet_infoline("Positive Test Dali::Handle::SetProperty()");
583 TestApplication application;
585 Actor actor = Actor::New();
587 DALI_TEST_CHECK( !actor.IsPropertyWritable( Actor::Property::WORLD_POSITION ) );
589 // World position is not writable so this is a no-op and should not crash
590 actor.SetProperty( Actor::Property::WORLD_POSITION, Vector3(1,2,3) );
595 int UtcDaliHandleRegisterProperty01(void)
597 tet_infoline("Positive Test Dali::Handle::RegisterProperty()");
598 TestApplication application;
600 Stage stage = Stage::GetCurrent();
602 Actor actor = Actor::New();
605 const unsigned int defaultPropertyCount = actor.GetPropertyCount();
607 application.SendNotification();
608 application.Render();
610 Property::Index index1 = actor.RegisterProperty( "MyProperty", Vector3::ONE );
612 application.SendNotification();
613 application.Render();
615 DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 1, TEST_LOCATION );
616 DALI_TEST_EQUALS( actor.GetProperty< Vector3 >( index1 ), Vector3::ONE, TEST_LOCATION );
618 // No new property should be registered when we call the below function
619 Property::Index index2 = actor.RegisterProperty( "MyProperty", Vector3::ZAXIS );
621 application.SendNotification();
622 application.Render();
625 DALI_TEST_EQUALS( index1, index2, TEST_LOCATION ); // We should have the same index as per the first registration
626 DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 1, TEST_LOCATION ); // Property count should be the same
627 DALI_TEST_EQUALS( actor.GetProperty< Vector3 >( index2 ), Vector3::ZAXIS, TEST_LOCATION ); // Value should be what we sent on second RegisterProperty call
632 int UtcDaliHandleRegisterProperty02(void)
634 tet_infoline("Positive Test Dali::Handle::RegisterProperty() int key");
635 TestApplication application;
637 Stage stage = Stage::GetCurrent();
639 Actor actor = Actor::New();
642 const unsigned int defaultPropertyCount = actor.GetPropertyCount();
644 application.SendNotification();
645 application.Render();
647 Property::Index key1 = CORE_PROPERTY_MAX_INDEX+1;
648 Property::Index key2 = CORE_PROPERTY_MAX_INDEX+2;
650 const Vector4 testColor(0.5f, 0.2f, 0.9f, 1.0f);
651 const float withFlake(99.f);
653 Property::Index index1 = actor.RegisterProperty( "MyPropertyOne", Vector3::ONE );
654 Property::Index index2 = actor.RegisterProperty( key1, "sideColor", testColor);
655 Property::Index index3 = actor.RegisterProperty( key2, "iceCream", withFlake );
657 application.SendNotification();
658 application.Render();
660 DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 3, TEST_LOCATION );
661 DALI_TEST_EQUALS( actor.GetProperty< Vector3 >( index1 ), Vector3::ONE, TEST_LOCATION );
662 DALI_TEST_EQUALS( actor.GetProperty< Vector4 >( index2 ), testColor, TEST_LOCATION );
663 DALI_TEST_EQUALS( actor.GetProperty< float >( index3 ), withFlake, TEST_LOCATION );
665 // No new property should be registered when we call the below functions
666 Property::Index testIndex2 = actor.RegisterProperty( "iceCream", 2200.f );
667 Property::Index testIndex1 = actor.RegisterProperty( "sideColor", Color::BLACK );
668 application.SendNotification();
669 application.Render();
671 DALI_TEST_EQUALS( index2, testIndex1, TEST_LOCATION ); // We should have the same index as per the first registration
672 DALI_TEST_EQUALS( index3, testIndex2, TEST_LOCATION ); // We should have the same index as per the first registration
673 DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 3, TEST_LOCATION ); // Property count should be the same
674 DALI_TEST_EQUALS( actor.GetProperty< Vector4 >( index2 ), Color::BLACK, TEST_LOCATION ); // Value should be what we sent on second RegisterProperty call
675 DALI_TEST_EQUALS( actor.GetProperty< float >( index3 ), 2200.f, TEST_LOCATION );
681 int UtcDaliHandleGetPropertyIndex02(void)
683 tet_infoline("Positive Test Dali::Handle::GetPropertyIndex() int key");
684 TestApplication application;
686 Stage stage = Stage::GetCurrent();
688 Actor actor = Actor::New();
691 const unsigned int defaultPropertyCount = actor.GetPropertyCount();
693 application.SendNotification();
694 application.Render();
696 Property::Index key1 = CORE_PROPERTY_MAX_INDEX+1;
697 Property::Index key2 = CORE_PROPERTY_MAX_INDEX+2;
699 const Vector4 testColor(0.5f, 0.2f, 0.9f, 1.0f);
700 const float withFlake(99.f);
702 Property::Index index1 = actor.RegisterProperty( "MyPropertyOne", Vector3::ONE );
703 Property::Index index2 = actor.RegisterProperty( key1, "sideColor", testColor);
704 Property::Index index3 = actor.RegisterProperty( "MyPropertyTwo", Vector3::ONE );
705 Property::Index index4 = actor.RegisterProperty( key2, "iceCream", withFlake );
706 Property::Index index5 = actor.RegisterProperty( "MyPropertyThree", Vector3::ONE );
708 application.SendNotification();
709 application.Render();
711 // Test that we can get the property index from the integer key
712 Property::Index testIndex1 = actor.GetPropertyIndex( key1 );
713 Property::Index testIndex2 = actor.GetPropertyIndex( key2 );
715 DALI_TEST_EQUALS( index2, testIndex1, TEST_LOCATION );
716 DALI_TEST_EQUALS( index4, testIndex2, TEST_LOCATION );
718 // Test that we keep the same indices on the named properties
719 Property::Index testIndex = actor.GetPropertyIndex("MyPropertyOne");
720 DALI_TEST_EQUALS(testIndex, index1, TEST_LOCATION);
721 testIndex = actor.GetPropertyIndex("MyPropertyTwo");
722 DALI_TEST_EQUALS(testIndex, index3, TEST_LOCATION);
723 testIndex = actor.GetPropertyIndex("MyPropertyThree");
724 DALI_TEST_EQUALS(testIndex, index5, TEST_LOCATION);
725 testIndex = actor.GetPropertyIndex("sideColor");
726 DALI_TEST_EQUALS(testIndex, index2, TEST_LOCATION);
727 testIndex = actor.GetPropertyIndex("iceCream");
728 DALI_TEST_EQUALS(testIndex, index4, TEST_LOCATION);
730 DALI_TEST_EQUALS(defaultPropertyCount+5, actor.GetPropertyCount(), TEST_LOCATION);
734 int UtcDaliHandleGetProperty(void)
736 tet_infoline("Positive Test Dali::Handle::GetProperty()");
737 TestApplication application;
739 Actor actor = Actor::New();
741 DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
742 DALI_TEST_CHECK( AnchorPoint::CENTER == actor.GetProperty( Actor::Property::ANCHOR_POINT ).Get<Vector3>() );
743 DALI_TEST_CHECK( Vector3::ZERO == actor.GetProperty( Actor::Property::SIZE ).Get<Vector3>() );
744 DALI_TEST_CHECK( Vector3::ZERO == actor.GetProperty( Actor::Property::POSITION ).Get<Vector3>() );
745 DALI_TEST_CHECK( Vector3::ONE == actor.GetProperty( Actor::Property::SCALE ).Get<Vector3>() );
746 DALI_TEST_CHECK( true == actor.GetProperty( Actor::Property::VISIBLE ).Get<bool>() );
747 DALI_TEST_CHECK( Color::WHITE == actor.GetProperty( Actor::Property::COLOR ).Get<Vector4>() );
751 int UtcDaliHandleDownCast(void)
753 TestApplication application;
754 tet_infoline("Testing Dali::Handle::DownCast()");
756 Actor actor = Actor::New();
758 BaseHandle baseHandle = actor;
760 Handle handle = Handle::DownCast(baseHandle);
762 DALI_TEST_CHECK( handle );
764 baseHandle = BaseHandle();
766 handle = Handle::DownCast(baseHandle);
768 DALI_TEST_CHECK( !handle );
773 int UtcDaliHandleDownCastNegative(void)
775 TestApplication application;
777 // BaseObject is NOT an Object, so this DownCast should fail
778 BaseHandle handle( new BaseObjectType );
779 Handle customHandle1 = Handle::DownCast( handle );
780 DALI_TEST_CHECK( ! customHandle1 );
782 // A DownCast on an empty handle will also fail
784 Handle customHandle2 = Handle::DownCast( empty );
785 DALI_TEST_CHECK( ! customHandle2 );
789 int UtcDaliHandleGetPropertyIndices(void)
791 TestApplication application;
792 Property::IndexContainer indices;
795 Actor actor = Actor::New();
796 actor.GetPropertyIndices( indices );
797 int numDefaultProperties = indices.Size();
798 DALI_TEST_CHECK( numDefaultProperties > 0 );
799 DALI_TEST_EQUALS( numDefaultProperties, actor.GetPropertyCount(), TEST_LOCATION );
801 const Vector4 testColor(0.5f, 0.2f, 0.9f, 1.0f);
802 const float withFlake(99.f);
804 Property::Index key1 = CORE_PROPERTY_MAX_INDEX+1;
805 Property::Index key2 = CORE_PROPERTY_MAX_INDEX+2;
807 actor.RegisterProperty( "MyPropertyOne", Vector3::ONE );
808 actor.RegisterProperty( key1, "sideColor", testColor);
809 actor.RegisterProperty( "MyPropertyTwo", 1234 );
810 Property::Index index4 = actor.RegisterProperty( key2, "iceCream", withFlake );
811 actor.RegisterProperty( "MyPropertyThree", Vector2(.2f,.7f) );
813 actor.GetPropertyIndices( indices );
815 DALI_TEST_EQUALS( indices.Size(), numDefaultProperties + 5, TEST_LOCATION );
816 DALI_TEST_EQUALS( indices[indices.Size()-2], index4, TEST_LOCATION );
821 int UtcDaliHandleRegisterPropertyTypes(void)
823 TestApplication application;
825 struct PropertyTypeAnimatable
828 Property::Value value;
832 Property::Array array;
835 PropertyTypeAnimatable properties[] =
837 { "Property::BOOLEAN", true, true },
838 { "Property::FLOAT", 1.0f, true },
839 { "Property::INTEGER", 1, true },
840 { "Property::VECTOR2", Vector2::ONE, true },
841 { "Property::VECTOR3", Vector3::ONE, true },
842 { "Property::VECTOR4", Vector4::ONE, true },
843 { "Property::MATRIX3", Matrix3::IDENTITY, true },
844 { "Property::MATRIX", Matrix::IDENTITY, true },
845 { "Property::RECTANGLE", Rect<int>(), false },
846 { "Property::ROTATION", AngleAxis(), true },
847 { "Property::STRING", std::string("Me"), false },
848 { "Property::ARRAY", array, false },
849 { "Property::MAP", map, false },
852 unsigned int numOfProperties( sizeof( properties ) / sizeof( properties[0] ) );
854 for ( unsigned int i = 0; i < numOfProperties; ++i )
856 tet_printf( "Testing: %s\n", properties[i].name );
858 bool exception = false;
861 Actor actor = Actor::New();
862 actor.RegisterProperty( "manFromDelmonte", properties[i].value );
864 catch (Dali::DaliException& e)
869 DALI_TEST_CHECK( properties[i].animatable != exception );
874 int UtcDaliHandleCustomProperty(void)
876 TestApplication application;
878 Handle handle = Handle::New();
880 float startValue(1.0f);
881 Property::Index index = handle.RegisterProperty( "testProperty", startValue );
882 DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
884 application.SendNotification();
885 application.Render(0);
886 DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
887 application.Render(0);
888 DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
890 handle.SetProperty( index, 5.0f );
892 application.SendNotification();
893 application.Render(0);
894 DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );
895 application.Render(0);
896 DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );
900 int UtcDaliHandleWeightNew(void)
902 TestApplication application;
904 Handle handle = WeightObject::New();;
905 DALI_TEST_CHECK( handle.GetProperty<float>(WeightObject::WEIGHT) == 0.0f );