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