Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-unmanaged / utc-Dali-View.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
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 #include <iostream>
18 #include <stdlib.h>
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali-toolkit/dali-toolkit.h>
21
22 using namespace Dali;
23 using namespace Toolkit;
24
25
26 void dali_view_startup(void)
27 {
28   test_return_value = TET_UNDEF;
29 }
30
31 void dali_view_cleanup(void)
32 {
33   test_return_value = TET_PASS;
34 }
35
36
37 namespace
38 {
39
40 static bool gAnimationStarted = false;
41
42 void StartAnimation( View, Animation& animation, const Orientation& orientation )
43 {
44   gAnimationStarted = true;
45 }
46
47
48 static bool gObjectCreatedCallBackCalled;
49 static void TestCallback(BaseHandle handle)
50 {
51   gObjectCreatedCallBackCalled = true;
52 }
53
54
55 }
56
57
58 int UtcDaliViewNew(void)
59 {
60   ToolkitTestApplication application;
61   tet_infoline(" UtcDaliViewNew");
62
63   View view1;
64   DALI_TEST_CHECK( !view1 );
65
66   view1 = View::New();
67   DALI_TEST_CHECK( view1 );
68
69   View view2( view1 );
70   DALI_TEST_CHECK( view2 );
71
72   View view3 = view2;
73   DALI_TEST_CHECK( view3 );
74
75   view1 = NULL;
76   view2 = NULL;
77   view3 = NULL;
78
79   //Additional check to ensure object is created by checking if it's registered
80   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
81   DALI_TEST_CHECK( registry );
82
83   gObjectCreatedCallBackCalled = false;
84   registry.ObjectCreatedSignal().Connect( &TestCallback );
85   {
86     View view = View::New();
87   }
88   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
89   END_TEST;
90 }
91
92 int UtcDaliViewAddGetRemoveContentLayer01(void)
93 {
94   ToolkitTestApplication application;
95   tet_infoline(" UtcDaliViewAddGetRemoveContentLayer01");
96
97   View view = View::New();
98   Layer layer1;
99   Layer layer2;
100   Layer layer3;
101   Layer layer4;
102
103   // Test: add and get layers.
104   try
105   {
106     layer1 = Layer::New();
107     layer1.SetName( "Layer1" );
108     layer2 = Layer::New();
109     layer2.SetName( "Layer2" );
110
111     unsigned int layerId1 = view.AddContentLayer( layer1 );
112     unsigned int layerId2 = view.AddContentLayer( layer2 );
113
114     layer3 = view.GetContentLayer( layerId1 );
115     layer4 = view.GetContentLayer( layerId2 );
116
117     DALI_TEST_EQUALS( layer1.GetName(), layer3.GetName(), TEST_LOCATION );
118     DALI_TEST_EQUALS( layer2.GetName(), layer4.GetName(), TEST_LOCATION );
119   }
120   catch( ... )
121   {
122     tet_printf( "UtcDaliViewAddGetRemoveContentLayer: Exception while adding and geting layers to/from view.\n" );
123     tet_result(TET_FAIL);
124   }
125
126   bool test1 = false;
127   bool test2 = false;
128   // Test: remove layers.
129   try
130   {
131     view.RemoveContentLayer( layer3 );
132     view.RemoveContentLayer( layer4 );
133     test1 = true;
134   }
135   catch( ... )
136   {
137     tet_printf( "UtcDaliViewAddGetRemoveContentLayer: Exception while removing layers from view.\n" );
138     tet_result(TET_FAIL);
139   }
140
141   // Test: add same layers again.
142   try
143   {
144     view.AddContentLayer( layer1 );
145     view.AddContentLayer( layer2 );
146     test2 = true;
147   }
148   catch( ... )
149   {
150     tet_printf( "UtcDaliViewAddGetRemoveContentLayer: Exception while adding layers from view after have been removed.\n" );
151     tet_result(TET_FAIL);
152   }
153
154   DALI_TEST_CHECK( test1 && test2 );
155   END_TEST;
156 }
157
158 int UtcDaliViewAddGetRemoveContentLayer02(void)
159 {
160   ToolkitTestApplication application;
161   tet_infoline(" UtcDaliViewAddGetRemoveContentLayer02");
162
163   View view = View::New();
164
165   Layer layer1 = Layer::New();
166   layer1.SetName( "Layer1" );
167   Layer layer2 = Layer::New();
168   layer2.SetName( "Layer2" );
169
170   view.AddContentLayer( layer1 );
171   view.AddContentLayer( layer2 );
172
173   // Test: add a layer twice.
174   try
175   {
176     view.AddContentLayer( layer1 );
177   }
178   catch( ... )
179   {
180     tet_result(TET_FAIL);
181   }
182
183   // Test: add an unitialized layer.
184   try
185   {
186     Layer layer;
187     view.AddContentLayer( layer );
188   }
189   catch( DaliException& e )
190   {
191     tet_printf("Assertion %s failed at %s when an unitialized layer is added.\n", e.mCondition.c_str(), e.mLocation.c_str());
192     DALI_TEST_EQUALS( e.mCondition, "layer", TEST_LOCATION );
193   }
194
195   // Test: get a layer which was not added before.
196   Layer layer = view.GetContentLayer( 100 );
197   DALI_TEST_CHECK( !layer );
198
199   // Test: Remove a layer which was not added before.
200   try
201   {
202     Layer layer = Layer::New();
203     view.RemoveContentLayer( layer );
204   }
205   catch( ... )
206   {
207     tet_result(TET_FAIL);
208   }
209
210   tet_result(TET_PASS);
211   END_TEST;
212 }
213
214 int UtcDaliViewSetGetBackgroundLayer01(void)
215 {
216   ToolkitTestApplication application;
217   tet_infoline(" UtcDaliViewSetGetBackgroundLayer01");
218
219   View view;
220   Layer layer1, layer2;
221
222   // Test with an actor.
223
224   view = View::New();
225   Stage::GetCurrent().Add( view );
226
227   ImageActor background = CreateSolidColorActor( Color::RED );
228
229   view.SetBackground( background );
230
231   layer1 = view.GetBackgroundLayer();
232
233   DALI_TEST_CHECK( layer1 );
234
235   background = CreateSolidColorActor( Color::GREEN );
236
237   view.SetBackground( background );
238
239   layer2 = view.GetBackgroundLayer();
240
241   DALI_TEST_CHECK( layer2 );
242
243   Stage::GetCurrent().Remove( view );
244   END_TEST;
245 }
246
247 int UtcDaliViewSetGetBackgroundLayer02(void)
248 {
249   ToolkitTestApplication application;
250   tet_infoline(" UtcDaliViewSetGetBackgroundLayer02");
251
252   bool assert = false;
253
254   try
255   {
256     View view = View::New();
257
258     ImageActor background = CreateSolidColorActor( Color::RED );
259
260     view.SetBackground( background );
261   }
262   catch( DaliException& e )
263   {
264     tet_printf("Assertion %s failed at %s when trying to add background to the view and the view is not on the stage.\n", e.mCondition.c_str(), e.mLocation.c_str());
265     DALI_TEST_EQUALS( e.mCondition, "mBackgroundLayer.OnStage()", TEST_LOCATION );
266     assert = true;
267   }
268
269   DALI_TEST_CHECK( assert );
270   END_TEST;
271 }
272
273 int UtcDaliViewSetOrientationFunction(void)
274 {
275   ToolkitTestApplication application;
276   tet_infoline(" UtcDaliViewSetOrientationFunction");
277
278   // Test it doesn't crash
279   try
280   {
281     View view = View::New();
282     Stage::GetCurrent().Add( view );
283
284     view.SetSize( 480, 800 );
285     view.SetOrientationFunction( Degree( 0.f ), Degree( 90.f ), Degree( 180.f ), Degree( 270.f ) );
286   }
287   catch( ... )
288   {
289     tet_result(TET_FAIL);
290   }
291
292   tet_result(TET_PASS);
293   END_TEST;
294 }
295
296 int UtcDaliViewOrientationChanged(void)
297 {
298   ToolkitTestApplication application;
299   tet_infoline(" UtcDaliViewOrientationChanged");
300
301   gAnimationStarted = false;
302
303   // Test it doesn't crash
304   try
305   {
306     View view = View::New();
307     Stage::GetCurrent().Add( view );
308
309     view.SetSize( 480, 800 );
310
311     view.OrientationAnimationStartedSignal().Connect( &StartAnimation );
312
313     application.SendNotification(); // Remove these two lines causes
314     application.Render();           // ToolkitTestApplication destructor to crash
315
316     //Orientation orientation = application.GetOrientation().GetHandle();
317     //application.GetOrientation().SetDegrees( 90 );
318     //view.OrientationChanged( orientation );
319   }
320   catch( ... )
321   {
322     tet_result(TET_FAIL);
323   }
324
325   // Check the view animation started.
326   DALI_TEST_CHECK( gAnimationStarted );
327   END_TEST;
328 }
329
330 int UtcSetAutoRotate(void)
331 {
332   ToolkitTestApplication application;
333   tet_infoline(" UtcSetAutoRotate");
334
335   gAnimationStarted = false;
336
337   View view;
338
339   // Test it doesn't crash
340   try
341   {
342     view = View::New();
343     Stage::GetCurrent().Add( view );
344
345     view.SetSize( 480, 800 );
346
347     //view.OrientationAnimationStartedSignal().Connect( &StartAnimation );
348
349     application.SendNotification();
350     application.Render();
351
352     //Orientation orientation = application.GetOrientation().GetHandle();
353     //application.GetOrientation().SetDegrees( 90 );
354     //view.OrientationChanged( orientation );
355   }
356   catch( ... )
357   {
358     tet_result(TET_FAIL);
359   }
360
361   // Check the view animation started.
362   //DALI_TEST_CHECK( gAnimationStarted );
363
364
365   gAnimationStarted = false;
366
367   try
368   {
369     view = View::New();
370     view.SetAutoRotate( false ); // Animation shouldn't start.
371     Stage::GetCurrent().Add( view );
372
373     view.SetSize( 480, 800 );
374
375     application.SendNotification();
376     application.Render();
377
378     //Orientation orientation = application.GetOrientation().GetHandle();
379     //application.GetOrientation().SetDegrees( 180 );
380     //view.OrientationChanged( orientation );
381   }
382   catch( ... )
383   {
384     tet_result(TET_FAIL);
385   }
386
387   // Check the view animation didn't start.
388   DALI_TEST_CHECK( !gAnimationStarted );
389   END_TEST;
390 }