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);
74 int UtcDaliHandleCopyConstructor(void)
76 TestApplication application;
77 tet_infoline("Testing Dali::Handle::Handle(const Handle&)");
79 // Initialize an object, ref count == 1
80 Handle object = Actor::New();
82 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
84 // Copy the object, ref count == 2
86 DALI_TEST_CHECK(copy);
89 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
93 // Pass by value, and return another copy, ref count == 3
94 Handle anotherCopy = ImplicitCopyConstructor(copy);
96 DALI_TEST_CHECK(anotherCopy);
99 DALI_TEST_EQUALS(3, anotherCopy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
103 // anotherCopy out of scope, ref count == 2
104 DALI_TEST_CHECK(copy);
107 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
112 int UtcDaliHandleAssignmentOperator(void)
114 TestApplication application;
115 tet_infoline("Testing Dali::Handle::operator=");
117 Handle object = Actor::New();
119 DALI_TEST_CHECK(object);
120 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
123 DALI_TEST_CHECK(!copy);
126 DALI_TEST_CHECK(copy);
127 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
128 DALI_TEST_CHECK(&(copy.GetBaseObject()) == &(object.GetBaseObject()));
132 int UtcDaliHandleSupports(void)
134 tet_infoline("Positive Test Dali::Handle::Supports()");
135 TestApplication application;
137 Actor actor = Actor::New();
138 DALI_TEST_CHECK( true == actor.Supports( Handle::DYNAMIC_PROPERTIES ) );
142 int UtcDaliHandleGetPropertyCount(void)
144 tet_infoline("Positive Test Dali::Handle::GetPropertyCount()");
145 TestApplication application;
147 Actor actor = Actor::New();
148 int defaultPropertyCount( actor.GetPropertyCount() );
150 // Register a dynamic property
151 actor.RegisterProperty( "test-property", float(123.0f) );
152 DALI_TEST_CHECK( (defaultPropertyCount + 1u) == actor.GetPropertyCount() );
156 int UtcDaliHandleGetPropertyName(void)
158 tet_infoline("Positive Test Dali::Handle::GetPropertyName()");
159 TestApplication application;
161 Actor actor = Actor::New();
162 DALI_TEST_CHECK( "parent-origin" == actor.GetPropertyName( Actor::Property::PARENT_ORIGIN ) );
164 // Register a dynamic property
165 std::string name("this-name-should-match");
166 Property::Index index = actor.RegisterProperty( name, float(123.0f) );
167 DALI_TEST_CHECK( name == actor.GetPropertyName( index ) );
172 int UtcDaliHandleGetPropertyIndex(void)
174 tet_infoline("Positive Test Dali::Handle::GetPropertyIndex()");
175 TestApplication application;
177 Actor actor = Actor::New();
178 DALI_TEST_CHECK( Actor::Property::PARENT_ORIGIN == actor.GetPropertyIndex("parent-origin") );
180 // Register a dynamic property
181 std::string name("this-name-should-match");
182 Property::Index index = actor.RegisterProperty( name, float(123.0f) );
183 DALI_TEST_CHECK( index == actor.GetPropertyIndex( name ) );
187 int UtcDaliHandleIsPropertyWritable(void)
189 tet_infoline("Positive Test Dali::Handle::IsPropertyWritable()");
190 TestApplication application;
192 Actor actor = Actor::New();
194 // Actor properties which are writable:
195 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN ) );
196 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN_X ) );
197 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN_Y ) );
198 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::PARENT_ORIGIN_Z ) );
199 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT ) );
200 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT_X ) );
201 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT_Y ) );
202 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ANCHOR_POINT_Z ) );
203 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE ) );
204 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE_WIDTH ) );
205 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE_HEIGHT ) );
206 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SIZE_DEPTH ) );
207 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION ) );
208 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION_X ) );
209 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION_Y ) );
210 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::POSITION_Z ) );
211 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::ORIENTATION ) );
212 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE ) );
213 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE_X ) );
214 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE_Y ) );
215 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::SCALE_Z ) );
216 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::VISIBLE ) );
217 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR ) );
218 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_RED ) );
219 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_GREEN ) );
220 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_BLUE ) );
221 DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_ALPHA ) );
223 // World-properties are not writable:
224 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION ) );
225 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_ORIENTATION ) );
226 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_SCALE ) );
227 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_COLOR ) );
228 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION_X ) );
229 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION_Y ) );
230 DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION_Z ) );
235 int UtcDaliHandleIsPropertyAnimatable(void)
237 tet_infoline("Positive Test Dali::Handle::IsPropertyAnimatable()");
238 TestApplication application;
240 Actor actor = Actor::New();
242 // Actor properties which are animatable:
243 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN ) );
244 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN_X ) );
245 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN_Y ) );
246 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::PARENT_ORIGIN_Z ) );
247 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT ) );
248 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT_X ) );
249 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT_Y ) );
250 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::ANCHOR_POINT_Z ) );
251 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE ) );
252 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE_WIDTH ) );
253 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE_HEIGHT ) );
254 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SIZE_DEPTH ) );
255 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION ) );
256 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION_X ) );
257 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION_Y ) );
258 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::POSITION_Z ) );
259 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::ORIENTATION ) );
260 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE ) );
261 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE_X ) );
262 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE_Y ) );
263 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::SCALE_Z ) );
264 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::VISIBLE ) );
265 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR ) );
266 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_RED ) );
267 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_GREEN ) );
268 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_BLUE ) );
269 DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_ALPHA ) );
271 // World-properties can not be animated
272 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION ) );
273 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_ORIENTATION ) );
274 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_SCALE ) );
275 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_COLOR ) );
276 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION_X ) );
277 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION_Y ) );
278 DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION_Z ) );
283 int UtcDaliHandleIsPropertyAConstraintInput(void)
285 TestApplication application;
287 Actor actor = Actor::New();
289 // Actor properties which can be used as a constraint input:
290 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN ) );
291 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN_X ) );
292 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN_Y ) );
293 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::PARENT_ORIGIN_Z ) );
294 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT ) );
295 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT_X ) );
296 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT_Y ) );
297 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ANCHOR_POINT_Z ) );
298 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE ) );
299 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_WIDTH ) );
300 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_HEIGHT ) );
301 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_DEPTH ) );
302 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION ) );
303 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_X ) );
304 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_Y ) );
305 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_Z ) );
306 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::ORIENTATION ) );
307 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE ) );
308 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE_X ) );
309 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE_Y ) );
310 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::SCALE_Z ) );
311 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::VISIBLE ) );
312 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR ) );
313 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_RED ) );
314 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_GREEN ) );
315 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_BLUE ) );
316 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_ALPHA ) );
317 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION ) );
318 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_ORIENTATION ) );
319 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_SCALE ) );
320 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_COLOR ) );
321 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION_X ) );
322 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION_Y ) );
323 DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION_Z ) );
325 // Actor properties that cannot be used as a constraint input
326 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::NAME ) );
327 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::SENSITIVE ) );
328 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::LEAVE_REQUIRED ) );
329 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::INHERIT_ORIENTATION ) );
330 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::INHERIT_SCALE ) );
331 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_MODE ) );
332 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::POSITION_INHERITANCE ) );
333 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::DRAW_MODE ) );
334 DALI_TEST_CHECK( false == actor.IsPropertyAConstraintInput( Actor::Property::SIZE_MODE_FACTOR ) );
340 int UtcDaliHandleGetPropertyType(void)
342 tet_infoline("Positive Test Dali::Handle::GetPropertyType()");
343 TestApplication application;
344 unsigned int unsingedIntTest = 33;
346 Actor actor = Actor::New();
347 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::PARENT_ORIGIN ) );
348 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::ANCHOR_POINT ) );
349 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::SIZE ) );
350 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::POSITION ) );
351 DALI_TEST_CHECK( Property::ROTATION == actor.GetPropertyType( Actor::Property::ORIENTATION ) );
352 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( Actor::Property::SCALE ) );
353 DALI_TEST_CHECK( Property::BOOLEAN == actor.GetPropertyType( Actor::Property::VISIBLE ) );
354 DALI_TEST_CHECK( Property::VECTOR4 == actor.GetPropertyType( Actor::Property::COLOR ) );
356 // Register some dynamic properties
357 Property::Index boolIndex = actor.RegisterProperty( "bool-property", bool(true) );
358 Property::Index floatIndex = actor.RegisterProperty( "float-property", float(123.0f) );
359 Property::Index intIndex = actor.RegisterProperty( "int-property", 123 );
360 Property::Index vector2Index = actor.RegisterProperty( "vector2-property", Vector2(1.0f, 2.0f) );
361 Property::Index vector3Index = actor.RegisterProperty( "vector3-property", Vector3(1.0f, 2.0f, 3.0f) );
362 Property::Index vector4Index = actor.RegisterProperty( "vector4-property", Vector4(1.0f, 2.0f, 3.0f, 4.0f) );
363 Property::Index rotationIndex = actor.RegisterProperty( "rotation-property", AngleAxis(Degree(180.0f), Vector3::YAXIS) );
365 DALI_TEST_CHECK( Property::BOOLEAN == actor.GetPropertyType( boolIndex ) );
366 DALI_TEST_CHECK( Property::FLOAT == actor.GetPropertyType( floatIndex ) );
367 DALI_TEST_CHECK( Property::INTEGER == actor.GetPropertyType( intIndex ) );
368 DALI_TEST_CHECK( Property::VECTOR2 == actor.GetPropertyType( vector2Index ) );
369 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( vector3Index ) );
370 DALI_TEST_CHECK( Property::VECTOR4 == actor.GetPropertyType( vector4Index ) );
371 DALI_TEST_CHECK( Property::ROTATION == actor.GetPropertyType( rotationIndex ) );
373 // Non animatable properties
374 Property::Index nonAnimStringIndex = actor.RegisterProperty( "man-from-delmonte", std::string("yes"), Property::READ_WRITE);
375 Property::Index nonAnimV2Index = actor.RegisterProperty( "v2", Vector2(1.f, 2.f), Property::READ_WRITE);
376 Property::Index nonAnimV3Index = actor.RegisterProperty( "v3", Vector3(1.f, 2.f, 3.f), Property::READ_WRITE);
377 Property::Index nonAnimV4Index = actor.RegisterProperty( "v4", Vector4(1.f, 2.f, 3.f, 4.f), Property::READ_WRITE);
378 Property::Index nonAnimBooleanIndex = actor.RegisterProperty( "bool", true, Property::READ_WRITE);
379 Property::Index nonAnimFloatIndex = actor.RegisterProperty( "float", 0.f, Property::READ_WRITE);
380 Property::Index nonAnimIntegerIndex = actor.RegisterProperty( "int", 0, Property::READ_WRITE);
381 Property::Index nonAnimUnsignedIntIndex = actor.RegisterProperty( "unsinged-int", unsingedIntTest, Property::READ_WRITE);
383 DALI_TEST_CHECK( nonAnimStringIndex != Property::INVALID_INDEX );
384 DALI_TEST_CHECK( nonAnimV2Index != Property::INVALID_INDEX );
385 DALI_TEST_CHECK( nonAnimV3Index != Property::INVALID_INDEX );
386 DALI_TEST_CHECK( nonAnimV4Index != Property::INVALID_INDEX );
387 DALI_TEST_CHECK( nonAnimBooleanIndex != Property::INVALID_INDEX );
388 DALI_TEST_CHECK( nonAnimFloatIndex != Property::INVALID_INDEX );
389 DALI_TEST_CHECK( nonAnimIntegerIndex != Property::INVALID_INDEX );
390 DALI_TEST_CHECK( nonAnimUnsignedIntIndex != Property::INVALID_INDEX );
392 DALI_TEST_CHECK( Property::STRING == actor.GetPropertyType( nonAnimStringIndex ) );
393 DALI_TEST_CHECK( Property::VECTOR2 == actor.GetPropertyType( nonAnimV2Index ) );
394 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( nonAnimV3Index ) );
395 DALI_TEST_CHECK( Property::VECTOR4 == actor.GetPropertyType( nonAnimV4Index ) );
396 DALI_TEST_CHECK( Property::BOOLEAN == actor.GetPropertyType( nonAnimBooleanIndex ) );
397 DALI_TEST_CHECK( Property::FLOAT == actor.GetPropertyType( nonAnimFloatIndex ) );
398 DALI_TEST_CHECK( Property::INTEGER == actor.GetPropertyType( nonAnimIntegerIndex ) );
399 DALI_TEST_CHECK( Property::UNSIGNED_INTEGER == actor.GetPropertyType( nonAnimUnsignedIntIndex ) );
401 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimStringIndex ) );
402 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV2Index ) );
403 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV3Index ) );
404 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV4Index ) );
405 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimBooleanIndex ) );
406 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimFloatIndex ) );
407 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimIntegerIndex ) );
408 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimUnsignedIntIndex ) );
410 DALI_TEST_EQUALS( "yes" , actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
411 DALI_TEST_EQUALS( Vector2(1.f, 2.f) , actor.GetProperty( nonAnimV2Index ).Get<Vector2>(), TEST_LOCATION );
412 DALI_TEST_EQUALS( Vector3(1.f, 2.f, 3.f) , actor.GetProperty( nonAnimV3Index ).Get<Vector3>(), TEST_LOCATION );
413 DALI_TEST_EQUALS( Vector4(1.f, 2.f, 3.f, 4.f) , actor.GetProperty( nonAnimV4Index ).Get<Vector4>(), TEST_LOCATION );
414 DALI_TEST_EQUALS( true, actor.GetProperty( nonAnimBooleanIndex ).Get<bool>(), TEST_LOCATION );
415 DALI_TEST_EQUALS( 0.f, actor.GetProperty( nonAnimFloatIndex ).Get<float>(), TEST_LOCATION );
416 DALI_TEST_EQUALS( 0, actor.GetProperty( nonAnimIntegerIndex ).Get<int>(), TEST_LOCATION );
417 DALI_TEST_EQUALS( unsingedIntTest, actor.GetProperty( nonAnimUnsignedIntIndex ).Get<unsigned int>(), TEST_LOCATION );
422 int UtcDaliHandleNonAnimtableProperties(void)
424 tet_infoline("Test Non Animatable Properties");
425 TestApplication application;
427 Actor actor = Actor::New();
429 Property::Index nonAnimStringIndex = actor.RegisterProperty( "man-from-delmonte", std::string("no"), Property::READ_WRITE);
431 //// modify writable?
434 actor.SetProperty( nonAnimStringIndex, Property::Value("yes") );
436 catch (Dali::DaliException& e)
438 DALI_TEST_CHECK(!"exception");
441 DALI_TEST_CHECK( "yes" == actor.GetProperty( nonAnimStringIndex ).Get<std::string>() );
443 //// cannot modify read only?
444 Property::Index readonly = actor.RegisterProperty( "float", 0.f, Property::READ_ONLY);
446 DALI_TEST_CHECK(!actor.IsPropertyAnimatable(readonly));
447 DALI_TEST_CHECK(!actor.IsPropertyWritable(readonly));
449 bool exception = false;
452 actor.SetProperty( readonly, Property::Value(1.f) );
454 catch (Dali::DaliException& e)
459 DALI_TEST_CHECK(!exception);// trying to set a read-only property is a no-op
461 DALI_TEST_EQUALS( 0.f, actor.GetProperty( readonly ).Get<float>(), TEST_LOCATION );
463 /// animatable can be set
464 Property::Index write_anim = actor.RegisterProperty( "write_float", 0.f, Property::ANIMATABLE);
466 DALI_TEST_CHECK(actor.IsPropertyAnimatable(write_anim));
467 DALI_TEST_CHECK(actor.IsPropertyWritable(write_anim));
472 actor.SetProperty( write_anim, Property::Value(1.f) );
474 catch (Dali::DaliException& e)
479 DALI_TEST_CHECK(!exception);
481 //// animate a non animatable property is a noop?
482 float durationSeconds(2.0f);
483 Animation animation = Animation::New(durationSeconds);
484 bool relativeValue(true);
490 animation.AnimateBy(Property(actor, nonAnimStringIndex), relativeValue, AlphaFunctions::EaseIn);
492 application.SendNotification();
493 application.Render(static_cast<unsigned int>(durationSeconds*0100.0f)/* some progress */);
495 catch (Dali::DaliException& e)
500 DALI_TEST_CHECK(!exception);
501 DALI_TEST_EQUALS( "yes", actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
506 int UtcDaliHandleNonAnimtableCompositeProperties(void)
508 tet_infoline("Test Non Animatable Composite Properties");
509 TestApplication application;
511 Actor actor = Actor::New();
513 Property::Value value(Property::ARRAY);
514 Property::Array anArray;
515 DALI_TEST_CHECK( Property::Value(anArray).GetType() == Property::ARRAY ); // 2nd constructor
517 value.AppendItem( Property::Value( 0.f ) );
518 value.AppendItem( "a string" );
519 value.SetItem(0, Property::Value( 5.f )); // exercise SetItem
521 int index = value.AppendItem( Vector3(1,2,3) );
523 DALI_TEST_EQUALS( 2, index, TEST_LOCATION);
524 DALI_TEST_EQUALS( 3, value.GetSize(), TEST_LOCATION);
526 Property::Index propertyIndex = actor.RegisterProperty( "composite", value, Property::READ_WRITE);
528 Property::Value out = actor.GetProperty( propertyIndex );
530 DALI_TEST_CHECK( Property::FLOAT == out.GetItem(0).GetType());
531 DALI_TEST_CHECK( Property::STRING == out.GetItem(1).GetType());
532 DALI_TEST_CHECK( Property::VECTOR3 == out.GetItem(2).GetType());
534 DALI_TEST_EQUALS( 5.f, out.GetItem(0).Get<float>(), TEST_LOCATION);
535 DALI_TEST_EQUALS( "a string", out.GetItem(1).Get<std::string>(), TEST_LOCATION);
536 DALI_TEST_EQUALS( Vector3(1,2,3), out.GetItem(2).Get<Vector3>(), TEST_LOCATION);
539 Property::Value valueMap(Property::MAP);
540 Property::Map aKindofMap;
541 DALI_TEST_CHECK( Property::Value(aKindofMap).GetType() == Property::MAP ); // 2nd constructor
543 valueMap.SetValue("key", 5.f);
544 valueMap.SetValue("2key", "a string");
546 DALI_TEST_EQUALS( true, valueMap.HasKey("key"), TEST_LOCATION);
547 DALI_TEST_EQUALS( "key", valueMap.GetKey(0), TEST_LOCATION);
549 DALI_TEST_EQUALS( true, valueMap.HasKey("2key"), TEST_LOCATION);
550 DALI_TEST_EQUALS( "2key", valueMap.GetKey(1), TEST_LOCATION);
552 DALI_TEST_EQUALS( 5.f, valueMap.GetValue("key").Get<float>(), TEST_LOCATION);
553 DALI_TEST_EQUALS( "a string", valueMap.GetValue("2key").Get<std::string>(), TEST_LOCATION);
555 valueMap.SetItem(0, Property::Value("a string"));
556 valueMap.SetItem(1, Property::Value(5.f));
558 DALI_TEST_EQUALS( 5.f, valueMap.GetValue("2key").Get<float>(), TEST_LOCATION);
559 DALI_TEST_EQUALS( "a string", valueMap.GetValue("key").Get<std::string>(), TEST_LOCATION);
562 valueMap = Property::Value(Property::MAP);
564 valueMap.SetValue("key", 5.f);
565 valueMap.SetValue("2key", "a string");
567 DALI_TEST_EQUALS( 5.f, valueMap.GetItem(0).Get<float>(), TEST_LOCATION);
568 DALI_TEST_EQUALS( "a string", valueMap.GetItem(1).Get<std::string>(), TEST_LOCATION);
570 DALI_TEST_EQUALS( 2, valueMap.GetSize(), TEST_LOCATION);
572 // composite types not animatable
573 bool exception = false;
576 /* Property::Index mapPropertyIndex = */ actor.RegisterProperty( "compositemap", value, Property::ANIMATABLE);
578 catch (Dali::DaliException& e)
581 DALI_TEST_PRINT_ASSERT( e );
584 DALI_TEST_EQUALS(exception, true, TEST_LOCATION);
587 Property::Value mapOfMaps(Property::MAP);
589 mapOfMaps.SetValue( "key", Property::Value(Property::MAP) );
590 mapOfMaps.SetValue( "2key", "a string" );
592 DALI_TEST_EQUALS( "a string", mapOfMaps.GetValue("2key").Get<std::string>(), TEST_LOCATION);
594 mapOfMaps.GetValue("key").SetValue("subkey", 5.f);
596 DALI_TEST_EQUALS( true, mapOfMaps.GetValue("key").HasKey("subkey"), TEST_LOCATION);
597 DALI_TEST_EQUALS( 5.f, mapOfMaps.GetValue("key").GetValue("subkey").Get<float>(), TEST_LOCATION);
600 Property::Value listOfMaps(Property::ARRAY);
602 listOfMaps.AppendItem( Property::Value(Property::MAP) );
603 listOfMaps.AppendItem( Property::Value(Property::MAP) );
605 listOfMaps.GetItem(0).SetValue("key", 5.f);
606 listOfMaps.GetItem(1).SetValue("key",10.f);
608 DALI_TEST_EQUALS( 5.f, listOfMaps.GetItem(0).GetValue("key").Get<float>(), TEST_LOCATION );
609 DALI_TEST_EQUALS( 10.f, listOfMaps.GetItem(1).GetValue("key").Get<float>(), TEST_LOCATION );
614 int UtcDaliHandleSetProperty01(void)
616 tet_infoline("Positive Test Dali::Handle::SetProperty()");
617 TestApplication application;
619 Actor actor = Actor::New();
620 DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
622 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
623 // flush the queue and render once
624 application.SendNotification();
625 application.Render();
626 DALI_TEST_CHECK( ParentOrigin::CENTER == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
630 int UtcDaliHandleSetProperty02(void)
632 tet_infoline("Positive Test Dali::Handle::SetProperty()");
633 TestApplication application;
635 Actor actor = Actor::New();
637 DALI_TEST_CHECK( !actor.IsPropertyWritable( Actor::Property::WORLD_POSITION ) );
639 // World position is not writable so this is a no-op and should not crash
640 actor.SetProperty( Actor::Property::WORLD_POSITION, Vector3(1,2,3) );
645 int UtcDaliHandleRegisterProperty(void)
647 tet_infoline("Positive Test Dali::Handle::RegisterProperty()");
648 TestApplication application;
650 Actor actor = Actor::New();
651 DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
656 int UtcDaliHandleGetProperty(void)
658 tet_infoline("Positive Test Dali::Handle::GetProperty()");
659 TestApplication application;
661 Actor actor = Actor::New();
663 DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
664 DALI_TEST_CHECK( AnchorPoint::CENTER == actor.GetProperty( Actor::Property::ANCHOR_POINT ).Get<Vector3>() );
665 DALI_TEST_CHECK( Vector3::ZERO == actor.GetProperty( Actor::Property::SIZE ).Get<Vector3>() );
666 DALI_TEST_CHECK( Vector3::ZERO == actor.GetProperty( Actor::Property::POSITION ).Get<Vector3>() );
667 DALI_TEST_CHECK( Vector3::ONE == actor.GetProperty( Actor::Property::SCALE ).Get<Vector3>() );
668 DALI_TEST_CHECK( true == actor.GetProperty( Actor::Property::VISIBLE ).Get<bool>() );
669 DALI_TEST_CHECK( Color::WHITE == actor.GetProperty( Actor::Property::COLOR ).Get<Vector4>() );
673 int UtcDaliHandleDownCast(void)
675 TestApplication application;
676 tet_infoline("Testing Dali::Handle::DownCast()");
678 Actor actor = Actor::New();
680 BaseHandle baseHandle = actor;
682 Handle handle = Handle::DownCast(baseHandle);
684 DALI_TEST_CHECK( handle );
686 baseHandle = BaseHandle();
688 handle = Handle::DownCast(baseHandle);
690 DALI_TEST_CHECK( !handle );
695 int UtcDaliHandleDownCastNegative(void)
697 TestApplication application;
699 // BaseObject is NOT an Object, so this DownCast should fail
700 BaseHandle handle( new BaseObjectType );
701 Handle customHandle1 = Handle::DownCast( handle );
702 DALI_TEST_CHECK( ! customHandle1 );
704 // A DownCast on an empty handle will also fail
706 Handle customHandle2 = Handle::DownCast( empty );
707 DALI_TEST_CHECK( ! customHandle2 );
711 int UtcDaliHandleGetPropertyIndices(void)
713 TestApplication application;
714 Property::IndexContainer indices;
717 Actor actor = Actor::New();
718 actor.GetPropertyIndices( indices );
719 DALI_TEST_CHECK( ! indices.empty() );
720 DALI_TEST_EQUALS( indices.size(), actor.GetPropertyCount(), TEST_LOCATION );
724 int UtcDaliHandleRegisterPropertyTypes(void)
726 TestApplication application;
728 struct PropertyTypeAnimatable
731 Property::Value value;
735 Property::Array array;
738 PropertyTypeAnimatable properties[] =
740 { "Property::BOOLEAN", true, true },
741 { "Property::FLOAT", 1.0f, true },
742 { "Property::INTEGER", 1, true },
743 { "Property::UNSIGNED_INTEGER", 1u, false },
744 { "Property::VECTOR2", Vector2::ONE, true },
745 { "Property::VECTOR3", Vector3::ONE, true },
746 { "Property::VECTOR4", Vector4::ONE, true },
747 { "Property::MATRIX3", Matrix3::IDENTITY, true },
748 { "Property::MATRIX", Matrix::IDENTITY, true },
749 { "Property::RECTANGLE", Rect<int>(), false },
750 { "Property::ROTATION", AngleAxis(), true },
751 { "Property::STRING", std::string("Me"), false },
752 { "Property::ARRAY", array, false },
753 { "Property::MAP", map, false },
755 unsigned int numOfProperties( sizeof( properties ) / sizeof( properties[0] ) );
757 for ( unsigned int i = 0; i < numOfProperties; ++i )
759 tet_printf( "Testing: %s\n", properties[i].name );
761 bool exception = false;
764 Actor actor = Actor::New();
765 actor.RegisterProperty( "man-from-delmonte", properties[i].value );
767 catch (Dali::DaliException& e)
772 DALI_TEST_CHECK( properties[i].animatable != exception );
777 int UtcDaliHandleCustomProperty(void)
779 TestApplication application;
781 Handle handle = Handle::New();
783 float startValue(1.0f);
784 Property::Index index = handle.RegisterProperty( "test-property", startValue );
785 DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
787 application.SendNotification();
788 application.Render(0);
789 DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
790 application.Render(0);
791 DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
793 handle.SetProperty( index, 5.0f );
795 application.SendNotification();
796 application.Render(0);
797 DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );
798 application.Render(0);
799 DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );