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