Merge "Clean up the code to build successfully on macOS" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Layer.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <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
198 int UtcDaliLayerLower1(void)
199 {
200   tet_infoline("Testing Dali::Layer::Lower()");
201   TestApplication application;
202   Layer           layer1 = Layer::New();
203   Layer           layer2 = Layer::New();
204
205   application.GetScene().Add(layer1);
206   application.GetScene().Add(layer2);
207   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
208
209   layer2.Lower();
210   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
211
212   // get root
213   Layer root = application.GetScene().GetLayer(0);
214   root.Lower();
215   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
216   layer2.Lower();
217   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
218   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
219   END_TEST;
220 }
221
222
223 int UtcDaliLayerLower2(void)
224 {
225   tet_infoline("Testing Dali::Layer lower Action");
226   TestApplication application;
227   Layer           layer1 = Layer::New();
228   Layer           layer2 = Layer::New();
229
230   application.GetScene().Add(layer1);
231   application.GetScene().Add(layer2);
232   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
233
234   layer2.Lower();
235   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
236
237   // get root
238   Layer root = application.GetScene().GetLayer(0);
239   GetImplementation(root).DoAction("lower", Property::Map());
240   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
241
242   GetImplementation(layer2).DoAction("lower", Property::Map());
243   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
244   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
245   END_TEST;
246 }
247
248 int UtcDaliLayerRaiseToTop1(void)
249 {
250   tet_infoline("Testing Dali::Layer::RaiseToTop()");
251   TestApplication application;
252   Layer           layer1 = Layer::New();
253   Layer           layer2 = Layer::New();
254   Layer           layer3 = Layer::New();
255
256   application.GetScene().Add(layer1);
257   application.GetScene().Add(layer2);
258   application.GetScene().Add(layer3);
259   Layer root = application.GetScene().GetLayer(0);
260
261   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
262   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
263   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
264   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
265
266   layer1.RaiseToTop();
267   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
268
269   root.RaiseToTop();
270   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
271   END_TEST;
272 }
273
274 int UtcDaliLayerRaiseToTop2(void)
275 {
276   tet_infoline("Testing Dali::Layer raiseToTop Action");
277   TestApplication application;
278   Layer           layer1 = Layer::New();
279   Layer           layer2 = Layer::New();
280   Layer           layer3 = Layer::New();
281
282   application.GetScene().Add(layer1);
283   application.GetScene().Add(layer2);
284   application.GetScene().Add(layer3);
285   Layer root = application.GetScene().GetLayer(0);
286
287   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
288   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
289   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
290   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
291
292   GetImplementation(layer1).DoAction("raiseToTop", Property::Map());
293   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
294
295   GetImplementation(root).DoAction("raiseToTop", Property::Map());
296   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
297   END_TEST;
298 }
299
300 int UtcDaliLayerLowerToBottom1(void)
301 {
302   tet_infoline("Testing Dali::Layer::LowerToBottom()");
303   TestApplication application;
304   Layer           layer1 = Layer::New();
305   Layer           layer2 = Layer::New();
306   Layer           layer3 = Layer::New();
307
308   application.GetScene().Add(layer1);
309   application.GetScene().Add(layer2);
310   application.GetScene().Add(layer3);
311
312   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
313   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
314   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
315
316   layer3.LowerToBottom();
317   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
318   END_TEST;
319 }
320
321 int UtcDaliLayerLowerToBottom2(void)
322 {
323   tet_infoline("Testing Dali::Layer lowerToBottom Action");
324   TestApplication application;
325   Layer           layer1 = Layer::New();
326   Layer           layer2 = Layer::New();
327   Layer           layer3 = Layer::New();
328
329   application.GetScene().Add(layer1);
330   application.GetScene().Add(layer2);
331   application.GetScene().Add(layer3);
332
333   DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
334   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
335   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
336
337   GetImplementation(layer3).DoAction("lowerToBottom", Property::Map());
338   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
339   END_TEST;
340 }
341
342
343 int UtcDaliLayerSetClipping(void)
344 {
345   tet_infoline("Testing Dali::Layer::SetClipping()");
346   TestApplication application;
347
348   Layer layer = Layer::New();
349   DALI_TEST_CHECK(!layer.GetProperty<bool>(Layer::Property::CLIPPING_ENABLE));
350
351   layer.SetProperty(Layer::Property::CLIPPING_ENABLE, true);
352   DALI_TEST_CHECK(layer.GetProperty<bool>(Layer::Property::CLIPPING_ENABLE));
353   END_TEST;
354 }
355
356 int UtcDaliLayerIsClipping(void)
357 {
358   tet_infoline("Testing Dali::Layer::IsClipping()");
359   TestApplication application;
360
361   Layer layer = Layer::New();
362   DALI_TEST_CHECK(!layer.GetProperty<bool>(Layer::Property::CLIPPING_ENABLE));
363   END_TEST;
364 }
365
366 int UtcDaliLayerSetClippingBox(void)
367 {
368   tet_infoline("Testing Dali::Layer::SetClippingBox()");
369   TestApplication application;
370
371   ClippingBox testBox(5, 6, 77, 83);
372
373   Layer layer = Layer::New();
374   DALI_TEST_CHECK(layer.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) != testBox);
375   layer.SetProperty(Layer::Property::CLIPPING_BOX, testBox);
376   DALI_TEST_CHECK(layer.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) == testBox);
377   END_TEST;
378 }
379
380 int UtcDaliLayerGetClippingBox(void)
381 {
382   tet_infoline("Testing Dali::Layer::GetClippingBox()");
383   TestApplication application;
384
385   Layer layer = Layer::New();
386   DALI_TEST_CHECK(layer.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) == ClippingBox(0, 0, 0, 0));
387   END_TEST;
388 }
389
390 static int gTestSortFunctionCalled;
391
392 static float TestSortFunction(const Vector3& /*position*/)
393 {
394   ++gTestSortFunctionCalled;
395   return 0.0f;
396 }
397
398 int UtcDaliLayerSetSortFunction(void)
399 {
400   tet_infoline("Testing Dali::Layer::SetSortFunction()");
401   TestApplication application;
402
403   // create two transparent actors so there is something to sort
404   Actor actor  = CreateRenderableActor();
405   Actor actor2 = CreateRenderableActor();
406   actor.SetProperty(Actor::Property::SIZE, Vector2(1, 1));
407   actor.SetProperty(Actor::Property::COLOR, Vector4(1, 1, 1, 0.5f)); // 50% transparent
408   actor2.SetProperty(Actor::Property::SIZE, Vector2(1, 1));
409   actor2.SetProperty(Actor::Property::COLOR, Vector4(1, 1, 1, 0.5f)); // 50% transparent
410
411   // add to scene
412   application.GetScene().Add(actor);
413   application.GetScene().Add(actor2);
414
415   Layer root              = application.GetScene().GetLayer(0);
416   gTestSortFunctionCalled = 0;
417   root.SetSortFunction(TestSortFunction);
418
419   // flush the queue and render once
420   application.SendNotification();
421   application.Render();
422
423   DALI_TEST_CHECK(gTestSortFunctionCalled > 0);
424   END_TEST;
425 }
426
427 int UtcDaliLayerRaiseAbove(void)
428 {
429   tet_infoline("Testing Dali::Layer::RaiseAbove()");
430   TestApplication application;
431   Layer           layer = Layer::New();
432   // try to raise above root layer
433   Layer root = application.GetScene().GetLayer(0);
434   layer.RaiseAbove(root);
435   // layer depth is zero as its not on scene
436   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
437   // add to scene
438   application.GetScene().Add(layer);
439   layer.RaiseAbove(root);
440   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
441   root.RaiseAbove(layer);
442   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
443   layer.RaiseAbove(layer);
444   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
445
446   // make another layer on the scene
447   Layer layer2 = Layer::New();
448   application.GetScene().Add(layer2);
449   layer.RaiseAbove(layer2);
450   DALI_TEST_GREATER(layer.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
451   layer2.RaiseAbove(layer);
452   DALI_TEST_GREATER(layer2.GetProperty<int>(Layer::Property::DEPTH), layer.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
453   root.RaiseAbove(layer2);
454   DALI_TEST_GREATER(root.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
455   END_TEST;
456 }
457
458 int UtcDaliLayerRaiseBelow(void)
459 {
460   tet_infoline("Testing Dali::Layer::RaiseBelow()");
461   TestApplication application;
462   Layer           layer = Layer::New();
463   // try to lower below root layer
464   Layer root = application.GetScene().GetLayer(0);
465   layer.LowerBelow(root);
466   // layer depth is zero as its not on scene
467   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
468   // add to scene
469   application.GetScene().Add(layer);
470   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
471   layer.LowerBelow(root);
472   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
473   root.LowerBelow(layer);
474   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
475   layer.LowerBelow(layer);
476   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
477
478   // make another layer on the scene
479   Layer layer2 = Layer::New();
480   application.GetScene().Add(layer2);
481   layer.LowerBelow(layer2);
482   DALI_TEST_GREATER(layer2.GetProperty<int>(Layer::Property::DEPTH), layer.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
483   layer2.LowerBelow(layer);
484   DALI_TEST_GREATER(layer.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
485   root.LowerBelow(layer2);
486   DALI_TEST_GREATER(layer2.GetProperty<int>(Layer::Property::DEPTH), root.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
487   END_TEST;
488 }
489
490 int UtcDaliLayerMoveAbove(void)
491 {
492   tet_infoline("Testing Dali::Layer::MoveAbove()");
493   TestApplication application;
494   Layer           layer = Layer::New();
495   // try to raise above root layer
496   Layer root = application.GetScene().GetLayer(0);
497   layer.MoveAbove(root);
498   // layer depth is zero as its not on scene
499   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
500   root.MoveAbove(layer);
501   // root depth is zero as layer is not on scene
502   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
503   // add to scene
504   application.GetScene().Add(layer);
505   layer.MoveAbove(root);
506   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
507   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
508   root.MoveAbove(layer);
509   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
510   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
511
512   // make another layer on the scene
513   Layer layer2 = Layer::New();
514   application.GetScene().Add(layer2);
515   layer.MoveAbove(layer2);
516   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH) + 1u, TEST_LOCATION);
517   layer2.MoveAbove(root);
518   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), root.GetProperty<int>(Layer::Property::DEPTH) + 1u, TEST_LOCATION);
519   root.MoveAbove(layer);
520   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), layer.GetProperty<int>(Layer::Property::DEPTH) + 1u, TEST_LOCATION);
521
522   Layer layer3 = Layer::New();
523   application.GetScene().Add(layer3);
524   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
525   root.MoveAbove(layer3);
526   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
527   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
528   DALI_TEST_EQUALS(application.GetScene().GetLayer(0).GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
529   layer3.MoveAbove(application.GetScene().GetLayer(0));
530   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
531   END_TEST;
532 }
533
534 int UtcDaliLayerMoveBelow(void)
535 {
536   tet_infoline("Testing Dali::Layer::MoveBelow()");
537   TestApplication application;
538   Layer           layer = Layer::New();
539   // try to raise above root layer
540   Layer root = application.GetScene().GetLayer(0);
541   layer.MoveBelow(root);
542   // layer depth is zero as its not on scene
543   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
544   root.MoveBelow(layer);
545   // root depth is zero as layer is not on scene
546   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
547   // add to scene
548   application.GetScene().Add(layer);
549   layer.MoveBelow(root);
550   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
551   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
552   root.MoveBelow(layer);
553   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
554   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
555
556   // make another layer on the scene
557   Layer layer2 = Layer::New();
558   application.GetScene().Add(layer2);
559   layer.MoveBelow(layer2);
560   DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH) - 1u, TEST_LOCATION);
561   layer2.MoveBelow(root);
562   DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), root.GetProperty<int>(Layer::Property::DEPTH) - 1u, TEST_LOCATION);
563   root.MoveBelow(layer);
564   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), layer.GetProperty<int>(Layer::Property::DEPTH) - 1u, TEST_LOCATION);
565
566   Layer layer3 = Layer::New();
567   application.GetScene().Add(layer3);
568   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
569   root.MoveBelow(layer3);
570   DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
571   DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
572   END_TEST;
573 }
574
575 int UtcDaliLayerDefaultProperties(void)
576 {
577   TestApplication application;
578   tet_infoline("Testing Dali::Layer DefaultProperties");
579
580   Layer actor = Layer::New();
581
582   std::vector<Property::Index> indices;
583   indices.push_back(Layer::Property::CLIPPING_ENABLE);
584   indices.push_back(Layer::Property::CLIPPING_BOX);
585   indices.push_back(Layer::Property::BEHAVIOR);
586   indices.push_back(Layer::Property::DEPTH);
587   indices.push_back(Layer::Property::DEPTH_TEST);
588   indices.push_back(Layer::Property::CONSUMES_TOUCH);
589   indices.push_back(Layer::Property::CONSUMES_HOVER);
590
591   DALI_TEST_CHECK(actor.GetPropertyCount() == (Actor::New().GetPropertyCount() + indices.size()));
592
593   for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
594   {
595     DALI_TEST_CHECK(*iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)));
596     DALI_TEST_CHECK(*iter == Layer::Property::DEPTH ? !actor.IsPropertyWritable(*iter) : actor.IsPropertyWritable(*iter));
597     DALI_TEST_CHECK(!actor.IsPropertyAnimatable(*iter));
598     DALI_TEST_CHECK(actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter)); // just checking call succeeds
599   }
600
601   // set/get one of them
602   actor.SetProperty(Layer::Property::CLIPPING_BOX, ClippingBox(0, 0, 0, 0));
603
604   ClippingBox testBox(10, 20, 30, 40);
605   DALI_TEST_CHECK(actor.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) != testBox);
606
607   actor.SetProperty(Layer::Property::CLIPPING_BOX, Property::Value(Rect<int>(testBox)));
608
609   DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(Layer::Property::CLIPPING_BOX));
610
611   Property::Value v = actor.GetProperty(Layer::Property::CLIPPING_BOX);
612   DALI_TEST_CHECK(v.Get<Rect<int> >() == testBox);
613
614   v = actor.GetCurrentProperty(Layer::Property::CLIPPING_BOX);
615   DALI_TEST_CHECK(v.Get<Rect<int> >() == testBox);
616
617   // set the same boundaries, but through a clipping box object
618   actor.SetProperty(Layer::Property::CLIPPING_BOX, testBox);
619   DALI_TEST_CHECK(actor.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) == testBox);
620
621   actor.SetProperty(Layer::Property::BEHAVIOR, Property::Value(Layer::LAYER_UI));
622   DALI_TEST_CHECK(Property::INTEGER == actor.GetPropertyType(Layer::Property::BEHAVIOR));
623
624   Property::Value behavior = actor.GetProperty(Layer::Property::BEHAVIOR);
625   DALI_TEST_EQUALS(behavior.Get<Dali::Layer::Behavior>(), Layer::LAYER_UI, TEST_LOCATION);
626
627   behavior = actor.GetCurrentProperty(Layer::Property::BEHAVIOR);
628   DALI_TEST_EQUALS(behavior.Get<Dali::Layer::Behavior>(), Layer::LAYER_UI, TEST_LOCATION);
629
630   END_TEST;
631 }
632
633 int UtcDaliLayerSetDepthTestDisabled(void)
634 {
635   TestApplication application;
636   tet_infoline("Testing Dali::Layer::SetDepthTestDisabled() ");
637
638   Layer actor = Layer::New();
639   // Note that Layer::Property::DEPTH_TEST does not depend on layer behavior,
640   // as 2D layers can still have depth tests performed on a per-renderer basis.
641   // Check default.
642   DALI_TEST_CHECK(!actor.GetProperty<bool>(Layer::Property::DEPTH_TEST));
643
644   // Check Set / Unset.
645   actor.SetProperty(Layer::Property::DEPTH_TEST, true);
646   DALI_TEST_CHECK(actor.GetProperty<bool>(Layer::Property::DEPTH_TEST));
647   actor.SetProperty(Layer::Property::DEPTH_TEST, false);
648   DALI_TEST_CHECK(!actor.GetProperty<bool>(Layer::Property::DEPTH_TEST));
649
650   END_TEST;
651 }
652
653 int UtcDaliLayerCreateDestroy(void)
654 {
655   tet_infoline("Testing Dali::Layer::CreateDestroy() ");
656   Layer* layer = new Layer;
657   DALI_TEST_CHECK(layer);
658   delete layer;
659   END_TEST;
660 }
661
662 int UtcDaliLayerPropertyIndices(void)
663 {
664   TestApplication application;
665   Actor           basicActor = Actor::New();
666   Layer           layer      = Layer::New();
667
668   Property::IndexContainer indices;
669   layer.GetPropertyIndices(indices);
670   DALI_TEST_CHECK(indices.Size() > basicActor.GetPropertyCount());
671   DALI_TEST_EQUALS(indices.Size(), layer.GetPropertyCount(), TEST_LOCATION);
672   END_TEST;
673 }
674
675 int UtcDaliLayerTouchConsumed(void)
676 {
677   TestApplication application;
678   Layer           layer = Layer::New();
679
680   DALI_TEST_EQUALS(layer.GetProperty<bool>(Layer::Property::CONSUMES_TOUCH), false, TEST_LOCATION);
681   layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
682   DALI_TEST_EQUALS(layer.GetProperty<bool>(Layer::Property::CONSUMES_TOUCH), true, TEST_LOCATION);
683   END_TEST;
684 }
685
686 int UtcDaliLayerHoverConsumed(void)
687 {
688   TestApplication application;
689   Layer           layer = Layer::New();
690
691   DALI_TEST_EQUALS(layer.GetProperty<bool>(Layer::Property::CONSUMES_HOVER), false, TEST_LOCATION);
692   layer.SetProperty(Layer::Property::CONSUMES_HOVER, true);
693   DALI_TEST_EQUALS(layer.GetProperty<bool>(Layer::Property::CONSUMES_HOVER), true, TEST_LOCATION);
694   END_TEST;
695 }
696
697 int UtcDaliLayerClippingGLCalls(void)
698 {
699   TestApplication                         application;
700   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
701   Integration::Scene                      scene(application.GetScene());
702
703   ClippingBox testBox(5, 6, 77, 83);
704   Layer       layer = application.GetScene().GetRootLayer();
705   layer.SetProperty(Layer::Property::CLIPPING_ENABLE, true);
706   layer.SetProperty(Layer::Property::CLIPPING_BOX, testBox);
707
708   // Add at least one renderable actor so the GL calls are actually made
709   Texture img   = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
710   Actor   actor = CreateRenderableActor(img);
711   scene.Add(actor);
712
713   // flush the queue and render once
714   application.SendNotification();
715   application.Render();
716
717   DALI_TEST_EQUALS(testBox.x, glScissorParams.x, TEST_LOCATION);
718   DALI_TEST_EQUALS(testBox.y, (int)(scene.GetSize().height - glScissorParams.y - testBox.height), TEST_LOCATION); // GL Coordinates are from bottom left
719   DALI_TEST_EQUALS(testBox.width, glScissorParams.width, TEST_LOCATION);
720   DALI_TEST_EQUALS(testBox.height, glScissorParams.height, TEST_LOCATION);
721   END_TEST;
722 }
723
724 int UtcDaliLayerBehaviour(void)
725 {
726   TestApplication application;
727   Layer           layer = Layer::New();
728
729   DALI_TEST_EQUALS(layer.GetProperty<Layer::Behavior>(Layer::Property::BEHAVIOR), Dali::Layer::LAYER_UI, TEST_LOCATION);
730   layer.SetProperty(Layer::Property::BEHAVIOR, Dali::Layer::LAYER_3D);
731   DALI_TEST_EQUALS(layer.GetProperty<Layer::Behavior>(Layer::Property::BEHAVIOR), Dali::Layer::LAYER_3D, TEST_LOCATION);
732   END_TEST;
733 }
734
735 Actor CreateActor(bool withAlpha)
736 {
737   Texture texture = Texture::New(TextureType::TEXTURE_2D, withAlpha ? Pixel::Format::RGBA8888 : Pixel::Format::RGB888, 1u, 1u);
738
739   Actor actor = CreateRenderableActor(texture);
740   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
741   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
742
743   return actor;
744 }
745
746 int UtcDaliLayer3DSort(void)
747 {
748   tet_infoline("Testing LAYER_3D sort coverage test");
749   TestApplication    application;
750   TestGlAbstraction& glAbstraction       = application.GetGlAbstraction();
751   TraceCallStack&    enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
752
753   application.GetScene().GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
754
755   // Create an actor.
756   Actor actor = CreateActor(false);
757   application.GetScene().Add(actor);
758
759   // Create child actors.
760   Actor child1 = CreateActor(true);
761   actor.Add(child1);
762   Actor child2 = CreateActor(false);
763   child1.Add(child2);
764
765   enabledDisableTrace.Reset();
766   enabledDisableTrace.Enable(true);
767   application.SendNotification();
768   application.Render();
769   enabledDisableTrace.Enable(false);
770
771   DALI_TEST_CHECK(enabledDisableTrace.FindMethodAndParams("Enable", "2929")); // 2929 is GL_DEPTH_TEST
772
773   END_TEST;
774 }
775
776 int UtcDaliLayerLowerBelowNegative(void)
777 {
778   TestApplication application;
779   Dali::Layer     instance;
780   try
781   {
782     Dali::Layer arg1;
783     instance.LowerBelow(arg1);
784     DALI_TEST_CHECK(false); // Should not get here
785   }
786   catch(...)
787   {
788     DALI_TEST_CHECK(true); // We expect an assert
789   }
790   END_TEST;
791 }
792
793 int UtcDaliLayerRaiseAboveNegative(void)
794 {
795   TestApplication application;
796   Dali::Layer     instance;
797   try
798   {
799     Dali::Layer arg1;
800     instance.RaiseAbove(arg1);
801     DALI_TEST_CHECK(false); // Should not get here
802   }
803   catch(...)
804   {
805     DALI_TEST_CHECK(true); // We expect an assert
806   }
807   END_TEST;
808 }
809
810 int UtcDaliLayerRaiseToTopNegative(void)
811 {
812   TestApplication application;
813   Dali::Layer     instance;
814   try
815   {
816     instance.RaiseToTop();
817     DALI_TEST_CHECK(false); // Should not get here
818   }
819   catch(...)
820   {
821     DALI_TEST_CHECK(true); // We expect an assert
822   }
823   END_TEST;
824 }
825
826 int UtcDaliLayerLowerToBottomNegative(void)
827 {
828   TestApplication application;
829   Dali::Layer     instance;
830   try
831   {
832     instance.LowerToBottom();
833     DALI_TEST_CHECK(false); // Should not get here
834   }
835   catch(...)
836   {
837     DALI_TEST_CHECK(true); // We expect an assert
838   }
839   END_TEST;
840 }
841
842 int UtcDaliLayerSetSortFunctionNegative(void)
843 {
844   TestApplication application;
845   Dali::Layer     instance;
846   try
847   {
848     Layer::SortFunctionType function = nullptr;
849     instance.SetSortFunction(function);
850     DALI_TEST_CHECK(false); // Should not get here
851   }
852   catch(...)
853   {
854     DALI_TEST_CHECK(true); // We expect an assert
855   }
856   END_TEST;
857 }
858
859 int UtcDaliLayerLowerNegative(void)
860 {
861   TestApplication application;
862   Dali::Layer     instance;
863   try
864   {
865     instance.Lower();
866     DALI_TEST_CHECK(false); // Should not get here
867   }
868   catch(...)
869   {
870     DALI_TEST_CHECK(true); // We expect an assert
871   }
872   END_TEST;
873 }
874
875 int UtcDaliLayerRaiseNegative(void)
876 {
877   TestApplication application;
878   Dali::Layer     instance;
879   try
880   {
881     instance.Raise();
882     DALI_TEST_CHECK(false); // Should not get here
883   }
884   catch(...)
885   {
886     DALI_TEST_CHECK(true); // We expect an assert
887   }
888   END_TEST;
889 }
890
891 int UtcDaliLayerMoveAboveNegative(void)
892 {
893   TestApplication application;
894   Dali::Layer     instance;
895   try
896   {
897     Dali::Layer arg1;
898     instance.MoveAbove(arg1);
899     DALI_TEST_CHECK(false); // Should not get here
900   }
901   catch(...)
902   {
903     DALI_TEST_CHECK(true); // We expect an assert
904   }
905   END_TEST;
906 }
907
908 int UtcDaliLayerMoveBelowNegative(void)
909 {
910   TestApplication application;
911   Dali::Layer     instance;
912   try
913   {
914     Dali::Layer arg1;
915     instance.MoveBelow(arg1);
916     DALI_TEST_CHECK(false); // Should not get here
917   }
918   catch(...)
919   {
920     DALI_TEST_CHECK(true); // We expect an assert
921   }
922   END_TEST;
923 }