2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali-test-suite-utils.h>
19 #include <dali/public-api/dali-core.h>
26 void layer_test_startup(void)
28 test_return_value = TET_UNDEF;
31 void layer_test_cleanup(void)
33 test_return_value = TET_PASS;
36 int UtcDaliLayerNew(void)
38 TestApplication application;
39 Layer layer = Layer::New();
41 DALI_TEST_CHECK(layer);
45 int UtcDaliLayerDownCast(void)
47 TestApplication application;
48 tet_infoline("Testing Dali::Layer::DownCast()");
50 Layer actor1 = Layer::New();
51 Actor anActor = Actor::New();
54 Actor child = anActor.GetChildAt(0);
55 Layer layer = DownCast<Layer>(child);
57 DALI_TEST_CHECK(layer);
61 int UtcDaliLayerDownCast2(void)
63 TestApplication application;
64 tet_infoline("Testing Dali::Layer::DownCast()");
66 Actor actor1 = Actor::New();
67 Actor anActor = Actor::New();
70 Actor child = anActor.GetChildAt(0);
71 Layer layer = DownCast<Layer>(child);
72 DALI_TEST_CHECK(!layer);
74 Actor unInitialzedActor;
75 layer = Layer::DownCast(unInitialzedActor);
76 DALI_TEST_CHECK(!layer);
80 int UtcDaliLayerMoveConstructor(void)
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);
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);
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);
101 int UtcDaliLayerMoveAssignment(void)
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);
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);
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);
123 int UtcDaliLayerGetDepth(void)
125 tet_infoline("Testing Dali::Layer::GetDepth()");
126 TestApplication application;
127 Layer layer1 = Layer::New();
128 Layer layer2 = Layer::New();
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);
135 Layer root = application.GetScene().GetLayer(0);
136 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
138 application.GetScene().Add(layer1);
139 application.GetScene().Add(layer2);
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);
147 int UtcDaliLayerRaise1(void)
149 tet_infoline("Testing Dali::Layer::Raise()");
150 TestApplication application;
151 Layer layer1 = Layer::New();
152 Layer layer2 = Layer::New();
154 application.GetScene().Add(layer1);
155 application.GetScene().Add(layer2);
156 DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
159 DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
162 Layer root = application.GetScene().GetLayer(0);
163 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
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);
171 int UtcDaliLayerRaise2(void)
173 tet_infoline("Testing Dali::Layer raise Action");
174 TestApplication application;
175 Layer layer1 = Layer::New();
176 Layer layer2 = Layer::New();
178 application.GetScene().Add(layer1);
179 application.GetScene().Add(layer2);
180 DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
183 DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
186 Layer root = application.GetScene().GetLayer(0);
187 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
189 GetImplementation(root).DoAction("raise", Property::Map());
191 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
192 DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
193 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
198 int UtcDaliLayerLower1(void)
200 tet_infoline("Testing Dali::Layer::Lower()");
201 TestApplication application;
202 Layer layer1 = Layer::New();
203 Layer layer2 = Layer::New();
205 application.GetScene().Add(layer1);
206 application.GetScene().Add(layer2);
207 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
210 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
213 Layer root = application.GetScene().GetLayer(0);
215 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
217 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
218 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
223 int UtcDaliLayerLower2(void)
225 tet_infoline("Testing Dali::Layer lower Action");
226 TestApplication application;
227 Layer layer1 = Layer::New();
228 Layer layer2 = Layer::New();
230 application.GetScene().Add(layer1);
231 application.GetScene().Add(layer2);
232 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
235 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
238 Layer root = application.GetScene().GetLayer(0);
239 GetImplementation(root).DoAction("lower", Property::Map());
240 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
242 GetImplementation(layer2).DoAction("lower", Property::Map());
243 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
244 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
248 int UtcDaliLayerRaiseToTop1(void)
250 tet_infoline("Testing Dali::Layer::RaiseToTop()");
251 TestApplication application;
252 Layer layer1 = Layer::New();
253 Layer layer2 = Layer::New();
254 Layer layer3 = Layer::New();
256 application.GetScene().Add(layer1);
257 application.GetScene().Add(layer2);
258 application.GetScene().Add(layer3);
259 Layer root = application.GetScene().GetLayer(0);
261 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
262 DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
263 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
264 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
267 DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
270 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
274 int UtcDaliLayerRaiseToTop2(void)
276 tet_infoline("Testing Dali::Layer raiseToTop Action");
277 TestApplication application;
278 Layer layer1 = Layer::New();
279 Layer layer2 = Layer::New();
280 Layer layer3 = Layer::New();
282 application.GetScene().Add(layer1);
283 application.GetScene().Add(layer2);
284 application.GetScene().Add(layer3);
285 Layer root = application.GetScene().GetLayer(0);
287 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
288 DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
289 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
290 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
292 GetImplementation(layer1).DoAction("raiseToTop", Property::Map());
293 DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
295 GetImplementation(root).DoAction("raiseToTop", Property::Map());
296 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
300 int UtcDaliLayerLowerToBottom1(void)
302 tet_infoline("Testing Dali::Layer::LowerToBottom()");
303 TestApplication application;
304 Layer layer1 = Layer::New();
305 Layer layer2 = Layer::New();
306 Layer layer3 = Layer::New();
308 application.GetScene().Add(layer1);
309 application.GetScene().Add(layer2);
310 application.GetScene().Add(layer3);
312 DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
313 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
314 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
316 layer3.LowerToBottom();
317 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
321 int UtcDaliLayerLowerToBottom2(void)
323 tet_infoline("Testing Dali::Layer lowerToBottom Action");
324 TestApplication application;
325 Layer layer1 = Layer::New();
326 Layer layer2 = Layer::New();
327 Layer layer3 = Layer::New();
329 application.GetScene().Add(layer1);
330 application.GetScene().Add(layer2);
331 application.GetScene().Add(layer3);
333 DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
334 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
335 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
337 GetImplementation(layer3).DoAction("lowerToBottom", Property::Map());
338 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
343 int UtcDaliLayerSetClipping(void)
345 tet_infoline("Testing Dali::Layer::SetClipping()");
346 TestApplication application;
348 Layer layer = Layer::New();
349 DALI_TEST_CHECK(!layer.GetProperty<bool>(Layer::Property::CLIPPING_ENABLE));
351 layer.SetProperty(Layer::Property::CLIPPING_ENABLE, true);
352 DALI_TEST_CHECK(layer.GetProperty<bool>(Layer::Property::CLIPPING_ENABLE));
356 int UtcDaliLayerIsClipping(void)
358 tet_infoline("Testing Dali::Layer::IsClipping()");
359 TestApplication application;
361 Layer layer = Layer::New();
362 DALI_TEST_CHECK(!layer.GetProperty<bool>(Layer::Property::CLIPPING_ENABLE));
366 int UtcDaliLayerSetClippingBox(void)
368 tet_infoline("Testing Dali::Layer::SetClippingBox()");
369 TestApplication application;
371 ClippingBox testBox(5, 6, 77, 83);
373 Layer layer = Layer::New();
374 DALI_TEST_CHECK(layer.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) != testBox);
375 layer.SetProperty(Layer::Property::CLIPPING_BOX, testBox);
376 DALI_TEST_CHECK(layer.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) == testBox);
380 int UtcDaliLayerGetClippingBox(void)
382 tet_infoline("Testing Dali::Layer::GetClippingBox()");
383 TestApplication application;
385 Layer layer = Layer::New();
386 DALI_TEST_CHECK(layer.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) == ClippingBox(0, 0, 0, 0));
390 static int gTestSortFunctionCalled;
392 static float TestSortFunction(const Vector3& /*position*/)
394 ++gTestSortFunctionCalled;
398 int UtcDaliLayerSetSortFunction(void)
400 tet_infoline("Testing Dali::Layer::SetSortFunction()");
401 TestApplication application;
403 // create two transparent actors so there is something to sort
404 Actor actor = CreateRenderableActor();
405 Actor actor2 = CreateRenderableActor();
406 actor.SetProperty(Actor::Property::SIZE, Vector2(1, 1));
407 actor.SetProperty(Actor::Property::COLOR, Vector4(1, 1, 1, 0.5f)); // 50% transparent
408 actor2.SetProperty(Actor::Property::SIZE, Vector2(1, 1));
409 actor2.SetProperty(Actor::Property::COLOR, Vector4(1, 1, 1, 0.5f)); // 50% transparent
412 application.GetScene().Add(actor);
413 application.GetScene().Add(actor2);
415 Layer root = application.GetScene().GetLayer(0);
416 gTestSortFunctionCalled = 0;
417 root.SetSortFunction(TestSortFunction);
419 // flush the queue and render once
420 application.SendNotification();
421 application.Render();
423 DALI_TEST_CHECK(gTestSortFunctionCalled > 0);
427 int UtcDaliLayerRaiseAbove(void)
429 tet_infoline("Testing Dali::Layer::RaiseAbove()");
430 TestApplication application;
431 Layer layer = Layer::New();
432 // try to raise above root layer
433 Layer root = application.GetScene().GetLayer(0);
434 layer.RaiseAbove(root);
435 // layer depth is zero as its not on scene
436 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
438 application.GetScene().Add(layer);
439 layer.RaiseAbove(root);
440 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
441 root.RaiseAbove(layer);
442 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
443 layer.RaiseAbove(layer);
444 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
446 // make another layer on the scene
447 Layer layer2 = Layer::New();
448 application.GetScene().Add(layer2);
449 layer.RaiseAbove(layer2);
450 DALI_TEST_GREATER(layer.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
451 layer2.RaiseAbove(layer);
452 DALI_TEST_GREATER(layer2.GetProperty<int>(Layer::Property::DEPTH), layer.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
453 root.RaiseAbove(layer2);
454 DALI_TEST_GREATER(root.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
458 int UtcDaliLayerRaiseBelow(void)
460 tet_infoline("Testing Dali::Layer::RaiseBelow()");
461 TestApplication application;
462 Layer layer = Layer::New();
463 // try to lower below root layer
464 Layer root = application.GetScene().GetLayer(0);
465 layer.LowerBelow(root);
466 // layer depth is zero as its not on scene
467 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
469 application.GetScene().Add(layer);
470 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
471 layer.LowerBelow(root);
472 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
473 root.LowerBelow(layer);
474 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
475 layer.LowerBelow(layer);
476 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
478 // make another layer on the scene
479 Layer layer2 = Layer::New();
480 application.GetScene().Add(layer2);
481 layer.LowerBelow(layer2);
482 DALI_TEST_GREATER(layer2.GetProperty<int>(Layer::Property::DEPTH), layer.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
483 layer2.LowerBelow(layer);
484 DALI_TEST_GREATER(layer.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
485 root.LowerBelow(layer2);
486 DALI_TEST_GREATER(layer2.GetProperty<int>(Layer::Property::DEPTH), root.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
490 int UtcDaliLayerMoveAbove(void)
492 tet_infoline("Testing Dali::Layer::MoveAbove()");
493 TestApplication application;
494 Layer layer = Layer::New();
495 // try to raise above root layer
496 Layer root = application.GetScene().GetLayer(0);
497 layer.MoveAbove(root);
498 // layer depth is zero as its not on scene
499 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
500 root.MoveAbove(layer);
501 // root depth is zero as layer is not on scene
502 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
504 application.GetScene().Add(layer);
505 layer.MoveAbove(root);
506 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
507 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
508 root.MoveAbove(layer);
509 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
510 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
512 // make another layer on the scene
513 Layer layer2 = Layer::New();
514 application.GetScene().Add(layer2);
515 layer.MoveAbove(layer2);
516 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH) + 1u, TEST_LOCATION);
517 layer2.MoveAbove(root);
518 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), root.GetProperty<int>(Layer::Property::DEPTH) + 1u, TEST_LOCATION);
519 root.MoveAbove(layer);
520 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), layer.GetProperty<int>(Layer::Property::DEPTH) + 1u, TEST_LOCATION);
522 Layer layer3 = Layer::New();
523 application.GetScene().Add(layer3);
524 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
525 root.MoveAbove(layer3);
526 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
527 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
528 DALI_TEST_EQUALS(application.GetScene().GetLayer(0).GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
529 layer3.MoveAbove(application.GetScene().GetLayer(0));
530 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
534 int UtcDaliLayerMoveBelow(void)
536 tet_infoline("Testing Dali::Layer::MoveBelow()");
537 TestApplication application;
538 Layer layer = Layer::New();
539 // try to raise above root layer
540 Layer root = application.GetScene().GetLayer(0);
541 layer.MoveBelow(root);
542 // layer depth is zero as its not on scene
543 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
544 root.MoveBelow(layer);
545 // root depth is zero as layer is not on scene
546 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
548 application.GetScene().Add(layer);
549 layer.MoveBelow(root);
550 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
551 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
552 root.MoveBelow(layer);
553 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
554 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
556 // make another layer on the scene
557 Layer layer2 = Layer::New();
558 application.GetScene().Add(layer2);
559 layer.MoveBelow(layer2);
560 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH) - 1u, TEST_LOCATION);
561 layer2.MoveBelow(root);
562 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), root.GetProperty<int>(Layer::Property::DEPTH) - 1u, TEST_LOCATION);
563 root.MoveBelow(layer);
564 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), layer.GetProperty<int>(Layer::Property::DEPTH) - 1u, TEST_LOCATION);
566 Layer layer3 = Layer::New();
567 application.GetScene().Add(layer3);
568 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
569 root.MoveBelow(layer3);
570 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
571 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
575 int UtcDaliLayerDefaultProperties(void)
577 TestApplication application;
578 tet_infoline("Testing Dali::Layer DefaultProperties");
580 Layer actor = Layer::New();
582 std::vector<Property::Index> indices;
583 indices.push_back(Layer::Property::CLIPPING_ENABLE);
584 indices.push_back(Layer::Property::CLIPPING_BOX);
585 indices.push_back(Layer::Property::BEHAVIOR);
586 indices.push_back(Layer::Property::DEPTH);
587 indices.push_back(Layer::Property::DEPTH_TEST);
588 indices.push_back(Layer::Property::CONSUMES_TOUCH);
589 indices.push_back(Layer::Property::CONSUMES_HOVER);
591 DALI_TEST_CHECK(actor.GetPropertyCount() == (Actor::New().GetPropertyCount() + indices.size()));
593 for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
595 DALI_TEST_CHECK(*iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)));
596 DALI_TEST_CHECK(*iter == Layer::Property::DEPTH ? !actor.IsPropertyWritable(*iter) : actor.IsPropertyWritable(*iter));
597 DALI_TEST_CHECK(!actor.IsPropertyAnimatable(*iter));
598 DALI_TEST_CHECK(actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter)); // just checking call succeeds
601 // set/get one of them
602 actor.SetProperty(Layer::Property::CLIPPING_BOX, ClippingBox(0, 0, 0, 0));
604 ClippingBox testBox(10, 20, 30, 40);
605 DALI_TEST_CHECK(actor.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) != testBox);
607 actor.SetProperty(Layer::Property::CLIPPING_BOX, Property::Value(Rect<int>(testBox)));
609 DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(Layer::Property::CLIPPING_BOX));
611 Property::Value v = actor.GetProperty(Layer::Property::CLIPPING_BOX);
612 DALI_TEST_CHECK(v.Get<Rect<int> >() == testBox);
614 v = actor.GetCurrentProperty(Layer::Property::CLIPPING_BOX);
615 DALI_TEST_CHECK(v.Get<Rect<int> >() == testBox);
617 // set the same boundaries, but through a clipping box object
618 actor.SetProperty(Layer::Property::CLIPPING_BOX, testBox);
619 DALI_TEST_CHECK(actor.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) == testBox);
621 actor.SetProperty(Layer::Property::BEHAVIOR, Property::Value(Layer::LAYER_UI));
622 DALI_TEST_CHECK(Property::INTEGER == actor.GetPropertyType(Layer::Property::BEHAVIOR));
624 Property::Value behavior = actor.GetProperty(Layer::Property::BEHAVIOR);
625 DALI_TEST_EQUALS(behavior.Get<Dali::Layer::Behavior>(), Layer::LAYER_UI, TEST_LOCATION);
627 behavior = actor.GetCurrentProperty(Layer::Property::BEHAVIOR);
628 DALI_TEST_EQUALS(behavior.Get<Dali::Layer::Behavior>(), Layer::LAYER_UI, TEST_LOCATION);
633 int UtcDaliLayerSetDepthTestDisabled(void)
635 TestApplication application;
636 tet_infoline("Testing Dali::Layer::SetDepthTestDisabled() ");
638 Layer actor = Layer::New();
639 // Note that Layer::Property::DEPTH_TEST does not depend on layer behavior,
640 // as 2D layers can still have depth tests performed on a per-renderer basis.
642 DALI_TEST_CHECK(!actor.GetProperty<bool>(Layer::Property::DEPTH_TEST));
644 // Check Set / Unset.
645 actor.SetProperty(Layer::Property::DEPTH_TEST, true);
646 DALI_TEST_CHECK(actor.GetProperty<bool>(Layer::Property::DEPTH_TEST));
647 actor.SetProperty(Layer::Property::DEPTH_TEST, false);
648 DALI_TEST_CHECK(!actor.GetProperty<bool>(Layer::Property::DEPTH_TEST));
653 int UtcDaliLayerCreateDestroy(void)
655 tet_infoline("Testing Dali::Layer::CreateDestroy() ");
656 Layer* layer = new Layer;
657 DALI_TEST_CHECK(layer);
662 int UtcDaliLayerPropertyIndices(void)
664 TestApplication application;
665 Actor basicActor = Actor::New();
666 Layer layer = Layer::New();
668 Property::IndexContainer indices;
669 layer.GetPropertyIndices(indices);
670 DALI_TEST_CHECK(indices.Size() > basicActor.GetPropertyCount());
671 DALI_TEST_EQUALS(indices.Size(), layer.GetPropertyCount(), TEST_LOCATION);
675 int UtcDaliLayerTouchConsumed(void)
677 TestApplication application;
678 Layer layer = Layer::New();
680 DALI_TEST_EQUALS(layer.GetProperty<bool>(Layer::Property::CONSUMES_TOUCH), false, TEST_LOCATION);
681 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
682 DALI_TEST_EQUALS(layer.GetProperty<bool>(Layer::Property::CONSUMES_TOUCH), true, TEST_LOCATION);
686 int UtcDaliLayerHoverConsumed(void)
688 TestApplication application;
689 Layer layer = Layer::New();
691 DALI_TEST_EQUALS(layer.GetProperty<bool>(Layer::Property::CONSUMES_HOVER), false, TEST_LOCATION);
692 layer.SetProperty(Layer::Property::CONSUMES_HOVER, true);
693 DALI_TEST_EQUALS(layer.GetProperty<bool>(Layer::Property::CONSUMES_HOVER), true, TEST_LOCATION);
697 int UtcDaliLayerClippingGLCalls(void)
699 TestApplication application;
700 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
701 Integration::Scene scene(application.GetScene());
703 ClippingBox testBox(5, 6, 77, 83);
704 Layer layer = application.GetScene().GetRootLayer();
705 layer.SetProperty(Layer::Property::CLIPPING_ENABLE, true);
706 layer.SetProperty(Layer::Property::CLIPPING_BOX, testBox);
708 // Add at least one renderable actor so the GL calls are actually made
709 Texture img = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
710 Actor actor = CreateRenderableActor(img);
713 // flush the queue and render once
714 application.SendNotification();
715 application.Render();
717 DALI_TEST_EQUALS(testBox.x, glScissorParams.x, TEST_LOCATION);
718 DALI_TEST_EQUALS(testBox.y, (int)(scene.GetSize().height - glScissorParams.y - testBox.height), TEST_LOCATION); // GL Coordinates are from bottom left
719 DALI_TEST_EQUALS(testBox.width, glScissorParams.width, TEST_LOCATION);
720 DALI_TEST_EQUALS(testBox.height, glScissorParams.height, TEST_LOCATION);
724 int UtcDaliLayerBehaviour(void)
726 TestApplication application;
727 Layer layer = Layer::New();
729 DALI_TEST_EQUALS(layer.GetProperty<Layer::Behavior>(Layer::Property::BEHAVIOR), Dali::Layer::LAYER_UI, TEST_LOCATION);
730 layer.SetProperty(Layer::Property::BEHAVIOR, Dali::Layer::LAYER_3D);
731 DALI_TEST_EQUALS(layer.GetProperty<Layer::Behavior>(Layer::Property::BEHAVIOR), Dali::Layer::LAYER_3D, TEST_LOCATION);
735 Actor CreateActor(bool withAlpha)
737 Texture texture = Texture::New(TextureType::TEXTURE_2D, withAlpha ? Pixel::Format::RGBA8888 : Pixel::Format::RGB888, 1u, 1u);
739 Actor actor = CreateRenderableActor(texture);
740 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
741 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
746 int UtcDaliLayer3DSort(void)
748 tet_infoline("Testing LAYER_3D sort coverage test");
749 TestApplication application;
750 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
751 TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
753 application.GetScene().GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
756 Actor actor = CreateActor(false);
757 application.GetScene().Add(actor);
759 // Create child actors.
760 Actor child1 = CreateActor(true);
762 Actor child2 = CreateActor(false);
765 enabledDisableTrace.Reset();
766 enabledDisableTrace.Enable(true);
767 application.SendNotification();
768 application.Render();
769 enabledDisableTrace.Enable(false);
771 DALI_TEST_CHECK(enabledDisableTrace.FindMethodAndParams("Enable", "2929")); // 2929 is GL_DEPTH_TEST
776 int UtcDaliLayerLowerBelowNegative(void)
778 TestApplication application;
779 Dali::Layer instance;
783 instance.LowerBelow(arg1);
784 DALI_TEST_CHECK(false); // Should not get here
788 DALI_TEST_CHECK(true); // We expect an assert
793 int UtcDaliLayerRaiseAboveNegative(void)
795 TestApplication application;
796 Dali::Layer instance;
800 instance.RaiseAbove(arg1);
801 DALI_TEST_CHECK(false); // Should not get here
805 DALI_TEST_CHECK(true); // We expect an assert
810 int UtcDaliLayerRaiseToTopNegative(void)
812 TestApplication application;
813 Dali::Layer instance;
816 instance.RaiseToTop();
817 DALI_TEST_CHECK(false); // Should not get here
821 DALI_TEST_CHECK(true); // We expect an assert
826 int UtcDaliLayerLowerToBottomNegative(void)
828 TestApplication application;
829 Dali::Layer instance;
832 instance.LowerToBottom();
833 DALI_TEST_CHECK(false); // Should not get here
837 DALI_TEST_CHECK(true); // We expect an assert
842 int UtcDaliLayerSetSortFunctionNegative(void)
844 TestApplication application;
845 Dali::Layer instance;
848 Layer::SortFunctionType function = nullptr;
849 instance.SetSortFunction(function);
850 DALI_TEST_CHECK(false); // Should not get here
854 DALI_TEST_CHECK(true); // We expect an assert
859 int UtcDaliLayerLowerNegative(void)
861 TestApplication application;
862 Dali::Layer instance;
866 DALI_TEST_CHECK(false); // Should not get here
870 DALI_TEST_CHECK(true); // We expect an assert
875 int UtcDaliLayerRaiseNegative(void)
877 TestApplication application;
878 Dali::Layer instance;
882 DALI_TEST_CHECK(false); // Should not get here
886 DALI_TEST_CHECK(true); // We expect an assert
891 int UtcDaliLayerMoveAboveNegative(void)
893 TestApplication application;
894 Dali::Layer instance;
898 instance.MoveAbove(arg1);
899 DALI_TEST_CHECK(false); // Should not get here
903 DALI_TEST_CHECK(true); // We expect an assert
908 int UtcDaliLayerMoveBelowNegative(void)
910 TestApplication application;
911 Dali::Layer instance;
915 instance.MoveBelow(arg1);
916 DALI_TEST_CHECK(false); // Should not get here
920 DALI_TEST_CHECK(true); // We expect an assert