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