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