Remove deprecated APIs in Tizen 3.0
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-CustomActor.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20 #include <dali/public-api/dali-core.h>
21
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"
30
31 using namespace Dali;
32
33
34 void custom_actor_test_startup(void)
35 {
36   test_return_value = TET_UNDEF;
37 }
38
39 void custom_actor_test_cleanup(void)
40 {
41   test_return_value = TET_PASS;
42 }
43
44
45
46 using namespace Dali;
47
48
49 int UtcDaliCustomActorDestructor(void)
50 {
51   TestApplication application;
52
53   CustomActor* actor = new CustomActor();
54   delete actor;
55
56   DALI_TEST_CHECK( true );
57   END_TEST;
58 }
59
60 int UtcDaliCustomActorImplDestructor(void)
61 {
62   TestApplication application;
63   CustomActorImpl* actor = new Test::Impl::TestCustomActor();
64   CustomActor customActor( *actor ); // Will automatically unref at the end of this function
65
66   DALI_TEST_CHECK( true );
67   END_TEST;
68 }
69
70 // Positive test case for a method
71 int UtcDaliCustomActorDownCast(void)
72 {
73   TestApplication application;
74   tet_infoline("Testing Dali::CustomActor::DownCast()");
75
76   Test::TestCustomActor custom = Test::TestCustomActor::New();
77
78   Actor anActor = Actor::New();
79   anActor.Add( custom );
80
81   Actor child = anActor.GetChildAt(0);
82   CustomActor customActor = CustomActor::DownCast( child );
83   DALI_TEST_CHECK( customActor );
84
85   customActor = NULL;
86   DALI_TEST_CHECK( !customActor );
87
88   customActor = DownCast< CustomActor >( child );
89   DALI_TEST_CHECK( customActor );
90   END_TEST;
91 }
92
93 // Negative test case for a method
94 int UtcDaliCustomActorDownCastNegative(void)
95 {
96   TestApplication application;
97   tet_infoline("Testing Dali::CustomActor::DownCast()");
98
99   Actor actor1 = Actor::New();
100   Actor anActor = Actor::New();
101   anActor.Add(actor1);
102
103   Actor child = anActor.GetChildAt(0);
104   CustomActor customActor = CustomActor::DownCast( child );
105   DALI_TEST_CHECK( !customActor );
106
107   Actor unInitialzedActor;
108   customActor = CustomActor::DownCast( unInitialzedActor );
109   DALI_TEST_CHECK( !customActor );
110
111   customActor = DownCast< CustomActor >( unInitialzedActor );
112   DALI_TEST_CHECK( !customActor );
113   END_TEST;
114 }
115
116 int UtcDaliCustomActorOnStageConnectionDisconnection(void)
117 {
118   TestApplication application;
119   tet_infoline("Testing Dali::CustomActor::OnStageConnection() & OnStageDisconnection");
120
121   Test::TestCustomActor custom = Test::TestCustomActor::New();
122   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
123
124   // add the custom actor to stage
125   Stage::GetCurrent().Add( custom );
126
127   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
128   DALI_TEST_EQUALS( "OnStageConnection", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
129
130   Stage::GetCurrent().Remove( custom );
131
132   DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
133   DALI_TEST_EQUALS( "OnStageDisconnection", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
134
135   // Excercise the message passing to Update thread
136
137   application.SendNotification();
138   application.Render();
139   application.Render();
140   END_TEST;
141 }
142
143 int UtcDaliCustomActorOnStageConnectionOrder(void)
144 {
145   TestApplication application;
146   tet_infoline("Testing Dali::CustomActor::OnStageConnection() order");
147
148   MasterCallStack.clear();
149
150   /* Build tree of actors:
151    *
152    *       A (parent)
153    *      / \
154    *     B   C
155    *    / \   \
156    *   D   E   F
157    *
158    * OnStageConnection should be received for A, B, D, E, C, and finally F
159    */
160
161   Test::TestCustomActor actorA = Test::TestCustomActor::New();
162   actorA.SetName( "ActorA" );
163
164   Test::TestCustomActor actorB = Test::TestCustomActor::New();
165   actorB.SetName( "ActorB" );
166   actorA.Add( actorB );
167
168   Test::TestCustomActor actorC = Test::TestCustomActor::New();
169   actorC.SetName( "ActorC" );
170   actorA.Add( actorC );
171
172   Test::TestCustomActor actorD = Test::TestCustomActor::New();
173   actorD.SetName( "ActorD" );
174   actorB.Add( actorD );
175
176   Test::TestCustomActor actorE = Test::TestCustomActor::New();
177   actorE.SetName( "ActorE" );
178   actorB.Add( actorE );
179
180   Test::TestCustomActor actorF = Test::TestCustomActor::New();
181   actorF.SetName( "ActorF" );
182   actorC.Add( actorF );
183
184   // add the custom actor to stage
185   Stage::GetCurrent().Add( actorA );
186
187   DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
188   DALI_TEST_EQUALS( "OnChildAdd",        actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
189   DALI_TEST_EQUALS( "OnChildAdd",        actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
190   DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
191
192   DALI_TEST_EQUALS( 3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
193   DALI_TEST_EQUALS( "OnChildAdd",        actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
194   DALI_TEST_EQUALS( "OnChildAdd",        actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
195   DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
196
197   DALI_TEST_EQUALS( 2, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
198   DALI_TEST_EQUALS( "OnChildAdd",        actorC.GetMethodsCalled()[ 0 ], TEST_LOCATION );
199   DALI_TEST_EQUALS( "OnStageConnection", actorC.GetMethodsCalled()[ 1 ], TEST_LOCATION );
200
201   DALI_TEST_EQUALS( 1, (int)(actorD.GetMethodsCalled().size()), TEST_LOCATION );
202   DALI_TEST_EQUALS( "OnStageConnection", actorD.GetMethodsCalled()[ 0 ], TEST_LOCATION );
203
204   DALI_TEST_EQUALS( 1, (int)(actorE.GetMethodsCalled().size()), TEST_LOCATION );
205   DALI_TEST_EQUALS( "OnStageConnection", actorE.GetMethodsCalled()[ 0 ], TEST_LOCATION );
206
207   DALI_TEST_EQUALS( 1, (int)(actorF.GetMethodsCalled().size()), TEST_LOCATION );
208   DALI_TEST_EQUALS( "OnStageConnection", actorF.GetMethodsCalled()[ 0 ], TEST_LOCATION );
209
210   // Check sequence is correct in MasterCallStack
211
212   DALI_TEST_EQUALS( 3+3+2+1+1+1, (int)(MasterCallStack.size()), TEST_LOCATION );
213
214   DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 0 ], TEST_LOCATION );
215   DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 1 ], TEST_LOCATION );
216   DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION );
217   DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 3 ], TEST_LOCATION );
218   DALI_TEST_EQUALS( "ActorC: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION );
219
220   DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 5 ], TEST_LOCATION );
221   DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 6 ], TEST_LOCATION );
222   DALI_TEST_EQUALS( "ActorD: OnStageConnection", MasterCallStack[ 7 ], TEST_LOCATION );
223   DALI_TEST_EQUALS( "ActorE: OnStageConnection", MasterCallStack[ 8 ], TEST_LOCATION );
224   DALI_TEST_EQUALS( "ActorC: OnStageConnection", MasterCallStack[ 9 ], TEST_LOCATION );
225   DALI_TEST_EQUALS( "ActorF: OnStageConnection", MasterCallStack[ 10 ], TEST_LOCATION );
226
227   // Excercise the message passing to Update thread
228
229   application.SendNotification();
230   application.Render();
231   application.Render();
232   END_TEST;
233 }
234
235 int UtcDaliCustomActorOnStageDisconnectionOrder(void)
236 {
237   TestApplication application;
238   tet_infoline("Testing Dali::CustomActor::OnStageDisconnection() order");
239
240   Stage stage = Stage::GetCurrent();
241
242   /* Build tree of actors:
243    *
244    *       A (parent)
245    *      / \
246    *     B   C
247    *    / \   \
248    *   D   E   F
249    *
250    * OnStageDisconnection should be received for D, E, B, F, C, and finally A.
251    */
252
253   Test::TestCustomActor actorA = Test::TestCustomActor::New();
254   actorA.SetName( "ActorA" );
255   stage.Add( actorA );
256
257   Test::TestCustomActor actorB = Test::TestCustomActor::New();
258   actorB.SetName( "ActorB" );
259   actorA.Add( actorB );
260
261   Test::TestCustomActor actorC = Test::TestCustomActor::New();
262   actorC.SetName( "ActorC" );
263   actorA.Add( actorC );
264
265   Test::TestCustomActor actorD = Test::TestCustomActor::New();
266   actorD.SetName( "ActorD" );
267   actorB.Add( actorD );
268
269   Test::TestCustomActor actorE = Test::TestCustomActor::New();
270   actorE.SetName( "ActorE" );
271   actorB.Add( actorE );
272
273   Test::TestCustomActor actorF = Test::TestCustomActor::New();
274   actorF.SetName( "ActorF" );
275   actorC.Add( actorF );
276
277   // Excercise the message passing to Update thread
278
279   application.SendNotification();
280   application.Render();
281   application.Render();
282
283   // Clear call stacks before disconnection
284   actorA.ResetCallStack();
285   actorB.ResetCallStack();
286   actorC.ResetCallStack();
287   actorD.ResetCallStack();
288   actorE.ResetCallStack();
289   actorF.ResetCallStack();
290   MasterCallStack.clear();
291
292   stage.Remove( actorA );
293
294   DALI_TEST_EQUALS( 1, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
295   DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
296
297   DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
298   DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
299
300   DALI_TEST_EQUALS( 1, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
301   DALI_TEST_EQUALS( "OnStageDisconnection", actorC.GetMethodsCalled()[ 0 ], TEST_LOCATION );
302
303   DALI_TEST_EQUALS( 1, (int)(actorD.GetMethodsCalled().size()), TEST_LOCATION );
304   DALI_TEST_EQUALS( "OnStageDisconnection", actorD.GetMethodsCalled()[ 0 ], TEST_LOCATION );
305
306   DALI_TEST_EQUALS( 1, (int)(actorE.GetMethodsCalled().size()), TEST_LOCATION );
307   DALI_TEST_EQUALS( "OnStageDisconnection", actorE.GetMethodsCalled()[ 0 ], TEST_LOCATION );
308
309   DALI_TEST_EQUALS( 1, (int)(actorF.GetMethodsCalled().size()), TEST_LOCATION );
310   DALI_TEST_EQUALS( "OnStageDisconnection", actorF.GetMethodsCalled()[ 0 ], TEST_LOCATION );
311
312   // Check sequence is correct in MasterCallStack
313
314   DALI_TEST_EQUALS( 6, (int)(MasterCallStack.size()), TEST_LOCATION );
315
316   DALI_TEST_EQUALS( "ActorD: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
317   DALI_TEST_EQUALS( "ActorE: OnStageDisconnection", MasterCallStack[ 1 ], TEST_LOCATION );
318   DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 2 ], TEST_LOCATION );
319   DALI_TEST_EQUALS( "ActorF: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
320   DALI_TEST_EQUALS( "ActorC: OnStageDisconnection", MasterCallStack[ 4 ], TEST_LOCATION );
321   DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 5 ], TEST_LOCATION );
322
323   // Excercise the message passing to Update thread
324
325   application.SendNotification();
326   application.Render();
327   application.Render();
328   END_TEST;
329 }
330
331 int UtcDaliCustomActorAddDuringOnStageConnection(void)
332 {
333   TestApplication application;
334   tet_infoline("Testing Actor::Add behaviour during Dali::CustomActor::OnStageConnection() callback");
335
336   Stage stage = Stage::GetCurrent();
337
338   MasterCallStack.clear();
339
340   /* The actorA is a special variant which adds a child to itself during OnStageConnection()
341    * The actorB is provided as the child
342    */
343
344   Test::TestCustomActor actorB = Test::TestCustomActor::New();
345   actorB.SetName( "ActorB" );
346
347   Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant1( actorB );
348   actorA.SetName( "ActorA" );
349   stage.Add( actorA );
350
351   // Check callback sequence
352
353   DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
354   DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
355   DALI_TEST_EQUALS( "OnChildAdd",        actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION ); // Called from within OnStageConnection()
356
357   DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
358   DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
359
360   DALI_TEST_EQUALS( 3, (int)(MasterCallStack.size()), TEST_LOCATION );
361
362   DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 0 ], TEST_LOCATION );
363   DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION ); // Occurs during Actor::Add from within from within OnStageConnection()
364   DALI_TEST_EQUALS( "ActorA: OnChildAdd",        MasterCallStack[ 2 ], TEST_LOCATION ); // Occurs after Actor::Add from within from within OnStageConnection()
365
366   // Excercise the message passing to Update thread
367
368   application.SendNotification();
369   application.Render();
370   application.Render();
371
372   // Check everything is ok after Actors are removed
373
374   stage.Remove( actorA );
375   application.SendNotification();
376   application.Render();
377   application.Render();
378   END_TEST;
379 }
380
381 int UtcDaliCustomActorRemoveDuringOnStageConnection(void)
382 {
383   TestApplication application;
384   tet_infoline("Testing Actor::Remove behaviour during Dali::CustomActor::OnStageConnection() callback");
385
386   Stage stage = Stage::GetCurrent();
387
388   MasterCallStack.clear();
389
390   /* The actorA is a special variant which removes its children during OnStageConnection()
391    * Actors B & C are provided as the children
392    */
393
394   Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant2();
395   actorA.SetName( "ActorA" );
396
397   Test::TestCustomActor actorB = Test::TestCustomActor::New();
398   actorB.SetName( "ActorB" );
399   actorA.Add( actorB );
400
401   Test::TestCustomActor actorC = Test::TestCustomActor::New();
402   actorC.SetName( "ActorC" );
403   actorA.Add( actorC );
404
405   stage.Add( actorA );
406
407   // Check callback sequence
408
409   DALI_TEST_EQUALS( 5, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
410   DALI_TEST_EQUALS( "OnChildAdd",        actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
411   DALI_TEST_EQUALS( "OnChildAdd",        actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
412   DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
413   DALI_TEST_EQUALS( "OnChildRemove",     actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION ); // Called from within OnStageConnection()
414   DALI_TEST_EQUALS( "OnChildRemove",     actorA.GetMethodsCalled()[ 4 ], TEST_LOCATION ); // Called from within OnStageConnection()
415
416   DALI_TEST_EQUALS( 5, (int)(MasterCallStack.size()), TEST_LOCATION );
417
418   DALI_TEST_EQUALS( "ActorA: OnChildAdd",        MasterCallStack[ 0 ], TEST_LOCATION );
419   DALI_TEST_EQUALS( "ActorA: OnChildAdd",        MasterCallStack[ 1 ], TEST_LOCATION );
420   DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 2 ], TEST_LOCATION );
421   DALI_TEST_EQUALS( "ActorA: OnChildRemove",     MasterCallStack[ 3 ], TEST_LOCATION );
422   DALI_TEST_EQUALS( "ActorA: OnChildRemove",     MasterCallStack[ 4 ], TEST_LOCATION );
423
424   /* Actors B & C should be removed before the point where they could receive an OnStageConnection callback
425    * Therefore they shouldn't receive either OnStageConnection or OnStageDisconnection
426    */
427   DALI_TEST_EQUALS( 0, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
428   DALI_TEST_EQUALS( 0, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
429
430   // Excercise the message passing to Update thread
431
432   application.SendNotification();
433   application.Render();
434   application.Render();
435
436   // Check everything is ok after last actor is removed
437
438   stage.Remove( actorA );
439   application.SendNotification();
440   application.Render();
441   application.Render();
442   END_TEST;
443 }
444
445 int UtcDaliCustomActorAddDuringOnStageDisconnection(void)
446 {
447   TestApplication application;
448   tet_infoline("Testing Actor::Add behaviour during Dali::CustomActor::OnStageDisonnection() callback");
449
450   Stage stage = Stage::GetCurrent();
451
452   /* The actorA is a special variant which adds a child to itself during OnStageDisconnection()
453    * The actorB is provided as the child
454    */
455
456   Test::TestCustomActor actorB = Test::TestCustomActor::New();
457   actorB.SetName( "ActorB" );
458
459   Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant3( actorB );
460   actorA.SetName( "ActorA" );
461   stage.Add( actorA );
462
463   // Excercise the message passing to Update thread
464
465   application.SendNotification();
466   application.Render();
467   application.Render();
468
469   // Clear call stacks before disconnection
470   actorA.ResetCallStack();
471   actorB.ResetCallStack();
472   MasterCallStack.clear();
473
474   stage.Remove( actorA );
475
476   // Check callback sequence
477
478   DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
479   DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
480   DALI_TEST_EQUALS( "OnChildAdd",           actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
481
482   // Child was added after parent disconnection, so should not receive OnStageConnection()
483   DALI_TEST_EQUALS( 0, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
484
485   DALI_TEST_EQUALS( 2, (int)(MasterCallStack.size()), TEST_LOCATION );
486
487   DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
488   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 1 ], TEST_LOCATION );
489
490   // Excercise the message passing to Update thread
491
492   application.SendNotification();
493   application.Render();
494   application.Render();
495   END_TEST;
496 }
497
498 int UtcDaliCustomActorRemoveDuringOnStageDisconnection(void)
499 {
500   TestApplication application;
501   tet_infoline("Testing Actor::Remove behaviour during Dali::CustomActor::OnStageDisconnection() callback");
502
503   Stage stage = Stage::GetCurrent();
504
505   /* The actorA is a special variant which removes its children during OnStageDisconnection()
506    * The actorB is provided as the child
507    */
508
509   Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant4();
510   actorA.SetName( "ActorA" );
511   stage.Add( actorA );
512
513   Test::TestCustomActor actorB = Test::TestCustomActor::New();
514   actorB.SetName( "ActorB" );
515   actorA.Add( actorB );
516
517   // Excercise the message passing to Update thread
518
519   application.SendNotification();
520   application.Render();
521   application.Render();
522
523   // Clear call stacks before disconnection
524   actorA.ResetCallStack();
525   actorB.ResetCallStack();
526   MasterCallStack.clear();
527
528   stage.Remove( actorA );
529
530   // Check callback sequence
531
532   DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
533   DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
534   DALI_TEST_EQUALS( "OnChildRemove",        actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
535
536   DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
537   DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
538
539   DALI_TEST_EQUALS( 3, (int)(MasterCallStack.size()), TEST_LOCATION );
540
541   DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
542   DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 1 ], TEST_LOCATION );
543   DALI_TEST_EQUALS( "ActorA: OnChildRemove",        MasterCallStack[ 2 ], TEST_LOCATION );
544
545   // Excercise the message passing to Update thread
546
547   application.SendNotification();
548   application.Render();
549   application.Render();
550   END_TEST;
551 }
552
553 int UtcDaliCustomActorRemoveParentDuringOnStageConnection(void)
554 {
555   TestApplication application;
556   tet_infoline("Weird test where child removes its own parent from Stage during Dali::CustomActor::OnStageConnection() callback");
557
558   Stage stage = Stage::GetCurrent();
559
560   MasterCallStack.clear();
561
562   /* The actorA is the parent of actorB
563    * The actorB is a special variant which removes its own parent during OnStageConnection()
564    * The child actor is interrupting the parent's connection to stage, therefore the parent should not get an OnStageDisconnection()
565    */
566
567   Test::TestCustomActor actorA = Test::TestCustomActor::New();
568   actorA.SetName( "ActorA" );
569
570   Test::TestCustomActor actorB = Test::TestCustomActor::NewVariant5();
571   actorB.SetName( "ActorB" );
572   actorA.Add( actorB );
573
574   stage.Add( actorA );
575
576   // Check callback sequence
577
578   DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
579   DALI_TEST_EQUALS( "OnChildAdd",           actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
580   DALI_TEST_EQUALS( "OnStageConnection",    actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
581   DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
582
583   DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
584   DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
585
586   DALI_TEST_EQUALS( 4, (int)(MasterCallStack.size()), TEST_LOCATION );
587
588   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 0 ], TEST_LOCATION );
589   DALI_TEST_EQUALS( "ActorA: OnStageConnection",    MasterCallStack[ 1 ], TEST_LOCATION );
590   DALI_TEST_EQUALS( "ActorB: OnStageConnection",    MasterCallStack[ 2 ], TEST_LOCATION );
591   DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
592
593   // Excercise the message passing to Update thread
594
595   application.SendNotification();
596   application.Render();
597   application.Render();
598   END_TEST;
599 }
600
601 int UtcDaliCustomActorAddParentDuringOnStageDisconnection(void)
602 {
603   TestApplication application;
604   tet_infoline("Weird test where child adds its own parent to Stage during Dali::CustomActor::OnStageDisconnection() callback");
605
606   Stage stage = Stage::GetCurrent();
607
608   MasterCallStack.clear();
609
610   /* The actorA is the parent of actorB
611    * The actorB is a special variant which (weirdly) adds its own parent during OnStageDisconnection()
612    * The child actor is interrupting the disconnection, such that parent should not get a OnStageDisconnection()
613    */
614
615   Test::TestCustomActor actorA = Test::TestCustomActor::New();
616   actorA.SetName( "ActorA" );
617   stage.Add( actorA );
618
619   Test::TestCustomActor actorB = Test::TestCustomActor::NewVariant6();
620   actorB.SetName( "ActorB" );
621   actorA.Add( actorB );
622
623   stage.Remove( actorA );
624
625   // Check callback sequence
626
627   DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
628   DALI_TEST_EQUALS( "OnStageConnection",    actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
629   DALI_TEST_EQUALS( "OnChildAdd",           actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
630
631   DALI_TEST_EQUALS( 2, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
632   DALI_TEST_EQUALS( "OnStageConnection",    actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
633   DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
634   // Disconnect was interrupted, so we should only get one OnStageConnection() for actorB
635
636   DALI_TEST_EQUALS( 4, (int)(MasterCallStack.size()), TEST_LOCATION );
637
638   DALI_TEST_EQUALS( "ActorA: OnStageConnection",    MasterCallStack[ 0 ], TEST_LOCATION );
639   DALI_TEST_EQUALS( "ActorB: OnStageConnection",    MasterCallStack[ 1 ], TEST_LOCATION );
640   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 2 ], TEST_LOCATION );
641   DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
642
643   // Excercise the message passing to Update thread
644
645   application.SendNotification();
646   application.Render();
647   application.Render();
648   END_TEST;
649 }
650
651 int UtcDaliCustomActorOnChildAddRemove(void)
652 {
653   TestApplication application;
654   tet_infoline("Testing Dali::CustomActor::OnChildAdd() & OnChildRemove()");
655
656   Test::TestCustomActor custom = Test::TestCustomActor::New();
657   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
658
659   Actor aChild = Actor::New();
660   custom.Add( aChild );
661
662   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
663   DALI_TEST_EQUALS( "OnChildAdd", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
664
665   custom.Remove( aChild );
666
667   DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
668   DALI_TEST_EQUALS( "OnChildRemove", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
669   END_TEST;
670 }
671
672 int UtcDaliCustomActorReparentDuringOnChildAdd(void)
673 {
674   TestApplication application;
675   tet_infoline("Testing Actor:Add (reparenting) behaviour during Dali::CustomActor::OnChildAdd() callback");
676
677   Stage stage = Stage::GetCurrent();
678
679   MasterCallStack.clear();
680
681   /* The actorA is a special variant which reparents children added into a separate container child
682    * The actorB is the child of actorA
683    */
684
685   Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant7( "ActorA" );
686   stage.Add( actorA );
687
688   Test::TestCustomActor actorB = Test::TestCustomActor::New();
689   actorB.SetName( "ActorB" );
690   actorA.Add( actorB );
691
692   // Check hierarchy is as follows:
693   //  A
694   //  |
695   //  Container
696   //  |
697   //  B
698
699   DALI_TEST_EQUALS( 1, (int)(actorA.GetChildCount()), TEST_LOCATION );
700
701   Actor container = actorA.GetChildAt(0);
702   Actor containerChild;
703
704   DALI_TEST_CHECK( container );
705   if ( container )
706   {
707     DALI_TEST_EQUALS( "Container", container.GetName(), TEST_LOCATION );
708     DALI_TEST_EQUALS( 1, (int)(container.GetChildCount()), TEST_LOCATION );
709     containerChild = container.GetChildAt(0);
710   }
711
712   DALI_TEST_CHECK( containerChild );
713   if ( containerChild )
714   {
715     DALI_TEST_EQUALS( "ActorB", containerChild.GetName(), TEST_LOCATION );
716     DALI_TEST_EQUALS( 0, (int)(containerChild.GetChildCount()), TEST_LOCATION );
717   }
718
719   // Check callback sequence
720
721   DALI_TEST_EQUALS( 4, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
722   DALI_TEST_EQUALS( "OnChildAdd",           actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION ); // The mContainer added to actorA
723   DALI_TEST_EQUALS( "OnStageConnection",    actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
724   DALI_TEST_EQUALS( "OnChildAdd",           actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION ); // The actorB added to actorA
725   DALI_TEST_EQUALS( "OnChildRemove",        actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION );
726   // mContainer will then receive OnChildAdd
727
728   DALI_TEST_EQUALS( 3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
729   DALI_TEST_EQUALS( "OnStageConnection",    actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
730   DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
731   DALI_TEST_EQUALS( "OnStageConnection",    actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
732
733   DALI_TEST_EQUALS( 7, (int)(MasterCallStack.size()), TEST_LOCATION );
734
735   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 0 ], TEST_LOCATION );
736   DALI_TEST_EQUALS( "ActorA: OnStageConnection",    MasterCallStack[ 1 ], TEST_LOCATION );
737   DALI_TEST_EQUALS( "ActorB: OnStageConnection",    MasterCallStack[ 2 ], TEST_LOCATION );
738   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 3 ], TEST_LOCATION );
739   DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 4 ], TEST_LOCATION );
740   DALI_TEST_EQUALS( "ActorA: OnChildRemove",        MasterCallStack[ 5 ], TEST_LOCATION );
741   DALI_TEST_EQUALS( "ActorB: OnStageConnection",    MasterCallStack[ 6 ], TEST_LOCATION );
742
743   // Excercise the message passing to Update thread
744
745   application.SendNotification();
746   application.Render();
747   application.Render();
748   END_TEST;
749 }
750
751 /**
752  * Test that Remove can be called (a NOOP) during the OnChildRemove
753  * triggered when reparenting an actor
754  */
755 int UtcDaliCustomActorRemoveDuringOnChildRemove(void)
756 {
757   TestApplication application;
758   tet_infoline("Testing Actor:Remove behaviour during OnChildRemove() callback triggered when reparenting");
759
760   Stage stage = Stage::GetCurrent();
761
762   MasterCallStack.clear();
763
764   /* The childActor will be reparented from actorA to actorB
765    * The actorA is a special variant which attempts to remove a child from actorB, during the OnChildRemove callback()
766    * This should be a NOOP since the reparenting has not occured yet
767    */
768
769   Test::TestCustomActor actorB = Test::TestCustomActor::New();
770   actorB.SetName( "ActorB" );
771   stage.Add( actorB );
772
773   Test::TestCustomActor actorA = Test::TestCustomActor::NewVariant8( actorB );
774   actorA.SetName( "ActorA" );
775   stage.Add( actorA );
776
777   Actor childActor = Actor::New();
778   childActor.SetName( "Child" );
779   // Reparent from actorA to actorB
780   actorA.Add( childActor );
781   actorB.Add( childActor );
782
783   // Check hierarchy is as follows:
784   //  A    B
785   //       |
786   //       Child
787
788   DALI_TEST_EQUALS( 0, (int)(actorA.GetChildCount()), TEST_LOCATION );
789   DALI_TEST_EQUALS( 1, (int)(actorB.GetChildCount()), TEST_LOCATION );
790   DALI_TEST_EQUALS( 0, (int)(childActor.GetChildCount()), TEST_LOCATION );
791
792   Actor child = actorB.GetChildAt(0);
793
794   DALI_TEST_CHECK( child );
795   if ( child )
796   {
797     DALI_TEST_EQUALS( "Child", child.GetName(), TEST_LOCATION );
798   }
799
800   // Check callback sequence
801
802   DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
803   DALI_TEST_EQUALS( "OnStageConnection",    actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION ); // The mContainer added to actorA
804   DALI_TEST_EQUALS( "OnChildAdd",           actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
805   DALI_TEST_EQUALS( "OnChildRemove",        actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION ); // The actorB added to actorA
806   // mContainer will then receive OnChildAdd
807
808   DALI_TEST_EQUALS( 3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
809   DALI_TEST_EQUALS( "OnStageConnection",    actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
810   // The derived class are always notified, no matter the child is successfully removed or not
811   DALI_TEST_EQUALS( "OnChildRemove",        actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
812   DALI_TEST_EQUALS( "OnChildAdd",           actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
813
814   DALI_TEST_EQUALS( 6, (int)(MasterCallStack.size()), TEST_LOCATION );
815
816   DALI_TEST_EQUALS( "ActorB: OnStageConnection",    MasterCallStack[ 0 ], TEST_LOCATION );
817   DALI_TEST_EQUALS( "ActorA: OnStageConnection",    MasterCallStack[ 1 ], TEST_LOCATION );
818   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 2 ], TEST_LOCATION );
819   DALI_TEST_EQUALS( "ActorA: OnChildRemove",        MasterCallStack[ 3 ], TEST_LOCATION );
820   // The derived class are always notified, no matter the child is successfully removed or not
821   DALI_TEST_EQUALS( "ActorB: OnChildRemove",        MasterCallStack[ 4 ], TEST_LOCATION );
822   DALI_TEST_EQUALS( "ActorB: OnChildAdd",           MasterCallStack[ 5 ], TEST_LOCATION );
823
824   // Excercise the message passing to Update thread
825
826   application.SendNotification();
827   application.Render();
828   application.Render();
829   END_TEST;
830 }
831
832 int UtcDaliCustomActorOnPropertySet(void)
833 {
834   TestApplication application;
835   tet_infoline("Testing Dali::CustomActor::OnPropertySet()");
836
837   Test::TestCustomActor custom = Test::TestCustomActor::New();
838   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
839
840   custom.SetDaliProperty("yes");
841
842   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
843   DALI_TEST_EQUALS( "OnPropertySet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
844   END_TEST;
845 }
846
847 int UtcDaliCustomActorOnSizeSet(void)
848 {
849   TestApplication application;
850   tet_infoline("Testing Dali::CustomActor::OnSizeSet()");
851
852   Test::TestCustomActor custom = Test::TestCustomActor::New();
853   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
854
855   custom.SetSize( Vector2( 9.0f, 10.0f ) );
856   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
857   DALI_TEST_EQUALS( "OnSizeSet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
858   DALI_TEST_EQUALS( 9.0f, custom.GetSize().width, TEST_LOCATION );
859   DALI_TEST_EQUALS( 10.0f, custom.GetSize().height, TEST_LOCATION );
860
861   custom.SetSize( Vector3( 4.0f, 5.0f, 6.0f ) );
862   DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
863   DALI_TEST_EQUALS( "OnSizeSet", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
864   DALI_TEST_EQUALS( 4.0f, custom.GetSize().width, TEST_LOCATION );
865   DALI_TEST_EQUALS( 5.0f, custom.GetSize().height, TEST_LOCATION );
866   DALI_TEST_EQUALS( 6.0f, custom.GetSize().depth, TEST_LOCATION );
867   END_TEST;
868 }
869
870 int UtcDaliCustomActorOnSizeAnimation(void)
871 {
872   TestApplication application;
873   tet_infoline("Testing Dali::CustomActor::OnSizeAnimation()");
874
875   Test::TestCustomActor custom = Test::TestCustomActor::New();
876   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
877
878   Animation anim = Animation::New( 1.0f );
879   anim.AnimateTo( Property( custom, Actor::Property::SIZE ), Vector3( 8.0f, 9.0f, 10.0f ) );
880   anim.Play();
881
882   application.SendNotification();
883   application.Render( static_cast<unsigned int>( 1000.0f ) );
884
885   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
886   DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
887   DALI_TEST_EQUALS( 8.0f, custom.GetTargetSize().width, TEST_LOCATION );
888   DALI_TEST_EQUALS( 9.0f, custom.GetTargetSize().height, TEST_LOCATION );
889   DALI_TEST_EQUALS( 10.0f, custom.GetTargetSize().depth, TEST_LOCATION );
890   END_TEST;
891 }
892
893 int UtcDaliCustomActorSizeComponentAnimation(void)
894 {
895   TestApplication application;
896   tet_infoline("Testing Size component animation");
897
898   Test::TestCustomActor custom = Test::TestCustomActor::New();
899   float intialWidth( 10.0f );
900
901   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
902   custom.SetSize( intialWidth, 10.0f); // First method
903
904   Animation anim = Animation::New( 1.0f );
905
906   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
907
908   anim.AnimateTo( Property( custom, Actor::Property::SIZE_WIDTH ), 20.0f );
909
910   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
911
912   anim.Play();   // Triggers second method ( OnSizeAnimation )
913
914   application.SendNotification();
915   application.Render( static_cast<unsigned int>( 1000.0f ) );
916
917   DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
918
919   DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
920
921   END_TEST;
922
923 }
924
925 int UtcDaliCustomActorOnTouchEvent(void)
926 {
927   TestApplication application;
928   tet_infoline("Testing Dali::CustomActor::OnTouchEvent()");
929
930   Test::TestCustomActor custom = Test::TestCustomActor::New();
931   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
932
933   // set size for custom actor
934   custom.SetSize( 100, 100 );
935   // add the custom actor to stage
936   Stage::GetCurrent().Add( custom );
937   custom.ResetCallStack();
938
939   // Render and notify a couple of times
940   application.SendNotification();
941   application.Render();
942   application.SendNotification();
943   application.Render();
944
945   // simulate a touch event
946   Dali::Integration::Point point;
947   point.SetState( PointState::DOWN );
948   point.SetScreenPosition( Vector2( 1, 1 ) );
949   Dali::Integration::TouchEvent event;
950   event.AddPoint( point );
951   application.ProcessEvent( event );
952
953   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
954   DALI_TEST_EQUALS( "OnTouchEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
955   END_TEST;
956 }
957
958 int UtcDaliCustomActorOnHoverEvent(void)
959 {
960   TestApplication application;
961   tet_infoline("Testing Dali::CustomActor::OnHoverEvent()");
962
963   Test::TestCustomActor custom = Test::TestCustomActor::New();
964   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
965
966   // set size for custom actor
967   custom.SetSize( 100, 100 );
968   // add the custom actor to stage
969   Stage::GetCurrent().Add( custom );
970   custom.ResetCallStack();
971
972   // Render and notify a couple of times
973   application.SendNotification();
974   application.Render();
975   application.SendNotification();
976   application.Render();
977
978   // simulate a hover event
979   Dali::Integration::Point point;
980   point.SetState( PointState::MOTION );
981   point.SetScreenPosition( Vector2( 1, 1 ) );
982   Dali::Integration::HoverEvent event;
983   event.AddPoint( point );
984   application.ProcessEvent( event );
985
986   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
987   DALI_TEST_EQUALS( "OnHoverEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
988   END_TEST;
989 }
990
991 int UtcDaliCustomActorOnWheelEvent(void)
992 {
993   TestApplication application;
994   tet_infoline("Testing Dali::CustomActor::OnWheelEvent()");
995
996   Test::TestCustomActor custom = Test::TestCustomActor::New();
997   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
998
999   // set size for custom actor
1000   custom.SetSize( 100, 100 );
1001   // add the custom actor to stage
1002   Stage::GetCurrent().Add( custom );
1003   custom.ResetCallStack();
1004
1005   // Render and notify a couple of times
1006   application.SendNotification();
1007   application.Render();
1008   application.SendNotification();
1009   application.Render();
1010
1011   // simulate a wheel event
1012   Vector2 screenCoordinates( 10.0f, 10.0f );
1013   Integration::WheelEvent event( Integration::WheelEvent::MOUSE_WHEEL, 0, 0u, screenCoordinates, 1, 1000u );
1014   application.ProcessEvent( event );
1015
1016   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1017   DALI_TEST_EQUALS( "OnWheelEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1018   END_TEST;
1019 }
1020
1021 int UtcDaliCustomActorImplOnPropertySet(void)
1022 {
1023   TestApplication application;
1024   CustomActorImpl* impl = new Test::Impl::SimpleTestCustomActor();
1025   CustomActor customActor( *impl ); // Will automatically unref at the end of this function
1026
1027   impl->OnPropertySet( 0, 0 );
1028
1029   DALI_TEST_CHECK( true );
1030
1031   END_TEST;
1032 }
1033
1034 int UtcDaliCustomActorGetImplementation(void)
1035 {
1036   TestApplication application;
1037
1038   Test::TestCustomActor custom = Test::TestCustomActor::New();
1039   CustomActorImpl& impl = custom.GetImplementation();
1040   impl.GetOwner();  // Test
1041
1042   const Test::TestCustomActor constCustom = Test::TestCustomActor::New();
1043   const CustomActorImpl& constImpl = constCustom.GetImplementation();
1044   constImpl.GetOwner();  // Test
1045
1046   DALI_TEST_CHECK( true );
1047   END_TEST;
1048 }
1049
1050 int UtcDaliCustomActorDoAction(void)
1051 {
1052   TestApplication application;
1053   tet_infoline("Testing Dali::CustomActor::DoAction()");
1054
1055   Test::TestCustomActor custom = Test::TestCustomActor::New();
1056
1057   BaseHandle customActorObject = custom;
1058
1059   DALI_TEST_CHECK(customActorObject);
1060
1061   Property::Map attributes;
1062
1063   // Check that an invalid command is not performed
1064   DALI_TEST_CHECK(customActorObject.DoAction("invalidCommand", attributes) == false);
1065
1066   // Check that the custom actor is visible
1067   custom.SetVisible(true);
1068   DALI_TEST_CHECK(custom.IsVisible() == true);
1069
1070   // Check the custom actor performed an action to hide itself
1071   DALI_TEST_CHECK(customActorObject.DoAction("hide", attributes) == true);
1072
1073   // flush the queue and render once
1074   application.SendNotification();
1075   application.Render();
1076
1077   // Check that the custom actor is now invisible
1078   DALI_TEST_CHECK(custom.IsVisible() == false);
1079
1080   // Check the custom actor performed an action to show itself
1081   DALI_TEST_CHECK(customActorObject.DoAction("show", attributes) == true);
1082
1083   // flush the queue and render once
1084   application.SendNotification();
1085   application.Render();
1086
1087   // Check that the custom actor is now visible
1088   DALI_TEST_CHECK(custom.IsVisible() == true);
1089   END_TEST;
1090 }
1091
1092 int UtcDaliCustomActorCustomActor(void)
1093 {
1094   Dali::CustomActor customA;
1095   Dali::CustomActor customB( customA );
1096
1097   DALI_TEST_CHECK( customA == customB );
1098
1099   END_TEST;
1100 }
1101
1102 int UtcDaliCustomActorImplRelayoutRequest(void)
1103 {
1104   TestApplication application;
1105
1106   DALI_TEST_CHECK( gOnRelayout == false );
1107
1108   Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1109   Stage::GetCurrent().Add(custom);
1110
1111   application.SendNotification();
1112   application.Render();
1113
1114   DALI_TEST_CHECK( gOnRelayout == true );
1115   gOnRelayout = false;
1116
1117   custom.TestRelayoutRequest();
1118   application.SendNotification();
1119   application.Render();
1120
1121   DALI_TEST_CHECK( gOnRelayout == true );
1122
1123   END_TEST;
1124 }
1125
1126 int UtcDaliCustomActorImplGetHeightForWidthBase(void)
1127 {
1128   TestApplication application;
1129   Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1130
1131   float width = 300.0f;
1132
1133   application.SendNotification();
1134   application.Render();
1135
1136   float v = custom.TestGetHeightForWidthBase( width );
1137
1138   DALI_TEST_CHECK( v == width );
1139
1140   END_TEST;
1141 }
1142
1143 int UtcDaliCustomActorImplGetWidthForHeightBase(void)
1144 {
1145   TestApplication application;
1146   Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1147
1148   float height = 300.0f;
1149
1150   application.SendNotification();
1151   application.Render();
1152
1153   float v = custom.TestGetWidthForHeightBase( height );
1154
1155   DALI_TEST_CHECK( v == height );
1156
1157   END_TEST;
1158 }
1159
1160 int UtcDaliCustomActorImplCalculateChildSizeBase(void)
1161 {
1162   TestApplication application;
1163   Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1164
1165   Actor child = Actor::New();
1166   child.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1167   child.SetSize(150, 150);
1168
1169   application.SendNotification();
1170   application.Render();
1171
1172   float v = custom.TestCalculateChildSizeBase( child, Dali::Dimension::ALL_DIMENSIONS );
1173   DALI_TEST_CHECK( v == 0.0f );
1174
1175   END_TEST;
1176 }
1177
1178 int UtcDaliCustomActorImplRelayoutDependentOnChildrenBase(void)
1179 {
1180   TestApplication application;
1181   Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1182   custom.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS);
1183
1184   bool v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::ALL_DIMENSIONS );
1185   DALI_TEST_CHECK( v == true );
1186
1187   application.SendNotification();
1188   application.Render();
1189
1190   custom.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1191   v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::WIDTH );
1192   DALI_TEST_CHECK( v == false );
1193
1194   // why is this here?
1195   application.SendNotification();
1196   application.Render();
1197
1198   END_TEST;
1199 }
1200
1201 int UtcDaliCustomActorTypeRegistry(void)
1202 {
1203   TestApplication application;
1204
1205   // Register Type
1206   TypeInfo type;
1207   type = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
1208   DALI_TEST_CHECK( type );
1209   BaseHandle handle = type.CreateInstance();
1210
1211   std::string name;
1212   std::string exception;
1213
1214   try
1215   {
1216     name = handle.GetTypeName();
1217     tet_result(TET_FAIL);
1218   }
1219   catch( DaliException& e )
1220   {
1221     exception = e.condition;
1222     DALI_TEST_EQUALS( exception, "handle && \"BaseObject handle is empty\"", TEST_LOCATION );
1223   }
1224
1225   END_TEST;
1226 }
1227
1228
1229 int UtcDaliCustomActorGetExtensionP(void)
1230 {
1231   TestApplication application;
1232
1233   Test::TestCustomActor custom = Test::TestCustomActor::NewVariant5();
1234
1235   DALI_TEST_CHECK( NULL == custom.GetImplementation().GetExtension() );
1236
1237   END_TEST;
1238 }
1239
1240 int UtcDaliCustomActorOnConnectionDepth(void)
1241 {
1242   TestApplication application;
1243   tet_infoline("Testing Dali::CustomActor::OnStageConnection() hierarchy depth");
1244
1245   Stage stage = Stage::GetCurrent();
1246
1247   /* Build tree of actors:
1248    *
1249    *                      Depth
1250    *
1251    *       A (parent)       1
1252    *      / \
1253    *     B   C              2
1254    *    / \   \
1255    *   D   E   F            3
1256    *
1257    * OnStageConnection should return 1 for A, 2 for B and C, and 3 for D, E and F.
1258    */
1259
1260   Test::TestCustomActor actorA = Test::TestCustomActor::New();
1261   stage.Add( actorA );
1262
1263   Test::TestCustomActor actorB = Test::TestCustomActor::New();
1264   actorA.Add( actorB );
1265
1266   Test::TestCustomActor actorC = Test::TestCustomActor::New();
1267   actorA.Add( actorC );
1268
1269   Test::TestCustomActor actorD = Test::TestCustomActor::New();
1270   actorB.Add( actorD );
1271
1272   Test::TestCustomActor actorE = Test::TestCustomActor::New();
1273   actorB.Add( actorE );
1274
1275   Test::TestCustomActor actorF = Test::TestCustomActor::New();
1276   actorC.Add( actorF );
1277
1278   // Excercise the message passing to Update thread
1279   application.SendNotification();
1280   application.Render();
1281   application.Render();
1282
1283   DALI_TEST_EQUALS( 1u, actorA.GetDepth(), TEST_LOCATION );
1284   DALI_TEST_EQUALS( 2u, actorB.GetDepth(), TEST_LOCATION );
1285   DALI_TEST_EQUALS( 2u, actorC.GetDepth(), TEST_LOCATION );
1286   DALI_TEST_EQUALS( 3u, actorD.GetDepth(), TEST_LOCATION );
1287   DALI_TEST_EQUALS( 3u, actorE.GetDepth(), TEST_LOCATION );
1288   DALI_TEST_EQUALS( 3u, actorF.GetDepth(), TEST_LOCATION );
1289
1290   END_TEST;
1291 }
1292
1293
1294 int UtcDaliCustomActorSetGetProperty(void)
1295 {
1296   TestApplication application; // Need the type registry
1297
1298   Test::TestCustomActor actor = Test::TestCustomActor::New();
1299   Stage::GetCurrent().Add( actor );
1300
1301   actor.SetProperty( Test::TestCustomActor::Property::TEST_PROPERTY1, 0.5f );
1302   actor.SetProperty( Test::TestCustomActor::Property::TEST_PROPERTY2, Color::WHITE );
1303   actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3, Color::BLUE );
1304   actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4, 20 );
1305   actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5, 40.0f );
1306
1307   Property::Value value = actor.GetProperty( Test::TestCustomActor::Property::TEST_PROPERTY1 );
1308   DALI_TEST_EQUALS( value.Get<float>(), 0.5f, 0.001f, TEST_LOCATION );
1309
1310   value = actor.GetProperty( Test::TestCustomActor::Property::TEST_PROPERTY2 );
1311   DALI_TEST_EQUALS( value.Get<Vector4>(), Color::WHITE, 0.001f, TEST_LOCATION );
1312
1313
1314   value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3 );
1315   DALI_TEST_EQUALS( value.Get<Vector4>(), Color::BLUE, 0.001f, TEST_LOCATION );
1316
1317   value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4 );
1318   DALI_TEST_EQUALS( value.Get<int>(), 20, TEST_LOCATION );
1319
1320   value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5 );
1321   DALI_TEST_EQUALS( value.Get<float>(), 40.0f, 0.001f, TEST_LOCATION );
1322
1323   // Get read-only property
1324   value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6 );
1325   DALI_TEST_EQUALS( value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION );
1326
1327   // Attempt to set read-only property and then ensure value hasn't changed
1328   actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6, 40.0f );
1329   DALI_TEST_EQUALS( value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION );
1330
1331   END_TEST;
1332 }
1333
1334 int utcDaliActorGetTypeInfo(void)
1335 {
1336   TestApplication application;
1337   tet_infoline( "Get the type info of a derived actor" );
1338
1339   Test::TestCustomActor customActor = Test::TestCustomActor::New();
1340
1341   Dali::TypeInfo typeInfo = Dali::DevelCustomActor::GetTypeInfo( customActor );
1342
1343   DALI_TEST_EQUALS( typeInfo.GetName(), std::string("TestCustomActor"), TEST_LOCATION );
1344
1345   END_TEST;
1346 }
1347
1348 namespace Impl
1349 {
1350 /**
1351  * A custom actor that is not type registered on purpose
1352  */
1353 struct UnregisteredCustomActor : public Dali::CustomActorImpl
1354 {
1355   UnregisteredCustomActor() : CustomActorImpl( ACTOR_BEHAVIOUR_DEFAULT )
1356   { }
1357   virtual ~UnregisteredCustomActor()
1358   { }
1359   virtual void OnStageConnection( int32_t depth )
1360   { }
1361   virtual void OnStageDisconnection()
1362   { }
1363   virtual void OnChildAdd(Actor& child)
1364   { }
1365   virtual void OnChildRemove(Actor& child)
1366   { }
1367   virtual void OnPropertySet( Property::Index index, Property::Value propertyValue )
1368   { }
1369   virtual void OnSizeSet(const Vector3& targetSize)
1370   { }
1371   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1372   { }
1373   virtual bool OnTouchEvent(const TouchEvent& event) DALI_DEPRECATED_API
1374   { return false; }
1375   virtual bool OnHoverEvent(const HoverEvent& event)
1376   { return false; }
1377   virtual bool OnKeyEvent(const KeyEvent& event)
1378   { return false; }
1379   virtual bool OnWheelEvent(const WheelEvent& event)
1380   { return false; }
1381   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
1382   { }
1383   virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
1384   { }
1385   virtual Vector3 GetNaturalSize()
1386   { return Vector3(); }
1387   virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
1388   { return 0.f; }
1389   virtual float GetHeightForWidth( float width )
1390   { return 0.f; }
1391   virtual float GetWidthForHeight( float height )
1392   { return 0.f; }
1393   virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
1394   { return false; }
1395   virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
1396   { }
1397   virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
1398   { }
1399 };
1400 }
1401 struct UnregisteredCustomActor : public Dali::CustomActor
1402 {
1403   static UnregisteredCustomActor New()
1404   {
1405     Impl::UnregisteredCustomActor* impl = new Impl::UnregisteredCustomActor;
1406     UnregisteredCustomActor custom( *impl ); // takes ownership
1407     return custom;
1408   }
1409   UnregisteredCustomActor()
1410   { }
1411   ~UnregisteredCustomActor()
1412   { }
1413   UnregisteredCustomActor( Internal::CustomActor* impl )
1414   : CustomActor( impl )
1415   { }
1416   UnregisteredCustomActor( Impl::UnregisteredCustomActor& impl )
1417   : CustomActor( impl )
1418   { }
1419   static UnregisteredCustomActor DownCast( BaseHandle handle )
1420   {
1421     UnregisteredCustomActor hndl;
1422     CustomActor custom = Dali::CustomActor::DownCast( handle );
1423     if( custom )
1424     {
1425       CustomActorImpl& customImpl = custom.GetImplementation();
1426
1427       Impl::UnregisteredCustomActor* impl = dynamic_cast<Impl::UnregisteredCustomActor*>( &customImpl );
1428
1429       if( impl )
1430       {
1431         hndl = UnregisteredCustomActor( customImpl.GetOwner() );
1432       }
1433     }
1434     return hndl;
1435   }
1436 };
1437
1438 int UtcDaliCustomActorSetGetActorPropertyActionSignal(void)
1439 {
1440   TestApplication application; // Need the type registry
1441
1442   auto custom = UnregisteredCustomActor::New();
1443   Stage::GetCurrent().Add( custom );
1444
1445   // should have all actor properties
1446   DALI_TEST_EQUALS( custom.GetPropertyType( Actor::Property::COLOR ), Property::VECTOR4, TEST_LOCATION );
1447   auto actorHandle = Actor::New();
1448   DALI_TEST_EQUALS( custom.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION );
1449
1450   DALI_TEST_EQUALS( custom.IsVisible(), true, TEST_LOCATION );
1451   custom.SetProperty( Actor::Property::VISIBLE, false );
1452   application.SendNotification();
1453   application.Render(); // IsVisible returns scene value
1454   DALI_TEST_EQUALS( custom.IsVisible(), false, TEST_LOCATION );
1455
1456   // should have custom actor typename (as it has not registered itself)
1457   DALI_TEST_EQUALS( "CustomActor", custom.GetTypeName(), TEST_LOCATION );
1458
1459   // should have actor actions
1460   custom.DoAction( "show",  Property::Map() );
1461   DALI_TEST_EQUALS( custom.GetProperty( Actor::Property::VISIBLE ).Get<bool>(), true, TEST_LOCATION );
1462
1463   Animation animation = Animation::New(0.01f); // very short animation
1464   // should be able to animate actor property
1465   animation.AnimateTo( Property( custom, Actor::Property::POSITION ), Vector3( 100.0f, 150.0f, 200.0f ) );
1466   animation.Play();
1467
1468   application.SendNotification();
1469   application.Render(1000.f);
1470
1471   DALI_TEST_EQUALS( Vector3( 100.0f, 150.0f, 200.0f ), custom.GetProperty( Actor::Property::POSITION ).Get<Vector3>(), TEST_LOCATION );
1472   DALI_TEST_EQUALS( Vector3( 100.0f, 150.0f, 200.0f ), custom.GetCurrentPosition(), TEST_LOCATION );
1473
1474   Dali::WeakHandle<UnregisteredCustomActor> weakRef( custom );
1475   // should have actor signals
1476   custom.ConnectSignal( &application, "offStage",
1477     [weakRef]()
1478       {
1479         DALI_TEST_EQUALS( weakRef.GetHandle().OnStage(), false, TEST_LOCATION );
1480       } );
1481
1482   Stage::GetCurrent().Remove( custom );
1483   Stage::GetCurrent().Add( custom );
1484
1485   END_TEST;
1486 }
1487
1488 namespace Impl
1489 {
1490 struct DerivedCustomActor : public UnregisteredCustomActor
1491 { };
1492 }
1493
1494 struct DerivedCustomActor : public UnregisteredCustomActor
1495 {
1496   static DerivedCustomActor New()
1497   {
1498     Impl::DerivedCustomActor* impl = new Impl::DerivedCustomActor;
1499     DerivedCustomActor custom( *impl ); // takes ownership
1500     return custom;
1501   }
1502   DerivedCustomActor()
1503   { }
1504   ~DerivedCustomActor()
1505   { }
1506   DerivedCustomActor( Internal::CustomActor* impl )
1507   : UnregisteredCustomActor( impl )
1508   { }
1509   DerivedCustomActor( Impl::UnregisteredCustomActor& impl )
1510   : UnregisteredCustomActor( impl )
1511   { }
1512 };
1513
1514 // register custom
1515 DALI_TYPE_REGISTRATION_BEGIN( DerivedCustomActor, UnregisteredCustomActor, nullptr );
1516 DALI_TYPE_REGISTRATION_END()
1517
1518 int UtcDaliCustomActorPropertyRegistrationDefaultValue(void)
1519 {
1520   TestApplication application; // Need the type registry
1521
1522   // register our base and add a property with default value for it
1523   Dali::TypeRegistration typeRegistration( typeid( UnregisteredCustomActor ), typeid( Dali::CustomActor ), nullptr );
1524
1525   auto derived = DerivedCustomActor::New();
1526   Stage::GetCurrent().Add( derived );
1527
1528   // should have all actor properties
1529   DALI_TEST_EQUALS( derived.GetPropertyType( Actor::Property::WORLD_MATRIX ), Property::MATRIX, TEST_LOCATION );
1530   auto actorHandle = Actor::New();
1531   DALI_TEST_EQUALS( derived.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION );
1532
1533   // add a property in base class
1534   AnimatablePropertyRegistration( typeRegistration, "Foobar", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, 10.f );
1535
1536   // should be one more property now
1537   DALI_TEST_EQUALS( derived.GetPropertyCount(), actorHandle.GetPropertyCount() + 1, TEST_LOCATION );
1538   // check that the default value is set for base class
1539   DALI_TEST_EQUALS( UnregisteredCustomActor::New().GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION );
1540   // check that the default value is set for the derived instance as well
1541   DALI_TEST_EQUALS( derived.GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION );
1542
1543   END_TEST;
1544 }
1545