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 unsignedIntIndex = actor.RegisterProperty( "unsigned-int-property", 456u );
361 Property::Index vector2Index = actor.RegisterProperty( "vector2-property", Vector2(1.0f, 2.0f) );
362 Property::Index vector3Index = actor.RegisterProperty( "vector3-property", Vector3(1.0f, 2.0f, 3.0f) );
363 Property::Index vector4Index = actor.RegisterProperty( "vector4-property", Vector4(1.0f, 2.0f, 3.0f, 4.0f) );
364 Property::Index rotationIndex = actor.RegisterProperty( "rotation-property", 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::UNSIGNED_INTEGER == actor.GetPropertyType( unsignedIntIndex ) );
370 DALI_TEST_CHECK( Property::VECTOR2 == actor.GetPropertyType( vector2Index ) );
371 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( vector3Index ) );
372 DALI_TEST_CHECK( Property::VECTOR4 == actor.GetPropertyType( vector4Index ) );
373 DALI_TEST_CHECK( Property::ROTATION == actor.GetPropertyType( rotationIndex ) );
375 // Non animatable properties
376 Property::Index nonAnimStringIndex = actor.RegisterProperty( "man-from-delmonte", std::string("yes"), Property::READ_WRITE);
377 Property::Index nonAnimV2Index = actor.RegisterProperty( "v2", Vector2(1.f, 2.f), Property::READ_WRITE);
378 Property::Index nonAnimV3Index = actor.RegisterProperty( "v3", Vector3(1.f, 2.f, 3.f), Property::READ_WRITE);
379 Property::Index nonAnimV4Index = actor.RegisterProperty( "v4", Vector4(1.f, 2.f, 3.f, 4.f), Property::READ_WRITE);
380 Property::Index nonAnimBooleanIndex = actor.RegisterProperty( "bool", true, Property::READ_WRITE);
381 Property::Index nonAnimFloatIndex = actor.RegisterProperty( "float", 0.f, Property::READ_WRITE);
382 Property::Index nonAnimIntegerIndex = actor.RegisterProperty( "int", 0, Property::READ_WRITE);
383 Property::Index nonAnimUnsignedIntIndex = actor.RegisterProperty( "unsinged-int", unsingedIntTest, Property::READ_WRITE);
385 DALI_TEST_CHECK( nonAnimStringIndex != Property::INVALID_INDEX );
386 DALI_TEST_CHECK( nonAnimV2Index != Property::INVALID_INDEX );
387 DALI_TEST_CHECK( nonAnimV3Index != Property::INVALID_INDEX );
388 DALI_TEST_CHECK( nonAnimV4Index != Property::INVALID_INDEX );
389 DALI_TEST_CHECK( nonAnimBooleanIndex != Property::INVALID_INDEX );
390 DALI_TEST_CHECK( nonAnimFloatIndex != Property::INVALID_INDEX );
391 DALI_TEST_CHECK( nonAnimIntegerIndex != Property::INVALID_INDEX );
392 DALI_TEST_CHECK( nonAnimUnsignedIntIndex != Property::INVALID_INDEX );
394 DALI_TEST_CHECK( Property::STRING == actor.GetPropertyType( nonAnimStringIndex ) );
395 DALI_TEST_CHECK( Property::VECTOR2 == actor.GetPropertyType( nonAnimV2Index ) );
396 DALI_TEST_CHECK( Property::VECTOR3 == actor.GetPropertyType( nonAnimV3Index ) );
397 DALI_TEST_CHECK( Property::VECTOR4 == actor.GetPropertyType( nonAnimV4Index ) );
398 DALI_TEST_CHECK( Property::BOOLEAN == actor.GetPropertyType( nonAnimBooleanIndex ) );
399 DALI_TEST_CHECK( Property::FLOAT == actor.GetPropertyType( nonAnimFloatIndex ) );
400 DALI_TEST_CHECK( Property::INTEGER == actor.GetPropertyType( nonAnimIntegerIndex ) );
401 DALI_TEST_CHECK( Property::UNSIGNED_INTEGER == actor.GetPropertyType( nonAnimUnsignedIntIndex ) );
403 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimStringIndex ) );
404 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV2Index ) );
405 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV3Index ) );
406 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimV4Index ) );
407 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimBooleanIndex ) );
408 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimFloatIndex ) );
409 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimIntegerIndex ) );
410 DALI_TEST_CHECK( !actor.IsPropertyAnimatable( nonAnimUnsignedIntIndex ) );
412 DALI_TEST_EQUALS( "yes" , actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
413 DALI_TEST_EQUALS( Vector2(1.f, 2.f) , actor.GetProperty( nonAnimV2Index ).Get<Vector2>(), TEST_LOCATION );
414 DALI_TEST_EQUALS( Vector3(1.f, 2.f, 3.f) , actor.GetProperty( nonAnimV3Index ).Get<Vector3>(), TEST_LOCATION );
415 DALI_TEST_EQUALS( Vector4(1.f, 2.f, 3.f, 4.f) , actor.GetProperty( nonAnimV4Index ).Get<Vector4>(), TEST_LOCATION );
416 DALI_TEST_EQUALS( true, actor.GetProperty( nonAnimBooleanIndex ).Get<bool>(), TEST_LOCATION );
417 DALI_TEST_EQUALS( 0.f, actor.GetProperty( nonAnimFloatIndex ).Get<float>(), TEST_LOCATION );
418 DALI_TEST_EQUALS( 0, actor.GetProperty( nonAnimIntegerIndex ).Get<int>(), TEST_LOCATION );
419 DALI_TEST_EQUALS( unsingedIntTest, actor.GetProperty( nonAnimUnsignedIntIndex ).Get<unsigned int>(), TEST_LOCATION );
424 int UtcDaliHandleNonAnimtableProperties(void)
426 tet_infoline("Test Non Animatable Properties");
427 TestApplication application;
429 Actor actor = Actor::New();
431 Property::Index nonAnimStringIndex = actor.RegisterProperty( "man-from-delmonte", std::string("no"), Property::READ_WRITE);
433 //// modify writable?
436 actor.SetProperty( nonAnimStringIndex, Property::Value("yes") );
438 catch (Dali::DaliException& e)
440 DALI_TEST_CHECK(!"exception");
443 DALI_TEST_CHECK( "yes" == actor.GetProperty( nonAnimStringIndex ).Get<std::string>() );
445 //// cannot modify read only?
446 Property::Index readonly = actor.RegisterProperty( "float", 0.f, Property::READ_ONLY);
448 DALI_TEST_CHECK(!actor.IsPropertyAnimatable(readonly));
449 DALI_TEST_CHECK(!actor.IsPropertyWritable(readonly));
451 bool exception = false;
454 actor.SetProperty( readonly, Property::Value(1.f) );
456 catch (Dali::DaliException& e)
461 DALI_TEST_CHECK(!exception);// trying to set a read-only property is a no-op
463 DALI_TEST_EQUALS( 0.f, actor.GetProperty( readonly ).Get<float>(), TEST_LOCATION );
465 /// animatable can be set
466 Property::Index write_anim = actor.RegisterProperty( "write_float", 0.f, Property::ANIMATABLE);
468 DALI_TEST_CHECK(actor.IsPropertyAnimatable(write_anim));
469 DALI_TEST_CHECK(actor.IsPropertyWritable(write_anim));
474 actor.SetProperty( write_anim, Property::Value(1.f) );
476 catch (Dali::DaliException& e)
481 DALI_TEST_CHECK(!exception);
483 //// animate a non animatable property is a noop?
484 float durationSeconds(2.0f);
485 Animation animation = Animation::New(durationSeconds);
486 bool relativeValue(true);
492 animation.AnimateBy(Property(actor, nonAnimStringIndex), relativeValue, AlphaFunctions::EaseIn);
494 application.SendNotification();
495 application.Render(static_cast<unsigned int>(durationSeconds*0100.0f)/* some progress */);
497 catch (Dali::DaliException& e)
502 DALI_TEST_CHECK(!exception);
503 DALI_TEST_EQUALS( "yes", actor.GetProperty( nonAnimStringIndex ).Get<std::string>(), TEST_LOCATION );
508 int UtcDaliHandleNonAnimtableCompositeProperties(void)
510 tet_infoline("Test Non Animatable Composite Properties");
511 TestApplication application;
513 Actor actor = Actor::New();
515 Property::Value value(Property::ARRAY);
516 Property::Array anArray;
517 DALI_TEST_CHECK( Property::Value(anArray).GetType() == Property::ARRAY ); // 2nd constructor
519 value.AppendItem( Property::Value( 0.f ) );
520 value.AppendItem( "a string" );
521 value.SetItem(0, Property::Value( 5.f )); // exercise SetItem
523 int index = value.AppendItem( Vector3(1,2,3) );
525 DALI_TEST_EQUALS( 2, index, TEST_LOCATION);
526 DALI_TEST_EQUALS( 3, value.GetSize(), TEST_LOCATION);
528 Property::Index propertyIndex = actor.RegisterProperty( "composite", value, Property::READ_WRITE);
530 Property::Value out = actor.GetProperty( propertyIndex );
532 DALI_TEST_CHECK( Property::FLOAT == out.GetItem(0).GetType());
533 DALI_TEST_CHECK( Property::STRING == out.GetItem(1).GetType());
534 DALI_TEST_CHECK( Property::VECTOR3 == out.GetItem(2).GetType());
536 DALI_TEST_EQUALS( 5.f, out.GetItem(0).Get<float>(), TEST_LOCATION);
537 DALI_TEST_EQUALS( "a string", out.GetItem(1).Get<std::string>(), TEST_LOCATION);
538 DALI_TEST_EQUALS( Vector3(1,2,3), out.GetItem(2).Get<Vector3>(), TEST_LOCATION);
541 Property::Value valueMap(Property::MAP);
542 Property::Map aKindofMap;
543 DALI_TEST_CHECK( Property::Value(aKindofMap).GetType() == Property::MAP ); // 2nd constructor
545 valueMap.SetValue("key", 5.f);
546 valueMap.SetValue("2key", "a string");
548 DALI_TEST_EQUALS( true, valueMap.HasKey("key"), TEST_LOCATION);
549 DALI_TEST_EQUALS( "key", valueMap.GetKey(0), TEST_LOCATION);
551 DALI_TEST_EQUALS( true, valueMap.HasKey("2key"), TEST_LOCATION);
552 DALI_TEST_EQUALS( "2key", valueMap.GetKey(1), TEST_LOCATION);
554 DALI_TEST_EQUALS( 5.f, valueMap.GetValue("key").Get<float>(), TEST_LOCATION);
555 DALI_TEST_EQUALS( "a string", valueMap.GetValue("2key").Get<std::string>(), TEST_LOCATION);
557 valueMap.SetItem(0, Property::Value("a string"));
558 valueMap.SetItem(1, Property::Value(5.f));
560 DALI_TEST_EQUALS( 5.f, valueMap.GetValue("2key").Get<float>(), TEST_LOCATION);
561 DALI_TEST_EQUALS( "a string", valueMap.GetValue("key").Get<std::string>(), TEST_LOCATION);
564 valueMap = Property::Value(Property::MAP);
566 valueMap.SetValue("key", 5.f);
567 valueMap.SetValue("2key", "a string");
569 DALI_TEST_EQUALS( 5.f, valueMap.GetItem(0).Get<float>(), TEST_LOCATION);
570 DALI_TEST_EQUALS( "a string", valueMap.GetItem(1).Get<std::string>(), TEST_LOCATION);
572 DALI_TEST_EQUALS( 2, valueMap.GetSize(), TEST_LOCATION);
574 // composite types not animatable
575 bool exception = false;
578 /* Property::Index mapPropertyIndex = */ actor.RegisterProperty( "compositemap", value, Property::ANIMATABLE);
580 catch (Dali::DaliException& e)
583 DALI_TEST_PRINT_ASSERT( e );
586 DALI_TEST_EQUALS(exception, true, TEST_LOCATION);
589 Property::Value mapOfMaps(Property::MAP);
591 mapOfMaps.SetValue( "key", Property::Value(Property::MAP) );
592 mapOfMaps.SetValue( "2key", "a string" );
594 DALI_TEST_EQUALS( "a string", mapOfMaps.GetValue("2key").Get<std::string>(), TEST_LOCATION);
596 mapOfMaps.GetValue("key").SetValue("subkey", 5.f);
598 DALI_TEST_EQUALS( true, mapOfMaps.GetValue("key").HasKey("subkey"), TEST_LOCATION);
599 DALI_TEST_EQUALS( 5.f, mapOfMaps.GetValue("key").GetValue("subkey").Get<float>(), TEST_LOCATION);
602 Property::Value listOfMaps(Property::ARRAY);
604 listOfMaps.AppendItem( Property::Value(Property::MAP) );
605 listOfMaps.AppendItem( Property::Value(Property::MAP) );
607 listOfMaps.GetItem(0).SetValue("key", 5.f);
608 listOfMaps.GetItem(1).SetValue("key",10.f);
610 DALI_TEST_EQUALS( 5.f, listOfMaps.GetItem(0).GetValue("key").Get<float>(), TEST_LOCATION );
611 DALI_TEST_EQUALS( 10.f, listOfMaps.GetItem(1).GetValue("key").Get<float>(), TEST_LOCATION );
616 int UtcDaliHandleSetProperty01(void)
618 tet_infoline("Positive Test Dali::Handle::SetProperty()");
619 TestApplication application;
621 Actor actor = Actor::New();
622 DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
624 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
625 // flush the queue and render once
626 application.SendNotification();
627 application.Render();
628 DALI_TEST_CHECK( ParentOrigin::CENTER == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
632 int UtcDaliHandleSetProperty02(void)
634 tet_infoline("Positive Test Dali::Handle::SetProperty()");
635 TestApplication application;
637 Actor actor = Actor::New();
639 DALI_TEST_CHECK( !actor.IsPropertyWritable( Actor::Property::WORLD_POSITION ) );
641 // World position is not writable so this is a no-op and should not crash
642 actor.SetProperty( Actor::Property::WORLD_POSITION, Vector3(1,2,3) );
647 int UtcDaliHandleRegisterProperty(void)
649 tet_infoline("Positive Test Dali::Handle::RegisterProperty()");
650 TestApplication application;
652 Actor actor = Actor::New();
653 DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
658 int UtcDaliHandleGetProperty(void)
660 tet_infoline("Positive Test Dali::Handle::GetProperty()");
661 TestApplication application;
663 Actor actor = Actor::New();
665 DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
666 DALI_TEST_CHECK( AnchorPoint::CENTER == actor.GetProperty( Actor::Property::ANCHOR_POINT ).Get<Vector3>() );
667 DALI_TEST_CHECK( Vector3::ZERO == actor.GetProperty( Actor::Property::SIZE ).Get<Vector3>() );
668 DALI_TEST_CHECK( Vector3::ZERO == actor.GetProperty( Actor::Property::POSITION ).Get<Vector3>() );
669 DALI_TEST_CHECK( Vector3::ONE == actor.GetProperty( Actor::Property::SCALE ).Get<Vector3>() );
670 DALI_TEST_CHECK( true == actor.GetProperty( Actor::Property::VISIBLE ).Get<bool>() );
671 DALI_TEST_CHECK( Color::WHITE == actor.GetProperty( Actor::Property::COLOR ).Get<Vector4>() );
675 int UtcDaliHandleDownCast(void)
677 TestApplication application;
678 tet_infoline("Testing Dali::Handle::DownCast()");
680 Actor actor = Actor::New();
682 BaseHandle baseHandle = actor;
684 Handle handle = Handle::DownCast(baseHandle);
686 DALI_TEST_CHECK( handle );
688 baseHandle = BaseHandle();
690 handle = Handle::DownCast(baseHandle);
692 DALI_TEST_CHECK( !handle );
697 int UtcDaliHandleDownCastNegative(void)
699 TestApplication application;
701 // BaseObject is NOT an Object, so this DownCast should fail
702 BaseHandle handle( new BaseObjectType );
703 Handle customHandle1 = Handle::DownCast( handle );
704 DALI_TEST_CHECK( ! customHandle1 );
706 // A DownCast on an empty handle will also fail
708 Handle customHandle2 = Handle::DownCast( empty );
709 DALI_TEST_CHECK( ! customHandle2 );
713 int UtcDaliHandleGetPropertyIndices(void)
715 TestApplication application;
716 Property::IndexContainer indices;
719 Actor actor = Actor::New();
720 actor.GetPropertyIndices( indices );
721 DALI_TEST_CHECK( ! indices.empty() );
722 DALI_TEST_EQUALS( indices.size(), actor.GetPropertyCount(), TEST_LOCATION );
726 int UtcDaliHandleRegisterPropertyTypes(void)
728 TestApplication application;
730 struct PropertyTypeAnimatable
733 Property::Value value;
737 Property::Array array;
740 PropertyTypeAnimatable properties[] =
742 { "Property::BOOLEAN", true, true },
743 { "Property::FLOAT", 1.0f, true },
744 { "Property::INTEGER", 1, true },
745 { "Property::UNSIGNED_INTEGER", 1u, true },
746 { "Property::VECTOR2", Vector2::ONE, true },
747 { "Property::VECTOR3", Vector3::ONE, true },
748 { "Property::VECTOR4", Vector4::ONE, true },
749 { "Property::MATRIX3", Matrix3::IDENTITY, true },
750 { "Property::MATRIX", Matrix::IDENTITY, true },
751 { "Property::RECTANGLE", Rect<int>(), false },
752 { "Property::ROTATION", AngleAxis(), true },
753 { "Property::STRING", std::string("Me"), false },
754 { "Property::ARRAY", array, false },
755 { "Property::MAP", map, false },
758 unsigned int numOfProperties( sizeof( properties ) / sizeof( properties[0] ) );
760 for ( unsigned int i = 0; i < numOfProperties; ++i )
762 tet_printf( "Testing: %s\n", properties[i].name );
764 bool exception = false;
767 Actor actor = Actor::New();
768 actor.RegisterProperty( "man-from-delmonte", properties[i].value );
770 catch (Dali::DaliException& e)
775 DALI_TEST_CHECK( properties[i].animatable != exception );
780 int UtcDaliHandleCustomProperty(void)
782 TestApplication application;
784 Handle handle = Handle::New();
786 float startValue(1.0f);
787 Property::Index index = handle.RegisterProperty( "test-property", startValue );
788 DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
790 application.SendNotification();
791 application.Render(0);
792 DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
793 application.Render(0);
794 DALI_TEST_CHECK( handle.GetProperty<float>(index) == startValue );
796 handle.SetProperty( index, 5.0f );
798 application.SendNotification();
799 application.Render(0);
800 DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );
801 application.Render(0);
802 DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );