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 UtcDaliCustomActorOnHoverEvent(void)
1004 TestApplication application;
1005 tet_infoline("Testing Dali::CustomActor::OnHoverEvent()");
1007 Test::TestCustomActor custom = Test::TestCustomActor::New();
1008 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1010 // set size for custom actor
1011 custom.SetProperty( Actor::Property::SIZE, Vector2( 100, 100 ) );
1012 // add the custom actor to stage
1013 application.GetScene().Add( custom );
1014 custom.ResetCallStack();
1016 // Render and notify a couple of times
1017 application.SendNotification();
1018 application.Render();
1019 application.SendNotification();
1020 application.Render();
1022 // simulate a hover event
1023 Dali::Integration::Point point;
1024 point.SetState( PointState::MOTION );
1025 point.SetScreenPosition( Vector2( 1, 1 ) );
1026 Dali::Integration::HoverEvent event;
1027 event.AddPoint( point );
1028 application.ProcessEvent( event );
1030 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1031 DALI_TEST_EQUALS( "OnHoverEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1035 int UtcDaliCustomActorOnWheelEvent(void)
1037 TestApplication application;
1038 tet_infoline("Testing Dali::CustomActor::OnWheelEvent()");
1040 Test::TestCustomActor custom = Test::TestCustomActor::New();
1041 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1043 // set size for custom actor
1044 custom.SetProperty( Actor::Property::SIZE, Vector2( 100, 100 ) );
1045 // add the custom actor to stage
1046 application.GetScene().Add( custom );
1047 custom.ResetCallStack();
1049 // Render and notify a couple of times
1050 application.SendNotification();
1051 application.Render();
1052 application.SendNotification();
1053 application.Render();
1055 // simulate a wheel event
1056 Vector2 screenCoordinates( 10.0f, 10.0f );
1057 Integration::WheelEvent event( Integration::WheelEvent::MOUSE_WHEEL, 0, 0u, screenCoordinates, 1, 1000u );
1058 application.ProcessEvent( event );
1060 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1061 DALI_TEST_EQUALS( "OnWheelEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1065 int UtcDaliCustomActorImplOnPropertySet(void)
1067 TestApplication application;
1068 CustomActorImpl* impl = new Test::Impl::SimpleTestCustomActor();
1069 CustomActor customActor( *impl ); // Will automatically unref at the end of this function
1071 impl->OnPropertySet( 0, 0 );
1073 DALI_TEST_CHECK( true );
1078 int UtcDaliCustomActorGetImplementation(void)
1080 TestApplication application;
1082 Test::TestCustomActor custom = Test::TestCustomActor::New();
1083 CustomActorImpl& impl = custom.GetImplementation();
1084 impl.GetOwner(); // Test
1086 const Test::TestCustomActor constCustom = Test::TestCustomActor::New();
1087 const CustomActorImpl& constImpl = constCustom.GetImplementation();
1088 constImpl.GetOwner(); // Test
1090 DALI_TEST_CHECK( true );
1094 int UtcDaliCustomActorDoAction(void)
1096 TestApplication application;
1097 tet_infoline("Testing Dali::CustomActor::DoAction()");
1099 Test::TestCustomActor custom = Test::TestCustomActor::New();
1101 BaseHandle customActorObject = custom;
1103 DALI_TEST_CHECK(customActorObject);
1105 Property::Map attributes;
1107 // Check that an invalid command is not performed
1108 DALI_TEST_CHECK(customActorObject.DoAction("invalidCommand", attributes) == false);
1110 // Check that the custom actor is visible
1111 custom.SetProperty( Actor::Property::VISIBLE,true);
1112 DALI_TEST_CHECK(custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) == true);
1114 // Check the custom actor performed an action to hide itself
1115 DALI_TEST_CHECK(customActorObject.DoAction("hide", attributes) == true);
1117 // flush the queue and render once
1118 application.SendNotification();
1119 application.Render();
1121 // Check that the custom actor is now invisible
1122 DALI_TEST_CHECK(custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) == false);
1124 // Check the custom actor performed an action to show itself
1125 DALI_TEST_CHECK(customActorObject.DoAction("show", attributes) == true);
1127 // flush the queue and render once
1128 application.SendNotification();
1129 application.Render();
1131 // Check that the custom actor is now visible
1132 DALI_TEST_CHECK(custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) == true);
1136 int UtcDaliCustomActorCustomActor(void)
1138 Dali::CustomActor customA;
1139 Dali::CustomActor customB( customA );
1141 DALI_TEST_CHECK( customA == customB );
1146 int UtcDaliCustomActorImplRelayoutRequest(void)
1148 TestApplication application;
1150 DALI_TEST_CHECK( gOnRelayout == false );
1152 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1153 application.GetScene().Add(custom);
1155 application.SendNotification();
1156 application.Render();
1158 DALI_TEST_CHECK( gOnRelayout == true );
1159 gOnRelayout = false;
1161 custom.TestRelayoutRequest();
1162 application.SendNotification();
1163 application.Render();
1165 DALI_TEST_CHECK( gOnRelayout == true );
1170 int UtcDaliCustomActorImplGetHeightForWidthBase(void)
1172 TestApplication application;
1173 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1175 float width = 300.0f;
1177 application.SendNotification();
1178 application.Render();
1180 float v = custom.TestGetHeightForWidthBase( width );
1182 DALI_TEST_CHECK( v == width );
1187 int UtcDaliCustomActorImplGetWidthForHeightBase(void)
1189 TestApplication application;
1190 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1192 float height = 300.0f;
1194 application.SendNotification();
1195 application.Render();
1197 float v = custom.TestGetWidthForHeightBase( height );
1199 DALI_TEST_CHECK( v == height );
1204 int UtcDaliCustomActorImplCalculateChildSizeBase(void)
1206 TestApplication application;
1207 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1209 Actor child = Actor::New();
1210 child.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1211 child.SetProperty( Actor::Property::SIZE, Vector2( 150, 150 ) );
1213 application.SendNotification();
1214 application.Render();
1216 float v = custom.TestCalculateChildSizeBase( child, Dali::Dimension::ALL_DIMENSIONS );
1217 DALI_TEST_CHECK( v == 0.0f );
1222 int UtcDaliCustomActorImplRelayoutDependentOnChildrenBase(void)
1224 TestApplication application;
1225 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1226 custom.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS);
1228 bool v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::ALL_DIMENSIONS );
1229 DALI_TEST_CHECK( v == true );
1231 application.SendNotification();
1232 application.Render();
1234 custom.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1235 v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::WIDTH );
1236 DALI_TEST_CHECK( v == false );
1238 // why is this here?
1239 application.SendNotification();
1240 application.Render();
1245 int UtcDaliCustomActorTypeRegistry(void)
1247 TestApplication application;
1251 type = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
1252 DALI_TEST_CHECK( type );
1253 BaseHandle handle = type.CreateInstance();
1256 std::string exception;
1260 name = handle.GetTypeName();
1261 tet_result(TET_FAIL);
1263 catch( DaliException& e )
1265 exception = e.condition;
1266 DALI_TEST_EQUALS( exception, "handle && \"BaseObject handle is empty\"", TEST_LOCATION );
1273 int UtcDaliCustomActorGetExtensionP(void)
1275 TestApplication application;
1277 Test::TestCustomActor custom = Test::TestCustomActor::NewVariant5(application.GetScene());
1279 DALI_TEST_CHECK( NULL == custom.GetImplementation().GetExtension() );
1284 int UtcDaliCustomActorOnConnectionDepth(void)
1286 TestApplication application;
1287 tet_infoline("Testing Dali::CustomActor::OnSceneConnection() hierarchy depth");
1289 Integration::Scene stage = application.GetScene();
1291 /* Build tree of actors:
1301 * OnSceneConnection should return 1 for A, 2 for B and C, and 3 for D, E and F.
1304 Test::TestCustomActor actorA = Test::TestCustomActor::New();
1305 stage.Add( actorA );
1307 Test::TestCustomActor actorB = Test::TestCustomActor::New();
1308 actorA.Add( actorB );
1310 Test::TestCustomActor actorC = Test::TestCustomActor::New();
1311 actorA.Add( actorC );
1313 Test::TestCustomActor actorD = Test::TestCustomActor::New();
1314 actorB.Add( actorD );
1316 Test::TestCustomActor actorE = Test::TestCustomActor::New();
1317 actorB.Add( actorE );
1319 Test::TestCustomActor actorF = Test::TestCustomActor::New();
1320 actorC.Add( actorF );
1322 // Excercise the message passing to Update thread
1323 application.SendNotification();
1324 application.Render();
1325 application.Render();
1327 DALI_TEST_EQUALS( 1u, actorA.GetDepth(), TEST_LOCATION );
1328 DALI_TEST_EQUALS( 2u, actorB.GetDepth(), TEST_LOCATION );
1329 DALI_TEST_EQUALS( 2u, actorC.GetDepth(), TEST_LOCATION );
1330 DALI_TEST_EQUALS( 3u, actorD.GetDepth(), TEST_LOCATION );
1331 DALI_TEST_EQUALS( 3u, actorE.GetDepth(), TEST_LOCATION );
1332 DALI_TEST_EQUALS( 3u, actorF.GetDepth(), TEST_LOCATION );
1338 int UtcDaliCustomActorSetGetProperty(void)
1340 TestApplication application; // Need the type registry
1342 Test::TestCustomActor actor = Test::TestCustomActor::New();
1343 application.GetScene().Add( actor );
1345 actor.SetProperty( Test::TestCustomActor::Property::TEST_PROPERTY1, 0.5f );
1346 actor.SetProperty( Test::TestCustomActor::Property::TEST_PROPERTY2, Color::WHITE );
1347 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3, Color::BLUE );
1348 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4, 20 );
1349 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5, 40.0f );
1351 Property::Value value = actor.GetProperty( Test::TestCustomActor::Property::TEST_PROPERTY1 );
1352 DALI_TEST_EQUALS( value.Get<float>(), 0.5f, 0.001f, TEST_LOCATION );
1354 value = actor.GetProperty( Test::TestCustomActor::Property::TEST_PROPERTY2 );
1355 DALI_TEST_EQUALS( value.Get<Vector4>(), Color::WHITE, 0.001f, TEST_LOCATION );
1358 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3 );
1359 DALI_TEST_EQUALS( value.Get<Vector4>(), Color::BLUE, 0.001f, TEST_LOCATION );
1361 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4 );
1362 DALI_TEST_EQUALS( value.Get<int>(), 20, TEST_LOCATION );
1364 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5 );
1365 DALI_TEST_EQUALS( value.Get<float>(), 40.0f, 0.001f, TEST_LOCATION );
1367 // Get read-only property
1368 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6 );
1369 DALI_TEST_EQUALS( value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION );
1371 // Attempt to set read-only property and then ensure value hasn't changed
1372 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6, 40.0f );
1373 DALI_TEST_EQUALS( value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION );
1378 int utcDaliActorGetTypeInfo(void)
1380 TestApplication application;
1381 tet_infoline( "Get the type info of a derived actor" );
1383 Test::TestCustomActor customActor = Test::TestCustomActor::New();
1385 Dali::TypeInfo typeInfo = Dali::DevelCustomActor::GetTypeInfo( customActor );
1387 DALI_TEST_EQUALS( typeInfo.GetName(), std::string("TestCustomActor"), TEST_LOCATION );
1395 * A custom actor that is not type registered on purpose
1397 struct UnregisteredCustomActor : public Dali::CustomActorImpl
1399 UnregisteredCustomActor() : CustomActorImpl( ACTOR_BEHAVIOUR_DEFAULT )
1401 virtual ~UnregisteredCustomActor()
1403 virtual void OnSceneConnection( int32_t depth )
1405 virtual void OnSceneDisconnection()
1407 virtual void OnChildAdd(Actor& child)
1409 virtual void OnChildRemove(Actor& child)
1411 virtual void OnPropertySet( Property::Index index, const Property::Value& propertyValue )
1413 virtual void OnSizeSet(const Vector3& targetSize)
1415 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1417 virtual bool OnHoverEvent(const HoverEvent& event)
1419 virtual bool OnKeyEvent(const KeyEvent& event)
1421 virtual bool OnWheelEvent(const WheelEvent& event)
1423 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
1425 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1427 virtual Vector3 GetNaturalSize()
1428 { return Vector3(); }
1429 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
1431 virtual float GetHeightForWidth( float width )
1433 virtual float GetWidthForHeight( float height )
1435 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
1437 virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
1439 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
1443 struct UnregisteredCustomActor : public Dali::CustomActor
1445 static UnregisteredCustomActor New()
1447 Impl::UnregisteredCustomActor* impl = new Impl::UnregisteredCustomActor;
1448 UnregisteredCustomActor custom( *impl ); // takes ownership
1451 UnregisteredCustomActor()
1453 ~UnregisteredCustomActor()
1455 UnregisteredCustomActor( Internal::CustomActor* impl )
1456 : CustomActor( impl )
1458 UnregisteredCustomActor( Impl::UnregisteredCustomActor& impl )
1459 : CustomActor( impl )
1461 static UnregisteredCustomActor DownCast( BaseHandle handle )
1463 UnregisteredCustomActor hndl;
1464 CustomActor custom = Dali::CustomActor::DownCast( handle );
1467 CustomActorImpl& customImpl = custom.GetImplementation();
1469 Impl::UnregisteredCustomActor* impl = dynamic_cast<Impl::UnregisteredCustomActor*>( &customImpl );
1473 hndl = UnregisteredCustomActor( customImpl.GetOwner() );
1480 int UtcDaliCustomActorSetGetActorPropertyActionSignal(void)
1482 TestApplication application; // Need the type registry
1484 auto custom = UnregisteredCustomActor::New();
1485 application.GetScene().Add( custom );
1487 // should have all actor properties
1488 DALI_TEST_EQUALS( custom.GetPropertyType( Actor::Property::COLOR ), Property::VECTOR4, TEST_LOCATION );
1489 auto actorHandle = Actor::New();
1490 DALI_TEST_EQUALS( custom.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION );
1492 DALI_TEST_EQUALS( custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ), true, TEST_LOCATION );
1493 custom.SetProperty( Actor::Property::VISIBLE, false );
1494 application.SendNotification();
1495 application.Render(); // IsVisible returns scene value
1496 DALI_TEST_EQUALS( custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ), false, TEST_LOCATION );
1498 // should have custom actor typename (as it has not registered itself)
1499 DALI_TEST_EQUALS( "CustomActor", custom.GetTypeName(), TEST_LOCATION );
1501 // should have actor actions
1502 custom.DoAction( "show", Property::Map() );
1503 DALI_TEST_EQUALS( custom.GetProperty( Actor::Property::VISIBLE ).Get<bool>(), true, TEST_LOCATION );
1505 Animation animation = Animation::New(0.01f); // very short animation
1506 // should be able to animate actor property
1507 animation.AnimateTo( Property( custom, Actor::Property::POSITION ), Vector3( 100.0f, 150.0f, 200.0f ) );
1510 application.SendNotification();
1511 application.Render(1000.f);
1513 DALI_TEST_EQUALS( Vector3( 100.0f, 150.0f, 200.0f ), custom.GetProperty( Actor::Property::POSITION ).Get<Vector3>(), TEST_LOCATION );
1514 DALI_TEST_EQUALS( Vector3( 100.0f, 150.0f, 200.0f ), custom.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), TEST_LOCATION );
1516 Dali::WeakHandle<UnregisteredCustomActor> weakRef( custom );
1517 // should have actor signals
1518 custom.ConnectSignal( &application, "offScene",
1521 DALI_TEST_EQUALS( weakRef.GetHandle().GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ), false, TEST_LOCATION );
1524 application.GetScene().Remove( custom );
1525 application.GetScene().Add( custom );
1532 struct DerivedCustomActor : public UnregisteredCustomActor
1536 struct DerivedCustomActor : public UnregisteredCustomActor
1538 static DerivedCustomActor New()
1540 Impl::DerivedCustomActor* impl = new Impl::DerivedCustomActor;
1541 DerivedCustomActor custom( *impl ); // takes ownership
1544 DerivedCustomActor()
1546 ~DerivedCustomActor()
1548 DerivedCustomActor( Internal::CustomActor* impl )
1549 : UnregisteredCustomActor( impl )
1551 DerivedCustomActor( Impl::UnregisteredCustomActor& impl )
1552 : UnregisteredCustomActor( impl )
1557 DALI_TYPE_REGISTRATION_BEGIN( DerivedCustomActor, UnregisteredCustomActor, nullptr );
1558 DALI_TYPE_REGISTRATION_END()
1560 int UtcDaliCustomActorPropertyRegistrationDefaultValue(void)
1562 TestApplication application; // Need the type registry
1564 // register our base and add a property with default value for it
1565 Dali::TypeRegistration typeRegistration( typeid( UnregisteredCustomActor ), typeid( Dali::CustomActor ), nullptr );
1567 auto derived = DerivedCustomActor::New();
1568 application.GetScene().Add( derived );
1570 // should have all actor properties
1571 DALI_TEST_EQUALS( derived.GetPropertyType( Actor::Property::WORLD_MATRIX ), Property::MATRIX, TEST_LOCATION );
1572 auto actorHandle = Actor::New();
1573 DALI_TEST_EQUALS( derived.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION );
1575 // add a property in base class
1576 AnimatablePropertyRegistration( typeRegistration, "Foobar", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, 10.f );
1578 // should be one more property now
1579 DALI_TEST_EQUALS( derived.GetPropertyCount(), actorHandle.GetPropertyCount() + 1, TEST_LOCATION );
1580 // check that the default value is set for base class
1581 DALI_TEST_EQUALS( UnregisteredCustomActor::New().GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION );
1582 // check that the default value is set for the derived instance as well
1583 DALI_TEST_EQUALS( derived.GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION );