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"
26 void handle_test_startup(void)
28 test_return_value = TET_UNDEF;
31 void handle_test_cleanup(void)
33 test_return_value = TET_PASS;
39 /// Allows the creation of a BaseObject
40 class BaseObjectType : public BaseObject
48 Handle ImplicitCopyConstructor(Handle passedByValue)
50 // object + copy + passedByValue, ref count == 3
51 DALI_TEST_CHECK(passedByValue);
54 DALI_TEST_EQUALS(3, passedByValue.GetBaseObject().ReferenceCount(), TEST_LOCATION);
63 int UtcDaliHandleConstructorVoid(void)
65 TestApplication application;
66 tet_infoline("Testing Dali::Handle::Handle()");
70 DALI_TEST_CHECK(!object);
75 int UtcDaliHandleCopyConstructor(void)
77 TestApplication application;
78 tet_infoline("Testing Dali::Handle::Handle(const Handle&)");
80 // Initialize an object, ref count == 1
81 Handle object = Actor::New();
83 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
85 // Copy the object, ref count == 2
87 DALI_TEST_CHECK(copy);
90 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
94 // Pass by value, and return another copy, ref count == 3
95 Handle anotherCopy = ImplicitCopyConstructor(copy);
97 DALI_TEST_CHECK(anotherCopy);
100 DALI_TEST_EQUALS(3, anotherCopy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
104 // anotherCopy out of scope, ref count == 2
105 DALI_TEST_CHECK(copy);
108 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
113 int UtcDaliHandleAssignmentOperator(void)
115 TestApplication application;
116 tet_infoline("Testing Dali::Handle::operator=");
118 Handle object = Actor::New();
120 DALI_TEST_CHECK(object);
121 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
124 DALI_TEST_CHECK(!copy);
127 DALI_TEST_CHECK(copy);
128 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
129 DALI_TEST_CHECK(&(copy.GetBaseObject()) == &(object.GetBaseObject()));
133 int UtcDaliHandleSupports(void)
135 tet_infoline("Positive Test Dali::Handle::Supports()");
136 TestApplication application;
138 Actor actor = Actor::New();
139 DALI_TEST_CHECK( true == actor.Supports( Handle::DYNAMIC_PROPERTIES ) );
143 int UtcDaliHandleGetPropertyCount(void)
145 tet_infoline("Positive Test Dali::Handle::GetPropertyCount()");
146 TestApplication application;
148 Actor actor = Actor::New();
149 int defaultPropertyCount( actor.GetPropertyCount() );
151 // Register a dynamic property
152 actor.RegisterProperty( "test-property", float(123.0f) );
153 DALI_TEST_CHECK( (defaultPropertyCount + 1u) == actor.GetPropertyCount() );
157 int UtcDaliHandleGetPropertyName(void)
159 tet_infoline("Positive Test Dali::Handle::GetPropertyName()");
160 TestApplication application;
162 Actor actor = Actor::New();
163 DALI_TEST_CHECK( "parent-origin" == actor.GetPropertyName( Actor::Property::PARENT_ORIGIN ) );
165 // Register a dynamic property
166 std::string name("this-name-should-match");
167 Property::Index index = actor.RegisterProperty( name, float(123.0f) );
168 DALI_TEST_CHECK( name == actor.GetPropertyName( index ) );
173 int UtcDaliHandleGetPropertyIndex(void)
175 tet_infoline("Positive Test Dali::Handle::GetPropertyIndex()");
176 TestApplication application;
178 Actor actor = Actor::New();
179 DALI_TEST_CHECK( Actor::Property::PARENT_ORIGIN == actor.GetPropertyIndex("parent-origin") );
181 // Register a dynamic property
182 std::string name("this-name-should-match");
183 Property::Index index = actor.RegisterProperty( name, float(123.0f) );
184 DALI_TEST_CHECK( index == actor.GetPropertyIndex( name ) );
188 int UtcDaliHandleIsPropertyWritable(void)
190 tet_infoline("Positive Test Dali::Handle::IsPropertyWritable()");
191 TestApplication application;
193 Actor actor = Actor::New();
195 // Actor properties which are writable:
196 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN ) );
197 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN_X ) );
198 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN_Y ) );
199 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN_Z ) );
200 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT ) );
201 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT_X ) );
202 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT_Y ) );
203 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT_Z ) );
204 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE ) );
205 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE_WIDTH ) );
206 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE_HEIGHT ) );
207 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE_DEPTH ) );
208 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION ) );
209 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION_X ) );
210 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION_Y ) );
211 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION_Z ) );
212 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ORIENTATION ) );
213 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE ) );
214 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE_X ) );
215 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE_Y ) );
216 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE_Z ) );
217 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::VISIBLE ) );
218 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR ) );
219 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_RED ) );
220 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_GREEN ) );
221 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_BLUE ) );
222 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_ALPHA ) );
224 // World-properties are not writable:
225 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION ) );
226 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_ORIENTATION ) );
227 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_SCALE ) );
228 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_COLOR ) );
229 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION_X ) );
230 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION_Y ) );
231 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION_Z ) );
236 int UtcDaliHandleIsPropertyAnimatable(void)
238 tet_infoline("Positive Test Dali::Handle::IsPropertyAnimatable()");
239 TestApplication application;
241 Actor actor = Actor::New();
243 // Actor properties which are animatable:
244 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN ) );
245 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN_X ) );
246 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN_Y ) );
247 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN_Z ) );
248 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT ) );
249 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT_X ) );
250 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT_Y ) );
251 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT_Z ) );
252 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE ) );
253 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE_WIDTH ) );
254 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE_HEIGHT ) );
255 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE_DEPTH ) );
256 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION ) );
257 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION_X ) );
258 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION_Y ) );
259 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION_Z ) );
260 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::ORIENTATION ) );
261 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE ) );
262 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE_X ) );
263 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE_Y ) );
264 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE_Z ) );
265 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::VISIBLE ) );
266 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR ) );
267 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_RED ) );
268 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_GREEN ) );
269 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_BLUE ) );
270 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_ALPHA ) );
272 // World-properties can not be animated
273 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION ) );
274 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_ORIENTATION ) );
275 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_SCALE ) );
276 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_COLOR ) );
277 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION_X ) );
278 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION_Y ) );
279 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION_Z ) );
284 int UtcDaliHandleIsPropertyAConstraintInput(void)
286 TestApplication application;
288 Actor actor = Actor::New();
290 // Actor properties which can be used as a constraint input:
291 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN ) );
292 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN_X ) );
293 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN_Y ) );
294 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN_Z ) );
295 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT ) );
296 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT_X ) );
297 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT_Y ) );
298 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT_Z ) );
299 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE ) );
300 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_WIDTH ) );
301 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_HEIGHT ) );
302 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_DEPTH ) );
303 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION ) );
304 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_X ) );
305 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_Y ) );
306 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_Z ) );
307 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ORIENTATION ) );
308 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE ) );
309 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE_X ) );
310 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE_Y ) );
311 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE_Z ) );
312 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::VISIBLE ) );
313 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR ) );
314 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_RED ) );
315 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_GREEN ) );
316 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_BLUE ) );
317 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_ALPHA ) );
318 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION ) );
319 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_ORIENTATION ) );
320 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_SCALE ) );
321 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_COLOR ) );
322 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION_X ) );
323 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION_Y ) );
324 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION_Z ) );
326 // Actor properties that cannot be used as a constraint input
327 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::NAME ) );
328 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::SENSITIVE ) );
329 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::LEAVE_REQUIRED ) );
330 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::INHERIT_ORIENTATION ) );
331 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::INHERIT_SCALE ) );
332 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_MODE ) );
333 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_INHERITANCE ) );
334 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::DRAW_MODE ) );
335 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_MODE_FACTOR ) );
341 int UtcDaliHandleGetPropertyType(void)
343 tet_infoline("Positive Test Dali::Handle::GetPropertyType()");
344 TestApplication application;
345 unsigned int unsingedIntTest = 33;
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( "bool-property", bool(true) );
359 Property::Index floatIndex = actor.RegisterProperty( "float-property", float(123.0f) );
360 Property::Index intIndex = actor.RegisterProperty( "int-property", 123 );
361 Property::Index unsignedIntIndex = actor.RegisterProperty( "unsigned-int-property", 456u );
362 Property::Index vector2Index = actor.RegisterProperty( "vector2-property", Vector2(1.0f, 2.0f) );
363 Property::Index vector3Index = actor.RegisterProperty( "vector3-property", Vector3(1.0f, 2.0f, 3.0f) );
364 Property::Index vector4Index = actor.RegisterProperty( "vector4-property", Vector4(1.0f, 2.0f, 3.0f, 4.0f) );
365 Property::Index rotationIndex = actor.RegisterProperty( "rotation-property", AngleAxis(Degree(180.0f), Vector3::YAXIS) );
367 DALI_TEST_CHECK( Property::BOOLEAN == actor.GetPropertyType( boolIndex ) );
368 DALI_TEST_CHECK( Property::FLOAT == actor.GetPropertyType( floatIndex ) );
369 DALI_TEST_CHECK( Property::INTEGER == actor.GetPropertyType( intIndex ) );
370 DALI_TEST_CHECK( Property::UNSIGNED_INTEGER == actor.GetPropertyType( unsignedIntIndex ) );
371 DALI_TEST_CHECK( Property::VECTOR2 == actor.GetPropertyType( vector2Index ) );
372 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( vector3Index ) );
373 DALI_TEST_CHECK( Property::VECTOR4 == actor.GetPropertyType( vector4Index ) );
374 DALI_TEST_CHECK( Property::ROTATION == actor.GetPropertyType( rotationIndex ) );
376 // Non animatable properties
377 Property::Index nonAnimStringIndex = actor.RegisterProperty( "man-from-delmonte", std::string("yes"), Property::READ_WRITE);
378 Property::Index nonAnimV2Index = actor.RegisterProperty( "v2", Vector2(1.f, 2.f), Property::READ_WRITE);
379 Property::Index nonAnimV3Index = actor.RegisterProperty( "v3", Vector3(1.f, 2.f, 3.f), Property::READ_WRITE);
380 Property::Index nonAnimV4Index = actor.RegisterProperty( "v4", Vector4(1.f, 2.f, 3.f, 4.f), Property::READ_WRITE);
381 Property::Index nonAnimBooleanIndex = actor.RegisterProperty( "bool", true, Property::READ_WRITE);
382 Property::Index nonAnimFloatIndex = actor.RegisterProperty( "float", 0.f, Property::READ_WRITE);
383 Property::Index nonAnimIntegerIndex = actor.RegisterProperty( "int", 0, Property::READ_WRITE);
384 Property::Index nonAnimUnsignedIntIndex = actor.RegisterProperty( "unsinged-int", unsingedIntTest, Property::READ_WRITE);
386 DALI_TEST_CHECK( nonAnimStringIndex != Property::INVALID_INDEX );
387 DALI_TEST_CHECK( nonAnimV2Index != Property::INVALID_INDEX );
388 DALI_TEST_CHECK( nonAnimV3Index != Property::INVALID_INDEX );
389 DALI_TEST_CHECK( nonAnimV4Index != Property::INVALID_INDEX );
390 DALI_TEST_CHECK( nonAnimBooleanIndex != Property::INVALID_INDEX );
391 DALI_TEST_CHECK( nonAnimFloatIndex != Property::INVALID_INDEX );
392 DALI_TEST_CHECK( nonAnimIntegerIndex != Property::INVALID_INDEX );
393 DALI_TEST_CHECK( nonAnimUnsignedIntIndex != Property::INVALID_INDEX );
395 DALI_TEST_CHECK( Property::STRING == actor.GetPropertyType( nonAnimStringIndex ) );
396 DALI_TEST_CHECK( Property::VECTOR2 == actor.GetPropertyType( nonAnimV2Index ) );
397 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( nonAnimV3Index ) );
398 DALI_TEST_CHECK( Property::VECTOR4 == actor.GetPropertyType( nonAnimV4Index ) );
399 DALI_TEST_CHECK( Property::BOOLEAN == actor.GetPropertyType( nonAnimBooleanIndex ) );
400 DALI_TEST_CHECK( Property::FLOAT == actor.GetPropertyType( nonAnimFloatIndex ) );
401 DALI_TEST_CHECK( Property::INTEGER == actor.GetPropertyType( nonAnimIntegerIndex ) );
402 DALI_TEST_CHECK( Property::UNSIGNED_INTEGER == actor.GetPropertyType( nonAnimUnsignedIntIndex ) );
404 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimStringIndex ) );
405 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV2Index ) );
406 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV3Index ) );
407 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV4Index ) );
408 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimBooleanIndex ) );
409 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimFloatIndex ) );
410 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimIntegerIndex ) );
411 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimUnsignedIntIndex ) );
413 DALI_TEST_EQUALS( "yes" , actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
414 DALI_TEST_EQUALS( Vector2(1.f, 2.f) , actor.GetProperty( nonAnimV2Index ).Get<Vector2>(), TEST_LOCATION );
415 DALI_TEST_EQUALS( Vector3(1.f, 2.f, 3.f) , actor.GetProperty( nonAnimV3Index ).Get<Vector3>(), TEST_LOCATION );
416 DALI_TEST_EQUALS( Vector4(1.f, 2.f, 3.f, 4.f) , actor.GetProperty( nonAnimV4Index ).Get<Vector4>(), TEST_LOCATION );
417 DALI_TEST_EQUALS( true, actor.GetProperty( nonAnimBooleanIndex ).Get<bool>(), TEST_LOCATION );
418 DALI_TEST_EQUALS( 0.f, actor.GetProperty( nonAnimFloatIndex ).Get<float>(), TEST_LOCATION );
419 DALI_TEST_EQUALS( 0, actor.GetProperty( nonAnimIntegerIndex ).Get<int>(), TEST_LOCATION );
420 DALI_TEST_EQUALS( unsingedIntTest, actor.GetProperty( nonAnimUnsignedIntIndex ).Get<unsigned int>(), TEST_LOCATION );
425 int UtcDaliHandleNonAnimtableProperties(void)
427 tet_infoline("Test Non Animatable Properties");
428 TestApplication application;
430 Actor actor = Actor::New();
432 Property::Index nonAnimStringIndex = actor.RegisterProperty( "man-from-delmonte", std::string("no"), Property::READ_WRITE);
434 //// modify writable?
437 actor.SetProperty( nonAnimStringIndex, Property::Value("yes") );
439 catch (Dali::DaliException& e)
441 DALI_TEST_CHECK(!"exception");
444 DALI_TEST_CHECK( "yes" == actor.GetProperty( nonAnimStringIndex ).Get<std::string>() );
446 //// cannot modify read only?
447 Property::Index readonly = actor.RegisterProperty( "float", 0.f, Property::READ_ONLY);
449 DALI_TEST_CHECK(!actor.IsPropertyAnimatable(readonly));
450 DALI_TEST_CHECK(!actor.IsPropertyWritable(readonly));
452 bool exception = false;
455 actor.SetProperty( readonly, Property::Value(1.f) );
457 catch (Dali::DaliException& e)
462 DALI_TEST_CHECK(!exception);// trying to set a read-only property is a no-op
464 DALI_TEST_EQUALS( 0.f, actor.GetProperty( readonly ).Get<float>(), TEST_LOCATION );
466 /// animatable can be set
467 Property::Index write_anim = actor.RegisterProperty( "write_float", 0.f, Property::ANIMATABLE);
469 DALI_TEST_CHECK(actor.IsPropertyAnimatable(write_anim));
470 DALI_TEST_CHECK(actor.IsPropertyWritable(write_anim));
475 actor.SetProperty( write_anim, Property::Value(1.f) );
477 catch (Dali::DaliException& e)
482 DALI_TEST_CHECK(!exception);
484 //// animate a non animatable property is a noop?
485 float durationSeconds(2.0f);
486 Animation animation = Animation::New(durationSeconds);
487 bool relativeValue(true);
493 animation.AnimateBy(Property(actor, nonAnimStringIndex), relativeValue, AlphaFunction::EASE_IN);
495 application.SendNotification();
496 application.Render(static_cast<unsigned int>(durationSeconds*0100.0f)/* some progress */);
498 catch (Dali::DaliException& e)
503 DALI_TEST_CHECK(!exception);
504 DALI_TEST_EQUALS( "yes", actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
509 int UtcDaliHandleNonAnimtableCompositeProperties(void)
511 tet_infoline("Test Non Animatable Composite Properties");
512 TestApplication application;
514 Actor actor = Actor::New();
516 Property::Value value(Property::ARRAY);
517 Property::Array anArray;
518 DALI_TEST_CHECK( Property::Value(anArray).GetType() == Property::ARRAY ); // 2nd constructor
520 value.AppendItem( Property::Value( 0.f ) );
521 value.AppendItem( "a string" );
522 value.SetItem(0, Property::Value( 5.f )); // exercise SetItem
524 int index = value.AppendItem( Vector3(1,2,3) );
526 DALI_TEST_EQUALS( 2, index, TEST_LOCATION);
527 DALI_TEST_EQUALS( 3, value.GetSize(), TEST_LOCATION);
529 Property::Index propertyIndex = actor.RegisterProperty( "composite", value, Property::READ_WRITE);
531 Property::Value out = actor.GetProperty( propertyIndex );
533 DALI_TEST_CHECK( Property::FLOAT == out.GetItem(0).GetType());
534 DALI_TEST_CHECK( Property::STRING == out.GetItem(1).GetType());
535 DALI_TEST_CHECK( Property::VECTOR3 == out.GetItem(2).GetType());
537 DALI_TEST_EQUALS( 5.f, out.GetItem(0).Get<float>(), TEST_LOCATION);
538 DALI_TEST_EQUALS( "a string", out.GetItem(1).Get<std::string>(), TEST_LOCATION);
539 DALI_TEST_EQUALS( Vector3(1,2,3), out.GetItem(2).Get<Vector3>(), TEST_LOCATION);
542 Property::Value valueMap(Property::MAP);
543 Property::Map aKindofMap;
544 DALI_TEST_CHECK( Property::Value(aKindofMap).GetType() == Property::MAP ); // 2nd constructor
546 valueMap.SetValue("key", 5.f);
547 valueMap.SetValue("2key", "a string");
549 DALI_TEST_EQUALS( true, valueMap.HasKey("key"), TEST_LOCATION);
550 DALI_TEST_EQUALS( "key", valueMap.GetKey(0), TEST_LOCATION);
552 DALI_TEST_EQUALS( true, valueMap.HasKey("2key"), TEST_LOCATION);
553 DALI_TEST_EQUALS( "2key", valueMap.GetKey(1), TEST_LOCATION);
555 DALI_TEST_EQUALS( 5.f, valueMap.GetValue("key").Get<float>(), TEST_LOCATION);
556 DALI_TEST_EQUALS( "a string", valueMap.GetValue("2key").Get<std::string>(), TEST_LOCATION);
558 valueMap.SetItem(0, Property::Value("a string"));
559 valueMap.SetItem(1, Property::Value(5.f));
561 DALI_TEST_EQUALS( 5.f, valueMap.GetValue("2key").Get<float>(), TEST_LOCATION);
562 DALI_TEST_EQUALS( "a string", valueMap.GetValue("key").Get<std::string>(), TEST_LOCATION);
565 valueMap = Property::Value(Property::MAP);
567 valueMap.SetValue("key", 5.f);
568 valueMap.SetValue("2key", "a string");
570 DALI_TEST_EQUALS( 5.f, valueMap.GetItem(0).Get<float>(), TEST_LOCATION);
571 DALI_TEST_EQUALS( "a string", valueMap.GetItem(1).Get<std::string>(), TEST_LOCATION);
573 DALI_TEST_EQUALS( 2, valueMap.GetSize(), TEST_LOCATION);
575 // composite types not animatable
576 bool exception = false;
579 /* Property::Index mapPropertyIndex = */ actor.RegisterProperty( "compositemap", value, Property::ANIMATABLE);
581 catch (Dali::DaliException& e)
584 DALI_TEST_PRINT_ASSERT( e );
587 DALI_TEST_EQUALS(exception, true, TEST_LOCATION);
590 Property::Value mapOfMaps(Property::MAP);
592 mapOfMaps.SetValue( "key", Property::Value(Property::MAP) );
593 mapOfMaps.SetValue( "2key", "a string" );
595 DALI_TEST_EQUALS( "a string", mapOfMaps.GetValue("2key").Get<std::string>(), TEST_LOCATION);
597 mapOfMaps.GetValue("key").SetValue("subkey", 5.f);
599 DALI_TEST_EQUALS( true, mapOfMaps.GetValue("key").HasKey("subkey"), TEST_LOCATION);
600 DALI_TEST_EQUALS( 5.f, mapOfMaps.GetValue("key").GetValue("subkey").Get<float>(), TEST_LOCATION);
603 Property::Value listOfMaps(Property::ARRAY);
605 listOfMaps.AppendItem( Property::Value(Property::MAP) );
606 listOfMaps.AppendItem( Property::Value(Property::MAP) );
608 listOfMaps.GetItem(0).SetValue("key", 5.f);
609 listOfMaps.GetItem(1).SetValue("key",10.f);
611 DALI_TEST_EQUALS( 5.f, listOfMaps.GetItem(0).GetValue("key").Get<float>(), TEST_LOCATION );
612 DALI_TEST_EQUALS( 10.f, listOfMaps.GetItem(1).GetValue("key").Get<float>(), TEST_LOCATION );
617 int UtcDaliHandleSetProperty01(void)
619 tet_infoline("Positive Test Dali::Handle::SetProperty()");
620 TestApplication application;
622 Actor actor = Actor::New();
623 DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
625 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
626 // flush the queue and render once
627 application.SendNotification();
628 application.Render();
629 DALI_TEST_CHECK( ParentOrigin::CENTER == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
633 int UtcDaliHandleSetProperty02(void)
635 tet_infoline("Positive Test Dali::Handle::SetProperty()");
636 TestApplication application;
638 Actor actor = Actor::New();
640 DALI_TEST_CHECK( !actor.IsPropertyWritable( Actor::Property::WORLD_POSITION ) );
642 // World position is not writable so this is a no-op and should not crash
643 actor.SetProperty( Actor::Property::WORLD_POSITION, Vector3(1,2,3) );
648 int UtcDaliHandleRegisterProperty(void)
650 tet_infoline("Positive Test Dali::Handle::RegisterProperty()");
651 TestApplication application;
653 Actor actor = Actor::New();
654 DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
659 int UtcDaliHandleGetProperty(void)
661 tet_infoline("Positive Test Dali::Handle::GetProperty()");
662 TestApplication application;
664 Actor actor = Actor::New();
666 DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
667 DALI_TEST_CHECK( AnchorPoint::CENTER == actor.GetProperty( Actor::Property::ANCHOR_POINT ).Get<Vector3>() );
668 DALI_TEST_CHECK( Vector3::ZERO == actor.GetProperty( Actor::Property::SIZE ).Get<Vector3>() );
669 DALI_TEST_CHECK( Vector3::ZERO == actor.GetProperty( Actor::Property::POSITION ).Get<Vector3>() );
670 DALI_TEST_CHECK( Vector3::ONE == actor.GetProperty( Actor::Property::SCALE ).Get<Vector3>() );
671 DALI_TEST_CHECK( true == actor.GetProperty( Actor::Property::VISIBLE ).Get<bool>() );
672 DALI_TEST_CHECK( Color::WHITE == actor.GetProperty( Actor::Property::COLOR ).Get<Vector4>() );
676 int UtcDaliHandleDownCast(void)
678 TestApplication application;
679 tet_infoline("Testing Dali::Handle::DownCast()");
681 Actor actor = Actor::New();
683 BaseHandle baseHandle = actor;
685 Handle handle = Handle::DownCast(baseHandle);
687 DALI_TEST_CHECK( handle );
689 baseHandle = BaseHandle();
691 handle = Handle::DownCast(baseHandle);
693 DALI_TEST_CHECK( !handle );
698 int UtcDaliHandleDownCastNegative(void)
700 TestApplication application;
702 // BaseObject is NOT an Object, so this DownCast should fail
703 BaseHandle handle( new BaseObjectType );
704 Handle customHandle1 = Handle::DownCast( handle );
705 DALI_TEST_CHECK( ! customHandle1 );
707 // A DownCast on an empty handle will also fail
709 Handle customHandle2 = Handle::DownCast( empty );
710 DALI_TEST_CHECK( ! customHandle2 );
714 int UtcDaliHandleGetPropertyIndices(void)
716 TestApplication application;
717 Property::IndexContainer indices;
720 Actor actor = Actor::New();
721 actor.GetPropertyIndices( indices );
722 DALI_TEST_CHECK( indices.Size() );
723 DALI_TEST_EQUALS( indices.Size(), actor.GetPropertyCount(), TEST_LOCATION );
727 int UtcDaliHandleRegisterPropertyTypes(void)
729 TestApplication application;
731 struct PropertyTypeAnimatable
734 Property::Value value;
738 Property::Array array;
741 PropertyTypeAnimatable properties[] =
743 { "Property::BOOLEAN", true, true },
744 { "Property::FLOAT", 1.0f, true },
745 { "Property::INTEGER", 1, true },
746 { "Property::UNSIGNED_INTEGER", 1u, true },
747 { "Property::VECTOR2", Vector2::ONE, true },
748 { "Property::VECTOR3", Vector3::ONE, true },
749 { "Property::VECTOR4", Vector4::ONE, true },
750 { "Property::MATRIX3", Matrix3::IDENTITY, true },
751 { "Property::MATRIX", Matrix::IDENTITY, true },
752 { "Property::RECTANGLE", Rect<int>(), false },
753 { "Property::ROTATION", AngleAxis(), true },
754 { "Property::STRING", std::string("Me"), false },
755 { "Property::ARRAY", array, false },
756 { "Property::MAP", map, false },
759 unsigned int numOfProperties( sizeof( properties ) / sizeof( properties[0] ) );
761 for ( unsigned int i = 0; i < numOfProperties; ++i )
763 tet_printf( "Testing: %s\n", properties[i].name );
765 bool exception = false;
768 Actor actor = Actor::New();
769 actor.RegisterProperty( "man-from-delmonte", properties[i].value );
771 catch (Dali::DaliException& e)
776 DALI_TEST_CHECK( properties[i].animatable != exception );
781 int UtcDaliHandleCustomProperty(void)
783 TestApplication application;
785 Handle handle = Handle::New();
787 float startValue(1.0f);
788 Property::Index index = handle.RegisterProperty( "test-property", startValue );
789 DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
791 application.SendNotification();
792 application.Render(0);
793 DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
794 application.Render(0);
795 DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
797 handle.SetProperty( index, 5.0f );
799 application.SendNotification();
800 application.Render(0);
801 DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );
802 application.Render(0);
803 DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );
806 int UtcDaliHandleWeightNew(void)
808 TestApplication application;
810 Handle handle = WeightObject::New();;
811 DALI_TEST_CHECK( handle.GetProperty<float>(WeightObject::WEIGHT) == 0.0f );