2 * Copyright (c) 2021 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 UtcDaliCustomActorImplSetTransparent(void)
1086 TestApplication application; // Need the type registry
1088 Test::TestCustomActor actor = Test::TestCustomActor::New();
1089 application.GetScene().Add(actor);
1090 actor.SetProperty(Actor::Property::OPACITY, 0.1f);
1091 actor.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
1093 DALI_TEST_EQUALS(false, actor.GetTransparent(), TEST_LOCATION);
1095 actor.SetTransparent(true);
1097 // flush the queue and render once
1098 application.SendNotification();
1099 application.Render();
1101 DALI_TEST_EQUALS(true, actor.GetTransparent(), TEST_LOCATION);
1103 application.GetScene().Remove(actor);
1107 int UtcDaliCustomActorImplRelayoutRequest(void)
1109 TestApplication application;
1111 DALI_TEST_CHECK(gOnRelayout == false);
1113 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1114 application.GetScene().Add(custom);
1116 application.SendNotification();
1117 application.Render();
1119 DALI_TEST_CHECK(gOnRelayout == true);
1120 gOnRelayout = false;
1122 custom.TestRelayoutRequest();
1123 application.SendNotification();
1124 application.Render();
1126 DALI_TEST_CHECK(gOnRelayout == true);
1131 int UtcDaliCustomActorImplGetHeightForWidthBase(void)
1133 TestApplication application;
1134 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1136 float width = 300.0f;
1138 application.SendNotification();
1139 application.Render();
1141 float v = custom.TestGetHeightForWidthBase(width);
1143 DALI_TEST_CHECK(v == width);
1148 int UtcDaliCustomActorImplGetWidthForHeightBase(void)
1150 TestApplication application;
1151 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1153 float height = 300.0f;
1155 application.SendNotification();
1156 application.Render();
1158 float v = custom.TestGetWidthForHeightBase(height);
1160 DALI_TEST_CHECK(v == height);
1165 int UtcDaliCustomActorImplCalculateChildSizeBase(void)
1167 TestApplication application;
1168 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1170 Actor child = Actor::New();
1171 child.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1172 child.SetProperty(Actor::Property::SIZE, Vector2(150, 150));
1174 application.SendNotification();
1175 application.Render();
1177 float v = custom.TestCalculateChildSizeBase(child, Dali::Dimension::ALL_DIMENSIONS);
1178 DALI_TEST_CHECK(v == 0.0f);
1183 int UtcDaliCustomActorImplRelayoutDependentOnChildrenBase(void)
1185 TestApplication application;
1186 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1187 custom.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS);
1189 bool v = custom.TestRelayoutDependentOnChildrenBase(Dali::Dimension::ALL_DIMENSIONS);
1190 DALI_TEST_CHECK(v == true);
1192 application.SendNotification();
1193 application.Render();
1195 custom.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1196 v = custom.TestRelayoutDependentOnChildrenBase(Dali::Dimension::WIDTH);
1197 DALI_TEST_CHECK(v == false);
1199 // why is this here?
1200 application.SendNotification();
1201 application.Render();
1206 int UtcDaliCustomActorTypeRegistry(void)
1208 TestApplication application;
1212 type = TypeRegistry::Get().GetTypeInfo("CustomActor");
1213 DALI_TEST_CHECK(type);
1214 BaseHandle handle = type.CreateInstance();
1217 std::string exception;
1221 name = handle.GetTypeName();
1222 tet_result(TET_FAIL);
1224 catch(DaliException& e)
1226 exception = e.condition;
1227 DALI_TEST_EQUALS(exception, "handle && \"BaseObject handle is empty\"", TEST_LOCATION);
1233 int UtcDaliCustomActorGetExtensionP(void)
1235 TestApplication application;
1237 Test::TestCustomActor custom = Test::TestCustomActor::NewVariant5(application.GetScene());
1239 DALI_TEST_CHECK(NULL == custom.GetImplementation().GetExtension());
1244 int UtcDaliCustomActorOnConnectionDepth(void)
1246 TestApplication application;
1247 tet_infoline("Testing Dali::CustomActor::OnSceneConnection() hierarchy depth");
1249 Integration::Scene stage = application.GetScene();
1251 /* Build tree of actors:
1261 * OnSceneConnection should return 1 for A, 2 for B and C, and 3 for D, E and F.
1264 Test::TestCustomActor actorA = Test::TestCustomActor::New();
1267 Test::TestCustomActor actorB = Test::TestCustomActor::New();
1270 Test::TestCustomActor actorC = Test::TestCustomActor::New();
1273 Test::TestCustomActor actorD = Test::TestCustomActor::New();
1276 Test::TestCustomActor actorE = Test::TestCustomActor::New();
1279 Test::TestCustomActor actorF = Test::TestCustomActor::New();
1282 // Excercise the message passing to Update thread
1283 application.SendNotification();
1284 application.Render();
1285 application.Render();
1287 DALI_TEST_EQUALS(1u, actorA.GetDepth(), TEST_LOCATION);
1288 DALI_TEST_EQUALS(2u, actorB.GetDepth(), TEST_LOCATION);
1289 DALI_TEST_EQUALS(2u, actorC.GetDepth(), TEST_LOCATION);
1290 DALI_TEST_EQUALS(3u, actorD.GetDepth(), TEST_LOCATION);
1291 DALI_TEST_EQUALS(3u, actorE.GetDepth(), TEST_LOCATION);
1292 DALI_TEST_EQUALS(3u, actorF.GetDepth(), TEST_LOCATION);
1297 int UtcDaliCustomActorSetGetProperty(void)
1299 TestApplication application; // Need the type registry
1301 Test::TestCustomActor actor = Test::TestCustomActor::New();
1302 application.GetScene().Add(actor);
1304 actor.SetProperty(Test::TestCustomActor::Property::TEST_PROPERTY1, 0.5f);
1305 actor.SetProperty(Test::TestCustomActor::Property::TEST_PROPERTY2, Color::WHITE);
1306 actor.SetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3, Color::BLUE);
1307 actor.SetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4, 20);
1308 actor.SetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5, 40.0f);
1310 Property::Value value = actor.GetProperty(Test::TestCustomActor::Property::TEST_PROPERTY1);
1311 DALI_TEST_EQUALS(value.Get<float>(), 0.5f, 0.001f, TEST_LOCATION);
1313 value = actor.GetProperty(Test::TestCustomActor::Property::TEST_PROPERTY2);
1314 DALI_TEST_EQUALS(value.Get<Vector4>(), Color::WHITE, 0.001f, TEST_LOCATION);
1316 value = actor.GetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3);
1317 DALI_TEST_EQUALS(value.Get<Vector4>(), Color::BLUE, 0.001f, TEST_LOCATION);
1319 value = actor.GetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4);
1320 DALI_TEST_EQUALS(value.Get<int>(), 20, TEST_LOCATION);
1322 value = actor.GetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5);
1323 DALI_TEST_EQUALS(value.Get<float>(), 40.0f, 0.001f, TEST_LOCATION);
1325 // Get read-only property
1326 value = actor.GetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6);
1327 DALI_TEST_EQUALS(value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION);
1329 // Attempt to set read-only property and then ensure value hasn't changed
1330 actor.SetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6, 40.0f);
1331 DALI_TEST_EQUALS(value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION);
1336 int utcDaliActorGetTypeInfo(void)
1338 TestApplication application;
1339 tet_infoline("Get the type info of a derived actor");
1341 Test::TestCustomActor customActor = Test::TestCustomActor::New();
1343 Dali::TypeInfo typeInfo = Dali::DevelCustomActor::GetTypeInfo(customActor);
1345 DALI_TEST_EQUALS(typeInfo.GetName(), std::string("TestCustomActor"), TEST_LOCATION);
1353 * A custom actor that is not type registered on purpose
1355 struct UnregisteredCustomActor : public Dali::CustomActorImpl
1357 UnregisteredCustomActor()
1358 : CustomActorImpl(ACTOR_BEHAVIOUR_DEFAULT)
1361 virtual ~UnregisteredCustomActor()
1364 virtual void OnSceneConnection(int32_t depth)
1367 virtual void OnSceneDisconnection()
1370 virtual void OnChildAdd(Actor& child)
1373 virtual void OnChildRemove(Actor& child)
1376 virtual void OnPropertySet(Property::Index index, const Property::Value& propertyValue)
1379 virtual void OnSizeSet(const Vector3& targetSize)
1382 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1385 virtual bool OnHoverEvent(const HoverEvent& event)
1389 virtual bool OnWheelEvent(const WheelEvent& event)
1393 virtual void OnRelayout(const Vector2& size, RelayoutContainer& container)
1396 virtual void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension)
1399 virtual Vector3 GetNaturalSize()
1403 virtual float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension)
1407 virtual float GetHeightForWidth(float width)
1411 virtual float GetWidthForHeight(float height)
1415 virtual bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS)
1419 virtual void OnCalculateRelayoutSize(Dimension::Type dimension)
1422 virtual void OnLayoutNegotiated(float size, Dimension::Type dimension)
1427 struct UnregisteredCustomActor : public Dali::CustomActor
1429 static UnregisteredCustomActor New()
1431 Impl::UnregisteredCustomActor* impl = new Impl::UnregisteredCustomActor;
1432 UnregisteredCustomActor custom(*impl); // takes ownership
1435 UnregisteredCustomActor()
1438 ~UnregisteredCustomActor()
1441 UnregisteredCustomActor(Internal::CustomActor* impl)
1445 UnregisteredCustomActor(Impl::UnregisteredCustomActor& impl)
1449 static UnregisteredCustomActor DownCast(BaseHandle handle)
1451 UnregisteredCustomActor hndl;
1452 CustomActor custom = Dali::CustomActor::DownCast(handle);
1455 CustomActorImpl& customImpl = custom.GetImplementation();
1457 Impl::UnregisteredCustomActor* impl = dynamic_cast<Impl::UnregisteredCustomActor*>(&customImpl);
1461 hndl = UnregisteredCustomActor(customImpl.GetOwner());
1468 int UtcDaliCustomActorSetGetActorPropertyActionSignal(void)
1470 TestApplication application; // Need the type registry
1472 auto custom = UnregisteredCustomActor::New();
1473 application.GetScene().Add(custom);
1475 // should have all actor properties
1476 DALI_TEST_EQUALS(custom.GetPropertyType(Actor::Property::COLOR), Property::VECTOR4, TEST_LOCATION);
1477 auto actorHandle = Actor::New();
1478 DALI_TEST_EQUALS(custom.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION);
1480 DALI_TEST_EQUALS(custom.GetCurrentProperty<bool>(Actor::Property::VISIBLE), true, TEST_LOCATION);
1481 custom.SetProperty(Actor::Property::VISIBLE, false);
1482 application.SendNotification();
1483 application.Render(); // IsVisible returns scene value
1484 DALI_TEST_EQUALS(custom.GetCurrentProperty<bool>(Actor::Property::VISIBLE), false, TEST_LOCATION);
1486 // should have custom actor typename (as it has not registered itself)
1487 DALI_TEST_EQUALS("CustomActor", custom.GetTypeName(), TEST_LOCATION);
1489 // should have actor actions
1490 custom.DoAction("show", Property::Map());
1491 DALI_TEST_EQUALS(custom.GetProperty(Actor::Property::VISIBLE).Get<bool>(), true, TEST_LOCATION);
1493 Animation animation = Animation::New(0.01f); // very short animation
1494 // should be able to animate actor property
1495 animation.AnimateTo(Property(custom, Actor::Property::POSITION), Vector3(100.0f, 150.0f, 200.0f));
1498 application.SendNotification();
1499 application.Render(1000.f);
1501 DALI_TEST_EQUALS(Vector3(100.0f, 150.0f, 200.0f), custom.GetProperty(Actor::Property::POSITION).Get<Vector3>(), TEST_LOCATION);
1502 DALI_TEST_EQUALS(Vector3(100.0f, 150.0f, 200.0f), custom.GetCurrentProperty<Vector3>(Actor::Property::POSITION), TEST_LOCATION);
1504 Dali::WeakHandle<UnregisteredCustomActor> weakRef(custom);
1505 // should have actor signals
1506 custom.ConnectSignal(&application, "offScene", [weakRef]() {
1507 DALI_TEST_EQUALS(weakRef.GetHandle().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE), false, TEST_LOCATION);
1510 application.GetScene().Remove(custom);
1511 application.GetScene().Add(custom);
1518 struct DerivedCustomActor : public UnregisteredCustomActor
1523 struct DerivedCustomActor : public UnregisteredCustomActor
1525 static DerivedCustomActor New()
1527 Impl::DerivedCustomActor* impl = new Impl::DerivedCustomActor;
1528 DerivedCustomActor custom(*impl); // takes ownership
1531 DerivedCustomActor()
1534 ~DerivedCustomActor()
1537 DerivedCustomActor(Internal::CustomActor* impl)
1538 : UnregisteredCustomActor(impl)
1541 DerivedCustomActor(Impl::UnregisteredCustomActor& impl)
1542 : UnregisteredCustomActor(impl)
1548 DALI_TYPE_REGISTRATION_BEGIN(DerivedCustomActor, UnregisteredCustomActor, nullptr);
1549 DALI_TYPE_REGISTRATION_END()
1551 int UtcDaliCustomActorPropertyRegistrationDefaultValue(void)
1553 TestApplication application; // Need the type registry
1555 // register our base and add a property with default value for it
1556 Dali::TypeRegistration typeRegistration(typeid(UnregisteredCustomActor), typeid(Dali::CustomActor), nullptr);
1558 auto derived = DerivedCustomActor::New();
1559 application.GetScene().Add(derived);
1561 // should have all actor properties
1562 DALI_TEST_EQUALS(derived.GetPropertyType(Actor::Property::WORLD_MATRIX), Property::MATRIX, TEST_LOCATION);
1563 auto actorHandle = Actor::New();
1564 DALI_TEST_EQUALS(derived.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION);
1566 // add a property in base class
1567 AnimatablePropertyRegistration(typeRegistration, "Foobar", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, 10.f);
1569 // should be one more property now
1570 DALI_TEST_EQUALS(derived.GetPropertyCount(), actorHandle.GetPropertyCount() + 1, TEST_LOCATION);
1571 // check that the default value is set for base class
1572 DALI_TEST_EQUALS(UnregisteredCustomActor::New().GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION);
1573 // check that the default value is set for the derived instance as well
1574 DALI_TEST_EQUALS(derived.GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION);