e33a7384b8dd14f94981b0c7d2f2636b88d416ee
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-CustomActor.cpp
1 /*
2  * Copyright (c) 2021 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 UtcDaliCustomActorImplSetTransparent(void)
1085 {
1086   TestApplication application; // Need the type registry
1087
1088   Test::TestCustomActor actor = Test::TestCustomActor::New();
1089   application.GetScene().Add(actor);
1090   actor.SetProperty(Actor::Property::OPACITY, 0.1f);
1091   actor.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
1092
1093   DALI_TEST_EQUALS(false, actor.IsTransparent(), TEST_LOCATION);
1094
1095   actor.SetTransparent(true);
1096
1097   // flush the queue and render once
1098   application.SendNotification();
1099   application.Render();
1100
1101   DALI_TEST_EQUALS(true, actor.IsTransparent(), TEST_LOCATION);
1102
1103   application.GetScene().Remove(actor);
1104   END_TEST;
1105 }
1106
1107 int UtcDaliCustomActorImplRelayoutRequest(void)
1108 {
1109   TestApplication application;
1110
1111   DALI_TEST_CHECK(gOnRelayout == false);
1112
1113   Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1114   application.GetScene().Add(custom);
1115
1116   application.SendNotification();
1117   application.Render();
1118
1119   DALI_TEST_CHECK(gOnRelayout == true);
1120   gOnRelayout = false;
1121
1122   custom.TestRelayoutRequest();
1123   application.SendNotification();
1124   application.Render();
1125
1126   DALI_TEST_CHECK(gOnRelayout == true);
1127
1128   END_TEST;
1129 }
1130
1131 int UtcDaliCustomActorImplGetHeightForWidthBase(void)
1132 {
1133   TestApplication       application;
1134   Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1135
1136   float width = 300.0f;
1137
1138   application.SendNotification();
1139   application.Render();
1140
1141   float v = custom.TestGetHeightForWidthBase(width);
1142
1143   DALI_TEST_CHECK(v == width);
1144
1145   END_TEST;
1146 }
1147
1148 int UtcDaliCustomActorImplGetWidthForHeightBase(void)
1149 {
1150   TestApplication       application;
1151   Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1152
1153   float height = 300.0f;
1154
1155   application.SendNotification();
1156   application.Render();
1157
1158   float v = custom.TestGetWidthForHeightBase(height);
1159
1160   DALI_TEST_CHECK(v == height);
1161
1162   END_TEST;
1163 }
1164
1165 int UtcDaliCustomActorImplCalculateChildSizeBase(void)
1166 {
1167   TestApplication       application;
1168   Test::TestCustomActor custom = Test::TestCustomActor::NewNegoSize();
1169
1170   Actor child = Actor::New();
1171   child.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1172   child.SetProperty(Actor::Property::SIZE, Vector2(150, 150));
1173
1174   application.SendNotification();
1175   application.Render();
1176
1177   float v = custom.TestCalculateChildSizeBase(child, Dali::Dimension::ALL_DIMENSIONS);
1178   DALI_TEST_CHECK(v == 0.0f);
1179
1180   END_TEST;
1181 }
1182
1183 int UtcDaliCustomActorImplRelayoutDependentOnChildrenBase(void)
1184 {
1185   TestApplication       application;
1186   Test::TestCustomActor customNego    = Test::TestCustomActor::NewNegoSize();
1187   Test::TestCustomActor customNotNego = Test::TestCustomActor::New();
1188
1189   // A custom actor with default flags has relayouting enabled on initialization,
1190   // and the default resize policy is USE_NATURAL_SIZE.
1191   bool v = customNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::ALL_DIMENSIONS);
1192   DALI_TEST_CHECK(v == true);
1193
1194   // A custom actor with size negotiation explicitly switched off has no relayouting,
1195   // and will not have any relayout dependencies. However, default resize policy when
1196   // there is no relayouting is to return USE_NATURAL_SIZE, so this will actually return true,
1197   // and is consistent.
1198   v = customNotNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::ALL_DIMENSIONS);
1199   DALI_TEST_CHECK(v == true);
1200
1201   customNego.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS);
1202   customNotNego.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS);
1203
1204   v = customNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::ALL_DIMENSIONS);
1205   DALI_TEST_CHECK(v == true);
1206   v = customNotNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::ALL_DIMENSIONS);
1207   DALI_TEST_CHECK(v == true);
1208
1209   application.SendNotification();
1210   application.Render();
1211
1212   customNego.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1213   customNotNego.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1214   v = customNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::WIDTH);
1215   DALI_TEST_CHECK(v == false);
1216   v = customNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::HEIGHT);
1217   DALI_TEST_CHECK(v == false);
1218   v = customNotNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::WIDTH);
1219   DALI_TEST_CHECK(v == false);
1220   v = customNotNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::HEIGHT);
1221   DALI_TEST_CHECK(v == false);
1222
1223   application.SendNotification();
1224   application.Render();
1225
1226   customNego.SetResizePolicy(Dali::ResizePolicy::USE_NATURAL_SIZE, Dali::Dimension::WIDTH);
1227   customNotNego.SetResizePolicy(Dali::ResizePolicy::USE_NATURAL_SIZE, Dali::Dimension::HEIGHT);
1228   v = customNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::WIDTH);
1229   DALI_TEST_CHECK(v == true);
1230   v = customNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::HEIGHT);
1231   DALI_TEST_CHECK(v == false);
1232   v = customNotNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::WIDTH);
1233   DALI_TEST_CHECK(v == false);
1234   v = customNotNego.TestRelayoutDependentOnChildrenBase(Dali::Dimension::HEIGHT);
1235   DALI_TEST_CHECK(v == true);
1236
1237   END_TEST;
1238 }
1239
1240 int UtcDaliCustomActorTypeRegistry(void)
1241 {
1242   TestApplication application;
1243
1244   // Register Type
1245   TypeInfo type;
1246   type = TypeRegistry::Get().GetTypeInfo("CustomActor");
1247   DALI_TEST_CHECK(type);
1248   BaseHandle handle = type.CreateInstance();
1249
1250   std::string name;
1251   std::string exception;
1252
1253   try
1254   {
1255     name = handle.GetTypeName();
1256     tet_result(TET_FAIL);
1257   }
1258   catch(DaliException& e)
1259   {
1260     exception = e.condition;
1261     DALI_TEST_EQUALS(exception, "handle && \"BaseObject handle is empty\"", TEST_LOCATION);
1262   }
1263
1264   END_TEST;
1265 }
1266
1267 int UtcDaliCustomActorGetExtensionP(void)
1268 {
1269   TestApplication application;
1270
1271   Test::TestCustomActor custom = Test::TestCustomActor::NewVariant5(application.GetScene());
1272
1273   DALI_TEST_CHECK(NULL == custom.GetImplementation().GetExtension());
1274
1275   END_TEST;
1276 }
1277
1278 int UtcDaliCustomActorOnConnectionDepth(void)
1279 {
1280   TestApplication application;
1281   tet_infoline("Testing Dali::CustomActor::OnSceneConnection() hierarchy depth");
1282
1283   Integration::Scene stage = application.GetScene();
1284
1285   /* Build tree of actors:
1286    *
1287    *                      Depth
1288    *
1289    *       A (parent)       1
1290    *      / \
1291    *     B   C              2
1292    *    / \   \
1293    *   D   E   F            3
1294    *
1295    * OnSceneConnection should return 1 for A, 2 for B and C, and 3 for D, E and F.
1296    */
1297
1298   Test::TestCustomActor actorA = Test::TestCustomActor::New();
1299   stage.Add(actorA);
1300
1301   Test::TestCustomActor actorB = Test::TestCustomActor::New();
1302   actorA.Add(actorB);
1303
1304   Test::TestCustomActor actorC = Test::TestCustomActor::New();
1305   actorA.Add(actorC);
1306
1307   Test::TestCustomActor actorD = Test::TestCustomActor::New();
1308   actorB.Add(actorD);
1309
1310   Test::TestCustomActor actorE = Test::TestCustomActor::New();
1311   actorB.Add(actorE);
1312
1313   Test::TestCustomActor actorF = Test::TestCustomActor::New();
1314   actorC.Add(actorF);
1315
1316   // Excercise the message passing to Update thread
1317   application.SendNotification();
1318   application.Render();
1319   application.Render();
1320
1321   DALI_TEST_EQUALS(1u, actorA.GetDepth(), TEST_LOCATION);
1322   DALI_TEST_EQUALS(2u, actorB.GetDepth(), TEST_LOCATION);
1323   DALI_TEST_EQUALS(2u, actorC.GetDepth(), TEST_LOCATION);
1324   DALI_TEST_EQUALS(3u, actorD.GetDepth(), TEST_LOCATION);
1325   DALI_TEST_EQUALS(3u, actorE.GetDepth(), TEST_LOCATION);
1326   DALI_TEST_EQUALS(3u, actorF.GetDepth(), TEST_LOCATION);
1327
1328   END_TEST;
1329 }
1330
1331 int UtcDaliCustomActorSetGetProperty(void)
1332 {
1333   TestApplication application; // Need the type registry
1334
1335   Test::TestCustomActor actor = Test::TestCustomActor::New();
1336   application.GetScene().Add(actor);
1337
1338   actor.SetProperty(Test::TestCustomActor::Property::TEST_PROPERTY1, 0.5f);
1339   actor.SetProperty(Test::TestCustomActor::Property::TEST_PROPERTY2, Color::WHITE);
1340   actor.SetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3, Color::BLUE);
1341   actor.SetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4, 20);
1342   actor.SetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5, 40.0f);
1343
1344   Property::Value value = actor.GetProperty(Test::TestCustomActor::Property::TEST_PROPERTY1);
1345   DALI_TEST_EQUALS(value.Get<float>(), 0.5f, 0.001f, TEST_LOCATION);
1346
1347   value = actor.GetProperty(Test::TestCustomActor::Property::TEST_PROPERTY2);
1348   DALI_TEST_EQUALS(value.Get<Vector4>(), Color::WHITE, 0.001f, TEST_LOCATION);
1349
1350   value = actor.GetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3);
1351   DALI_TEST_EQUALS(value.Get<Vector4>(), Color::BLUE, 0.001f, TEST_LOCATION);
1352
1353   value = actor.GetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4);
1354   DALI_TEST_EQUALS(value.Get<int>(), 20, TEST_LOCATION);
1355
1356   value = actor.GetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5);
1357   DALI_TEST_EQUALS(value.Get<float>(), 40.0f, 0.001f, TEST_LOCATION);
1358
1359   // Get read-only property
1360   value = actor.GetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6);
1361   DALI_TEST_EQUALS(value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION);
1362
1363   // Attempt to set read-only property and then ensure value hasn't changed
1364   actor.SetProperty(Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6, 40.0f);
1365   DALI_TEST_EQUALS(value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION);
1366
1367   END_TEST;
1368 }
1369
1370 int utcDaliActorGetTypeInfo(void)
1371 {
1372   TestApplication application;
1373   tet_infoline("Get the type info of a derived actor");
1374
1375   Test::TestCustomActor customActor = Test::TestCustomActor::New();
1376
1377   Dali::TypeInfo typeInfo = Dali::DevelCustomActor::GetTypeInfo(customActor);
1378
1379   DALI_TEST_EQUALS(typeInfo.GetName(), std::string("TestCustomActor"), TEST_LOCATION);
1380
1381   END_TEST;
1382 }
1383
1384 namespace Impl
1385 {
1386 /**
1387  * A custom actor that is not type registered on purpose
1388  */
1389 struct UnregisteredCustomActor : public Dali::CustomActorImpl
1390 {
1391   UnregisteredCustomActor()
1392   : CustomActorImpl(ACTOR_BEHAVIOUR_DEFAULT)
1393   {
1394   }
1395   virtual ~UnregisteredCustomActor()
1396   {
1397   }
1398   virtual void OnSceneConnection(int32_t depth)
1399   {
1400   }
1401   virtual void OnSceneDisconnection()
1402   {
1403   }
1404   virtual void OnChildAdd(Actor& child)
1405   {
1406   }
1407   virtual void OnChildRemove(Actor& child)
1408   {
1409   }
1410   virtual void OnPropertySet(Property::Index index, const Property::Value& propertyValue)
1411   {
1412   }
1413   virtual void OnSizeSet(const Vector3& targetSize)
1414   {
1415   }
1416   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1417   {
1418   }
1419   virtual bool OnHoverEvent(const HoverEvent& event)
1420   {
1421     return false;
1422   }
1423   virtual bool OnWheelEvent(const WheelEvent& event)
1424   {
1425     return false;
1426   }
1427   virtual void OnRelayout(const Vector2& size, RelayoutContainer& container)
1428   {
1429   }
1430   virtual void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension)
1431   {
1432   }
1433   virtual Vector3 GetNaturalSize()
1434   {
1435     return Vector3();
1436   }
1437   virtual float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension)
1438   {
1439     return 0.f;
1440   }
1441   virtual float GetHeightForWidth(float width)
1442   {
1443     return 0.f;
1444   }
1445   virtual float GetWidthForHeight(float height)
1446   {
1447     return 0.f;
1448   }
1449   virtual bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS)
1450   {
1451     return false;
1452   }
1453   virtual void OnCalculateRelayoutSize(Dimension::Type dimension)
1454   {
1455   }
1456   virtual void OnLayoutNegotiated(float size, Dimension::Type dimension)
1457   {
1458   }
1459 };
1460 } // namespace Impl
1461 struct UnregisteredCustomActor : public Dali::CustomActor
1462 {
1463   static UnregisteredCustomActor New()
1464   {
1465     Impl::UnregisteredCustomActor* impl = new Impl::UnregisteredCustomActor;
1466     UnregisteredCustomActor        custom(*impl); // takes ownership
1467     return custom;
1468   }
1469   UnregisteredCustomActor()
1470   {
1471   }
1472   ~UnregisteredCustomActor()
1473   {
1474   }
1475   UnregisteredCustomActor(Internal::CustomActor* impl)
1476   : CustomActor(impl)
1477   {
1478   }
1479   UnregisteredCustomActor(Impl::UnregisteredCustomActor& impl)
1480   : CustomActor(impl)
1481   {
1482   }
1483   static UnregisteredCustomActor DownCast(BaseHandle handle)
1484   {
1485     UnregisteredCustomActor hndl;
1486     CustomActor             custom = Dali::CustomActor::DownCast(handle);
1487     if(custom)
1488     {
1489       CustomActorImpl& customImpl = custom.GetImplementation();
1490
1491       Impl::UnregisteredCustomActor* impl = dynamic_cast<Impl::UnregisteredCustomActor*>(&customImpl);
1492
1493       if(impl)
1494       {
1495         hndl = UnregisteredCustomActor(customImpl.GetOwner());
1496       }
1497     }
1498     return hndl;
1499   }
1500 };
1501
1502 int UtcDaliCustomActorSetGetActorPropertyActionSignal(void)
1503 {
1504   TestApplication application; // Need the type registry
1505
1506   auto custom = UnregisteredCustomActor::New();
1507   application.GetScene().Add(custom);
1508
1509   // should have all actor properties
1510   DALI_TEST_EQUALS(custom.GetPropertyType(Actor::Property::COLOR), Property::VECTOR4, TEST_LOCATION);
1511   auto actorHandle = Actor::New();
1512   DALI_TEST_EQUALS(custom.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION);
1513
1514   DALI_TEST_EQUALS(custom.GetCurrentProperty<bool>(Actor::Property::VISIBLE), true, TEST_LOCATION);
1515   custom.SetProperty(Actor::Property::VISIBLE, false);
1516   application.SendNotification();
1517   application.Render(); // IsVisible returns scene value
1518   DALI_TEST_EQUALS(custom.GetCurrentProperty<bool>(Actor::Property::VISIBLE), false, TEST_LOCATION);
1519
1520   // should have custom actor typename (as it has not registered itself)
1521   DALI_TEST_EQUALS("CustomActor", custom.GetTypeName(), TEST_LOCATION);
1522
1523   // should have actor actions
1524   custom.DoAction("show", Property::Map());
1525   DALI_TEST_EQUALS(custom.GetProperty(Actor::Property::VISIBLE).Get<bool>(), true, TEST_LOCATION);
1526
1527   Animation animation = Animation::New(0.01f); // very short animation
1528   // should be able to animate actor property
1529   animation.AnimateTo(Property(custom, Actor::Property::POSITION), Vector3(100.0f, 150.0f, 200.0f));
1530   animation.Play();
1531
1532   application.SendNotification();
1533   application.Render(1000.f);
1534
1535   DALI_TEST_EQUALS(Vector3(100.0f, 150.0f, 200.0f), custom.GetProperty(Actor::Property::POSITION).Get<Vector3>(), TEST_LOCATION);
1536   DALI_TEST_EQUALS(Vector3(100.0f, 150.0f, 200.0f), custom.GetCurrentProperty<Vector3>(Actor::Property::POSITION), TEST_LOCATION);
1537
1538   Dali::WeakHandle<UnregisteredCustomActor> weakRef(custom);
1539   // should have actor signals
1540   custom.ConnectSignal(&application, "offScene", [weakRef]() {
1541     DALI_TEST_EQUALS(weakRef.GetHandle().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE), false, TEST_LOCATION);
1542   });
1543
1544   application.GetScene().Remove(custom);
1545   application.GetScene().Add(custom);
1546
1547   END_TEST;
1548 }
1549
1550 namespace Impl
1551 {
1552 struct DerivedCustomActor : public UnregisteredCustomActor
1553 {
1554 };
1555 } // namespace Impl
1556
1557 struct DerivedCustomActor : public UnregisteredCustomActor
1558 {
1559   static DerivedCustomActor New()
1560   {
1561     Impl::DerivedCustomActor* impl = new Impl::DerivedCustomActor;
1562     DerivedCustomActor        custom(*impl); // takes ownership
1563     return custom;
1564   }
1565   DerivedCustomActor()
1566   {
1567   }
1568   ~DerivedCustomActor()
1569   {
1570   }
1571   DerivedCustomActor(Internal::CustomActor* impl)
1572   : UnregisteredCustomActor(impl)
1573   {
1574   }
1575   DerivedCustomActor(Impl::UnregisteredCustomActor& impl)
1576   : UnregisteredCustomActor(impl)
1577   {
1578   }
1579 };
1580
1581 // register custom
1582 DALI_TYPE_REGISTRATION_BEGIN(DerivedCustomActor, UnregisteredCustomActor, nullptr);
1583 DALI_TYPE_REGISTRATION_END()
1584
1585 int UtcDaliCustomActorPropertyRegistrationDefaultValue(void)
1586 {
1587   TestApplication application; // Need the type registry
1588
1589   // register our base and add a property with default value for it
1590   Dali::TypeRegistration typeRegistration(typeid(UnregisteredCustomActor), typeid(Dali::CustomActor), nullptr);
1591
1592   auto derived = DerivedCustomActor::New();
1593   application.GetScene().Add(derived);
1594
1595   // should have all actor properties
1596   DALI_TEST_EQUALS(derived.GetPropertyType(Actor::Property::WORLD_MATRIX), Property::MATRIX, TEST_LOCATION);
1597   auto actorHandle = Actor::New();
1598   DALI_TEST_EQUALS(derived.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION);
1599
1600   // add a property in base class
1601   AnimatablePropertyRegistration(typeRegistration, "Foobar", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, 10.f);
1602
1603   // should be one more property now
1604   DALI_TEST_EQUALS(derived.GetPropertyCount(), actorHandle.GetPropertyCount() + 1, TEST_LOCATION);
1605   // check that the default value is set for base class
1606   DALI_TEST_EQUALS(UnregisteredCustomActor::New().GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION);
1607   // check that the default value is set for the derived instance as well
1608   DALI_TEST_EQUALS(derived.GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION);
1609
1610   END_TEST;
1611 }