Merge "Support multiple window rendering" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Scene.cpp
1 /*
2  * Copyright (c) 2016 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 #include <dali/integration-api/scene.h>
22 #include <dali-test-suite-utils.h>
23
24 // Internal headers are allowed here
25
26 int UtcDaliSceneAdd(void)
27 {
28   TestApplication application;
29   tet_infoline("Testing Dali::Integration::Scene::Add");
30
31   Dali::Integration::Scene scene = application.GetScene();
32
33   Actor actor = Actor::New();
34   DALI_TEST_CHECK( !actor.OnStage() );
35
36   scene.Add( actor );
37   DALI_TEST_CHECK( actor.OnStage() );
38
39   END_TEST;
40 }
41
42 int UtcDaliSceneRemove(void)
43 {
44   TestApplication application;
45   tet_infoline("Testing Dali::Integration::Scene::Remove");
46
47   Dali::Integration::Scene scene = application.GetScene();
48
49   Actor actor = Actor::New();
50   DALI_TEST_CHECK( !actor.OnStage() );
51
52   scene.Add( actor );
53   DALI_TEST_CHECK( actor.OnStage() );
54
55   scene.Remove(actor);
56   DALI_TEST_CHECK( !actor.OnStage() );
57
58   END_TEST;
59 }
60
61 int UtcDaliSceneGetSize(void)
62 {
63   TestApplication application;
64   tet_infoline("Testing Dali::Integration::Scene::GetSize");
65
66   Dali::Integration::Scene scene = application.GetScene();
67   Size size = scene.GetSize();
68   DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION );
69   DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION );
70
71   END_TEST;
72 }
73
74 int UtcDaliSceneGetDpi(void)
75 {
76   TestApplication application; // Initializes core DPI to default values
77
78   // Test that setting core DPI explicitly also sets up the scene's DPI.
79   Dali::Integration::Scene scene = application.GetScene();
80   scene.SetDpi( Vector2(200.0f, 180.0f) );
81   Vector2 dpi = scene.GetDpi();
82   DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
83   DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
84   END_TEST;
85 }
86
87 int UtcDaliSceneGetRenderTaskList(void)
88 {
89   TestApplication application;
90   tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
91
92   Dali::Integration::Scene scene = application.GetScene();
93
94   // Check we get a valid instance.
95   const RenderTaskList& tasks = scene.GetRenderTaskList();
96
97   // There should be 1 task by default.
98   DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
99
100   // RenderTaskList has it's own UTC tests.
101   // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
102   RenderTask newTask = scene.GetRenderTaskList().CreateTask();
103
104   DALI_TEST_EQUALS( scene.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
105
106   END_TEST;
107 }
108
109 int UtcDaliSceneGetRootLayer(void)
110 {
111   TestApplication application;
112   tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
113
114   Dali::Integration::Scene scene = application.GetScene();
115   Layer layer = scene.GetLayer( 0 );
116   DALI_TEST_CHECK( layer );
117
118   // Check that GetRootLayer() correctly retreived layer 0.
119   DALI_TEST_CHECK( scene.GetRootLayer() == layer );
120
121   END_TEST;
122 }
123
124 int UtcDaliSceneGetLayerCount(void)
125 {
126   TestApplication application;
127   tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
128
129   Dali::Integration::Scene scene = application.GetScene();
130   // Initially we have a default layer
131   DALI_TEST_EQUALS( scene.GetLayerCount(), 1u, TEST_LOCATION );
132
133   Layer layer = Layer::New();
134   scene.Add( layer );
135
136   DALI_TEST_EQUALS( scene.GetLayerCount(), 2u, TEST_LOCATION );
137   END_TEST;
138 }
139
140 int UtcDaliSceneGetLayer(void)
141 {
142   TestApplication application;
143   tet_infoline("Testing Dali::Integration::Scene::GetLayer");
144
145   Dali::Integration::Scene scene = application.GetScene();
146
147   Layer rootLayer = scene.GetLayer( 0 );
148   DALI_TEST_CHECK( rootLayer );
149
150   Layer layer = Layer::New();
151   scene.Add( layer );
152
153   Layer sameLayer = scene.GetLayer( 1 );
154   DALI_TEST_CHECK( layer == sameLayer );
155
156   END_TEST;
157 }
158