2 * Copyright (c) 2021 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);
197 int UtcDaliLayerLower1(void)
199 tet_infoline("Testing Dali::Layer::Lower()");
200 TestApplication application;
201 Layer layer1 = Layer::New();
202 Layer layer2 = Layer::New();
204 application.GetScene().Add(layer1);
205 application.GetScene().Add(layer2);
206 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
209 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
212 Layer root = application.GetScene().GetLayer(0);
214 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
216 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
217 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
221 int UtcDaliLayerLower2(void)
223 tet_infoline("Testing Dali::Layer lower Action");
224 TestApplication application;
225 Layer layer1 = Layer::New();
226 Layer layer2 = Layer::New();
228 application.GetScene().Add(layer1);
229 application.GetScene().Add(layer2);
230 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
233 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
236 Layer root = application.GetScene().GetLayer(0);
237 GetImplementation(root).DoAction("lower", Property::Map());
238 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
240 GetImplementation(layer2).DoAction("lower", Property::Map());
241 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
242 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
246 int UtcDaliLayerRaiseToTop1(void)
248 tet_infoline("Testing Dali::Layer::RaiseToTop()");
249 TestApplication application;
250 Layer layer1 = Layer::New();
251 Layer layer2 = Layer::New();
252 Layer layer3 = Layer::New();
254 application.GetScene().Add(layer1);
255 application.GetScene().Add(layer2);
256 application.GetScene().Add(layer3);
257 Layer root = application.GetScene().GetLayer(0);
259 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
260 DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
261 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
262 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
265 DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
268 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
272 int UtcDaliLayerRaiseToTop2(void)
274 tet_infoline("Testing Dali::Layer raiseToTop Action");
275 TestApplication application;
276 Layer layer1 = Layer::New();
277 Layer layer2 = Layer::New();
278 Layer layer3 = Layer::New();
280 application.GetScene().Add(layer1);
281 application.GetScene().Add(layer2);
282 application.GetScene().Add(layer3);
283 Layer root = application.GetScene().GetLayer(0);
285 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
286 DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
287 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
288 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
290 GetImplementation(layer1).DoAction("raiseToTop", Property::Map());
291 DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
293 GetImplementation(root).DoAction("raiseToTop", Property::Map());
294 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
298 int UtcDaliLayerLowerToBottom1(void)
300 tet_infoline("Testing Dali::Layer::LowerToBottom()");
301 TestApplication application;
302 Layer layer1 = Layer::New();
303 Layer layer2 = Layer::New();
304 Layer layer3 = Layer::New();
306 application.GetScene().Add(layer1);
307 application.GetScene().Add(layer2);
308 application.GetScene().Add(layer3);
310 DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
311 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
312 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
314 layer3.LowerToBottom();
315 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
319 int UtcDaliLayerLowerToBottom2(void)
321 tet_infoline("Testing Dali::Layer lowerToBottom Action");
322 TestApplication application;
323 Layer layer1 = Layer::New();
324 Layer layer2 = Layer::New();
325 Layer layer3 = Layer::New();
327 application.GetScene().Add(layer1);
328 application.GetScene().Add(layer2);
329 application.GetScene().Add(layer3);
331 DALI_TEST_EQUALS(layer1.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
332 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
333 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
335 GetImplementation(layer3).DoAction("lowerToBottom", Property::Map());
336 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
340 int UtcDaliLayerSetClipping(void)
342 tet_infoline("Testing Dali::Layer::SetClipping()");
343 TestApplication application;
345 Layer layer = Layer::New();
346 DALI_TEST_CHECK(!layer.GetProperty<bool>(Layer::Property::CLIPPING_ENABLE));
348 layer.SetProperty(Layer::Property::CLIPPING_ENABLE, true);
349 DALI_TEST_CHECK(layer.GetProperty<bool>(Layer::Property::CLIPPING_ENABLE));
353 int UtcDaliLayerIsClipping(void)
355 tet_infoline("Testing Dali::Layer::IsClipping()");
356 TestApplication application;
358 Layer layer = Layer::New();
359 DALI_TEST_CHECK(!layer.GetProperty<bool>(Layer::Property::CLIPPING_ENABLE));
363 int UtcDaliLayerSetClippingBox(void)
365 tet_infoline("Testing Dali::Layer::SetClippingBox()");
366 TestApplication application;
368 ClippingBox testBox(5, 6, 77, 83);
370 Layer layer = Layer::New();
371 DALI_TEST_CHECK(layer.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) != testBox);
372 layer.SetProperty(Layer::Property::CLIPPING_BOX, testBox);
373 DALI_TEST_CHECK(layer.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) == testBox);
377 int UtcDaliLayerGetClippingBox(void)
379 tet_infoline("Testing Dali::Layer::GetClippingBox()");
380 TestApplication application;
382 Layer layer = Layer::New();
383 DALI_TEST_CHECK(layer.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) == ClippingBox(0, 0, 0, 0));
387 static int gTestSortFunctionCalled;
389 static float TestSortFunction(const Vector3& /*position*/)
391 ++gTestSortFunctionCalled;
395 int UtcDaliLayerSetSortFunction(void)
397 tet_infoline("Testing Dali::Layer::SetSortFunction()");
398 TestApplication application;
400 // create two transparent actors so there is something to sort
401 Actor actor = CreateRenderableActor();
402 Actor actor2 = CreateRenderableActor();
403 actor.SetProperty(Actor::Property::SIZE, Vector2(1, 1));
404 actor.SetProperty(Actor::Property::COLOR, Vector4(1, 1, 1, 0.5f)); // 50% transparent
405 actor2.SetProperty(Actor::Property::SIZE, Vector2(1, 1));
406 actor2.SetProperty(Actor::Property::COLOR, Vector4(1, 1, 1, 0.5f)); // 50% transparent
409 application.GetScene().Add(actor);
410 application.GetScene().Add(actor2);
412 Layer root = application.GetScene().GetLayer(0);
413 gTestSortFunctionCalled = 0;
414 root.SetSortFunction(TestSortFunction);
416 // flush the queue and render once
417 application.SendNotification();
418 application.Render();
420 DALI_TEST_CHECK(gTestSortFunctionCalled > 0);
424 int UtcDaliLayerRaiseAbove(void)
426 tet_infoline("Testing Dali::Layer::RaiseAbove()");
427 TestApplication application;
428 Layer layer = Layer::New();
429 // try to raise above root layer
430 Layer root = application.GetScene().GetLayer(0);
431 layer.RaiseAbove(root);
432 // layer depth is zero as its not on scene
433 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
435 application.GetScene().Add(layer);
436 layer.RaiseAbove(root);
437 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
438 root.RaiseAbove(layer);
439 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
440 layer.RaiseAbove(layer);
441 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
443 // make another layer on the scene
444 Layer layer2 = Layer::New();
445 application.GetScene().Add(layer2);
446 layer.RaiseAbove(layer2);
447 DALI_TEST_GREATER(layer.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
448 layer2.RaiseAbove(layer);
449 DALI_TEST_GREATER(layer2.GetProperty<int>(Layer::Property::DEPTH), layer.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
450 root.RaiseAbove(layer2);
451 DALI_TEST_GREATER(root.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
455 int UtcDaliLayerRaiseBelow(void)
457 tet_infoline("Testing Dali::Layer::RaiseBelow()");
458 TestApplication application;
459 Layer layer = Layer::New();
460 // try to lower below root layer
461 Layer root = application.GetScene().GetLayer(0);
462 layer.LowerBelow(root);
463 // layer depth is zero as its not on scene
464 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
466 application.GetScene().Add(layer);
467 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
468 layer.LowerBelow(root);
469 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
470 root.LowerBelow(layer);
471 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
472 layer.LowerBelow(layer);
473 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
475 // make another layer on the scene
476 Layer layer2 = Layer::New();
477 application.GetScene().Add(layer2);
478 layer.LowerBelow(layer2);
479 DALI_TEST_GREATER(layer2.GetProperty<int>(Layer::Property::DEPTH), layer.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
480 layer2.LowerBelow(layer);
481 DALI_TEST_GREATER(layer.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
482 root.LowerBelow(layer2);
483 DALI_TEST_GREATER(layer2.GetProperty<int>(Layer::Property::DEPTH), root.GetProperty<int>(Layer::Property::DEPTH), TEST_LOCATION);
487 int UtcDaliLayerMoveAbove(void)
489 tet_infoline("Testing Dali::Layer::MoveAbove()");
490 TestApplication application;
491 Layer layer = Layer::New();
492 // try to raise above root layer
493 Layer root = application.GetScene().GetLayer(0);
494 layer.MoveAbove(root);
495 // layer depth is zero as its not on scene
496 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
497 root.MoveAbove(layer);
498 // root depth is zero as layer is not on scene
499 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
501 application.GetScene().Add(layer);
502 layer.MoveAbove(root);
503 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
504 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
505 root.MoveAbove(layer);
506 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
507 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
509 // make another layer on the scene
510 Layer layer2 = Layer::New();
511 application.GetScene().Add(layer2);
512 layer.MoveAbove(layer2);
513 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH) + 1u, TEST_LOCATION);
514 layer2.MoveAbove(root);
515 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), root.GetProperty<int>(Layer::Property::DEPTH) + 1u, TEST_LOCATION);
516 root.MoveAbove(layer);
517 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), layer.GetProperty<int>(Layer::Property::DEPTH) + 1u, TEST_LOCATION);
519 Layer layer3 = Layer::New();
520 application.GetScene().Add(layer3);
521 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
522 root.MoveAbove(layer3);
523 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
524 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
525 DALI_TEST_EQUALS(application.GetScene().GetLayer(0).GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
526 layer3.MoveAbove(application.GetScene().GetLayer(0));
527 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
531 int UtcDaliLayerMoveBelow(void)
533 tet_infoline("Testing Dali::Layer::MoveBelow()");
534 TestApplication application;
535 Layer layer = Layer::New();
536 // try to raise above root layer
537 Layer root = application.GetScene().GetLayer(0);
538 layer.MoveBelow(root);
539 // layer depth is zero as its not on scene
540 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
541 root.MoveBelow(layer);
542 // root depth is zero as layer is not on scene
543 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
545 application.GetScene().Add(layer);
546 layer.MoveBelow(root);
547 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
548 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
549 root.MoveBelow(layer);
550 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), 1u, TEST_LOCATION);
551 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 0u, TEST_LOCATION);
553 // make another layer on the scene
554 Layer layer2 = Layer::New();
555 application.GetScene().Add(layer2);
556 layer.MoveBelow(layer2);
557 DALI_TEST_EQUALS(layer.GetProperty<int>(Layer::Property::DEPTH), layer2.GetProperty<int>(Layer::Property::DEPTH) - 1u, TEST_LOCATION);
558 layer2.MoveBelow(root);
559 DALI_TEST_EQUALS(layer2.GetProperty<int>(Layer::Property::DEPTH), root.GetProperty<int>(Layer::Property::DEPTH) - 1u, TEST_LOCATION);
560 root.MoveBelow(layer);
561 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), layer.GetProperty<int>(Layer::Property::DEPTH) - 1u, TEST_LOCATION);
563 Layer layer3 = Layer::New();
564 application.GetScene().Add(layer3);
565 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
566 root.MoveBelow(layer3);
567 DALI_TEST_EQUALS(root.GetProperty<int>(Layer::Property::DEPTH), 2u, TEST_LOCATION);
568 DALI_TEST_EQUALS(layer3.GetProperty<int>(Layer::Property::DEPTH), 3u, TEST_LOCATION);
572 int UtcDaliLayerDefaultProperties(void)
574 TestApplication application;
575 tet_infoline("Testing Dali::Layer DefaultProperties");
577 Layer actor = Layer::New();
579 std::vector<Property::Index> indices;
580 indices.push_back(Layer::Property::CLIPPING_ENABLE);
581 indices.push_back(Layer::Property::CLIPPING_BOX);
582 indices.push_back(Layer::Property::BEHAVIOR);
583 indices.push_back(Layer::Property::DEPTH);
584 indices.push_back(Layer::Property::DEPTH_TEST);
585 indices.push_back(Layer::Property::CONSUMES_TOUCH);
586 indices.push_back(Layer::Property::CONSUMES_HOVER);
588 DALI_TEST_CHECK(actor.GetPropertyCount() == (Actor::New().GetPropertyCount() + indices.size()));
590 for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
592 DALI_TEST_CHECK(*iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)));
593 DALI_TEST_CHECK(*iter == Layer::Property::DEPTH ? !actor.IsPropertyWritable(*iter) : actor.IsPropertyWritable(*iter));
594 DALI_TEST_CHECK(!actor.IsPropertyAnimatable(*iter));
595 DALI_TEST_CHECK(actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter)); // just checking call succeeds
598 // set/get one of them
599 actor.SetProperty(Layer::Property::CLIPPING_BOX, ClippingBox(0, 0, 0, 0));
601 ClippingBox testBox(10, 20, 30, 40);
602 DALI_TEST_CHECK(actor.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) != testBox);
604 actor.SetProperty(Layer::Property::CLIPPING_BOX, Property::Value(Rect<int>(testBox)));
606 DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(Layer::Property::CLIPPING_BOX));
608 Property::Value v = actor.GetProperty(Layer::Property::CLIPPING_BOX);
609 DALI_TEST_CHECK(v.Get<Rect<int> >() == testBox);
611 v = actor.GetCurrentProperty(Layer::Property::CLIPPING_BOX);
612 DALI_TEST_CHECK(v.Get<Rect<int> >() == testBox);
614 // set the same boundaries, but through a clipping box object
615 actor.SetProperty(Layer::Property::CLIPPING_BOX, testBox);
616 DALI_TEST_CHECK(actor.GetProperty<Rect<int32_t> >(Layer::Property::CLIPPING_BOX) == testBox);
618 actor.SetProperty(Layer::Property::BEHAVIOR, Property::Value(Layer::LAYER_UI));
619 DALI_TEST_CHECK(Property::INTEGER == actor.GetPropertyType(Layer::Property::BEHAVIOR));
621 Property::Value behavior = actor.GetProperty(Layer::Property::BEHAVIOR);
622 DALI_TEST_EQUALS(behavior.Get<Dali::Layer::Behavior>(), Layer::LAYER_UI, TEST_LOCATION);
624 behavior = actor.GetCurrentProperty(Layer::Property::BEHAVIOR);
625 DALI_TEST_EQUALS(behavior.Get<Dali::Layer::Behavior>(), Layer::LAYER_UI, TEST_LOCATION);
630 int UtcDaliLayerSetDepthTestDisabled(void)
632 TestApplication application;
633 tet_infoline("Testing Dali::Layer::SetDepthTestDisabled() ");
635 Layer actor = Layer::New();
636 // Note that Layer::Property::DEPTH_TEST does not depend on layer behavior,
637 // as 2D layers can still have depth tests performed on a per-renderer basis.
639 DALI_TEST_CHECK(!actor.GetProperty<bool>(Layer::Property::DEPTH_TEST));
641 // Check Set / Unset.
642 actor.SetProperty(Layer::Property::DEPTH_TEST, true);
643 DALI_TEST_CHECK(actor.GetProperty<bool>(Layer::Property::DEPTH_TEST));
644 actor.SetProperty(Layer::Property::DEPTH_TEST, false);
645 DALI_TEST_CHECK(!actor.GetProperty<bool>(Layer::Property::DEPTH_TEST));
650 int UtcDaliLayerCreateDestroy(void)
652 tet_infoline("Testing Dali::Layer::CreateDestroy() ");
653 Layer* layer = new Layer;
654 DALI_TEST_CHECK(layer);
659 int UtcDaliLayerPropertyIndices(void)
661 TestApplication application;
662 Actor basicActor = Actor::New();
663 Layer layer = Layer::New();
665 Property::IndexContainer indices;
666 layer.GetPropertyIndices(indices);
667 DALI_TEST_CHECK(indices.Size() > basicActor.GetPropertyCount());
668 DALI_TEST_EQUALS(indices.Size(), layer.GetPropertyCount(), TEST_LOCATION);
672 int UtcDaliLayerTouchConsumed(void)
674 TestApplication application;
675 Layer layer = Layer::New();
677 DALI_TEST_EQUALS(layer.GetProperty<bool>(Layer::Property::CONSUMES_TOUCH), false, TEST_LOCATION);
678 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
679 DALI_TEST_EQUALS(layer.GetProperty<bool>(Layer::Property::CONSUMES_TOUCH), true, TEST_LOCATION);
683 int UtcDaliLayerHoverConsumed(void)
685 TestApplication application;
686 Layer layer = Layer::New();
688 DALI_TEST_EQUALS(layer.GetProperty<bool>(Layer::Property::CONSUMES_HOVER), false, TEST_LOCATION);
689 layer.SetProperty(Layer::Property::CONSUMES_HOVER, true);
690 DALI_TEST_EQUALS(layer.GetProperty<bool>(Layer::Property::CONSUMES_HOVER), true, TEST_LOCATION);
694 int UtcDaliLayerClippingGLCalls(void)
696 TestApplication application;
697 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
698 Integration::Scene scene(application.GetScene());
700 ClippingBox testBox(5, 6, 77, 83);
701 Layer layer = application.GetScene().GetRootLayer();
702 layer.SetProperty(Layer::Property::CLIPPING_ENABLE, true);
703 layer.SetProperty(Layer::Property::CLIPPING_BOX, testBox);
705 // Add at least one renderable actor so the GL calls are actually made
706 Texture img = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
707 Actor actor = CreateRenderableActor(img);
710 // flush the queue and render once
711 application.SendNotification();
712 application.Render();
714 DALI_TEST_EQUALS(testBox.x, glScissorParams.x, TEST_LOCATION);
715 DALI_TEST_EQUALS(testBox.y, (int)(scene.GetSize().height - glScissorParams.y - testBox.height), TEST_LOCATION); // GL Coordinates are from bottom left
716 DALI_TEST_EQUALS(testBox.width, glScissorParams.width, TEST_LOCATION);
717 DALI_TEST_EQUALS(testBox.height, glScissorParams.height, TEST_LOCATION);
721 int UtcDaliLayerBehaviour(void)
723 TestApplication application;
724 Layer layer = Layer::New();
726 DALI_TEST_EQUALS(layer.GetProperty<Layer::Behavior>(Layer::Property::BEHAVIOR), Dali::Layer::LAYER_UI, TEST_LOCATION);
727 layer.SetProperty(Layer::Property::BEHAVIOR, Dali::Layer::LAYER_3D);
728 DALI_TEST_EQUALS(layer.GetProperty<Layer::Behavior>(Layer::Property::BEHAVIOR), Dali::Layer::LAYER_3D, TEST_LOCATION);
732 Actor CreateActor(bool withAlpha)
734 Texture texture = Texture::New(TextureType::TEXTURE_2D, withAlpha ? Pixel::Format::RGBA8888 : Pixel::Format::RGB888, 1u, 1u);
736 Actor actor = CreateRenderableActor(texture);
737 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
738 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
743 int UtcDaliLayer3DSort(void)
745 tet_infoline("Testing LAYER_3D sort coverage test");
746 TestApplication application;
747 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
748 TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
750 application.GetScene().GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
753 Actor actor = CreateActor(false);
754 application.GetScene().Add(actor);
756 // Create child actors.
757 Actor child1 = CreateActor(true);
759 Actor child2 = CreateActor(false);
762 enabledDisableTrace.Reset();
763 enabledDisableTrace.Enable(true);
764 application.SendNotification();
765 application.Render();
766 enabledDisableTrace.Enable(false);
768 std::ostringstream depth;
769 depth << std::hex << GL_DEPTH_TEST;
770 DALI_TEST_CHECK(enabledDisableTrace.FindMethodAndParams("Enable", depth.str()));
775 int UtcDaliLayerLowerBelowNegative(void)
777 TestApplication application;
778 Dali::Layer instance;
782 instance.LowerBelow(arg1);
783 DALI_TEST_CHECK(false); // Should not get here
787 DALI_TEST_CHECK(true); // We expect an assert
792 int UtcDaliLayerRaiseAboveNegative(void)
794 TestApplication application;
795 Dali::Layer instance;
799 instance.RaiseAbove(arg1);
800 DALI_TEST_CHECK(false); // Should not get here
804 DALI_TEST_CHECK(true); // We expect an assert
809 int UtcDaliLayerRaiseToTopNegative(void)
811 TestApplication application;
812 Dali::Layer instance;
815 instance.RaiseToTop();
816 DALI_TEST_CHECK(false); // Should not get here
820 DALI_TEST_CHECK(true); // We expect an assert
825 int UtcDaliLayerLowerToBottomNegative(void)
827 TestApplication application;
828 Dali::Layer instance;
831 instance.LowerToBottom();
832 DALI_TEST_CHECK(false); // Should not get here
836 DALI_TEST_CHECK(true); // We expect an assert
841 int UtcDaliLayerSetSortFunctionNegative(void)
843 TestApplication application;
844 Dali::Layer instance;
847 Layer::SortFunctionType function = nullptr;
848 instance.SetSortFunction(function);
849 DALI_TEST_CHECK(false); // Should not get here
853 DALI_TEST_CHECK(true); // We expect an assert
858 int UtcDaliLayerLowerNegative(void)
860 TestApplication application;
861 Dali::Layer instance;
865 DALI_TEST_CHECK(false); // Should not get here
869 DALI_TEST_CHECK(true); // We expect an assert
874 int UtcDaliLayerRaiseNegative(void)
876 TestApplication application;
877 Dali::Layer instance;
881 DALI_TEST_CHECK(false); // Should not get here
885 DALI_TEST_CHECK(true); // We expect an assert
890 int UtcDaliLayerMoveAboveNegative(void)
892 TestApplication application;
893 Dali::Layer instance;
897 instance.MoveAbove(arg1);
898 DALI_TEST_CHECK(false); // Should not get here
902 DALI_TEST_CHECK(true); // We expect an assert
907 int UtcDaliLayerMoveBelowNegative(void)
909 TestApplication application;
910 Dali::Layer instance;
914 instance.MoveBelow(arg1);
915 DALI_TEST_CHECK(false); // Should not get here
919 DALI_TEST_CHECK(true); // We expect an assert