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