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