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.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 Stage::GetCurrent().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 Stage stage = Stage::GetCurrent();
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 Stage stage = Stage::GetCurrent();
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 Stage stage = Stage::GetCurrent();
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 Stage stage = Stage::GetCurrent();
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 Stage stage = Stage::GetCurrent();
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 Stage stage = Stage::GetCurrent();
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 Stage stage = Stage::GetCurrent();
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 Stage stage = Stage::GetCurrent();
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 Stage stage = Stage::GetCurrent();
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.SetSize( Vector2( 9.0f, 10.0f ) );
893 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
894 DALI_TEST_EQUALS( "OnSizeSet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
895 DALI_TEST_EQUALS( 9.0f, custom.GetSize().width, TEST_LOCATION );
896 DALI_TEST_EQUALS( 10.0f, custom.GetSize().height, TEST_LOCATION );
898 custom.SetSize( Vector3( 4.0f, 5.0f, 6.0f ) );
899 DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
900 DALI_TEST_EQUALS( "OnSizeSet", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
901 DALI_TEST_EQUALS( 4.0f, custom.GetSize().width, TEST_LOCATION );
902 DALI_TEST_EQUALS( 5.0f, custom.GetSize().height, TEST_LOCATION );
903 DALI_TEST_EQUALS( 6.0f, custom.GetSize().depth, TEST_LOCATION );
907 int UtcDaliCustomActorOnSizeAnimation(void)
909 TestApplication application;
910 tet_infoline("Testing Dali::CustomActor::OnSizeAnimation()");
912 Test::TestCustomActor custom = Test::TestCustomActor::New();
913 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
915 Animation anim = Animation::New( 1.0f );
916 anim.AnimateTo( Property( custom, Actor::Property::SIZE ), Vector3( 8.0f, 9.0f, 10.0f ) );
919 application.SendNotification();
920 application.Render( static_cast<unsigned int>( 1000.0f ) );
922 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
923 DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
924 DALI_TEST_EQUALS( 8.0f, custom.GetTargetSize().width, TEST_LOCATION );
925 DALI_TEST_EQUALS( 9.0f, custom.GetTargetSize().height, TEST_LOCATION );
926 DALI_TEST_EQUALS( 10.0f, custom.GetTargetSize().depth, TEST_LOCATION );
930 int UtcDaliCustomActorSizeComponentAnimation(void)
932 TestApplication application;
933 tet_infoline("Testing Size component animation");
935 Test::TestCustomActor custom = Test::TestCustomActor::New();
936 float intialWidth( 10.0f );
938 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
939 custom.SetSize( intialWidth, 10.0f); // First method
941 Animation anim = Animation::New( 1.0f );
943 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
945 anim.AnimateTo( Property( custom, Actor::Property::SIZE_WIDTH ), 20.0f );
947 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
949 anim.Play(); // Triggers second method ( OnSizeAnimation )
951 application.SendNotification();
952 application.Render( static_cast<unsigned int>( 1000.0f ) );
954 DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
956 DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
962 int UtcDaliCustomActorOnTouchEvent(void)
964 TestApplication application;
965 tet_infoline("Testing Dali::CustomActor::OnTouchEvent()");
967 Test::TestCustomActor custom = Test::TestCustomActor::New();
968 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
970 // set size for custom actor
971 custom.SetSize( 100, 100 );
972 // add the custom actor to stage
973 Stage::GetCurrent().Add( custom );
974 custom.ResetCallStack();
976 // Render and notify a couple of times
977 application.SendNotification();
978 application.Render();
979 application.SendNotification();
980 application.Render();
982 // simulate a touch event
983 Dali::Integration::Point point;
984 point.SetState( PointState::DOWN );
985 point.SetScreenPosition( Vector2( 1, 1 ) );
986 Dali::Integration::TouchEvent event;
987 event.AddPoint( point );
988 application.ProcessEvent( event );
990 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
991 DALI_TEST_EQUALS( "OnTouchEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
995 int UtcDaliCustomActorOnHoverEvent(void)
997 TestApplication application;
998 tet_infoline("Testing Dali::CustomActor::OnHoverEvent()");
1000 Test::TestCustomActor custom = Test::TestCustomActor::New();
1001 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1003 // set size for custom actor
1004 custom.SetSize( 100, 100 );
1005 // add the custom actor to stage
1006 Stage::GetCurrent().Add( custom );
1007 custom.ResetCallStack();
1009 // Render and notify a couple of times
1010 application.SendNotification();
1011 application.Render();
1012 application.SendNotification();
1013 application.Render();
1015 // simulate a hover event
1016 Dali::Integration::Point point;
1017 point.SetState( PointState::MOTION );
1018 point.SetScreenPosition( Vector2( 1, 1 ) );
1019 Dali::Integration::HoverEvent event;
1020 event.AddPoint( point );
1021 application.ProcessEvent( event );
1023 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1024 DALI_TEST_EQUALS( "OnHoverEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1028 int UtcDaliCustomActorOnWheelEvent(void)
1030 TestApplication application;
1031 tet_infoline("Testing Dali::CustomActor::OnWheelEvent()");
1033 Test::TestCustomActor custom = Test::TestCustomActor::New();
1034 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1036 // set size for custom actor
1037 custom.SetSize( 100, 100 );
1038 // add the custom actor to stage
1039 Stage::GetCurrent().Add( custom );
1040 custom.ResetCallStack();
1042 // Render and notify a couple of times
1043 application.SendNotification();
1044 application.Render();
1045 application.SendNotification();
1046 application.Render();
1048 // simulate a wheel event
1049 Vector2 screenCoordinates( 10.0f, 10.0f );
1050 Integration::WheelEvent event( Integration::WheelEvent::MOUSE_WHEEL, 0, 0u, screenCoordinates, 1, 1000u );
1051 application.ProcessEvent( event );
1053 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1054 DALI_TEST_EQUALS( "OnWheelEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1058 int UtcDaliCustomActorImplOnPropertySet(void)
1060 TestApplication application;
1061 CustomActorImpl* impl = new Test::Impl::SimpleTestCustomActor();
1062 CustomActor customActor( *impl ); // Will automatically unref at the end of this function
1064 impl->OnPropertySet( 0, 0 );
1066 DALI_TEST_CHECK( true );
1071 int UtcDaliCustomActorGetImplementation(void)
1073 TestApplication application;
1075 Test::TestCustomActor custom = Test::TestCustomActor::New();
1076 CustomActorImpl& impl = custom.GetImplementation();
1077 impl.GetOwner(); // Test
1079 const Test::TestCustomActor constCustom = Test::TestCustomActor::New();
1080 const CustomActorImpl& constImpl = constCustom.GetImplementation();
1081 constImpl.GetOwner(); // Test
1083 DALI_TEST_CHECK( true );
1087 int UtcDaliCustomActorDoAction(void)
1089 TestApplication application;
1090 tet_infoline("Testing Dali::CustomActor::DoAction()");
1092 Test::TestCustomActor custom = Test::TestCustomActor::New();
1094 BaseHandle customActorObject = custom;
1096 DALI_TEST_CHECK(customActorObject);
1098 Property::Map attributes;
1100 // Check that an invalid command is not performed
1101 DALI_TEST_CHECK(customActorObject.DoAction("invalidCommand", attributes) == false);
1103 // Check that the custom actor is visible
1104 custom.SetProperty( Actor::Property::VISIBLE,true);
1105 DALI_TEST_CHECK(custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) == true);
1107 // Check the custom actor performed an action to hide itself
1108 DALI_TEST_CHECK(customActorObject.DoAction("hide", attributes) == true);
1110 // flush the queue and render once
1111 application.SendNotification();
1112 application.Render();
1114 // Check that the custom actor is now invisible
1115 DALI_TEST_CHECK(custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) == false);
1117 // Check the custom actor performed an action to show itself
1118 DALI_TEST_CHECK(customActorObject.DoAction("show", attributes) == true);
1120 // flush the queue and render once
1121 application.SendNotification();
1122 application.Render();
1124 // Check that the custom actor is now visible
1125 DALI_TEST_CHECK(custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) == true);
1129 int UtcDaliCustomActorCustomActor(void)
1131 Dali::CustomActor customA;
1132 Dali::CustomActor customB( customA );
1134 DALI_TEST_CHECK( customA == customB );
1139 int UtcDaliCustomActorImplRelayoutRequest(void)
1141 TestApplication application;
1143 DALI_TEST_CHECK( gOnRelayout == false );
1145 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1146 Stage::GetCurrent().Add(custom);
1148 application.SendNotification();
1149 application.Render();
1151 DALI_TEST_CHECK( gOnRelayout == true );
1152 gOnRelayout = false;
1154 custom.TestRelayoutRequest();
1155 application.SendNotification();
1156 application.Render();
1158 DALI_TEST_CHECK( gOnRelayout == true );
1163 int UtcDaliCustomActorImplGetHeightForWidthBase(void)
1165 TestApplication application;
1166 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1168 float width = 300.0f;
1170 application.SendNotification();
1171 application.Render();
1173 float v = custom.TestGetHeightForWidthBase( width );
1175 DALI_TEST_CHECK( v == width );
1180 int UtcDaliCustomActorImplGetWidthForHeightBase(void)
1182 TestApplication application;
1183 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1185 float height = 300.0f;
1187 application.SendNotification();
1188 application.Render();
1190 float v = custom.TestGetWidthForHeightBase( height );
1192 DALI_TEST_CHECK( v == height );
1197 int UtcDaliCustomActorImplCalculateChildSizeBase(void)
1199 TestApplication application;
1200 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1202 Actor child = Actor::New();
1203 child.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1204 child.SetSize(150, 150);
1206 application.SendNotification();
1207 application.Render();
1209 float v = custom.TestCalculateChildSizeBase( child, Dali::Dimension::ALL_DIMENSIONS );
1210 DALI_TEST_CHECK( v == 0.0f );
1215 int UtcDaliCustomActorImplRelayoutDependentOnChildrenBase(void)
1217 TestApplication application;
1218 Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1219 custom.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS);
1221 bool v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::ALL_DIMENSIONS );
1222 DALI_TEST_CHECK( v == true );
1224 application.SendNotification();
1225 application.Render();
1227 custom.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1228 v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::WIDTH );
1229 DALI_TEST_CHECK( v == false );
1231 // why is this here?
1232 application.SendNotification();
1233 application.Render();
1238 int UtcDaliCustomActorTypeRegistry(void)
1240 TestApplication application;
1244 type = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
1245 DALI_TEST_CHECK( type );
1246 BaseHandle handle = type.CreateInstance();
1249 std::string exception;
1253 name = handle.GetTypeName();
1254 tet_result(TET_FAIL);
1256 catch( DaliException& e )
1258 exception = e.condition;
1259 DALI_TEST_EQUALS( exception, "handle && \"BaseObject handle is empty\"", TEST_LOCATION );
1266 int UtcDaliCustomActorGetExtensionP(void)
1268 TestApplication application;
1270 Test::TestCustomActor custom = Test::TestCustomActor::NewVariant5();
1272 DALI_TEST_CHECK( NULL == custom.GetImplementation().GetExtension() );
1277 int UtcDaliCustomActorOnConnectionDepth(void)
1279 TestApplication application;
1280 tet_infoline("Testing Dali::CustomActor::OnStageConnection() hierarchy depth");
1282 Stage stage = Stage::GetCurrent();
1284 /* Build tree of actors:
1294 * OnStageConnection should return 1 for A, 2 for B and C, and 3 for D, E and F.
1297 Test::TestCustomActor actorA = Test::TestCustomActor::New();
1298 stage.Add( actorA );
1300 Test::TestCustomActor actorB = Test::TestCustomActor::New();
1301 actorA.Add( actorB );
1303 Test::TestCustomActor actorC = Test::TestCustomActor::New();
1304 actorA.Add( actorC );
1306 Test::TestCustomActor actorD = Test::TestCustomActor::New();
1307 actorB.Add( actorD );
1309 Test::TestCustomActor actorE = Test::TestCustomActor::New();
1310 actorB.Add( actorE );
1312 Test::TestCustomActor actorF = Test::TestCustomActor::New();
1313 actorC.Add( actorF );
1315 // Excercise the message passing to Update thread
1316 application.SendNotification();
1317 application.Render();
1318 application.Render();
1320 DALI_TEST_EQUALS( 1u, actorA.GetDepth(), TEST_LOCATION );
1321 DALI_TEST_EQUALS( 2u, actorB.GetDepth(), TEST_LOCATION );
1322 DALI_TEST_EQUALS( 2u, actorC.GetDepth(), TEST_LOCATION );
1323 DALI_TEST_EQUALS( 3u, actorD.GetDepth(), TEST_LOCATION );
1324 DALI_TEST_EQUALS( 3u, actorE.GetDepth(), TEST_LOCATION );
1325 DALI_TEST_EQUALS( 3u, actorF.GetDepth(), TEST_LOCATION );
1331 int UtcDaliCustomActorSetGetProperty(void)
1333 TestApplication application; // Need the type registry
1335 Test::TestCustomActor actor = Test::TestCustomActor::New();
1336 Stage::GetCurrent().Add( actor );
1338 actor.SetProperty( Test::TestCustomActor::Property::TEST_PROPERTY1, 0.5f );
1339 actor.SetProperty( Test::TestCustomActor::Property::TEST_PROPERTY2, Color::WHITE );
1340 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3, Color::BLUE );
1341 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4, 20 );
1342 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5, 40.0f );
1344 Property::Value value = actor.GetProperty( Test::TestCustomActor::Property::TEST_PROPERTY1 );
1345 DALI_TEST_EQUALS( value.Get<float>(), 0.5f, 0.001f, TEST_LOCATION );
1347 value = actor.GetProperty( Test::TestCustomActor::Property::TEST_PROPERTY2 );
1348 DALI_TEST_EQUALS( value.Get<Vector4>(), Color::WHITE, 0.001f, TEST_LOCATION );
1351 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3 );
1352 DALI_TEST_EQUALS( value.Get<Vector4>(), Color::BLUE, 0.001f, TEST_LOCATION );
1354 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4 );
1355 DALI_TEST_EQUALS( value.Get<int>(), 20, TEST_LOCATION );
1357 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5 );
1358 DALI_TEST_EQUALS( value.Get<float>(), 40.0f, 0.001f, TEST_LOCATION );
1360 // Get read-only property
1361 value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6 );
1362 DALI_TEST_EQUALS( value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION );
1364 // Attempt to set read-only property and then ensure value hasn't changed
1365 actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6, 40.0f );
1366 DALI_TEST_EQUALS( value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION );
1371 int utcDaliActorGetTypeInfo(void)
1373 TestApplication application;
1374 tet_infoline( "Get the type info of a derived actor" );
1376 Test::TestCustomActor customActor = Test::TestCustomActor::New();
1378 Dali::TypeInfo typeInfo = Dali::DevelCustomActor::GetTypeInfo( customActor );
1380 DALI_TEST_EQUALS( typeInfo.GetName(), std::string("TestCustomActor"), TEST_LOCATION );
1388 * A custom actor that is not type registered on purpose
1390 struct UnregisteredCustomActor : public Dali::CustomActorImpl
1392 UnregisteredCustomActor() : CustomActorImpl( ACTOR_BEHAVIOUR_DEFAULT )
1394 virtual ~UnregisteredCustomActor()
1396 virtual void OnStageConnection( int32_t depth )
1398 virtual void OnStageDisconnection()
1400 virtual void OnChildAdd(Actor& child)
1402 virtual void OnChildRemove(Actor& child)
1404 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue )
1406 virtual void OnSizeSet(const Vector3& targetSize)
1408 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1410 virtual bool OnTouchEvent(const TouchEvent& event) DALI_DEPRECATED_API
1412 virtual bool OnHoverEvent(const HoverEvent& event)
1414 virtual bool OnKeyEvent(const KeyEvent& event)
1416 virtual bool OnWheelEvent(const WheelEvent& event)
1418 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
1420 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1422 virtual Vector3 GetNaturalSize()
1423 { return Vector3(); }
1424 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
1426 virtual float GetHeightForWidth( float width )
1428 virtual float GetWidthForHeight( float height )
1430 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
1432 virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
1434 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
1438 struct UnregisteredCustomActor : public Dali::CustomActor
1440 static UnregisteredCustomActor New()
1442 Impl::UnregisteredCustomActor* impl = new Impl::UnregisteredCustomActor;
1443 UnregisteredCustomActor custom( *impl ); // takes ownership
1446 UnregisteredCustomActor()
1448 ~UnregisteredCustomActor()
1450 UnregisteredCustomActor( Internal::CustomActor* impl )
1451 : CustomActor( impl )
1453 UnregisteredCustomActor( Impl::UnregisteredCustomActor& impl )
1454 : CustomActor( impl )
1456 static UnregisteredCustomActor DownCast( BaseHandle handle )
1458 UnregisteredCustomActor hndl;
1459 CustomActor custom = Dali::CustomActor::DownCast( handle );
1462 CustomActorImpl& customImpl = custom.GetImplementation();
1464 Impl::UnregisteredCustomActor* impl = dynamic_cast<Impl::UnregisteredCustomActor*>( &customImpl );
1468 hndl = UnregisteredCustomActor( customImpl.GetOwner() );
1475 int UtcDaliCustomActorSetGetActorPropertyActionSignal(void)
1477 TestApplication application; // Need the type registry
1479 auto custom = UnregisteredCustomActor::New();
1480 Stage::GetCurrent().Add( custom );
1482 // should have all actor properties
1483 DALI_TEST_EQUALS( custom.GetPropertyType( Actor::Property::COLOR ), Property::VECTOR4, TEST_LOCATION );
1484 auto actorHandle = Actor::New();
1485 DALI_TEST_EQUALS( custom.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION );
1487 DALI_TEST_EQUALS( custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ), true, TEST_LOCATION );
1488 custom.SetProperty( Actor::Property::VISIBLE, false );
1489 application.SendNotification();
1490 application.Render(); // IsVisible returns scene value
1491 DALI_TEST_EQUALS( custom.GetCurrentProperty< bool >( Actor::Property::VISIBLE ), false, TEST_LOCATION );
1493 // should have custom actor typename (as it has not registered itself)
1494 DALI_TEST_EQUALS( "CustomActor", custom.GetTypeName(), TEST_LOCATION );
1496 // should have actor actions
1497 custom.DoAction( "show", Property::Map() );
1498 DALI_TEST_EQUALS( custom.GetProperty( Actor::Property::VISIBLE ).Get<bool>(), true, TEST_LOCATION );
1500 Animation animation = Animation::New(0.01f); // very short animation
1501 // should be able to animate actor property
1502 animation.AnimateTo( Property( custom, Actor::Property::POSITION ), Vector3( 100.0f, 150.0f, 200.0f ) );
1505 application.SendNotification();
1506 application.Render(1000.f);
1508 DALI_TEST_EQUALS( Vector3( 100.0f, 150.0f, 200.0f ), custom.GetProperty( Actor::Property::POSITION ).Get<Vector3>(), TEST_LOCATION );
1509 DALI_TEST_EQUALS( Vector3( 100.0f, 150.0f, 200.0f ), custom.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), TEST_LOCATION );
1511 Dali::WeakHandle<UnregisteredCustomActor> weakRef( custom );
1512 // should have actor signals
1513 custom.ConnectSignal( &application, "offStage",
1516 DALI_TEST_EQUALS( weakRef.GetHandle().OnStage(), false, TEST_LOCATION );
1519 Stage::GetCurrent().Remove( custom );
1520 Stage::GetCurrent().Add( custom );
1527 struct DerivedCustomActor : public UnregisteredCustomActor
1531 struct DerivedCustomActor : public UnregisteredCustomActor
1533 static DerivedCustomActor New()
1535 Impl::DerivedCustomActor* impl = new Impl::DerivedCustomActor;
1536 DerivedCustomActor custom( *impl ); // takes ownership
1539 DerivedCustomActor()
1541 ~DerivedCustomActor()
1543 DerivedCustomActor( Internal::CustomActor* impl )
1544 : UnregisteredCustomActor( impl )
1546 DerivedCustomActor( Impl::UnregisteredCustomActor& impl )
1547 : UnregisteredCustomActor( impl )
1552 DALI_TYPE_REGISTRATION_BEGIN( DerivedCustomActor, UnregisteredCustomActor, nullptr );
1553 DALI_TYPE_REGISTRATION_END()
1555 int UtcDaliCustomActorPropertyRegistrationDefaultValue(void)
1557 TestApplication application; // Need the type registry
1559 // register our base and add a property with default value for it
1560 Dali::TypeRegistration typeRegistration( typeid( UnregisteredCustomActor ), typeid( Dali::CustomActor ), nullptr );
1562 auto derived = DerivedCustomActor::New();
1563 Stage::GetCurrent().Add( derived );
1565 // should have all actor properties
1566 DALI_TEST_EQUALS( derived.GetPropertyType( Actor::Property::WORLD_MATRIX ), Property::MATRIX, TEST_LOCATION );
1567 auto actorHandle = Actor::New();
1568 DALI_TEST_EQUALS( derived.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION );
1570 // add a property in base class
1571 AnimatablePropertyRegistration( typeRegistration, "Foobar", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, 10.f );
1573 // should be one more property now
1574 DALI_TEST_EQUALS( derived.GetPropertyCount(), actorHandle.GetPropertyCount() + 1, TEST_LOCATION );
1575 // check that the default value is set for base class
1576 DALI_TEST_EQUALS( UnregisteredCustomActor::New().GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION );
1577 // check that the default value is set for the derived instance as well
1578 DALI_TEST_EQUALS( derived.GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION );