2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <dali/public-api/dali-core.h>
22 #include <dali/devel-api/actors/custom-actor-devel.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali/integration-api/events/hover-event-integ.h>
25 #include <dali/integration-api/events/wheel-event-integ.h>
26 #include <dali/integration-api/events/key-event-integ.h>
27 #include <dali/public-api/object/type-registry-helper.h>
28 #include "dali-test-suite-utils/dali-test-suite-utils.h"
29 #include "test-custom-actor.h"
34 void custom_actor_test_startup(void)
36 test_return_value = TET_UNDEF;
39 void custom_actor_test_cleanup(void)
41 test_return_value = TET_PASS;
49 int UtcDaliCustomActorDestructor(void)
51 TestApplication application;
53 CustomActor* actor = new CustomActor();
56 DALI_TEST_CHECK( true );
60 int UtcDaliCustomActorImplDestructor(void)
62 TestApplication application;
63 CustomActorImpl* actor = new Test::Impl::TestCustomActor();
64 CustomActor customActor( *actor ); // Will automatically unref at the end of this function
66 DALI_TEST_CHECK( true );
70 // Positive test case for a method
71 int UtcDaliCustomActorDownCast(void)
73 TestApplication application;
74 tet_infoline("Testing Dali::CustomActor::DownCast()");
76 Test::TestCustomActor custom = Test::TestCustomActor::New();
78 Actor anActor = Actor::New();
79 anActor.Add( custom );
81 Actor child = anActor.GetChildAt(0);
82 CustomActor customActor = CustomActor::DownCast( child );
83 DALI_TEST_CHECK( customActor );
86 DALI_TEST_CHECK( !customActor );
88 customActor = DownCast< CustomActor >( child );
89 DALI_TEST_CHECK( customActor );
93 // Negative test case for a method
94 int UtcDaliCustomActorDownCastNegative(void)
96 TestApplication application;
97 tet_infoline("Testing Dali::CustomActor::DownCast()");
99 Actor actor1 = Actor::New();
100 Actor anActor = Actor::New();
103 Actor child = anActor.GetChildAt(0);
104 CustomActor customActor = CustomActor::DownCast( child );
105 DALI_TEST_CHECK( !customActor );
107 Actor unInitialzedActor;
108 customActor = CustomActor::DownCast( unInitialzedActor );
109 DALI_TEST_CHECK( !customActor );
111 customActor = DownCast< CustomActor >( unInitialzedActor );
112 DALI_TEST_CHECK( !customActor );
116 int 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 application.GetScene().Add( custom );
127 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
128 DALI_TEST_EQUALS( "OnStageConnection", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
130 application.GetScene().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.SetProperty( Actor::Property::NAME, "ActorA" );
164 Test::TestCustomActor actorB = Test::TestCustomActor::New();
165 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
166 actorA.Add( actorB );
168 Test::TestCustomActor actorC = Test::TestCustomActor::New();
169 actorC.SetProperty( Actor::Property::NAME, "ActorC" );
170 actorA.Add( actorC );
172 Test::TestCustomActor actorD = Test::TestCustomActor::New();
173 actorD.SetProperty( Actor::Property::NAME, "ActorD" );
174 actorB.Add( actorD );
176 Test::TestCustomActor actorE = Test::TestCustomActor::New();
177 actorE.SetProperty( Actor::Property::NAME, "ActorE" );
178 actorB.Add( actorE );
180 Test::TestCustomActor actorF = Test::TestCustomActor::New();
181 actorF.SetProperty( Actor::Property::NAME, "ActorF" );
182 actorC.Add( actorF );
184 // add the custom actor to stage
185 application.GetScene().Add( actorA );
187 DALI_TEST_EQUALS( 4, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
188 DALI_TEST_EQUALS( "OnPropertySet", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
189 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
190 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
191 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION );
193 DALI_TEST_EQUALS( 4, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
194 DALI_TEST_EQUALS( "OnPropertySet", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
195 DALI_TEST_EQUALS( "OnChildAdd", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
196 DALI_TEST_EQUALS( "OnChildAdd", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
197 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 3 ], TEST_LOCATION );
199 DALI_TEST_EQUALS( 3, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
200 DALI_TEST_EQUALS( "OnPropertySet", actorC.GetMethodsCalled()[ 0 ], TEST_LOCATION );
201 DALI_TEST_EQUALS( "OnChildAdd", actorC.GetMethodsCalled()[ 1 ], TEST_LOCATION );
202 DALI_TEST_EQUALS( "OnStageConnection", actorC.GetMethodsCalled()[ 2 ], TEST_LOCATION );
204 DALI_TEST_EQUALS( 2, (int)(actorD.GetMethodsCalled().size()), TEST_LOCATION );
205 DALI_TEST_EQUALS( "OnPropertySet", actorD.GetMethodsCalled()[ 0 ], TEST_LOCATION );
206 DALI_TEST_EQUALS( "OnStageConnection", actorD.GetMethodsCalled()[ 1 ], TEST_LOCATION );
208 DALI_TEST_EQUALS( 2, (int)(actorE.GetMethodsCalled().size()), TEST_LOCATION );
209 DALI_TEST_EQUALS( "OnPropertySet", actorE.GetMethodsCalled()[ 0 ], TEST_LOCATION );
210 DALI_TEST_EQUALS( "OnStageConnection", actorE.GetMethodsCalled()[ 1 ], TEST_LOCATION );
212 DALI_TEST_EQUALS( 2, (int)(actorF.GetMethodsCalled().size()), TEST_LOCATION );
213 DALI_TEST_EQUALS( "OnPropertySet", actorF.GetMethodsCalled()[ 0 ], TEST_LOCATION );
214 DALI_TEST_EQUALS( "OnStageConnection", actorF.GetMethodsCalled()[ 1 ], TEST_LOCATION );
216 // Check sequence is correct in MasterCallStack
218 DALI_TEST_EQUALS( 4+4+3+2+2+2, (int)(MasterCallStack.size()), TEST_LOCATION );
220 DALI_TEST_EQUALS( "ActorA: OnPropertySet", MasterCallStack[ 0 ], TEST_LOCATION );
221 DALI_TEST_EQUALS( "ActorB: OnPropertySet", MasterCallStack[ 1 ], TEST_LOCATION );
222 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION );
223 DALI_TEST_EQUALS( "ActorC: OnPropertySet", MasterCallStack[ 3 ], TEST_LOCATION );
224 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION );
225 DALI_TEST_EQUALS( "ActorD: OnPropertySet", MasterCallStack[ 5 ], TEST_LOCATION );
227 DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 6 ], TEST_LOCATION );
228 DALI_TEST_EQUALS( "ActorE: OnPropertySet", MasterCallStack[ 7 ], TEST_LOCATION );
229 DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 8 ], TEST_LOCATION );
230 DALI_TEST_EQUALS( "ActorF: OnPropertySet", MasterCallStack[ 9 ], TEST_LOCATION );
231 DALI_TEST_EQUALS( "ActorC: OnChildAdd", MasterCallStack[ 10 ], TEST_LOCATION );
233 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 11 ], TEST_LOCATION );
234 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 12 ], TEST_LOCATION );
235 DALI_TEST_EQUALS( "ActorD: OnStageConnection", MasterCallStack[ 13 ], TEST_LOCATION );
236 DALI_TEST_EQUALS( "ActorE: OnStageConnection", MasterCallStack[ 14 ], TEST_LOCATION );
237 DALI_TEST_EQUALS( "ActorC: OnStageConnection", MasterCallStack[ 15 ], TEST_LOCATION );
238 DALI_TEST_EQUALS( "ActorF: OnStageConnection", MasterCallStack[ 16 ], TEST_LOCATION );
240 // Excercise the message passing to Update thread
242 application.SendNotification();
243 application.Render();
244 application.Render();
248 int UtcDaliCustomActorOnStageDisconnectionOrder(void)
250 TestApplication application;
251 tet_infoline("Testing Dali::CustomActor::OnStageDisconnection() order");
253 Integration::Scene stage = application.GetScene();
255 /* Build tree of actors:
263 * OnStageDisconnection should be received for D, E, B, F, C, and finally A.
266 Test::TestCustomActor actorA = Test::TestCustomActor::New();
267 actorA.SetProperty( Actor::Property::NAME, "ActorA" );
270 Test::TestCustomActor actorB = Test::TestCustomActor::New();
271 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
272 actorA.Add( actorB );
274 Test::TestCustomActor actorC = Test::TestCustomActor::New();
275 actorC.SetProperty( Actor::Property::NAME, "ActorC" );
276 actorA.Add( actorC );
278 Test::TestCustomActor actorD = Test::TestCustomActor::New();
279 actorD.SetProperty( Actor::Property::NAME, "ActorD" );
280 actorB.Add( actorD );
282 Test::TestCustomActor actorE = Test::TestCustomActor::New();
283 actorE.SetProperty( Actor::Property::NAME, "ActorE" );
284 actorB.Add( actorE );
286 Test::TestCustomActor actorF = Test::TestCustomActor::New();
287 actorF.SetProperty( Actor::Property::NAME, "ActorF" );
288 actorC.Add( actorF );
290 // Excercise the message passing to Update thread
292 application.SendNotification();
293 application.Render();
294 application.Render();
296 // Clear call stacks before disconnection
297 actorA.ResetCallStack();
298 actorB.ResetCallStack();
299 actorC.ResetCallStack();
300 actorD.ResetCallStack();
301 actorE.ResetCallStack();
302 actorF.ResetCallStack();
303 MasterCallStack.clear();
305 stage.Remove( actorA );
307 DALI_TEST_EQUALS( 1, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
308 DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
310 DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
311 DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
313 DALI_TEST_EQUALS( 1, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
314 DALI_TEST_EQUALS( "OnStageDisconnection", actorC.GetMethodsCalled()[ 0 ], TEST_LOCATION );
316 DALI_TEST_EQUALS( 1, (int)(actorD.GetMethodsCalled().size()), TEST_LOCATION );
317 DALI_TEST_EQUALS( "OnStageDisconnection", actorD.GetMethodsCalled()[ 0 ], TEST_LOCATION );
319 DALI_TEST_EQUALS( 1, (int)(actorE.GetMethodsCalled().size()), TEST_LOCATION );
320 DALI_TEST_EQUALS( "OnStageDisconnection", actorE.GetMethodsCalled()[ 0 ], TEST_LOCATION );
322 DALI_TEST_EQUALS( 1, (int)(actorF.GetMethodsCalled().size()), TEST_LOCATION );
323 DALI_TEST_EQUALS( "OnStageDisconnection", actorF.GetMethodsCalled()[ 0 ], TEST_LOCATION );
325 // Check sequence is correct in MasterCallStack
327 DALI_TEST_EQUALS( 6, (int)(MasterCallStack.size()), TEST_LOCATION );
329 DALI_TEST_EQUALS( "ActorD: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
330 DALI_TEST_EQUALS( "ActorE: OnStageDisconnection", MasterCallStack[ 1 ], TEST_LOCATION );
331 DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 2 ], TEST_LOCATION );
332 DALI_TEST_EQUALS( "ActorF: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
333 DALI_TEST_EQUALS( "ActorC: OnStageDisconnection", MasterCallStack[ 4 ], TEST_LOCATION );
334 DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 5 ], TEST_LOCATION );
336 // Excercise the message passing to Update thread
338 application.SendNotification();
339 application.Render();
340 application.Render();
344 int UtcDaliCustomActorAddDuringOnStageConnection(void)
346 TestApplication application;
347 tet_infoline("Testing Actor::Add behaviour during Dali::CustomActor::OnStageConnection() callback");
349 Integration::Scene stage = application.GetScene();
351 MasterCallStack.clear();
353 /* The actorA is a special variant which adds a child to itself during OnStageConnection()
354 * The actorB is provided as the child
357 Test::TestCustomActor actorB = Test::TestCustomActor::New();
358 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
360 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant1( actorB );
361 actorA.SetProperty( Actor::Property::NAME, "ActorA" );
364 // Check callback sequence
366 DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
367 DALI_TEST_EQUALS( "OnPropertySet", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
368 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
369 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION ); // Called from within OnStageConnection()
371 DALI_TEST_EQUALS( 2, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
372 DALI_TEST_EQUALS( "OnPropertySet", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
373 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
375 DALI_TEST_EQUALS( 5, (int)(MasterCallStack.size()), TEST_LOCATION );
377 DALI_TEST_EQUALS( "ActorB: OnPropertySet", MasterCallStack[ 0 ], TEST_LOCATION );
378 DALI_TEST_EQUALS( "ActorA: OnPropertySet", MasterCallStack[ 1 ], TEST_LOCATION );
379 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 2 ], TEST_LOCATION );
380 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 3 ], TEST_LOCATION ); // Occurs during Actor::Add from within from within OnStageConnection()
381 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION ); // Occurs after Actor::Add from within from within OnStageConnection()
383 // Excercise the message passing to Update thread
385 application.SendNotification();
386 application.Render();
387 application.Render();
389 // Check everything is ok after Actors are removed
391 stage.Remove( actorA );
392 application.SendNotification();
393 application.Render();
394 application.Render();
398 int UtcDaliCustomActorRemoveDuringOnStageConnection(void)
400 TestApplication application;
401 tet_infoline("Testing Actor::Remove behaviour during Dali::CustomActor::OnStageConnection() callback");
403 Integration::Scene stage = application.GetScene();
405 MasterCallStack.clear();
407 /* The actorA is a special variant which removes its children during OnStageConnection()
408 * Actors B & C are provided as the children
411 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant2();
412 actorA.SetProperty( Actor::Property::NAME, "ActorA" );
414 Test::TestCustomActor actorB = Test::TestCustomActor::New();
415 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
416 actorA.Add( actorB );
418 Test::TestCustomActor actorC = Test::TestCustomActor::New();
419 actorC.SetProperty( Actor::Property::NAME, "ActorC" );
420 actorA.Add( actorC );
424 // Check callback sequence
426 DALI_TEST_EQUALS( 6, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
427 DALI_TEST_EQUALS( "OnPropertySet", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
428 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
429 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
430 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION );
431 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 4 ], TEST_LOCATION ); // Called from within OnStageConnection()
432 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 5 ], TEST_LOCATION ); // Called from within OnStageConnection()
434 DALI_TEST_EQUALS( 8, (int)(MasterCallStack.size()), TEST_LOCATION );
436 DALI_TEST_EQUALS( "ActorA: OnPropertySet", MasterCallStack[ 0 ], TEST_LOCATION );
437 DALI_TEST_EQUALS( "ActorB: OnPropertySet", MasterCallStack[ 1 ], TEST_LOCATION );
438 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION );
439 DALI_TEST_EQUALS( "ActorC: OnPropertySet", MasterCallStack[ 3 ], TEST_LOCATION );
440 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION );
441 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 5 ], TEST_LOCATION );
442 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 6 ], TEST_LOCATION );
443 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 7 ], TEST_LOCATION );
445 /* Actors B & C should be removed before the point where they could receive an OnStageConnection callback
446 * Therefore they shouldn't receive either OnStageConnection or OnStageDisconnection
448 DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
449 DALI_TEST_EQUALS( 1, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
451 // Excercise the message passing to Update thread
453 application.SendNotification();
454 application.Render();
455 application.Render();
457 // Check everything is ok after last actor is removed
459 stage.Remove( actorA );
460 application.SendNotification();
461 application.Render();
462 application.Render();
466 int UtcDaliCustomActorAddDuringOnStageDisconnection(void)
468 TestApplication application;
469 tet_infoline("Testing Actor::Add behaviour during Dali::CustomActor::OnStageDisonnection() callback");
471 Integration::Scene stage = application.GetScene();
473 /* The actorA is a special variant which adds a child to itself during OnStageDisconnection()
474 * The actorB is provided as the child
477 Test::TestCustomActor actorB = Test::TestCustomActor::New();
478 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
480 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant3( actorB );
481 actorA.SetProperty( Actor::Property::NAME, "ActorA" );
484 // Excercise the message passing to Update thread
486 application.SendNotification();
487 application.Render();
488 application.Render();
490 // Clear call stacks before disconnection
491 actorA.ResetCallStack();
492 actorB.ResetCallStack();
493 MasterCallStack.clear();
495 stage.Remove( actorA );
497 // Check callback sequence
499 DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
500 DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
501 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
503 // Child was added after parent disconnection, so should not receive OnStageConnection()
504 DALI_TEST_EQUALS( 0, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
506 DALI_TEST_EQUALS( 2, (int)(MasterCallStack.size()), TEST_LOCATION );
508 DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
509 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 1 ], TEST_LOCATION );
511 // Excercise the message passing to Update thread
513 application.SendNotification();
514 application.Render();
515 application.Render();
519 int UtcDaliCustomActorRemoveDuringOnStageDisconnection(void)
521 TestApplication application;
522 tet_infoline("Testing Actor::Remove behaviour during Dali::CustomActor::OnStageDisconnection() callback");
524 Integration::Scene stage = application.GetScene();
526 /* The actorA is a special variant which removes its children during OnStageDisconnection()
527 * The actorB is provided as the child
530 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant4();
531 actorA.SetProperty( Actor::Property::NAME, "ActorA" );
534 Test::TestCustomActor actorB = Test::TestCustomActor::New();
535 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
536 actorA.Add( actorB );
538 // Excercise the message passing to Update thread
540 application.SendNotification();
541 application.Render();
542 application.Render();
544 // Clear call stacks before disconnection
545 actorA.ResetCallStack();
546 actorB.ResetCallStack();
547 MasterCallStack.clear();
549 stage.Remove( actorA );
551 // Check callback sequence
553 DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
554 DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
555 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
557 DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
558 DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
560 DALI_TEST_EQUALS( 3, (int)(MasterCallStack.size()), TEST_LOCATION );
562 DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
563 DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 1 ], TEST_LOCATION );
564 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 2 ], TEST_LOCATION );
566 // Excercise the message passing to Update thread
568 application.SendNotification();
569 application.Render();
570 application.Render();
574 int UtcDaliCustomActorRemoveParentDuringOnStageConnection(void)
576 TestApplication application;
577 tet_infoline("Weird test where child removes its own parent from Stage during Dali::CustomActor::OnStageConnection() callback");
579 Integration::Scene stage = application.GetScene();
581 MasterCallStack.clear();
583 /* The actorA is the parent of actorB
584 * The actorB is a special variant which removes its own parent during OnStageConnection()
585 * The child actor is interrupting the parent's connection to stage, therefore the parent should not get an OnStageDisconnection()
588 Test::TestCustomActor actorA = Test::TestCustomActor::New();
589 actorA.SetProperty( Actor::Property::NAME, "ActorA" );
591 Test::TestCustomActor actorB = Test::TestCustomActor::NewVariant5();
592 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
593 actorA.Add( actorB );
597 // Check callback sequence
599 DALI_TEST_EQUALS( 4, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
600 DALI_TEST_EQUALS( "OnPropertySet", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
601 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
602 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
603 DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION );
605 DALI_TEST_EQUALS( 2, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
606 DALI_TEST_EQUALS( "OnPropertySet", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
607 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
609 DALI_TEST_EQUALS( 6, (int)(MasterCallStack.size()), TEST_LOCATION );
611 DALI_TEST_EQUALS( "ActorA: OnPropertySet", MasterCallStack[ 0 ], TEST_LOCATION );
612 DALI_TEST_EQUALS( "ActorB: OnPropertySet", MasterCallStack[ 1 ], TEST_LOCATION );
613 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION );
614 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 3 ], TEST_LOCATION );
615 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 4 ], TEST_LOCATION );
616 DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 5 ], TEST_LOCATION );
618 // Excercise the message passing to Update thread
620 application.SendNotification();
621 application.Render();
622 application.Render();
626 int UtcDaliCustomActorAddParentDuringOnStageDisconnection(void)
628 TestApplication application;
629 tet_infoline("Weird test where child adds its own parent to Stage during Dali::CustomActor::OnStageDisconnection() callback");
631 Integration::Scene stage = application.GetScene();
633 MasterCallStack.clear();
635 /* The actorA is the parent of actorB
636 * The actorB is a special variant which (weirdly) adds its own parent during OnStageDisconnection()
637 * The child actor is interrupting the disconnection, such that parent should not get a OnStageDisconnection()
640 Test::TestCustomActor actorA = Test::TestCustomActor::New();
641 actorA.SetProperty( Actor::Property::NAME, "ActorA" );
644 Test::TestCustomActor actorB = Test::TestCustomActor::NewVariant6();
645 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
646 actorA.Add( actorB );
648 stage.Remove( actorA );
650 // Check callback sequence
652 DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
653 DALI_TEST_EQUALS( "OnPropertySet", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
654 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
655 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
657 DALI_TEST_EQUALS( 3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
658 DALI_TEST_EQUALS( "OnPropertySet", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
659 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
660 DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
661 // Disconnect was interrupted, so we should only get one OnStageConnection() for actorB
663 DALI_TEST_EQUALS( 6, (int)(MasterCallStack.size()), TEST_LOCATION );
665 DALI_TEST_EQUALS( "ActorA: OnPropertySet", MasterCallStack[ 0 ], TEST_LOCATION );
666 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION );
667 DALI_TEST_EQUALS( "ActorB: OnPropertySet", MasterCallStack[ 2 ], TEST_LOCATION );
668 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 3 ], TEST_LOCATION );
669 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION );
670 DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 5 ], TEST_LOCATION );
672 // Excercise the message passing to Update thread
674 application.SendNotification();
675 application.Render();
676 application.Render();
680 int UtcDaliCustomActorOnChildAddRemove(void)
682 TestApplication application;
683 tet_infoline("Testing Dali::CustomActor::OnChildAdd() & OnChildRemove()");
685 Test::TestCustomActor custom = Test::TestCustomActor::New();
686 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
688 Actor aChild = Actor::New();
689 custom.Add( aChild );
691 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
692 DALI_TEST_EQUALS( "OnChildAdd", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
694 custom.Remove( aChild );
696 DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
697 DALI_TEST_EQUALS( "OnChildRemove", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
701 int UtcDaliCustomActorReparentDuringOnChildAdd(void)
703 TestApplication application;
704 tet_infoline("Testing Actor:Add (reparenting) behaviour during Dali::CustomActor::OnChildAdd() callback");
706 Integration::Scene stage = application.GetScene();
708 MasterCallStack.clear();
710 /* The actorA is a special variant which reparents children added into a separate container child
711 * The actorB is the child of actorA
714 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant7( "ActorA" );
717 Test::TestCustomActor actorB = Test::TestCustomActor::New();
718 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
719 actorA.Add( actorB );
721 // Check hierarchy is as follows:
728 DALI_TEST_EQUALS( 1, (int)(actorA.GetChildCount()), TEST_LOCATION );
730 Actor container = actorA.GetChildAt(0);
731 Actor containerChild;
733 DALI_TEST_CHECK( container );
736 DALI_TEST_EQUALS( "Container", container.GetProperty< std::string >( Actor::Property::NAME ), TEST_LOCATION );
737 DALI_TEST_EQUALS( 1, (int)(container.GetChildCount()), TEST_LOCATION );
738 containerChild = container.GetChildAt(0);
741 DALI_TEST_CHECK( containerChild );
742 if ( containerChild )
744 DALI_TEST_EQUALS( "ActorB", containerChild.GetProperty< std::string >( Actor::Property::NAME ), TEST_LOCATION );
745 DALI_TEST_EQUALS( 0, (int)(containerChild.GetChildCount()), TEST_LOCATION );
748 // Check callback sequence
750 DALI_TEST_EQUALS( 5, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
751 DALI_TEST_EQUALS( "OnPropertySet", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
752 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION ); // The mContainer added to actorA
753 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
754 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION ); // The actorB added to actorA
755 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 4 ], TEST_LOCATION );
756 // mContainer will then receive OnChildAdd
758 DALI_TEST_EQUALS( 4, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
759 DALI_TEST_EQUALS( "OnPropertySet", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
760 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
761 DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
762 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 3 ], TEST_LOCATION );
764 DALI_TEST_EQUALS( 9, (int)(MasterCallStack.size()), TEST_LOCATION );
766 DALI_TEST_EQUALS( "ActorA: OnPropertySet", MasterCallStack[ 0 ], TEST_LOCATION );
767 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 1 ], TEST_LOCATION );
768 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 2 ], TEST_LOCATION );
769 DALI_TEST_EQUALS( "ActorB: OnPropertySet", MasterCallStack[ 3 ], TEST_LOCATION );
770 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 4 ], TEST_LOCATION );
771 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 5 ], TEST_LOCATION );
772 DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 6 ], TEST_LOCATION );
773 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 7 ], TEST_LOCATION );
774 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 8 ], TEST_LOCATION );
776 // Excercise the message passing to Update thread
778 application.SendNotification();
779 application.Render();
780 application.Render();
785 * Test that Remove can be called (a NOOP) during the OnChildRemove
786 * triggered when reparenting an actor
788 int UtcDaliCustomActorRemoveDuringOnChildRemove(void)
790 TestApplication application;
791 tet_infoline("Testing Actor:Remove behaviour during OnChildRemove() callback triggered when reparenting");
793 Integration::Scene stage = application.GetScene();
795 MasterCallStack.clear();
797 /* The childActor will be reparented from actorA to actorB
798 * The actorA is a special variant which attempts to remove a child from actorB, during the OnChildRemove callback()
799 * This should be a NOOP since the reparenting has not occured yet
802 Test::TestCustomActor actorB = Test::TestCustomActor::New();
803 actorB.SetProperty( Actor::Property::NAME, "ActorB" );
806 Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant8( actorB );
807 actorA.SetProperty( Actor::Property::NAME, "ActorA" );
810 Actor childActor = Actor::New();
811 childActor.SetProperty( Actor::Property::NAME, "Child" );
812 // Reparent from actorA to actorB
813 actorA.Add( childActor );
814 actorB.Add( childActor );
816 // Check hierarchy is as follows:
821 DALI_TEST_EQUALS( 0, (int)(actorA.GetChildCount()), TEST_LOCATION );
822 DALI_TEST_EQUALS( 1, (int)(actorB.GetChildCount()), TEST_LOCATION );
823 DALI_TEST_EQUALS( 0, (int)(childActor.GetChildCount()), TEST_LOCATION );
825 Actor child = actorB.GetChildAt(0);
827 DALI_TEST_CHECK( child );
830 DALI_TEST_EQUALS( "Child", child.GetProperty< std::string >( Actor::Property::NAME ), TEST_LOCATION );
833 // Check callback sequence
835 DALI_TEST_EQUALS( 4, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
836 DALI_TEST_EQUALS( "OnPropertySet", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
837 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION ); // The mContainer added to actorA
838 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
839 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION ); // The actorB added to actorA
840 // mContainer will then receive OnChildAdd
842 DALI_TEST_EQUALS( 4, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
843 DALI_TEST_EQUALS( "OnPropertySet", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
844 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
845 // The derived class are always notified, no matter the child is successfully removed or not
846 DALI_TEST_EQUALS( "OnChildRemove", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
847 DALI_TEST_EQUALS( "OnChildAdd", actorB.GetMethodsCalled()[ 3 ], TEST_LOCATION );
849 DALI_TEST_EQUALS( 8, (int)(MasterCallStack.size()), TEST_LOCATION );
851 DALI_TEST_EQUALS( "ActorB: OnPropertySet", MasterCallStack[ 0 ], TEST_LOCATION );
852 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION );
853 DALI_TEST_EQUALS( "ActorA: OnPropertySet", MasterCallStack[ 2 ], TEST_LOCATION );
854 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 3 ], TEST_LOCATION );
855 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION );
856 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 5 ], TEST_LOCATION );
857 // The derived class are always notified, no matter the child is successfully removed or not
858 DALI_TEST_EQUALS( "ActorB: OnChildRemove", MasterCallStack[ 6 ], TEST_LOCATION );
859 DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 7 ], TEST_LOCATION );
861 // Excercise the message passing to Update thread
863 application.SendNotification();
864 application.Render();
865 application.Render();
869 int UtcDaliCustomActorOnPropertySet(void)
871 TestApplication application;
872 tet_infoline("Testing Dali::CustomActor::OnPropertySet()");
874 Test::TestCustomActor custom = Test::TestCustomActor::New();
875 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
877 custom.SetDaliProperty("yes");
879 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
880 DALI_TEST_EQUALS( "OnPropertySet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
884 int UtcDaliCustomActorOnSizeSet(void)
886 TestApplication application;
887 tet_infoline("Testing Dali::CustomActor::OnSizeSet()");
889 Test::TestCustomActor custom = Test::TestCustomActor::New();
890 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
892 custom.SetProperty( Actor::Property::SIZE, Vector2( 9.0f, 10.0f ) );
893 DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
894 DALI_TEST_EQUALS( "OnSizeSet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
895 DALI_TEST_EQUALS( "OnPropertySet", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
896 DALI_TEST_EQUALS( 9.0f, custom.GetSize().width, TEST_LOCATION );
897 DALI_TEST_EQUALS( 10.0f, custom.GetSize().height, TEST_LOCATION );
899 custom.SetProperty( Actor::Property::SIZE, Vector3( 4.0f, 5.0f, 6.0f ) );
900 DALI_TEST_EQUALS( 4, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
901 DALI_TEST_EQUALS( "OnSizeSet", custom.GetMethodsCalled()[ 2 ], TEST_LOCATION );
902 DALI_TEST_EQUALS( "OnPropertySet", custom.GetMethodsCalled()[ 3 ], TEST_LOCATION );
903 DALI_TEST_EQUALS( 4.0f, custom.GetSize().width, TEST_LOCATION );
904 DALI_TEST_EQUALS( 5.0f, custom.GetSize().height, TEST_LOCATION );
905 DALI_TEST_EQUALS( 6.0f, custom.GetSize().depth, TEST_LOCATION );
909 int UtcDaliCustomActorOnSizeAnimation(void)
911 TestApplication application;
912 tet_infoline("Testing Dali::CustomActor::OnSizeAnimation()");
914 Test::TestCustomActor custom = Test::TestCustomActor::New();
915 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
917 Animation anim = Animation::New( 1.0f );
918 anim.AnimateTo( Property( custom, Actor::Property::SIZE ), Vector3( 8.0f, 9.0f, 10.0f ) );
921 application.SendNotification();
922 application.Render( static_cast<unsigned int>( 1000.0f ) );
924 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
925 DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
926 DALI_TEST_EQUALS( 8.0f, custom.GetTargetSize().width, TEST_LOCATION );
927 DALI_TEST_EQUALS( 9.0f, custom.GetTargetSize().height, TEST_LOCATION );
928 DALI_TEST_EQUALS( 10.0f, custom.GetTargetSize().depth, TEST_LOCATION );
932 int UtcDaliCustomActorSizeComponentAnimation(void)
934 TestApplication application;
935 tet_infoline("Testing Size component animation");
937 Test::TestCustomActor custom = Test::TestCustomActor::New();
938 float intialWidth( 10.0f );
940 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
941 custom.SetProperty( Actor::Property::SIZE, Vector2( intialWidth, 10.0f) ); // First method
943 Animation anim = Animation::New( 1.0f );
945 DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
947 anim.AnimateTo( Property( custom, Actor::Property::SIZE_WIDTH ), 20.0f );
949 DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
951 anim.Play(); // Triggers second method ( OnSizeAnimation )
953 application.SendNotification();
954 application.Render( static_cast<unsigned int>( 1000.0f ) );
956 DALI_TEST_EQUALS( 3, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
958 DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 2 ], TEST_LOCATION );
964 int UtcDaliCustomActorOnTouchEvent(void)
966 TestApplication application;
967 tet_infoline("Testing Dali::CustomActor::OnTouchEvent()");
969 Test::TestCustomActor custom = Test::TestCustomActor::New();
970 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
972 // set size for custom actor
973 custom.SetProperty( Actor::Property::SIZE, Vector2( 100, 100 ) );
974 // add the custom actor to stage
975 application.GetScene().Add( custom );
976 custom.ResetCallStack();
978 // Render and notify a couple of times
979 application.SendNotification();
980 application.Render();
981 application.SendNotification();
982 application.Render();
984 // simulate a touch event
985 Dali::Integration::Point point;
986 point.SetState( PointState::DOWN );
987 point.SetScreenPosition( Vector2( 1, 1 ) );
988 Dali::Integration::TouchEvent event;
989 event.AddPoint( point );
990 application.ProcessEvent( event );
992 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
993 DALI_TEST_EQUALS( "OnTouchEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
997 int UtcDaliCustomActorOnHoverEvent(void)
999 TestApplication application;
1000 tet_infoline("Testing Dali::CustomActor::OnHoverEvent()");
1002 Test::TestCustomActor custom = Test::TestCustomActor::New();
1003 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1005 // set size for custom actor
1006 custom.SetProperty( Actor::Property::SIZE, Vector2( 100, 100 ) );
1007 // add the custom actor to stage
1008 application.GetScene().Add( custom );
1009 custom.ResetCallStack();
1011 // Render and notify a couple of times
1012 application.SendNotification();
1013 application.Render();
1014 application.SendNotification();
1015 application.Render();
1017 // simulate a hover event
1018 Dali::Integration::Point point;
1019 point.SetState( PointState::MOTION );
1020 point.SetScreenPosition( Vector2( 1, 1 ) );
1021 Dali::Integration::HoverEvent event;
1022 event.AddPoint( point );
1023 application.ProcessEvent( event );
1025 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1026 DALI_TEST_EQUALS( "OnHoverEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1030 int UtcDaliCustomActorOnWheelEvent(void)
1032 TestApplication application;
1033 tet_infoline("Testing Dali::CustomActor::OnWheelEvent()");
1035 Test::TestCustomActor custom = Test::TestCustomActor::New();
1036 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1038 // set size for custom actor
1039 custom.SetProperty( Actor::Property::SIZE, Vector2( 100, 100 ) );
1040 // add the custom actor to stage
1041 application.GetScene().Add( custom );
1042 custom.ResetCallStack();
1044 // Render and notify a couple of times
1045 application.SendNotification();
1046 application.Render();
1047 application.SendNotification();
1048 application.Render();
1050 // simulate a wheel event
1051 Vector2 screenCoordinates( 10.0f, 10.0f );
1052 Integration::WheelEvent event( Integration::WheelEvent::MOUSE_WHEEL, 0, 0u, screenCoordinates, 1, 1000u );
1053 application.ProcessEvent( event );
1055 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1056 DALI_TEST_EQUALS( "OnWheelEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1060 int UtcDaliCustomActorImplOnPropertySet(void)
1062 TestApplication application;
1063 CustomActorImpl* impl = new Test::Impl::SimpleTestCustomActor();
1064 CustomActor customActor( *impl ); // Will automatically unref at the end of this function
1066 impl->OnPropertySet( 0, 0 );
1068 DALI_TEST_CHECK( true );
1073 int UtcDaliCustomActorGetImplementation(void)
1075 TestApplication application;
1077 Test::TestCustomActor custom = Test::TestCustomActor::New();
1078 CustomActorImpl& impl = custom.GetImplementation();
1079 impl.GetOwner(); // Test
1081 const Test::TestCustomActor constCustom = Test::TestCustomActor::New();
1082 const CustomActorImpl& constImpl = constCustom.GetImplementation();
1083 constImpl.GetOwner(); // Test
1085 DALI_TEST_CHECK( true );
1089 int UtcDaliCustomActorDoAction(void)
1091 TestApplication application;
1092 tet_infoline("Testing Dali::CustomActor::DoAction()");
1094 Test::TestCustomActor custom = Test::TestCustomActor::New();
1096 BaseHandle customActorObject = custom;
1098 DALI_TEST_CHECK(customActorObject);
1100 Property::Map attributes;
1102 // Check that an invalid command is not performed
1103 DALI_TEST_CHECK(customActorObject.DoAction("invalidCommand", attributes) == false);
1105 // Check that the custom actor is visible
1106 custom.SetProperty( Actor::Property::VISIBLE,true);
1107 DALI_TEST_CHECK(custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) == true);
1109 // Check the custom actor performed an action to hide itself
1110 DALI_TEST_CHECK(customActorObject.DoAction("hide", attributes) == true);
1112 // flush the queue and render once
1113 application.SendNotification();
1114 application.Render();
1116 // Check that the custom actor is now invisible
1117 DALI_TEST_CHECK(custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) == false);
1119 // Check the custom actor performed an action to show itself
1120 DALI_TEST_CHECK(customActorObject.DoAction("show", attributes) == true);
1122 // flush the queue and render once
1123 application.SendNotification();
1124 application.Render();
1126 // Check that the custom actor is now visible
1127 DALI_TEST_CHECK(custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) == true);
1131 int UtcDaliCustomActorCustomActor(void)
1133 Dali::CustomActor customA;
1134 Dali::CustomActor customB( customA );
1136 DALI_TEST_CHECK( customA == customB );
1141 int UtcDaliCustomActorImplRelayoutRequest(void)
1143 TestApplication application;
1145 DALI_TEST_CHECK( gOnRelayout == false );
1147 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1148 application.GetScene().Add(custom);
1150 application.SendNotification();
1151 application.Render();
1153 DALI_TEST_CHECK( gOnRelayout == true );
1154 gOnRelayout = false;
1156 custom.TestRelayoutRequest();
1157 application.SendNotification();
1158 application.Render();
1160 DALI_TEST_CHECK( gOnRelayout == true );
1165 int UtcDaliCustomActorImplGetHeightForWidthBase(void)
1167 TestApplication application;
1168 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1170 float width = 300.0f;
1172 application.SendNotification();
1173 application.Render();
1175 float v = custom.TestGetHeightForWidthBase( width );
1177 DALI_TEST_CHECK( v == width );
1182 int UtcDaliCustomActorImplGetWidthForHeightBase(void)
1184 TestApplication application;
1185 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1187 float height = 300.0f;
1189 application.SendNotification();
1190 application.Render();
1192 float v = custom.TestGetWidthForHeightBase( height );
1194 DALI_TEST_CHECK( v == height );
1199 int UtcDaliCustomActorImplCalculateChildSizeBase(void)
1201 TestApplication application;
1202 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1204 Actor child = Actor::New();
1205 child.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1206 child.SetProperty( Actor::Property::SIZE, Vector2( 150, 150 ) );
1208 application.SendNotification();
1209 application.Render();
1211 float v = custom.TestCalculateChildSizeBase( child, Dali::Dimension::ALL_DIMENSIONS );
1212 DALI_TEST_CHECK( v == 0.0f );
1217 int UtcDaliCustomActorImplRelayoutDependentOnChildrenBase(void)
1219 TestApplication application;
1220 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1221 custom.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS);
1223 bool v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::ALL_DIMENSIONS );
1224 DALI_TEST_CHECK( v == true );
1226 application.SendNotification();
1227 application.Render();
1229 custom.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1230 v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::WIDTH );
1231 DALI_TEST_CHECK( v == false );
1233 // why is this here?
1234 application.SendNotification();
1235 application.Render();
1240 int UtcDaliCustomActorTypeRegistry(void)
1242 TestApplication application;
1246 type = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
1247 DALI_TEST_CHECK( type );
1248 BaseHandle handle = type.CreateInstance();
1251 std::string exception;
1255 name = handle.GetTypeName();
1256 tet_result(TET_FAIL);
1258 catch( DaliException& e )
1260 exception = e.condition;
1261 DALI_TEST_EQUALS( exception, "handle && \"BaseObject handle is empty\"", TEST_LOCATION );
1268 int UtcDaliCustomActorGetExtensionP(void)
1270 TestApplication application;
1272 Test::TestCustomActor custom = Test::TestCustomActor::NewVariant5();
1274 DALI_TEST_CHECK( NULL == custom.GetImplementation().GetExtension() );
1279 int UtcDaliCustomActorOnConnectionDepth(void)
1281 TestApplication application;
1282 tet_infoline("Testing Dali::CustomActor::OnStageConnection() hierarchy depth");
1284 Integration::Scene stage = application.GetScene();
1286 /* Build tree of actors:
1296 * OnStageConnection should return 1 for A, 2 for B and C, and 3 for D, E and F.
1299 Test::TestCustomActor actorA = Test::TestCustomActor::New();
1300 stage.Add( actorA );
1302 Test::TestCustomActor actorB = Test::TestCustomActor::New();
1303 actorA.Add( actorB );
1305 Test::TestCustomActor actorC = Test::TestCustomActor::New();
1306 actorA.Add( actorC );
1308 Test::TestCustomActor actorD = Test::TestCustomActor::New();
1309 actorB.Add( actorD );
1311 Test::TestCustomActor actorE = Test::TestCustomActor::New();
1312 actorB.Add( actorE );
1314 Test::TestCustomActor actorF = Test::TestCustomActor::New();
1315 actorC.Add( actorF );
1317 // Excercise the message passing to Update thread
1318 application.SendNotification();
1319 application.Render();
1320 application.Render();
1322 DALI_TEST_EQUALS( 1u, actorA.GetDepth(), TEST_LOCATION );
1323 DALI_TEST_EQUALS( 2u, actorB.GetDepth(), TEST_LOCATION );
1324 DALI_TEST_EQUALS( 2u, actorC.GetDepth(), TEST_LOCATION );
1325 DALI_TEST_EQUALS( 3u, actorD.GetDepth(), TEST_LOCATION );
1326 DALI_TEST_EQUALS( 3u, actorE.GetDepth(), TEST_LOCATION );
1327 DALI_TEST_EQUALS( 3u, actorF.GetDepth(), TEST_LOCATION );
1333 int UtcDaliCustomActorSetGetProperty(void)
1335 TestApplication application; // Need the type registry
1337 Test::TestCustomActor actor = Test::TestCustomActor::New();
1338 application.GetScene().Add( actor );
1340 actor.SetProperty( Test::TestCustomActor::Property::TEST_PROPERTY1, 0.5f );
1341 actor.SetProperty( Test::TestCustomActor::Property::TEST_PROPERTY2, Color::WHITE );
1342 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3, Color::BLUE );
1343 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4, 20 );
1344 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5, 40.0f );
1346 Property::Value value = actor.GetProperty( Test::TestCustomActor::Property::TEST_PROPERTY1 );
1347 DALI_TEST_EQUALS( value.Get<float>(), 0.5f, 0.001f, TEST_LOCATION );
1349 value = actor.GetProperty( Test::TestCustomActor::Property::TEST_PROPERTY2 );
1350 DALI_TEST_EQUALS( value.Get<Vector4>(), Color::WHITE, 0.001f, TEST_LOCATION );
1353 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3 );
1354 DALI_TEST_EQUALS( value.Get<Vector4>(), Color::BLUE, 0.001f, TEST_LOCATION );
1356 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4 );
1357 DALI_TEST_EQUALS( value.Get<int>(), 20, TEST_LOCATION );
1359 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5 );
1360 DALI_TEST_EQUALS( value.Get<float>(), 40.0f, 0.001f, TEST_LOCATION );
1362 // Get read-only property
1363 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6 );
1364 DALI_TEST_EQUALS( value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION );
1366 // Attempt to set read-only property and then ensure value hasn't changed
1367 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6, 40.0f );
1368 DALI_TEST_EQUALS( value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION );
1373 int utcDaliActorGetTypeInfo(void)
1375 TestApplication application;
1376 tet_infoline( "Get the type info of a derived actor" );
1378 Test::TestCustomActor customActor = Test::TestCustomActor::New();
1380 Dali::TypeInfo typeInfo = Dali::DevelCustomActor::GetTypeInfo( customActor );
1382 DALI_TEST_EQUALS( typeInfo.GetName(), std::string("TestCustomActor"), TEST_LOCATION );
1390 * A custom actor that is not type registered on purpose
1392 struct UnregisteredCustomActor : public Dali::CustomActorImpl
1394 UnregisteredCustomActor() : CustomActorImpl( ACTOR_BEHAVIOUR_DEFAULT )
1396 virtual ~UnregisteredCustomActor()
1398 virtual void OnStageConnection( int32_t depth )
1400 virtual void OnStageDisconnection()
1402 virtual void OnChildAdd(Actor& child)
1404 virtual void OnChildRemove(Actor& child)
1406 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue )
1408 virtual void OnSizeSet(const Vector3& targetSize)
1410 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1412 virtual bool OnTouchEvent(const TouchEvent& event) DALI_DEPRECATED_API
1414 virtual bool OnHoverEvent(const HoverEvent& event)
1416 virtual bool OnKeyEvent(const KeyEvent& event)
1418 virtual bool OnWheelEvent(const WheelEvent& event)
1420 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
1422 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1424 virtual Vector3 GetNaturalSize()
1425 { return Vector3(); }
1426 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
1428 virtual float GetHeightForWidth( float width )
1430 virtual float GetWidthForHeight( float height )
1432 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
1434 virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
1436 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
1440 struct UnregisteredCustomActor : public Dali::CustomActor
1442 static UnregisteredCustomActor New()
1444 Impl::UnregisteredCustomActor* impl = new Impl::UnregisteredCustomActor;
1445 UnregisteredCustomActor custom( *impl ); // takes ownership
1448 UnregisteredCustomActor()
1450 ~UnregisteredCustomActor()
1452 UnregisteredCustomActor( Internal::CustomActor* impl )
1453 : CustomActor( impl )
1455 UnregisteredCustomActor( Impl::UnregisteredCustomActor& impl )
1456 : CustomActor( impl )
1458 static UnregisteredCustomActor DownCast( BaseHandle handle )
1460 UnregisteredCustomActor hndl;
1461 CustomActor custom = Dali::CustomActor::DownCast( handle );
1464 CustomActorImpl& customImpl = custom.GetImplementation();
1466 Impl::UnregisteredCustomActor* impl = dynamic_cast<Impl::UnregisteredCustomActor*>( &customImpl );
1470 hndl = UnregisteredCustomActor( customImpl.GetOwner() );
1477 int UtcDaliCustomActorSetGetActorPropertyActionSignal(void)
1479 TestApplication application; // Need the type registry
1481 auto custom = UnregisteredCustomActor::New();
1482 application.GetScene().Add( custom );
1484 // should have all actor properties
1485 DALI_TEST_EQUALS( custom.GetPropertyType( Actor::Property::COLOR ), Property::VECTOR4, TEST_LOCATION );
1486 auto actorHandle = Actor::New();
1487 DALI_TEST_EQUALS( custom.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION );
1489 DALI_TEST_EQUALS( custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ), true, TEST_LOCATION );
1490 custom.SetProperty( Actor::Property::VISIBLE, false );
1491 application.SendNotification();
1492 application.Render(); // IsVisible returns scene value
1493 DALI_TEST_EQUALS( custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ), false, TEST_LOCATION );
1495 // should have custom actor typename (as it has not registered itself)
1496 DALI_TEST_EQUALS( "CustomActor", custom.GetTypeName(), TEST_LOCATION );
1498 // should have actor actions
1499 custom.DoAction( "show", Property::Map() );
1500 DALI_TEST_EQUALS( custom.GetProperty( Actor::Property::VISIBLE ).Get<bool>(), true, TEST_LOCATION );
1502 Animation animation = Animation::New(0.01f); // very short animation
1503 // should be able to animate actor property
1504 animation.AnimateTo( Property( custom, Actor::Property::POSITION ), Vector3( 100.0f, 150.0f, 200.0f ) );
1507 application.SendNotification();
1508 application.Render(1000.f);
1510 DALI_TEST_EQUALS( Vector3( 100.0f, 150.0f, 200.0f ), custom.GetProperty( Actor::Property::POSITION ).Get<Vector3>(), TEST_LOCATION );
1511 DALI_TEST_EQUALS( Vector3( 100.0f, 150.0f, 200.0f ), custom.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), TEST_LOCATION );
1513 Dali::WeakHandle<UnregisteredCustomActor> weakRef( custom );
1514 // should have actor signals
1515 custom.ConnectSignal( &application, "offStage",
1518 DALI_TEST_EQUALS( weakRef.GetHandle().GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ), false, TEST_LOCATION );
1521 application.GetScene().Remove( custom );
1522 application.GetScene().Add( custom );
1529 struct DerivedCustomActor : public UnregisteredCustomActor
1533 struct DerivedCustomActor : public UnregisteredCustomActor
1535 static DerivedCustomActor New()
1537 Impl::DerivedCustomActor* impl = new Impl::DerivedCustomActor;
1538 DerivedCustomActor custom( *impl ); // takes ownership
1541 DerivedCustomActor()
1543 ~DerivedCustomActor()
1545 DerivedCustomActor( Internal::CustomActor* impl )
1546 : UnregisteredCustomActor( impl )
1548 DerivedCustomActor( Impl::UnregisteredCustomActor& impl )
1549 : UnregisteredCustomActor( impl )
1554 DALI_TYPE_REGISTRATION_BEGIN( DerivedCustomActor, UnregisteredCustomActor, nullptr );
1555 DALI_TYPE_REGISTRATION_END()
1557 int UtcDaliCustomActorPropertyRegistrationDefaultValue(void)
1559 TestApplication application; // Need the type registry
1561 // register our base and add a property with default value for it
1562 Dali::TypeRegistration typeRegistration( typeid( UnregisteredCustomActor ), typeid( Dali::CustomActor ), nullptr );
1564 auto derived = DerivedCustomActor::New();
1565 application.GetScene().Add( derived );
1567 // should have all actor properties
1568 DALI_TEST_EQUALS( derived.GetPropertyType( Actor::Property::WORLD_MATRIX ), Property::MATRIX, TEST_LOCATION );
1569 auto actorHandle = Actor::New();
1570 DALI_TEST_EQUALS( derived.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION );
1572 // add a property in base class
1573 AnimatablePropertyRegistration( typeRegistration, "Foobar", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, 10.f );
1575 // should be one more property now
1576 DALI_TEST_EQUALS( derived.GetPropertyCount(), actorHandle.GetPropertyCount() + 1, TEST_LOCATION );
1577 // check that the default value is set for base class
1578 DALI_TEST_EQUALS( UnregisteredCustomActor::New().GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION );
1579 // check that the default value is set for the derived instance as well
1580 DALI_TEST_EQUALS( derived.GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION );