2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <dali/public-api/dali-core.h>
22 #include <dali/devel-api/actors/custom-actor-devel.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali/integration-api/events/hover-event-integ.h>
25 #include <dali/integration-api/events/wheel-event-integ.h>
26 #include <dali/integration-api/events/key-event-integ.h>
27 #include <dali/public-api/object/type-registry-helper.h>
28 #include "dali-test-suite-utils/dali-test-suite-utils.h"
29 #include "test-custom-actor.h"
34 void custom_actor_test_startup(void)
36 test_return_value = TET_UNDEF;
39 void custom_actor_test_cleanup(void)
41 test_return_value = TET_PASS;
49 int UtcDaliCustomActorDestructor(void)
51 TestApplication application;
53 CustomActor* actor = new CustomActor();
56 DALI_TEST_CHECK( true );
60 int UtcDaliCustomActorImplDestructor(void)
62 TestApplication application;
63 CustomActorImpl* actor = new Test::Impl::TestCustomActor();
64 CustomActor customActor( *actor ); // Will automatically unref at the end of this function
66 DALI_TEST_CHECK( true );
70 // Positive test case for a method
71 int UtcDaliCustomActorDownCast(void)
73 TestApplication application;
74 tet_infoline("Testing Dali::CustomActor::DownCast()");
76 Test::TestCustomActor custom = Test::TestCustomActor::New();
78 Actor anActor = Actor::New();
79 anActor.Add( custom );
81 Actor child = anActor.GetChildAt(0);
82 CustomActor customActor = CustomActor::DownCast( child );
83 DALI_TEST_CHECK( customActor );
86 DALI_TEST_CHECK( !customActor );
88 customActor = DownCast< CustomActor >( child );
89 DALI_TEST_CHECK( customActor );
93 // Negative test case for a method
94 int UtcDaliCustomActorDownCastNegative(void)
96 TestApplication application;
97 tet_infoline("Testing Dali::CustomActor::DownCast()");
99 Actor actor1 = Actor::New();
100 Actor anActor = Actor::New();
103 Actor child = anActor.GetChildAt(0);
104 CustomActor customActor = CustomActor::DownCast( child );
105 DALI_TEST_CHECK( !customActor );
107 Actor unInitialzedActor;
108 customActor = CustomActor::DownCast( unInitialzedActor );
109 DALI_TEST_CHECK( !customActor );
111 customActor = DownCast< CustomActor >( unInitialzedActor );
112 DALI_TEST_CHECK( !customActor );
116 int UtcDaliCustomActorOnStageConnectionDisconnection(void)
118 TestApplication application;
119 tet_infoline("Testing Dali::CustomActor::OnStageConnection() & OnStageDisconnection");
121 Test::TestCustomActor custom = Test::TestCustomActor::New();
122 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
124 // add the custom actor to stage
125 Stage::GetCurrent().Add( custom );
127 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
128 DALI_TEST_EQUALS( "OnStageConnection", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
130 Stage::GetCurrent().Remove( custom );
132 DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
133 DALI_TEST_EQUALS( "OnStageDisconnection", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
135 // Excercise the message passing to Update thread
137 application.SendNotification();
138 application.Render();
139 application.Render();
143 int UtcDaliCustomActorOnStageConnectionOrder(void)
145 TestApplication application;
146 tet_infoline("Testing Dali::CustomActor::OnStageConnection() order");
148 MasterCallStack.clear();
150 /* Build tree of actors:
158 * OnStageConnection should be received for A, B, D, E, C, and finally F
161 Test::TestCustomActor actorA = Test::TestCustomActor::New();
162 actorA.SetName( "ActorA" );
164 Test::TestCustomActor actorB = Test::TestCustomActor::New();
165 actorB.SetName( "ActorB" );
166 actorA.Add( actorB );
168 Test::TestCustomActor actorC = Test::TestCustomActor::New();
169 actorC.SetName( "ActorC" );
170 actorA.Add( actorC );
172 Test::TestCustomActor actorD = Test::TestCustomActor::New();
173 actorD.SetName( "ActorD" );
174 actorB.Add( actorD );
176 Test::TestCustomActor actorE = Test::TestCustomActor::New();
177 actorE.SetName( "ActorE" );
178 actorB.Add( actorE );
180 Test::TestCustomActor actorF = Test::TestCustomActor::New();
181 actorF.SetName( "ActorF" );
182 actorC.Add( actorF );
184 // add the custom actor to stage
185 Stage::GetCurrent().Add( actorA );
187 DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
188 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
189 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
190 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
192 DALI_TEST_EQUALS( 3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
193 DALI_TEST_EQUALS( "OnChildAdd", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
194 DALI_TEST_EQUALS( "OnChildAdd", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
195 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
197 DALI_TEST_EQUALS( 2, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
198 DALI_TEST_EQUALS( "OnChildAdd", actorC.GetMethodsCalled()[ 0 ], TEST_LOCATION );
199 DALI_TEST_EQUALS( "OnStageConnection", actorC.GetMethodsCalled()[ 1 ], TEST_LOCATION );
201 DALI_TEST_EQUALS( 1, (int)(actorD.GetMethodsCalled().size()), TEST_LOCATION );
202 DALI_TEST_EQUALS( "OnStageConnection", actorD.GetMethodsCalled()[ 0 ], TEST_LOCATION );
204 DALI_TEST_EQUALS( 1, (int)(actorE.GetMethodsCalled().size()), TEST_LOCATION );
205 DALI_TEST_EQUALS( "OnStageConnection", actorE.GetMethodsCalled()[ 0 ], TEST_LOCATION );
207 DALI_TEST_EQUALS( 1, (int)(actorF.GetMethodsCalled().size()), TEST_LOCATION );
208 DALI_TEST_EQUALS( "OnStageConnection", actorF.GetMethodsCalled()[ 0 ], TEST_LOCATION );
210 // Check sequence is correct in MasterCallStack
212 DALI_TEST_EQUALS( 3+3+2+1+1+1, (int)(MasterCallStack.size()), TEST_LOCATION );
214 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 0 ], TEST_LOCATION );
215 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 1 ], TEST_LOCATION );
216 DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION );
217 DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 3 ], TEST_LOCATION );
218 DALI_TEST_EQUALS( "ActorC: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION );
220 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 5 ], TEST_LOCATION );
221 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 6 ], TEST_LOCATION );
222 DALI_TEST_EQUALS( "ActorD: OnStageConnection", MasterCallStack[ 7 ], TEST_LOCATION );
223 DALI_TEST_EQUALS( "ActorE: OnStageConnection", MasterCallStack[ 8 ], TEST_LOCATION );
224 DALI_TEST_EQUALS( "ActorC: OnStageConnection", MasterCallStack[ 9 ], TEST_LOCATION );
225 DALI_TEST_EQUALS( "ActorF: OnStageConnection", MasterCallStack[ 10 ], TEST_LOCATION );
227 // Excercise the message passing to Update thread
229 application.SendNotification();
230 application.Render();
231 application.Render();
235 int UtcDaliCustomActorOnStageDisconnectionOrder(void)
237 TestApplication application;
238 tet_infoline("Testing Dali::CustomActor::OnStageDisconnection() order");
240 Stage stage = Stage::GetCurrent();
242 /* Build tree of actors:
250 * OnStageDisconnection should be received for D, E, B, F, C, and finally A.
253 Test::TestCustomActor actorA = Test::TestCustomActor::New();
254 actorA.SetName( "ActorA" );
257 Test::TestCustomActor actorB = Test::TestCustomActor::New();
258 actorB.SetName( "ActorB" );
259 actorA.Add( actorB );
261 Test::TestCustomActor actorC = Test::TestCustomActor::New();
262 actorC.SetName( "ActorC" );
263 actorA.Add( actorC );
265 Test::TestCustomActor actorD = Test::TestCustomActor::New();
266 actorD.SetName( "ActorD" );
267 actorB.Add( actorD );
269 Test::TestCustomActor actorE = Test::TestCustomActor::New();
270 actorE.SetName( "ActorE" );
271 actorB.Add( actorE );
273 Test::TestCustomActor actorF = Test::TestCustomActor::New();
274 actorF.SetName( "ActorF" );
275 actorC.Add( actorF );
277 // Excercise the message passing to Update thread
279 application.SendNotification();
280 application.Render();
281 application.Render();
283 // Clear call stacks before disconnection
284 actorA.ResetCallStack();
285 actorB.ResetCallStack();
286 actorC.ResetCallStack();
287 actorD.ResetCallStack();
288 actorE.ResetCallStack();
289 actorF.ResetCallStack();
290 MasterCallStack.clear();
292 stage.Remove( actorA );
294 DALI_TEST_EQUALS( 1, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
295 DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
297 DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
298 DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
300 DALI_TEST_EQUALS( 1, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
301 DALI_TEST_EQUALS( "OnStageDisconnection", actorC.GetMethodsCalled()[ 0 ], TEST_LOCATION );
303 DALI_TEST_EQUALS( 1, (int)(actorD.GetMethodsCalled().size()), TEST_LOCATION );
304 DALI_TEST_EQUALS( "OnStageDisconnection", actorD.GetMethodsCalled()[ 0 ], TEST_LOCATION );
306 DALI_TEST_EQUALS( 1, (int)(actorE.GetMethodsCalled().size()), TEST_LOCATION );
307 DALI_TEST_EQUALS( "OnStageDisconnection", actorE.GetMethodsCalled()[ 0 ], TEST_LOCATION );
309 DALI_TEST_EQUALS( 1, (int)(actorF.GetMethodsCalled().size()), TEST_LOCATION );
310 DALI_TEST_EQUALS( "OnStageDisconnection", actorF.GetMethodsCalled()[ 0 ], TEST_LOCATION );
312 // Check sequence is correct in MasterCallStack
314 DALI_TEST_EQUALS( 6, (int)(MasterCallStack.size()), TEST_LOCATION );
316 DALI_TEST_EQUALS( "ActorD: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
317 DALI_TEST_EQUALS( "ActorE: OnStageDisconnection", MasterCallStack[ 1 ], TEST_LOCATION );
318 DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 2 ], TEST_LOCATION );
319 DALI_TEST_EQUALS( "ActorF: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
320 DALI_TEST_EQUALS( "ActorC: OnStageDisconnection", MasterCallStack[ 4 ], TEST_LOCATION );
321 DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 5 ], TEST_LOCATION );
323 // Excercise the message passing to Update thread
325 application.SendNotification();
326 application.Render();
327 application.Render();
331 int UtcDaliCustomActorAddDuringOnStageConnection(void)
333 TestApplication application;
334 tet_infoline("Testing Actor::Add behaviour during Dali::CustomActor::OnStageConnection() callback");
336 Stage stage = Stage::GetCurrent();
338 MasterCallStack.clear();
340 /* The actorA is a special variant which adds a child to itself during OnStageConnection()
341 * The actorB is provided as the child
344 Test::TestCustomActor actorB = Test::TestCustomActor::New();
345 actorB.SetName( "ActorB" );
347 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant1( actorB );
348 actorA.SetName( "ActorA" );
351 // Check callback sequence
353 DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
354 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
355 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION ); // Called from within OnStageConnection()
357 DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
358 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
360 DALI_TEST_EQUALS( 3, (int)(MasterCallStack.size()), TEST_LOCATION );
362 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 0 ], TEST_LOCATION );
363 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION ); // Occurs during Actor::Add from within from within OnStageConnection()
364 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION ); // Occurs after Actor::Add from within from within OnStageConnection()
366 // Excercise the message passing to Update thread
368 application.SendNotification();
369 application.Render();
370 application.Render();
372 // Check everything is ok after Actors are removed
374 stage.Remove( actorA );
375 application.SendNotification();
376 application.Render();
377 application.Render();
381 int UtcDaliCustomActorRemoveDuringOnStageConnection(void)
383 TestApplication application;
384 tet_infoline("Testing Actor::Remove behaviour during Dali::CustomActor::OnStageConnection() callback");
386 Stage stage = Stage::GetCurrent();
388 MasterCallStack.clear();
390 /* The actorA is a special variant which removes its children during OnStageConnection()
391 * Actors B & C are provided as the children
394 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant2();
395 actorA.SetName( "ActorA" );
397 Test::TestCustomActor actorB = Test::TestCustomActor::New();
398 actorB.SetName( "ActorB" );
399 actorA.Add( actorB );
401 Test::TestCustomActor actorC = Test::TestCustomActor::New();
402 actorC.SetName( "ActorC" );
403 actorA.Add( actorC );
407 // Check callback sequence
409 DALI_TEST_EQUALS( 5, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
410 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
411 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
412 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
413 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION ); // Called from within OnStageConnection()
414 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 4 ], TEST_LOCATION ); // Called from within OnStageConnection()
416 DALI_TEST_EQUALS( 5, (int)(MasterCallStack.size()), TEST_LOCATION );
418 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 0 ], TEST_LOCATION );
419 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 1 ], TEST_LOCATION );
420 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 2 ], TEST_LOCATION );
421 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 3 ], TEST_LOCATION );
422 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 4 ], TEST_LOCATION );
424 /* Actors B & C should be removed before the point where they could receive an OnStageConnection callback
425 * Therefore they shouldn't receive either OnStageConnection or OnStageDisconnection
427 DALI_TEST_EQUALS( 0, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
428 DALI_TEST_EQUALS( 0, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
430 // Excercise the message passing to Update thread
432 application.SendNotification();
433 application.Render();
434 application.Render();
436 // Check everything is ok after last actor is removed
438 stage.Remove( actorA );
439 application.SendNotification();
440 application.Render();
441 application.Render();
445 int UtcDaliCustomActorAddDuringOnStageDisconnection(void)
447 TestApplication application;
448 tet_infoline("Testing Actor::Add behaviour during Dali::CustomActor::OnStageDisonnection() callback");
450 Stage stage = Stage::GetCurrent();
452 /* The actorA is a special variant which adds a child to itself during OnStageDisconnection()
453 * The actorB is provided as the child
456 Test::TestCustomActor actorB = Test::TestCustomActor::New();
457 actorB.SetName( "ActorB" );
459 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant3( actorB );
460 actorA.SetName( "ActorA" );
463 // Excercise the message passing to Update thread
465 application.SendNotification();
466 application.Render();
467 application.Render();
469 // Clear call stacks before disconnection
470 actorA.ResetCallStack();
471 actorB.ResetCallStack();
472 MasterCallStack.clear();
474 stage.Remove( actorA );
476 // Check callback sequence
478 DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
479 DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
480 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
482 // Child was added after parent disconnection, so should not receive OnStageConnection()
483 DALI_TEST_EQUALS( 0, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
485 DALI_TEST_EQUALS( 2, (int)(MasterCallStack.size()), TEST_LOCATION );
487 DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
488 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 1 ], TEST_LOCATION );
490 // Excercise the message passing to Update thread
492 application.SendNotification();
493 application.Render();
494 application.Render();
498 int UtcDaliCustomActorRemoveDuringOnStageDisconnection(void)
500 TestApplication application;
501 tet_infoline("Testing Actor::Remove behaviour during Dali::CustomActor::OnStageDisconnection() callback");
503 Stage stage = Stage::GetCurrent();
505 /* The actorA is a special variant which removes its children during OnStageDisconnection()
506 * The actorB is provided as the child
509 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant4();
510 actorA.SetName( "ActorA" );
513 Test::TestCustomActor actorB = Test::TestCustomActor::New();
514 actorB.SetName( "ActorB" );
515 actorA.Add( actorB );
517 // Excercise the message passing to Update thread
519 application.SendNotification();
520 application.Render();
521 application.Render();
523 // Clear call stacks before disconnection
524 actorA.ResetCallStack();
525 actorB.ResetCallStack();
526 MasterCallStack.clear();
528 stage.Remove( actorA );
530 // Check callback sequence
532 DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
533 DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
534 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
536 DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
537 DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
539 DALI_TEST_EQUALS( 3, (int)(MasterCallStack.size()), TEST_LOCATION );
541 DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
542 DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 1 ], TEST_LOCATION );
543 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 2 ], TEST_LOCATION );
545 // Excercise the message passing to Update thread
547 application.SendNotification();
548 application.Render();
549 application.Render();
553 int UtcDaliCustomActorRemoveParentDuringOnStageConnection(void)
555 TestApplication application;
556 tet_infoline("Weird test where child removes its own parent from Stage during Dali::CustomActor::OnStageConnection() callback");
558 Stage stage = Stage::GetCurrent();
560 MasterCallStack.clear();
562 /* The actorA is the parent of actorB
563 * The actorB is a special variant which removes its own parent during OnStageConnection()
564 * The child actor is interrupting the parent's connection to stage, therefore the parent should not get an OnStageDisconnection()
567 Test::TestCustomActor actorA = Test::TestCustomActor::New();
568 actorA.SetName( "ActorA" );
570 Test::TestCustomActor actorB = Test::TestCustomActor::NewVariant5();
571 actorB.SetName( "ActorB" );
572 actorA.Add( actorB );
576 // Check callback sequence
578 DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
579 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
580 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
581 DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
583 DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
584 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
586 DALI_TEST_EQUALS( 4, (int)(MasterCallStack.size()), TEST_LOCATION );
588 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 0 ], TEST_LOCATION );
589 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION );
590 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 2 ], TEST_LOCATION );
591 DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
593 // Excercise the message passing to Update thread
595 application.SendNotification();
596 application.Render();
597 application.Render();
601 int UtcDaliCustomActorAddParentDuringOnStageDisconnection(void)
603 TestApplication application;
604 tet_infoline("Weird test where child adds its own parent to Stage during Dali::CustomActor::OnStageDisconnection() callback");
606 Stage stage = Stage::GetCurrent();
608 MasterCallStack.clear();
610 /* The actorA is the parent of actorB
611 * The actorB is a special variant which (weirdly) adds its own parent during OnStageDisconnection()
612 * The child actor is interrupting the disconnection, such that parent should not get a OnStageDisconnection()
615 Test::TestCustomActor actorA = Test::TestCustomActor::New();
616 actorA.SetName( "ActorA" );
619 Test::TestCustomActor actorB = Test::TestCustomActor::NewVariant6();
620 actorB.SetName( "ActorB" );
621 actorA.Add( actorB );
623 stage.Remove( actorA );
625 // Check callback sequence
627 DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
628 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
629 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
631 DALI_TEST_EQUALS( 2, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
632 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
633 DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
634 // Disconnect was interrupted, so we should only get one OnStageConnection() for actorB
636 DALI_TEST_EQUALS( 4, (int)(MasterCallStack.size()), TEST_LOCATION );
638 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 0 ], TEST_LOCATION );
639 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION );
640 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION );
641 DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
643 // Excercise the message passing to Update thread
645 application.SendNotification();
646 application.Render();
647 application.Render();
651 int UtcDaliCustomActorOnChildAddRemove(void)
653 TestApplication application;
654 tet_infoline("Testing Dali::CustomActor::OnChildAdd() & OnChildRemove()");
656 Test::TestCustomActor custom = Test::TestCustomActor::New();
657 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
659 Actor aChild = Actor::New();
660 custom.Add( aChild );
662 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
663 DALI_TEST_EQUALS( "OnChildAdd", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
665 custom.Remove( aChild );
667 DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
668 DALI_TEST_EQUALS( "OnChildRemove", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
672 int UtcDaliCustomActorReparentDuringOnChildAdd(void)
674 TestApplication application;
675 tet_infoline("Testing Actor:Add (reparenting) behaviour during Dali::CustomActor::OnChildAdd() callback");
677 Stage stage = Stage::GetCurrent();
679 MasterCallStack.clear();
681 /* The actorA is a special variant which reparents children added into a separate container child
682 * The actorB is the child of actorA
685 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant7( "ActorA" );
688 Test::TestCustomActor actorB = Test::TestCustomActor::New();
689 actorB.SetName( "ActorB" );
690 actorA.Add( actorB );
692 // Check hierarchy is as follows:
699 DALI_TEST_EQUALS( 1, (int)(actorA.GetChildCount()), TEST_LOCATION );
701 Actor container = actorA.GetChildAt(0);
702 Actor containerChild;
704 DALI_TEST_CHECK( container );
707 DALI_TEST_EQUALS( "Container", container.GetName(), TEST_LOCATION );
708 DALI_TEST_EQUALS( 1, (int)(container.GetChildCount()), TEST_LOCATION );
709 containerChild = container.GetChildAt(0);
712 DALI_TEST_CHECK( containerChild );
713 if ( containerChild )
715 DALI_TEST_EQUALS( "ActorB", containerChild.GetName(), TEST_LOCATION );
716 DALI_TEST_EQUALS( 0, (int)(containerChild.GetChildCount()), TEST_LOCATION );
719 // Check callback sequence
721 DALI_TEST_EQUALS( 4, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
722 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION ); // The mContainer added to actorA
723 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
724 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION ); // The actorB added to actorA
725 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION );
726 // mContainer will then receive OnChildAdd
728 DALI_TEST_EQUALS( 3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
729 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
730 DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
731 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
733 DALI_TEST_EQUALS( 7, (int)(MasterCallStack.size()), TEST_LOCATION );
735 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 0 ], TEST_LOCATION );
736 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION );
737 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 2 ], TEST_LOCATION );
738 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 3 ], TEST_LOCATION );
739 DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 4 ], TEST_LOCATION );
740 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 5 ], TEST_LOCATION );
741 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 6 ], TEST_LOCATION );
743 // Excercise the message passing to Update thread
745 application.SendNotification();
746 application.Render();
747 application.Render();
752 * Test that Remove can be called (a NOOP) during the OnChildRemove
753 * triggered when reparenting an actor
755 int UtcDaliCustomActorRemoveDuringOnChildRemove(void)
757 TestApplication application;
758 tet_infoline("Testing Actor:Remove behaviour during OnChildRemove() callback triggered when reparenting");
760 Stage stage = Stage::GetCurrent();
762 MasterCallStack.clear();
764 /* The childActor will be reparented from actorA to actorB
765 * The actorA is a special variant which attempts to remove a child from actorB, during the OnChildRemove callback()
766 * This should be a NOOP since the reparenting has not occured yet
769 Test::TestCustomActor actorB = Test::TestCustomActor::New();
770 actorB.SetName( "ActorB" );
773 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant8( actorB );
774 actorA.SetName( "ActorA" );
777 Actor childActor = Actor::New();
778 childActor.SetName( "Child" );
779 // Reparent from actorA to actorB
780 actorA.Add( childActor );
781 actorB.Add( childActor );
783 // Check hierarchy is as follows:
788 DALI_TEST_EQUALS( 0, (int)(actorA.GetChildCount()), TEST_LOCATION );
789 DALI_TEST_EQUALS( 1, (int)(actorB.GetChildCount()), TEST_LOCATION );
790 DALI_TEST_EQUALS( 0, (int)(childActor.GetChildCount()), TEST_LOCATION );
792 Actor child = actorB.GetChildAt(0);
794 DALI_TEST_CHECK( child );
797 DALI_TEST_EQUALS( "Child", child.GetName(), TEST_LOCATION );
800 // Check callback sequence
802 DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
803 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION ); // The mContainer added to actorA
804 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
805 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION ); // The actorB added to actorA
806 // mContainer will then receive OnChildAdd
808 DALI_TEST_EQUALS( 3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
809 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
810 // The derived class are always notified, no matter the child is successfully removed or not
811 DALI_TEST_EQUALS( "OnChildRemove", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
812 DALI_TEST_EQUALS( "OnChildAdd", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
814 DALI_TEST_EQUALS( 6, (int)(MasterCallStack.size()), TEST_LOCATION );
816 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 0 ], TEST_LOCATION );
817 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION );
818 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION );
819 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 3 ], TEST_LOCATION );
820 // The derived class are always notified, no matter the child is successfully removed or not
821 DALI_TEST_EQUALS( "ActorB: OnChildRemove", MasterCallStack[ 4 ], TEST_LOCATION );
822 DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 5 ], TEST_LOCATION );
824 // Excercise the message passing to Update thread
826 application.SendNotification();
827 application.Render();
828 application.Render();
832 int UtcDaliCustomActorOnPropertySet(void)
834 TestApplication application;
835 tet_infoline("Testing Dali::CustomActor::OnPropertySet()");
837 Test::TestCustomActor custom = Test::TestCustomActor::New();
838 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
840 custom.SetDaliProperty("yes");
842 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
843 DALI_TEST_EQUALS( "OnPropertySet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
847 int UtcDaliCustomActorOnSizeSet(void)
849 TestApplication application;
850 tet_infoline("Testing Dali::CustomActor::OnSizeSet()");
852 Test::TestCustomActor custom = Test::TestCustomActor::New();
853 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
855 custom.SetSize( Vector2( 9.0f, 10.0f ) );
856 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
857 DALI_TEST_EQUALS( "OnSizeSet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
858 DALI_TEST_EQUALS( 9.0f, custom.GetSize().width, TEST_LOCATION );
859 DALI_TEST_EQUALS( 10.0f, custom.GetSize().height, TEST_LOCATION );
861 custom.SetSize( Vector3( 4.0f, 5.0f, 6.0f ) );
862 DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
863 DALI_TEST_EQUALS( "OnSizeSet", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
864 DALI_TEST_EQUALS( 4.0f, custom.GetSize().width, TEST_LOCATION );
865 DALI_TEST_EQUALS( 5.0f, custom.GetSize().height, TEST_LOCATION );
866 DALI_TEST_EQUALS( 6.0f, custom.GetSize().depth, TEST_LOCATION );
870 int UtcDaliCustomActorOnSizeAnimation(void)
872 TestApplication application;
873 tet_infoline("Testing Dali::CustomActor::OnSizeAnimation()");
875 Test::TestCustomActor custom = Test::TestCustomActor::New();
876 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
878 Animation anim = Animation::New( 1.0f );
879 anim.AnimateTo( Property( custom, Actor::Property::SIZE ), Vector3( 8.0f, 9.0f, 10.0f ) );
882 application.SendNotification();
883 application.Render( static_cast<unsigned int>( 1000.0f ) );
885 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
886 DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
887 DALI_TEST_EQUALS( 8.0f, custom.GetTargetSize().width, TEST_LOCATION );
888 DALI_TEST_EQUALS( 9.0f, custom.GetTargetSize().height, TEST_LOCATION );
889 DALI_TEST_EQUALS( 10.0f, custom.GetTargetSize().depth, TEST_LOCATION );
893 int UtcDaliCustomActorSizeComponentAnimation(void)
895 TestApplication application;
896 tet_infoline("Testing Size component animation");
898 Test::TestCustomActor custom = Test::TestCustomActor::New();
899 float intialWidth( 10.0f );
901 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
902 custom.SetSize( intialWidth, 10.0f); // First method
904 Animation anim = Animation::New( 1.0f );
906 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
908 anim.AnimateTo( Property( custom, Actor::Property::SIZE_WIDTH ), 20.0f );
910 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
912 anim.Play(); // Triggers second method ( OnSizeAnimation )
914 application.SendNotification();
915 application.Render( static_cast<unsigned int>( 1000.0f ) );
917 DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
919 DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
925 int UtcDaliCustomActorOnTouchEvent(void)
927 TestApplication application;
928 tet_infoline("Testing Dali::CustomActor::OnTouchEvent()");
930 Test::TestCustomActor custom = Test::TestCustomActor::New();
931 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
933 // set size for custom actor
934 custom.SetSize( 100, 100 );
935 // add the custom actor to stage
936 Stage::GetCurrent().Add( custom );
937 custom.ResetCallStack();
939 // Render and notify a couple of times
940 application.SendNotification();
941 application.Render();
942 application.SendNotification();
943 application.Render();
945 // simulate a touch event
946 Dali::Integration::Point point;
947 point.SetState( PointState::DOWN );
948 point.SetScreenPosition( Vector2( 1, 1 ) );
949 Dali::Integration::TouchEvent event;
950 event.AddPoint( point );
951 application.ProcessEvent( event );
953 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
954 DALI_TEST_EQUALS( "OnTouchEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
958 int UtcDaliCustomActorOnHoverEvent(void)
960 TestApplication application;
961 tet_infoline("Testing Dali::CustomActor::OnHoverEvent()");
963 Test::TestCustomActor custom = Test::TestCustomActor::New();
964 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
966 // set size for custom actor
967 custom.SetSize( 100, 100 );
968 // add the custom actor to stage
969 Stage::GetCurrent().Add( custom );
970 custom.ResetCallStack();
972 // Render and notify a couple of times
973 application.SendNotification();
974 application.Render();
975 application.SendNotification();
976 application.Render();
978 // simulate a hover event
979 Dali::Integration::Point point;
980 point.SetState( PointState::MOTION );
981 point.SetScreenPosition( Vector2( 1, 1 ) );
982 Dali::Integration::HoverEvent event;
983 event.AddPoint( point );
984 application.ProcessEvent( event );
986 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
987 DALI_TEST_EQUALS( "OnHoverEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
991 int UtcDaliCustomActorOnWheelEvent(void)
993 TestApplication application;
994 tet_infoline("Testing Dali::CustomActor::OnWheelEvent()");
996 Test::TestCustomActor custom = Test::TestCustomActor::New();
997 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
999 // set size for custom actor
1000 custom.SetSize( 100, 100 );
1001 // add the custom actor to stage
1002 Stage::GetCurrent().Add( custom );
1003 custom.ResetCallStack();
1005 // Render and notify a couple of times
1006 application.SendNotification();
1007 application.Render();
1008 application.SendNotification();
1009 application.Render();
1011 // simulate a wheel event
1012 Vector2 screenCoordinates( 10.0f, 10.0f );
1013 Integration::WheelEvent event( Integration::WheelEvent::MOUSE_WHEEL, 0, 0u, screenCoordinates, 1, 1000u );
1014 application.ProcessEvent( event );
1016 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1017 DALI_TEST_EQUALS( "OnWheelEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1021 int UtcDaliCustomActorImplOnPropertySet(void)
1023 TestApplication application;
1024 CustomActorImpl* impl = new Test::Impl::SimpleTestCustomActor();
1025 CustomActor customActor( *impl ); // Will automatically unref at the end of this function
1027 impl->OnPropertySet( 0, 0 );
1029 DALI_TEST_CHECK( true );
1034 int UtcDaliCustomActorGetImplementation(void)
1036 TestApplication application;
1038 Test::TestCustomActor custom = Test::TestCustomActor::New();
1039 CustomActorImpl& impl = custom.GetImplementation();
1040 impl.GetOwner(); // Test
1042 const Test::TestCustomActor constCustom = Test::TestCustomActor::New();
1043 const CustomActorImpl& constImpl = constCustom.GetImplementation();
1044 constImpl.GetOwner(); // Test
1046 DALI_TEST_CHECK( true );
1050 int UtcDaliCustomActorDoAction(void)
1052 TestApplication application;
1053 tet_infoline("Testing Dali::CustomActor::DoAction()");
1055 Test::TestCustomActor custom = Test::TestCustomActor::New();
1057 BaseHandle customActorObject = custom;
1059 DALI_TEST_CHECK(customActorObject);
1061 Property::Map attributes;
1063 // Check that an invalid command is not performed
1064 DALI_TEST_CHECK(customActorObject.DoAction("invalidCommand", attributes) == false);
1066 // Check that the custom actor is visible
1067 custom.SetVisible(true);
1068 DALI_TEST_CHECK(custom.IsVisible() == true);
1070 // Check the custom actor performed an action to hide itself
1071 DALI_TEST_CHECK(customActorObject.DoAction("hide", attributes) == true);
1073 // flush the queue and render once
1074 application.SendNotification();
1075 application.Render();
1077 // Check that the custom actor is now invisible
1078 DALI_TEST_CHECK(custom.IsVisible() == false);
1080 // Check the custom actor performed an action to show itself
1081 DALI_TEST_CHECK(customActorObject.DoAction("show", attributes) == true);
1083 // flush the queue and render once
1084 application.SendNotification();
1085 application.Render();
1087 // Check that the custom actor is now visible
1088 DALI_TEST_CHECK(custom.IsVisible() == true);
1092 int UtcDaliCustomActorCustomActor(void)
1094 Dali::CustomActor customA;
1095 Dali::CustomActor customB( customA );
1097 DALI_TEST_CHECK( customA == customB );
1102 int UtcDaliCustomActorImplRelayoutRequest(void)
1104 TestApplication application;
1106 DALI_TEST_CHECK( gOnRelayout == false );
1108 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1109 Stage::GetCurrent().Add(custom);
1111 application.SendNotification();
1112 application.Render();
1114 DALI_TEST_CHECK( gOnRelayout == true );
1115 gOnRelayout = false;
1117 custom.TestRelayoutRequest();
1118 application.SendNotification();
1119 application.Render();
1121 DALI_TEST_CHECK( gOnRelayout == true );
1126 int UtcDaliCustomActorImplGetHeightForWidthBase(void)
1128 TestApplication application;
1129 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1131 float width = 300.0f;
1133 application.SendNotification();
1134 application.Render();
1136 float v = custom.TestGetHeightForWidthBase( width );
1138 DALI_TEST_CHECK( v == width );
1143 int UtcDaliCustomActorImplGetWidthForHeightBase(void)
1145 TestApplication application;
1146 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1148 float height = 300.0f;
1150 application.SendNotification();
1151 application.Render();
1153 float v = custom.TestGetWidthForHeightBase( height );
1155 DALI_TEST_CHECK( v == height );
1160 int UtcDaliCustomActorImplCalculateChildSizeBase(void)
1162 TestApplication application;
1163 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1165 Actor child = Actor::New();
1166 child.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1167 child.SetSize(150, 150);
1169 application.SendNotification();
1170 application.Render();
1172 float v = custom.TestCalculateChildSizeBase( child, Dali::Dimension::ALL_DIMENSIONS );
1173 DALI_TEST_CHECK( v == 0.0f );
1178 int UtcDaliCustomActorImplRelayoutDependentOnChildrenBase(void)
1180 TestApplication application;
1181 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1182 custom.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS);
1184 bool v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::ALL_DIMENSIONS );
1185 DALI_TEST_CHECK( v == true );
1187 application.SendNotification();
1188 application.Render();
1190 custom.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1191 v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::WIDTH );
1192 DALI_TEST_CHECK( v == false );
1194 // why is this here?
1195 application.SendNotification();
1196 application.Render();
1201 int UtcDaliCustomActorTypeRegistry(void)
1203 TestApplication application;
1207 type = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
1208 DALI_TEST_CHECK( type );
1209 BaseHandle handle = type.CreateInstance();
1212 std::string exception;
1216 name = handle.GetTypeName();
1217 tet_result(TET_FAIL);
1219 catch( DaliException& e )
1221 exception = e.condition;
1222 DALI_TEST_EQUALS( exception, "handle && \"BaseObject handle is empty\"", TEST_LOCATION );
1229 int UtcDaliCustomActorGetExtensionP(void)
1231 TestApplication application;
1233 Test::TestCustomActor custom = Test::TestCustomActor::NewVariant5();
1235 DALI_TEST_CHECK( NULL == custom.GetImplementation().GetExtension() );
1240 int UtcDaliCustomActorOnConnectionDepth(void)
1242 TestApplication application;
1243 tet_infoline("Testing Dali::CustomActor::OnStageConnection() hierarchy depth");
1245 Stage stage = Stage::GetCurrent();
1247 /* Build tree of actors:
1257 * OnStageConnection should return 1 for A, 2 for B and C, and 3 for D, E and F.
1260 Test::TestCustomActor actorA = Test::TestCustomActor::New();
1261 stage.Add( actorA );
1263 Test::TestCustomActor actorB = Test::TestCustomActor::New();
1264 actorA.Add( actorB );
1266 Test::TestCustomActor actorC = Test::TestCustomActor::New();
1267 actorA.Add( actorC );
1269 Test::TestCustomActor actorD = Test::TestCustomActor::New();
1270 actorB.Add( actorD );
1272 Test::TestCustomActor actorE = Test::TestCustomActor::New();
1273 actorB.Add( actorE );
1275 Test::TestCustomActor actorF = Test::TestCustomActor::New();
1276 actorC.Add( actorF );
1278 // Excercise the message passing to Update thread
1279 application.SendNotification();
1280 application.Render();
1281 application.Render();
1283 DALI_TEST_EQUALS( 1u, actorA.GetDepth(), TEST_LOCATION );
1284 DALI_TEST_EQUALS( 2u, actorB.GetDepth(), TEST_LOCATION );
1285 DALI_TEST_EQUALS( 2u, actorC.GetDepth(), TEST_LOCATION );
1286 DALI_TEST_EQUALS( 3u, actorD.GetDepth(), TEST_LOCATION );
1287 DALI_TEST_EQUALS( 3u, actorE.GetDepth(), TEST_LOCATION );
1288 DALI_TEST_EQUALS( 3u, actorF.GetDepth(), TEST_LOCATION );
1294 int UtcDaliCustomActorSetGetProperty(void)
1296 TestApplication application; // Need the type registry
1298 Test::TestCustomActor actor = Test::TestCustomActor::New();
1299 Stage::GetCurrent().Add( actor );
1301 actor.SetProperty( Test::TestCustomActor::Property::TEST_PROPERTY1, 0.5f );
1302 actor.SetProperty( Test::TestCustomActor::Property::TEST_PROPERTY2, Color::WHITE );
1303 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3, Color::BLUE );
1304 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4, 20 );
1305 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5, 40.0f );
1307 Property::Value value = actor.GetProperty( Test::TestCustomActor::Property::TEST_PROPERTY1 );
1308 DALI_TEST_EQUALS( value.Get<float>(), 0.5f, 0.001f, TEST_LOCATION );
1310 value = actor.GetProperty( Test::TestCustomActor::Property::TEST_PROPERTY2 );
1311 DALI_TEST_EQUALS( value.Get<Vector4>(), Color::WHITE, 0.001f, TEST_LOCATION );
1314 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3 );
1315 DALI_TEST_EQUALS( value.Get<Vector4>(), Color::BLUE, 0.001f, TEST_LOCATION );
1317 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4 );
1318 DALI_TEST_EQUALS( value.Get<int>(), 20, TEST_LOCATION );
1320 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5 );
1321 DALI_TEST_EQUALS( value.Get<float>(), 40.0f, 0.001f, TEST_LOCATION );
1323 // Get read-only property
1324 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6 );
1325 DALI_TEST_EQUALS( value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION );
1327 // Attempt to set read-only property and then ensure value hasn't changed
1328 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6, 40.0f );
1329 DALI_TEST_EQUALS( value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION );
1334 int utcDaliActorGetTypeInfo(void)
1336 TestApplication application;
1337 tet_infoline( "Get the type info of a derived actor" );
1339 Test::TestCustomActor customActor = Test::TestCustomActor::New();
1341 Dali::TypeInfo typeInfo = Dali::DevelCustomActor::GetTypeInfo( customActor );
1343 DALI_TEST_EQUALS( typeInfo.GetName(), std::string("TestCustomActor"), TEST_LOCATION );
1351 * A custom actor that is not type registered on purpose
1353 struct UnregisteredCustomActor : public Dali::CustomActorImpl
1355 UnregisteredCustomActor() : CustomActorImpl( ACTOR_BEHAVIOUR_DEFAULT )
1357 virtual ~UnregisteredCustomActor()
1359 virtual void OnStageConnection( int32_t depth )
1361 virtual void OnStageDisconnection()
1363 virtual void OnChildAdd(Actor& child)
1365 virtual void OnChildRemove(Actor& child)
1367 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue )
1369 virtual void OnSizeSet(const Vector3& targetSize)
1371 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1373 virtual bool OnTouchEvent(const TouchEvent& event) DALI_DEPRECATED_API
1375 virtual bool OnHoverEvent(const HoverEvent& event)
1377 virtual bool OnKeyEvent(const KeyEvent& event)
1379 virtual bool OnWheelEvent(const WheelEvent& event)
1381 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
1383 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1385 virtual Vector3 GetNaturalSize()
1386 { return Vector3(); }
1387 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
1389 virtual float GetHeightForWidth( float width )
1391 virtual float GetWidthForHeight( float height )
1393 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
1395 virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
1397 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
1401 struct UnregisteredCustomActor : public Dali::CustomActor
1403 static UnregisteredCustomActor New()
1405 Impl::UnregisteredCustomActor* impl = new Impl::UnregisteredCustomActor;
1406 UnregisteredCustomActor custom( *impl ); // takes ownership
1409 UnregisteredCustomActor()
1411 ~UnregisteredCustomActor()
1413 UnregisteredCustomActor( Internal::CustomActor* impl )
1414 : CustomActor( impl )
1416 UnregisteredCustomActor( Impl::UnregisteredCustomActor& impl )
1417 : CustomActor( impl )
1419 static UnregisteredCustomActor DownCast( BaseHandle handle )
1421 UnregisteredCustomActor hndl;
1422 CustomActor custom = Dali::CustomActor::DownCast( handle );
1425 CustomActorImpl& customImpl = custom.GetImplementation();
1427 Impl::UnregisteredCustomActor* impl = dynamic_cast<Impl::UnregisteredCustomActor*>( &customImpl );
1431 hndl = UnregisteredCustomActor( customImpl.GetOwner() );
1438 int UtcDaliCustomActorSetGetActorPropertyActionSignal(void)
1440 TestApplication application; // Need the type registry
1442 auto custom = UnregisteredCustomActor::New();
1443 Stage::GetCurrent().Add( custom );
1445 // should have all actor properties
1446 DALI_TEST_EQUALS( custom.GetPropertyType( Actor::Property::COLOR ), Property::VECTOR4, TEST_LOCATION );
1447 auto actorHandle = Actor::New();
1448 DALI_TEST_EQUALS( custom.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION );
1450 DALI_TEST_EQUALS( custom.IsVisible(), true, TEST_LOCATION );
1451 custom.SetProperty( Actor::Property::VISIBLE, false );
1452 application.SendNotification();
1453 application.Render(); // IsVisible returns scene value
1454 DALI_TEST_EQUALS( custom.IsVisible(), false, TEST_LOCATION );
1456 // should have custom actor typename (as it has not registered itself)
1457 DALI_TEST_EQUALS( "CustomActor", custom.GetTypeName(), TEST_LOCATION );
1459 // should have actor actions
1460 custom.DoAction( "show", Property::Map() );
1461 DALI_TEST_EQUALS( custom.GetProperty( Actor::Property::VISIBLE ).Get<bool>(), true, TEST_LOCATION );
1463 Animation animation = Animation::New(0.01f); // very short animation
1464 // should be able to animate actor property
1465 animation.AnimateTo( Property( custom, Actor::Property::POSITION ), Vector3( 100.0f, 150.0f, 200.0f ) );
1468 application.SendNotification();
1469 application.Render(1000.f);
1471 DALI_TEST_EQUALS( Vector3( 100.0f, 150.0f, 200.0f ), custom.GetProperty( Actor::Property::POSITION ).Get<Vector3>(), TEST_LOCATION );
1472 DALI_TEST_EQUALS( Vector3( 100.0f, 150.0f, 200.0f ), custom.GetCurrentPosition(), TEST_LOCATION );
1474 Dali::WeakHandle<UnregisteredCustomActor> weakRef( custom );
1475 // should have actor signals
1476 custom.ConnectSignal( &application, "offStage",
1479 DALI_TEST_EQUALS( weakRef.GetHandle().OnStage(), false, TEST_LOCATION );
1482 Stage::GetCurrent().Remove( custom );
1483 Stage::GetCurrent().Add( custom );
1490 struct DerivedCustomActor : public UnregisteredCustomActor
1494 struct DerivedCustomActor : public UnregisteredCustomActor
1496 static DerivedCustomActor New()
1498 Impl::DerivedCustomActor* impl = new Impl::DerivedCustomActor;
1499 DerivedCustomActor custom( *impl ); // takes ownership
1502 DerivedCustomActor()
1504 ~DerivedCustomActor()
1506 DerivedCustomActor( Internal::CustomActor* impl )
1507 : UnregisteredCustomActor( impl )
1509 DerivedCustomActor( Impl::UnregisteredCustomActor& impl )
1510 : UnregisteredCustomActor( impl )
1515 DALI_TYPE_REGISTRATION_BEGIN( DerivedCustomActor, UnregisteredCustomActor, nullptr );
1516 DALI_TYPE_REGISTRATION_END()
1518 int UtcDaliCustomActorPropertyRegistrationDefaultValue(void)
1520 TestApplication application; // Need the type registry
1522 // register our base and add a property with default value for it
1523 Dali::TypeRegistration typeRegistration( typeid( UnregisteredCustomActor ), typeid( Dali::CustomActor ), nullptr );
1525 auto derived = DerivedCustomActor::New();
1526 Stage::GetCurrent().Add( derived );
1528 // should have all actor properties
1529 DALI_TEST_EQUALS( derived.GetPropertyType( Actor::Property::WORLD_MATRIX ), Property::MATRIX, TEST_LOCATION );
1530 auto actorHandle = Actor::New();
1531 DALI_TEST_EQUALS( derived.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION );
1533 // add a property in base class
1534 AnimatablePropertyRegistration( typeRegistration, "Foobar", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, 10.f );
1536 // should be one more property now
1537 DALI_TEST_EQUALS( derived.GetPropertyCount(), actorHandle.GetPropertyCount() + 1, TEST_LOCATION );
1538 // check that the default value is set for base class
1539 DALI_TEST_EQUALS( UnregisteredCustomActor::New().GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION );
1540 // check that the default value is set for the derived instance as well
1541 DALI_TEST_EQUALS( derived.GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION );