Uses TextArray new type definition.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Alignment.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 <iostream>
19 #include <stdlib.h>
20
21
22 // Need to override adaptor classes for toolkit test harness, so include
23 // test harness headers before dali headers.
24 #include <dali-toolkit-test-suite-utils.h>
25 #include <dali/integration-api/events/key-event-integ.h>
26 #include <dali/integration-api/events/touch-event-integ.h>
27 #include <dali-toolkit/dali-toolkit.h>
28
29 using namespace Dali;
30 using namespace Dali::Toolkit;
31
32 void utc_dali_toolkit_alignment_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void utc_dali_toolkit_alignment_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42
43 namespace
44 {
45 static bool gObjectCreatedCallBackCalled;
46
47 static void TestCallback(BaseHandle handle)
48 {
49   gObjectCreatedCallBackCalled = true;
50 }
51 } // namespace
52
53
54 int UtcDaliAlignmentConstructorNegative(void)
55 {
56   ToolkitTestApplication application;
57
58   Alignment alignment;
59
60   try
61   {
62     Alignment::Padding padding;
63     alignment.SetPadding(padding);
64     tet_result(TET_FAIL);
65   }
66   catch (DaliException& exception)
67   {
68     if (exception.mCondition == "alignment")
69     {
70       tet_result(TET_PASS);
71     }
72   }
73   END_TEST;
74 }
75
76 int UtcDaliAlignmentConstructorPositive(void)
77 {
78   ToolkitTestApplication application;
79
80   Alignment alignment = Alignment::New();
81
82   try
83   {
84     Alignment::Padding padding;
85     alignment.SetPadding(padding);
86     tet_result(TET_PASS);
87   }
88   catch (DaliException& exception)
89   {
90     tet_result(TET_FAIL);
91   }
92
93   Actor actor = alignment;
94   alignment = Alignment::DownCast( actor );
95
96   DALI_TEST_CHECK( alignment );
97   END_TEST;
98 }
99
100 int UtcDaliAlignmentConstructorRegister(void)
101 {
102   ToolkitTestApplication application;
103
104   //Te ensure the object is registered after creation
105   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
106   DALI_TEST_CHECK( registry );
107
108   gObjectCreatedCallBackCalled = false;
109   registry.ObjectCreatedSignal().Connect(&TestCallback);
110   {
111     Alignment alignment = Alignment::New();
112   }
113   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
114   END_TEST;
115 }
116
117 int UtcDaliAlignmentSetAlignmentTypePositiveOffStage(void)
118 {
119   ToolkitTestApplication application;
120
121   // Default, HorizontalCenter, VerticalCenter - Ensure they do not change!
122   {
123     Alignment alignment = Alignment::New();
124
125     // Check default values
126     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
127
128     Alignment::Type type(Alignment::Type(Alignment::HorizontalCenter | Alignment::VerticalCenter));
129     alignment.SetAlignmentType(type);
130     DALI_TEST_CHECK(alignment.GetAlignmentType() & type);
131   }
132
133   // HorizontalLeft, VerticalCenter
134   {
135     Alignment alignment = Alignment::New();
136
137     // Check default values
138     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
139
140     Alignment::Type type(Alignment::HorizontalLeft);
141     alignment.SetAlignmentType(type);
142     DALI_TEST_CHECK(alignment.GetAlignmentType() & type);
143   }
144
145   // HorizontalRight, VerticalCenter
146   {
147     Alignment alignment = Alignment::New();
148
149     // Check default values
150     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
151
152     Alignment::Type type(Alignment::HorizontalRight);
153     alignment.SetAlignmentType(type);
154     DALI_TEST_CHECK(alignment.GetAlignmentType() & type);
155   }
156
157   // HorizontalLeft, VerticalTop
158   {
159     Alignment alignment = Alignment::New();
160
161     // Check default values
162     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
163
164     Alignment::Type type(Alignment::Type(Alignment::HorizontalLeft | Alignment::VerticalTop));
165     alignment.SetAlignmentType(type);
166     DALI_TEST_CHECK(alignment.GetAlignmentType() & type);
167   }
168
169   // HorizontalCenter, VerticalTop
170   {
171     Alignment alignment = Alignment::New();
172
173     // Check default values
174     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
175
176     Alignment::Type type(Alignment::VerticalTop);
177     alignment.SetAlignmentType(type);
178     DALI_TEST_CHECK(alignment.GetAlignmentType() & type);
179   }
180
181   // HorizontalRight, VerticalTop
182   {
183     Alignment alignment = Alignment::New();
184
185     // Check default values
186     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
187
188     Alignment::Type type(Alignment::Type(Alignment::HorizontalRight | Alignment::VerticalTop));
189     alignment.SetAlignmentType(type);
190     DALI_TEST_CHECK(alignment.GetAlignmentType() & type);
191   }
192
193   // HorizontalLeft, VerticalBottom
194   {
195     Alignment alignment = Alignment::New();
196
197     // Check default values
198     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
199
200     Alignment::Type type(Alignment::Type(Alignment::HorizontalLeft | Alignment::VerticalBottom));
201     alignment.SetAlignmentType(type);
202     DALI_TEST_CHECK(alignment.GetAlignmentType() & type);
203   }
204
205   // HorizontalCenter, VerticalBottom
206   {
207     Alignment alignment = Alignment::New();
208
209     // Check default values
210     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
211
212     Alignment::Type type(Alignment::VerticalBottom);
213     alignment.SetAlignmentType(type);
214     DALI_TEST_CHECK(alignment.GetAlignmentType() & type);
215   }
216
217   // HorizontalRight, VerticalBottom
218   {
219     Alignment alignment = Alignment::New();
220
221     // Check default values
222     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
223
224     Alignment::Type type(Alignment::Type(Alignment::HorizontalRight | Alignment::VerticalBottom));
225     alignment.SetAlignmentType(type);
226     DALI_TEST_CHECK(alignment.GetAlignmentType() & type);
227   }
228   END_TEST;
229 }
230
231 int UtcDaliAlignmentSetAlignmentTypePositiveOnStage(void)
232 {
233   ToolkitTestApplication application;
234
235   // Default, HorizontalCenter, VerticalCenter - Ensure they do not change!
236   {
237     Alignment alignment = Alignment::New();
238     alignment.Add(RenderableActor::New());
239     Stage::GetCurrent().Add(alignment);
240     application.Render();
241     application.SendNotification();
242
243     // Check default values
244     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
245
246     Alignment::Type type(Alignment::Type(Alignment::HorizontalCenter | Alignment::VerticalCenter));
247     alignment.SetAlignmentType(type);
248     DALI_TEST_CHECK(alignment.GetAlignmentType() & type);
249
250     Stage::GetCurrent().Remove(alignment);
251     application.Render();
252     application.SendNotification();
253   }
254
255   // HorizontalLeft, VerticalCenter
256   {
257     Alignment alignment = Alignment::New();
258     alignment.Add(RenderableActor::New());
259     Stage::GetCurrent().Add(alignment);
260     application.Render();
261     application.SendNotification();
262
263     // Check default values
264     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
265
266     Alignment::Type type(Alignment::HorizontalLeft);
267     alignment.SetAlignmentType(type);
268     DALI_TEST_CHECK(alignment.GetAlignmentType() & type);
269
270     Stage::GetCurrent().Remove(alignment);
271     application.Render();
272     application.SendNotification();
273   }
274
275   // HorizontalRight, VerticalCenter
276   {
277     Alignment alignment = Alignment::New();
278     alignment.Add(RenderableActor::New());
279     Stage::GetCurrent().Add(alignment);
280     application.Render();
281     application.SendNotification();
282
283     // Check default values
284     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
285
286     Alignment::Type type(Alignment::HorizontalRight);
287     alignment.SetAlignmentType(type);
288     DALI_TEST_CHECK(alignment.GetAlignmentType() & type);
289
290     Stage::GetCurrent().Remove(alignment);
291     application.Render();
292     application.SendNotification();
293   }
294
295   // HorizontalLeft, VerticalTop
296   {
297     Alignment alignment = Alignment::New();
298     alignment.Add(RenderableActor::New());
299     Stage::GetCurrent().Add(alignment);
300     application.Render();
301     application.SendNotification();
302
303     // Check default values
304     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
305
306     Alignment::Type type(Alignment::Type(Alignment::HorizontalLeft | Alignment::VerticalTop));
307     alignment.SetAlignmentType(type);
308     DALI_TEST_CHECK(alignment.GetAlignmentType() & type);
309
310     Stage::GetCurrent().Remove(alignment);
311     application.Render();
312     application.SendNotification();
313   }
314
315   // HorizontalCenter, VerticalTop
316   {
317     Alignment alignment = Alignment::New();
318     alignment.Add(RenderableActor::New());
319     Stage::GetCurrent().Add(alignment);
320     application.Render();
321     application.SendNotification();
322
323     // Check default values
324     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
325
326     Alignment::Type type(Alignment::VerticalTop);
327     alignment.SetAlignmentType(type);
328     DALI_TEST_CHECK(alignment.GetAlignmentType() & type);
329
330     Stage::GetCurrent().Remove(alignment);
331     application.Render();
332     application.SendNotification();
333   }
334
335   // HorizontalRight, VerticalTop
336   {
337     Alignment alignment = Alignment::New();
338     alignment.Add(RenderableActor::New());
339     Stage::GetCurrent().Add(alignment);
340     application.Render();
341     application.SendNotification();
342
343     // Check default values
344     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
345
346     Alignment::Type type(Alignment::Type(Alignment::HorizontalRight | Alignment::VerticalTop));
347     alignment.SetAlignmentType(type);
348     DALI_TEST_CHECK(alignment.GetAlignmentType() & type);
349
350     Stage::GetCurrent().Remove(alignment);
351     application.Render();
352     application.SendNotification();
353   }
354
355   // HorizontalLeft, VerticalBottom
356   {
357     Alignment alignment = Alignment::New();
358     alignment.Add(RenderableActor::New());
359     Stage::GetCurrent().Add(alignment);
360     application.Render();
361     application.SendNotification();
362
363     // Check default values
364     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
365
366     Alignment::Type type(Alignment::Type(Alignment::HorizontalLeft | Alignment::VerticalBottom));
367     alignment.SetAlignmentType(type);
368     DALI_TEST_CHECK(alignment.GetAlignmentType() & type);
369
370     Stage::GetCurrent().Remove(alignment);
371     application.Render();
372     application.SendNotification();
373   }
374
375   // HorizontalCenter, VerticalBottom
376   {
377     Alignment alignment = Alignment::New();
378     alignment.Add(RenderableActor::New());
379     Stage::GetCurrent().Add(alignment);
380     application.Render();
381     application.SendNotification();
382
383     // Check default values
384     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
385
386     Alignment::Type type(Alignment::VerticalBottom);
387     alignment.SetAlignmentType(type);
388     DALI_TEST_CHECK(alignment.GetAlignmentType() & type);
389
390     Stage::GetCurrent().Remove(alignment);
391     application.Render();
392     application.SendNotification();
393   }
394
395   // HorizontalRight, VerticalBottom
396   {
397     Alignment alignment = Alignment::New();
398     alignment.Add(RenderableActor::New());
399     Stage::GetCurrent().Add(alignment);
400     application.Render();
401     application.SendNotification();
402
403     // Check default values
404     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
405
406     Alignment::Type type(Alignment::Type(Alignment::HorizontalRight | Alignment::VerticalBottom));
407     alignment.SetAlignmentType(type);
408     DALI_TEST_CHECK(alignment.GetAlignmentType() & type);
409
410     Stage::GetCurrent().Remove(alignment);
411     application.Render();
412     application.SendNotification();
413   }
414   END_TEST;
415 }
416
417 int UtcDaliAlignmentSetAlignmentTypeNegative(void)
418 {
419   ToolkitTestApplication application;
420
421   // Setting HorizontalLeft, HorizontalCenter
422   {
423     Alignment alignment = Alignment::New();
424     Alignment::Type type(Alignment::Type(Alignment::HorizontalLeft | Alignment::HorizontalCenter));
425
426     try
427     {
428       alignment.SetAlignmentType(type);
429       tet_result(TET_FAIL);
430     }
431     catch (DaliException& exception)
432     {
433       if (exception.mCondition == "!horizontalSet")
434       {
435         tet_result(TET_PASS);
436       }
437     }
438   }
439
440   // Setting HorizontalCenter, HorizontalRight
441   {
442     Alignment alignment = Alignment::New();
443     Alignment::Type type(Alignment::Type(Alignment::HorizontalCenter | Alignment::HorizontalRight));
444
445     try
446     {
447       alignment.SetAlignmentType(type);
448       tet_result(TET_FAIL);
449     }
450     catch (DaliException& exception)
451     {
452       if (exception.mCondition == "!horizontalSet")
453       {
454         tet_result(TET_PASS);
455       }
456     }
457   }
458
459   // Setting VerticalTop, VerticalCenter
460   {
461     Alignment alignment = Alignment::New();
462     Alignment::Type type(Alignment::Type(Alignment::VerticalTop | Alignment::VerticalCenter));
463
464     try
465     {
466       alignment.SetAlignmentType(type);
467       tet_result(TET_FAIL);
468     }
469     catch (DaliException& exception)
470     {
471       if (exception.mCondition == "!verticalSet")
472       {
473         tet_result(TET_PASS);
474       }
475     }
476   }
477
478   // Setting VerticalCenter, VerticalBottom
479   {
480     Alignment alignment = Alignment::New();
481     Alignment::Type type(Alignment::Type(Alignment::VerticalTop | Alignment::VerticalBottom));
482
483     try
484     {
485       alignment.SetAlignmentType(type);
486       tet_result(TET_FAIL);
487     }
488     catch (DaliException& exception)
489     {
490       if (exception.mCondition == "!veritcalSet")
491       {
492         tet_result(TET_PASS);
493       }
494     }
495   }
496   END_TEST;
497 }
498
499 int UtcDaliAlignmentGetAlignmentType(void)
500 {
501   ToolkitTestApplication application;
502
503   // Default, HorizonalCenter, VerticalCenter
504   {
505     Alignment alignment = Alignment::New();
506     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
507     alignment.Add(RenderableActor::New());
508     Stage::GetCurrent().Add(alignment);
509     application.Render();
510     application.SendNotification();
511     Stage::GetCurrent().Remove(alignment);
512     application.Render();
513     application.SendNotification();
514   }
515
516   // HorizontalLeft, VerticalCenter
517   {
518     Alignment alignment = Alignment::New(Alignment::HorizontalLeft);
519     DALI_TEST_EQUALS(Alignment::HorizontalLeft | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
520     alignment.Add(RenderableActor::New());
521     Stage::GetCurrent().Add(alignment);
522     application.Render();
523     application.SendNotification();
524     Stage::GetCurrent().Remove(alignment);
525     application.Render();
526     application.SendNotification();
527   }
528
529   // HorizontalRight, VerticalCenter
530   {
531     Alignment alignment = Alignment::New(Alignment::HorizontalRight);
532     DALI_TEST_EQUALS(Alignment::HorizontalRight | Alignment::VerticalCenter, alignment.GetAlignmentType(), TEST_LOCATION);
533     alignment.Add(RenderableActor::New());
534     Stage::GetCurrent().Add(alignment);
535     application.Render();
536     application.SendNotification();
537     Stage::GetCurrent().Remove(alignment);
538     application.Render();
539     application.SendNotification();
540   }
541
542   // HorizontalLeft, VerticalTop
543   {
544     Alignment alignment = Alignment::New(Alignment::HorizontalLeft, Alignment::VerticalTop);
545     DALI_TEST_EQUALS(Alignment::HorizontalLeft | Alignment::VerticalTop, alignment.GetAlignmentType(), TEST_LOCATION);
546     alignment.Add(RenderableActor::New());
547     Stage::GetCurrent().Add(alignment);
548     application.Render();
549     application.SendNotification();
550     Stage::GetCurrent().Remove(alignment);
551     application.Render();
552     application.SendNotification();
553   }
554
555   // HorizontalCenter, VerticalTop
556   {
557     Alignment alignment = Alignment::New(Alignment::HorizontalCenter, Alignment::VerticalTop);
558     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalTop, alignment.GetAlignmentType(), TEST_LOCATION);
559     alignment.Add(RenderableActor::New());
560     Stage::GetCurrent().Add(alignment);
561     application.Render();
562     application.SendNotification();
563     Stage::GetCurrent().Remove(alignment);
564     application.Render();
565     application.SendNotification();
566   }
567
568   // HorizontalRight, VerticalTop
569   {
570     Alignment alignment = Alignment::New(Alignment::HorizontalRight, Alignment::VerticalTop);
571     DALI_TEST_EQUALS(Alignment::HorizontalRight | Alignment::VerticalTop, alignment.GetAlignmentType(), TEST_LOCATION);
572     alignment.Add(RenderableActor::New());
573     Stage::GetCurrent().Add(alignment);
574     application.Render();
575     application.SendNotification();
576     Stage::GetCurrent().Remove(alignment);
577     application.Render();
578     application.SendNotification();
579   }
580
581   // HorizontalLeft, VerticalBottom
582   {
583     Alignment alignment = Alignment::New(Alignment::HorizontalLeft, Alignment::VerticalBottom);
584     DALI_TEST_EQUALS(Alignment::HorizontalLeft | Alignment::VerticalBottom, alignment.GetAlignmentType(), TEST_LOCATION);
585     alignment.Add(RenderableActor::New());
586     Stage::GetCurrent().Add(alignment);
587     application.Render();
588     application.SendNotification();
589     Stage::GetCurrent().Remove(alignment);
590     application.Render();
591     application.SendNotification();
592   }
593
594   // HorizontalCenter, VerticalBottom
595   {
596     Alignment alignment = Alignment::New(Alignment::HorizontalCenter, Alignment::VerticalBottom);
597     DALI_TEST_EQUALS(Alignment::HorizontalCenter | Alignment::VerticalBottom, alignment.GetAlignmentType(), TEST_LOCATION);
598     alignment.Add(RenderableActor::New());
599     Stage::GetCurrent().Add(alignment);
600     application.Render();
601     application.SendNotification();
602     Stage::GetCurrent().Remove(alignment);
603     application.Render();
604     application.SendNotification();
605   }
606
607   // HorizontalRight, VerticalBottom
608   {
609     Alignment alignment = Alignment::New(Alignment::HorizontalRight, Alignment::VerticalBottom);
610     DALI_TEST_EQUALS(Alignment::HorizontalRight | Alignment::VerticalBottom, alignment.GetAlignmentType(), TEST_LOCATION);
611     alignment.Add(RenderableActor::New());
612     Stage::GetCurrent().Add(alignment);
613     application.Render();
614     application.SendNotification();
615     Stage::GetCurrent().Remove(alignment);
616     application.Render();
617     application.SendNotification();
618   }
619   END_TEST;
620 }
621
622 int UtcDaliAlignmentSetScaling(void)
623 {
624   ToolkitTestApplication application;
625
626   // ScaleToFill
627   {
628     Alignment alignment = Alignment::New();
629     alignment.Add(RenderableActor::New());
630     Stage::GetCurrent().Add(alignment);
631     application.Render();
632     application.SendNotification();
633
634     DALI_TEST_EQUALS(Alignment::ScaleNone, alignment.GetScaling(), TEST_LOCATION);
635     alignment.SetScaling(Alignment::ScaleToFill);
636     DALI_TEST_EQUALS(Alignment::ScaleToFill, alignment.GetScaling(), TEST_LOCATION);
637     application.Render();
638     application.SendNotification();
639
640     // For complete line coverage
641     alignment.SetAlignmentType(Alignment::HorizontalLeft);
642     application.Render();
643     application.SendNotification();
644     alignment.SetAlignmentType(Alignment::HorizontalRight);
645     application.Render();
646     application.SendNotification();
647     alignment.SetAlignmentType(Alignment::VerticalTop);
648     application.Render();
649     application.SendNotification();
650     alignment.SetAlignmentType(Alignment::VerticalBottom);
651     application.Render();
652     application.SendNotification();
653
654     Stage::GetCurrent().Remove(alignment);
655     application.Render();
656     application.SendNotification();
657   }
658
659   // ScaleToFitKeepAspect
660   {
661     Alignment alignment = Alignment::New();
662     alignment.Add(RenderableActor::New());
663     Stage::GetCurrent().Add(alignment);
664     application.Render();
665     application.SendNotification();
666
667     DALI_TEST_EQUALS(Alignment::ScaleNone, alignment.GetScaling(), TEST_LOCATION);
668     alignment.SetScaling(Alignment::ScaleToFitKeepAspect);
669     DALI_TEST_EQUALS(Alignment::ScaleToFitKeepAspect, alignment.GetScaling(), TEST_LOCATION);
670     application.Render();
671     application.SendNotification();
672
673     // For complete line coverage
674     alignment.SetAlignmentType(Alignment::HorizontalLeft);
675     application.Render();
676     application.SendNotification();
677     alignment.SetAlignmentType(Alignment::HorizontalRight);
678     application.Render();
679     application.SendNotification();
680     alignment.SetAlignmentType(Alignment::VerticalTop);
681     application.Render();
682     application.SendNotification();
683     alignment.SetAlignmentType(Alignment::VerticalBottom);
684     application.Render();
685     application.SendNotification();
686
687     Stage::GetCurrent().Remove(alignment);
688     application.Render();
689     application.SendNotification();
690   }
691
692   // ScaleToFillKeepAspect
693   {
694     Alignment alignment = Alignment::New();
695     alignment.Add(RenderableActor::New());
696     Stage::GetCurrent().Add(alignment);
697     application.Render();
698     application.SendNotification();
699
700     DALI_TEST_EQUALS(Alignment::ScaleNone, alignment.GetScaling(), TEST_LOCATION);
701     alignment.SetScaling(Alignment::ScaleToFillKeepAspect);
702     DALI_TEST_EQUALS(Alignment::ScaleToFillKeepAspect, alignment.GetScaling(), TEST_LOCATION);
703     application.Render();
704     application.SendNotification();
705
706     // For complete line coverage
707     alignment.SetAlignmentType(Alignment::HorizontalLeft);
708     application.Render();
709     application.SendNotification();
710     alignment.SetAlignmentType(Alignment::HorizontalRight);
711     application.Render();
712     application.SendNotification();
713     alignment.SetAlignmentType(Alignment::VerticalTop);
714     application.Render();
715     application.SendNotification();
716     alignment.SetAlignmentType(Alignment::VerticalBottom);
717     application.Render();
718     application.SendNotification();
719
720     Stage::GetCurrent().Remove(alignment);
721     application.Render();
722     application.SendNotification();
723   }
724
725   // ShrinkToFit
726   {
727     Alignment alignment = Alignment::New();
728     alignment.Add(RenderableActor::New());
729     Stage::GetCurrent().Add(alignment);
730     application.Render();
731     application.SendNotification();
732
733     DALI_TEST_EQUALS(Alignment::ScaleNone, alignment.GetScaling(), TEST_LOCATION);
734     alignment.SetScaling(Alignment::ShrinkToFit);
735     DALI_TEST_EQUALS(Alignment::ShrinkToFit, alignment.GetScaling(), TEST_LOCATION);
736     application.Render();
737     application.SendNotification();
738
739     // For complete line coverage
740     alignment.SetAlignmentType(Alignment::HorizontalLeft);
741     application.Render();
742     application.SendNotification();
743     alignment.SetAlignmentType(Alignment::HorizontalRight);
744     application.Render();
745     application.SendNotification();
746     alignment.SetAlignmentType(Alignment::VerticalTop);
747     application.Render();
748     application.SendNotification();
749     alignment.SetAlignmentType(Alignment::VerticalBottom);
750     application.Render();
751     application.SendNotification();
752
753     Stage::GetCurrent().Remove(alignment);
754     application.Render();
755     application.SendNotification();
756   }
757
758   // ShrinkToFitKeepAspect
759   {
760     Alignment alignment = Alignment::New();
761     alignment.Add(RenderableActor::New());
762     Stage::GetCurrent().Add(alignment);
763     application.Render();
764     application.SendNotification();
765
766     DALI_TEST_EQUALS(Alignment::ScaleNone, alignment.GetScaling(), TEST_LOCATION);
767     alignment.SetScaling(Alignment::ShrinkToFitKeepAspect);
768     DALI_TEST_EQUALS(Alignment::ShrinkToFitKeepAspect, alignment.GetScaling(), TEST_LOCATION);
769     application.Render();
770     application.SendNotification();
771
772     // For complete line coverage
773     alignment.SetAlignmentType(Alignment::HorizontalLeft);
774     application.Render();
775     application.SendNotification();
776     alignment.SetAlignmentType(Alignment::HorizontalRight);
777     application.Render();
778     application.SendNotification();
779     alignment.SetAlignmentType(Alignment::VerticalTop);
780     application.Render();
781     application.SendNotification();
782     alignment.SetAlignmentType(Alignment::VerticalBottom);
783     application.Render();
784     application.SendNotification();
785
786     Stage::GetCurrent().Remove(alignment);
787     application.Render();
788     application.SendNotification();
789   }
790   END_TEST;
791 }
792
793 int UtcDaliAlignmentGetScaling(void)
794 {
795   ToolkitTestApplication application;
796
797   // ScaleToFill
798   {
799     Alignment alignment = Alignment::New();
800     DALI_TEST_CHECK(alignment.GetScaling() == Alignment::ScaleNone);
801
802     alignment.SetScaling(Alignment::ScaleToFill);
803     DALI_TEST_CHECK(alignment.GetScaling() == Alignment::ScaleToFill);
804   }
805
806   // ScaleToFitKeepAspect
807   {
808     Alignment alignment = Alignment::New();
809     DALI_TEST_CHECK(alignment.GetScaling() == Alignment::ScaleNone);
810
811     alignment.SetScaling(Alignment::ScaleToFitKeepAspect);
812     DALI_TEST_CHECK(alignment.GetScaling() == Alignment::ScaleToFitKeepAspect);
813   }
814
815   // ScaleToFillKeepAspect
816   {
817     Alignment alignment = Alignment::New();
818     DALI_TEST_CHECK(alignment.GetScaling() == Alignment::ScaleNone);
819
820     alignment.SetScaling(Alignment::ScaleToFillKeepAspect);
821     DALI_TEST_CHECK(alignment.GetScaling() == Alignment::ScaleToFillKeepAspect);
822   }
823
824   // ShrinkToFit
825   {
826     Alignment alignment = Alignment::New();
827     DALI_TEST_CHECK(alignment.GetScaling() == Alignment::ScaleNone);
828
829     alignment.SetScaling(Alignment::ShrinkToFit);
830     DALI_TEST_CHECK(alignment.GetScaling() == Alignment::ShrinkToFit);
831   }
832
833   // ShrinkToFitKeepAspect
834   {
835     Alignment alignment = Alignment::New();
836     DALI_TEST_CHECK(alignment.GetScaling() == Alignment::ScaleNone);
837
838     alignment.SetScaling(Alignment::ShrinkToFitKeepAspect);
839     DALI_TEST_CHECK(alignment.GetScaling() == Alignment::ShrinkToFitKeepAspect);
840   }
841
842   END_TEST;
843 }
844
845 int UtcDaliAlignmentSetPaddingPositive(void)
846 {
847   ToolkitTestApplication application;
848
849   Alignment alignment = Alignment::New();
850
851   Alignment::Padding padding(1.0f, 1.5f, 2.f, 0.5f);
852   DALI_TEST_CHECK( fabs( padding.left - alignment.GetPadding().left ) > GetRangedEpsilon( padding.left, alignment.GetPadding().left ) );
853   DALI_TEST_CHECK( fabs( padding.right - alignment.GetPadding().right ) > GetRangedEpsilon( padding.right, alignment.GetPadding().right ) );
854   DALI_TEST_CHECK( fabs( padding.top - alignment.GetPadding().top ) > GetRangedEpsilon( padding.top, alignment.GetPadding().top ) );
855   DALI_TEST_CHECK( fabs( padding.bottom - alignment.GetPadding().bottom ) > GetRangedEpsilon( padding.bottom, alignment.GetPadding().bottom ) );
856
857   alignment.SetPadding(padding);
858   DALI_TEST_CHECK( fabs( padding.left - alignment.GetPadding().left ) < GetRangedEpsilon( padding.left, alignment.GetPadding().left ) );
859   DALI_TEST_CHECK( fabs( padding.right - alignment.GetPadding().right ) < GetRangedEpsilon( padding.right, alignment.GetPadding().right ) );
860   DALI_TEST_CHECK( fabs( padding.top - alignment.GetPadding().top ) < GetRangedEpsilon( padding.top, alignment.GetPadding().top ) );
861   DALI_TEST_CHECK( fabs( padding.bottom - alignment.GetPadding().bottom ) < GetRangedEpsilon( padding.bottom, alignment.GetPadding().bottom ) );
862   END_TEST;
863 }
864
865 int UtcDaliAlignmentSetPaddingNegative(void)
866 {
867   ToolkitTestApplication application;
868
869   Alignment alignment = Alignment::New();
870
871   try
872   {
873     Alignment::Padding padding(-1.0f, 1.5f, 2.f, 0.f);
874     alignment.SetPadding(padding);
875     tet_result(TET_FAIL);
876   }
877   catch (DaliException& exception)
878   {
879     if (exception.mCondition == "( padding.left >= 0.f ) && ( padding.top >= 0.f ) && ( padding.right >= 0.f ) && ( padding.bottom >= 0.f )")
880     {
881       tet_result(TET_PASS);
882     }
883   }
884
885   try
886   {
887     Alignment::Padding padding(1.0f, 1.5f, -2.f, 0.f);
888     alignment.SetPadding(padding);
889     tet_result(TET_FAIL);
890   }
891   catch (DaliException& exception)
892   {
893     if (exception.mCondition == "( padding.left >= 0.f ) && ( padding.top >= 0.f ) && ( padding.right >= 0.f ) && ( padding.bottom >= 0.f )")
894     {
895       tet_result(TET_PASS);
896     }
897   }
898
899   try
900   {
901     Alignment::Padding padding(1.0f, 1.5f, 2.f, -1.f);
902     alignment.SetPadding(padding);
903     tet_result(TET_FAIL);
904   }
905   catch (DaliException& exception)
906   {
907     if (exception.mCondition == "( padding.left >= 0.f ) && ( padding.top >= 0.f ) && ( padding.right >= 0.f ) && ( padding.bottom >= 0.f )")
908     {
909       tet_result(TET_PASS);
910     }
911   }
912
913   try
914   {
915     Alignment::Padding padding(1.0f, -1.5f, 2.f, 0.f);
916     alignment.SetPadding(padding);
917     tet_result(TET_FAIL);
918   }
919   catch (DaliException& exception)
920   {
921     if (exception.mCondition == "( padding.left >= 0.f ) && ( padding.top >= 0.f ) && ( padding.right >= 0.f ) && ( padding.bottom >= 0.f )")
922     {
923       tet_result(TET_PASS);
924     }
925   }
926   END_TEST;
927 }
928
929 int UtcDaliAlignmentGetPadding(void)
930 {
931   ToolkitTestApplication application;
932
933   Alignment alignment = Alignment::New();
934   DALI_TEST_CHECK( fabs( alignment.GetPadding().left ) < GetRangedEpsilon( 0.f, alignment.GetPadding().left ) );
935   DALI_TEST_CHECK( fabs( alignment.GetPadding().right ) < GetRangedEpsilon( 0.f, alignment.GetPadding().right ) );
936   DALI_TEST_CHECK( fabs( alignment.GetPadding().top ) < GetRangedEpsilon( 0.f, alignment.GetPadding().top ) );
937   DALI_TEST_CHECK( fabs( alignment.GetPadding().bottom ) < GetRangedEpsilon( 0.f, alignment.GetPadding().bottom ) );
938
939   Alignment::Padding padding(1.0f, 1.5f, 2.f, 0.f);
940   alignment.SetPadding(padding);
941   DALI_TEST_CHECK( fabs( padding.left - alignment.GetPadding().left ) < GetRangedEpsilon( padding.left, alignment.GetPadding().left ) );
942   DALI_TEST_CHECK( fabs( padding.right - alignment.GetPadding().right ) < GetRangedEpsilon( padding.right, alignment.GetPadding().right ) );
943   DALI_TEST_CHECK( fabs( padding.top - alignment.GetPadding().top ) < GetRangedEpsilon( padding.top, alignment.GetPadding().top ) );
944   DALI_TEST_CHECK( fabs( padding.bottom - alignment.GetPadding().bottom ) < GetRangedEpsilon( padding.bottom, alignment.GetPadding().bottom ) );
945   END_TEST;
946 }
947
948 int UtcDaliAlignmentChildAddAndRemove(void)
949 {
950   ToolkitTestApplication application;
951
952   Alignment alignment = Alignment::New();
953   Stage::GetCurrent().Add(alignment);
954
955   application.Render();
956   application.SendNotification();
957
958   Actor actor = RenderableActor::New();
959   alignment.Add(actor);
960
961   DALI_TEST_EQUALS(alignment.GetChildCount(), 1u, TEST_LOCATION);
962
963   application.Render();
964   application.SendNotification();
965
966   alignment.Remove(actor);
967
968   DALI_TEST_EQUALS(alignment.GetChildCount(), 0u, TEST_LOCATION);
969
970   application.Render();
971   application.SendNotification();
972
973   Stage::GetCurrent().Remove(alignment);
974   END_TEST;
975 }
976
977 int UtcDaliAlignmentOnSizeSet(void)
978 {
979   ToolkitTestApplication application;
980
981   Alignment alignment = Alignment::New();
982   Stage::GetCurrent().Add(alignment);
983
984   application.Render();
985   application.SendNotification();
986
987   Vector3 size(100.0f, 200.0f, 0.0f);
988   alignment.SetSize(size);
989
990   application.Render();
991   application.SendNotification();
992   application.Render();
993   application.SendNotification();
994
995   DALI_TEST_EQUALS(size, alignment.GetImplementation().GetControlSize(), TEST_LOCATION);
996
997   Stage::GetCurrent().Remove(alignment);
998   END_TEST;
999 }
1000
1001 ///////////////////////////////////////////////////////////////////////////////
1002 static bool TouchEventCallback(Actor actor, const TouchEvent& event)
1003 {
1004   return false;
1005 }
1006
1007 ///////////////////////////////////////////////////////////////////////////////
1008
1009 int UtcDaliAlignmentOnTouchEvent(void)
1010 {
1011   ToolkitTestApplication application;
1012
1013   Alignment alignment = Alignment::New();
1014   alignment.SetSize(100.0f, 100.0f);
1015   alignment.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1016   Stage::GetCurrent().Add(alignment);
1017
1018   alignment.TouchedSignal().Connect(&TouchEventCallback);
1019
1020   application.Render();
1021   application.SendNotification();
1022   application.Render();
1023   application.SendNotification();
1024
1025   Integration::TouchEvent touchEvent(1);
1026   TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
1027   touchEvent.AddPoint(point);
1028   application.ProcessEvent(touchEvent);
1029
1030   tet_result(TET_PASS); // For line coverage, as long as there are no exceptions, we assume passed.
1031   END_TEST;
1032 }
1033
1034 int UtcDaliAlignmentOnKeyEvent(void)
1035 {
1036   ToolkitTestApplication application;
1037
1038   Alignment alignment = Alignment::New();
1039   Stage::GetCurrent().Add(alignment);
1040
1041   alignment.SetKeyInputFocus();
1042
1043   application.Render();
1044   application.SendNotification();
1045   application.Render();
1046   application.SendNotification();
1047
1048   Integration::KeyEvent keyEvent;
1049   application.ProcessEvent(keyEvent);
1050
1051   tet_result(TET_PASS); // For line coverage, as long as there are no exceptions, we assume passed.
1052   END_TEST;
1053 }
1054
1055 int UtcDaliAlignmentOnSizeAnimation(void)
1056 {
1057   ToolkitTestApplication application;
1058
1059   Alignment alignment = Alignment::New();
1060   Stage::GetCurrent().Add(alignment);
1061
1062   Animation animation = Animation::New(100.0f);
1063   animation.Resize(alignment, Vector3(100.0f, 150.0f, 200.0f));
1064   animation.Play();
1065
1066   application.Render();
1067   application.SendNotification();
1068   application.Render();
1069   application.SendNotification();
1070
1071   tet_result(TET_PASS); // For line coverage, as long as there are no exceptions, we assume passed.
1072   END_TEST;
1073 }
1074
1075 int UtcDaliAlignmentCopyAndAssignment(void)
1076 {
1077   ToolkitTestApplication application;
1078
1079   Alignment alignment = Alignment::New();
1080   Alignment emptyAlignment;
1081
1082   Alignment::Padding padding(100.0f, 150.0f, 200.f, 0.f);
1083   alignment.SetPadding(padding);
1084
1085   Alignment alignmentCopy(alignment);
1086   DALI_TEST_CHECK( fabs( padding.left - alignmentCopy.GetPadding().left ) < GetRangedEpsilon( padding.left, alignmentCopy.GetPadding().left ) );
1087   DALI_TEST_CHECK( fabs( padding.right - alignmentCopy.GetPadding().right ) < GetRangedEpsilon( padding.right, alignmentCopy.GetPadding().right ) );
1088   DALI_TEST_CHECK( fabs( padding.top - alignmentCopy.GetPadding().top ) < GetRangedEpsilon( padding.top, alignmentCopy.GetPadding().top ) );
1089   DALI_TEST_CHECK( fabs( padding.bottom - alignmentCopy.GetPadding().bottom ) < GetRangedEpsilon( padding.bottom, alignmentCopy.GetPadding().bottom ) );
1090
1091   Alignment alignmentEmptyCopy(emptyAlignment);
1092   DALI_TEST_CHECK(emptyAlignment == alignmentEmptyCopy);
1093
1094   Alignment alignmentEquals;
1095   alignmentEquals = alignment;
1096   DALI_TEST_CHECK( fabs( padding.left - alignmentEquals.GetPadding().left ) < GetRangedEpsilon( padding.left, alignmentEquals.GetPadding().left ) );
1097   DALI_TEST_CHECK( fabs( padding.right - alignmentEquals.GetPadding().right ) < GetRangedEpsilon( padding.right, alignmentEquals.GetPadding().right ) );
1098   DALI_TEST_CHECK( fabs( padding.top - alignmentEquals.GetPadding().top ) < GetRangedEpsilon( padding.top, alignmentEquals.GetPadding().top ) );
1099   DALI_TEST_CHECK( fabs( padding.bottom - alignmentEquals.GetPadding().bottom ) < GetRangedEpsilon( padding.bottom, alignmentEquals.GetPadding().bottom ) );
1100
1101   Alignment alignmentEmptyEquals;
1102   alignmentEmptyEquals = emptyAlignment;
1103   DALI_TEST_CHECK(emptyAlignment == alignmentEmptyEquals);
1104
1105   // Self assignment
1106   alignment = alignment;
1107   DALI_TEST_CHECK(alignment == alignmentCopy);
1108   END_TEST;
1109 }