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