2 * Copyright (c) 2020 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.
20 #include <dali/public-api/dali-core.h>
22 #include <dali/devel-api/actors/custom-actor-devel.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali/integration-api/events/hover-event-integ.h>
25 #include <dali/integration-api/events/wheel-event-integ.h>
26 #include <dali/integration-api/events/key-event-integ.h>
27 #include <dali/public-api/object/type-registry-helper.h>
28 #include "dali-test-suite-utils/dali-test-suite-utils.h"
29 #include "test-custom-actor.h"
34 void custom_actor_test_startup(void)
36 test_return_value = TET_UNDEF;
39 void custom_actor_test_cleanup(void)
41 test_return_value = TET_PASS;
49 int UtcDaliCustomActorDestructor(void)
51 TestApplication application;
53 CustomActor* actor = new CustomActor();
56 DALI_TEST_CHECK( true );
60 int UtcDaliCustomActorImplDestructor(void)
62 TestApplication application;
63 CustomActorImpl* actor = new Test::Impl::TestCustomActor();
64 CustomActor customActor( *actor ); // Will automatically unref at the end of this function
66 DALI_TEST_CHECK( true );
70 // Positive test case for a method
71 int UtcDaliCustomActorDownCast(void)
73 TestApplication application;
74 tet_infoline("Testing Dali::CustomActor::DownCast()");
76 Test::TestCustomActor custom = Test::TestCustomActor::New();
78 Actor anActor = Actor::New();
79 anActor.Add( custom );
81 Actor child = anActor.GetChildAt(0);
82 CustomActor customActor = CustomActor::DownCast( child );
83 DALI_TEST_CHECK( customActor );
86 DALI_TEST_CHECK( !customActor );
88 customActor = DownCast< CustomActor >( child );
89 DALI_TEST_CHECK( customActor );
93 // Negative test case for a method
94 int UtcDaliCustomActorDownCastNegative(void)
96 TestApplication application;
97 tet_infoline("Testing Dali::CustomActor::DownCast()");
99 Actor actor1 = Actor::New();
100 Actor anActor = Actor::New();
103 Actor child = anActor.GetChildAt(0);
104 CustomActor customActor = CustomActor::DownCast( child );
105 DALI_TEST_CHECK( !customActor );
107 Actor unInitialzedActor;
108 customActor = CustomActor::DownCast( unInitialzedActor );
109 DALI_TEST_CHECK( !customActor );
111 customActor = DownCast< CustomActor >( unInitialzedActor );
112 DALI_TEST_CHECK( !customActor );
116 int UtcDaliCustomActorMoveConstructor(void)
118 TestApplication application;
120 Test::TestCustomActor custom = Test::TestCustomActor::New();
121 DALI_TEST_CHECK( custom );
122 DALI_TEST_EQUALS( 1, custom.GetBaseObject().ReferenceCount(), TEST_LOCATION );
124 int id = custom.GetProperty< int >( Actor::Property::ID );
126 Test::TestCustomActor moved = std::move( custom );
127 DALI_TEST_CHECK( moved );
128 DALI_TEST_EQUALS( id, moved.GetProperty< int >( Actor::Property::ID ), TEST_LOCATION );
129 DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
130 DALI_TEST_CHECK( !custom );
135 int UtcDaliCustomActorMoveAssignment(void)
137 TestApplication application;
139 Test::TestCustomActor custom = Test::TestCustomActor::New();
140 DALI_TEST_CHECK( custom );
141 DALI_TEST_EQUALS( 1, custom.GetBaseObject().ReferenceCount(), TEST_LOCATION );
143 int id = custom.GetProperty< int >( Actor::Property::ID );
145 Test::TestCustomActor moved;
146 moved = std::move( custom );
147 DALI_TEST_CHECK( moved );
148 DALI_TEST_EQUALS( id, moved.GetProperty< int >( Actor::Property::ID ), TEST_LOCATION );
149 DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
150 DALI_TEST_CHECK( !custom );
155 int UtcDaliCustomActorOnSceneConnectionDisconnection(void)
157 TestApplication application;
158 tet_infoline("Testing Dali::CustomActor::OnSceneConnection() & OnSceneDisconnection");
160 Test::TestCustomActor custom = Test::TestCustomActor::New();
161 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
163 // add the custom actor to stage
164 application.GetScene().Add( custom );
166 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
167 DALI_TEST_EQUALS( "OnSceneConnection", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
169 application.GetScene().Remove( custom );
171 DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
172 DALI_TEST_EQUALS( "OnSceneDisconnection", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
174 // Excercise the message passing to Update thread
176 application.SendNotification();
177 application.Render();
178 application.Render();
182 int UtcDaliCustomActorOnSceneConnectionOrder(void)
184 TestApplication application;
185 tet_infoline("Testing Dali::CustomActor::OnSceneConnection() order");
187 MasterCallStack.clear();
189 /* Build tree of actors:
197 * OnSceneConnection should be received for A, B, D, E, C, and finally F
200 Test::TestCustomActor actorA = Test::TestCustomActor::New();
201 actorA.SetProperty( Actor::Property::NAME, "ActorA" );
203 Test::TestCustomActor actorB = Test::TestCustomActor::New();
204 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
205 actorA.Add( actorB );
207 Test::TestCustomActor actorC = Test::TestCustomActor::New();
208 actorC.SetProperty( Actor::Property::NAME, "ActorC" );
209 actorA.Add( actorC );
211 Test::TestCustomActor actorD = Test::TestCustomActor::New();
212 actorD.SetProperty( Actor::Property::NAME, "ActorD" );
213 actorB.Add( actorD );
215 Test::TestCustomActor actorE = Test::TestCustomActor::New();
216 actorE.SetProperty( Actor::Property::NAME, "ActorE" );
217 actorB.Add( actorE );
219 Test::TestCustomActor actorF = Test::TestCustomActor::New();
220 actorF.SetProperty( Actor::Property::NAME, "ActorF" );
221 actorC.Add( actorF );
223 // add the custom actor to stage
224 application.GetScene().Add( actorA );
226 DALI_TEST_EQUALS( 4, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
227 DALI_TEST_EQUALS( "OnPropertySet", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
228 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
229 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
230 DALI_TEST_EQUALS( "OnSceneConnection", actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION );
232 DALI_TEST_EQUALS( 4, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
233 DALI_TEST_EQUALS( "OnPropertySet", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
234 DALI_TEST_EQUALS( "OnChildAdd", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
235 DALI_TEST_EQUALS( "OnChildAdd", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
236 DALI_TEST_EQUALS( "OnSceneConnection", actorB.GetMethodsCalled()[ 3 ], TEST_LOCATION );
238 DALI_TEST_EQUALS( 3, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
239 DALI_TEST_EQUALS( "OnPropertySet", actorC.GetMethodsCalled()[ 0 ], TEST_LOCATION );
240 DALI_TEST_EQUALS( "OnChildAdd", actorC.GetMethodsCalled()[ 1 ], TEST_LOCATION );
241 DALI_TEST_EQUALS( "OnSceneConnection", actorC.GetMethodsCalled()[ 2 ], TEST_LOCATION );
243 DALI_TEST_EQUALS( 2, (int)(actorD.GetMethodsCalled().size()), TEST_LOCATION );
244 DALI_TEST_EQUALS( "OnPropertySet", actorD.GetMethodsCalled()[ 0 ], TEST_LOCATION );
245 DALI_TEST_EQUALS( "OnSceneConnection", actorD.GetMethodsCalled()[ 1 ], TEST_LOCATION );
247 DALI_TEST_EQUALS( 2, (int)(actorE.GetMethodsCalled().size()), TEST_LOCATION );
248 DALI_TEST_EQUALS( "OnPropertySet", actorE.GetMethodsCalled()[ 0 ], TEST_LOCATION );
249 DALI_TEST_EQUALS( "OnSceneConnection", actorE.GetMethodsCalled()[ 1 ], TEST_LOCATION );
251 DALI_TEST_EQUALS( 2, (int)(actorF.GetMethodsCalled().size()), TEST_LOCATION );
252 DALI_TEST_EQUALS( "OnPropertySet", actorF.GetMethodsCalled()[ 0 ], TEST_LOCATION );
253 DALI_TEST_EQUALS( "OnSceneConnection", actorF.GetMethodsCalled()[ 1 ], TEST_LOCATION );
255 // Check sequence is correct in MasterCallStack
257 DALI_TEST_EQUALS( 4+4+3+2+2+2, (int)(MasterCallStack.size()), TEST_LOCATION );
259 DALI_TEST_EQUALS( "ActorA: OnPropertySet", MasterCallStack[ 0 ], TEST_LOCATION );
260 DALI_TEST_EQUALS( "ActorB: OnPropertySet", MasterCallStack[ 1 ], TEST_LOCATION );
261 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION );
262 DALI_TEST_EQUALS( "ActorC: OnPropertySet", MasterCallStack[ 3 ], TEST_LOCATION );
263 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION );
264 DALI_TEST_EQUALS( "ActorD: OnPropertySet", MasterCallStack[ 5 ], TEST_LOCATION );
266 DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 6 ], TEST_LOCATION );
267 DALI_TEST_EQUALS( "ActorE: OnPropertySet", MasterCallStack[ 7 ], TEST_LOCATION );
268 DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 8 ], TEST_LOCATION );
269 DALI_TEST_EQUALS( "ActorF: OnPropertySet", MasterCallStack[ 9 ], TEST_LOCATION );
270 DALI_TEST_EQUALS( "ActorC: OnChildAdd", MasterCallStack[ 10 ], TEST_LOCATION );
272 DALI_TEST_EQUALS( "ActorA: OnSceneConnection", MasterCallStack[ 11 ], TEST_LOCATION );
273 DALI_TEST_EQUALS( "ActorB: OnSceneConnection", MasterCallStack[ 12 ], TEST_LOCATION );
274 DALI_TEST_EQUALS( "ActorD: OnSceneConnection", MasterCallStack[ 13 ], TEST_LOCATION );
275 DALI_TEST_EQUALS( "ActorE: OnSceneConnection", MasterCallStack[ 14 ], TEST_LOCATION );
276 DALI_TEST_EQUALS( "ActorC: OnSceneConnection", MasterCallStack[ 15 ], TEST_LOCATION );
277 DALI_TEST_EQUALS( "ActorF: OnSceneConnection", MasterCallStack[ 16 ], TEST_LOCATION );
279 // Excercise the message passing to Update thread
281 application.SendNotification();
282 application.Render();
283 application.Render();
287 int UtcDaliCustomActorOnSceneDisconnectionOrder(void)
289 TestApplication application;
290 tet_infoline("Testing Dali::CustomActor::OnSceneDisconnection() order");
292 Integration::Scene stage = application.GetScene();
294 /* Build tree of actors:
302 * OnSceneDisconnection should be received for D, E, B, F, C, and finally A.
305 Test::TestCustomActor actorA = Test::TestCustomActor::New();
306 actorA.SetProperty( Actor::Property::NAME, "ActorA" );
309 Test::TestCustomActor actorB = Test::TestCustomActor::New();
310 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
311 actorA.Add( actorB );
313 Test::TestCustomActor actorC = Test::TestCustomActor::New();
314 actorC.SetProperty( Actor::Property::NAME, "ActorC" );
315 actorA.Add( actorC );
317 Test::TestCustomActor actorD = Test::TestCustomActor::New();
318 actorD.SetProperty( Actor::Property::NAME, "ActorD" );
319 actorB.Add( actorD );
321 Test::TestCustomActor actorE = Test::TestCustomActor::New();
322 actorE.SetProperty( Actor::Property::NAME, "ActorE" );
323 actorB.Add( actorE );
325 Test::TestCustomActor actorF = Test::TestCustomActor::New();
326 actorF.SetProperty( Actor::Property::NAME, "ActorF" );
327 actorC.Add( actorF );
329 // Excercise the message passing to Update thread
331 application.SendNotification();
332 application.Render();
333 application.Render();
335 // Clear call stacks before disconnection
336 actorA.ResetCallStack();
337 actorB.ResetCallStack();
338 actorC.ResetCallStack();
339 actorD.ResetCallStack();
340 actorE.ResetCallStack();
341 actorF.ResetCallStack();
342 MasterCallStack.clear();
344 stage.Remove( actorA );
346 DALI_TEST_EQUALS( 1, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
347 DALI_TEST_EQUALS( "OnSceneDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
349 DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
350 DALI_TEST_EQUALS( "OnSceneDisconnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
352 DALI_TEST_EQUALS( 1, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
353 DALI_TEST_EQUALS( "OnSceneDisconnection", actorC.GetMethodsCalled()[ 0 ], TEST_LOCATION );
355 DALI_TEST_EQUALS( 1, (int)(actorD.GetMethodsCalled().size()), TEST_LOCATION );
356 DALI_TEST_EQUALS( "OnSceneDisconnection", actorD.GetMethodsCalled()[ 0 ], TEST_LOCATION );
358 DALI_TEST_EQUALS( 1, (int)(actorE.GetMethodsCalled().size()), TEST_LOCATION );
359 DALI_TEST_EQUALS( "OnSceneDisconnection", actorE.GetMethodsCalled()[ 0 ], TEST_LOCATION );
361 DALI_TEST_EQUALS( 1, (int)(actorF.GetMethodsCalled().size()), TEST_LOCATION );
362 DALI_TEST_EQUALS( "OnSceneDisconnection", actorF.GetMethodsCalled()[ 0 ], TEST_LOCATION );
364 // Check sequence is correct in MasterCallStack
366 DALI_TEST_EQUALS( 6, (int)(MasterCallStack.size()), TEST_LOCATION );
368 DALI_TEST_EQUALS( "ActorD: OnSceneDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
369 DALI_TEST_EQUALS( "ActorE: OnSceneDisconnection", MasterCallStack[ 1 ], TEST_LOCATION );
370 DALI_TEST_EQUALS( "ActorB: OnSceneDisconnection", MasterCallStack[ 2 ], TEST_LOCATION );
371 DALI_TEST_EQUALS( "ActorF: OnSceneDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
372 DALI_TEST_EQUALS( "ActorC: OnSceneDisconnection", MasterCallStack[ 4 ], TEST_LOCATION );
373 DALI_TEST_EQUALS( "ActorA: OnSceneDisconnection", MasterCallStack[ 5 ], TEST_LOCATION );
375 // Excercise the message passing to Update thread
377 application.SendNotification();
378 application.Render();
379 application.Render();
383 int UtcDaliCustomActorAddDuringOnSceneConnection(void)
385 TestApplication application;
386 tet_infoline("Testing Actor::Add behaviour during Dali::CustomActor::OnSceneConnection() callback");
388 Integration::Scene stage = application.GetScene();
390 MasterCallStack.clear();
392 /* The actorA is a special variant which adds a child to itself during OnSceneConnection()
393 * The actorB is provided as the child
396 Test::TestCustomActor actorB = Test::TestCustomActor::New();
397 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
399 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant1( actorB );
400 actorA.SetProperty( Actor::Property::NAME, "ActorA" );
403 // Check callback sequence
405 DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
406 DALI_TEST_EQUALS( "OnPropertySet", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
407 DALI_TEST_EQUALS( "OnSceneConnection", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
408 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION ); // Called from within OnSceneConnection()
410 DALI_TEST_EQUALS( 2, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
411 DALI_TEST_EQUALS( "OnPropertySet", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
412 DALI_TEST_EQUALS( "OnSceneConnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
414 DALI_TEST_EQUALS( 5, (int)(MasterCallStack.size()), TEST_LOCATION );
416 DALI_TEST_EQUALS( "ActorB: OnPropertySet", MasterCallStack[ 0 ], TEST_LOCATION );
417 DALI_TEST_EQUALS( "ActorA: OnPropertySet", MasterCallStack[ 1 ], TEST_LOCATION );
418 DALI_TEST_EQUALS( "ActorA: OnSceneConnection", MasterCallStack[ 2 ], TEST_LOCATION );
419 DALI_TEST_EQUALS( "ActorB: OnSceneConnection", MasterCallStack[ 3 ], TEST_LOCATION ); // Occurs during Actor::Add from within from within OnSceneConnection()
420 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION ); // Occurs after Actor::Add from within from within OnSceneConnection()
422 // Excercise the message passing to Update thread
424 application.SendNotification();
425 application.Render();
426 application.Render();
428 // Check everything is ok after Actors are removed
430 stage.Remove( actorA );
431 application.SendNotification();
432 application.Render();
433 application.Render();
437 int UtcDaliCustomActorRemoveDuringOnSceneConnection(void)
439 TestApplication application;
440 tet_infoline("Testing Actor::Remove behaviour during Dali::CustomActor::OnSceneConnection() callback");
442 Integration::Scene stage = application.GetScene();
444 MasterCallStack.clear();
446 /* The actorA is a special variant which removes its children during OnSceneConnection()
447 * Actors B & C are provided as the children
450 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant2();
451 actorA.SetProperty( Actor::Property::NAME, "ActorA" );
453 Test::TestCustomActor actorB = Test::TestCustomActor::New();
454 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
455 actorA.Add( actorB );
457 Test::TestCustomActor actorC = Test::TestCustomActor::New();
458 actorC.SetProperty( Actor::Property::NAME, "ActorC" );
459 actorA.Add( actorC );
463 // Check callback sequence
465 DALI_TEST_EQUALS( 6, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
466 DALI_TEST_EQUALS( "OnPropertySet", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
467 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
468 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
469 DALI_TEST_EQUALS( "OnSceneConnection", actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION );
470 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 4 ], TEST_LOCATION ); // Called from within OnSceneConnection()
471 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 5 ], TEST_LOCATION ); // Called from within OnSceneConnection()
473 DALI_TEST_EQUALS( 8, (int)(MasterCallStack.size()), TEST_LOCATION );
475 DALI_TEST_EQUALS( "ActorA: OnPropertySet", MasterCallStack[ 0 ], TEST_LOCATION );
476 DALI_TEST_EQUALS( "ActorB: OnPropertySet", MasterCallStack[ 1 ], TEST_LOCATION );
477 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION );
478 DALI_TEST_EQUALS( "ActorC: OnPropertySet", MasterCallStack[ 3 ], TEST_LOCATION );
479 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION );
480 DALI_TEST_EQUALS( "ActorA: OnSceneConnection", MasterCallStack[ 5 ], TEST_LOCATION );
481 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 6 ], TEST_LOCATION );
482 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 7 ], TEST_LOCATION );
484 /* Actors B & C should be removed before the point where they could receive an OnSceneConnection callback
485 * Therefore they shouldn't receive either OnSceneConnection or OnSceneDisconnection
487 DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
488 DALI_TEST_EQUALS( 1, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
490 // Excercise the message passing to Update thread
492 application.SendNotification();
493 application.Render();
494 application.Render();
496 // Check everything is ok after last actor is removed
498 stage.Remove( actorA );
499 application.SendNotification();
500 application.Render();
501 application.Render();
505 int UtcDaliCustomActorAddDuringOnSceneDisconnection(void)
507 TestApplication application;
508 tet_infoline("Testing Actor::Add behaviour during Dali::CustomActor::OnSceneDisonnection() callback");
510 Integration::Scene stage = application.GetScene();
512 /* The actorA is a special variant which adds a child to itself during OnSceneDisconnection()
513 * The actorB is provided as the child
516 Test::TestCustomActor actorB = Test::TestCustomActor::New();
517 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
519 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant3( actorB );
520 actorA.SetProperty( Actor::Property::NAME, "ActorA" );
523 // Excercise the message passing to Update thread
525 application.SendNotification();
526 application.Render();
527 application.Render();
529 // Clear call stacks before disconnection
530 actorA.ResetCallStack();
531 actorB.ResetCallStack();
532 MasterCallStack.clear();
534 stage.Remove( actorA );
536 // Check callback sequence
538 DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
539 DALI_TEST_EQUALS( "OnSceneDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
540 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
542 // Child was added after parent disconnection, so should not receive OnSceneConnection()
543 DALI_TEST_EQUALS( 0, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
545 DALI_TEST_EQUALS( 2, (int)(MasterCallStack.size()), TEST_LOCATION );
547 DALI_TEST_EQUALS( "ActorA: OnSceneDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
548 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 1 ], TEST_LOCATION );
550 // Excercise the message passing to Update thread
552 application.SendNotification();
553 application.Render();
554 application.Render();
558 int UtcDaliCustomActorRemoveDuringOnSceneDisconnection(void)
560 TestApplication application;
561 tet_infoline("Testing Actor::Remove behaviour during Dali::CustomActor::OnSceneDisconnection() callback");
563 Integration::Scene stage = application.GetScene();
565 /* The actorA is a special variant which removes its children during OnSceneDisconnection()
566 * The actorB is provided as the child
569 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant4();
570 actorA.SetProperty( Actor::Property::NAME, "ActorA" );
573 Test::TestCustomActor actorB = Test::TestCustomActor::New();
574 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
575 actorA.Add( actorB );
577 // Excercise the message passing to Update thread
579 application.SendNotification();
580 application.Render();
581 application.Render();
583 // Clear call stacks before disconnection
584 actorA.ResetCallStack();
585 actorB.ResetCallStack();
586 MasterCallStack.clear();
588 stage.Remove( actorA );
590 // Check callback sequence
592 DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
593 DALI_TEST_EQUALS( "OnSceneDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
594 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
596 DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
597 DALI_TEST_EQUALS( "OnSceneDisconnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
599 DALI_TEST_EQUALS( 3, (int)(MasterCallStack.size()), TEST_LOCATION );
601 DALI_TEST_EQUALS( "ActorB: OnSceneDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
602 DALI_TEST_EQUALS( "ActorA: OnSceneDisconnection", MasterCallStack[ 1 ], TEST_LOCATION );
603 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 2 ], TEST_LOCATION );
605 // Excercise the message passing to Update thread
607 application.SendNotification();
608 application.Render();
609 application.Render();
613 int UtcDaliCustomActorRemoveParentDuringOnSceneConnection(void)
615 TestApplication application;
616 tet_infoline("Weird test where child removes its own parent from Stage during Dali::CustomActor::OnSceneConnection() callback");
618 Integration::Scene scene = application.GetScene();
620 MasterCallStack.clear();
622 /* The actorA is the parent of actorB
623 * The actorB is a special variant which removes its own parent during OnSceneConnection()
624 * The child actor is interrupting the parent's connection to stage, therefore the parent should not get an OnSceneDisconnection()
627 Test::TestCustomActor actorA = Test::TestCustomActor::New();
628 actorA.SetProperty( Actor::Property::NAME, "ActorA" );
630 Test::TestCustomActor actorB = Test::TestCustomActor::NewVariant5(scene);
631 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
632 actorA.Add( actorB );
636 // Check callback sequence
638 DALI_TEST_EQUALS( 4, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
639 DALI_TEST_EQUALS( "OnPropertySet", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
640 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
641 DALI_TEST_EQUALS( "OnSceneConnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
642 DALI_TEST_EQUALS( "OnSceneDisconnection", actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION );
644 DALI_TEST_EQUALS( 2, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
645 DALI_TEST_EQUALS( "OnPropertySet", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
646 DALI_TEST_EQUALS( "OnSceneConnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
648 DALI_TEST_EQUALS( 6, (int)(MasterCallStack.size()), TEST_LOCATION );
650 DALI_TEST_EQUALS( "ActorA: OnPropertySet", MasterCallStack[ 0 ], TEST_LOCATION );
651 DALI_TEST_EQUALS( "ActorB: OnPropertySet", MasterCallStack[ 1 ], TEST_LOCATION );
652 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION );
653 DALI_TEST_EQUALS( "ActorA: OnSceneConnection", MasterCallStack[ 3 ], TEST_LOCATION );
654 DALI_TEST_EQUALS( "ActorB: OnSceneConnection", MasterCallStack[ 4 ], TEST_LOCATION );
655 DALI_TEST_EQUALS( "ActorA: OnSceneDisconnection", MasterCallStack[ 5 ], TEST_LOCATION );
657 // Excercise the message passing to Update thread
659 application.SendNotification();
660 application.Render();
661 application.Render();
665 int UtcDaliCustomActorAddParentDuringOnSceneDisconnection(void)
667 TestApplication application;
668 tet_infoline("Weird test where child adds its own parent to Stage during Dali::CustomActor::OnSceneDisconnection() callback");
670 Integration::Scene scene = application.GetScene();
672 MasterCallStack.clear();
674 /* The actorA is the parent of actorB
675 * The actorB is a special variant which (weirdly) adds its own parent during OnSceneDisconnection()
676 * The child actor is interrupting the disconnection, such that parent should not get a OnSceneDisconnection()
679 Test::TestCustomActor actorA = Test::TestCustomActor::New();
680 actorA.SetProperty( Actor::Property::NAME, "ActorA" );
683 Test::TestCustomActor actorB = Test::TestCustomActor::NewVariant6(scene);
684 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
685 actorA.Add( actorB );
687 scene.Remove( actorA );
689 // Check callback sequence
691 DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
692 DALI_TEST_EQUALS( "OnPropertySet", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
693 DALI_TEST_EQUALS( "OnSceneConnection", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
694 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
696 DALI_TEST_EQUALS( 3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
697 DALI_TEST_EQUALS( "OnPropertySet", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
698 DALI_TEST_EQUALS( "OnSceneConnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
699 DALI_TEST_EQUALS( "OnSceneDisconnection", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
700 // Disconnect was interrupted, so we should only get one OnSceneConnection() for actorB
702 DALI_TEST_EQUALS( 6, (int)(MasterCallStack.size()), TEST_LOCATION );
704 DALI_TEST_EQUALS( "ActorA: OnPropertySet", MasterCallStack[ 0 ], TEST_LOCATION );
705 DALI_TEST_EQUALS( "ActorA: OnSceneConnection", MasterCallStack[ 1 ], TEST_LOCATION );
706 DALI_TEST_EQUALS( "ActorB: OnPropertySet", MasterCallStack[ 2 ], TEST_LOCATION );
707 DALI_TEST_EQUALS( "ActorB: OnSceneConnection", MasterCallStack[ 3 ], TEST_LOCATION );
708 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION );
709 DALI_TEST_EQUALS( "ActorB: OnSceneDisconnection", MasterCallStack[ 5 ], TEST_LOCATION );
711 // Excercise the message passing to Update thread
713 application.SendNotification();
714 application.Render();
715 application.Render();
719 int UtcDaliCustomActorOnChildAddRemove(void)
721 TestApplication application;
722 tet_infoline("Testing Dali::CustomActor::OnChildAdd() & OnChildRemove()");
724 Test::TestCustomActor custom = Test::TestCustomActor::New();
725 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
727 Actor aChild = Actor::New();
728 custom.Add( aChild );
730 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
731 DALI_TEST_EQUALS( "OnChildAdd", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
733 custom.Remove( aChild );
735 DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
736 DALI_TEST_EQUALS( "OnChildRemove", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
740 int UtcDaliCustomActorReparentDuringOnChildAdd(void)
742 TestApplication application;
743 tet_infoline("Testing Actor:Add (reparenting) behaviour during Dali::CustomActor::OnChildAdd() callback");
745 Integration::Scene stage = application.GetScene();
747 MasterCallStack.clear();
749 /* The actorA is a special variant which reparents children added into a separate container child
750 * The actorB is the child of actorA
753 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant7( "ActorA" );
756 Test::TestCustomActor actorB = Test::TestCustomActor::New();
757 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
758 actorA.Add( actorB );
760 // Check hierarchy is as follows:
767 DALI_TEST_EQUALS( 1, (int)(actorA.GetChildCount()), TEST_LOCATION );
769 Actor container = actorA.GetChildAt(0);
770 Actor containerChild;
772 DALI_TEST_CHECK( container );
775 DALI_TEST_EQUALS( "Container", container.GetProperty< std::string >( Actor::Property::NAME ), TEST_LOCATION );
776 DALI_TEST_EQUALS( 1, (int)(container.GetChildCount()), TEST_LOCATION );
777 containerChild = container.GetChildAt(0);
780 DALI_TEST_CHECK( containerChild );
781 if ( containerChild )
783 DALI_TEST_EQUALS( "ActorB", containerChild.GetProperty< std::string >( Actor::Property::NAME ), TEST_LOCATION );
784 DALI_TEST_EQUALS( 0, (int)(containerChild.GetChildCount()), TEST_LOCATION );
787 // Check callback sequence
789 DALI_TEST_EQUALS( 5, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
790 DALI_TEST_EQUALS( "OnPropertySet", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
791 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION ); // The mContainer added to actorA
792 DALI_TEST_EQUALS( "OnSceneConnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
793 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION ); // The actorB added to actorA
794 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 4 ], TEST_LOCATION );
795 // mContainer will then receive OnChildAdd
797 DALI_TEST_EQUALS( 4, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
798 DALI_TEST_EQUALS( "OnPropertySet", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
799 DALI_TEST_EQUALS( "OnSceneConnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
800 DALI_TEST_EQUALS( "OnSceneDisconnection", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
801 DALI_TEST_EQUALS( "OnSceneConnection", actorB.GetMethodsCalled()[ 3 ], TEST_LOCATION );
803 DALI_TEST_EQUALS( 9, (int)(MasterCallStack.size()), TEST_LOCATION );
805 DALI_TEST_EQUALS( "ActorA: OnPropertySet", MasterCallStack[ 0 ], TEST_LOCATION );
806 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 1 ], TEST_LOCATION );
807 DALI_TEST_EQUALS( "ActorA: OnSceneConnection", MasterCallStack[ 2 ], TEST_LOCATION );
808 DALI_TEST_EQUALS( "ActorB: OnPropertySet", MasterCallStack[ 3 ], TEST_LOCATION );
809 DALI_TEST_EQUALS( "ActorB: OnSceneConnection", MasterCallStack[ 4 ], TEST_LOCATION );
810 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 5 ], TEST_LOCATION );
811 DALI_TEST_EQUALS( "ActorB: OnSceneDisconnection", MasterCallStack[ 6 ], TEST_LOCATION );
812 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 7 ], TEST_LOCATION );
813 DALI_TEST_EQUALS( "ActorB: OnSceneConnection", MasterCallStack[ 8 ], TEST_LOCATION );
815 // Excercise the message passing to Update thread
817 application.SendNotification();
818 application.Render();
819 application.Render();
824 * Test that Remove can be called (a NOOP) during the OnChildRemove
825 * triggered when reparenting an actor
827 int UtcDaliCustomActorRemoveDuringOnChildRemove(void)
829 TestApplication application;
830 tet_infoline("Testing Actor:Remove behaviour during OnChildRemove() callback triggered when reparenting");
832 Integration::Scene stage = application.GetScene();
834 MasterCallStack.clear();
836 /* The childActor will be reparented from actorA to actorB
837 * The actorA is a special variant which attempts to remove a child from actorB, during the OnChildRemove callback()
838 * This should be a NOOP since the reparenting has not occured yet
841 Test::TestCustomActor actorB = Test::TestCustomActor::New();
842 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
845 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant8( actorB );
846 actorA.SetProperty( Actor::Property::NAME, "ActorA" );
849 Actor childActor = Actor::New();
850 childActor.SetProperty( Actor::Property::NAME, "Child" );
851 // Reparent from actorA to actorB
852 actorA.Add( childActor );
853 actorB.Add( childActor );
855 // Check hierarchy is as follows:
860 DALI_TEST_EQUALS( 0, (int)(actorA.GetChildCount()), TEST_LOCATION );
861 DALI_TEST_EQUALS( 1, (int)(actorB.GetChildCount()), TEST_LOCATION );
862 DALI_TEST_EQUALS( 0, (int)(childActor.GetChildCount()), TEST_LOCATION );
864 Actor child = actorB.GetChildAt(0);
866 DALI_TEST_CHECK( child );
869 DALI_TEST_EQUALS( "Child", child.GetProperty< std::string >( Actor::Property::NAME ), TEST_LOCATION );
872 // Check callback sequence
874 DALI_TEST_EQUALS( 4, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
875 DALI_TEST_EQUALS( "OnPropertySet", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
876 DALI_TEST_EQUALS( "OnSceneConnection", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION ); // The mContainer added to actorA
877 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
878 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION ); // The actorB added to actorA
879 // mContainer will then receive OnChildAdd
881 DALI_TEST_EQUALS( 4, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
882 DALI_TEST_EQUALS( "OnPropertySet", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
883 DALI_TEST_EQUALS( "OnSceneConnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
884 // The derived class are always notified, no matter the child is successfully removed or not
885 DALI_TEST_EQUALS( "OnChildRemove", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
886 DALI_TEST_EQUALS( "OnChildAdd", actorB.GetMethodsCalled()[ 3 ], TEST_LOCATION );
888 DALI_TEST_EQUALS( 8, (int)(MasterCallStack.size()), TEST_LOCATION );
890 DALI_TEST_EQUALS( "ActorB: OnPropertySet", MasterCallStack[ 0 ], TEST_LOCATION );
891 DALI_TEST_EQUALS( "ActorB: OnSceneConnection", MasterCallStack[ 1 ], TEST_LOCATION );
892 DALI_TEST_EQUALS( "ActorA: OnPropertySet", MasterCallStack[ 2 ], TEST_LOCATION );
893 DALI_TEST_EQUALS( "ActorA: OnSceneConnection", MasterCallStack[ 3 ], TEST_LOCATION );
894 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION );
895 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 5 ], TEST_LOCATION );
896 // The derived class are always notified, no matter the child is successfully removed or not
897 DALI_TEST_EQUALS( "ActorB: OnChildRemove", MasterCallStack[ 6 ], TEST_LOCATION );
898 DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 7 ], TEST_LOCATION );
900 // Excercise the message passing to Update thread
902 application.SendNotification();
903 application.Render();
904 application.Render();
908 int UtcDaliCustomActorOnPropertySet(void)
910 TestApplication application;
911 tet_infoline("Testing Dali::CustomActor::OnPropertySet()");
913 Test::TestCustomActor custom = Test::TestCustomActor::New();
914 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
916 custom.SetDaliProperty("yes");
918 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
919 DALI_TEST_EQUALS( "OnPropertySet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
923 int UtcDaliCustomActorOnSizeSet(void)
925 TestApplication application;
926 tet_infoline("Testing Dali::CustomActor::OnSizeSet()");
928 Test::TestCustomActor custom = Test::TestCustomActor::New();
929 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
931 custom.SetProperty( Actor::Property::SIZE, Vector2( 9.0f, 10.0f ) );
932 DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
933 DALI_TEST_EQUALS( "OnSizeSet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
934 DALI_TEST_EQUALS( "OnPropertySet", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
935 DALI_TEST_EQUALS( 9.0f, custom.GetSize().width, TEST_LOCATION );
936 DALI_TEST_EQUALS( 10.0f, custom.GetSize().height, TEST_LOCATION );
938 custom.SetProperty( Actor::Property::SIZE, Vector3( 4.0f, 5.0f, 6.0f ) );
939 DALI_TEST_EQUALS( 4, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
940 DALI_TEST_EQUALS( "OnSizeSet", custom.GetMethodsCalled()[ 2 ], TEST_LOCATION );
941 DALI_TEST_EQUALS( "OnPropertySet", custom.GetMethodsCalled()[ 3 ], TEST_LOCATION );
942 DALI_TEST_EQUALS( 4.0f, custom.GetSize().width, TEST_LOCATION );
943 DALI_TEST_EQUALS( 5.0f, custom.GetSize().height, TEST_LOCATION );
944 DALI_TEST_EQUALS( 6.0f, custom.GetSize().depth, TEST_LOCATION );
948 int UtcDaliCustomActorOnSizeAnimation(void)
950 TestApplication application;
951 tet_infoline("Testing Dali::CustomActor::OnSizeAnimation()");
953 Test::TestCustomActor custom = Test::TestCustomActor::New();
954 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
956 Animation anim = Animation::New( 1.0f );
957 anim.AnimateTo( Property( custom, Actor::Property::SIZE ), Vector3( 8.0f, 9.0f, 10.0f ) );
960 application.SendNotification();
961 application.Render( static_cast<unsigned int>( 1000.0f ) );
963 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
964 DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
965 DALI_TEST_EQUALS( 8.0f, custom.GetTargetSize().width, TEST_LOCATION );
966 DALI_TEST_EQUALS( 9.0f, custom.GetTargetSize().height, TEST_LOCATION );
967 DALI_TEST_EQUALS( 10.0f, custom.GetTargetSize().depth, TEST_LOCATION );
971 int UtcDaliCustomActorSizeComponentAnimation(void)
973 TestApplication application;
974 tet_infoline("Testing Size component animation");
976 Test::TestCustomActor custom = Test::TestCustomActor::New();
977 float intialWidth( 10.0f );
979 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
980 custom.SetProperty( Actor::Property::SIZE, Vector2( intialWidth, 10.0f) ); // First method
982 Animation anim = Animation::New( 1.0f );
984 DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
986 anim.AnimateTo( Property( custom, Actor::Property::SIZE_WIDTH ), 20.0f );
988 DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
990 anim.Play(); // Triggers second method ( OnSizeAnimation )
992 application.SendNotification();
993 application.Render( static_cast<unsigned int>( 1000.0f ) );
995 DALI_TEST_EQUALS( 3, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
997 DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 2 ], TEST_LOCATION );
1002 int UtcDaliCustomActorImplOnPropertySet(void)
1004 TestApplication application;
1005 CustomActorImpl* impl = new Test::Impl::SimpleTestCustomActor();
1006 CustomActor customActor( *impl ); // Will automatically unref at the end of this function
1008 impl->OnPropertySet( 0, 0 );
1010 DALI_TEST_CHECK( true );
1015 int UtcDaliCustomActorGetImplementation(void)
1017 TestApplication application;
1019 Test::TestCustomActor custom = Test::TestCustomActor::New();
1020 CustomActorImpl& impl = custom.GetImplementation();
1021 impl.GetOwner(); // Test
1023 const Test::TestCustomActor constCustom = Test::TestCustomActor::New();
1024 const CustomActorImpl& constImpl = constCustom.GetImplementation();
1025 constImpl.GetOwner(); // Test
1027 DALI_TEST_CHECK( true );
1031 int UtcDaliCustomActorDoAction(void)
1033 TestApplication application;
1034 tet_infoline("Testing Dali::CustomActor::DoAction()");
1036 Test::TestCustomActor custom = Test::TestCustomActor::New();
1038 BaseHandle customActorObject = custom;
1040 DALI_TEST_CHECK(customActorObject);
1042 Property::Map attributes;
1044 // Check that an invalid command is not performed
1045 DALI_TEST_CHECK(customActorObject.DoAction("invalidCommand", attributes) == false);
1047 // Check that the custom actor is visible
1048 custom.SetProperty( Actor::Property::VISIBLE,true);
1049 DALI_TEST_CHECK(custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) == true);
1051 // Check the custom actor performed an action to hide itself
1052 DALI_TEST_CHECK(customActorObject.DoAction("hide", attributes) == true);
1054 // flush the queue and render once
1055 application.SendNotification();
1056 application.Render();
1058 // Check that the custom actor is now invisible
1059 DALI_TEST_CHECK(custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) == false);
1061 // Check the custom actor performed an action to show itself
1062 DALI_TEST_CHECK(customActorObject.DoAction("show", attributes) == true);
1064 // flush the queue and render once
1065 application.SendNotification();
1066 application.Render();
1068 // Check that the custom actor is now visible
1069 DALI_TEST_CHECK(custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) == true);
1073 int UtcDaliCustomActorCustomActor(void)
1075 Dali::CustomActor customA;
1076 Dali::CustomActor customB( customA );
1078 DALI_TEST_CHECK( customA == customB );
1083 int UtcDaliCustomActorImplRelayoutRequest(void)
1085 TestApplication application;
1087 DALI_TEST_CHECK( gOnRelayout == false );
1089 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1090 application.GetScene().Add(custom);
1092 application.SendNotification();
1093 application.Render();
1095 DALI_TEST_CHECK( gOnRelayout == true );
1096 gOnRelayout = false;
1098 custom.TestRelayoutRequest();
1099 application.SendNotification();
1100 application.Render();
1102 DALI_TEST_CHECK( gOnRelayout == true );
1107 int UtcDaliCustomActorImplGetHeightForWidthBase(void)
1109 TestApplication application;
1110 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1112 float width = 300.0f;
1114 application.SendNotification();
1115 application.Render();
1117 float v = custom.TestGetHeightForWidthBase( width );
1119 DALI_TEST_CHECK( v == width );
1124 int UtcDaliCustomActorImplGetWidthForHeightBase(void)
1126 TestApplication application;
1127 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1129 float height = 300.0f;
1131 application.SendNotification();
1132 application.Render();
1134 float v = custom.TestGetWidthForHeightBase( height );
1136 DALI_TEST_CHECK( v == height );
1141 int UtcDaliCustomActorImplCalculateChildSizeBase(void)
1143 TestApplication application;
1144 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1146 Actor child = Actor::New();
1147 child.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1148 child.SetProperty( Actor::Property::SIZE, Vector2( 150, 150 ) );
1150 application.SendNotification();
1151 application.Render();
1153 float v = custom.TestCalculateChildSizeBase( child, Dali::Dimension::ALL_DIMENSIONS );
1154 DALI_TEST_CHECK( v == 0.0f );
1159 int UtcDaliCustomActorImplRelayoutDependentOnChildrenBase(void)
1161 TestApplication application;
1162 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1163 custom.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS);
1165 bool v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::ALL_DIMENSIONS );
1166 DALI_TEST_CHECK( v == true );
1168 application.SendNotification();
1169 application.Render();
1171 custom.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1172 v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::WIDTH );
1173 DALI_TEST_CHECK( v == false );
1175 // why is this here?
1176 application.SendNotification();
1177 application.Render();
1182 int UtcDaliCustomActorTypeRegistry(void)
1184 TestApplication application;
1188 type = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
1189 DALI_TEST_CHECK( type );
1190 BaseHandle handle = type.CreateInstance();
1193 std::string exception;
1197 name = handle.GetTypeName();
1198 tet_result(TET_FAIL);
1200 catch( DaliException& e )
1202 exception = e.condition;
1203 DALI_TEST_EQUALS( exception, "handle && \"BaseObject handle is empty\"", TEST_LOCATION );
1210 int UtcDaliCustomActorGetExtensionP(void)
1212 TestApplication application;
1214 Test::TestCustomActor custom = Test::TestCustomActor::NewVariant5(application.GetScene());
1216 DALI_TEST_CHECK( NULL == custom.GetImplementation().GetExtension() );
1221 int UtcDaliCustomActorOnConnectionDepth(void)
1223 TestApplication application;
1224 tet_infoline("Testing Dali::CustomActor::OnSceneConnection() hierarchy depth");
1226 Integration::Scene stage = application.GetScene();
1228 /* Build tree of actors:
1238 * OnSceneConnection should return 1 for A, 2 for B and C, and 3 for D, E and F.
1241 Test::TestCustomActor actorA = Test::TestCustomActor::New();
1242 stage.Add( actorA );
1244 Test::TestCustomActor actorB = Test::TestCustomActor::New();
1245 actorA.Add( actorB );
1247 Test::TestCustomActor actorC = Test::TestCustomActor::New();
1248 actorA.Add( actorC );
1250 Test::TestCustomActor actorD = Test::TestCustomActor::New();
1251 actorB.Add( actorD );
1253 Test::TestCustomActor actorE = Test::TestCustomActor::New();
1254 actorB.Add( actorE );
1256 Test::TestCustomActor actorF = Test::TestCustomActor::New();
1257 actorC.Add( actorF );
1259 // Excercise the message passing to Update thread
1260 application.SendNotification();
1261 application.Render();
1262 application.Render();
1264 DALI_TEST_EQUALS( 1u, actorA.GetDepth(), TEST_LOCATION );
1265 DALI_TEST_EQUALS( 2u, actorB.GetDepth(), TEST_LOCATION );
1266 DALI_TEST_EQUALS( 2u, actorC.GetDepth(), TEST_LOCATION );
1267 DALI_TEST_EQUALS( 3u, actorD.GetDepth(), TEST_LOCATION );
1268 DALI_TEST_EQUALS( 3u, actorE.GetDepth(), TEST_LOCATION );
1269 DALI_TEST_EQUALS( 3u, actorF.GetDepth(), TEST_LOCATION );
1275 int UtcDaliCustomActorSetGetProperty(void)
1277 TestApplication application; // Need the type registry
1279 Test::TestCustomActor actor = Test::TestCustomActor::New();
1280 application.GetScene().Add( actor );
1282 actor.SetProperty( Test::TestCustomActor::Property::TEST_PROPERTY1, 0.5f );
1283 actor.SetProperty( Test::TestCustomActor::Property::TEST_PROPERTY2, Color::WHITE );
1284 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3, Color::BLUE );
1285 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4, 20 );
1286 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5, 40.0f );
1288 Property::Value value = actor.GetProperty( Test::TestCustomActor::Property::TEST_PROPERTY1 );
1289 DALI_TEST_EQUALS( value.Get<float>(), 0.5f, 0.001f, TEST_LOCATION );
1291 value = actor.GetProperty( Test::TestCustomActor::Property::TEST_PROPERTY2 );
1292 DALI_TEST_EQUALS( value.Get<Vector4>(), Color::WHITE, 0.001f, TEST_LOCATION );
1295 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3 );
1296 DALI_TEST_EQUALS( value.Get<Vector4>(), Color::BLUE, 0.001f, TEST_LOCATION );
1298 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4 );
1299 DALI_TEST_EQUALS( value.Get<int>(), 20, TEST_LOCATION );
1301 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5 );
1302 DALI_TEST_EQUALS( value.Get<float>(), 40.0f, 0.001f, TEST_LOCATION );
1304 // Get read-only property
1305 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6 );
1306 DALI_TEST_EQUALS( value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION );
1308 // Attempt to set read-only property and then ensure value hasn't changed
1309 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6, 40.0f );
1310 DALI_TEST_EQUALS( value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION );
1315 int utcDaliActorGetTypeInfo(void)
1317 TestApplication application;
1318 tet_infoline( "Get the type info of a derived actor" );
1320 Test::TestCustomActor customActor = Test::TestCustomActor::New();
1322 Dali::TypeInfo typeInfo = Dali::DevelCustomActor::GetTypeInfo( customActor );
1324 DALI_TEST_EQUALS( typeInfo.GetName(), std::string("TestCustomActor"), TEST_LOCATION );
1332 * A custom actor that is not type registered on purpose
1334 struct UnregisteredCustomActor : public Dali::CustomActorImpl
1336 UnregisteredCustomActor() : CustomActorImpl( ACTOR_BEHAVIOUR_DEFAULT )
1338 virtual ~UnregisteredCustomActor()
1340 virtual void OnSceneConnection( int32_t depth )
1342 virtual void OnSceneDisconnection()
1344 virtual void OnChildAdd(Actor& child)
1346 virtual void OnChildRemove(Actor& child)
1348 virtual void OnPropertySet( Property::Index index, const Property::Value& propertyValue )
1350 virtual void OnSizeSet(const Vector3& targetSize)
1352 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1354 virtual bool OnHoverEvent(const HoverEvent& event)
1356 virtual bool OnWheelEvent(const WheelEvent& event)
1358 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
1360 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1362 virtual Vector3 GetNaturalSize()
1363 { return Vector3(); }
1364 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
1366 virtual float GetHeightForWidth( float width )
1368 virtual float GetWidthForHeight( float height )
1370 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
1372 virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
1374 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
1378 struct UnregisteredCustomActor : public Dali::CustomActor
1380 static UnregisteredCustomActor New()
1382 Impl::UnregisteredCustomActor* impl = new Impl::UnregisteredCustomActor;
1383 UnregisteredCustomActor custom( *impl ); // takes ownership
1386 UnregisteredCustomActor()
1388 ~UnregisteredCustomActor()
1390 UnregisteredCustomActor( Internal::CustomActor* impl )
1391 : CustomActor( impl )
1393 UnregisteredCustomActor( Impl::UnregisteredCustomActor& impl )
1394 : CustomActor( impl )
1396 static UnregisteredCustomActor DownCast( BaseHandle handle )
1398 UnregisteredCustomActor hndl;
1399 CustomActor custom = Dali::CustomActor::DownCast( handle );
1402 CustomActorImpl& customImpl = custom.GetImplementation();
1404 Impl::UnregisteredCustomActor* impl = dynamic_cast<Impl::UnregisteredCustomActor*>( &customImpl );
1408 hndl = UnregisteredCustomActor( customImpl.GetOwner() );
1415 int UtcDaliCustomActorSetGetActorPropertyActionSignal(void)
1417 TestApplication application; // Need the type registry
1419 auto custom = UnregisteredCustomActor::New();
1420 application.GetScene().Add( custom );
1422 // should have all actor properties
1423 DALI_TEST_EQUALS( custom.GetPropertyType( Actor::Property::COLOR ), Property::VECTOR4, TEST_LOCATION );
1424 auto actorHandle = Actor::New();
1425 DALI_TEST_EQUALS( custom.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION );
1427 DALI_TEST_EQUALS( custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ), true, TEST_LOCATION );
1428 custom.SetProperty( Actor::Property::VISIBLE, false );
1429 application.SendNotification();
1430 application.Render(); // IsVisible returns scene value
1431 DALI_TEST_EQUALS( custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ), false, TEST_LOCATION );
1433 // should have custom actor typename (as it has not registered itself)
1434 DALI_TEST_EQUALS( "CustomActor", custom.GetTypeName(), TEST_LOCATION );
1436 // should have actor actions
1437 custom.DoAction( "show", Property::Map() );
1438 DALI_TEST_EQUALS( custom.GetProperty( Actor::Property::VISIBLE ).Get<bool>(), true, TEST_LOCATION );
1440 Animation animation = Animation::New(0.01f); // very short animation
1441 // should be able to animate actor property
1442 animation.AnimateTo( Property( custom, Actor::Property::POSITION ), Vector3( 100.0f, 150.0f, 200.0f ) );
1445 application.SendNotification();
1446 application.Render(1000.f);
1448 DALI_TEST_EQUALS( Vector3( 100.0f, 150.0f, 200.0f ), custom.GetProperty( Actor::Property::POSITION ).Get<Vector3>(), TEST_LOCATION );
1449 DALI_TEST_EQUALS( Vector3( 100.0f, 150.0f, 200.0f ), custom.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), TEST_LOCATION );
1451 Dali::WeakHandle<UnregisteredCustomActor> weakRef( custom );
1452 // should have actor signals
1453 custom.ConnectSignal( &application, "offScene",
1456 DALI_TEST_EQUALS( weakRef.GetHandle().GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ), false, TEST_LOCATION );
1459 application.GetScene().Remove( custom );
1460 application.GetScene().Add( custom );
1467 struct DerivedCustomActor : public UnregisteredCustomActor
1471 struct DerivedCustomActor : public UnregisteredCustomActor
1473 static DerivedCustomActor New()
1475 Impl::DerivedCustomActor* impl = new Impl::DerivedCustomActor;
1476 DerivedCustomActor custom( *impl ); // takes ownership
1479 DerivedCustomActor()
1481 ~DerivedCustomActor()
1483 DerivedCustomActor( Internal::CustomActor* impl )
1484 : UnregisteredCustomActor( impl )
1486 DerivedCustomActor( Impl::UnregisteredCustomActor& impl )
1487 : UnregisteredCustomActor( impl )
1492 DALI_TYPE_REGISTRATION_BEGIN( DerivedCustomActor, UnregisteredCustomActor, nullptr );
1493 DALI_TYPE_REGISTRATION_END()
1495 int UtcDaliCustomActorPropertyRegistrationDefaultValue(void)
1497 TestApplication application; // Need the type registry
1499 // register our base and add a property with default value for it
1500 Dali::TypeRegistration typeRegistration( typeid( UnregisteredCustomActor ), typeid( Dali::CustomActor ), nullptr );
1502 auto derived = DerivedCustomActor::New();
1503 application.GetScene().Add( derived );
1505 // should have all actor properties
1506 DALI_TEST_EQUALS( derived.GetPropertyType( Actor::Property::WORLD_MATRIX ), Property::MATRIX, TEST_LOCATION );
1507 auto actorHandle = Actor::New();
1508 DALI_TEST_EQUALS( derived.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION );
1510 // add a property in base class
1511 AnimatablePropertyRegistration( typeRegistration, "Foobar", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, 10.f );
1513 // should be one more property now
1514 DALI_TEST_EQUALS( derived.GetPropertyCount(), actorHandle.GetPropertyCount() + 1, TEST_LOCATION );
1515 // check that the default value is set for base class
1516 DALI_TEST_EQUALS( UnregisteredCustomActor::New().GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION );
1517 // check that the default value is set for the derived instance as well
1518 DALI_TEST_EQUALS( derived.GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION );