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