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