Migrating to new test framework
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Layer.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 #include <iostream>
18
19 #include <stdlib.h>
20
21 #include <dali/dali.h>
22
23 #include <dali-test-suite-utils.h>
24
25 using namespace Dali;
26
27 void layer_test_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void layer_test_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37
38 int UtcDaliLayerNew(void)
39 {
40   TestApplication application;
41   Layer layer = Layer::New();
42
43   DALI_TEST_CHECK(layer);
44   END_TEST;
45 }
46
47 int UtcDaliLayerDownCast(void)
48 {
49   TestApplication application;
50   tet_infoline("Testing Dali::Layer::DownCast()");
51
52   Layer actor1 = Layer::New();
53   Actor anActor = Actor::New();
54   anActor.Add(actor1);
55
56   Actor child = anActor.GetChildAt(0);
57   Layer layer = DownCast< Layer >(child);
58
59   DALI_TEST_CHECK(layer);
60   END_TEST;
61 }
62
63 int UtcDaliLayerDownCast2(void)
64 {
65   TestApplication application;
66   tet_infoline("Testing Dali::Layer::DownCast()");
67
68   Actor actor1 = Actor::New();
69   Actor anActor = Actor::New();
70   anActor.Add(actor1);
71
72   Actor child = anActor.GetChildAt(0);
73   Layer layer = DownCast< Layer >(child);
74   DALI_TEST_CHECK(!layer);
75
76   Actor unInitialzedActor;
77   layer = Layer::DownCast( unInitialzedActor );
78   DALI_TEST_CHECK(!layer);
79   END_TEST;
80 }
81
82
83 int UtcDaliLayerGetDepth(void)
84 {
85   tet_infoline("Testing Dali::Layer::GetDepth()");
86   TestApplication application;
87   Layer layer1 = Layer::New();
88   Layer layer2 = Layer::New();
89
90   // layers are not on stage
91   DALI_TEST_EQUALS(layer1.GetDepth(), 0u, TEST_LOCATION);
92   DALI_TEST_EQUALS(layer2.GetDepth(), 0u, TEST_LOCATION);
93
94   // root depth is 0
95   Layer root = Stage::GetCurrent().GetLayer( 0 );
96   DALI_TEST_EQUALS(root.GetDepth(), 0u, TEST_LOCATION);
97
98   Stage::GetCurrent().Add(layer1);
99   Stage::GetCurrent().Add(layer2);
100
101   DALI_TEST_EQUALS(  root.GetDepth(), 0u, TEST_LOCATION);
102   DALI_TEST_EQUALS(layer1.GetDepth(), 1u, TEST_LOCATION);
103   DALI_TEST_EQUALS(layer2.GetDepth(), 2u, TEST_LOCATION);
104   END_TEST;
105 }
106
107 int UtcDaliLayerRaise(void)
108 {
109   tet_infoline("Testing Dali::Layer::Raise()");
110   TestApplication application;
111   Layer layer1 = Layer::New();
112   Layer layer2 = Layer::New();
113
114   Stage::GetCurrent().Add(layer1);
115   Stage::GetCurrent().Add(layer2);
116   DALI_TEST_EQUALS(layer1.GetDepth(), 1u, TEST_LOCATION);
117
118   layer1.Raise();
119   DALI_TEST_EQUALS(layer1.GetDepth(), 2u, TEST_LOCATION);
120
121   // get root
122   Layer root = Stage::GetCurrent().GetLayer( 0 );
123   DALI_TEST_EQUALS(  root.GetDepth(), 0u, TEST_LOCATION);
124   root.Raise();
125   DALI_TEST_EQUALS(  root.GetDepth(), 1u, TEST_LOCATION);
126   DALI_TEST_EQUALS(layer1.GetDepth(), 2u, TEST_LOCATION);
127   DALI_TEST_EQUALS(layer2.GetDepth(), 0u, TEST_LOCATION);
128   END_TEST;
129 }
130
131 int UtcDaliLayerLower(void)
132 {
133   tet_infoline("Testing Dali::Layer::Lower()");
134   TestApplication application;
135   Layer layer1 = Layer::New();
136   Layer layer2 = Layer::New();
137
138   Stage::GetCurrent().Add(layer1);
139   Stage::GetCurrent().Add(layer2);
140   DALI_TEST_EQUALS(layer2.GetDepth(), 2u, TEST_LOCATION);
141
142   layer2.Lower();
143   DALI_TEST_EQUALS(layer2.GetDepth(), 1u, TEST_LOCATION);
144
145   // get root
146   Layer root = Stage::GetCurrent().GetLayer( 0 );
147   root.Lower();
148   DALI_TEST_EQUALS(  root.GetDepth(), 0u, TEST_LOCATION);
149   layer2.Lower();
150   DALI_TEST_EQUALS(  root.GetDepth(), 1u, TEST_LOCATION);
151   DALI_TEST_EQUALS(layer2.GetDepth(), 0u, TEST_LOCATION);
152   END_TEST;
153 }
154
155 int UtcDaliLayerRaiseToTop(void)
156 {
157   tet_infoline("Testing Dali::Layer::RaiseToTop()");
158   TestApplication application;
159   Layer layer1 = Layer::New();
160   Layer layer2 = Layer::New();
161   Layer layer3 = Layer::New();
162
163   Stage::GetCurrent().Add(layer1);
164   Stage::GetCurrent().Add(layer2);
165   Stage::GetCurrent().Add(layer3);
166   Layer root = Stage::GetCurrent().GetLayer( 0 );
167
168   DALI_TEST_EQUALS(  root.GetDepth(), 0u, TEST_LOCATION);
169   DALI_TEST_EQUALS(layer1.GetDepth(), 1u, TEST_LOCATION);
170   DALI_TEST_EQUALS(layer2.GetDepth(), 2u, TEST_LOCATION);
171   DALI_TEST_EQUALS(layer3.GetDepth(), 3u, TEST_LOCATION);
172
173   layer1.RaiseToTop();
174   DALI_TEST_EQUALS(layer1.GetDepth(), 3u, TEST_LOCATION);
175
176   root.RaiseToTop();
177   DALI_TEST_EQUALS(  root.GetDepth(), 3u, TEST_LOCATION);
178   END_TEST;
179 }
180
181 int UtcDaliLayerLowerToBottom(void)
182 {
183   tet_infoline("Testing Dali::Layer::LowerToBottom()");
184   TestApplication application;
185   Layer layer1 = Layer::New();
186   Layer layer2 = Layer::New();
187   Layer layer3 = Layer::New();
188
189   Stage::GetCurrent().Add(layer1);
190   Stage::GetCurrent().Add(layer2);
191   Stage::GetCurrent().Add(layer3);
192
193   DALI_TEST_EQUALS(layer1.GetDepth(), 1u, TEST_LOCATION);
194   DALI_TEST_EQUALS(layer2.GetDepth(), 2u, TEST_LOCATION);
195   DALI_TEST_EQUALS(layer3.GetDepth(), 3u, TEST_LOCATION);
196
197   layer3.LowerToBottom();
198   DALI_TEST_EQUALS(layer3.GetDepth(), 0u, TEST_LOCATION);
199   END_TEST;
200 }
201
202 int UtcDaliLayerSetClipping(void)
203 {
204   tet_infoline("Testing Dali::Layer::SetClipping()");
205   TestApplication application;
206
207   Layer layer = Layer::New();
208   DALI_TEST_CHECK(!layer.IsClipping());
209
210   layer.SetClipping(true);
211   DALI_TEST_CHECK(layer.IsClipping());
212   END_TEST;
213 }
214
215 int UtcDaliLayerIsClipping(void)
216 {
217   tet_infoline("Testing Dali::Layer::IsClipping()");
218   TestApplication application;
219
220   Layer layer = Layer::New();
221   DALI_TEST_CHECK(!layer.IsClipping());
222   END_TEST;
223 }
224
225 int UtcDaliLayerSetClippingBox(void)
226 {
227   tet_infoline("Testing Dali::Layer::SetClippingBox()");
228   TestApplication application;
229
230   ClippingBox testBox(5,6, 77,83);
231
232   Layer layer = Layer::New();
233   DALI_TEST_CHECK(layer.GetClippingBox() != testBox);
234
235   layer.SetClippingBox(5,6, 77,83);
236   DALI_TEST_CHECK(layer.GetClippingBox() == 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.GetClippingBox() == ClippingBox(0,0,0,0));
247   END_TEST;
248 }
249
250 static int gTestSortFunctionCalled;
251
252 static float TestSortFunction(const Vector3& /*position*/, float /*sortModifier*/)
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   BitmapImage img = BitmapImage::New( 1,1 );
263   // create two transparent actors so there is something to sort
264   ImageActor actor = ImageActor::New( img );
265   ImageActor actor2 = ImageActor::New( img );
266   actor.SetSize(1,1);
267   actor.SetColor( Vector4(1, 1, 1, 0.5f ) ); // 50% transparent
268   actor2.SetSize(1,1);
269   actor2.SetColor( 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.GetDepth(), 0u, TEST_LOCATION );
298   // add to stage
299   Stage::GetCurrent().Add( layer );
300   layer.RaiseAbove( root );
301   DALI_TEST_EQUALS( layer.GetDepth(), 1u, TEST_LOCATION );
302   root.RaiseAbove( layer );
303   DALI_TEST_EQUALS( layer.GetDepth(), 0u, TEST_LOCATION );
304   layer.RaiseAbove( layer );
305   DALI_TEST_EQUALS( layer.GetDepth(), 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.GetDepth(), layer2.GetDepth(), TEST_LOCATION );
312   layer2.RaiseAbove( layer );
313   DALI_TEST_GREATER( layer2.GetDepth(), layer.GetDepth(), TEST_LOCATION );
314   root.RaiseAbove( layer2 );
315   DALI_TEST_GREATER( root.GetDepth(), layer2.GetDepth(), 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.GetDepth(), 0u, TEST_LOCATION );
329   // add to stage
330   Stage::GetCurrent().Add( layer );
331   DALI_TEST_EQUALS( layer.GetDepth(), 1u, TEST_LOCATION );
332   layer.LowerBelow( root );
333   DALI_TEST_EQUALS( layer.GetDepth(), 0u, TEST_LOCATION );
334   root.LowerBelow( layer );
335   DALI_TEST_EQUALS( layer.GetDepth(), 1u, TEST_LOCATION );
336   layer.LowerBelow( layer );
337   DALI_TEST_EQUALS( layer.GetDepth(), 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.GetDepth(), layer.GetDepth(), TEST_LOCATION );
344   layer2.LowerBelow( layer );
345   DALI_TEST_GREATER( layer.GetDepth(), layer2.GetDepth(), TEST_LOCATION );
346   root.LowerBelow( layer2 );
347   DALI_TEST_GREATER( layer2.GetDepth(), root.GetDepth(), 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.GetDepth(), 0u, TEST_LOCATION );
361   root.MoveAbove( layer );
362   // root depth is zero as layer is not on stage
363   DALI_TEST_EQUALS( layer.GetDepth(), 0u, TEST_LOCATION );
364   // add to stage
365   Stage::GetCurrent().Add( layer );
366   layer.MoveAbove( root );
367   DALI_TEST_EQUALS( layer.GetDepth(), 1u, TEST_LOCATION );
368   DALI_TEST_EQUALS( root.GetDepth(), 0u, TEST_LOCATION );
369   root.MoveAbove( layer );
370   DALI_TEST_EQUALS( layer.GetDepth(), 0u, TEST_LOCATION );
371   DALI_TEST_EQUALS( root.GetDepth(), 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.GetDepth(), layer2.GetDepth() + 1u, TEST_LOCATION );
378   layer2.MoveAbove( root );
379   DALI_TEST_EQUALS( layer2.GetDepth(), root.GetDepth() + 1u, TEST_LOCATION );
380   root.MoveAbove( layer );
381   DALI_TEST_EQUALS( root.GetDepth(), layer.GetDepth() + 1u, TEST_LOCATION );
382
383   Layer layer3 = Layer::New();
384   Stage::GetCurrent().Add( layer3 );
385   DALI_TEST_EQUALS( layer3.GetDepth(), 3u, TEST_LOCATION );
386   root.MoveAbove( layer3 );
387   DALI_TEST_EQUALS( root.GetDepth(), 3u, TEST_LOCATION );
388   DALI_TEST_EQUALS( layer3.GetDepth(), 2u, TEST_LOCATION );
389   DALI_TEST_EQUALS( Stage::GetCurrent().GetLayer( 0 ).GetDepth(), 0u, TEST_LOCATION );
390   layer3.MoveAbove( Stage::GetCurrent().GetLayer( 0 ) );
391   DALI_TEST_EQUALS( layer3.GetDepth(), 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.GetDepth(), 0u, TEST_LOCATION );
405   root.MoveBelow( layer );
406   // root depth is zero as layer is not on stage
407   DALI_TEST_EQUALS( layer.GetDepth(), 0u, TEST_LOCATION );
408   // add to stage
409   Stage::GetCurrent().Add( layer );
410   layer.MoveBelow( root );
411   DALI_TEST_EQUALS( layer.GetDepth(), 0u, TEST_LOCATION );
412   DALI_TEST_EQUALS( root.GetDepth(), 1u, TEST_LOCATION );
413   root.MoveBelow( layer );
414   DALI_TEST_EQUALS( layer.GetDepth(), 1u, TEST_LOCATION );
415   DALI_TEST_EQUALS( root.GetDepth(), 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.GetDepth(), layer2.GetDepth() - 1u, TEST_LOCATION );
422   layer2.MoveBelow( root );
423   DALI_TEST_EQUALS( layer2.GetDepth(), root.GetDepth() - 1u, TEST_LOCATION );
424   root.MoveBelow( layer );
425   DALI_TEST_EQUALS( root.GetDepth(), layer.GetDepth() - 1u, TEST_LOCATION );
426
427   Layer layer3 = Layer::New();
428   Stage::GetCurrent().Add( layer3 );
429   DALI_TEST_EQUALS( layer3.GetDepth(), 3u, TEST_LOCATION );
430   root.MoveBelow( layer3 );
431   DALI_TEST_EQUALS( root.GetDepth(), 2u, TEST_LOCATION );
432   DALI_TEST_EQUALS( layer3.GetDepth(), 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::CLIPPING_ENABLE );
445   indices.push_back(Layer::CLIPPING_BOX    );
446
447   DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
448
449   for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
450   {
451     DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
452     DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
453     DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
454     DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) );  // just checking call succeeds
455   }
456
457   // set/get one of them
458   actor.SetClippingBox(0,0,0,0);
459
460   ClippingBox testBox(10,20,30,40);
461   DALI_TEST_CHECK(actor.GetClippingBox() != testBox);
462
463   actor.SetProperty(Layer::CLIPPING_BOX, Property::Value(Rect<int>(testBox)));
464
465   DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(Layer::CLIPPING_BOX)) ;
466
467   Property::Value v = actor.GetProperty(Layer::CLIPPING_BOX);
468
469   DALI_TEST_CHECK(v.Get<Rect<int> >() == testBox);
470
471   // set the same boundaries, but through a clipping box object
472   actor.SetClippingBox( testBox );
473
474   DALI_TEST_CHECK( actor.GetClippingBox() == testBox );
475
476   END_TEST;
477 }
478
479 int UtcDaliLayerSetDepthTestDisabled(void)
480 {
481   TestApplication application;
482   tet_infoline("Testing Dali::Layer::SetDepthTestDisabled() ");
483
484   Layer actor = Layer::New();
485
486   DALI_TEST_CHECK( !actor.IsDepthTestDisabled() );
487
488   actor.SetDepthTestDisabled( true );
489   DALI_TEST_CHECK( actor.IsDepthTestDisabled() );
490   END_TEST;
491 }
492
493 int UtcDaliLayerCreateDestroy(void)
494 {
495   tet_infoline("Testing Dali::Layer::CreateDestroy() ");
496   Layer* layer = new Layer;
497   DALI_TEST_CHECK( layer );
498   delete layer;
499   END_TEST;
500 }
501
502 int UtcDaliLayerPropertyIndices(void)
503 {
504   TestApplication application;
505   Actor basicActor = Actor::New();
506   Layer layer = Layer::New();
507
508   Property::IndexContainer indices;
509   layer.GetPropertyIndices( indices );
510   DALI_TEST_CHECK( indices.size() > basicActor.GetPropertyCount() );
511   DALI_TEST_EQUALS( indices.size(), layer.GetPropertyCount(), TEST_LOCATION );
512   END_TEST;
513 }