2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
21 #include <dali/dali.h>
23 #include <dali-test-suite-utils.h>
27 void layer_test_startup(void)
29 test_return_value = TET_UNDEF;
32 void layer_test_cleanup(void)
34 test_return_value = TET_PASS;
38 int UtcDaliLayerNew(void)
40 TestApplication application;
41 Layer layer = Layer::New();
43 DALI_TEST_CHECK(layer);
47 int UtcDaliLayerDownCast(void)
49 TestApplication application;
50 tet_infoline("Testing Dali::Layer::DownCast()");
52 Layer actor1 = Layer::New();
53 Actor anActor = Actor::New();
56 Actor child = anActor.GetChildAt(0);
57 Layer layer = DownCast< Layer >(child);
59 DALI_TEST_CHECK(layer);
63 int UtcDaliLayerDownCast2(void)
65 TestApplication application;
66 tet_infoline("Testing Dali::Layer::DownCast()");
68 Actor actor1 = Actor::New();
69 Actor anActor = Actor::New();
72 Actor child = anActor.GetChildAt(0);
73 Layer layer = DownCast< Layer >(child);
74 DALI_TEST_CHECK(!layer);
76 Actor unInitialzedActor;
77 layer = Layer::DownCast( unInitialzedActor );
78 DALI_TEST_CHECK(!layer);
83 int UtcDaliLayerGetDepth(void)
85 tet_infoline("Testing Dali::Layer::GetDepth()");
86 TestApplication application;
87 Layer layer1 = Layer::New();
88 Layer layer2 = Layer::New();
90 // layers are not on stage
91 DALI_TEST_EQUALS(layer1.GetDepth(), 0u, TEST_LOCATION);
92 DALI_TEST_EQUALS(layer2.GetDepth(), 0u, TEST_LOCATION);
95 Layer root = Stage::GetCurrent().GetLayer( 0 );
96 DALI_TEST_EQUALS(root.GetDepth(), 0u, TEST_LOCATION);
98 Stage::GetCurrent().Add(layer1);
99 Stage::GetCurrent().Add(layer2);
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);
107 int UtcDaliLayerRaise(void)
109 tet_infoline("Testing Dali::Layer::Raise()");
110 TestApplication application;
111 Layer layer1 = Layer::New();
112 Layer layer2 = Layer::New();
114 Stage::GetCurrent().Add(layer1);
115 Stage::GetCurrent().Add(layer2);
116 DALI_TEST_EQUALS(layer1.GetDepth(), 1u, TEST_LOCATION);
119 DALI_TEST_EQUALS(layer1.GetDepth(), 2u, TEST_LOCATION);
122 Layer root = Stage::GetCurrent().GetLayer( 0 );
123 DALI_TEST_EQUALS( root.GetDepth(), 0u, TEST_LOCATION);
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);
131 int UtcDaliLayerLower(void)
133 tet_infoline("Testing Dali::Layer::Lower()");
134 TestApplication application;
135 Layer layer1 = Layer::New();
136 Layer layer2 = Layer::New();
138 Stage::GetCurrent().Add(layer1);
139 Stage::GetCurrent().Add(layer2);
140 DALI_TEST_EQUALS(layer2.GetDepth(), 2u, TEST_LOCATION);
143 DALI_TEST_EQUALS(layer2.GetDepth(), 1u, TEST_LOCATION);
146 Layer root = Stage::GetCurrent().GetLayer( 0 );
148 DALI_TEST_EQUALS( root.GetDepth(), 0u, TEST_LOCATION);
150 DALI_TEST_EQUALS( root.GetDepth(), 1u, TEST_LOCATION);
151 DALI_TEST_EQUALS(layer2.GetDepth(), 0u, TEST_LOCATION);
155 int UtcDaliLayerRaiseToTop(void)
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();
163 Stage::GetCurrent().Add(layer1);
164 Stage::GetCurrent().Add(layer2);
165 Stage::GetCurrent().Add(layer3);
166 Layer root = Stage::GetCurrent().GetLayer( 0 );
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);
174 DALI_TEST_EQUALS(layer1.GetDepth(), 3u, TEST_LOCATION);
177 DALI_TEST_EQUALS( root.GetDepth(), 3u, TEST_LOCATION);
181 int UtcDaliLayerLowerToBottom(void)
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();
189 Stage::GetCurrent().Add(layer1);
190 Stage::GetCurrent().Add(layer2);
191 Stage::GetCurrent().Add(layer3);
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);
197 layer3.LowerToBottom();
198 DALI_TEST_EQUALS(layer3.GetDepth(), 0u, TEST_LOCATION);
202 int UtcDaliLayerSetClipping(void)
204 tet_infoline("Testing Dali::Layer::SetClipping()");
205 TestApplication application;
207 Layer layer = Layer::New();
208 DALI_TEST_CHECK(!layer.IsClipping());
210 layer.SetClipping(true);
211 DALI_TEST_CHECK(layer.IsClipping());
215 int UtcDaliLayerIsClipping(void)
217 tet_infoline("Testing Dali::Layer::IsClipping()");
218 TestApplication application;
220 Layer layer = Layer::New();
221 DALI_TEST_CHECK(!layer.IsClipping());
225 int UtcDaliLayerSetClippingBox(void)
227 tet_infoline("Testing Dali::Layer::SetClippingBox()");
228 TestApplication application;
230 ClippingBox testBox(5,6, 77,83);
232 Layer layer = Layer::New();
233 DALI_TEST_CHECK(layer.GetClippingBox() != testBox);
235 layer.SetClippingBox(5,6, 77,83);
236 DALI_TEST_CHECK(layer.GetClippingBox() == testBox);
240 int UtcDaliLayerGetClippingBox(void)
242 tet_infoline("Testing Dali::Layer::GetClippingBox()");
243 TestApplication application;
245 Layer layer = Layer::New();
246 DALI_TEST_CHECK(layer.GetClippingBox() == ClippingBox(0,0,0,0));
250 static int gTestSortFunctionCalled;
252 static float TestSortFunction(const Vector3& /*position*/, float /*sortModifier*/)
254 ++gTestSortFunctionCalled;
258 int UtcDaliLayerSetSortFunction(void)
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 );
267 actor.SetColor( Vector4(1, 1, 1, 0.5f ) ); // 50% transparent
269 actor2.SetColor( Vector4(1, 1, 1, 0.5f ) ); // 50% transparent
272 Stage::GetCurrent().Add( actor );
273 Stage::GetCurrent().Add( actor2 );
275 Layer root = Stage::GetCurrent().GetLayer( 0 );
276 gTestSortFunctionCalled = 0;
277 root.SetSortFunction(TestSortFunction);
279 // flush the queue and render once
280 application.SendNotification();
281 application.Render();
283 DALI_TEST_CHECK( gTestSortFunctionCalled > 0 );
288 int UtcDaliLayerRaiseAbove(void)
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 );
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 );
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 );
319 int UtcDaliLayerRaiseBelow(void)
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 );
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 );
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 );
351 int UtcDaliLayerMoveAbove(void)
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 );
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 );
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 );
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 );
395 int UtcDaliLayerMoveBelow(void)
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 );
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 );
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 );
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 );
436 int UtcDaliLayerDefaultProperties(void)
438 TestApplication application;
439 tet_infoline("Testing Dali::Layer DefaultProperties");
441 Layer actor = Layer::New();
443 std::vector<Property::Index> indices ;
444 indices.push_back(Layer::CLIPPING_ENABLE );
445 indices.push_back(Layer::CLIPPING_BOX );
447 DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
449 for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
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
457 // set/get one of them
458 actor.SetClippingBox(0,0,0,0);
460 ClippingBox testBox(10,20,30,40);
461 DALI_TEST_CHECK(actor.GetClippingBox() != testBox);
463 actor.SetProperty(Layer::CLIPPING_BOX, Property::Value(Rect<int>(testBox)));
465 DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(Layer::CLIPPING_BOX)) ;
467 Property::Value v = actor.GetProperty(Layer::CLIPPING_BOX);
469 DALI_TEST_CHECK(v.Get<Rect<int> >() == testBox);
471 // set the same boundaries, but through a clipping box object
472 actor.SetClippingBox( testBox );
474 DALI_TEST_CHECK( actor.GetClippingBox() == testBox );
479 int UtcDaliLayerSetDepthTestDisabled(void)
481 TestApplication application;
482 tet_infoline("Testing Dali::Layer::SetDepthTestDisabled() ");
484 Layer actor = Layer::New();
486 DALI_TEST_CHECK( !actor.IsDepthTestDisabled() );
488 actor.SetDepthTestDisabled( true );
489 DALI_TEST_CHECK( actor.IsDepthTestDisabled() );
493 int UtcDaliLayerCreateDestroy(void)
495 tet_infoline("Testing Dali::Layer::CreateDestroy() ");
496 Layer* layer = new Layer;
497 DALI_TEST_CHECK( layer );
502 int UtcDaliLayerPropertyIndices(void)
504 TestApplication application;
505 Actor basicActor = Actor::New();
506 Layer layer = Layer::New();
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 );