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