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.
18 #include <dali/devel-api/actors/custom-actor-devel.h>
19 #include <dali/integration-api/events/hover-event-integ.h>
20 #include <dali/integration-api/events/key-event-integ.h>
21 #include <dali/integration-api/events/touch-event-integ.h>
22 #include <dali/integration-api/events/wheel-event-integ.h>
23 #include <dali/public-api/dali-core.h>
24 #include <dali/public-api/object/type-registry-helper.h>
29 #include "dali-test-suite-utils/dali-test-suite-utils.h"
30 #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;
46 int UtcDaliCustomActorDestructor(void)
48 TestApplication application;
50 CustomActor* actor = new CustomActor();
53 DALI_TEST_CHECK(true);
57 int UtcDaliCustomActorImplDestructor(void)
59 TestApplication application;
60 CustomActorImpl* actor = new Test::Impl::TestCustomActor();
61 CustomActor customActor(*actor); // Will automatically unref at the end of this function
63 DALI_TEST_CHECK(true);
67 // Positive test case for a method
68 int UtcDaliCustomActorDownCast(void)
70 TestApplication application;
71 tet_infoline("Testing Dali::CustomActor::DownCast()");
73 Test::TestCustomActor custom = Test::TestCustomActor::New();
75 Actor anActor = Actor::New();
78 Actor child = anActor.GetChildAt(0);
79 CustomActor customActor = CustomActor::DownCast(child);
80 DALI_TEST_CHECK(customActor);
83 DALI_TEST_CHECK(!customActor);
85 customActor = DownCast<CustomActor>(child);
86 DALI_TEST_CHECK(customActor);
90 // Negative test case for a method
91 int UtcDaliCustomActorDownCastNegative(void)
93 TestApplication application;
94 tet_infoline("Testing Dali::CustomActor::DownCast()");
96 Actor actor1 = Actor::New();
97 Actor anActor = Actor::New();
100 Actor child = anActor.GetChildAt(0);
101 CustomActor customActor = CustomActor::DownCast(child);
102 DALI_TEST_CHECK(!customActor);
104 Actor unInitialzedActor;
105 customActor = CustomActor::DownCast(unInitialzedActor);
106 DALI_TEST_CHECK(!customActor);
108 customActor = DownCast<CustomActor>(unInitialzedActor);
109 DALI_TEST_CHECK(!customActor);
113 int UtcDaliCustomActorMoveConstructor(void)
115 TestApplication application;
117 Test::TestCustomActor custom = Test::TestCustomActor::New();
118 DALI_TEST_CHECK(custom);
119 DALI_TEST_EQUALS(1, custom.GetBaseObject().ReferenceCount(), TEST_LOCATION);
121 int id = custom.GetProperty<int>(Actor::Property::ID);
123 Test::TestCustomActor moved = std::move(custom);
124 DALI_TEST_CHECK(moved);
125 DALI_TEST_EQUALS(id, moved.GetProperty<int>(Actor::Property::ID), TEST_LOCATION);
126 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
127 DALI_TEST_CHECK(!custom);
132 int UtcDaliCustomActorMoveAssignment(void)
134 TestApplication application;
136 Test::TestCustomActor custom = Test::TestCustomActor::New();
137 DALI_TEST_CHECK(custom);
138 DALI_TEST_EQUALS(1, custom.GetBaseObject().ReferenceCount(), TEST_LOCATION);
140 int id = custom.GetProperty<int>(Actor::Property::ID);
142 Test::TestCustomActor moved;
143 moved = std::move(custom);
144 DALI_TEST_CHECK(moved);
145 DALI_TEST_EQUALS(id, moved.GetProperty<int>(Actor::Property::ID), TEST_LOCATION);
146 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
147 DALI_TEST_CHECK(!custom);
152 int UtcDaliCustomActorOnSceneConnectionDisconnection(void)
154 TestApplication application;
155 tet_infoline("Testing Dali::CustomActor::OnSceneConnection() & OnSceneDisconnection");
157 Test::TestCustomActor custom = Test::TestCustomActor::New();
158 DALI_TEST_EQUALS(0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
160 // add the custom actor to stage
161 application.GetScene().Add(custom);
163 DALI_TEST_EQUALS(1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
164 DALI_TEST_EQUALS("OnSceneConnection", custom.GetMethodsCalled()[0], TEST_LOCATION);
166 application.GetScene().Remove(custom);
168 DALI_TEST_EQUALS(2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
169 DALI_TEST_EQUALS("OnSceneDisconnection", custom.GetMethodsCalled()[1], TEST_LOCATION);
171 // Excercise the message passing to Update thread
173 application.SendNotification();
174 application.Render();
175 application.Render();
179 int UtcDaliCustomActorOnSceneConnectionOrder(void)
181 TestApplication application;
182 tet_infoline("Testing Dali::CustomActor::OnSceneConnection() order");
184 MasterCallStack.clear();
186 /* Build tree of actors:
194 * OnSceneConnection should be received for A, B, D, E, C, and finally F
197 Test::TestCustomActor actorA = Test::TestCustomActor::New();
198 actorA.SetProperty(Actor::Property::NAME, "ActorA");
200 Test::TestCustomActor actorB = Test::TestCustomActor::New();
201 actorB.SetProperty(Actor::Property::NAME, "ActorB");
204 Test::TestCustomActor actorC = Test::TestCustomActor::New();
205 actorC.SetProperty(Actor::Property::NAME, "ActorC");
208 Test::TestCustomActor actorD = Test::TestCustomActor::New();
209 actorD.SetProperty(Actor::Property::NAME, "ActorD");
212 Test::TestCustomActor actorE = Test::TestCustomActor::New();
213 actorE.SetProperty(Actor::Property::NAME, "ActorE");
216 Test::TestCustomActor actorF = Test::TestCustomActor::New();
217 actorF.SetProperty(Actor::Property::NAME, "ActorF");
220 // add the custom actor to stage
221 application.GetScene().Add(actorA);
223 DALI_TEST_EQUALS(4, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION);
224 DALI_TEST_EQUALS("OnPropertySet", actorA.GetMethodsCalled()[0], TEST_LOCATION);
225 DALI_TEST_EQUALS("OnChildAdd", actorA.GetMethodsCalled()[1], TEST_LOCATION);
226 DALI_TEST_EQUALS("OnChildAdd", actorA.GetMethodsCalled()[2], TEST_LOCATION);
227 DALI_TEST_EQUALS("OnSceneConnection", actorA.GetMethodsCalled()[3], TEST_LOCATION);
229 DALI_TEST_EQUALS(4, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION);
230 DALI_TEST_EQUALS("OnPropertySet", actorB.GetMethodsCalled()[0], TEST_LOCATION);
231 DALI_TEST_EQUALS("OnChildAdd", actorB.GetMethodsCalled()[1], TEST_LOCATION);
232 DALI_TEST_EQUALS("OnChildAdd", actorB.GetMethodsCalled()[2], TEST_LOCATION);
233 DALI_TEST_EQUALS("OnSceneConnection", actorB.GetMethodsCalled()[3], TEST_LOCATION);
235 DALI_TEST_EQUALS(3, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION);
236 DALI_TEST_EQUALS("OnPropertySet", actorC.GetMethodsCalled()[0], TEST_LOCATION);
237 DALI_TEST_EQUALS("OnChildAdd", actorC.GetMethodsCalled()[1], TEST_LOCATION);
238 DALI_TEST_EQUALS("OnSceneConnection", actorC.GetMethodsCalled()[2], TEST_LOCATION);
240 DALI_TEST_EQUALS(2, (int)(actorD.GetMethodsCalled().size()), TEST_LOCATION);
241 DALI_TEST_EQUALS("OnPropertySet", actorD.GetMethodsCalled()[0], TEST_LOCATION);
242 DALI_TEST_EQUALS("OnSceneConnection", actorD.GetMethodsCalled()[1], TEST_LOCATION);
244 DALI_TEST_EQUALS(2, (int)(actorE.GetMethodsCalled().size()), TEST_LOCATION);
245 DALI_TEST_EQUALS("OnPropertySet", actorE.GetMethodsCalled()[0], TEST_LOCATION);
246 DALI_TEST_EQUALS("OnSceneConnection", actorE.GetMethodsCalled()[1], TEST_LOCATION);
248 DALI_TEST_EQUALS(2, (int)(actorF.GetMethodsCalled().size()), TEST_LOCATION);
249 DALI_TEST_EQUALS("OnPropertySet", actorF.GetMethodsCalled()[0], TEST_LOCATION);
250 DALI_TEST_EQUALS("OnSceneConnection", actorF.GetMethodsCalled()[1], TEST_LOCATION);
252 // Check sequence is correct in MasterCallStack
254 DALI_TEST_EQUALS(4 + 4 + 3 + 2 + 2 + 2, (int)(MasterCallStack.size()), TEST_LOCATION);
256 DALI_TEST_EQUALS("ActorA: OnPropertySet", MasterCallStack[0], TEST_LOCATION);
257 DALI_TEST_EQUALS("ActorB: OnPropertySet", MasterCallStack[1], TEST_LOCATION);
258 DALI_TEST_EQUALS("ActorA: OnChildAdd", MasterCallStack[2], TEST_LOCATION);
259 DALI_TEST_EQUALS("ActorC: OnPropertySet", MasterCallStack[3], TEST_LOCATION);
260 DALI_TEST_EQUALS("ActorA: OnChildAdd", MasterCallStack[4], TEST_LOCATION);
261 DALI_TEST_EQUALS("ActorD: OnPropertySet", MasterCallStack[5], TEST_LOCATION);
263 DALI_TEST_EQUALS("ActorB: OnChildAdd", MasterCallStack[6], TEST_LOCATION);
264 DALI_TEST_EQUALS("ActorE: OnPropertySet", MasterCallStack[7], TEST_LOCATION);
265 DALI_TEST_EQUALS("ActorB: OnChildAdd", MasterCallStack[8], TEST_LOCATION);
266 DALI_TEST_EQUALS("ActorF: OnPropertySet", MasterCallStack[9], TEST_LOCATION);
267 DALI_TEST_EQUALS("ActorC: OnChildAdd", MasterCallStack[10], TEST_LOCATION);
269 DALI_TEST_EQUALS("ActorA: OnSceneConnection", MasterCallStack[11], TEST_LOCATION);
270 DALI_TEST_EQUALS("ActorB: OnSceneConnection", MasterCallStack[12], TEST_LOCATION);
271 DALI_TEST_EQUALS("ActorD: OnSceneConnection", MasterCallStack[13], TEST_LOCATION);
272 DALI_TEST_EQUALS("ActorE: OnSceneConnection", MasterCallStack[14], TEST_LOCATION);
273 DALI_TEST_EQUALS("ActorC: OnSceneConnection", MasterCallStack[15], TEST_LOCATION);
274 DALI_TEST_EQUALS("ActorF: OnSceneConnection", MasterCallStack[16], TEST_LOCATION);
276 // Excercise the message passing to Update thread
278 application.SendNotification();
279 application.Render();
280 application.Render();
284 int UtcDaliCustomActorOnSceneDisconnectionOrder(void)
286 TestApplication application;
287 tet_infoline("Testing Dali::CustomActor::OnSceneDisconnection() order");
289 Integration::Scene stage = application.GetScene();
291 /* Build tree of actors:
299 * OnSceneDisconnection should be received for D, E, B, F, C, and finally A.
302 Test::TestCustomActor actorA = Test::TestCustomActor::New();
303 actorA.SetProperty(Actor::Property::NAME, "ActorA");
306 Test::TestCustomActor actorB = Test::TestCustomActor::New();
307 actorB.SetProperty(Actor::Property::NAME, "ActorB");
310 Test::TestCustomActor actorC = Test::TestCustomActor::New();
311 actorC.SetProperty(Actor::Property::NAME, "ActorC");
314 Test::TestCustomActor actorD = Test::TestCustomActor::New();
315 actorD.SetProperty(Actor::Property::NAME, "ActorD");
318 Test::TestCustomActor actorE = Test::TestCustomActor::New();
319 actorE.SetProperty(Actor::Property::NAME, "ActorE");
322 Test::TestCustomActor actorF = Test::TestCustomActor::New();
323 actorF.SetProperty(Actor::Property::NAME, "ActorF");
326 // Excercise the message passing to Update thread
328 application.SendNotification();
329 application.Render();
330 application.Render();
332 // Clear call stacks before disconnection
333 actorA.ResetCallStack();
334 actorB.ResetCallStack();
335 actorC.ResetCallStack();
336 actorD.ResetCallStack();
337 actorE.ResetCallStack();
338 actorF.ResetCallStack();
339 MasterCallStack.clear();
341 stage.Remove(actorA);
343 DALI_TEST_EQUALS(1, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION);
344 DALI_TEST_EQUALS("OnSceneDisconnection", actorA.GetMethodsCalled()[0], TEST_LOCATION);
346 DALI_TEST_EQUALS(1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION);
347 DALI_TEST_EQUALS("OnSceneDisconnection", actorB.GetMethodsCalled()[0], TEST_LOCATION);
349 DALI_TEST_EQUALS(1, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION);
350 DALI_TEST_EQUALS("OnSceneDisconnection", actorC.GetMethodsCalled()[0], TEST_LOCATION);
352 DALI_TEST_EQUALS(1, (int)(actorD.GetMethodsCalled().size()), TEST_LOCATION);
353 DALI_TEST_EQUALS("OnSceneDisconnection", actorD.GetMethodsCalled()[0], TEST_LOCATION);
355 DALI_TEST_EQUALS(1, (int)(actorE.GetMethodsCalled().size()), TEST_LOCATION);
356 DALI_TEST_EQUALS("OnSceneDisconnection", actorE.GetMethodsCalled()[0], TEST_LOCATION);
358 DALI_TEST_EQUALS(1, (int)(actorF.GetMethodsCalled().size()), TEST_LOCATION);
359 DALI_TEST_EQUALS("OnSceneDisconnection", actorF.GetMethodsCalled()[0], TEST_LOCATION);
361 // Check sequence is correct in MasterCallStack
363 DALI_TEST_EQUALS(6, (int)(MasterCallStack.size()), TEST_LOCATION);
365 DALI_TEST_EQUALS("ActorD: OnSceneDisconnection", MasterCallStack[0], TEST_LOCATION);
366 DALI_TEST_EQUALS("ActorE: OnSceneDisconnection", MasterCallStack[1], TEST_LOCATION);
367 DALI_TEST_EQUALS("ActorB: OnSceneDisconnection", MasterCallStack[2], TEST_LOCATION);
368 DALI_TEST_EQUALS("ActorF: OnSceneDisconnection", MasterCallStack[3], TEST_LOCATION);
369 DALI_TEST_EQUALS("ActorC: OnSceneDisconnection", MasterCallStack[4], TEST_LOCATION);
370 DALI_TEST_EQUALS("ActorA: OnSceneDisconnection", MasterCallStack[5], TEST_LOCATION);
372 // Excercise the message passing to Update thread
374 application.SendNotification();
375 application.Render();
376 application.Render();
380 int UtcDaliCustomActorAddDuringOnSceneConnection(void)
382 TestApplication application;
383 tet_infoline("Testing Actor::Add behaviour during Dali::CustomActor::OnSceneConnection() callback");
385 Integration::Scene stage = application.GetScene();
387 MasterCallStack.clear();
389 /* The actorA is a special variant which adds a child to itself during OnSceneConnection()
390 * The actorB is provided as the child
393 Test::TestCustomActor actorB = Test::TestCustomActor::New();
394 actorB.SetProperty(Actor::Property::NAME, "ActorB");
396 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant1(actorB);
397 actorA.SetProperty(Actor::Property::NAME, "ActorA");
400 // Check callback sequence
402 DALI_TEST_EQUALS(3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION);
403 DALI_TEST_EQUALS("OnPropertySet", actorA.GetMethodsCalled()[0], TEST_LOCATION);
404 DALI_TEST_EQUALS("OnSceneConnection", actorA.GetMethodsCalled()[1], TEST_LOCATION);
405 DALI_TEST_EQUALS("OnChildAdd", actorA.GetMethodsCalled()[2], TEST_LOCATION); // Called from within OnSceneConnection()
407 DALI_TEST_EQUALS(2, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION);
408 DALI_TEST_EQUALS("OnPropertySet", actorB.GetMethodsCalled()[0], TEST_LOCATION);
409 DALI_TEST_EQUALS("OnSceneConnection", actorB.GetMethodsCalled()[1], TEST_LOCATION);
411 DALI_TEST_EQUALS(5, (int)(MasterCallStack.size()), TEST_LOCATION);
413 DALI_TEST_EQUALS("ActorB: OnPropertySet", MasterCallStack[0], TEST_LOCATION);
414 DALI_TEST_EQUALS("ActorA: OnPropertySet", MasterCallStack[1], TEST_LOCATION);
415 DALI_TEST_EQUALS("ActorA: OnSceneConnection", MasterCallStack[2], TEST_LOCATION);
416 DALI_TEST_EQUALS("ActorB: OnSceneConnection", MasterCallStack[3], TEST_LOCATION); // Occurs during Actor::Add from within from within OnSceneConnection()
417 DALI_TEST_EQUALS("ActorA: OnChildAdd", MasterCallStack[4], TEST_LOCATION); // Occurs after Actor::Add from within from within OnSceneConnection()
419 // Excercise the message passing to Update thread
421 application.SendNotification();
422 application.Render();
423 application.Render();
425 // Check everything is ok after Actors are removed
427 stage.Remove(actorA);
428 application.SendNotification();
429 application.Render();
430 application.Render();
434 int UtcDaliCustomActorRemoveDuringOnSceneConnection(void)
436 TestApplication application;
437 tet_infoline("Testing Actor::Remove behaviour during Dali::CustomActor::OnSceneConnection() callback");
439 Integration::Scene stage = application.GetScene();
441 MasterCallStack.clear();
443 /* The actorA is a special variant which removes its children during OnSceneConnection()
444 * Actors B & C are provided as the children
447 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant2();
448 actorA.SetProperty(Actor::Property::NAME, "ActorA");
450 Test::TestCustomActor actorB = Test::TestCustomActor::New();
451 actorB.SetProperty(Actor::Property::NAME, "ActorB");
454 Test::TestCustomActor actorC = Test::TestCustomActor::New();
455 actorC.SetProperty(Actor::Property::NAME, "ActorC");
460 // Check callback sequence
462 DALI_TEST_EQUALS(6, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION);
463 DALI_TEST_EQUALS("OnPropertySet", actorA.GetMethodsCalled()[0], TEST_LOCATION);
464 DALI_TEST_EQUALS("OnChildAdd", actorA.GetMethodsCalled()[1], TEST_LOCATION);
465 DALI_TEST_EQUALS("OnChildAdd", actorA.GetMethodsCalled()[2], TEST_LOCATION);
466 DALI_TEST_EQUALS("OnSceneConnection", actorA.GetMethodsCalled()[3], TEST_LOCATION);
467 DALI_TEST_EQUALS("OnChildRemove", actorA.GetMethodsCalled()[4], TEST_LOCATION); // Called from within OnSceneConnection()
468 DALI_TEST_EQUALS("OnChildRemove", actorA.GetMethodsCalled()[5], TEST_LOCATION); // Called from within OnSceneConnection()
470 DALI_TEST_EQUALS(8, (int)(MasterCallStack.size()), TEST_LOCATION);
472 DALI_TEST_EQUALS("ActorA: OnPropertySet", MasterCallStack[0], TEST_LOCATION);
473 DALI_TEST_EQUALS("ActorB: OnPropertySet", MasterCallStack[1], TEST_LOCATION);
474 DALI_TEST_EQUALS("ActorA: OnChildAdd", MasterCallStack[2], TEST_LOCATION);
475 DALI_TEST_EQUALS("ActorC: OnPropertySet", MasterCallStack[3], TEST_LOCATION);
476 DALI_TEST_EQUALS("ActorA: OnChildAdd", MasterCallStack[4], TEST_LOCATION);
477 DALI_TEST_EQUALS("ActorA: OnSceneConnection", MasterCallStack[5], TEST_LOCATION);
478 DALI_TEST_EQUALS("ActorA: OnChildRemove", MasterCallStack[6], TEST_LOCATION);
479 DALI_TEST_EQUALS("ActorA: OnChildRemove", MasterCallStack[7], TEST_LOCATION);
481 /* Actors B & C should be removed before the point where they could receive an OnSceneConnection callback
482 * Therefore they shouldn't receive either OnSceneConnection or OnSceneDisconnection
484 DALI_TEST_EQUALS(1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION);
485 DALI_TEST_EQUALS(1, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION);
487 // Excercise the message passing to Update thread
489 application.SendNotification();
490 application.Render();
491 application.Render();
493 // Check everything is ok after last actor is removed
495 stage.Remove(actorA);
496 application.SendNotification();
497 application.Render();
498 application.Render();
502 int UtcDaliCustomActorAddDuringOnSceneDisconnection(void)
504 TestApplication application;
505 tet_infoline("Testing Actor::Add behaviour during Dali::CustomActor::OnSceneDisonnection() callback");
507 Integration::Scene stage = application.GetScene();
509 /* The actorA is a special variant which adds a child to itself during OnSceneDisconnection()
510 * The actorB is provided as the child
513 Test::TestCustomActor actorB = Test::TestCustomActor::New();
514 actorB.SetProperty(Actor::Property::NAME, "ActorB");
516 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant3(actorB);
517 actorA.SetProperty(Actor::Property::NAME, "ActorA");
520 // Excercise the message passing to Update thread
522 application.SendNotification();
523 application.Render();
524 application.Render();
526 // Clear call stacks before disconnection
527 actorA.ResetCallStack();
528 actorB.ResetCallStack();
529 MasterCallStack.clear();
531 stage.Remove(actorA);
533 // Check callback sequence
535 DALI_TEST_EQUALS(2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION);
536 DALI_TEST_EQUALS("OnSceneDisconnection", actorA.GetMethodsCalled()[0], TEST_LOCATION);
537 DALI_TEST_EQUALS("OnChildAdd", actorA.GetMethodsCalled()[1], TEST_LOCATION);
539 // Child was added after parent disconnection, so should not receive OnSceneConnection()
540 DALI_TEST_EQUALS(0, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION);
542 DALI_TEST_EQUALS(2, (int)(MasterCallStack.size()), TEST_LOCATION);
544 DALI_TEST_EQUALS("ActorA: OnSceneDisconnection", MasterCallStack[0], TEST_LOCATION);
545 DALI_TEST_EQUALS("ActorA: OnChildAdd", MasterCallStack[1], TEST_LOCATION);
547 // Excercise the message passing to Update thread
549 application.SendNotification();
550 application.Render();
551 application.Render();
555 int UtcDaliCustomActorRemoveDuringOnSceneDisconnection(void)
557 TestApplication application;
558 tet_infoline("Testing Actor::Remove behaviour during Dali::CustomActor::OnSceneDisconnection() callback");
560 Integration::Scene stage = application.GetScene();
562 /* The actorA is a special variant which removes its children during OnSceneDisconnection()
563 * The actorB is provided as the child
566 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant4();
567 actorA.SetProperty(Actor::Property::NAME, "ActorA");
570 Test::TestCustomActor actorB = Test::TestCustomActor::New();
571 actorB.SetProperty(Actor::Property::NAME, "ActorB");
574 // Excercise the message passing to Update thread
576 application.SendNotification();
577 application.Render();
578 application.Render();
580 // Clear call stacks before disconnection
581 actorA.ResetCallStack();
582 actorB.ResetCallStack();
583 MasterCallStack.clear();
585 stage.Remove(actorA);
587 // Check callback sequence
589 DALI_TEST_EQUALS(2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION);
590 DALI_TEST_EQUALS("OnSceneDisconnection", actorA.GetMethodsCalled()[0], TEST_LOCATION);
591 DALI_TEST_EQUALS("OnChildRemove", actorA.GetMethodsCalled()[1], TEST_LOCATION);
593 DALI_TEST_EQUALS(1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION);
594 DALI_TEST_EQUALS("OnSceneDisconnection", actorB.GetMethodsCalled()[0], TEST_LOCATION);
596 DALI_TEST_EQUALS(3, (int)(MasterCallStack.size()), TEST_LOCATION);
598 DALI_TEST_EQUALS("ActorB: OnSceneDisconnection", MasterCallStack[0], TEST_LOCATION);
599 DALI_TEST_EQUALS("ActorA: OnSceneDisconnection", MasterCallStack[1], TEST_LOCATION);
600 DALI_TEST_EQUALS("ActorA: OnChildRemove", MasterCallStack[2], TEST_LOCATION);
602 // Excercise the message passing to Update thread
604 application.SendNotification();
605 application.Render();
606 application.Render();
610 int UtcDaliCustomActorRemoveParentDuringOnSceneConnection(void)
612 TestApplication application;
613 tet_infoline("Weird test where child removes its own parent from Stage during Dali::CustomActor::OnSceneConnection() callback");
615 Integration::Scene scene = application.GetScene();
617 MasterCallStack.clear();
619 /* The actorA is the parent of actorB
620 * The actorB is a special variant which removes its own parent during OnSceneConnection()
621 * The child actor is interrupting the parent's connection to stage, therefore the parent should not get an OnSceneDisconnection()
624 Test::TestCustomActor actorA = Test::TestCustomActor::New();
625 actorA.SetProperty(Actor::Property::NAME, "ActorA");
627 Test::TestCustomActor actorB = Test::TestCustomActor::NewVariant5(scene);
628 actorB.SetProperty(Actor::Property::NAME, "ActorB");
633 // Check callback sequence
635 DALI_TEST_EQUALS(4, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION);
636 DALI_TEST_EQUALS("OnPropertySet", actorA.GetMethodsCalled()[0], TEST_LOCATION);
637 DALI_TEST_EQUALS("OnChildAdd", actorA.GetMethodsCalled()[1], TEST_LOCATION);
638 DALI_TEST_EQUALS("OnSceneConnection", actorA.GetMethodsCalled()[2], TEST_LOCATION);
639 DALI_TEST_EQUALS("OnSceneDisconnection", actorA.GetMethodsCalled()[3], TEST_LOCATION);
641 DALI_TEST_EQUALS(2, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION);
642 DALI_TEST_EQUALS("OnPropertySet", actorB.GetMethodsCalled()[0], TEST_LOCATION);
643 DALI_TEST_EQUALS("OnSceneConnection", actorB.GetMethodsCalled()[1], TEST_LOCATION);
645 DALI_TEST_EQUALS(6, (int)(MasterCallStack.size()), TEST_LOCATION);
647 DALI_TEST_EQUALS("ActorA: OnPropertySet", MasterCallStack[0], TEST_LOCATION);
648 DALI_TEST_EQUALS("ActorB: OnPropertySet", MasterCallStack[1], TEST_LOCATION);
649 DALI_TEST_EQUALS("ActorA: OnChildAdd", MasterCallStack[2], TEST_LOCATION);
650 DALI_TEST_EQUALS("ActorA: OnSceneConnection", MasterCallStack[3], TEST_LOCATION);
651 DALI_TEST_EQUALS("ActorB: OnSceneConnection", MasterCallStack[4], TEST_LOCATION);
652 DALI_TEST_EQUALS("ActorA: OnSceneDisconnection", MasterCallStack[5], TEST_LOCATION);
654 // Excercise the message passing to Update thread
656 application.SendNotification();
657 application.Render();
658 application.Render();
662 int UtcDaliCustomActorAddParentDuringOnSceneDisconnection(void)
664 TestApplication application;
665 tet_infoline("Weird test where child adds its own parent to Stage during Dali::CustomActor::OnSceneDisconnection() callback");
667 Integration::Scene scene = application.GetScene();
669 MasterCallStack.clear();
671 /* The actorA is the parent of actorB
672 * The actorB is a special variant which (weirdly) adds its own parent during OnSceneDisconnection()
673 * The child actor is interrupting the disconnection, such that parent should not get a OnSceneDisconnection()
676 Test::TestCustomActor actorA = Test::TestCustomActor::New();
677 actorA.SetProperty(Actor::Property::NAME, "ActorA");
680 Test::TestCustomActor actorB = Test::TestCustomActor::NewVariant6(scene);
681 actorB.SetProperty(Actor::Property::NAME, "ActorB");
684 scene.Remove(actorA);
686 // Check callback sequence
688 DALI_TEST_EQUALS(3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION);
689 DALI_TEST_EQUALS("OnPropertySet", actorA.GetMethodsCalled()[0], TEST_LOCATION);
690 DALI_TEST_EQUALS("OnSceneConnection", actorA.GetMethodsCalled()[1], TEST_LOCATION);
691 DALI_TEST_EQUALS("OnChildAdd", actorA.GetMethodsCalled()[2], TEST_LOCATION);
693 DALI_TEST_EQUALS(3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION);
694 DALI_TEST_EQUALS("OnPropertySet", actorB.GetMethodsCalled()[0], TEST_LOCATION);
695 DALI_TEST_EQUALS("OnSceneConnection", actorB.GetMethodsCalled()[1], TEST_LOCATION);
696 DALI_TEST_EQUALS("OnSceneDisconnection", actorB.GetMethodsCalled()[2], TEST_LOCATION);
697 // Disconnect was interrupted, so we should only get one OnSceneConnection() for actorB
699 DALI_TEST_EQUALS(6, (int)(MasterCallStack.size()), TEST_LOCATION);
701 DALI_TEST_EQUALS("ActorA: OnPropertySet", MasterCallStack[0], TEST_LOCATION);
702 DALI_TEST_EQUALS("ActorA: OnSceneConnection", MasterCallStack[1], TEST_LOCATION);
703 DALI_TEST_EQUALS("ActorB: OnPropertySet", MasterCallStack[2], TEST_LOCATION);
704 DALI_TEST_EQUALS("ActorB: OnSceneConnection", MasterCallStack[3], TEST_LOCATION);
705 DALI_TEST_EQUALS("ActorA: OnChildAdd", MasterCallStack[4], TEST_LOCATION);
706 DALI_TEST_EQUALS("ActorB: OnSceneDisconnection", MasterCallStack[5], TEST_LOCATION);
708 // Excercise the message passing to Update thread
710 application.SendNotification();
711 application.Render();
712 application.Render();
716 int UtcDaliCustomActorOnChildAddRemove(void)
718 TestApplication application;
719 tet_infoline("Testing Dali::CustomActor::OnChildAdd() & OnChildRemove()");
721 Test::TestCustomActor custom = Test::TestCustomActor::New();
722 DALI_TEST_EQUALS(0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
724 Actor aChild = Actor::New();
727 DALI_TEST_EQUALS(1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
728 DALI_TEST_EQUALS("OnChildAdd", custom.GetMethodsCalled()[0], TEST_LOCATION);
730 custom.Remove(aChild);
732 DALI_TEST_EQUALS(2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
733 DALI_TEST_EQUALS("OnChildRemove", custom.GetMethodsCalled()[1], TEST_LOCATION);
737 int UtcDaliCustomActorReparentDuringOnChildAdd(void)
739 TestApplication application;
740 tet_infoline("Testing Actor:Add (reparenting) behaviour during Dali::CustomActor::OnChildAdd() callback");
742 Integration::Scene stage = application.GetScene();
744 MasterCallStack.clear();
746 /* The actorA is a special variant which reparents children added into a separate container child
747 * The actorB is the child of actorA
750 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant7("ActorA");
753 Test::TestCustomActor actorB = Test::TestCustomActor::New();
754 actorB.SetProperty(Actor::Property::NAME, "ActorB");
757 // Check hierarchy is as follows:
764 DALI_TEST_EQUALS(1, (int)(actorA.GetChildCount()), TEST_LOCATION);
766 Actor container = actorA.GetChildAt(0);
767 Actor containerChild;
769 DALI_TEST_CHECK(container);
772 DALI_TEST_EQUALS("Container", container.GetProperty<std::string>(Actor::Property::NAME), TEST_LOCATION);
773 DALI_TEST_EQUALS(1, (int)(container.GetChildCount()), TEST_LOCATION);
774 containerChild = container.GetChildAt(0);
777 DALI_TEST_CHECK(containerChild);
780 DALI_TEST_EQUALS("ActorB", containerChild.GetProperty<std::string>(Actor::Property::NAME), TEST_LOCATION);
781 DALI_TEST_EQUALS(0, (int)(containerChild.GetChildCount()), TEST_LOCATION);
784 // Check callback sequence
786 DALI_TEST_EQUALS(5, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION);
787 DALI_TEST_EQUALS("OnPropertySet", actorA.GetMethodsCalled()[0], TEST_LOCATION);
788 DALI_TEST_EQUALS("OnChildAdd", actorA.GetMethodsCalled()[1], TEST_LOCATION); // The mContainer added to actorA
789 DALI_TEST_EQUALS("OnSceneConnection", actorA.GetMethodsCalled()[2], TEST_LOCATION);
790 DALI_TEST_EQUALS("OnChildAdd", actorA.GetMethodsCalled()[3], TEST_LOCATION); // The actorB added to actorA
791 DALI_TEST_EQUALS("OnChildRemove", actorA.GetMethodsCalled()[4], TEST_LOCATION);
792 // mContainer will then receive OnChildAdd
794 DALI_TEST_EQUALS(4, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION);
795 DALI_TEST_EQUALS("OnPropertySet", actorB.GetMethodsCalled()[0], TEST_LOCATION);
796 DALI_TEST_EQUALS("OnSceneConnection", actorB.GetMethodsCalled()[1], TEST_LOCATION);
797 DALI_TEST_EQUALS("OnSceneDisconnection", actorB.GetMethodsCalled()[2], TEST_LOCATION);
798 DALI_TEST_EQUALS("OnSceneConnection", actorB.GetMethodsCalled()[3], TEST_LOCATION);
800 DALI_TEST_EQUALS(9, (int)(MasterCallStack.size()), TEST_LOCATION);
802 DALI_TEST_EQUALS("ActorA: OnPropertySet", MasterCallStack[0], TEST_LOCATION);
803 DALI_TEST_EQUALS("ActorA: OnChildAdd", MasterCallStack[1], TEST_LOCATION);
804 DALI_TEST_EQUALS("ActorA: OnSceneConnection", MasterCallStack[2], TEST_LOCATION);
805 DALI_TEST_EQUALS("ActorB: OnPropertySet", MasterCallStack[3], TEST_LOCATION);
806 DALI_TEST_EQUALS("ActorB: OnSceneConnection", MasterCallStack[4], TEST_LOCATION);
807 DALI_TEST_EQUALS("ActorA: OnChildAdd", MasterCallStack[5], TEST_LOCATION);
808 DALI_TEST_EQUALS("ActorB: OnSceneDisconnection", MasterCallStack[6], TEST_LOCATION);
809 DALI_TEST_EQUALS("ActorA: OnChildRemove", MasterCallStack[7], TEST_LOCATION);
810 DALI_TEST_EQUALS("ActorB: OnSceneConnection", MasterCallStack[8], TEST_LOCATION);
812 // Excercise the message passing to Update thread
814 application.SendNotification();
815 application.Render();
816 application.Render();
821 * Test that Remove can be called (a NOOP) during the OnChildRemove
822 * triggered when reparenting an actor
824 int UtcDaliCustomActorRemoveDuringOnChildRemove(void)
826 TestApplication application;
827 tet_infoline("Testing Actor:Remove behaviour during OnChildRemove() callback triggered when reparenting");
829 Integration::Scene stage = application.GetScene();
831 MasterCallStack.clear();
833 /* The childActor will be reparented from actorA to actorB
834 * The actorA is a special variant which attempts to remove a child from actorB, during the OnChildRemove callback()
835 * This should be a NOOP since the reparenting has not occured yet
838 Test::TestCustomActor actorB = Test::TestCustomActor::New();
839 actorB.SetProperty(Actor::Property::NAME, "ActorB");
842 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant8(actorB);
843 actorA.SetProperty(Actor::Property::NAME, "ActorA");
846 Actor childActor = Actor::New();
847 childActor.SetProperty(Actor::Property::NAME, "Child");
848 // Reparent from actorA to actorB
849 actorA.Add(childActor);
850 actorB.Add(childActor);
852 // Check hierarchy is as follows:
857 DALI_TEST_EQUALS(0, (int)(actorA.GetChildCount()), TEST_LOCATION);
858 DALI_TEST_EQUALS(1, (int)(actorB.GetChildCount()), TEST_LOCATION);
859 DALI_TEST_EQUALS(0, (int)(childActor.GetChildCount()), TEST_LOCATION);
861 Actor child = actorB.GetChildAt(0);
863 DALI_TEST_CHECK(child);
866 DALI_TEST_EQUALS("Child", child.GetProperty<std::string>(Actor::Property::NAME), TEST_LOCATION);
869 // Check callback sequence
871 DALI_TEST_EQUALS(4, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION);
872 DALI_TEST_EQUALS("OnPropertySet", actorA.GetMethodsCalled()[0], TEST_LOCATION);
873 DALI_TEST_EQUALS("OnSceneConnection", actorA.GetMethodsCalled()[1], TEST_LOCATION); // The mContainer added to actorA
874 DALI_TEST_EQUALS("OnChildAdd", actorA.GetMethodsCalled()[2], TEST_LOCATION);
875 DALI_TEST_EQUALS("OnChildRemove", actorA.GetMethodsCalled()[3], TEST_LOCATION); // The actorB added to actorA
876 // mContainer will then receive OnChildAdd
878 DALI_TEST_EQUALS(4, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION);
879 DALI_TEST_EQUALS("OnPropertySet", actorB.GetMethodsCalled()[0], TEST_LOCATION);
880 DALI_TEST_EQUALS("OnSceneConnection", actorB.GetMethodsCalled()[1], TEST_LOCATION);
881 // The derived class are always notified, no matter the child is successfully removed or not
882 DALI_TEST_EQUALS("OnChildRemove", actorB.GetMethodsCalled()[2], TEST_LOCATION);
883 DALI_TEST_EQUALS("OnChildAdd", actorB.GetMethodsCalled()[3], TEST_LOCATION);
885 DALI_TEST_EQUALS(8, (int)(MasterCallStack.size()), TEST_LOCATION);
887 DALI_TEST_EQUALS("ActorB: OnPropertySet", MasterCallStack[0], TEST_LOCATION);
888 DALI_TEST_EQUALS("ActorB: OnSceneConnection", MasterCallStack[1], TEST_LOCATION);
889 DALI_TEST_EQUALS("ActorA: OnPropertySet", MasterCallStack[2], TEST_LOCATION);
890 DALI_TEST_EQUALS("ActorA: OnSceneConnection", MasterCallStack[3], TEST_LOCATION);
891 DALI_TEST_EQUALS("ActorA: OnChildAdd", MasterCallStack[4], TEST_LOCATION);
892 DALI_TEST_EQUALS("ActorA: OnChildRemove", MasterCallStack[5], TEST_LOCATION);
893 // The derived class are always notified, no matter the child is successfully removed or not
894 DALI_TEST_EQUALS("ActorB: OnChildRemove", MasterCallStack[6], TEST_LOCATION);
895 DALI_TEST_EQUALS("ActorB: OnChildAdd", MasterCallStack[7], TEST_LOCATION);
897 // Excercise the message passing to Update thread
899 application.SendNotification();
900 application.Render();
901 application.Render();
905 int UtcDaliCustomActorOnPropertySet(void)
907 TestApplication application;
908 tet_infoline("Testing Dali::CustomActor::OnPropertySet()");
910 Test::TestCustomActor custom = Test::TestCustomActor::New();
911 DALI_TEST_EQUALS(0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
913 custom.SetDaliProperty("yes");
915 DALI_TEST_EQUALS(1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
916 DALI_TEST_EQUALS("OnPropertySet", custom.GetMethodsCalled()[0], TEST_LOCATION);
920 int UtcDaliCustomActorOnSizeSet(void)
922 TestApplication application;
923 tet_infoline("Testing Dali::CustomActor::OnSizeSet()");
925 Test::TestCustomActor custom = Test::TestCustomActor::New();
926 DALI_TEST_EQUALS(0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
928 custom.SetProperty(Actor::Property::SIZE, Vector2(9.0f, 10.0f));
929 DALI_TEST_EQUALS(2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
930 DALI_TEST_EQUALS("OnSizeSet", custom.GetMethodsCalled()[0], TEST_LOCATION);
931 DALI_TEST_EQUALS("OnPropertySet", custom.GetMethodsCalled()[1], TEST_LOCATION);
932 DALI_TEST_EQUALS(9.0f, custom.GetSize().width, TEST_LOCATION);
933 DALI_TEST_EQUALS(10.0f, custom.GetSize().height, TEST_LOCATION);
935 custom.SetProperty(Actor::Property::SIZE, Vector3(4.0f, 5.0f, 6.0f));
936 DALI_TEST_EQUALS(4, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
937 DALI_TEST_EQUALS("OnSizeSet", custom.GetMethodsCalled()[2], TEST_LOCATION);
938 DALI_TEST_EQUALS("OnPropertySet", custom.GetMethodsCalled()[3], TEST_LOCATION);
939 DALI_TEST_EQUALS(4.0f, custom.GetSize().width, TEST_LOCATION);
940 DALI_TEST_EQUALS(5.0f, custom.GetSize().height, TEST_LOCATION);
941 DALI_TEST_EQUALS(6.0f, custom.GetSize().depth, TEST_LOCATION);
945 int UtcDaliCustomActorOnSizeAnimation(void)
947 TestApplication application;
948 tet_infoline("Testing Dali::CustomActor::OnSizeAnimation()");
950 Test::TestCustomActor custom = Test::TestCustomActor::New();
951 DALI_TEST_EQUALS(0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
953 application.GetScene().Add(custom);
955 Animation anim = Animation::New(1.0f);
956 anim.AnimateTo(Property(custom, Actor::Property::SIZE), Vector3(8.0f, 9.0f, 10.0f));
959 application.SendNotification();
960 application.Render(static_cast<unsigned int>(1000.0f));
962 DALI_TEST_EQUALS(2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
963 DALI_TEST_EQUALS("OnSizeAnimation", custom.GetMethodsCalled()[1], TEST_LOCATION);
964 DALI_TEST_EQUALS(8.0f, custom.GetTargetSize().width, TEST_LOCATION);
965 DALI_TEST_EQUALS(9.0f, custom.GetTargetSize().height, TEST_LOCATION);
966 DALI_TEST_EQUALS(10.0f, custom.GetTargetSize().depth, TEST_LOCATION);
970 int UtcDaliCustomActorSizeComponentAnimation(void)
972 TestApplication application;
973 tet_infoline("Testing Size component animation");
975 Test::TestCustomActor custom = Test::TestCustomActor::New();
976 float intialWidth(10.0f);
978 DALI_TEST_EQUALS(0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
980 custom.SetProperty(Actor::Property::SIZE, Vector2(intialWidth, 10.0f)); // First method
981 application.GetScene().Add(custom);
983 Animation anim = Animation::New(1.0f);
985 DALI_TEST_EQUALS(3, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
987 anim.AnimateTo(Property(custom, Actor::Property::SIZE_WIDTH), 20.0f);
989 DALI_TEST_EQUALS(3, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
991 anim.Play(); // Triggers second method ( OnSizeAnimation )
993 application.SendNotification();
994 application.Render(static_cast<unsigned int>(1000.0f));
996 DALI_TEST_EQUALS(4, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION);
998 DALI_TEST_EQUALS("OnSizeAnimation", custom.GetMethodsCalled()[3], TEST_LOCATION);
1003 int UtcDaliCustomActorImplOnPropertySet(void)
1005 TestApplication application;
1006 CustomActorImpl* impl = new Test::Impl::SimpleTestCustomActor();
1007 CustomActor customActor(*impl); // Will automatically unref at the end of this function
1009 impl->OnPropertySet(0, 0);
1011 DALI_TEST_CHECK(true);
1016 int UtcDaliCustomActorGetImplementation(void)
1018 TestApplication application;
1020 Test::TestCustomActor custom = Test::TestCustomActor::New();
1021 CustomActorImpl& impl = custom.GetImplementation();
1022 impl.GetOwner(); // Test
1024 const Test::TestCustomActor constCustom = Test::TestCustomActor::New();
1025 const CustomActorImpl& constImpl = constCustom.GetImplementation();
1026 constImpl.GetOwner(); // Test
1028 DALI_TEST_CHECK(true);
1032 int UtcDaliCustomActorDoAction(void)
1034 TestApplication application;
1035 tet_infoline("Testing Dali::CustomActor::DoAction()");
1037 Test::TestCustomActor custom = Test::TestCustomActor::New();
1039 BaseHandle customActorObject = custom;
1041 DALI_TEST_CHECK(customActorObject);
1043 Property::Map attributes;
1045 // Check that an invalid command is not performed
1046 DALI_TEST_CHECK(customActorObject.DoAction("invalidCommand", attributes) == false);
1048 // Check that the custom actor is visible
1049 custom.SetProperty(Actor::Property::VISIBLE, true);
1050 DALI_TEST_CHECK(custom.GetCurrentProperty<bool>(Actor::Property::VISIBLE) == true);
1052 // Check the custom actor performed an action to hide itself
1053 DALI_TEST_CHECK(customActorObject.DoAction("hide", attributes) == true);
1055 // flush the queue and render once
1056 application.SendNotification();
1057 application.Render();
1059 // Check that the custom actor is now invisible
1060 DALI_TEST_CHECK(custom.GetCurrentProperty<bool>(Actor::Property::VISIBLE) == false);
1062 // Check the custom actor performed an action to show itself
1063 DALI_TEST_CHECK(customActorObject.DoAction("show", attributes) == true);
1065 // flush the queue and render once
1066 application.SendNotification();
1067 application.Render();
1069 // Check that the custom actor is now visible
1070 DALI_TEST_CHECK(custom.GetCurrentProperty<bool>(Actor::Property::VISIBLE) == true);
1074 int UtcDaliCustomActorCustomActor(void)
1076 Dali::CustomActor customA;
1077 Dali::CustomActor customB(customA);
1079 DALI_TEST_CHECK(customA == customB);
1084 int UtcDaliCustomActorImplRelayoutRequest(void)
1086 TestApplication application;
1088 DALI_TEST_CHECK(gOnRelayout == false);
1090 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1091 application.GetScene().Add(custom);
1093 application.SendNotification();
1094 application.Render();
1096 DALI_TEST_CHECK(gOnRelayout == true);
1097 gOnRelayout = false;
1099 custom.TestRelayoutRequest();
1100 application.SendNotification();
1101 application.Render();
1103 DALI_TEST_CHECK(gOnRelayout == true);
1108 int UtcDaliCustomActorImplGetHeightForWidthBase(void)
1110 TestApplication application;
1111 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1113 float width = 300.0f;
1115 application.SendNotification();
1116 application.Render();
1118 float v = custom.TestGetHeightForWidthBase(width);
1120 DALI_TEST_CHECK(v == width);
1125 int UtcDaliCustomActorImplGetWidthForHeightBase(void)
1127 TestApplication application;
1128 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1130 float height = 300.0f;
1132 application.SendNotification();
1133 application.Render();
1135 float v = custom.TestGetWidthForHeightBase(height);
1137 DALI_TEST_CHECK(v == height);
1142 int UtcDaliCustomActorImplCalculateChildSizeBase(void)
1144 TestApplication application;
1145 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1147 Actor child = Actor::New();
1148 child.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1149 child.SetProperty(Actor::Property::SIZE, Vector2(150, 150));
1151 application.SendNotification();
1152 application.Render();
1154 float v = custom.TestCalculateChildSizeBase(child, Dali::Dimension::ALL_DIMENSIONS);
1155 DALI_TEST_CHECK(v == 0.0f);
1160 int UtcDaliCustomActorImplRelayoutDependentOnChildrenBase(void)
1162 TestApplication application;
1163 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1164 custom.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS);
1166 bool v = custom.TestRelayoutDependentOnChildrenBase(Dali::Dimension::ALL_DIMENSIONS);
1167 DALI_TEST_CHECK(v == true);
1169 application.SendNotification();
1170 application.Render();
1172 custom.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1173 v = custom.TestRelayoutDependentOnChildrenBase(Dali::Dimension::WIDTH);
1174 DALI_TEST_CHECK(v == false);
1176 // why is this here?
1177 application.SendNotification();
1178 application.Render();
1183 int UtcDaliCustomActorTypeRegistry(void)
1185 TestApplication application;
1189 type = TypeRegistry::Get().GetTypeInfo("CustomActor");
1190 DALI_TEST_CHECK(type);
1191 BaseHandle handle = type.CreateInstance();
1194 std::string exception;
1198 name = handle.GetTypeName();
1199 tet_result(TET_FAIL);
1201 catch(DaliException& e)
1203 exception = e.condition;
1204 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();
1244 Test::TestCustomActor actorB = Test::TestCustomActor::New();
1247 Test::TestCustomActor actorC = Test::TestCustomActor::New();
1250 Test::TestCustomActor actorD = Test::TestCustomActor::New();
1253 Test::TestCustomActor actorE = Test::TestCustomActor::New();
1256 Test::TestCustomActor actorF = Test::TestCustomActor::New();
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);
1274 int UtcDaliCustomActorSetGetProperty(void)
1276 TestApplication application; // Need the type registry
1278 Test::TestCustomActor actor = Test::TestCustomActor::New();
1279 application.GetScene().Add(actor);
1281 actor.SetProperty(Test::TestCustomActor::Property::TEST_PROPERTY1, 0.5f);
1282 actor.SetProperty(Test::TestCustomActor::Property::TEST_PROPERTY2, Color::WHITE);
1283 actor.SetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3, Color::BLUE);
1284 actor.SetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4, 20);
1285 actor.SetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5, 40.0f);
1287 Property::Value value = actor.GetProperty(Test::TestCustomActor::Property::TEST_PROPERTY1);
1288 DALI_TEST_EQUALS(value.Get<float>(), 0.5f, 0.001f, TEST_LOCATION);
1290 value = actor.GetProperty(Test::TestCustomActor::Property::TEST_PROPERTY2);
1291 DALI_TEST_EQUALS(value.Get<Vector4>(), Color::WHITE, 0.001f, TEST_LOCATION);
1293 value = actor.GetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3);
1294 DALI_TEST_EQUALS(value.Get<Vector4>(), Color::BLUE, 0.001f, TEST_LOCATION);
1296 value = actor.GetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4);
1297 DALI_TEST_EQUALS(value.Get<int>(), 20, TEST_LOCATION);
1299 value = actor.GetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5);
1300 DALI_TEST_EQUALS(value.Get<float>(), 40.0f, 0.001f, TEST_LOCATION);
1302 // Get read-only property
1303 value = actor.GetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6);
1304 DALI_TEST_EQUALS(value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION);
1306 // Attempt to set read-only property and then ensure value hasn't changed
1307 actor.SetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6, 40.0f);
1308 DALI_TEST_EQUALS(value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION);
1313 int utcDaliActorGetTypeInfo(void)
1315 TestApplication application;
1316 tet_infoline("Get the type info of a derived actor");
1318 Test::TestCustomActor customActor = Test::TestCustomActor::New();
1320 Dali::TypeInfo typeInfo = Dali::DevelCustomActor::GetTypeInfo(customActor);
1322 DALI_TEST_EQUALS(typeInfo.GetName(), std::string("TestCustomActor"), TEST_LOCATION);
1330 * A custom actor that is not type registered on purpose
1332 struct UnregisteredCustomActor : public Dali::CustomActorImpl
1334 UnregisteredCustomActor()
1335 : CustomActorImpl(ACTOR_BEHAVIOUR_DEFAULT)
1338 virtual ~UnregisteredCustomActor()
1341 virtual void OnSceneConnection(int32_t depth)
1344 virtual void OnSceneDisconnection()
1347 virtual void OnChildAdd(Actor& child)
1350 virtual void OnChildRemove(Actor& child)
1353 virtual void OnPropertySet(Property::Index index, const Property::Value& propertyValue)
1356 virtual void OnSizeSet(const Vector3& targetSize)
1359 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1362 virtual bool OnHoverEvent(const HoverEvent& event)
1366 virtual bool OnWheelEvent(const WheelEvent& event)
1370 virtual void OnRelayout(const Vector2& size, RelayoutContainer& container)
1373 virtual void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension)
1376 virtual Vector3 GetNaturalSize()
1380 virtual float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension)
1384 virtual float GetHeightForWidth(float width)
1388 virtual float GetWidthForHeight(float height)
1392 virtual bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS)
1396 virtual void OnCalculateRelayoutSize(Dimension::Type dimension)
1399 virtual void OnLayoutNegotiated(float size, Dimension::Type dimension)
1404 struct UnregisteredCustomActor : public Dali::CustomActor
1406 static UnregisteredCustomActor New()
1408 Impl::UnregisteredCustomActor* impl = new Impl::UnregisteredCustomActor;
1409 UnregisteredCustomActor custom(*impl); // takes ownership
1412 UnregisteredCustomActor()
1415 ~UnregisteredCustomActor()
1418 UnregisteredCustomActor(Internal::CustomActor* impl)
1422 UnregisteredCustomActor(Impl::UnregisteredCustomActor& impl)
1426 static UnregisteredCustomActor DownCast(BaseHandle handle)
1428 UnregisteredCustomActor hndl;
1429 CustomActor custom = Dali::CustomActor::DownCast(handle);
1432 CustomActorImpl& customImpl = custom.GetImplementation();
1434 Impl::UnregisteredCustomActor* impl = dynamic_cast<Impl::UnregisteredCustomActor*>(&customImpl);
1438 hndl = UnregisteredCustomActor(customImpl.GetOwner());
1445 int UtcDaliCustomActorSetGetActorPropertyActionSignal(void)
1447 TestApplication application; // Need the type registry
1449 auto custom = UnregisteredCustomActor::New();
1450 application.GetScene().Add(custom);
1452 // should have all actor properties
1453 DALI_TEST_EQUALS(custom.GetPropertyType(Actor::Property::COLOR), Property::VECTOR4, TEST_LOCATION);
1454 auto actorHandle = Actor::New();
1455 DALI_TEST_EQUALS(custom.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION);
1457 DALI_TEST_EQUALS(custom.GetCurrentProperty<bool>(Actor::Property::VISIBLE), true, TEST_LOCATION);
1458 custom.SetProperty(Actor::Property::VISIBLE, false);
1459 application.SendNotification();
1460 application.Render(); // IsVisible returns scene value
1461 DALI_TEST_EQUALS(custom.GetCurrentProperty<bool>(Actor::Property::VISIBLE), false, TEST_LOCATION);
1463 // should have custom actor typename (as it has not registered itself)
1464 DALI_TEST_EQUALS("CustomActor", custom.GetTypeName(), TEST_LOCATION);
1466 // should have actor actions
1467 custom.DoAction("show", Property::Map());
1468 DALI_TEST_EQUALS(custom.GetProperty(Actor::Property::VISIBLE).Get<bool>(), true, TEST_LOCATION);
1470 Animation animation = Animation::New(0.01f); // very short animation
1471 // should be able to animate actor property
1472 animation.AnimateTo(Property(custom, Actor::Property::POSITION), Vector3(100.0f, 150.0f, 200.0f));
1475 application.SendNotification();
1476 application.Render(1000.f);
1478 DALI_TEST_EQUALS(Vector3(100.0f, 150.0f, 200.0f), custom.GetProperty(Actor::Property::POSITION).Get<Vector3>(), TEST_LOCATION);
1479 DALI_TEST_EQUALS(Vector3(100.0f, 150.0f, 200.0f), custom.GetCurrentProperty<Vector3>(Actor::Property::POSITION), TEST_LOCATION);
1481 Dali::WeakHandle<UnregisteredCustomActor> weakRef(custom);
1482 // should have actor signals
1483 custom.ConnectSignal(&application, "offScene", [weakRef]() {
1484 DALI_TEST_EQUALS(weakRef.GetHandle().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE), false, TEST_LOCATION);
1487 application.GetScene().Remove(custom);
1488 application.GetScene().Add(custom);
1495 struct DerivedCustomActor : public UnregisteredCustomActor
1500 struct DerivedCustomActor : public UnregisteredCustomActor
1502 static DerivedCustomActor New()
1504 Impl::DerivedCustomActor* impl = new Impl::DerivedCustomActor;
1505 DerivedCustomActor custom(*impl); // takes ownership
1508 DerivedCustomActor()
1511 ~DerivedCustomActor()
1514 DerivedCustomActor(Internal::CustomActor* impl)
1515 : UnregisteredCustomActor(impl)
1518 DerivedCustomActor(Impl::UnregisteredCustomActor& impl)
1519 : UnregisteredCustomActor(impl)
1525 DALI_TYPE_REGISTRATION_BEGIN(DerivedCustomActor, UnregisteredCustomActor, nullptr);
1526 DALI_TYPE_REGISTRATION_END()
1528 int UtcDaliCustomActorPropertyRegistrationDefaultValue(void)
1530 TestApplication application; // Need the type registry
1532 // register our base and add a property with default value for it
1533 Dali::TypeRegistration typeRegistration(typeid(UnregisteredCustomActor), typeid(Dali::CustomActor), nullptr);
1535 auto derived = DerivedCustomActor::New();
1536 application.GetScene().Add(derived);
1538 // should have all actor properties
1539 DALI_TEST_EQUALS(derived.GetPropertyType(Actor::Property::WORLD_MATRIX), Property::MATRIX, TEST_LOCATION);
1540 auto actorHandle = Actor::New();
1541 DALI_TEST_EQUALS(derived.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION);
1543 // add a property in base class
1544 AnimatablePropertyRegistration(typeRegistration, "Foobar", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, 10.f);
1546 // should be one more property now
1547 DALI_TEST_EQUALS(derived.GetPropertyCount(), actorHandle.GetPropertyCount() + 1, TEST_LOCATION);
1548 // check that the default value is set for base class
1549 DALI_TEST_EQUALS(UnregisteredCustomActor::New().GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION);
1550 // check that the default value is set for the derived instance as well
1551 DALI_TEST_EQUALS(derived.GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION);