[dali_2.3.24] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Layer.cpp
1 /*
2  * Copyright (c) 2023 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 <dali-test-suite-utils.h>
19 #include <dali/public-api/dali-core.h>
20 #include <stdlib.h>
21
22 #include <iostream>
23
24 using namespace Dali;
25
26 void layer_test_startup(void)
27 {
28   test_return_value = TET_UNDEF;
29 }
30
31 void layer_test_cleanup(void)
32 {
33   test_return_value = TET_PASS;
34 }
35
36 int UtcDaliLayerNew(void)
37 {
38   TestApplication application;
39   Layer           layer = Layer::New();
40
41   DALI_TEST_CHECK(layer);
42   END_TEST;
43 }
44
45 int UtcDaliLayerDownCast(void)
46 {
47   TestApplication application;
48   tet_infoline("Testing Dali::Layer::DownCast()");
49
50   Layer actor1  = Layer::New();
51   Actor anActor = Actor::New();
52   anActor.Add(actor1);
53
54   Actor child = anActor.GetChildAt(0);
55   Layer layer = DownCast<Layer>(child);
56
57   DALI_TEST_CHECK(layer);
58   END_TEST;
59 }
60
61 int UtcDaliLayerDownCast2(void)
62 {
63   TestApplication application;
64   tet_infoline("Testing Dali::Layer::DownCast()");
65
66   Actor actor1  = Actor::New();
67   Actor anActor = Actor::New();
68   anActor.Add(actor1);
69
70   Actor child = anActor.GetChildAt(0);
71   Layer layer = DownCast<Layer>(child);
72   DALI_TEST_CHECK(!layer);
73
74   Actor unInitialzedActor;
75   layer = Layer::DownCast(unInitialzedActor);
76   DALI_TEST_CHECK(!layer);
77   END_TEST;
78 }
79
80 int UtcDaliLayerMoveConstructor(void)
81 {
82   TestApplication application;
83   Layer           layer = Layer::New();
84   DALI_TEST_CHECK(layer);
85   DALI_TEST_EQUALS(1, layer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
86   DALI_TEST_EQUALS(0, layer.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
87
88   application.GetScene().Add(layer);
89   DALI_TEST_EQUALS(2, layer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
90   DALI_TEST_EQUALS(1, layer.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
91
92   Layer move = std::move(layer);
93   DALI_TEST_CHECK(move);
94   DALI_TEST_EQUALS(2, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
95   DALI_TEST_EQUALS(1, move.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
96   DALI_TEST_CHECK(!layer);
97
98   END_TEST;
99 }
100
101 int UtcDaliLayerMoveAssignment(void)
102 {
103   TestApplication application;
104   Layer           layer = Layer::New();
105   DALI_TEST_CHECK(layer);
106   DALI_TEST_EQUALS(1, layer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
107   DALI_TEST_EQUALS(0, layer.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
108
109   application.GetScene().Add(layer);
110   DALI_TEST_EQUALS(2, layer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
111   DALI_TEST_EQUALS(1, layer.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
112
113   Layer move;
114   move = std::move(layer);
115   DALI_TEST_CHECK(move);
116   DALI_TEST_EQUALS(2, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
117   DALI_TEST_EQUALS(1, move.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
118   DALI_TEST_CHECK(!layer);
119
120   END_TEST;
121 }
122
123 int UtcDaliLayerGetDepth(void)
124 {
125   tet_infoline("Testing Dali::Layer::GetDepth()");
126   TestApplication application;
127   Layer           layer1 = Layer::New();
128   Layer           layer2 = Layer::New();
129
130   // layers are not on scene
131   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
132   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
133
134   // root depth is 0
135   Layer root = application.GetScene().GetLayer(0);
136   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
137
138   application.GetScene().Add(layer1);
139   application.GetScene().Add(layer2);
140
141   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
142   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
143   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
144   END_TEST;
145 }
146
147 int UtcDaliLayerRaise1(void)
148 {
149   tet_infoline("Testing Dali::Layer::Raise()");
150   TestApplication application;
151   Layer           layer1 = Layer::New();
152   Layer           layer2 = Layer::New();
153
154   application.GetScene().Add(layer1);
155   application.GetScene().Add(layer2);
156   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
157
158   layer1.Raise();
159   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
160
161   // get root
162   Layer root = application.GetScene().GetLayer(0);
163   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
164   root.Raise();
165   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
166   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
167   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
168   END_TEST;
169 }
170
171 int UtcDaliLayerRaise2(void)
172 {
173   tet_infoline("Testing Dali::Layer raise Action");
174   TestApplication application;
175   Layer           layer1 = Layer::New();
176   Layer           layer2 = Layer::New();
177
178   application.GetScene().Add(layer1);
179   application.GetScene().Add(layer2);
180   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
181
182   layer1.Raise();
183   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
184
185   // get root
186   Layer root = application.GetScene().GetLayer(0);
187   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
188
189   GetImplementation(root).DoAction("raise", Property::Map());
190
191   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
192   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
193   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
194   END_TEST;
195 }
196
197 int UtcDaliLayerLower1(void)
198 {
199   tet_infoline("Testing Dali::Layer::Lower()");
200   TestApplication application;
201   Layer           layer1 = Layer::New();
202   Layer           layer2 = Layer::New();
203
204   application.GetScene().Add(layer1);
205   application.GetScene().Add(layer2);
206   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
207
208   layer2.Lower();
209   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
210
211   // get root
212   Layer root = application.GetScene().GetLayer(0);
213   root.Lower();
214   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
215   layer2.Lower();
216   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
217   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
218   END_TEST;
219 }
220
221 int UtcDaliLayerLower2(void)
222 {
223   tet_infoline("Testing Dali::Layer lower Action");
224   TestApplication application;
225   Layer           layer1 = Layer::New();
226   Layer           layer2 = Layer::New();
227
228   application.GetScene().Add(layer1);
229   application.GetScene().Add(layer2);
230   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
231
232   layer2.Lower();
233   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
234
235   // get root
236   Layer root = application.GetScene().GetLayer(0);
237   GetImplementation(root).DoAction("lower", Property::Map());
238   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
239
240   GetImplementation(layer2).DoAction("lower", Property::Map());
241   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
242   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
243   END_TEST;
244 }
245
246 int UtcDaliLayerRaiseToTop1(void)
247 {
248   tet_infoline("Testing Dali::Layer::RaiseToTop()");
249   TestApplication application;
250   Layer           layer1 = Layer::New();
251   Layer           layer2 = Layer::New();
252   Layer           layer3 = Layer::New();
253
254   application.GetScene().Add(layer1);
255   application.GetScene().Add(layer2);
256   application.GetScene().Add(layer3);
257   Layer root = application.GetScene().GetLayer(0);
258
259   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
260   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
261   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
262   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
263
264   layer1.RaiseToTop();
265   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
266
267   root.RaiseToTop();
268   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
269   END_TEST;
270 }
271
272 int UtcDaliLayerRaiseToTop2(void)
273 {
274   tet_infoline("Testing Dali::Layer raiseToTop Action");
275   TestApplication application;
276   Layer           layer1 = Layer::New();
277   Layer           layer2 = Layer::New();
278   Layer           layer3 = Layer::New();
279
280   application.GetScene().Add(layer1);
281   application.GetScene().Add(layer2);
282   application.GetScene().Add(layer3);
283   Layer root = application.GetScene().GetLayer(0);
284
285   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
286   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
287   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
288   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
289
290   GetImplementation(layer1).DoAction("raiseToTop", Property::Map());
291   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
292
293   GetImplementation(root).DoAction("raiseToTop", Property::Map());
294   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
295   END_TEST;
296 }
297
298 int UtcDaliLayerLowerToBottom1(void)
299 {
300   tet_infoline("Testing Dali::Layer::LowerToBottom()");
301   TestApplication application;
302   Layer           layer1 = Layer::New();
303   Layer           layer2 = Layer::New();
304   Layer           layer3 = Layer::New();
305
306   application.GetScene().Add(layer1);
307   application.GetScene().Add(layer2);
308   application.GetScene().Add(layer3);
309
310   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
311   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
312   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
313
314   layer3.LowerToBottom();
315   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
316   END_TEST;
317 }
318
319 int UtcDaliLayerLowerToBottom2(void)
320 {
321   tet_infoline("Testing Dali::Layer lowerToBottom Action");
322   TestApplication application;
323   Layer           layer1 = Layer::New();
324   Layer           layer2 = Layer::New();
325   Layer           layer3 = Layer::New();
326
327   application.GetScene().Add(layer1);
328   application.GetScene().Add(layer2);
329   application.GetScene().Add(layer3);
330
331   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
332   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
333   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
334
335   GetImplementation(layer3).DoAction("lowerToBottom", Property::Map());
336   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
337   END_TEST;
338 }
339
340 int UtcDaliLayerSetClipping(void)
341 {
342   tet_infoline("Testing Dali::Layer::SetClipping()");
343   TestApplication application;
344
345   Layer layer = Layer::New();
346   DALI_TEST_CHECK(!layer.GetProperty<bool>(Layer::Property::CLIPPING_ENABLE));
347
348   layer.SetProperty(Layer::Property::CLIPPING_ENABLE, true);
349   DALI_TEST_CHECK(layer.GetProperty<bool>(Layer::Property::CLIPPING_ENABLE));
350   END_TEST;
351 }
352
353 int UtcDaliLayerIsClipping(void)
354 {
355   tet_infoline("Testing Dali::Layer::IsClipping()");
356   TestApplication application;
357
358   Layer layer = Layer::New();
359   DALI_TEST_CHECK(!layer.GetProperty<bool>(Layer::Property::CLIPPING_ENABLE));
360   END_TEST;
361 }
362
363 int UtcDaliLayerSetClippingBox(void)
364 {
365   tet_infoline("Testing Dali::Layer::SetClippingBox()");
366   TestApplication application;
367
368   ClippingBox testBox(5, 6, 77, 83);
369
370   Layer layer = Layer::New();
371   DALI_TEST_CHECK(layer.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) != testBox);
372   layer.SetProperty(Layer::Property::CLIPPING_BOX, testBox);
373   DALI_TEST_CHECK(layer.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) == testBox);
374   END_TEST;
375 }
376
377 int UtcDaliLayerGetClippingBox(void)
378 {
379   tet_infoline("Testing Dali::Layer::GetClippingBox()");
380   TestApplication application;
381
382   Layer layer = Layer::New();
383   DALI_TEST_CHECK(layer.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) == ClippingBox(0, 0, 0, 0));
384   END_TEST;
385 }
386
387 static int gTestSortFunctionCalled;
388
389 static float TestSortFunction(const Vector3& /*position*/)
390 {
391   ++gTestSortFunctionCalled;
392   return 0.0f;
393 }
394
395 int UtcDaliLayerSetSortFunction(void)
396 {
397   tet_infoline("Testing Dali::Layer::SetSortFunction()");
398   TestApplication application;
399
400   // create two transparent actors so there is something to sort
401   Actor actor  = CreateRenderableActor();
402   Actor actor2 = CreateRenderableActor();
403   actor.SetProperty(Actor::Property::SIZE, Vector2(1, 1));
404   actor.SetProperty(Actor::Property::COLOR, Vector4(1, 1, 1, 0.5f)); // 50% transparent
405   actor2.SetProperty(Actor::Property::SIZE, Vector2(1, 1));
406   actor2.SetProperty(Actor::Property::COLOR, Vector4(1, 1, 1, 0.5f)); // 50% transparent
407
408   // add to scene
409   application.GetScene().Add(actor);
410   application.GetScene().Add(actor2);
411
412   Layer root              = application.GetScene().GetLayer(0);
413   gTestSortFunctionCalled = 0;
414   root.SetSortFunction(TestSortFunction);
415
416   // flush the queue and render once
417   application.SendNotification();
418   application.Render();
419
420   DALI_TEST_CHECK(gTestSortFunctionCalled > 0);
421   END_TEST;
422 }
423
424 int UtcDaliLayerRaiseAbove(void)
425 {
426   tet_infoline("Testing Dali::Layer::RaiseAbove()");
427   TestApplication application;
428   Layer           layer = Layer::New();
429   // try to raise above root layer
430   Layer root = application.GetScene().GetLayer(0);
431   layer.RaiseAbove(root);
432   // layer depth is zero as its not on scene
433   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
434   // add to scene
435   application.GetScene().Add(layer);
436   layer.RaiseAbove(root);
437   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
438   root.RaiseAbove(layer);
439   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
440   layer.RaiseAbove(layer);
441   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
442
443   // make another layer on the scene
444   Layer layer2 = Layer::New();
445   application.GetScene().Add(layer2);
446   layer.RaiseAbove(layer2);
447   DALI_TEST_GREATER(layer.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
448   layer2.RaiseAbove(layer);
449   DALI_TEST_GREATER(layer2.GetProperty<int>(Layer::Property::DEPTH), layer.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
450   root.RaiseAbove(layer2);
451   DALI_TEST_GREATER(root.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
452   END_TEST;
453 }
454
455 int UtcDaliLayerRaiseBelow(void)
456 {
457   tet_infoline("Testing Dali::Layer::RaiseBelow()");
458   TestApplication application;
459   Layer           layer = Layer::New();
460   // try to lower below root layer
461   Layer root = application.GetScene().GetLayer(0);
462   layer.LowerBelow(root);
463   // layer depth is zero as its not on scene
464   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
465   // add to scene
466   application.GetScene().Add(layer);
467   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
468   layer.LowerBelow(root);
469   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
470   root.LowerBelow(layer);
471   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
472   layer.LowerBelow(layer);
473   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
474
475   // make another layer on the scene
476   Layer layer2 = Layer::New();
477   application.GetScene().Add(layer2);
478   layer.LowerBelow(layer2);
479   DALI_TEST_GREATER(layer2.GetProperty<int>(Layer::Property::DEPTH), layer.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
480   layer2.LowerBelow(layer);
481   DALI_TEST_GREATER(layer.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
482   root.LowerBelow(layer2);
483   DALI_TEST_GREATER(layer2.GetProperty<int>(Layer::Property::DEPTH), root.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
484   END_TEST;
485 }
486
487 int UtcDaliLayerMoveAbove(void)
488 {
489   tet_infoline("Testing Dali::Layer::MoveAbove()");
490   TestApplication application;
491   Layer           layer = Layer::New();
492   // try to raise above root layer
493   Layer root = application.GetScene().GetLayer(0);
494   layer.MoveAbove(root);
495   // layer depth is zero as its not on scene
496   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
497   root.MoveAbove(layer);
498   // root depth is zero as layer is not on scene
499   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
500   // add to scene
501   application.GetScene().Add(layer);
502   layer.MoveAbove(root);
503   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
504   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
505   root.MoveAbove(layer);
506   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
507   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
508
509   // make another layer on the scene
510   Layer layer2 = Layer::New();
511   application.GetScene().Add(layer2);
512   layer.MoveAbove(layer2);
513   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH) + 1u, TEST_LOCATION);
514   layer2.MoveAbove(root);
515   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), root.GetProperty<int>(Layer::Property::DEPTH) + 1u, TEST_LOCATION);
516   root.MoveAbove(layer);
517   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), layer.GetProperty<int>(Layer::Property::DEPTH) + 1u, TEST_LOCATION);
518
519   Layer layer3 = Layer::New();
520   application.GetScene().Add(layer3);
521   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
522   root.MoveAbove(layer3);
523   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
524   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
525   DALI_TEST_EQUALS(application.GetScene().GetLayer(0).GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
526   layer3.MoveAbove(application.GetScene().GetLayer(0));
527   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
528   END_TEST;
529 }
530
531 int UtcDaliLayerMoveBelow(void)
532 {
533   tet_infoline("Testing Dali::Layer::MoveBelow()");
534   TestApplication application;
535   Layer           layer = Layer::New();
536   // try to raise above root layer
537   Layer root = application.GetScene().GetLayer(0);
538   layer.MoveBelow(root);
539   // layer depth is zero as its not on scene
540   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
541   root.MoveBelow(layer);
542   // root depth is zero as layer is not on scene
543   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
544   // add to scene
545   application.GetScene().Add(layer);
546   layer.MoveBelow(root);
547   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
548   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
549   root.MoveBelow(layer);
550   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
551   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
552
553   // make another layer on the scene
554   Layer layer2 = Layer::New();
555   application.GetScene().Add(layer2);
556   layer.MoveBelow(layer2);
557   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH) - 1u, TEST_LOCATION);
558   layer2.MoveBelow(root);
559   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), root.GetProperty<int>(Layer::Property::DEPTH) - 1u, TEST_LOCATION);
560   root.MoveBelow(layer);
561   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), layer.GetProperty<int>(Layer::Property::DEPTH) - 1u, TEST_LOCATION);
562
563   Layer layer3 = Layer::New();
564   application.GetScene().Add(layer3);
565   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
566   root.MoveBelow(layer3);
567   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
568   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
569   END_TEST;
570 }
571
572 int UtcDaliLayerDefaultProperties(void)
573 {
574   TestApplication application;
575   tet_infoline("Testing Dali::Layer DefaultProperties");
576
577   Layer actor = Layer::New();
578
579   std::vector<Property::Index> indices;
580   indices.push_back(Layer::Property::CLIPPING_ENABLE);
581   indices.push_back(Layer::Property::CLIPPING_BOX);
582   indices.push_back(Layer::Property::BEHAVIOR);
583   indices.push_back(Layer::Property::DEPTH);
584   indices.push_back(Layer::Property::DEPTH_TEST);
585   indices.push_back(Layer::Property::CONSUMES_TOUCH);
586   indices.push_back(Layer::Property::CONSUMES_HOVER);
587
588   DALI_TEST_CHECK(actor.GetPropertyCount() == (Actor::New().GetPropertyCount() + indices.size()));
589
590   for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
591   {
592     DALI_TEST_CHECK(*iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)));
593     DALI_TEST_CHECK(*iter == Layer::Property::DEPTH ? !actor.IsPropertyWritable(*iter) : actor.IsPropertyWritable(*iter));
594     DALI_TEST_CHECK(!actor.IsPropertyAnimatable(*iter));
595     DALI_TEST_CHECK(actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter)); // just checking call succeeds
596   }
597
598   // set/get one of them
599   actor.SetProperty(Layer::Property::CLIPPING_BOX, ClippingBox(0, 0, 0, 0));
600
601   ClippingBox testBox(10, 20, 30, 40);
602   DALI_TEST_CHECK(actor.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) != testBox);
603
604   actor.SetProperty(Layer::Property::CLIPPING_BOX, Property::Value(Rect<int>(testBox)));
605
606   DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(Layer::Property::CLIPPING_BOX));
607
608   Property::Value v = actor.GetProperty(Layer::Property::CLIPPING_BOX);
609   DALI_TEST_CHECK(v.Get<Rect<int> >() == testBox);
610
611   v = actor.GetCurrentProperty(Layer::Property::CLIPPING_BOX);
612   DALI_TEST_CHECK(v.Get<Rect<int> >() == testBox);
613
614   // set the same boundaries, but through a clipping box object
615   actor.SetProperty(Layer::Property::CLIPPING_BOX, testBox);
616   DALI_TEST_CHECK(actor.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) == testBox);
617
618   actor.SetProperty(Layer::Property::BEHAVIOR, Property::Value(Layer::LAYER_UI));
619   DALI_TEST_CHECK(Property::INTEGER == actor.GetPropertyType(Layer::Property::BEHAVIOR));
620
621   Property::Value behavior = actor.GetProperty(Layer::Property::BEHAVIOR);
622   DALI_TEST_EQUALS(behavior.Get<Dali::Layer::Behavior>(), Layer::LAYER_UI, TEST_LOCATION);
623
624   behavior = actor.GetCurrentProperty(Layer::Property::BEHAVIOR);
625   DALI_TEST_EQUALS(behavior.Get<Dali::Layer::Behavior>(), Layer::LAYER_UI, TEST_LOCATION);
626
627   END_TEST;
628 }
629
630 int UtcDaliLayerSetDepthTestDisabled(void)
631 {
632   TestApplication application;
633   tet_infoline("Testing Dali::Layer::SetDepthTestDisabled() ");
634
635   Layer actor = Layer::New();
636   // Note that Layer::Property::DEPTH_TEST does not depend on layer behavior,
637   // as 2D layers can still have depth tests performed on a per-renderer basis.
638   // Check default.
639   DALI_TEST_CHECK(!actor.GetProperty<bool>(Layer::Property::DEPTH_TEST));
640
641   // Check Set / Unset.
642   actor.SetProperty(Layer::Property::DEPTH_TEST, true);
643   DALI_TEST_CHECK(actor.GetProperty<bool>(Layer::Property::DEPTH_TEST));
644   actor.SetProperty(Layer::Property::DEPTH_TEST, false);
645   DALI_TEST_CHECK(!actor.GetProperty<bool>(Layer::Property::DEPTH_TEST));
646
647   END_TEST;
648 }
649
650 int UtcDaliLayerCreateDestroy(void)
651 {
652   tet_infoline("Testing Dali::Layer::CreateDestroy() ");
653   Layer* layer = new Layer;
654   DALI_TEST_CHECK(layer);
655   delete layer;
656   END_TEST;
657 }
658
659 int UtcDaliLayerPropertyIndices(void)
660 {
661   TestApplication application;
662   Actor           basicActor = Actor::New();
663   Layer           layer      = Layer::New();
664
665   Property::IndexContainer indices;
666   layer.GetPropertyIndices(indices);
667   DALI_TEST_CHECK(indices.Size() > basicActor.GetPropertyCount());
668   DALI_TEST_EQUALS(indices.Size(), layer.GetPropertyCount(), TEST_LOCATION);
669   END_TEST;
670 }
671
672 int UtcDaliLayerTouchConsumed(void)
673 {
674   TestApplication application;
675   Layer           layer = Layer::New();
676
677   DALI_TEST_EQUALS(layer.GetProperty<bool>(Layer::Property::CONSUMES_TOUCH), false, TEST_LOCATION);
678   layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
679   DALI_TEST_EQUALS(layer.GetProperty<bool>(Layer::Property::CONSUMES_TOUCH), true, TEST_LOCATION);
680   END_TEST;
681 }
682
683 int UtcDaliLayerHoverConsumed(void)
684 {
685   TestApplication application;
686   Layer           layer = Layer::New();
687
688   DALI_TEST_EQUALS(layer.GetProperty<bool>(Layer::Property::CONSUMES_HOVER), false, TEST_LOCATION);
689   layer.SetProperty(Layer::Property::CONSUMES_HOVER, true);
690   DALI_TEST_EQUALS(layer.GetProperty<bool>(Layer::Property::CONSUMES_HOVER), true, TEST_LOCATION);
691   END_TEST;
692 }
693
694 int UtcDaliLayerClippingGLCalls(void)
695 {
696   TestApplication                         application;
697   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
698   Integration::Scene                      scene(application.GetScene());
699
700   ClippingBox testBox(5, 6, 77, 83);
701   Layer       layer = application.GetScene().GetRootLayer();
702   layer.SetProperty(Layer::Property::CLIPPING_ENABLE, true);
703   layer.SetProperty(Layer::Property::CLIPPING_BOX, testBox);
704
705   // Add at least one renderable actor so the GL calls are actually made
706   Texture img   = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
707   Actor   actor = CreateRenderableActor(img);
708   scene.Add(actor);
709
710   // flush the queue and render once
711   application.SendNotification();
712   application.Render();
713
714   DALI_TEST_EQUALS(testBox.x, glScissorParams.x, TEST_LOCATION);
715   DALI_TEST_EQUALS(testBox.y, (int)(scene.GetSize().height - glScissorParams.y - testBox.height), TEST_LOCATION); // GL Coordinates are from bottom left
716   DALI_TEST_EQUALS(testBox.width, glScissorParams.width, TEST_LOCATION);
717   DALI_TEST_EQUALS(testBox.height, glScissorParams.height, TEST_LOCATION);
718   END_TEST;
719 }
720
721 int UtcDaliLayerBehaviour(void)
722 {
723   TestApplication application;
724   Layer           layer = Layer::New();
725
726   DALI_TEST_EQUALS(layer.GetProperty<Layer::Behavior>(Layer::Property::BEHAVIOR), Dali::Layer::LAYER_UI, TEST_LOCATION);
727   layer.SetProperty(Layer::Property::BEHAVIOR, Dali::Layer::LAYER_3D);
728   DALI_TEST_EQUALS(layer.GetProperty<Layer::Behavior>(Layer::Property::BEHAVIOR), Dali::Layer::LAYER_3D, TEST_LOCATION);
729   END_TEST;
730 }
731
732 Actor CreateActor(bool withAlpha)
733 {
734   Texture texture = CreateTexture(TextureType::TEXTURE_2D, withAlpha ? Pixel::Format::RGBA8888 : Pixel::Format::RGB888, 1u, 1u);
735
736   Actor actor = CreateRenderableActor(texture);
737   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
738   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
739
740   return actor;
741 }
742
743 int UtcDaliLayer3DSort(void)
744 {
745   tet_infoline("Testing LAYER_3D sort coverage test");
746   TestApplication    application;
747   TestGlAbstraction& glAbstraction       = application.GetGlAbstraction();
748   TraceCallStack&    enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
749
750   application.GetScene().GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
751
752   // Create an actor.
753   Actor actor = CreateActor(false);
754   application.GetScene().Add(actor);
755
756   // Create child actors.
757   Actor child1 = CreateActor(true);
758   actor.Add(child1);
759   Actor child2 = CreateActor(false);
760   child1.Add(child2);
761
762   enabledDisableTrace.Reset();
763   enabledDisableTrace.Enable(true);
764   application.SendNotification();
765   application.Render();
766   enabledDisableTrace.Enable(false);
767
768   std::ostringstream depth;
769   depth << std::hex << GL_DEPTH_TEST;
770   DALI_TEST_CHECK(enabledDisableTrace.FindMethodAndParams("Enable", depth.str()));
771
772   END_TEST;
773 }
774
775 int UtcDaliLayerLowerBelowNegative(void)
776 {
777   TestApplication application;
778   Dali::Layer     instance;
779   try
780   {
781     Dali::Layer arg1;
782     instance.LowerBelow(arg1);
783     DALI_TEST_CHECK(false); // Should not get here
784   }
785   catch(...)
786   {
787     DALI_TEST_CHECK(true); // We expect an assert
788   }
789   END_TEST;
790 }
791
792 int UtcDaliLayerRaiseAboveNegative(void)
793 {
794   TestApplication application;
795   Dali::Layer     instance;
796   try
797   {
798     Dali::Layer arg1;
799     instance.RaiseAbove(arg1);
800     DALI_TEST_CHECK(false); // Should not get here
801   }
802   catch(...)
803   {
804     DALI_TEST_CHECK(true); // We expect an assert
805   }
806   END_TEST;
807 }
808
809 int UtcDaliLayerRaiseToTopNegative(void)
810 {
811   TestApplication application;
812   Dali::Layer     instance;
813   try
814   {
815     instance.RaiseToTop();
816     DALI_TEST_CHECK(false); // Should not get here
817   }
818   catch(...)
819   {
820     DALI_TEST_CHECK(true); // We expect an assert
821   }
822   END_TEST;
823 }
824
825 int UtcDaliLayerLowerToBottomNegative(void)
826 {
827   TestApplication application;
828   Dali::Layer     instance;
829   try
830   {
831     instance.LowerToBottom();
832     DALI_TEST_CHECK(false); // Should not get here
833   }
834   catch(...)
835   {
836     DALI_TEST_CHECK(true); // We expect an assert
837   }
838   END_TEST;
839 }
840
841 int UtcDaliLayerSetSortFunctionNegative(void)
842 {
843   TestApplication application;
844   Dali::Layer     instance;
845   try
846   {
847     Layer::SortFunctionType function = nullptr;
848     instance.SetSortFunction(function);
849     DALI_TEST_CHECK(false); // Should not get here
850   }
851   catch(...)
852   {
853     DALI_TEST_CHECK(true); // We expect an assert
854   }
855   END_TEST;
856 }
857
858 int UtcDaliLayerLowerNegative(void)
859 {
860   TestApplication application;
861   Dali::Layer     instance;
862   try
863   {
864     instance.Lower();
865     DALI_TEST_CHECK(false); // Should not get here
866   }
867   catch(...)
868   {
869     DALI_TEST_CHECK(true); // We expect an assert
870   }
871   END_TEST;
872 }
873
874 int UtcDaliLayerRaiseNegative(void)
875 {
876   TestApplication application;
877   Dali::Layer     instance;
878   try
879   {
880     instance.Raise();
881     DALI_TEST_CHECK(false); // Should not get here
882   }
883   catch(...)
884   {
885     DALI_TEST_CHECK(true); // We expect an assert
886   }
887   END_TEST;
888 }
889
890 int UtcDaliLayerMoveAboveNegative(void)
891 {
892   TestApplication application;
893   Dali::Layer     instance;
894   try
895   {
896     Dali::Layer arg1;
897     instance.MoveAbove(arg1);
898     DALI_TEST_CHECK(false); // Should not get here
899   }
900   catch(...)
901   {
902     DALI_TEST_CHECK(true); // We expect an assert
903   }
904   END_TEST;
905 }
906
907 int UtcDaliLayerMoveBelowNegative(void)
908 {
909   TestApplication application;
910   Dali::Layer     instance;
911   try
912   {
913     Dali::Layer arg1;
914     instance.MoveBelow(arg1);
915     DALI_TEST_CHECK(false); // Should not get here
916   }
917   catch(...)
918   {
919     DALI_TEST_CHECK(true); // We expect an assert
920   }
921   END_TEST;
922 }