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