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