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