Remove Setter/Getter public APIs from Dali::Layer
[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
84 int UtcDaliLayerGetDepth(void)
85 {
86   tet_infoline("Testing Dali::Layer::GetDepth()");
87   TestApplication application;
88   Layer layer1 = Layer::New();
89   Layer layer2 = Layer::New();
90
91   // layers are not on stage
92   DALI_TEST_EQUALS(layer1.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION);
93   DALI_TEST_EQUALS(layer2.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION);
94
95   // root depth is 0
96   Layer root = Stage::GetCurrent().GetLayer( 0 );
97   DALI_TEST_EQUALS(root.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION);
98
99   Stage::GetCurrent().Add(layer1);
100   Stage::GetCurrent().Add(layer2);
101
102   DALI_TEST_EQUALS(  root.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION);
103   DALI_TEST_EQUALS(layer1.GetProperty< int >( Layer::Property::DEPTH ), 1u, TEST_LOCATION);
104   DALI_TEST_EQUALS(layer2.GetProperty< int >( Layer::Property::DEPTH ), 2u, TEST_LOCATION);
105   END_TEST;
106 }
107
108 int UtcDaliLayerRaise(void)
109 {
110   tet_infoline("Testing Dali::Layer::Raise()");
111   TestApplication application;
112   Layer layer1 = Layer::New();
113   Layer layer2 = Layer::New();
114
115   Stage::GetCurrent().Add(layer1);
116   Stage::GetCurrent().Add(layer2);
117   DALI_TEST_EQUALS(layer1.GetProperty< int >( Layer::Property::DEPTH ), 1u, TEST_LOCATION);
118
119   layer1.Raise();
120   DALI_TEST_EQUALS(layer1.GetProperty< int >( Layer::Property::DEPTH ), 2u, TEST_LOCATION);
121
122   // get root
123   Layer root = Stage::GetCurrent().GetLayer( 0 );
124   DALI_TEST_EQUALS(  root.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION);
125   root.Raise();
126   DALI_TEST_EQUALS(  root.GetProperty< int >( Layer::Property::DEPTH ), 1u, TEST_LOCATION);
127   DALI_TEST_EQUALS(layer1.GetProperty< int >( Layer::Property::DEPTH ), 2u, TEST_LOCATION);
128   DALI_TEST_EQUALS(layer2.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION);
129   END_TEST;
130 }
131
132 int UtcDaliLayerLower(void)
133 {
134   tet_infoline("Testing Dali::Layer::Lower()");
135   TestApplication application;
136   Layer layer1 = Layer::New();
137   Layer layer2 = Layer::New();
138
139   Stage::GetCurrent().Add(layer1);
140   Stage::GetCurrent().Add(layer2);
141   DALI_TEST_EQUALS(layer2.GetProperty< int >( Layer::Property::DEPTH ), 2u, TEST_LOCATION);
142
143   layer2.Lower();
144   DALI_TEST_EQUALS(layer2.GetProperty< int >( Layer::Property::DEPTH ), 1u, TEST_LOCATION);
145
146   // get root
147   Layer root = Stage::GetCurrent().GetLayer( 0 );
148   root.Lower();
149   DALI_TEST_EQUALS(  root.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION);
150   layer2.Lower();
151   DALI_TEST_EQUALS(  root.GetProperty< int >( Layer::Property::DEPTH ), 1u, TEST_LOCATION);
152   DALI_TEST_EQUALS(layer2.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION);
153   END_TEST;
154 }
155
156 int UtcDaliLayerRaiseToTop(void)
157 {
158   tet_infoline("Testing Dali::Layer::RaiseToTop()");
159   TestApplication application;
160   Layer layer1 = Layer::New();
161   Layer layer2 = Layer::New();
162   Layer layer3 = Layer::New();
163
164   Stage::GetCurrent().Add(layer1);
165   Stage::GetCurrent().Add(layer2);
166   Stage::GetCurrent().Add(layer3);
167   Layer root = Stage::GetCurrent().GetLayer( 0 );
168
169   DALI_TEST_EQUALS(  root.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION);
170   DALI_TEST_EQUALS(layer1.GetProperty< int >( Layer::Property::DEPTH ), 1u, TEST_LOCATION);
171   DALI_TEST_EQUALS(layer2.GetProperty< int >( Layer::Property::DEPTH ), 2u, TEST_LOCATION);
172   DALI_TEST_EQUALS(layer3.GetProperty< int >( Layer::Property::DEPTH ), 3u, TEST_LOCATION);
173
174   layer1.RaiseToTop();
175   DALI_TEST_EQUALS(layer1.GetProperty< int >( Layer::Property::DEPTH ), 3u, TEST_LOCATION);
176
177   root.RaiseToTop();
178   DALI_TEST_EQUALS(  root.GetProperty< int >( Layer::Property::DEPTH ), 3u, TEST_LOCATION);
179   END_TEST;
180 }
181
182 int UtcDaliLayerLowerToBottom(void)
183 {
184   tet_infoline("Testing Dali::Layer::LowerToBottom()");
185   TestApplication application;
186   Layer layer1 = Layer::New();
187   Layer layer2 = Layer::New();
188   Layer layer3 = Layer::New();
189
190   Stage::GetCurrent().Add(layer1);
191   Stage::GetCurrent().Add(layer2);
192   Stage::GetCurrent().Add(layer3);
193
194   DALI_TEST_EQUALS(layer1.GetProperty< int >( Layer::Property::DEPTH ), 1u, TEST_LOCATION);
195   DALI_TEST_EQUALS(layer2.GetProperty< int >( Layer::Property::DEPTH ), 2u, TEST_LOCATION);
196   DALI_TEST_EQUALS(layer3.GetProperty< int >( Layer::Property::DEPTH ), 3u, TEST_LOCATION);
197
198   layer3.LowerToBottom();
199   DALI_TEST_EQUALS(layer3.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION);
200   END_TEST;
201 }
202
203 int UtcDaliLayerSetClipping(void)
204 {
205   tet_infoline("Testing Dali::Layer::SetClipping()");
206   TestApplication application;
207
208   Layer layer = Layer::New();
209   DALI_TEST_CHECK( !layer.GetProperty< bool >( Layer::Property::CLIPPING_ENABLE ) );
210
211   layer.SetProperty( Layer::Property::CLIPPING_ENABLE, true );
212   DALI_TEST_CHECK( layer.GetProperty< bool >( Layer::Property::CLIPPING_ENABLE ) );
213   END_TEST;
214 }
215
216 int UtcDaliLayerIsClipping(void)
217 {
218   tet_infoline("Testing Dali::Layer::IsClipping()");
219   TestApplication application;
220
221   Layer layer = Layer::New();
222   DALI_TEST_CHECK( !layer.GetProperty< bool >( Layer::Property::CLIPPING_ENABLE ) );
223   END_TEST;
224 }
225
226 int UtcDaliLayerSetClippingBox(void)
227 {
228   tet_infoline("Testing Dali::Layer::SetClippingBox()");
229   TestApplication application;
230
231   ClippingBox testBox(5,6, 77,83);
232
233   Layer layer = Layer::New();
234   DALI_TEST_CHECK(layer.GetProperty< Rect<int32_t> >( Layer::Property::CLIPPING_BOX ) != testBox);
235   layer.SetProperty( Layer::Property::CLIPPING_BOX, testBox );
236   DALI_TEST_CHECK(layer.GetProperty< Rect<int32_t> >( Layer::Property::CLIPPING_BOX ) == testBox);
237   END_TEST;
238 }
239
240 int UtcDaliLayerGetClippingBox(void)
241 {
242   tet_infoline("Testing Dali::Layer::GetClippingBox()");
243   TestApplication application;
244
245   Layer layer = Layer::New();
246   DALI_TEST_CHECK( layer.GetProperty< Rect<int32_t> >( Layer::Property::CLIPPING_BOX ) == ClippingBox(0,0,0,0) );
247   END_TEST;
248 }
249
250 static int gTestSortFunctionCalled;
251
252 static float TestSortFunction(const Vector3& /*position*/)
253 {
254   ++gTestSortFunctionCalled;
255   return 0.0f;
256 }
257
258 int UtcDaliLayerSetSortFunction(void)
259 {
260   tet_infoline("Testing Dali::Layer::SetSortFunction()");
261   TestApplication application;
262
263   // create two transparent actors so there is something to sort
264   Actor actor = CreateRenderableActor();
265   Actor actor2 = CreateRenderableActor();
266   actor.SetProperty( Actor::Property::SIZE, Vector2( 1, 1 ) );
267   actor.SetProperty( Actor::Property::COLOR, Vector4(1, 1, 1, 0.5f ) ); // 50% transparent
268   actor2.SetProperty( Actor::Property::SIZE, Vector2( 1, 1 ) );
269   actor2.SetProperty( Actor::Property::COLOR, Vector4(1, 1, 1, 0.5f ) ); // 50% transparent
270
271   // add to stage
272   Stage::GetCurrent().Add( actor );
273   Stage::GetCurrent().Add( actor2 );
274
275   Layer root = Stage::GetCurrent().GetLayer( 0 );
276   gTestSortFunctionCalled = 0;
277   root.SetSortFunction(TestSortFunction);
278
279   // flush the queue and render once
280   application.SendNotification();
281   application.Render();
282
283   DALI_TEST_CHECK( gTestSortFunctionCalled > 0 );
284   END_TEST;
285 }
286
287
288 int UtcDaliLayerRaiseAbove(void)
289 {
290   tet_infoline("Testing Dali::Layer::RaiseAbove()");
291   TestApplication application;
292   Layer layer = Layer::New();
293   // try to raise above root layer
294   Layer root = Stage::GetCurrent().GetLayer( 0 );
295   layer.RaiseAbove( root );
296   // layer depth is zero as its not on stage
297   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION );
298   // add to stage
299   Stage::GetCurrent().Add( layer );
300   layer.RaiseAbove( root );
301   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), 1u, TEST_LOCATION );
302   root.RaiseAbove( layer );
303   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION );
304   layer.RaiseAbove( layer );
305   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION );
306
307   // make another layer on the stage
308   Layer layer2 = Layer::New();
309   Stage::GetCurrent().Add( layer2 );
310   layer.RaiseAbove( layer2 );
311   DALI_TEST_GREATER( layer.GetProperty< int >( Layer::Property::DEPTH ), layer2.GetProperty< int >( Layer::Property::DEPTH ), TEST_LOCATION );
312   layer2.RaiseAbove( layer );
313   DALI_TEST_GREATER( layer2.GetProperty< int >( Layer::Property::DEPTH ), layer.GetProperty< int >( Layer::Property::DEPTH ), TEST_LOCATION );
314   root.RaiseAbove( layer2 );
315   DALI_TEST_GREATER( root.GetProperty< int >( Layer::Property::DEPTH ), layer2.GetProperty< int >( Layer::Property::DEPTH ), TEST_LOCATION );
316   END_TEST;
317 }
318
319 int UtcDaliLayerRaiseBelow(void)
320 {
321   tet_infoline("Testing Dali::Layer::RaiseBelow()");
322   TestApplication application;
323   Layer layer = Layer::New();
324   // try to lower below root layer
325   Layer root = Stage::GetCurrent().GetLayer( 0 );
326   layer.LowerBelow( root );
327   // layer depth is zero as its not on stage
328   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION );
329   // add to stage
330   Stage::GetCurrent().Add( layer );
331   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), 1u, TEST_LOCATION );
332   layer.LowerBelow( root );
333   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION );
334   root.LowerBelow( layer );
335   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), 1u, TEST_LOCATION );
336   layer.LowerBelow( layer );
337   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), 1u, TEST_LOCATION );
338
339   // make another layer on the stage
340   Layer layer2 = Layer::New();
341   Stage::GetCurrent().Add( layer2 );
342   layer.LowerBelow( layer2 );
343   DALI_TEST_GREATER( layer2.GetProperty< int >( Layer::Property::DEPTH ), layer.GetProperty< int >( Layer::Property::DEPTH ), TEST_LOCATION );
344   layer2.LowerBelow( layer );
345   DALI_TEST_GREATER( layer.GetProperty< int >( Layer::Property::DEPTH ), layer2.GetProperty< int >( Layer::Property::DEPTH ), TEST_LOCATION );
346   root.LowerBelow( layer2 );
347   DALI_TEST_GREATER( layer2.GetProperty< int >( Layer::Property::DEPTH ), root.GetProperty< int >( Layer::Property::DEPTH ), TEST_LOCATION );
348   END_TEST;
349 }
350
351 int UtcDaliLayerMoveAbove(void)
352 {
353   tet_infoline("Testing Dali::Layer::MoveAbove()");
354   TestApplication application;
355   Layer layer = Layer::New();
356   // try to raise above root layer
357   Layer root = Stage::GetCurrent().GetLayer( 0 );
358   layer.MoveAbove( root );
359   // layer depth is zero as its not on stage
360   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION );
361   root.MoveAbove( layer );
362   // root depth is zero as layer is not on stage
363   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION );
364   // add to stage
365   Stage::GetCurrent().Add( layer );
366   layer.MoveAbove( root );
367   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), 1u, TEST_LOCATION );
368   DALI_TEST_EQUALS( root.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION );
369   root.MoveAbove( layer );
370   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION );
371   DALI_TEST_EQUALS( root.GetProperty< int >( Layer::Property::DEPTH ), 1u, TEST_LOCATION );
372
373   // make another layer on the stage
374   Layer layer2 = Layer::New();
375   Stage::GetCurrent().Add( layer2 );
376   layer.MoveAbove( layer2 );
377   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), layer2.GetProperty< int >( Layer::Property::DEPTH ) + 1u, TEST_LOCATION );
378   layer2.MoveAbove( root );
379   DALI_TEST_EQUALS( layer2.GetProperty< int >( Layer::Property::DEPTH ), root.GetProperty< int >( Layer::Property::DEPTH ) + 1u, TEST_LOCATION );
380   root.MoveAbove( layer );
381   DALI_TEST_EQUALS( root.GetProperty< int >( Layer::Property::DEPTH ), layer.GetProperty< int >( Layer::Property::DEPTH ) + 1u, TEST_LOCATION );
382
383   Layer layer3 = Layer::New();
384   Stage::GetCurrent().Add( layer3 );
385   DALI_TEST_EQUALS( layer3.GetProperty< int >( Layer::Property::DEPTH ), 3u, TEST_LOCATION );
386   root.MoveAbove( layer3 );
387   DALI_TEST_EQUALS( root.GetProperty< int >( Layer::Property::DEPTH ), 3u, TEST_LOCATION );
388   DALI_TEST_EQUALS( layer3.GetProperty< int >( Layer::Property::DEPTH ), 2u, TEST_LOCATION );
389   DALI_TEST_EQUALS( Stage::GetCurrent().GetLayer( 0 ).GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION );
390   layer3.MoveAbove( Stage::GetCurrent().GetLayer( 0 ) );
391   DALI_TEST_EQUALS( layer3.GetProperty< int >( Layer::Property::DEPTH ), 1u, TEST_LOCATION );
392   END_TEST;
393 }
394
395 int UtcDaliLayerMoveBelow(void)
396 {
397   tet_infoline("Testing Dali::Layer::MoveBelow()");
398   TestApplication application;
399   Layer layer = Layer::New();
400   // try to raise above root layer
401   Layer root = Stage::GetCurrent().GetLayer( 0 );
402   layer.MoveBelow( root );
403   // layer depth is zero as its not on stage
404   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION );
405   root.MoveBelow( layer );
406   // root depth is zero as layer is not on stage
407   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION );
408   // add to stage
409   Stage::GetCurrent().Add( layer );
410   layer.MoveBelow( root );
411   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION );
412   DALI_TEST_EQUALS( root.GetProperty< int >( Layer::Property::DEPTH ), 1u, TEST_LOCATION );
413   root.MoveBelow( layer );
414   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), 1u, TEST_LOCATION );
415   DALI_TEST_EQUALS( root.GetProperty< int >( Layer::Property::DEPTH ), 0u, TEST_LOCATION );
416
417   // make another layer on the stage
418   Layer layer2 = Layer::New();
419   Stage::GetCurrent().Add( layer2 );
420   layer.MoveBelow( layer2 );
421   DALI_TEST_EQUALS( layer.GetProperty< int >( Layer::Property::DEPTH ), layer2.GetProperty< int >( Layer::Property::DEPTH ) - 1u, TEST_LOCATION );
422   layer2.MoveBelow( root );
423   DALI_TEST_EQUALS( layer2.GetProperty< int >( Layer::Property::DEPTH ), root.GetProperty< int >( Layer::Property::DEPTH ) - 1u, TEST_LOCATION );
424   root.MoveBelow( layer );
425   DALI_TEST_EQUALS( root.GetProperty< int >( Layer::Property::DEPTH ), layer.GetProperty< int >( Layer::Property::DEPTH ) - 1u, TEST_LOCATION );
426
427   Layer layer3 = Layer::New();
428   Stage::GetCurrent().Add( layer3 );
429   DALI_TEST_EQUALS( layer3.GetProperty< int >( Layer::Property::DEPTH ), 3u, TEST_LOCATION );
430   root.MoveBelow( layer3 );
431   DALI_TEST_EQUALS( root.GetProperty< int >( Layer::Property::DEPTH ), 2u, TEST_LOCATION );
432   DALI_TEST_EQUALS( layer3.GetProperty< int >( Layer::Property::DEPTH ), 3u, TEST_LOCATION );
433   END_TEST;
434 }
435
436 int UtcDaliLayerDefaultProperties(void)
437 {
438   TestApplication application;
439   tet_infoline("Testing Dali::Layer DefaultProperties");
440
441   Layer actor = Layer::New();
442
443   std::vector<Property::Index> indices;
444   indices.push_back(Layer::Property::CLIPPING_ENABLE);
445   indices.push_back(Layer::Property::CLIPPING_BOX);
446   indices.push_back(Layer::Property::BEHAVIOR);
447   indices.push_back(Layer::Property::DEPTH);
448   indices.push_back(Layer::Property::DEPTH_TEST);
449   indices.push_back(Layer::Property::CONSUMES_TOUCH);
450   indices.push_back(Layer::Property::CONSUMES_HOVER);
451
452   DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
453
454   for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
455   {
456     DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
457     DALI_TEST_CHECK( *iter == Layer::Property::DEPTH ? !actor.IsPropertyWritable(*iter) : actor.IsPropertyWritable(*iter) );
458     DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
459     DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) );  // just checking call succeeds
460   }
461
462   // set/get one of them
463   actor.SetProperty( Layer::Property::CLIPPING_BOX, ClippingBox( 0, 0, 0, 0 ) );
464
465   ClippingBox testBox(10,20,30,40);
466   DALI_TEST_CHECK(actor.GetProperty< Rect<int32_t> >( Layer::Property::CLIPPING_BOX ) != testBox);
467
468   actor.SetProperty(Layer::Property::CLIPPING_BOX, Property::Value(Rect<int>(testBox)));
469
470   DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(Layer::Property::CLIPPING_BOX));
471
472   Property::Value v = actor.GetProperty(Layer::Property::CLIPPING_BOX);
473   DALI_TEST_CHECK(v.Get<Rect<int> >() == testBox);
474
475   v = actor.GetCurrentProperty( Layer::Property::CLIPPING_BOX );
476   DALI_TEST_CHECK(v.Get<Rect<int> >() == testBox);
477
478   // set the same boundaries, but through a clipping box object
479   actor.SetProperty( Layer::Property::CLIPPING_BOX, testBox );
480   DALI_TEST_CHECK( actor.GetProperty< Rect<int32_t> >( Layer::Property::CLIPPING_BOX ) == testBox );
481
482   actor.SetProperty(Layer::Property::BEHAVIOR, Property::Value(Layer::LAYER_UI));
483   DALI_TEST_CHECK(Property::INTEGER == actor.GetPropertyType(Layer::Property::BEHAVIOR));
484
485   Property::Value behavior = actor.GetProperty(Layer::Property::BEHAVIOR);
486   DALI_TEST_EQUALS( behavior.Get<Dali::Layer::Behavior>(), Layer::LAYER_UI, TEST_LOCATION );
487
488   behavior = actor.GetCurrentProperty( Layer::Property::BEHAVIOR );
489   DALI_TEST_EQUALS( behavior.Get<Dali::Layer::Behavior>(), Layer::LAYER_UI, TEST_LOCATION );
490
491   END_TEST;
492 }
493
494 int UtcDaliLayerSetDepthTestDisabled(void)
495 {
496   TestApplication application;
497   tet_infoline("Testing Dali::Layer::SetDepthTestDisabled() ");
498
499   Layer actor = Layer::New();
500   // Note that Layer::Property::DEPTH_TEST does not depend on layer behavior,
501   // as 2D layers can still have depth tests performed on a per-renderer basis.
502   // Check default.
503   DALI_TEST_CHECK( !actor.GetProperty< bool >( Layer::Property::DEPTH_TEST ) );
504
505   // Check Set / Unset.
506   actor.SetProperty(Layer::Property::DEPTH_TEST, true );
507   DALI_TEST_CHECK( actor.GetProperty< bool >( Layer::Property::DEPTH_TEST ) );
508   actor.SetProperty(Layer::Property::DEPTH_TEST, false );
509   DALI_TEST_CHECK( !actor.GetProperty< bool >( Layer::Property::DEPTH_TEST ) );
510
511   END_TEST;
512 }
513
514 int UtcDaliLayerCreateDestroy(void)
515 {
516   tet_infoline("Testing Dali::Layer::CreateDestroy() ");
517   Layer* layer = new Layer;
518   DALI_TEST_CHECK( layer );
519   delete layer;
520   END_TEST;
521 }
522
523 int UtcDaliLayerPropertyIndices(void)
524 {
525   TestApplication application;
526   Actor basicActor = Actor::New();
527   Layer layer = Layer::New();
528
529   Property::IndexContainer indices;
530   layer.GetPropertyIndices( indices );
531   DALI_TEST_CHECK( indices.Size() > basicActor.GetPropertyCount() );
532   DALI_TEST_EQUALS( indices.Size(), layer.GetPropertyCount(), TEST_LOCATION );
533   END_TEST;
534 }
535
536 int UtcDaliLayerTouchConsumed(void)
537 {
538   TestApplication application;
539   Layer layer = Layer::New();
540
541   DALI_TEST_EQUALS( layer.GetProperty< bool >( Layer::Property::CONSUMES_TOUCH ), false, TEST_LOCATION );
542   layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
543   DALI_TEST_EQUALS( layer.GetProperty< bool >( Layer::Property::CONSUMES_TOUCH ), true, TEST_LOCATION );
544   END_TEST;
545 }
546
547 int UtcDaliLayerHoverConsumed(void)
548 {
549   TestApplication application;
550   Layer layer = Layer::New();
551
552   DALI_TEST_EQUALS( layer.GetProperty< bool >( Layer::Property::CONSUMES_HOVER ), false, TEST_LOCATION );
553   layer.SetProperty( Layer::Property::CONSUMES_HOVER, true );
554   DALI_TEST_EQUALS( layer.GetProperty< bool >( Layer::Property::CONSUMES_HOVER ), true, TEST_LOCATION );
555   END_TEST;
556 }
557
558 int UtcDaliLayerClippingGLCalls(void)
559 {
560   TestApplication application;
561   const TestGlAbstraction::ScissorParams& glScissorParams( application.GetGlAbstraction().GetScissorParams() );
562   Stage stage( Stage::GetCurrent() );
563
564   ClippingBox testBox( 5, 6, 77, 83 );
565   Layer layer = Stage::GetCurrent().GetRootLayer();
566   layer.SetProperty( Layer::Property::CLIPPING_ENABLE, true );
567   layer.SetProperty( Layer::Property::CLIPPING_BOX, testBox );
568
569   // Add at least one renderable actor so the GL calls are actually made
570   Texture img = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1 );
571   Actor actor = CreateRenderableActor( img );
572   stage.Add( actor );
573
574   // flush the queue and render once
575   application.SendNotification();
576   application.Render();
577
578   DALI_TEST_EQUALS( testBox.x, glScissorParams.x, TEST_LOCATION );
579   DALI_TEST_EQUALS( testBox.y, (int)(stage.GetSize().height - glScissorParams.y - testBox.height), TEST_LOCATION ); // GL Coordinates are from bottom left
580   DALI_TEST_EQUALS( testBox.width, glScissorParams.width, TEST_LOCATION );
581   DALI_TEST_EQUALS( testBox.height, glScissorParams.height, TEST_LOCATION );
582   END_TEST;
583 }
584
585 int UtcDaliLayerBehaviour(void)
586 {
587   TestApplication application;
588   Layer layer = Layer::New();
589
590   DALI_TEST_EQUALS( layer.GetProperty<Layer::Behavior>( Layer::Property::BEHAVIOR ), Dali::Layer::LAYER_UI, TEST_LOCATION );
591   layer.SetProperty( Layer::Property::BEHAVIOR, Dali::Layer::LAYER_3D );
592   DALI_TEST_EQUALS( layer.GetProperty<Layer::Behavior>( Layer::Property::BEHAVIOR ), Dali::Layer::LAYER_3D, TEST_LOCATION );
593   END_TEST;
594 }
595
596 Actor CreateActor( bool withAlpha )
597 {
598   Texture texture = Texture::New(TextureType::TEXTURE_2D, withAlpha ? Pixel::Format::RGBA8888 : Pixel::Format::RGB888, 1u, 1u );
599
600   Actor actor = CreateRenderableActor( texture );
601   actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
602   actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
603
604   return actor;
605 }
606
607 int UtcDaliLayer3DSort(void)
608 {
609   tet_infoline( "Testing LAYER_3D sort coverage test" );
610   TestApplication application;
611   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
612   TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
613
614   Stage::GetCurrent().GetRootLayer().SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D );
615
616   // Create an actor.
617   Actor actor = CreateActor( false );
618   Stage::GetCurrent().Add( actor );
619
620   // Create child actors.
621   Actor child1 = CreateActor( true );
622   actor.Add( child1 );
623   Actor child2 = CreateActor( false );
624   child1.Add( child2 );
625
626   enabledDisableTrace.Reset();
627   enabledDisableTrace.Enable( true );
628   application.SendNotification();
629   application.Render();
630   enabledDisableTrace.Enable( false );
631
632   DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParams( "Enable", "2929" ) );  // 2929 is GL_DEPTH_TEST
633
634   END_TEST;
635 }