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