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