Merge remote-tracking branch 'origin/tizen' into devel/new_mesh
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Actor.cpp
1 /*
2  * Copyright (c) 2014 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 "assert.h"
19 #include <dali/public-api/dali-core.h>
20 #include <string>
21 #include <cfloat>   // For FLT_MAX
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/events/hover-event-integ.h>
24 #include <dali-test-suite-utils.h>
25
26 //& set: DaliActor
27
28 using std::string;
29 using namespace Dali;
30
31
32 void utc_dali_actor_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void utc_dali_actor_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42 namespace
43 {
44 bool gTouchCallBackCalled=false;
45 bool gTouchCallBack2Called=false;
46 bool gHoverCallBackCalled=false;
47
48 /**
49  * Simulates a Down Touch at 25.0, 25.0.
50  * @param[in] app Test Application instance.
51  */
52 int SimulateTouchForSetOverlayHitTest(TestApplication& app)
53 {
54   app.SendNotification();
55   app.Render(1);
56   app.SendNotification();
57   app.Render(1);
58
59   gTouchCallBackCalled = false;
60   gTouchCallBack2Called = false;
61
62   // simulate a touch event
63   Dali::TouchPoint point( 0, TouchPoint::Down, 25.0f, 25.0f );
64   Dali::Integration::TouchEvent event;
65   event.AddPoint( point );
66   app.ProcessEvent( event );
67
68   app.SendNotification();
69   app.Render(1);
70   app.SendNotification();
71   app.Render(1);
72   END_TEST;
73 }
74
75
76 static bool gTestConstraintCalled;
77
78 struct TestConstraint
79 {
80   void operator()( Vector4& color, const PropertyInputContainer& /* inputs */ )
81   {
82     gTestConstraintCalled = true;
83   }
84 };
85
86 /**
87  * TestConstraint reference.
88  * When constraint is called, the resultRef is updated
89  * with the value supplied.
90  */
91 template<typename T>
92 struct TestConstraintRef
93 {
94   TestConstraintRef(unsigned int& resultRef, unsigned int value)
95   : mResultRef(resultRef),
96     mValue(value)
97   {
98   }
99
100   void operator()( T& current, const PropertyInputContainer& /* inputs */ )
101   {
102     mResultRef = mValue;
103   }
104
105   unsigned int& mResultRef;
106   unsigned int mValue;
107 };
108
109 static bool TestCallback(Actor actor, const TouchEvent& event)
110 {
111   gTouchCallBackCalled = true;
112   return false;
113   END_TEST;
114 }
115
116 static bool TestCallback2(Actor actor, const TouchEvent& event)
117 {
118   gTouchCallBack2Called = true;
119   return false;
120   END_TEST;
121 }
122
123 static bool TestCallback3(Actor actor, const HoverEvent& event)
124 {
125   gHoverCallBackCalled = true;
126   return false;
127   END_TEST;
128 }
129
130 static Vector3 gSetSize;
131 static bool gSetSizeCallBackCalled;
132 void SetSizeCallback( Actor actor, const Vector3& size )
133 {
134   gSetSizeCallBackCalled = true;
135   gSetSize = size;
136 }
137 // validation stuff for onstage & offstage signals
138 static std::vector< std::string > gActorNamesOnOffStage;
139 static int gOnStageCallBackCalled;
140 void OnStageCallback( Actor actor )
141 {
142   ++gOnStageCallBackCalled;
143   gActorNamesOnOffStage.push_back( actor.GetName() );
144   DALI_TEST_CHECK( actor.OnStage() == true );
145 }
146 static int gOffStageCallBackCalled;
147 void OffStageCallback( Actor actor )
148 {
149   ++gOffStageCallBackCalled;
150   gActorNamesOnOffStage.push_back( actor.GetName() );
151   DALI_TEST_CHECK( actor.OnStage() == false );
152 }
153
154 struct PositionComponentConstraint
155 {
156   PositionComponentConstraint(){}
157
158   void operator()( Vector3& pos, const PropertyInputContainer& inputs )
159   {
160     const Matrix& m = inputs[0]->GetMatrix();
161     Vector3 scale;
162     Quaternion rot;
163     m.GetTransformComponents(pos, rot, scale);
164   }
165 };
166
167 // OnRelayout
168
169 static bool gOnRelayoutCallBackCalled = 0;
170 static std::vector< std::string > gActorNamesRelayout;
171
172 void OnRelayoutCallback( Actor actor )
173 {
174   ++gOnRelayoutCallBackCalled;
175   gActorNamesRelayout.push_back( actor.GetName() );
176 }
177
178 } // anonymous namespace
179
180
181 //& purpose: Testing New API
182 int UtcDaliActorNew(void)
183 {
184   TestApplication application;
185
186   Actor actor = Actor::New();
187
188   DALI_TEST_CHECK(actor);
189   END_TEST;
190 }
191
192 //& purpose: Testing Dali::Actor::DownCast()
193 int UtcDaliActorDownCastP(void)
194 {
195   TestApplication application;
196   tet_infoline("Testing Dali::Actor::DownCast()");
197
198   Actor actor = Actor::New();
199   BaseHandle object(actor);
200   Actor actor2 = Actor::DownCast(object);
201   DALI_TEST_CHECK(actor2);
202   END_TEST;
203 }
204
205 //& purpose: Testing Dali::Actor::DownCast()
206 int UtcDaliActorDownCastN(void)
207 {
208   TestApplication application;
209   tet_infoline("Testing Dali::Actor::DownCast()");
210
211   BaseHandle unInitializedObject;
212   Actor actor = Actor::DownCast(unInitializedObject);
213   DALI_TEST_CHECK(!actor);
214   END_TEST;
215 }
216
217 //& purpose: Testing Dali::Actor::GetName()
218 int UtcDaliActorGetName(void)
219 {
220   TestApplication application;
221
222   Actor actor = Actor::New();
223
224   DALI_TEST_CHECK(actor.GetName().empty());
225   END_TEST;
226 }
227
228 //& purpose: Testing Dali::Actor::SetName()
229 int UtcDaliActorSetName(void)
230 {
231   TestApplication application;
232
233   string str("ActorName");
234   Actor actor = Actor::New();
235
236   actor.SetName(str);
237   DALI_TEST_CHECK(actor.GetName() == str);
238   END_TEST;
239 }
240
241 int UtcDaliActorGetId(void)
242 {
243   tet_infoline("Testing Dali::Actor::UtcDaliActorGetId()");
244   TestApplication application;
245
246   Actor first = Actor::New();
247   Actor second = Actor::New();
248   Actor third = Actor::New();
249
250   DALI_TEST_CHECK(first.GetId() != second.GetId());
251   DALI_TEST_CHECK(second.GetId() != third.GetId());
252   END_TEST;
253 }
254
255 int UtcDaliActorIsRoot(void)
256 {
257   TestApplication application;
258
259   Actor actor = Actor::New();
260   DALI_TEST_CHECK(!actor.IsRoot());
261
262   // get the root layer
263   actor = Stage::GetCurrent().GetLayer( 0 );
264   DALI_TEST_CHECK( actor.IsRoot() );
265   END_TEST;
266 }
267
268 int UtcDaliActorOnStage(void)
269 {
270   TestApplication application;
271
272   Actor actor = Actor::New();
273   DALI_TEST_CHECK( !actor.OnStage() );
274
275   // get the root layer
276   actor = Stage::GetCurrent().GetLayer( 0 );
277   DALI_TEST_CHECK( actor.OnStage() );
278   END_TEST;
279 }
280
281 int UtcDaliActorIsLayer(void)
282 {
283   TestApplication application;
284
285   Actor actor = Actor::New();
286   DALI_TEST_CHECK( !actor.IsLayer() );
287
288   // get the root layer
289   actor = Stage::GetCurrent().GetLayer( 0 );
290   DALI_TEST_CHECK( actor.IsLayer() );
291   END_TEST;
292 }
293
294 int UtcDaliActorGetLayer(void)
295 {
296   TestApplication application;
297
298   Actor actor = Actor::New();
299   Stage::GetCurrent().Add(actor);
300   Layer layer = actor.GetLayer();
301
302   DALI_TEST_CHECK(layer);
303
304   // get the root layers layer
305   actor = Stage::GetCurrent().GetLayer( 0 );
306   DALI_TEST_CHECK( actor.GetLayer() );
307   END_TEST;
308 }
309
310 int UtcDaliActorAddP(void)
311 {
312   tet_infoline("Testing Actor::Add");
313   TestApplication application;
314
315   Actor parent = Actor::New();
316   Actor child = Actor::New();
317
318   DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
319
320   parent.Add(child);
321
322   DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
323
324   Actor parent2 = Actor::New();
325   parent2.Add( child );
326
327   DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
328   DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
329
330   // try Adding to same parent again, works
331   parent2.Add( child );
332   DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
333
334   // try reparenting an orphaned child
335   {
336     Actor temporaryParent = Actor::New();
337     temporaryParent.Add( child );
338     DALI_TEST_EQUALS( parent2.GetChildCount(), 0u, TEST_LOCATION );
339   }
340   // temporaryParent has now died, reparent the orphaned child
341   parent2.Add( child );
342   DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
343
344   END_TEST;
345 }
346
347 int UtcDaliActorAddN(void)
348 {
349   tet_infoline("Testing Actor::Add");
350   TestApplication application;
351
352   Actor child = Actor::New();
353
354   Actor parent2 = Actor::New();
355   parent2.Add( child );
356
357   // try illegal Add
358   try
359   {
360     parent2.Add( parent2 );
361     tet_printf("Assertion test failed - no Exception\n" );
362     tet_result(TET_FAIL);
363   }
364   catch(Dali::DaliException& e)
365   {
366     DALI_TEST_PRINT_ASSERT( e );
367     DALI_TEST_ASSERT(e, "this != &child", TEST_LOCATION);
368     DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
369   }
370   catch(...)
371   {
372     tet_printf("Assertion test failed - wrong Exception\n" );
373     tet_result(TET_FAIL);
374   }
375
376   // try reparenting root
377   try
378   {
379     parent2.Add( Stage::GetCurrent().GetLayer( 0 ) );
380     tet_printf("Assertion test failed - no Exception\n" );
381     tet_result(TET_FAIL);
382   }
383   catch(Dali::DaliException& e)
384   {
385     DALI_TEST_PRINT_ASSERT( e );
386     DALI_TEST_ASSERT(e, "!child.IsRoot()", TEST_LOCATION);
387     DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
388   }
389   catch(...)
390   {
391     tet_printf("Assertion test failed - wrong Exception\n" );
392     tet_result(TET_FAIL);
393   }
394
395   // try Add empty
396   try
397   {
398     Actor empty;
399     parent2.Add( empty );
400     tet_printf("Assertion test failed - no Exception\n" );
401     tet_result(TET_FAIL);
402   }
403   catch(Dali::DaliException& e)
404   {
405     DALI_TEST_PRINT_ASSERT( e );
406     DALI_TEST_ASSERT(e, "actor", TEST_LOCATION);
407     DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
408   }
409   catch(...)
410   {
411     tet_printf("Assertion test failed - wrong Exception\n" );
412     tet_result(TET_FAIL);
413   }
414
415   END_TEST;
416 }
417
418 int UtcDaliActorInsert(void)
419 {
420   tet_infoline("Testing Actor::Insert");
421   TestApplication application;
422
423   Actor parent = Actor::New();
424   Stage::GetCurrent().Add( parent );
425   Actor first = Actor::New();
426   Actor second = Actor::New();
427   Actor third = Actor::New();
428
429   parent.Insert(1, first); // test insert beyond range
430   DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
431   parent.Insert(0, second);
432   DALI_TEST_EQUALS( parent.GetChildCount(), 2u, TEST_LOCATION );
433   parent.Insert(1, third);
434
435   DALI_TEST_EQUALS( parent.GetChildCount(), 3u, TEST_LOCATION );
436
437   DALI_TEST_CHECK(parent.GetChildAt(0) == second);
438   DALI_TEST_CHECK(parent.GetChildAt(1) == third);
439   DALI_TEST_CHECK(parent.GetChildAt(2) == first);
440
441   END_TEST;
442 }
443
444
445 int UtcDaliActorRemoveN(void)
446 {
447   tet_infoline("Testing Actor::Remove");
448   TestApplication application;
449
450   Actor parent = Actor::New();
451   Actor child = Actor::New();
452   DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
453
454   parent.Add(child);
455   DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
456
457   parent.Remove(child);
458   DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
459
460   // remove again, no problem
461   parent.Remove(child);
462   DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
463
464   // add child back
465   parent.Add(child);
466   // try illegal Remove
467   try
468   {
469     parent.Remove( parent );
470     tet_printf("Assertion test failed - no Exception\n" );
471     tet_result(TET_FAIL);
472   }
473   catch(Dali::DaliException& e)
474   {
475     DALI_TEST_PRINT_ASSERT( e );
476     DALI_TEST_ASSERT(e, "this != &child", TEST_LOCATION);
477     DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
478   }
479   catch(...)
480   {
481     tet_printf("Assertion test failed - wrong Exception\n" );
482     tet_result(TET_FAIL);
483   }
484
485   // try Remove empty
486   try
487   {
488     Actor empty;
489     parent.Remove( empty );
490     tet_printf("Assertion test failed - no Exception\n" );
491     tet_result(TET_FAIL);
492   }
493   catch(Dali::DaliException& e)
494   {
495     DALI_TEST_PRINT_ASSERT( e );
496     DALI_TEST_ASSERT(e, "actor", TEST_LOCATION);
497     DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
498   }
499   catch(...)
500   {
501     tet_printf("Assertion test failed - wrong Exception\n" );
502     tet_result(TET_FAIL);
503   }
504   END_TEST;
505 }
506
507 int UtcDaliActorRemoveP(void)
508 {
509   TestApplication application;
510
511   Actor parent = Actor::New();
512   Actor child = Actor::New();
513   Actor random = Actor::New();
514
515   Stage::GetCurrent().Add( parent );
516
517   DALI_TEST_CHECK(parent.GetChildCount() == 0);
518
519   parent.Add(child);
520
521   DALI_TEST_CHECK(parent.GetChildCount() == 1);
522
523   parent.Remove(random);
524
525   DALI_TEST_CHECK(parent.GetChildCount() == 1);
526
527   Stage::GetCurrent().Remove( parent );
528
529   DALI_TEST_CHECK(parent.GetChildCount() == 1);
530   END_TEST;
531 }
532
533 int UtcDaliActorGetChildCount(void)
534 {
535   TestApplication application;
536
537   Actor parent = Actor::New();
538   Actor child = Actor::New();
539
540   DALI_TEST_CHECK(parent.GetChildCount() == 0);
541
542   parent.Add(child);
543
544   DALI_TEST_CHECK(parent.GetChildCount() == 1);
545   END_TEST;
546 }
547
548 int UtcDaliActorGetChildren01(void)
549 {
550   TestApplication application;
551
552   Actor parent = Actor::New();
553   Actor first  = Actor::New();
554   Actor second = Actor::New();
555   Actor third  = Actor::New();
556
557   parent.Add(first);
558   parent.Add(second);
559   parent.Add(third);
560
561   DALI_TEST_CHECK(parent.GetChildAt(0) == first);
562   DALI_TEST_CHECK(parent.GetChildAt(1) == second);
563   DALI_TEST_CHECK(parent.GetChildAt(2) == third);
564   END_TEST;
565 }
566
567 int UtcDaliActorGetChildren02(void)
568 {
569   TestApplication application;
570
571   Actor parent = Actor::New();
572   Actor first  = Actor::New();
573   Actor second = Actor::New();
574   Actor third  = Actor::New();
575
576   parent.Add(first);
577   parent.Add(second);
578   parent.Add(third);
579
580   const Actor& constParent = parent;
581
582   DALI_TEST_CHECK(constParent.GetChildAt(0) == first);
583   DALI_TEST_CHECK(constParent.GetChildAt(1) == second);
584   DALI_TEST_CHECK(constParent.GetChildAt(2) == third);
585   END_TEST;
586 }
587
588 int UtcDaliActorGetParent01(void)
589 {
590   TestApplication application;
591
592   Actor parent = Actor::New();
593   Actor child = Actor::New();
594
595   parent.Add(child);
596
597   DALI_TEST_CHECK(child.GetParent() == parent);
598   END_TEST;
599 }
600
601 int UtcDaliActorGetParent02(void)
602 {
603   TestApplication application;
604
605   Actor actor = Actor::New();
606
607   DALI_TEST_CHECK(!actor.GetParent());
608   END_TEST;
609 }
610
611 int UtcDaliActorSetParentOrigin(void)
612 {
613   TestApplication application;
614
615   Actor actor = Actor::New();
616
617   Vector3 vector(0.7f, 0.8f, 0.9f);
618   DALI_TEST_CHECK(vector != actor.GetCurrentParentOrigin());
619
620   actor.SetParentOrigin(vector);
621
622   // flush the queue and render once
623   application.SendNotification();
624   application.Render();
625
626   DALI_TEST_CHECK(vector == actor.GetCurrentParentOrigin());
627
628   Stage::GetCurrent().Add( actor );
629
630   actor.SetParentOrigin( Vector3( 0.1f, 0.2f, 0.3f ) );
631
632   // flush the queue and render once
633   application.SendNotification();
634   application.Render();
635
636   DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), actor.GetCurrentParentOrigin(), TEST_LOCATION );
637
638   Stage::GetCurrent().Remove( actor );
639   END_TEST;
640 }
641
642 int UtcDaliActorGetCurrentParentOrigin(void)
643 {
644   TestApplication application;
645
646   Actor actor = Actor::New();
647
648   Vector3 vector(0.7f, 0.8f, 0.9f);
649   DALI_TEST_CHECK(vector != actor.GetCurrentParentOrigin());
650
651   actor.SetParentOrigin(vector);
652
653   // flush the queue and render once
654   application.SendNotification();
655   application.Render();
656
657   DALI_TEST_CHECK(vector == actor.GetCurrentParentOrigin());
658   END_TEST;
659 }
660
661 int UtcDaliActorSetAnchorPoint(void)
662 {
663   TestApplication application;
664
665   Actor actor = Actor::New();
666
667   Vector3 vector(0.7f, 0.8f, 0.9f);
668   DALI_TEST_CHECK(vector != actor.GetCurrentAnchorPoint());
669
670   actor.SetAnchorPoint(vector);
671
672   // flush the queue and render once
673   application.SendNotification();
674   application.Render();
675
676   DALI_TEST_CHECK(vector == actor.GetCurrentAnchorPoint());
677
678   Stage::GetCurrent().Add( actor );
679
680   actor.SetAnchorPoint( Vector3( 0.1f, 0.2f, 0.3f ) );
681   // flush the queue and render once
682   application.SendNotification();
683   application.Render();
684
685   DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), actor.GetCurrentAnchorPoint(), TEST_LOCATION );
686
687   Stage::GetCurrent().Remove( actor );
688   END_TEST;
689 }
690
691 int UtcDaliActorGetCurrentAnchorPoint(void)
692 {
693   TestApplication application;
694
695   Actor actor = Actor::New();
696
697   Vector3 vector(0.7f, 0.8f, 0.9f);
698   DALI_TEST_CHECK(vector != actor.GetCurrentAnchorPoint());
699
700   actor.SetAnchorPoint(vector);
701
702   // flush the queue and render once
703   application.SendNotification();
704   application.Render();
705
706   DALI_TEST_CHECK(vector == actor.GetCurrentAnchorPoint());
707   END_TEST;
708 }
709
710 // SetSize(float width, float height)
711 int UtcDaliActorSetSize01(void)
712 {
713   TestApplication application;
714
715   Actor actor = Actor::New();
716   Vector3 vector(100.0f, 100.0f, 100.0f);
717
718   DALI_TEST_CHECK(vector != actor.GetCurrentSize());
719
720   actor.SetSize(vector.x, vector.y);
721
722   // flush the queue and render once
723   application.SendNotification();
724   application.Render();
725
726   DALI_TEST_CHECK(vector == actor.GetCurrentSize());
727   END_TEST;
728 }
729
730 // SetSize(float width, float height, float depth)
731 int UtcDaliActorSetSize02(void)
732 {
733   TestApplication application;
734
735   Actor actor = Actor::New();
736   Vector3 vector(100.0f, 100.0f, 100.0f);
737
738   DALI_TEST_CHECK(vector != actor.GetCurrentSize());
739
740   actor.SetSize(vector.x, vector.y, vector.z);
741
742   // flush the queue and render once
743   application.SendNotification();
744   application.Render();
745
746   DALI_TEST_CHECK(vector == actor.GetCurrentSize());
747   END_TEST;
748 }
749
750 // SetSize(Vector2 size)
751 int UtcDaliActorSetSize03(void)
752 {
753   TestApplication application;
754
755   Actor actor = Actor::New();
756   Vector3 vector(100.0f, 100.0f, 100.0f);
757
758   DALI_TEST_CHECK(vector != actor.GetCurrentSize());
759
760   actor.SetSize(Vector2(vector.x, vector.y));
761
762   // flush the queue and render once
763   application.SendNotification();
764   application.Render();
765
766   DALI_TEST_CHECK(vector == actor.GetCurrentSize());
767   END_TEST;
768 }
769
770 // SetSize(Vector3 size)
771 int UtcDaliActorSetSize04(void)
772 {
773   TestApplication application;
774
775   Actor actor = Actor::New();
776   Vector3 vector(100.0f, 100.0f, 100.0f);
777
778   DALI_TEST_CHECK(vector != actor.GetCurrentSize());
779
780   actor.SetSize(vector);
781
782   // flush the queue and render once
783   application.SendNotification();
784   application.Render();
785
786   DALI_TEST_CHECK(vector == actor.GetCurrentSize());
787
788   Stage::GetCurrent().Add( actor );
789   actor.SetSize( Vector3( 0.1f, 0.2f, 0.3f ) );
790
791   // flush the queue and render once
792   application.SendNotification();
793   application.Render();
794
795   DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), actor.GetCurrentSize(), TEST_LOCATION );
796   Stage::GetCurrent().Remove( actor );
797   END_TEST;
798 }
799
800 int UtcDaliActorGetCurrentSize(void)
801 {
802   TestApplication application;
803
804   Actor actor = Actor::New();
805   Vector3 vector(100.0f, 100.0f, 20.0f);
806
807   DALI_TEST_CHECK(vector != actor.GetCurrentSize());
808
809   actor.SetSize(vector);
810
811   // flush the queue and render once
812   application.SendNotification();
813   application.Render();
814
815   DALI_TEST_CHECK(vector == actor.GetCurrentSize());
816   END_TEST;
817 }
818
819 int UtcDaliActorGetNaturalSize(void)
820 {
821   TestApplication application;
822
823   Actor actor = Actor::New();
824   Vector3 vector( 0.0f, 0.0f, 0.0f );
825
826   DALI_TEST_CHECK( actor.GetNaturalSize() == vector );
827
828   END_TEST;
829 }
830
831 int UtcDaliActorGetCurrentSizeImmediate(void)
832 {
833   TestApplication application;
834
835   Actor actor = Actor::New();
836   Vector3 vector(100.0f, 100.0f, 20.0f);
837
838   DALI_TEST_CHECK(vector != actor.GetTargetSize());
839   DALI_TEST_CHECK(vector != actor.GetCurrentSize());
840
841   actor.SetSize(vector);
842
843   DALI_TEST_CHECK(vector == actor.GetTargetSize());
844   DALI_TEST_CHECK(vector != actor.GetCurrentSize());
845
846   // flush the queue and render once
847   application.SendNotification();
848   application.Render();
849
850   DALI_TEST_CHECK(vector == actor.GetTargetSize());
851   DALI_TEST_CHECK(vector == actor.GetCurrentSize());
852
853   // Animation
854   // Build the animation
855   const float durationSeconds = 2.0f;
856   Animation animation = Animation::New( durationSeconds );
857   const Vector3 targetValue( 10.0f, 20.0f, 30.0f );
858   animation.AnimateTo( Property( actor, Actor::Property::SIZE ), targetValue );
859
860   DALI_TEST_CHECK( actor.GetTargetSize() == targetValue );
861
862   // Start the animation
863   animation.Play();
864
865   application.SendNotification();
866   application.Render( static_cast<unsigned int>( durationSeconds * 1000.0f ) );
867
868   DALI_TEST_CHECK( actor.GetTargetSize() == targetValue );
869
870   END_TEST;
871 }
872
873 // SetPosition(float x, float y)
874 int UtcDaliActorSetPosition01(void)
875 {
876   TestApplication application;
877
878   Actor actor = Actor::New();
879
880   // Set to random to start off with
881   actor.SetPosition(Vector3(120.0f, 120.0f, 0.0f));
882
883   Vector3 vector(100.0f, 100.0f, 0.0f);
884
885   DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
886
887   actor.SetPosition(vector.x, vector.y);
888   // flush the queue and render once
889   application.SendNotification();
890   application.Render();
891   DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
892
893   Stage::GetCurrent().Add( actor );
894   actor.SetPosition( Vector3( 0.1f, 0.2f, 0.3f ) );
895   // flush the queue and render once
896   application.SendNotification();
897   application.Render();
898   DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), actor.GetCurrentPosition(), TEST_LOCATION );
899
900   actor.SetX( 1.0f );
901   actor.SetY( 1.1f );
902   actor.SetZ( 1.2f );
903   // flush the queue and render once
904   application.SendNotification();
905   application.Render();
906   DALI_TEST_EQUALS( Vector3( 1.0f, 1.1f, 1.2f ), actor.GetCurrentPosition(), TEST_LOCATION );
907
908   actor.TranslateBy( Vector3( 0.1f, 0.1f, 0.1f ) );
909   // flush the queue and render once
910   application.SendNotification();
911   application.Render();
912   DALI_TEST_EQUALS( Vector3( 1.1f, 1.2f, 1.3f ), actor.GetCurrentPosition(), Math::MACHINE_EPSILON_10000, TEST_LOCATION );
913
914   Stage::GetCurrent().Remove( actor );
915   END_TEST;
916 }
917
918 // SetPosition(float x, float y, float z)
919 int UtcDaliActorSetPosition02(void)
920 {
921   TestApplication application;
922
923   Actor actor = Actor::New();
924
925   // Set to random to start off with
926   actor.SetPosition(Vector3(120.0f, 120.0f, 120.0f));
927
928   Vector3 vector(100.0f, 100.0f, 100.0f);
929
930   DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
931
932   actor.SetPosition(vector.x, vector.y, vector.z);
933
934   // flush the queue and render once
935   application.SendNotification();
936   application.Render();
937
938   DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
939   END_TEST;
940 }
941
942 // SetPosition(Vector3 position)
943 int UtcDaliActorSetPosition03(void)
944 {
945   TestApplication application;
946
947   Actor actor = Actor::New();
948
949   // Set to random to start off with
950   actor.SetPosition(Vector3(120.0f, 120.0f, 120.0f));
951
952   Vector3 vector(100.0f, 100.0f, 100.0f);
953
954   DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
955
956   actor.SetPosition(vector);
957
958   // flush the queue and render once
959   application.SendNotification();
960   application.Render();
961
962   DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
963   END_TEST;
964 }
965
966 int UtcDaliActorSetX(void)
967 {
968   TestApplication application;
969
970   Actor actor = Actor::New();
971
972   Vector3 vector(100.0f, 0.0f, 0.0f);
973
974   DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
975
976   actor.SetX(100.0f);
977
978   // flush the queue and render once
979   application.SendNotification();
980   application.Render();
981
982   DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
983   END_TEST;
984 }
985
986 int UtcDaliActorSetY(void)
987 {
988   TestApplication application;
989
990   Actor actor = Actor::New();
991
992   Vector3 vector(0.0f, 100.0f, 0.0f);
993
994   DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
995
996   actor.SetY(100.0f);
997
998   // flush the queue and render once
999   application.SendNotification();
1000   application.Render();
1001
1002   DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
1003   END_TEST;
1004 }
1005
1006 int UtcDaliActorSetZ(void)
1007 {
1008   TestApplication application;
1009
1010   Actor actor = Actor::New();
1011
1012   Vector3 vector(0.0f, 0.0f, 100.0f);
1013
1014   DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
1015
1016   actor.SetZ(100.0f);
1017
1018   // flush the queue and render once
1019   application.SendNotification();
1020   application.Render();
1021
1022   DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
1023   END_TEST;
1024 }
1025
1026 int UtcDaliActorTranslateBy(void)
1027 {
1028   TestApplication application;
1029
1030   Actor actor = Actor::New();
1031   Vector3 vector(100.0f, 100.0f, 100.0f);
1032
1033   DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
1034
1035   actor.SetPosition(vector);
1036
1037   // flush the queue and render once
1038   application.SendNotification();
1039   application.Render();
1040
1041   DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
1042
1043   actor.TranslateBy(vector);
1044
1045   // flush the queue and render once
1046   application.SendNotification();
1047   application.Render();
1048
1049   DALI_TEST_CHECK(vector*2.0f == actor.GetCurrentPosition());
1050   END_TEST;
1051 }
1052
1053 int UtcDaliActorGetCurrentPosition(void)
1054 {
1055   TestApplication application;
1056
1057   Actor actor = Actor::New();
1058   Vector3 setVector(100.0f, 100.0f, 0.0f);
1059   actor.SetPosition(setVector);
1060
1061   // flush the queue and render once
1062   application.SendNotification();
1063   application.Render();
1064
1065   DALI_TEST_CHECK(actor.GetCurrentPosition() == setVector);
1066   END_TEST;
1067 }
1068
1069 int UtcDaliActorGetCurrentWorldPosition(void)
1070 {
1071   TestApplication application;
1072
1073   Actor parent = Actor::New();
1074   Vector3 parentPosition( 1.0f, 2.0f, 3.0f );
1075   parent.SetPosition( parentPosition );
1076   parent.SetParentOrigin( ParentOrigin::CENTER );
1077   parent.SetAnchorPoint( AnchorPoint::CENTER );
1078   Stage::GetCurrent().Add( parent );
1079
1080   Actor child = Actor::New();
1081   child.SetParentOrigin( ParentOrigin::CENTER );
1082   child.SetAnchorPoint( AnchorPoint::CENTER );
1083   Vector3 childPosition( 6.0f, 6.0f, 6.0f );
1084   child.SetPosition( childPosition );
1085   parent.Add( child );
1086
1087   // The actors should not have a world position yet
1088   DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
1089   DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
1090
1091   application.SendNotification();
1092   application.Render(0);
1093
1094   DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
1095   DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
1096
1097   // The actors should have a world position now
1098   DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
1099   DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), parentPosition + childPosition, TEST_LOCATION );
1100   END_TEST;
1101 }
1102
1103 int UtcDaliActorInheritPosition(void)
1104 {
1105   tet_infoline("Testing Actor::SetPositionInheritanceMode");
1106   TestApplication application;
1107
1108   Actor parent = Actor::New();
1109   Vector3 parentPosition( 1.0f, 2.0f, 3.0f );
1110   parent.SetPosition( parentPosition );
1111   parent.SetParentOrigin( ParentOrigin::CENTER );
1112   parent.SetAnchorPoint( AnchorPoint::CENTER );
1113   Stage::GetCurrent().Add( parent );
1114
1115   Actor child = Actor::New();
1116   child.SetParentOrigin( ParentOrigin::CENTER );
1117   child.SetAnchorPoint( AnchorPoint::CENTER );
1118   Vector3 childPosition( 10.0f, 11.0f, 12.0f );
1119   child.SetPosition( childPosition );
1120   parent.Add( child );
1121
1122   // The actors should not have a world position yet
1123   DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
1124   DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
1125
1126   // first test default, which is INHERIT_PARENT_POSITION
1127   DALI_TEST_EQUALS( child.GetPositionInheritanceMode(), Dali::INHERIT_PARENT_POSITION, TEST_LOCATION );
1128   application.SendNotification();
1129   application.Render(0); // should only really call Update as Render is not required to update scene
1130   DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
1131   DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
1132   DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
1133   DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), parentPosition + childPosition, TEST_LOCATION );
1134
1135   // Change inheritance mode to use parent
1136   child.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
1137   DALI_TEST_EQUALS( child.GetPositionInheritanceMode(), Dali::USE_PARENT_POSITION, TEST_LOCATION );
1138   application.SendNotification();
1139   application.Render(0); // should only really call Update as Render is not required to update scene
1140   DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
1141   DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
1142   DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
1143   DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
1144
1145   // Change inheritance mode to use parent + offset
1146   child.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
1147   Vector3 childOffset( -1.0f, 1.0f, 0.0f );
1148   child.SetPosition( childOffset );
1149   DALI_TEST_EQUALS( child.GetPositionInheritanceMode(), Dali::USE_PARENT_POSITION_PLUS_LOCAL_POSITION, TEST_LOCATION );
1150   application.SendNotification();
1151   application.Render(0); // should only really call Update as Render is not required to update scene
1152   DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
1153   DALI_TEST_EQUALS( child.GetCurrentPosition(), childOffset, TEST_LOCATION );
1154   DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
1155   DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), parentPosition + childOffset, TEST_LOCATION );
1156
1157   // Change inheritance mode to not inherit
1158   child.SetPositionInheritanceMode( Dali::DONT_INHERIT_POSITION );
1159   DALI_TEST_EQUALS( child.GetPositionInheritanceMode(), Dali::DONT_INHERIT_POSITION, TEST_LOCATION );
1160   application.SendNotification();
1161   application.Render(0); // should only really call Update as Render is not required to update scene
1162   DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
1163   DALI_TEST_EQUALS( child.GetCurrentPosition(), childOffset, TEST_LOCATION );
1164   DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
1165   DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), childOffset, TEST_LOCATION );
1166   END_TEST;
1167 }
1168
1169 // SetOrientation(float angleRadians, Vector3 axis)
1170 int UtcDaliActorSetOrientation01(void)
1171 {
1172   TestApplication application;
1173
1174   Quaternion rotation( Radian(0.785f), Vector3(1.0f, 1.0f, 0.0f));
1175   Actor actor = Actor::New();
1176
1177   actor.SetOrientation(rotation);
1178
1179   // flush the queue and render once
1180   application.SendNotification();
1181   application.Render();
1182
1183   DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1184   END_TEST;
1185 }
1186
1187 int UtcDaliActorSetOrientation02(void)
1188 {
1189   TestApplication application;
1190
1191   Actor actor = Actor::New();
1192
1193   Radian angle( 0.785f );
1194   Vector3 axis(1.0f, 1.0f, 0.0f);
1195
1196   actor.SetOrientation( angle, axis);
1197   Quaternion rotation( angle, axis );
1198   // flush the queue and render once
1199   application.SendNotification();
1200   application.Render();
1201   DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1202
1203   Stage::GetCurrent().Add( actor );
1204   actor.RotateBy( Degree( 360 ), axis);
1205   DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1206
1207   actor.SetOrientation( Degree( 0 ), Vector3( 1.0f, 0.0f, 0.0f ) );
1208   Quaternion result( Radian( 0 ), Vector3( 1.0f, 0.0f, 0.0f ) );
1209   // flush the queue and render once
1210   application.SendNotification();
1211   application.Render();
1212   DALI_TEST_EQUALS( result, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1213
1214   actor.SetOrientation( angle, axis);
1215   // flush the queue and render once
1216   application.SendNotification();
1217   application.Render();
1218   DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1219
1220   Stage::GetCurrent().Remove( actor );
1221   END_TEST;
1222 }
1223
1224 // RotateBy(float angleRadians, Vector3 axis)
1225 int UtcDaliActorRotateBy01(void)
1226 {
1227   TestApplication application;
1228
1229   Actor actor = Actor::New();
1230
1231   Radian angle( M_PI * 0.25f );
1232   actor.RotateBy(( angle ), Vector3::ZAXIS);
1233   // flush the queue and render once
1234   application.SendNotification();
1235   application.Render();
1236   DALI_TEST_EQUALS(Quaternion( angle, Vector3::ZAXIS), actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1237
1238   Stage::GetCurrent().Add( actor );
1239
1240   actor.RotateBy( angle, Vector3::ZAXIS);
1241   // flush the queue and render once
1242   application.SendNotification();
1243   application.Render();
1244   DALI_TEST_EQUALS(Quaternion(angle * 2.0f, Vector3::ZAXIS), actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1245
1246   Stage::GetCurrent().Remove( actor );
1247   END_TEST;
1248 }
1249
1250 // RotateBy(Quaternion relativeRotation)
1251 int UtcDaliActorRotateBy02(void)
1252 {
1253   TestApplication application;
1254
1255   Actor actor = Actor::New();
1256
1257   Radian angle( M_PI * 0.25f );
1258   Quaternion rotation(angle, Vector3::ZAXIS);
1259   actor.RotateBy(rotation);
1260   // flush the queue and render once
1261   application.SendNotification();
1262   application.Render();
1263   DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1264
1265   actor.RotateBy(rotation);
1266   // flush the queue and render once
1267   application.SendNotification();
1268   application.Render();
1269   DALI_TEST_EQUALS(Quaternion(angle * 2.0f, Vector3::ZAXIS), actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1270   END_TEST;
1271 }
1272
1273 int UtcDaliActorGetCurrentOrientation(void)
1274 {
1275   TestApplication application;
1276   Actor actor = Actor::New();
1277
1278   Quaternion rotation(Radian(0.785f), Vector3(1.0f, 1.0f, 0.0f));
1279   actor.SetOrientation(rotation);
1280   // flush the queue and render once
1281   application.SendNotification();
1282   application.Render();
1283   DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1284   END_TEST;
1285 }
1286
1287 int UtcDaliActorGetCurrentWorldOrientation(void)
1288 {
1289   tet_infoline("Testing Actor::GetCurrentWorldRotation");
1290   TestApplication application;
1291
1292   Actor parent = Actor::New();
1293   Radian rotationAngle( Degree(90.0f) );
1294   Quaternion rotation( rotationAngle, Vector3::YAXIS );
1295   parent.SetOrientation( rotation );
1296   Stage::GetCurrent().Add( parent );
1297
1298   Actor child = Actor::New();
1299   child.SetOrientation( rotation );
1300   parent.Add( child );
1301
1302   // The actors should not have a world rotation yet
1303   DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion(Radian(0.0f), Vector3::YAXIS), 0.001, TEST_LOCATION );
1304   DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), Quaternion(Radian(0.0f), Vector3::YAXIS), 0.001, TEST_LOCATION );
1305
1306   application.SendNotification();
1307   application.Render(0);
1308
1309   DALI_TEST_EQUALS( parent.GetCurrentOrientation(), rotation, 0.001, TEST_LOCATION );
1310   DALI_TEST_EQUALS( child.GetCurrentOrientation(), rotation, 0.001, TEST_LOCATION );
1311
1312   // The actors should have a world rotation now
1313   DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion( rotationAngle, Vector3::YAXIS ), 0.001, TEST_LOCATION );
1314   DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), Quaternion( rotationAngle * 2.0f, Vector3::YAXIS ), 0.001, TEST_LOCATION );
1315
1316   // turn off child rotation inheritance
1317   child.SetInheritOrientation( false );
1318   DALI_TEST_EQUALS( child.IsOrientationInherited(), false, TEST_LOCATION );
1319   application.SendNotification();
1320   application.Render(0);
1321
1322   // The actors should have a world rotation now
1323   DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion( rotationAngle, Vector3::YAXIS ), 0.001, TEST_LOCATION );
1324   DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), rotation, 0.001, TEST_LOCATION );
1325   END_TEST;
1326 }
1327
1328 // SetScale(float scale)
1329 int UtcDaliActorSetScale01(void)
1330 {
1331   TestApplication application;
1332
1333   Actor actor = Actor::New();
1334
1335   // Set to random value first - GetCurrentScale() asserts if called before SetScale()
1336   actor.SetScale(0.25f);
1337
1338   Vector3 scale(10.0f, 10.0f, 10.0f);
1339   DALI_TEST_CHECK(actor.GetCurrentScale() != scale);
1340
1341   actor.SetScale(scale.x);
1342
1343   // flush the queue and render once
1344   application.SendNotification();
1345   application.Render();
1346
1347   DALI_TEST_CHECK(actor.GetCurrentScale() == scale);
1348   END_TEST;
1349 }
1350
1351 // SetScale(float scaleX, float scaleY, float scaleZ)
1352 int UtcDaliActorSetScale02(void)
1353 {
1354   TestApplication application;
1355   Vector3 scale(10.0f, 10.0f, 10.0f);
1356
1357   Actor actor = Actor::New();
1358
1359   // Set to random value first - GetCurrentScale() asserts if called before SetScale()
1360   actor.SetScale(Vector3(12.0f, 1.0f, 2.0f));
1361
1362   DALI_TEST_CHECK(actor.GetCurrentScale() != scale);
1363
1364   actor.SetScale(scale.x, scale.y, scale.z);
1365   // flush the queue and render once
1366   application.SendNotification();
1367   application.Render();
1368   DALI_TEST_CHECK(actor.GetCurrentScale() == scale);
1369
1370   // add to stage and test
1371   Stage::GetCurrent().Add( actor );
1372   actor.SetScale( 2.0f, 2.0f, 2.0f );
1373   // flush the queue and render once
1374   application.SendNotification();
1375   application.Render();
1376   DALI_TEST_EQUALS( Vector3( 2.0f, 2.0f, 2.0f ), actor.GetCurrentScale(), 0.001, TEST_LOCATION);
1377
1378   Stage::GetCurrent().Remove( actor );
1379
1380   END_TEST;
1381 }
1382
1383 // SetScale(Vector3 scale)
1384 int UtcDaliActorSetScale03(void)
1385 {
1386   TestApplication application;
1387   Vector3 scale(10.0f, 10.0f, 10.0f);
1388
1389   Actor actor = Actor::New();
1390
1391   // Set to random value first - GetCurrentScale() asserts if called before SetScale()
1392   actor.SetScale(Vector3(12.0f, 1.0f, 2.0f));
1393
1394   DALI_TEST_CHECK(actor.GetCurrentScale() != scale);
1395
1396   actor.SetScale(scale);
1397
1398   // flush the queue and render once
1399   application.SendNotification();
1400   application.Render();
1401
1402   DALI_TEST_CHECK(actor.GetCurrentScale() == scale);
1403   END_TEST;
1404 }
1405
1406 int UtcDaliActorScaleBy(void)
1407 {
1408   TestApplication application;
1409   Actor actor = Actor::New();
1410   Vector3 vector(100.0f, 100.0f, 100.0f);
1411
1412   DALI_TEST_CHECK(vector != actor.GetCurrentScale());
1413
1414   actor.SetScale(vector);
1415
1416   // flush the queue and render once
1417   application.SendNotification();
1418   application.Render();
1419
1420   DALI_TEST_CHECK(vector == actor.GetCurrentScale());
1421
1422   actor.ScaleBy(vector);
1423
1424   // flush the queue and render once
1425   application.SendNotification();
1426   application.Render();
1427
1428   DALI_TEST_CHECK(vector*100.0f == actor.GetCurrentScale());
1429   END_TEST;
1430 }
1431
1432 int UtcDaliActorGetCurrentScale(void)
1433 {
1434   TestApplication application;
1435   Vector3 scale(12.0f, 1.0f, 2.0f);
1436
1437   Actor actor = Actor::New();
1438
1439   actor.SetScale(scale);
1440
1441   // flush the queue and render once
1442   application.SendNotification();
1443   application.Render();
1444
1445   DALI_TEST_CHECK(actor.GetCurrentScale() == scale);
1446   END_TEST;
1447 }
1448
1449 int UtcDaliActorGetCurrentWorldScale(void)
1450 {
1451   TestApplication application;
1452
1453   Actor parent = Actor::New();
1454   Vector3 parentScale( 1.0f, 2.0f, 3.0f );
1455   parent.SetScale( parentScale );
1456   Stage::GetCurrent().Add( parent );
1457
1458   Actor child = Actor::New();
1459   Vector3 childScale( 2.0f, 2.0f, 2.0f );
1460   child.SetScale( childScale );
1461   parent.Add( child );
1462
1463   // The actors should not have a scale yet
1464   DALI_TEST_EQUALS( parent.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
1465   DALI_TEST_EQUALS( child.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
1466
1467   // The actors should not have a world scale yet
1468   DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
1469   DALI_TEST_EQUALS( child.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
1470
1471   application.SendNotification();
1472   application.Render(0);
1473
1474   DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale, TEST_LOCATION );
1475   DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
1476
1477   // The actors should have a world scale now
1478   DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale, TEST_LOCATION );
1479   DALI_TEST_EQUALS( child.GetCurrentWorldScale(), parentScale * childScale, TEST_LOCATION );
1480   END_TEST;
1481 }
1482
1483 int UtcDaliActorInheritScale(void)
1484 {
1485   tet_infoline("Testing Actor::SetInheritScale");
1486   TestApplication application;
1487
1488   Actor parent = Actor::New();
1489   Vector3 parentScale( 1.0f, 2.0f, 3.0f );
1490   parent.SetScale( parentScale );
1491   Stage::GetCurrent().Add( parent );
1492
1493   Actor child = Actor::New();
1494   Vector3 childScale( 2.0f, 2.0f, 2.0f );
1495   child.SetScale( childScale );
1496   parent.Add( child );
1497
1498   application.SendNotification();
1499   application.Render(0);
1500
1501   DALI_TEST_EQUALS( child.IsScaleInherited(), true, TEST_LOCATION );
1502   DALI_TEST_EQUALS( child.GetCurrentWorldScale(), parentScale * childScale, TEST_LOCATION );
1503
1504   child.SetInheritScale( false );
1505   DALI_TEST_EQUALS( child.IsScaleInherited(), false, TEST_LOCATION );
1506
1507   application.SendNotification();
1508   application.Render(0);
1509
1510   DALI_TEST_EQUALS( child.GetCurrentWorldScale(), childScale, TEST_LOCATION );
1511   END_TEST;
1512 }
1513
1514 int UtcDaliActorSetVisible(void)
1515 {
1516   TestApplication application;
1517
1518   Actor actor = Actor::New();
1519   actor.SetVisible(false);
1520   // flush the queue and render once
1521   application.SendNotification();
1522   application.Render();
1523   DALI_TEST_CHECK(actor.IsVisible() == false);
1524
1525   actor.SetVisible(true);
1526   // flush the queue and render once
1527   application.SendNotification();
1528   application.Render();
1529   DALI_TEST_CHECK(actor.IsVisible() == true);
1530
1531   // put actor on stage
1532   Stage::GetCurrent().Add( actor );
1533   actor.SetVisible(false);
1534   // flush the queue and render once
1535   application.SendNotification();
1536   application.Render();
1537   DALI_TEST_CHECK(actor.IsVisible() == false);
1538   END_TEST;
1539 }
1540
1541 int UtcDaliActorIsVisible(void)
1542 {
1543   TestApplication application;
1544
1545   Actor actor = Actor::New();
1546
1547   DALI_TEST_CHECK(actor.IsVisible() == true);
1548   END_TEST;
1549 }
1550
1551 int UtcDaliActorSetOpacity(void)
1552 {
1553   TestApplication application;
1554
1555   Actor actor = Actor::New();
1556   // initial opacity is 1
1557   DALI_TEST_EQUALS(actor.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1558
1559   actor.SetOpacity( 0.4f);
1560   // flush the queue and render once
1561   application.SendNotification();
1562   application.Render();
1563   DALI_TEST_EQUALS(actor.GetCurrentOpacity(), 0.4f, TEST_LOCATION );
1564
1565   // change opacity, actor is on stage to change is not immediate
1566   actor.SetOpacity( actor.GetCurrentOpacity() + 0.1f );
1567   // flush the queue and render once
1568   application.SendNotification();
1569   application.Render();
1570   DALI_TEST_EQUALS(actor.GetCurrentOpacity(), 0.5f, TEST_LOCATION );
1571
1572   // put actor on stage
1573   Stage::GetCurrent().Add( actor );
1574
1575   // change opacity, actor is on stage to change is not immediate
1576   actor.SetOpacity( 0.9f );
1577   DALI_TEST_EQUALS(actor.GetCurrentOpacity(), 0.5f, TEST_LOCATION );
1578   // flush the queue and render once
1579   application.SendNotification();
1580   application.Render();
1581   DALI_TEST_EQUALS(actor.GetCurrentOpacity(), 0.9f, TEST_LOCATION );
1582
1583   // change opacity, actor is on stage to change is not immediate
1584   actor.SetOpacity( actor.GetCurrentOpacity() - 0.9f );
1585   // flush the queue and render once
1586   application.SendNotification();
1587   application.Render();
1588   DALI_TEST_EQUALS(actor.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
1589   END_TEST;
1590 }
1591
1592 int UtcDaliActorGetCurrentOpacity(void)
1593 {
1594   TestApplication application;
1595
1596   Actor actor = Actor::New();
1597   DALI_TEST_CHECK(actor.GetCurrentOpacity() != 0.5f);
1598
1599   actor.SetOpacity(0.5f);
1600   // flush the queue and render once
1601   application.SendNotification();
1602   application.Render();
1603   DALI_TEST_CHECK(actor.GetCurrentOpacity() == 0.5f);
1604   END_TEST;
1605 }
1606
1607 int UtcDaliActorSetSensitive(void)
1608 {
1609   TestApplication application;
1610   Actor actor = Actor::New();
1611
1612   bool sensitive = !actor.IsSensitive();
1613
1614   actor.SetSensitive(sensitive);
1615
1616   DALI_TEST_CHECK(sensitive == actor.IsSensitive());
1617   END_TEST;
1618 }
1619
1620 int UtcDaliActorIsSensitive(void)
1621 {
1622   TestApplication application;
1623   Actor actor = Actor::New();
1624   actor.SetSensitive(false);
1625
1626   DALI_TEST_CHECK(false == actor.IsSensitive());
1627   END_TEST;
1628 }
1629
1630 int UtcDaliActorSetColor(void)
1631 {
1632   TestApplication application;
1633   Actor actor = Actor::New();
1634   Vector4 color(1.0f, 1.0f, 1.0f, 0.5f);
1635
1636   DALI_TEST_CHECK(color != actor.GetCurrentColor());
1637
1638   actor.SetColor(color);
1639   // flush the queue and render once
1640   application.SendNotification();
1641   application.Render();
1642   DALI_TEST_CHECK(color == actor.GetCurrentColor());
1643
1644   actor.SetColor( actor.GetCurrentColor() + Vector4( -0.4f, -0.5f, -0.6f, -0.4f ) );
1645   // flush the queue and render once
1646   application.SendNotification();
1647   application.Render();
1648   DALI_TEST_EQUALS( Vector4( 0.6f, 0.5f, 0.4f, 0.1f ), actor.GetCurrentColor(),  TEST_LOCATION );
1649
1650   Stage::GetCurrent().Add( actor );
1651   actor.SetColor( color );
1652   // flush the queue and render once
1653   application.SendNotification();
1654   application.Render();
1655   DALI_TEST_EQUALS( color, actor.GetCurrentColor(),  TEST_LOCATION );
1656
1657   actor.SetColor( actor.GetCurrentColor() + Vector4( 1.1f, 1.1f, 1.1f, 1.1f ) );
1658   // flush the queue and render once
1659   application.SendNotification();
1660   application.Render();
1661   // Actor color is not clamped
1662   DALI_TEST_EQUALS( Vector4( 2.1f, 2.1f, 2.1f, 1.6f ), actor.GetCurrentColor(),  TEST_LOCATION );
1663   // world color is clamped
1664   DALI_TEST_EQUALS( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ), actor.GetCurrentWorldColor(),  TEST_LOCATION );
1665
1666   Stage::GetCurrent().Remove( actor );
1667   END_TEST;
1668 }
1669
1670 int UtcDaliActorGetCurrentColor(void)
1671 {
1672   TestApplication application;
1673   Actor actor = Actor::New();
1674   Vector4 color(1.0f, 1.0f, 1.0f, 0.5f);
1675
1676   actor.SetColor(color);
1677   // flush the queue and render once
1678   application.SendNotification();
1679   application.Render();
1680   DALI_TEST_CHECK(color == actor.GetCurrentColor());
1681   END_TEST;
1682 }
1683
1684 int UtcDaliActorGetCurrentWorldColor(void)
1685 {
1686   tet_infoline("Actor::GetCurrentWorldColor");
1687   TestApplication application;
1688
1689   Actor parent = Actor::New();
1690   Vector4 parentColor( 1.0f, 0.5f, 0.0f, 0.8f );
1691   parent.SetColor( parentColor );
1692   Stage::GetCurrent().Add( parent );
1693
1694   Actor child = Actor::New();
1695   Vector4 childColor( 0.5f, 0.6f, 0.5f, 1.0f );
1696   child.SetColor( childColor );
1697   parent.Add( child );
1698
1699   DALI_TEST_EQUALS( parent.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
1700   DALI_TEST_EQUALS( child.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
1701
1702   // verify the default color mode
1703   DALI_TEST_EQUALS( USE_OWN_MULTIPLY_PARENT_ALPHA, child.GetColorMode(), TEST_LOCATION );
1704
1705   // The actors should not have a world color yet
1706   DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION );
1707   DALI_TEST_EQUALS( child.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION );
1708
1709   application.SendNotification();
1710   application.Render(0);
1711
1712   DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
1713   DALI_TEST_EQUALS( child.GetCurrentColor(), childColor, TEST_LOCATION );
1714
1715   // The actors should have a world color now
1716   DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
1717   DALI_TEST_EQUALS( child.GetCurrentWorldColor(), Vector4( childColor.r, childColor.g, childColor.b, childColor.a * parentColor.a), TEST_LOCATION );
1718
1719   // use own color
1720   child.SetColorMode( USE_OWN_COLOR );
1721   application.SendNotification();
1722   application.Render(0);
1723   DALI_TEST_EQUALS( child.GetCurrentWorldColor(), childColor, TEST_LOCATION );
1724
1725   // use parent color
1726   child.SetColorMode( USE_PARENT_COLOR );
1727   application.SendNotification();
1728   application.Render(0);
1729   DALI_TEST_EQUALS( child.GetCurrentColor(), childColor, TEST_LOCATION );
1730   DALI_TEST_EQUALS( child.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
1731
1732   // use parent alpha
1733   child.SetColorMode( USE_OWN_MULTIPLY_PARENT_ALPHA );
1734   application.SendNotification();
1735   application.Render(0);
1736   Vector4 expectedColor( childColor );
1737   expectedColor.a *= parentColor.a;
1738   DALI_TEST_EQUALS( child.GetCurrentColor(), childColor, TEST_LOCATION );
1739   DALI_TEST_EQUALS( child.GetCurrentWorldColor(), expectedColor, TEST_LOCATION );
1740   END_TEST;
1741 }
1742
1743 int UtcDaliActorSetColorMode(void)
1744 {
1745   tet_infoline("Actor::SetColorMode");
1746   TestApplication application;
1747   Actor actor = Actor::New();
1748   Actor child = Actor::New();
1749   actor.Add( child );
1750
1751   actor.SetColorMode( USE_OWN_COLOR );
1752   DALI_TEST_EQUALS( USE_OWN_COLOR, actor.GetColorMode(), TEST_LOCATION );
1753
1754   actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
1755   DALI_TEST_EQUALS( USE_OWN_MULTIPLY_PARENT_COLOR, actor.GetColorMode(), TEST_LOCATION );
1756
1757   actor.SetColorMode( USE_PARENT_COLOR );
1758   DALI_TEST_EQUALS( USE_PARENT_COLOR, actor.GetColorMode(), TEST_LOCATION );
1759
1760   actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_ALPHA );
1761   DALI_TEST_EQUALS( USE_OWN_MULTIPLY_PARENT_ALPHA, actor.GetColorMode(), TEST_LOCATION );
1762   END_TEST;
1763 }
1764
1765 int UtcDaliActorScreenToLocal(void)
1766 {
1767   TestApplication application;
1768   Actor actor = Actor::New();
1769   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1770   actor.SetSize(100.0f, 100.0f);
1771   actor.SetPosition(10.0f, 10.0f);
1772   Stage::GetCurrent().Add(actor);
1773
1774   // flush the queue and render once
1775   application.SendNotification();
1776   application.Render();
1777
1778   float localX;
1779   float localY;
1780
1781   DALI_TEST_CHECK( actor.ScreenToLocal(localX, localY, 50.0f, 50.0f) );
1782
1783   DALI_TEST_EQUALS(localX, 40.0f, 0.01f, TEST_LOCATION);
1784   DALI_TEST_EQUALS(localY, 40.0f, 0.01f, TEST_LOCATION);
1785   END_TEST;
1786 }
1787
1788 int UtcDaliActorSetLeaveRequired(void)
1789 {
1790   TestApplication application;
1791
1792   Actor actor = Actor::New();
1793
1794   actor.SetLeaveRequired(false);
1795   DALI_TEST_CHECK(actor.GetLeaveRequired() == false);
1796
1797   actor.SetLeaveRequired(true);
1798   DALI_TEST_CHECK(actor.GetLeaveRequired() == true);
1799   END_TEST;
1800 }
1801
1802 int UtcDaliActorGetLeaveRequired(void)
1803 {
1804   TestApplication application;
1805
1806   Actor actor = Actor::New();
1807
1808   DALI_TEST_CHECK(actor.GetLeaveRequired() == false);
1809   END_TEST;
1810 }
1811
1812 int UtcDaliActorSetKeyboardFocusable(void)
1813 {
1814   TestApplication application;
1815
1816   Actor actor = Actor::New();
1817
1818   actor.SetKeyboardFocusable(true);
1819   DALI_TEST_CHECK(actor.IsKeyboardFocusable() == true);
1820
1821   actor.SetKeyboardFocusable(false);
1822   DALI_TEST_CHECK(actor.IsKeyboardFocusable() == false);
1823   END_TEST;
1824 }
1825
1826 int UtcDaliActorIsKeyboardFocusable(void)
1827 {
1828   TestApplication application;
1829
1830   Actor actor = Actor::New();
1831
1832   DALI_TEST_CHECK(actor.IsKeyboardFocusable() == false);
1833   END_TEST;
1834 }
1835
1836 int UtcDaliActorRemoveConstraints(void)
1837 {
1838   tet_infoline(" UtcDaliActorRemoveConstraints");
1839   TestApplication application;
1840
1841   gTestConstraintCalled = false;
1842
1843   Actor actor = Actor::New();
1844
1845   Constraint constraint = Constraint::New<Vector4>( actor, Actor::Property::COLOR, TestConstraint() );
1846   constraint.Apply();
1847   actor.RemoveConstraints();
1848
1849   DALI_TEST_CHECK( gTestConstraintCalled == false );
1850
1851   Stage::GetCurrent().Add( actor );
1852   constraint.Apply();
1853
1854   // flush the queue and render once
1855   application.SendNotification();
1856   application.Render();
1857
1858   actor.RemoveConstraints();
1859
1860   DALI_TEST_CHECK( gTestConstraintCalled == true );
1861   END_TEST;
1862 }
1863
1864 int UtcDaliActorRemoveConstraintTag(void)
1865 {
1866   tet_infoline(" UtcDaliActorRemoveConstraintTag");
1867   TestApplication application;
1868
1869   Actor actor = Actor::New();
1870
1871   // 1. Apply Constraint1 and Constraint2, and test...
1872   unsigned int result1 = 0u;
1873   unsigned int result2 = 0u;
1874
1875   unsigned constraint1Tag = 1u;
1876   Constraint constraint1 = Constraint::New<Vector4>( actor, Actor::Property::COLOR, TestConstraintRef<Vector4>(result1, 1) );
1877   constraint1.SetTag( constraint1Tag );
1878   constraint1.Apply();
1879
1880   unsigned constraint2Tag = 2u;
1881   Constraint constraint2 = Constraint::New<Vector4>( actor, Actor::Property::COLOR, TestConstraintRef<Vector4>(result2, 2) );
1882   constraint2.SetTag( constraint2Tag );
1883   constraint2.Apply();
1884
1885   Stage::GetCurrent().Add( actor );
1886   // flush the queue and render once
1887   application.SendNotification();
1888   application.Render();
1889
1890   DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION );
1891   DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION );
1892
1893   // 2. Remove Constraint1 and test...
1894   result1 = 0;
1895   result2 = 0;
1896   actor.RemoveConstraints(constraint1Tag);
1897   // make color property dirty, which will trigger constraints to be reapplied.
1898   actor.SetColor( Color::WHITE );
1899   // flush the queue and render once
1900   application.SendNotification();
1901   application.Render();
1902
1903   DALI_TEST_EQUALS( result1, 0u, TEST_LOCATION );  ///< constraint 1 should not apply now.
1904   DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION );
1905
1906   // 3. Re-Apply Constraint1 and test...
1907   result1 = 0;
1908   result2 = 0;
1909   constraint1.Apply();
1910   // make color property dirty, which will trigger constraints to be reapplied.
1911   actor.SetColor( Color::WHITE );
1912   // flush the queue and render once
1913   application.SendNotification();
1914   application.Render();
1915
1916   DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION );
1917   DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION );
1918
1919   // 2. Remove Constraint2 and test...
1920   result1 = 0;
1921   result2 = 0;
1922   actor.RemoveConstraints(constraint2Tag);
1923   // make color property dirty, which will trigger constraints to be reapplied.
1924   actor.SetColor( Color::WHITE );
1925   // flush the queue and render once
1926   application.SendNotification();
1927   application.Render();
1928
1929   DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION );
1930   DALI_TEST_EQUALS( result2, 0u, TEST_LOCATION ); ///< constraint 2 should not apply now.
1931
1932   // 2. Remove Constraint1 as well and test...
1933   result1 = 0;
1934   result2 = 0;
1935   actor.RemoveConstraints(constraint1Tag);
1936   // make color property dirty, which will trigger constraints to be reapplied.
1937   actor.SetColor( Color::WHITE );
1938   // flush the queue and render once
1939   application.SendNotification();
1940   application.Render();
1941
1942   DALI_TEST_EQUALS( result1, 0u, TEST_LOCATION ); ///< constraint 1 should not apply now.
1943   DALI_TEST_EQUALS( result2, 0u, TEST_LOCATION ); ///< constraint 2 should not apply now.
1944   END_TEST;
1945 }
1946
1947 int UtcDaliActorTouchedSignal(void)
1948 {
1949   TestApplication application;
1950
1951   gTouchCallBackCalled = false;
1952
1953   // get the root layer
1954   Actor actor = Stage::GetCurrent().GetRootLayer();
1955   DALI_TEST_CHECK( gTouchCallBackCalled == false );
1956
1957   application.SendNotification();
1958   application.Render();
1959
1960   // connect to its touch signal
1961   actor.TouchedSignal().Connect( TestCallback );
1962
1963   // simulate a touch event in the middle of the screen
1964   Vector2 touchPoint( Stage::GetCurrent().GetSize() * 0.5 );
1965   Dali::TouchPoint point( 1, TouchPoint::Down, touchPoint.x, touchPoint.y );
1966   Dali::Integration::TouchEvent event;
1967   event.AddPoint( point );
1968   application.ProcessEvent( event );
1969
1970   DALI_TEST_CHECK( gTouchCallBackCalled == true );
1971   END_TEST;
1972 }
1973
1974 int UtcDaliActorHoveredSignal(void)
1975 {
1976   TestApplication application;
1977
1978   gHoverCallBackCalled = false;
1979
1980   // get the root layer
1981   Actor actor = Stage::GetCurrent().GetRootLayer();
1982   DALI_TEST_CHECK( gHoverCallBackCalled == false );
1983
1984   application.SendNotification();
1985   application.Render();
1986
1987   // connect to its hover signal
1988   actor.HoveredSignal().Connect( TestCallback3 );
1989
1990   // simulate a hover event in the middle of the screen
1991   Vector2 touchPoint( Stage::GetCurrent().GetSize() * 0.5 );
1992   Dali::TouchPoint point( 1, TouchPoint::Motion, touchPoint.x, touchPoint.y );
1993   Dali::Integration::HoverEvent event;
1994   event.AddPoint( point );
1995   application.ProcessEvent( event );
1996
1997   DALI_TEST_CHECK( gHoverCallBackCalled == true );
1998   END_TEST;
1999 }
2000
2001 int UtcDaliActorOnOffStageSignal(void)
2002 {
2003   tet_infoline("Testing Dali::Actor::OnStageSignal() and OffStageSignal()");
2004
2005   TestApplication application;
2006
2007   // clean test data
2008   gOnStageCallBackCalled = gOffStageCallBackCalled = 0;
2009   gActorNamesOnOffStage.clear();
2010
2011   Actor parent = Actor::New();
2012   parent.SetName( "parent" );
2013   parent.OnStageSignal().Connect( OnStageCallback );
2014   parent.OffStageSignal().Connect( OffStageCallback );
2015   // sanity check
2016   DALI_TEST_CHECK( gOnStageCallBackCalled == 0 );
2017   DALI_TEST_CHECK( gOffStageCallBackCalled == 0 );
2018
2019   // add parent to stage
2020   Stage::GetCurrent().Add( parent );
2021   // onstage emitted, offstage not
2022   DALI_TEST_EQUALS(  gOnStageCallBackCalled, 1, TEST_LOCATION );
2023   DALI_TEST_EQUALS( gOffStageCallBackCalled, 0, TEST_LOCATION );
2024   DALI_TEST_EQUALS( "parent", gActorNamesOnOffStage[ 0 ], TEST_LOCATION );
2025
2026   // test adding a child, should get onstage emitted
2027   // clean test data
2028   gOnStageCallBackCalled = gOffStageCallBackCalled = 0;
2029   gActorNamesOnOffStage.clear();
2030
2031   Actor child = Actor::New();
2032   child.SetName( "child" );
2033   child.OnStageSignal().Connect( OnStageCallback );
2034   child.OffStageSignal().Connect( OffStageCallback );
2035   parent.Add( child ); // add child
2036   // onstage emitted, offstage not
2037   DALI_TEST_EQUALS(  gOnStageCallBackCalled, 1, TEST_LOCATION );
2038   DALI_TEST_EQUALS( gOffStageCallBackCalled, 0, TEST_LOCATION );
2039   DALI_TEST_EQUALS( "child", gActorNamesOnOffStage[ 0 ], TEST_LOCATION );
2040
2041   // test removing parent from stage
2042   // clean test data
2043   gOnStageCallBackCalled = gOffStageCallBackCalled = 0;
2044   gActorNamesOnOffStage.clear();
2045
2046   Stage::GetCurrent().Remove( parent );
2047   // onstage not emitted, offstage is
2048   DALI_TEST_EQUALS(  gOnStageCallBackCalled, 0, TEST_LOCATION );
2049   DALI_TEST_EQUALS( gOffStageCallBackCalled, 2, TEST_LOCATION );
2050   DALI_TEST_EQUALS( "child", gActorNamesOnOffStage[ 0 ], TEST_LOCATION );
2051   DALI_TEST_EQUALS( "parent", gActorNamesOnOffStage[ 1 ], TEST_LOCATION );
2052
2053   // test adding parent back to stage
2054   // clean test data
2055   gOnStageCallBackCalled = gOffStageCallBackCalled = 0;
2056   gActorNamesOnOffStage.clear();
2057
2058   Stage::GetCurrent().Add( parent );
2059   // onstage emitted, offstage not
2060   DALI_TEST_EQUALS(  gOnStageCallBackCalled, 2, TEST_LOCATION );
2061   DALI_TEST_EQUALS( gOffStageCallBackCalled, 0, TEST_LOCATION );
2062   DALI_TEST_EQUALS( "parent", gActorNamesOnOffStage[ 0 ], TEST_LOCATION );
2063   DALI_TEST_EQUALS( "child", gActorNamesOnOffStage[ 1 ], TEST_LOCATION );
2064
2065   // test removing child
2066   // clean test data
2067   gOnStageCallBackCalled = gOffStageCallBackCalled = 0;
2068   gActorNamesOnOffStage.clear();
2069
2070   parent.Remove( child );
2071   // onstage not emitted, offstage is
2072   DALI_TEST_EQUALS(  gOnStageCallBackCalled, 0, TEST_LOCATION );
2073   DALI_TEST_EQUALS( gOffStageCallBackCalled, 1, TEST_LOCATION );
2074   DALI_TEST_EQUALS( "child", gActorNamesOnOffStage[ 0 ], TEST_LOCATION );
2075
2076   // test removing parent
2077   // clean test data
2078   gOnStageCallBackCalled = gOffStageCallBackCalled = 0;
2079   gActorNamesOnOffStage.clear();
2080
2081   Stage::GetCurrent().Remove( parent );
2082   // onstage not emitted, offstage is
2083   DALI_TEST_EQUALS(  gOnStageCallBackCalled, 0, TEST_LOCATION );
2084   DALI_TEST_EQUALS( gOffStageCallBackCalled, 1, TEST_LOCATION );
2085   DALI_TEST_EQUALS( "parent", gActorNamesOnOffStage[ 0 ], TEST_LOCATION );
2086   END_TEST;
2087 }
2088
2089 int UtcDaliActorFindChildByName(void)
2090 {
2091   tet_infoline("Testing Dali::Actor::FindChildByName()");
2092   TestApplication application;
2093
2094   Actor parent = Actor::New();
2095   parent.SetName( "parent" );
2096   Actor first  = Actor::New();
2097   first .SetName( "first" );
2098   Actor second = Actor::New();
2099   second.SetName( "second" );
2100
2101   parent.Add(first);
2102   first.Add(second);
2103
2104   Actor found = parent.FindChildByName( "foo" );
2105   DALI_TEST_CHECK( !found );
2106
2107   found = parent.FindChildByName( "parent" );
2108   DALI_TEST_CHECK( found == parent );
2109
2110   found = parent.FindChildByName( "first" );
2111   DALI_TEST_CHECK( found == first );
2112
2113   found = parent.FindChildByName( "second" );
2114   DALI_TEST_CHECK( found == second );
2115   END_TEST;
2116 }
2117
2118 int UtcDaliActorFindChildById(void)
2119 {
2120   tet_infoline("Testing Dali::Actor::UtcDaliActorFindChildById()");
2121   TestApplication application;
2122
2123   Actor parent = Actor::New();
2124   Actor first  = Actor::New();
2125   Actor second = Actor::New();
2126
2127   parent.Add(first);
2128   first.Add(second);
2129
2130   Actor found = parent.FindChildById( 100000 );
2131   DALI_TEST_CHECK( !found );
2132
2133   found = parent.FindChildById( parent.GetId() );
2134   DALI_TEST_CHECK( found == parent );
2135
2136   found = parent.FindChildById( first.GetId() );
2137   DALI_TEST_CHECK( found == first );
2138
2139   found = parent.FindChildById( second.GetId() );
2140   DALI_TEST_CHECK( found == second );
2141   END_TEST;
2142 }
2143
2144 int UtcDaliActorHitTest(void)
2145 {
2146   struct HitTestData
2147   {
2148   public:
2149     HitTestData( const Vector3& scale, const Vector2& touchPoint, bool result )
2150     : mScale( scale ),
2151       mTouchPoint( touchPoint ),
2152       mResult( result )
2153     {}
2154
2155     Vector3 mScale;
2156     Vector2 mTouchPoint;
2157     bool mResult;
2158   };
2159
2160   TestApplication application;
2161   tet_infoline(" UtcDaliActorHitTest");
2162
2163   // Fill a vector with different hit tests.
2164   struct HitTestData* hitTestData[] = {
2165     //                    scale                     touch point           result
2166     new HitTestData( Vector3( 100.f, 100.f, 1.f ), Vector2( 289.f, 400.f ), true ),  // touch point close to the right edge (inside)
2167     new HitTestData( Vector3( 100.f, 100.f, 1.f ), Vector2( 291.f, 400.f ), false ), // touch point close to the right edge (outside)
2168     new HitTestData( Vector3( 110.f, 100.f, 1.f ), Vector2( 291.f, 400.f ), true ),  // same point as above with a wider scale. Should be inside.
2169     new HitTestData( Vector3( 100.f, 100.f, 1.f ), Vector2( 200.f, 451.f ), false ), // touch point close to the down edge (outside)
2170     new HitTestData( Vector3( 100.f, 110.f, 1.f ), Vector2( 200.f, 451.f ), true ),  // same point as above with a wider scale. Should be inside.
2171     NULL,
2172   };
2173
2174   // get the root layer
2175   Actor actor = Actor::New();
2176   actor.SetAnchorPoint( AnchorPoint::CENTER );
2177   actor.SetParentOrigin( ParentOrigin::CENTER );
2178
2179   Stage::GetCurrent().Add( actor );
2180
2181   gTouchCallBackCalled = false;
2182
2183   unsigned int index = 0;
2184   while( NULL != hitTestData[index] )
2185   {
2186     actor.SetSize( 1.f, 1.f );
2187     actor.SetScale( hitTestData[index]->mScale.x, hitTestData[index]->mScale.y, hitTestData[index]->mScale.z );
2188
2189     // flush the queue and render once
2190     application.SendNotification();
2191     application.Render();
2192
2193     DALI_TEST_CHECK( !gTouchCallBackCalled );
2194
2195     // connect to its touch signal
2196     actor.TouchedSignal().Connect(TestCallback);
2197
2198     Dali::TouchPoint point( 0, TouchPoint::Down, hitTestData[index]->mTouchPoint.x, hitTestData[index]->mTouchPoint.y );
2199     Dali::Integration::TouchEvent event;
2200     event.AddPoint( point );
2201
2202     // flush the queue and render once
2203     application.SendNotification();
2204     application.Render();
2205     application.ProcessEvent( event );
2206
2207     DALI_TEST_CHECK( gTouchCallBackCalled == hitTestData[index]->mResult );
2208
2209     if( gTouchCallBackCalled != hitTestData[index]->mResult )
2210       tet_printf("Test failed:\nScale %f %f %f\nTouchPoint %f, %f\nResult %d\n",
2211                  hitTestData[index]->mScale.x, hitTestData[index]->mScale.y, hitTestData[index]->mScale.z,
2212                  hitTestData[index]->mTouchPoint.x, hitTestData[index]->mTouchPoint.y,
2213                  hitTestData[index]->mResult );
2214
2215     gTouchCallBackCalled = false;
2216     ++index;
2217   }
2218   END_TEST;
2219 }
2220
2221 int UtcDaliActorSetDrawMode(void)
2222 {
2223   TestApplication app;
2224   tet_infoline(" UtcDaliActorSetDrawModeOverlay");
2225
2226   Actor a = Actor::New();
2227
2228   Stage::GetCurrent().Add(a);
2229   app.SendNotification();
2230   app.Render(0);
2231   app.SendNotification();
2232   app.Render(1);
2233
2234   DALI_TEST_CHECK( DrawMode::NORMAL == a.GetDrawMode() ); // Ensure overlay is off by default
2235
2236   a.SetDrawMode( DrawMode::OVERLAY );
2237   app.SendNotification();
2238   app.Render(1);
2239
2240   DALI_TEST_CHECK( DrawMode::OVERLAY == a.GetDrawMode() ); // Check Actor is overlay
2241
2242   a.SetDrawMode( DrawMode::STENCIL );
2243   app.SendNotification();
2244   app.Render(1);
2245
2246   DALI_TEST_CHECK( DrawMode::STENCIL == a.GetDrawMode() ); // Check Actor is stencil, not overlay
2247
2248   a.SetDrawMode( DrawMode::NORMAL );
2249   app.SendNotification();
2250   app.Render(1);
2251
2252   DALI_TEST_CHECK( DrawMode::NORMAL == a.GetDrawMode() ); // Check Actor is not stencil
2253   END_TEST;
2254 }
2255
2256 int UtcDaliActorSetDrawModeOverlayRender(void)
2257 {
2258   TestApplication app;
2259   tet_infoline(" UtcDaliActorSetDrawModeOverlayRender");
2260
2261   app.SendNotification();
2262   app.Render(1);
2263
2264   std::vector<GLuint> ids;
2265   ids.push_back( 8 );   // first rendered actor
2266   ids.push_back( 9 );   // second rendered actor
2267   ids.push_back( 10 );  // third rendered actor
2268   app.GetGlAbstraction().SetNextTextureIds( ids );
2269
2270   BufferImage imageA = BufferImage::New(16, 16);
2271   BufferImage imageB = BufferImage::New(16, 16);
2272   BufferImage imageC = BufferImage::New(16, 16);
2273   ImageActor a = ImageActor::New( imageA );
2274   ImageActor b = ImageActor::New( imageB );
2275   ImageActor c = ImageActor::New( imageC );
2276
2277   // Render a,b,c as regular non-overlays. so order will be:
2278   // a (8)
2279   // b (9)
2280   // c (10)
2281   Stage::GetCurrent().Add(a);
2282   Stage::GetCurrent().Add(b);
2283   Stage::GetCurrent().Add(c);
2284
2285   app.SendNotification();
2286   app.Render(1);
2287
2288   // Should be 3 textures changes.
2289   const std::vector<GLuint>& boundTextures = app.GetGlAbstraction().GetBoundTextures( GL_TEXTURE0 );
2290   typedef std::vector<GLuint>::size_type TextureSize;
2291   DALI_TEST_EQUALS( boundTextures.size(), static_cast<TextureSize>( 3 ), TEST_LOCATION );
2292   if( boundTextures.size() == 3 )
2293   {
2294     DALI_TEST_CHECK( boundTextures[0] == 8u );
2295     DALI_TEST_CHECK( boundTextures[1] == 9u );
2296     DALI_TEST_CHECK( boundTextures[2] == 10u );
2297   }
2298
2299   // Now texture ids have been set, we can monitor their render order.
2300   // render a as an overlay (last), so order will be:
2301   // b (9)
2302   // c (10)
2303   // a (8)
2304   a.SetDrawMode( DrawMode::OVERLAY );
2305   app.GetGlAbstraction().ClearBoundTextures();
2306
2307   app.SendNotification();
2308   app.Render(1);
2309
2310   // Should be 3 texture changes.
2311   DALI_TEST_EQUALS( boundTextures.size(), static_cast<TextureSize>(3), TEST_LOCATION );
2312   if( boundTextures.size() == 3 )
2313   {
2314     DALI_TEST_CHECK( boundTextures[0] == 9u );
2315     DALI_TEST_CHECK( boundTextures[1] == 10u );
2316     DALI_TEST_CHECK( boundTextures[2] == 8u );
2317   }
2318   END_TEST;
2319 }
2320
2321
2322 int UtcDaliActorSetDrawModeOverlayHitTest(void)
2323 {
2324   TestApplication app;
2325   tet_infoline(" UtcDaliActorSetDrawModeOverlayHitTest");
2326
2327   BufferImage imageA = BufferImage::New(16, 16);
2328   BufferImage imageB = BufferImage::New(16, 16);
2329   ImageActor a = ImageActor::New( imageA );
2330   ImageActor b = ImageActor::New( imageB );
2331
2332   // Render a,b as regular non-overlays. so order will be:
2333   Stage::GetCurrent().Add(a);
2334   Stage::GetCurrent().Add(b);
2335
2336   a.SetSize( 100.0f, 100.0f );
2337   b.SetSize( 100.0f, 100.0f );
2338
2339   // position b overlapping a. (regular non-overlays)
2340   // hit test at point 'x'
2341   // --------
2342   // |      |
2343   // | a    |
2344   // |   --------
2345   // |   |x     |
2346   // |   |      |
2347   // ----|      |
2348   //     |   b  |
2349   //     |      |
2350   //     --------
2351   // note: b is on top, because it's Z position is higher.
2352   a.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
2353   b.SetPosition(Vector3(50.0f, 50.0f, 1.0f));
2354
2355   // connect to their touch signals
2356   a.TouchedSignal().Connect(TestCallback);
2357   b.TouchedSignal().Connect(TestCallback2);
2358
2359   a.SetDrawMode( DrawMode::NORMAL );
2360   b.SetDrawMode( DrawMode::NORMAL );
2361   SimulateTouchForSetOverlayHitTest(app);
2362
2363   DALI_TEST_CHECK( gTouchCallBackCalled == false );
2364   DALI_TEST_CHECK( gTouchCallBack2Called == true );
2365   // Make Actor a an overlay.
2366   // --------
2367   // |      |
2368   // | a    |
2369   // |      |----
2370   // |    x |   |
2371   // |      |   |
2372   // --------   |
2373   //     |   b  |
2374   //     |      |
2375   //     --------
2376   // note: a is on top, because it is an overlay.
2377   a.SetDrawMode( DrawMode::OVERLAY );
2378   b.SetDrawMode( DrawMode::NORMAL );
2379   SimulateTouchForSetOverlayHitTest(app);
2380
2381   DALI_TEST_CHECK( gTouchCallBackCalled == true );
2382   DALI_TEST_CHECK( gTouchCallBack2Called == false );
2383   // Make both Actors as overlays
2384   // --------
2385   // |      |
2386   // | a    |
2387   // |   --------
2388   // |   |x     |
2389   // |   |      |
2390   // ----|      |
2391   //     |   b  |
2392   //     |      |
2393   //     --------
2394   // note: b is on top, because it is the 2nd child in the hierarchy.
2395   a.SetDrawMode( DrawMode::OVERLAY );
2396   b.SetDrawMode( DrawMode::OVERLAY );
2397   SimulateTouchForSetOverlayHitTest(app);
2398
2399   DALI_TEST_CHECK( gTouchCallBackCalled == false );
2400   DALI_TEST_CHECK( gTouchCallBack2Called == true );
2401   END_TEST;
2402 }
2403
2404 int UtcDaliActorGetCurrentWorldMatrix(void)
2405 {
2406   TestApplication app;
2407   tet_infoline(" UtcDaliActorGetCurrentWorldMatrix");
2408
2409   Actor parent = Actor::New();
2410   parent.SetParentOrigin(ParentOrigin::CENTER);
2411   parent.SetAnchorPoint(AnchorPoint::CENTER);
2412   Vector3 parentPosition( 10.0f, 20.0f, 30.0f);
2413   Radian rotationAngle(Degree(85.0f));
2414   Quaternion parentRotation(rotationAngle, Vector3::ZAXIS);
2415   Vector3 parentScale( 1.0f, 2.0f, 3.0f );
2416   parent.SetPosition( parentPosition );
2417   parent.SetOrientation( parentRotation );
2418   parent.SetScale( parentScale );
2419   Stage::GetCurrent().Add( parent );
2420
2421   Actor child = Actor::New();
2422   child.SetParentOrigin(ParentOrigin::CENTER);
2423   Vector3 childPosition( 0.0f, 0.0f, 100.0f );
2424   Radian childRotationAngle(Degree(23.0f));
2425   Quaternion childRotation( childRotationAngle, Vector3::YAXIS );
2426   Vector3 childScale( 2.0f, 2.0f, 2.0f );
2427   child.SetPosition( childPosition );
2428   child.SetOrientation( childRotation );
2429   child.SetScale( childScale );
2430   parent.Add( child );
2431
2432   // The actors should not have a world matrix yet
2433   DALI_TEST_EQUALS( parent.GetCurrentWorldMatrix(), Matrix::IDENTITY, 0.001, TEST_LOCATION );
2434   DALI_TEST_EQUALS( child.GetCurrentWorldMatrix(), Matrix::IDENTITY, 0.001, TEST_LOCATION );
2435
2436   app.SendNotification();
2437   app.Render(0);
2438   app.Render();
2439   app.SendNotification();
2440
2441   Matrix parentMatrix(false);
2442   parentMatrix.SetTransformComponents(parentScale, parentRotation, parentPosition);
2443
2444   Vector3 childWorldPosition = parentPosition + parentRotation * parentScale * childPosition;
2445   Quaternion childWorldRotation = parentRotation * childRotation;
2446   Vector3 childWorldScale = parentScale * childScale;
2447
2448   Matrix childWorldMatrix(false);
2449   childWorldMatrix.SetTransformComponents(childWorldScale, childWorldRotation, childWorldPosition);
2450
2451   DALI_TEST_EQUALS( parent.GetCurrentWorldMatrix(), parentMatrix, 0.001, TEST_LOCATION );
2452   DALI_TEST_EQUALS( child.GetCurrentWorldMatrix(), childWorldMatrix, 0.001, TEST_LOCATION );
2453   END_TEST;
2454 }
2455
2456
2457
2458 int UtcDaliActorConstrainedToWorldMatrix(void)
2459 {
2460   TestApplication app;
2461   tet_infoline(" UtcDaliActorConstrainedToWorldMatrix");
2462
2463   Actor parent = Actor::New();
2464   parent.SetParentOrigin(ParentOrigin::CENTER);
2465   parent.SetAnchorPoint(AnchorPoint::CENTER);
2466   Vector3 parentPosition( 10.0f, 20.0f, 30.0f);
2467   Radian rotationAngle(Degree(85.0f));
2468   Quaternion parentRotation(rotationAngle, Vector3::ZAXIS);
2469   Vector3 parentScale( 1.0f, 2.0f, 3.0f );
2470   parent.SetPosition( parentPosition );
2471   parent.SetOrientation( parentRotation );
2472   parent.SetScale( parentScale );
2473   Stage::GetCurrent().Add( parent );
2474
2475   Actor child = Actor::New();
2476   child.SetParentOrigin(ParentOrigin::CENTER);
2477   Constraint posConstraint = Constraint::New<Vector3>( child, Actor::Property::POSITION, PositionComponentConstraint() );
2478   posConstraint.AddSource( Source( parent, Actor::Property::WORLD_MATRIX ) );
2479   posConstraint.Apply();
2480
2481   Stage::GetCurrent().Add( child );
2482
2483   // The actors should not have a world matrix yet
2484   DALI_TEST_EQUALS( parent.GetCurrentWorldMatrix(), Matrix::IDENTITY, 0.001, TEST_LOCATION );
2485   DALI_TEST_EQUALS( child.GetCurrentWorldMatrix(), Matrix::IDENTITY, 0.001, TEST_LOCATION );
2486
2487   app.SendNotification();
2488   app.Render(0);
2489   app.Render();
2490   app.SendNotification();
2491
2492   Matrix parentMatrix(false);
2493   parentMatrix.SetTransformComponents(parentScale, parentRotation, parentPosition);
2494
2495   DALI_TEST_EQUALS( parent.GetCurrentWorldMatrix(), parentMatrix, 0.001, TEST_LOCATION );
2496   DALI_TEST_EQUALS( child.GetCurrentPosition(), parent.GetCurrentPosition(), 0.001, TEST_LOCATION );
2497   END_TEST;
2498 }
2499
2500 int UtcDaliActorUnparent(void)
2501 {
2502   TestApplication app;
2503   tet_infoline(" UtcDaliActorUnparent");
2504
2505   Actor parent = Actor::New();
2506   Stage::GetCurrent().Add( parent );
2507
2508   Actor child = Actor::New();
2509
2510   DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
2511   DALI_TEST_CHECK( !child.GetParent() );
2512
2513   // Test that calling Unparent with no parent is a NOOP
2514   child.Unparent();
2515
2516   DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
2517   DALI_TEST_CHECK( !child.GetParent() );
2518
2519   // Test that Unparent works
2520   parent.Add( child );
2521
2522   DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
2523   DALI_TEST_CHECK( parent == child.GetParent() );
2524
2525   child.Unparent();
2526
2527   DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
2528   DALI_TEST_CHECK( !child.GetParent() );
2529
2530   // Test that UnparentAndReset works
2531   parent.Add( child );
2532
2533   DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
2534   DALI_TEST_CHECK( parent == child.GetParent() );
2535
2536   UnparentAndReset( child );
2537
2538   DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
2539   DALI_TEST_CHECK( !child );
2540
2541   // Test that UnparentAndReset is a NOOP with empty handle
2542   UnparentAndReset( child );
2543
2544   DALI_TEST_CHECK( !child );
2545   END_TEST;
2546 }
2547
2548 int UtcDaliActorGetChildAt(void)
2549 {
2550   TestApplication app;
2551   tet_infoline(" UtcDaliActorGetChildAt");
2552
2553   Actor parent = Actor::New();
2554   Stage::GetCurrent().Add( parent );
2555
2556   Actor child0 = Actor::New();
2557   parent.Add( child0 );
2558
2559   Actor child1 = Actor::New();
2560   parent.Add( child1 );
2561
2562   Actor child2 = Actor::New();
2563   parent.Add( child2 );
2564
2565   DALI_TEST_EQUALS( parent.GetChildAt( 0 ), child0, TEST_LOCATION );
2566   DALI_TEST_EQUALS( parent.GetChildAt( 1 ), child1, TEST_LOCATION );
2567   DALI_TEST_EQUALS( parent.GetChildAt( 2 ), child2, TEST_LOCATION );
2568   END_TEST;
2569 }
2570
2571 int UtcDaliActorSetGetOverlay(void)
2572 {
2573   TestApplication app;
2574   tet_infoline(" UtcDaliActorSetGetOverlay");
2575
2576   Actor parent = Actor::New();
2577   parent.SetDrawMode(DrawMode::OVERLAY );
2578   DALI_TEST_CHECK( parent.GetDrawMode() == DrawMode::OVERLAY );
2579   END_TEST;
2580 }
2581
2582
2583 // Current Dynamics functions are crashing, so testing these sections are futile
2584
2585 int UtcDaliActorDynamics(void)
2586 {
2587   DALI_TEST_CHECK( true );
2588   END_TEST;
2589 }
2590
2591 int UtcDaliActorCreateDestroy(void)
2592 {
2593   Actor* actor = new Actor;
2594   DALI_TEST_CHECK( actor );
2595   delete actor;
2596   END_TEST;
2597 }
2598
2599 namespace
2600 {
2601 struct PropertyStringIndex
2602 {
2603   const char * const name;
2604   const Property::Index index;
2605   const Property::Type type;
2606 };
2607
2608 const PropertyStringIndex PROPERTY_TABLE[] =
2609 {
2610   { "parent-origin",            Actor::Property::PARENT_ORIGIN,            Property::VECTOR3     },
2611   { "parent-origin-x",          Actor::Property::PARENT_ORIGIN_X,          Property::FLOAT       },
2612   { "parent-origin-y",          Actor::Property::PARENT_ORIGIN_Y,          Property::FLOAT       },
2613   { "parent-origin-z",          Actor::Property::PARENT_ORIGIN_Z,          Property::FLOAT       },
2614   { "anchor-point",             Actor::Property::ANCHOR_POINT,             Property::VECTOR3     },
2615   { "anchor-point-x",           Actor::Property::ANCHOR_POINT_X,           Property::FLOAT       },
2616   { "anchor-point-y",           Actor::Property::ANCHOR_POINT_Y,           Property::FLOAT       },
2617   { "anchor-point-z",           Actor::Property::ANCHOR_POINT_Z,           Property::FLOAT       },
2618   { "size",                     Actor::Property::SIZE,                     Property::VECTOR3     },
2619   { "size-width",               Actor::Property::SIZE_WIDTH,               Property::FLOAT       },
2620   { "size-height",              Actor::Property::SIZE_HEIGHT,              Property::FLOAT       },
2621   { "size-depth",               Actor::Property::SIZE_DEPTH,               Property::FLOAT       },
2622   { "position",                 Actor::Property::POSITION,                 Property::VECTOR3     },
2623   { "position-x",               Actor::Property::POSITION_X,               Property::FLOAT       },
2624   { "position-y",               Actor::Property::POSITION_Y,               Property::FLOAT       },
2625   { "position-z",               Actor::Property::POSITION_Z,               Property::FLOAT       },
2626   { "world-position",           Actor::Property::WORLD_POSITION,           Property::VECTOR3     },
2627   { "world-position-x",         Actor::Property::WORLD_POSITION_X,         Property::FLOAT       },
2628   { "world-position-y",         Actor::Property::WORLD_POSITION_Y,         Property::FLOAT       },
2629   { "world-position-z",         Actor::Property::WORLD_POSITION_Z,         Property::FLOAT       },
2630   { "orientation",              Actor::Property::ORIENTATION,              Property::ROTATION    },
2631   { "world-orientation",        Actor::Property::WORLD_ORIENTATION,        Property::ROTATION    },
2632   { "scale",                    Actor::Property::SCALE,                    Property::VECTOR3     },
2633   { "scale-x",                  Actor::Property::SCALE_X,                  Property::FLOAT       },
2634   { "scale-y",                  Actor::Property::SCALE_Y,                  Property::FLOAT       },
2635   { "scale-z",                  Actor::Property::SCALE_Z,                  Property::FLOAT       },
2636   { "world-scale",              Actor::Property::WORLD_SCALE,              Property::VECTOR3     },
2637   { "visible",                  Actor::Property::VISIBLE,                  Property::BOOLEAN     },
2638   { "color",                    Actor::Property::COLOR,                    Property::VECTOR4     },
2639   { "color-red",                Actor::Property::COLOR_RED,                Property::FLOAT       },
2640   { "color-green",              Actor::Property::COLOR_GREEN,              Property::FLOAT       },
2641   { "color-blue",               Actor::Property::COLOR_BLUE,               Property::FLOAT       },
2642   { "color-alpha",              Actor::Property::COLOR_ALPHA,              Property::FLOAT       },
2643   { "world-color",              Actor::Property::WORLD_COLOR,              Property::VECTOR4     },
2644   { "world-matrix",             Actor::Property::WORLD_MATRIX,             Property::MATRIX      },
2645   { "name",                     Actor::Property::NAME,                     Property::STRING      },
2646   { "sensitive",                Actor::Property::SENSITIVE,                Property::BOOLEAN     },
2647   { "leave-required",           Actor::Property::LEAVE_REQUIRED,           Property::BOOLEAN     },
2648   { "inherit-orientation",      Actor::Property::INHERIT_ORIENTATION,      Property::BOOLEAN     },
2649   { "inherit-scale",            Actor::Property::INHERIT_SCALE,            Property::BOOLEAN     },
2650   { "color-mode",               Actor::Property::COLOR_MODE,               Property::STRING      },
2651   { "position-inheritance",     Actor::Property::POSITION_INHERITANCE,     Property::STRING      },
2652   { "draw-mode",                Actor::Property::DRAW_MODE,                Property::STRING      },
2653   { "size-mode-factor",         Actor::Property::SIZE_MODE_FACTOR,         Property::VECTOR3     },
2654   { "width-resize-policy",      Actor::Property::WIDTH_RESIZE_POLICY,      Property::STRING      },
2655   { "height-resize-policy",     Actor::Property::HEIGHT_RESIZE_POLICY,     Property::STRING      },
2656   { "size-scale-policy",        Actor::Property::SIZE_SCALE_POLICY,        Property::STRING      },
2657   { "width-for-height",         Actor::Property::WIDTH_FOR_HEIGHT,         Property::BOOLEAN     },
2658   { "height-for-width",         Actor::Property::HEIGHT_FOR_WIDTH,         Property::BOOLEAN     },
2659   { "padding",                  Actor::Property::PADDING,                  Property::VECTOR4     },
2660   { "minimum-size",             Actor::Property::MINIMUM_SIZE,             Property::VECTOR2     },
2661   { "maximum-size",             Actor::Property::MAXIMUM_SIZE,             Property::VECTOR2     },
2662 };
2663 const unsigned int PROPERTY_TABLE_COUNT = sizeof( PROPERTY_TABLE ) / sizeof( PROPERTY_TABLE[0] );
2664 } // unnamed namespace
2665
2666 int UtcDaliActorProperties(void)
2667 {
2668   TestApplication app;
2669
2670   Actor actor = Actor::New();
2671
2672   for ( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2673   {
2674     tet_printf( "Checking %s == %d\n", PROPERTY_TABLE[i].name, PROPERTY_TABLE[i].index );
2675     DALI_TEST_EQUALS( actor.GetPropertyName( PROPERTY_TABLE[i].index ), PROPERTY_TABLE[i].name, TEST_LOCATION );
2676     DALI_TEST_EQUALS( actor.GetPropertyIndex( PROPERTY_TABLE[i].name ), PROPERTY_TABLE[i].index, TEST_LOCATION );
2677     DALI_TEST_EQUALS( actor.GetPropertyType( PROPERTY_TABLE[i].index ), PROPERTY_TABLE[i].type, TEST_LOCATION );
2678   }
2679   END_TEST;
2680 }
2681
2682 int UtcDaliRelayoutProperties_ResizePolicies(void)
2683 {
2684   TestApplication app;
2685
2686   Actor actor = Actor::New();
2687
2688   // Defaults
2689   DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::WIDTH_RESIZE_POLICY ).Get< std::string >(), "FIXED", TEST_LOCATION );
2690   DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::HEIGHT_RESIZE_POLICY ).Get< std::string >(), "FIXED", TEST_LOCATION );
2691
2692   // Set resize policy for all dimensions
2693   actor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
2694   for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i)
2695   {
2696     DALI_TEST_EQUALS( actor.GetResizePolicy( static_cast< Dimension::Type >( 1 << i ) ), ResizePolicy::USE_NATURAL_SIZE, TEST_LOCATION );
2697   }
2698
2699   // Set individual dimensions
2700   const char* const widthPolicy = "FILL_TO_PARENT";
2701   const char* const heightPolicy = "FIXED";
2702
2703   actor.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, widthPolicy );
2704   actor.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, heightPolicy );
2705
2706   DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::WIDTH_RESIZE_POLICY ).Get< std::string >(), widthPolicy, TEST_LOCATION );
2707   DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::HEIGHT_RESIZE_POLICY ).Get< std::string >(), heightPolicy, TEST_LOCATION );
2708
2709   END_TEST;
2710 }
2711
2712 int UtcDaliRelayoutProperties_SizeScalePolicy(void)
2713 {
2714   TestApplication app;
2715
2716   Actor actor = Actor::New();
2717
2718   // Defaults
2719   DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::SIZE_SCALE_POLICY ).Get< std::string >(), "USE_SIZE_SET", TEST_LOCATION );
2720   DALI_TEST_EQUALS( actor.GetSizeScalePolicy(), SizeScalePolicy::USE_SIZE_SET, TEST_LOCATION );
2721
2722   SizeScalePolicy::Type policy = SizeScalePolicy::FILL_WITH_ASPECT_RATIO;
2723   actor.SetSizeScalePolicy( policy );
2724   DALI_TEST_EQUALS( actor.GetSizeScalePolicy(), policy, TEST_LOCATION );
2725
2726   // Set
2727   const char* const policy1 = "FIT_WITH_ASPECT_RATIO";
2728   const char* const policy2 = "FILL_WITH_ASPECT_RATIO";
2729
2730   actor.SetProperty( Actor::Property::SIZE_SCALE_POLICY, policy1 );
2731   DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::SIZE_SCALE_POLICY ).Get< std::string >(), policy1, TEST_LOCATION );
2732
2733   actor.SetProperty( Actor::Property::SIZE_SCALE_POLICY, policy2 );
2734   DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::SIZE_SCALE_POLICY ).Get< std::string >(), policy2, TEST_LOCATION );
2735
2736   END_TEST;
2737 }
2738
2739 int UtcDaliRelayoutProperties_SizeModeFactor(void)
2740 {
2741   TestApplication app;
2742
2743   Actor actor = Actor::New();
2744
2745   // Defaults
2746   DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::SIZE_MODE_FACTOR ).Get< Vector3 >(), Vector3( 1.0f, 1.0f, 1.0f ), TEST_LOCATION );
2747   DALI_TEST_EQUALS( actor.GetSizeModeFactor(), Vector3( 1.0f, 1.0f, 1.0f ), TEST_LOCATION );
2748
2749   Vector3 sizeMode( 1.0f, 2.0f, 3.0f );
2750   actor.SetSizeModeFactor( sizeMode );
2751   DALI_TEST_EQUALS( actor.GetSizeModeFactor(), sizeMode, TEST_LOCATION );
2752
2753   // Set
2754   Vector3 sizeMode1( 2.0f, 3.0f, 4.0f );
2755
2756   actor.SetProperty( Actor::Property::SIZE_MODE_FACTOR, sizeMode1 );
2757   DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::SIZE_MODE_FACTOR ).Get< Vector3 >(), sizeMode1, TEST_LOCATION );
2758
2759   END_TEST;
2760 }
2761
2762 int UtcDaliRelayoutProperties_DimensionDependency(void)
2763 {
2764   TestApplication app;
2765
2766   Actor actor = Actor::New();
2767
2768   // Defaults
2769   DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::WIDTH_FOR_HEIGHT ).Get< bool >(), false, TEST_LOCATION );
2770   DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::HEIGHT_FOR_WIDTH ).Get< bool >(), false, TEST_LOCATION );
2771
2772   // Set
2773   actor.SetProperty( Actor::Property::WIDTH_FOR_HEIGHT, true );
2774   DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::WIDTH_FOR_HEIGHT ).Get< bool >(), true, TEST_LOCATION );
2775
2776   actor.SetProperty( Actor::Property::HEIGHT_FOR_WIDTH, true );
2777   DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::HEIGHT_FOR_WIDTH ).Get< bool >(), true, TEST_LOCATION );
2778
2779   // Test setting another resize policy
2780   actor.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, "FIXED" );
2781   DALI_TEST_EQUALS( actor.GetProperty( Actor::Property::WIDTH_FOR_HEIGHT ).Get< bool >(), false, TEST_LOCATION );
2782
2783   END_TEST;
2784 }
2785
2786 int UtcDaliRelayoutProperties_Padding(void)
2787 {
2788   TestApplication app;
2789
2790   Actor actor = Actor::New();
2791
2792   // Data
2793   Vector4 padding( 1.0f, 2.0f, 3.0f, 4.0f );
2794
2795   // PADDING
2796   actor.SetProperty( Actor::Property::PADDING, padding );
2797   Vector4 paddingResult = actor.GetProperty( Actor::Property::PADDING ).Get< Vector4 >();
2798
2799   DALI_TEST_EQUALS( paddingResult, padding, Math::MACHINE_EPSILON_0, TEST_LOCATION );
2800
2801   END_TEST;
2802 }
2803
2804 int UtcDaliRelayoutProperties_MinimumMaximumSize(void)
2805 {
2806   TestApplication app;
2807
2808   Actor actor = Actor::New();
2809
2810   // Data
2811   Vector2 minSize( 1.0f, 2.0f );
2812
2813   actor.SetProperty( Actor::Property::MINIMUM_SIZE, minSize );
2814   Vector2 resultMin = actor.GetProperty( Actor::Property::MINIMUM_SIZE ).Get< Vector2 >();
2815
2816   DALI_TEST_EQUALS( resultMin, minSize, Math::MACHINE_EPSILON_0, TEST_LOCATION );
2817
2818   Vector2 maxSize( 3.0f, 4.0f );
2819
2820   actor.SetProperty( Actor::Property::MAXIMUM_SIZE, maxSize );
2821   Vector2 resultMax = actor.GetProperty( Actor::Property::MAXIMUM_SIZE ).Get< Vector2 >();
2822
2823   DALI_TEST_EQUALS( resultMax, maxSize, Math::MACHINE_EPSILON_0, TEST_LOCATION );
2824
2825   END_TEST;
2826 }
2827
2828 int UtcDaliActorGetHeightForWidth(void)
2829 {
2830   TestApplication app;
2831
2832   Actor actor = Actor::New();
2833
2834   DALI_TEST_EQUALS( actor.GetHeightForWidth( 1.0f ), 0.0f, TEST_LOCATION );
2835
2836   END_TEST;
2837 }
2838
2839 int UtcDaliActorGetWidthForHeight(void)
2840 {
2841   TestApplication app;
2842
2843   Actor actor = Actor::New();
2844
2845   DALI_TEST_EQUALS( actor.GetWidthForHeight( 1.0f ), 0.0f, TEST_LOCATION );
2846
2847   END_TEST;
2848 }
2849
2850 int UtcDaliActorGetRelayoutSize(void)
2851 {
2852   TestApplication app;
2853
2854   Actor actor = Actor::New();
2855
2856   // Add actor to stage
2857   Stage::GetCurrent().Add( actor );
2858
2859   DALI_TEST_EQUALS( actor.GetRelayoutSize( Dimension::WIDTH ), 0.0f, TEST_LOCATION );
2860
2861   actor.SetResizePolicy( ResizePolicy::FIXED, Dimension::WIDTH );
2862   actor.SetSize( Vector2( 1.0f, 0.0f ) );
2863
2864   // Flush the queue and render once
2865   app.SendNotification();
2866   app.Render();
2867
2868   DALI_TEST_EQUALS( actor.GetRelayoutSize( Dimension::WIDTH ), 1.0f, TEST_LOCATION );
2869
2870   END_TEST;
2871 }
2872
2873 int UtcDaliActorSetPadding(void)
2874 {
2875   TestApplication app;
2876
2877   Actor actor = Actor::New();
2878
2879   Padding padding;
2880   actor.GetPadding( padding );
2881
2882   DALI_TEST_EQUALS( padding.left, 0.0f, TEST_LOCATION );
2883   DALI_TEST_EQUALS( padding.right, 0.0f, TEST_LOCATION );
2884   DALI_TEST_EQUALS( padding.bottom, 0.0f, TEST_LOCATION );
2885   DALI_TEST_EQUALS( padding.top, 0.0f, TEST_LOCATION );
2886
2887   Padding padding2( 1.0f, 2.0f, 3.0f, 4.0f );
2888   actor.SetPadding( padding2 );
2889
2890   actor.GetPadding( padding );
2891
2892   DALI_TEST_EQUALS( padding.left, padding2.left, TEST_LOCATION );
2893   DALI_TEST_EQUALS( padding.right, padding2.right, TEST_LOCATION );
2894   DALI_TEST_EQUALS( padding.bottom, padding2.bottom, TEST_LOCATION );
2895   DALI_TEST_EQUALS( padding.top, padding2.top, TEST_LOCATION );
2896
2897   END_TEST;
2898 }
2899
2900 int UtcDaliActorSetMinimumSize(void)
2901 {
2902   TestApplication app;
2903
2904   Actor actor = Actor::New();
2905
2906   Vector2 size = actor.GetMinimumSize();
2907
2908   DALI_TEST_EQUALS( size.width, 0.0f, TEST_LOCATION );
2909   DALI_TEST_EQUALS( size.height, 0.0f, TEST_LOCATION );
2910
2911   Vector2 size2( 1.0f, 2.0f );
2912   actor.SetMinimumSize( size2 );
2913
2914   size = actor.GetMinimumSize();
2915
2916   DALI_TEST_EQUALS( size.width, size2.width, TEST_LOCATION );
2917   DALI_TEST_EQUALS( size.height, size2.height, TEST_LOCATION );
2918
2919   END_TEST;
2920 }
2921
2922 int UtcDaliActorSetMaximumSize(void)
2923 {
2924   TestApplication app;
2925
2926   Actor actor = Actor::New();
2927
2928   Vector2 size = actor.GetMaximumSize();
2929
2930   DALI_TEST_EQUALS( size.width, FLT_MAX, TEST_LOCATION );
2931   DALI_TEST_EQUALS( size.height, FLT_MAX, TEST_LOCATION );
2932
2933   Vector2 size2( 1.0f, 2.0f );
2934   actor.SetMaximumSize( size2 );
2935
2936   size = actor.GetMaximumSize();
2937
2938   DALI_TEST_EQUALS( size.width, size2.width, TEST_LOCATION );
2939   DALI_TEST_EQUALS( size.height, size2.height, TEST_LOCATION );
2940
2941   END_TEST;
2942 }
2943
2944 int UtcDaliActorOnRelayoutSignal(void)
2945 {
2946   tet_infoline("Testing Dali::Actor::OnRelayoutSignal()");
2947
2948   TestApplication application;
2949
2950   // Clean test data
2951   gOnRelayoutCallBackCalled = 0;
2952   gActorNamesRelayout.clear();
2953
2954   Actor actor = Actor::New();
2955   actor.SetName( "actor" );
2956   actor.OnRelayoutSignal().Connect( OnRelayoutCallback );
2957
2958   // Sanity check
2959   DALI_TEST_CHECK( gOnRelayoutCallBackCalled == 0 );
2960
2961   // Add actor to stage
2962   Stage::GetCurrent().Add( actor );
2963
2964   actor.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
2965   actor.SetSize( Vector2( 1.0f, 2.0 ) );
2966
2967   // Flush the queue and render once
2968   application.SendNotification();
2969   application.Render();
2970
2971   // OnRelayout emitted
2972   DALI_TEST_EQUALS(  gOnRelayoutCallBackCalled, 1, TEST_LOCATION );
2973   DALI_TEST_EQUALS( "actor", gActorNamesRelayout[ 0 ], TEST_LOCATION );
2974
2975   END_TEST;
2976 }