Dali 3D User Interface Engine
utc-Dali-Layer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #include <iostream>
19 
20 #include <stdlib.h>
21 
23 
24 #include <dali-test-suite-utils.h>
25 
26 using namespace Dali;
27 
29 {
31 }
32 
34 {
36 }
37 
38 
39 int UtcDaliLayerNew(void)
40 {
41  TestApplication application;
42  Layer layer = Layer::New();
43 
44  DALI_TEST_CHECK(layer);
45  END_TEST;
46 }
47 
49 {
50  TestApplication application;
51  tet_infoline("Testing Dali::Layer::DownCast()");
52 
53  Layer actor1 = Layer::New();
54  Actor anActor = Actor::New();
55  anActor.Add(actor1);
56 
57  Actor child = anActor.GetChildAt(0);
58  Layer layer = DownCast< Layer >(child);
59 
60  DALI_TEST_CHECK(layer);
61  END_TEST;
62 }
63 
65 {
66  TestApplication application;
67  tet_infoline("Testing Dali::Layer::DownCast()");
68 
69  Actor actor1 = Actor::New();
70  Actor anActor = Actor::New();
71  anActor.Add(actor1);
72 
73  Actor child = anActor.GetChildAt(0);
74  Layer layer = DownCast< Layer >(child);
75  DALI_TEST_CHECK(!layer);
76 
77  Actor unInitialzedActor;
78  layer = Layer::DownCast( unInitialzedActor );
79  DALI_TEST_CHECK(!layer);
80  END_TEST;
81 }
82 
83 
85 {
86  tet_infoline("Testing Dali::Layer::GetDepth()");
87  TestApplication application;
88  Layer layer1 = Layer::New();
89  Layer layer2 = Layer::New();
90 
91  // layers are not on stage
94 
95  // root depth is 0
96  Layer root = Stage::GetCurrent().GetLayer( 0 );
97  DALI_TEST_EQUALS(root.GetDepth(), 0u, TEST_LOCATION);
98 
99  Stage::GetCurrent().Add(layer1);
100  Stage::GetCurrent().Add(layer2);
101 
102  DALI_TEST_EQUALS( root.GetDepth(), 0u, TEST_LOCATION);
103  DALI_TEST_EQUALS(layer1.GetDepth(), 1u, TEST_LOCATION);
104  DALI_TEST_EQUALS(layer2.GetDepth(), 2u, TEST_LOCATION);
105  END_TEST;
106 }
107 
109 {
110  tet_infoline("Testing Dali::Layer::Raise()");
111  TestApplication application;
112  Layer layer1 = Layer::New();
113  Layer layer2 = Layer::New();
114 
115  Stage::GetCurrent().Add(layer1);
116  Stage::GetCurrent().Add(layer2);
117  DALI_TEST_EQUALS(layer1.GetDepth(), 1u, TEST_LOCATION);
118 
119  layer1.Raise();
120  DALI_TEST_EQUALS(layer1.GetDepth(), 2u, TEST_LOCATION);
121 
122  // get root
123  Layer root = Stage::GetCurrent().GetLayer( 0 );
124  DALI_TEST_EQUALS( root.GetDepth(), 0u, TEST_LOCATION);
125  root.Raise();
126  DALI_TEST_EQUALS( root.GetDepth(), 1u, TEST_LOCATION);
127  DALI_TEST_EQUALS(layer1.GetDepth(), 2u, TEST_LOCATION);
128  DALI_TEST_EQUALS(layer2.GetDepth(), 0u, TEST_LOCATION);
129  END_TEST;
130 }
131 
133 {
134  tet_infoline("Testing Dali::Layer::Lower()");
135  TestApplication application;
136  Layer layer1 = Layer::New();
137  Layer layer2 = Layer::New();
138 
139  Stage::GetCurrent().Add(layer1);
140  Stage::GetCurrent().Add(layer2);
141  DALI_TEST_EQUALS(layer2.GetDepth(), 2u, TEST_LOCATION);
142 
143  layer2.Lower();
144  DALI_TEST_EQUALS(layer2.GetDepth(), 1u, TEST_LOCATION);
145 
146  // get root
147  Layer root = Stage::GetCurrent().GetLayer( 0 );
148  root.Lower();
149  DALI_TEST_EQUALS( root.GetDepth(), 0u, TEST_LOCATION);
150  layer2.Lower();
151  DALI_TEST_EQUALS( root.GetDepth(), 1u, TEST_LOCATION);
152  DALI_TEST_EQUALS(layer2.GetDepth(), 0u, TEST_LOCATION);
153  END_TEST;
154 }
155 
157 {
158  tet_infoline("Testing Dali::Layer::RaiseToTop()");
159  TestApplication application;
160  Layer layer1 = Layer::New();
161  Layer layer2 = Layer::New();
162  Layer layer3 = Layer::New();
163 
164  Stage::GetCurrent().Add(layer1);
165  Stage::GetCurrent().Add(layer2);
166  Stage::GetCurrent().Add(layer3);
167  Layer root = Stage::GetCurrent().GetLayer( 0 );
168 
170  DALI_TEST_EQUALS(layer1.GetDepth(), 1u, TEST_LOCATION);
171  DALI_TEST_EQUALS(layer2.GetDepth(), 2u, TEST_LOCATION);
172  DALI_TEST_EQUALS(layer3.GetDepth(), 3u, TEST_LOCATION);
173 
174  layer1.RaiseToTop();
175  DALI_TEST_EQUALS(layer1.GetDepth(), 3u, TEST_LOCATION);
176 
177  root.RaiseToTop();
179  END_TEST;
180 }
181 
183 {
184  tet_infoline("Testing Dali::Layer::LowerToBottom()");
185  TestApplication application;
186  Layer layer1 = Layer::New();
187  Layer layer2 = Layer::New();
188  Layer layer3 = Layer::New();
189 
190  Stage::GetCurrent().Add(layer1);
191  Stage::GetCurrent().Add(layer2);
192  Stage::GetCurrent().Add(layer3);
193 
194  DALI_TEST_EQUALS(layer1.GetDepth(), 1u, TEST_LOCATION);
195  DALI_TEST_EQUALS(layer2.GetDepth(), 2u, TEST_LOCATION);
196  DALI_TEST_EQUALS(layer3.GetDepth(), 3u, TEST_LOCATION);
197 
198  layer3.LowerToBottom();
199  DALI_TEST_EQUALS(layer3.GetDepth(), 0u, TEST_LOCATION);
200  END_TEST;
201 }
202 
204 {
205  tet_infoline("Testing Dali::Layer::SetClipping()");
206  TestApplication application;
207 
208  Layer layer = Layer::New();
209  DALI_TEST_CHECK(!layer.IsClipping());
210 
211  layer.SetClipping(true);
212  DALI_TEST_CHECK(layer.IsClipping());
213  END_TEST;
214 }
215 
217 {
218  tet_infoline("Testing Dali::Layer::IsClipping()");
219  TestApplication application;
220 
221  Layer layer = Layer::New();
222  DALI_TEST_CHECK(!layer.IsClipping());
223  END_TEST;
224 }
225 
227 {
228  tet_infoline("Testing Dali::Layer::SetClippingBox()");
229  TestApplication application;
230 
231  ClippingBox testBox(5,6, 77,83);
232 
233  Layer layer = Layer::New();
234  DALI_TEST_CHECK(layer.GetClippingBox() != testBox);
235 
236  layer.SetClippingBox(5,6, 77,83);
237  DALI_TEST_CHECK(layer.GetClippingBox() == testBox);
238  END_TEST;
239 }
240 
242 {
243  tet_infoline("Testing Dali::Layer::GetClippingBox()");
244  TestApplication application;
245 
246  Layer layer = Layer::New();
247  DALI_TEST_CHECK(layer.GetClippingBox() == ClippingBox(0,0,0,0));
248  END_TEST;
249 }
250 
252 
253 static float TestSortFunction(const Vector3& /*position*/)
254 {
256  return 0.0f;
257 }
258 
260 {
261  tet_infoline("Testing Dali::Layer::SetSortFunction()");
262  TestApplication application;
263  BufferImage img = BufferImage::New( 1,1 );
264  // create two transparent actors so there is something to sort
265  ImageActor actor = ImageActor::New( img );
266  ImageActor actor2 = ImageActor::New( img );
267  actor.SetSize(1,1);
268  actor.SetColor( Vector4(1, 1, 1, 0.5f ) ); // 50% transparent
269  actor2.SetSize(1,1);
270  actor2.SetColor( Vector4(1, 1, 1, 0.5f ) ); // 50% transparent
271 
272  // add to stage
273  Stage::GetCurrent().Add( actor );
274  Stage::GetCurrent().Add( actor2 );
275 
276  Layer root = Stage::GetCurrent().GetLayer( 0 );
279 
280  // flush the queue and render once
281  application.SendNotification();
282  application.Render();
283 
285  END_TEST;
286 }
287 
288 
290 {
291  tet_infoline("Testing Dali::Layer::RaiseAbove()");
292  TestApplication application;
293  Layer layer = Layer::New();
294  // try to raise above root layer
295  Layer root = Stage::GetCurrent().GetLayer( 0 );
296  layer.RaiseAbove( root );
297  // layer depth is zero as its not on stage
298  DALI_TEST_EQUALS( layer.GetDepth(), 0u, TEST_LOCATION );
299  // add to stage
300  Stage::GetCurrent().Add( layer );
301  layer.RaiseAbove( root );
302  DALI_TEST_EQUALS( layer.GetDepth(), 1u, TEST_LOCATION );
303  root.RaiseAbove( layer );
304  DALI_TEST_EQUALS( layer.GetDepth(), 0u, TEST_LOCATION );
305  layer.RaiseAbove( layer );
306  DALI_TEST_EQUALS( layer.GetDepth(), 0u, TEST_LOCATION );
307 
308  // make another layer on the stage
309  Layer layer2 = Layer::New();
310  Stage::GetCurrent().Add( layer2 );
311  layer.RaiseAbove( layer2 );
312  DALI_TEST_GREATER( layer.GetDepth(), layer2.GetDepth(), TEST_LOCATION );
313  layer2.RaiseAbove( layer );
314  DALI_TEST_GREATER( layer2.GetDepth(), layer.GetDepth(), TEST_LOCATION );
315  root.RaiseAbove( layer2 );
316  DALI_TEST_GREATER( root.GetDepth(), layer2.GetDepth(), TEST_LOCATION );
317  END_TEST;
318 }
319 
321 {
322  tet_infoline("Testing Dali::Layer::RaiseBelow()");
323  TestApplication application;
324  Layer layer = Layer::New();
325  // try to lower below root layer
326  Layer root = Stage::GetCurrent().GetLayer( 0 );
327  layer.LowerBelow( root );
328  // layer depth is zero as its not on stage
329  DALI_TEST_EQUALS( layer.GetDepth(), 0u, TEST_LOCATION );
330  // add to stage
331  Stage::GetCurrent().Add( layer );
332  DALI_TEST_EQUALS( layer.GetDepth(), 1u, TEST_LOCATION );
333  layer.LowerBelow( root );
334  DALI_TEST_EQUALS( layer.GetDepth(), 0u, TEST_LOCATION );
335  root.LowerBelow( layer );
336  DALI_TEST_EQUALS( layer.GetDepth(), 1u, TEST_LOCATION );
337  layer.LowerBelow( layer );
338  DALI_TEST_EQUALS( layer.GetDepth(), 1u, TEST_LOCATION );
339 
340  // make another layer on the stage
341  Layer layer2 = Layer::New();
342  Stage::GetCurrent().Add( layer2 );
343  layer.LowerBelow( layer2 );
344  DALI_TEST_GREATER( layer2.GetDepth(), layer.GetDepth(), TEST_LOCATION );
345  layer2.LowerBelow( layer );
346  DALI_TEST_GREATER( layer.GetDepth(), layer2.GetDepth(), TEST_LOCATION );
347  root.LowerBelow( layer2 );
348  DALI_TEST_GREATER( layer2.GetDepth(), root.GetDepth(), TEST_LOCATION );
349  END_TEST;
350 }
351 
353 {
354  tet_infoline("Testing Dali::Layer::MoveAbove()");
355  TestApplication application;
356  Layer layer = Layer::New();
357  // try to raise above root layer
358  Layer root = Stage::GetCurrent().GetLayer( 0 );
359  layer.MoveAbove( root );
360  // layer depth is zero as its not on stage
361  DALI_TEST_EQUALS( layer.GetDepth(), 0u, TEST_LOCATION );
362  root.MoveAbove( layer );
363  // root depth is zero as layer is not on stage
364  DALI_TEST_EQUALS( layer.GetDepth(), 0u, TEST_LOCATION );
365  // add to stage
366  Stage::GetCurrent().Add( layer );
367  layer.MoveAbove( root );
368  DALI_TEST_EQUALS( layer.GetDepth(), 1u, TEST_LOCATION );
369  DALI_TEST_EQUALS( root.GetDepth(), 0u, TEST_LOCATION );
370  root.MoveAbove( layer );
371  DALI_TEST_EQUALS( layer.GetDepth(), 0u, TEST_LOCATION );
372  DALI_TEST_EQUALS( root.GetDepth(), 1u, TEST_LOCATION );
373 
374  // make another layer on the stage
375  Layer layer2 = Layer::New();
376  Stage::GetCurrent().Add( layer2 );
377  layer.MoveAbove( layer2 );
378  DALI_TEST_EQUALS( layer.GetDepth(), layer2.GetDepth() + 1u, TEST_LOCATION );
379  layer2.MoveAbove( root );
380  DALI_TEST_EQUALS( layer2.GetDepth(), root.GetDepth() + 1u, TEST_LOCATION );
381  root.MoveAbove( layer );
382  DALI_TEST_EQUALS( root.GetDepth(), layer.GetDepth() + 1u, TEST_LOCATION );
383 
384  Layer layer3 = Layer::New();
385  Stage::GetCurrent().Add( layer3 );
386  DALI_TEST_EQUALS( layer3.GetDepth(), 3u, TEST_LOCATION );
387  root.MoveAbove( layer3 );
388  DALI_TEST_EQUALS( root.GetDepth(), 3u, TEST_LOCATION );
389  DALI_TEST_EQUALS( layer3.GetDepth(), 2u, TEST_LOCATION );
390  DALI_TEST_EQUALS( Stage::GetCurrent().GetLayer( 0 ).GetDepth(), 0u, TEST_LOCATION );
391  layer3.MoveAbove( Stage::GetCurrent().GetLayer( 0 ) );
392  DALI_TEST_EQUALS( layer3.GetDepth(), 1u, TEST_LOCATION );
393  END_TEST;
394 }
395 
397 {
398  tet_infoline("Testing Dali::Layer::MoveBelow()");
399  TestApplication application;
400  Layer layer = Layer::New();
401  // try to raise above root layer
402  Layer root = Stage::GetCurrent().GetLayer( 0 );
403  layer.MoveBelow( root );
404  // layer depth is zero as its not on stage
405  DALI_TEST_EQUALS( layer.GetDepth(), 0u, TEST_LOCATION );
406  root.MoveBelow( layer );
407  // root depth is zero as layer is not on stage
408  DALI_TEST_EQUALS( layer.GetDepth(), 0u, TEST_LOCATION );
409  // add to stage
410  Stage::GetCurrent().Add( layer );
411  layer.MoveBelow( root );
412  DALI_TEST_EQUALS( layer.GetDepth(), 0u, TEST_LOCATION );
413  DALI_TEST_EQUALS( root.GetDepth(), 1u, TEST_LOCATION );
414  root.MoveBelow( layer );
415  DALI_TEST_EQUALS( layer.GetDepth(), 1u, TEST_LOCATION );
416  DALI_TEST_EQUALS( root.GetDepth(), 0u, TEST_LOCATION );
417 
418  // make another layer on the stage
419  Layer layer2 = Layer::New();
420  Stage::GetCurrent().Add( layer2 );
421  layer.MoveBelow( layer2 );
422  DALI_TEST_EQUALS( layer.GetDepth(), layer2.GetDepth() - 1u, TEST_LOCATION );
423  layer2.MoveBelow( root );
424  DALI_TEST_EQUALS( layer2.GetDepth(), root.GetDepth() - 1u, TEST_LOCATION );
425  root.MoveBelow( layer );
426  DALI_TEST_EQUALS( root.GetDepth(), layer.GetDepth() - 1u, TEST_LOCATION );
427 
428  Layer layer3 = Layer::New();
429  Stage::GetCurrent().Add( layer3 );
430  DALI_TEST_EQUALS( layer3.GetDepth(), 3u, TEST_LOCATION );
431  root.MoveBelow( layer3 );
432  DALI_TEST_EQUALS( root.GetDepth(), 2u, TEST_LOCATION );
433  DALI_TEST_EQUALS( layer3.GetDepth(), 3u, TEST_LOCATION );
434  END_TEST;
435 }
436 
438 {
439  TestApplication application;
440  tet_infoline("Testing Dali::Layer DefaultProperties");
441 
442  Layer actor = Layer::New();
443 
444  std::vector<Property::Index> indices;
445  indices.push_back(Layer::Property::CLIPPING_ENABLE);
446  indices.push_back(Layer::Property::CLIPPING_BOX);
447  indices.push_back(Layer::Property::BEHAVIOR);
448 
449  DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
450 
451  for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
452  {
453  DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
454  DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
455  DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
456  DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) ); // just checking call succeeds
457  }
458 
459  // set/get one of them
460  actor.SetClippingBox(0,0,0,0);
461 
462  ClippingBox testBox(10,20,30,40);
463  DALI_TEST_CHECK(actor.GetClippingBox() != testBox);
464 
466 
468 
470 
471  DALI_TEST_CHECK(v.Get<Rect<int> >() == testBox);
472 
473  // set the same boundaries, but through a clipping box object
474  actor.SetClippingBox( testBox );
475 
476  DALI_TEST_CHECK( actor.GetClippingBox() == testBox );
477 
478 
480  DALI_TEST_EQUALS(behavior.Get<std::string>().c_str(), "LAYER_2D", TEST_LOCATION );
481 
482  END_TEST;
483 }
484 
486 {
487  TestApplication application;
488  tet_infoline("Testing Dali::Layer::SetDepthTestDisabled() ");
489 
490  Layer actor = Layer::New();
492 
493  actor.SetBehavior( Layer::LAYER_3D );
494 
496  DALI_TEST_EQUALS(behavior.Get<std::string>().c_str(), "LAYER_3D", TEST_LOCATION );
498 
499  actor.SetDepthTestDisabled( true );
501  END_TEST;
502 }
503 
505 {
506  tet_infoline("Testing Dali::Layer::CreateDestroy() ");
507  Layer* layer = new Layer;
508  DALI_TEST_CHECK( layer );
509  delete layer;
510  END_TEST;
511 }
512 
514 {
515  TestApplication application;
516  Actor basicActor = Actor::New();
517  Layer layer = Layer::New();
518 
519  Property::IndexContainer indices;
520  layer.GetPropertyIndices( indices );
521  DALI_TEST_CHECK( indices.Size() > basicActor.GetPropertyCount() );
522  DALI_TEST_EQUALS( indices.Size(), layer.GetPropertyCount(), TEST_LOCATION );
523  END_TEST;
524 }
525 
527 {
528  TestApplication application;
529  Layer layer = Layer::New();
530 
532  layer.SetTouchConsumed( true );
534  END_TEST;
535 }
536 
538 {
539  TestApplication application;
540  Layer layer = Layer::New();
541 
543  layer.SetHoverConsumed( true );
545  END_TEST;
546 }
547 
549 {
550  TestApplication application;
551  const TestGlAbstraction::ScissorParams& glScissorParams( application.GetGlAbstraction().GetScissorParams() );
552  Stage stage( Stage::GetCurrent() );
553 
554  ClippingBox testBox( 5, 6, 77, 83 );
556  layer.SetClipping( true );
557  layer.SetClippingBox( testBox );
558 
559  // Add at least one renderable actor so the GL calls are actually made
560  BufferImage img = BufferImage::New( 1,1 );
561  Actor actor = ImageActor::New( img );
562  stage.Add( actor );
563 
564  // flush the queue and render once
565  application.SendNotification();
566  application.Render();
567 
568  DALI_TEST_EQUALS( testBox.x, glScissorParams.x, TEST_LOCATION );
569  DALI_TEST_EQUALS( testBox.y, (int)(stage.GetSize().height - glScissorParams.y - testBox.height), TEST_LOCATION ); // GL Coordinates are from bottom left
570  DALI_TEST_EQUALS( testBox.width, glScissorParams.width, TEST_LOCATION );
571  DALI_TEST_EQUALS( testBox.height, glScissorParams.height, TEST_LOCATION );
572  END_TEST;
573 }
574 
576 {
577  TestApplication application;
578  Layer layer = Layer::New();
579 
583  END_TEST;
584 }
Dali Docs Home
Read more about Dali