2 * Copyright (c) 2014 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.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
24 using namespace Toolkit;
27 void dali_view_startup(void)
29 test_return_value = TET_UNDEF;
32 void dali_view_cleanup(void)
34 test_return_value = TET_PASS;
41 static bool gAnimationStarted = false;
43 void StartAnimation( View, Animation& animation, const Orientation& orientation )
45 gAnimationStarted = true;
49 static bool gObjectCreatedCallBackCalled;
50 static void TestCallback(BaseHandle handle)
52 gObjectCreatedCallBackCalled = true;
59 int UtcDaliViewNew(void)
61 ToolkitTestApplication application;
62 tet_infoline(" UtcDaliViewNew");
65 DALI_TEST_CHECK( !view1 );
68 DALI_TEST_CHECK( view1 );
71 DALI_TEST_CHECK( view2 );
74 DALI_TEST_CHECK( view3 );
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 );
84 gObjectCreatedCallBackCalled = false;
85 registry.ObjectCreatedSignal().Connect( &TestCallback );
87 View view = View::New();
89 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
93 int UtcDaliViewAddGetRemoveContentLayer01(void)
95 ToolkitTestApplication application;
96 tet_infoline(" UtcDaliViewAddGetRemoveContentLayer01");
98 View view = View::New();
104 // Test: add and get layers.
107 layer1 = Layer::New();
108 layer1.SetName( "Layer1" );
109 layer2 = Layer::New();
110 layer2.SetName( "Layer2" );
112 unsigned int layerId1 = view.AddContentLayer( layer1 );
113 unsigned int layerId2 = view.AddContentLayer( layer2 );
115 layer3 = view.GetContentLayer( layerId1 );
116 layer4 = view.GetContentLayer( layerId2 );
118 DALI_TEST_EQUALS( layer1.GetName(), layer3.GetName(), TEST_LOCATION );
119 DALI_TEST_EQUALS( layer2.GetName(), layer4.GetName(), TEST_LOCATION );
123 tet_printf( "UtcDaliViewAddGetRemoveContentLayer: Exception while adding and geting layers to/from view.\n" );
124 tet_result(TET_FAIL);
129 // Test: remove layers.
132 view.RemoveContentLayer( layer3 );
133 view.RemoveContentLayer( layer4 );
138 tet_printf( "UtcDaliViewAddGetRemoveContentLayer: Exception while removing layers from view.\n" );
139 tet_result(TET_FAIL);
142 // Test: add same layers again.
145 view.AddContentLayer( layer1 );
146 view.AddContentLayer( layer2 );
151 tet_printf( "UtcDaliViewAddGetRemoveContentLayer: Exception while adding layers from view after have been removed.\n" );
152 tet_result(TET_FAIL);
155 DALI_TEST_CHECK( test1 && test2 );
159 int UtcDaliViewAddGetRemoveContentLayer02(void)
161 ToolkitTestApplication application;
162 tet_infoline(" UtcDaliViewAddGetRemoveContentLayer02");
164 View view = View::New();
166 Layer layer1 = Layer::New();
167 layer1.SetName( "Layer1" );
168 Layer layer2 = Layer::New();
169 layer2.SetName( "Layer2" );
171 view.AddContentLayer( layer1 );
172 view.AddContentLayer( layer2 );
174 // Test: add a layer twice.
177 view.AddContentLayer( layer1 );
181 tet_result(TET_FAIL);
184 // Test: add an unitialized layer.
188 view.AddContentLayer( layer );
190 catch( DaliException& e )
192 DALI_TEST_PRINT_ASSERT( e );
193 DALI_TEST_EQUALS( e.condition, "layer", TEST_LOCATION );
196 // Test: get a layer which was not added before.
197 Layer layer = view.GetContentLayer( 100 );
198 DALI_TEST_CHECK( !layer );
200 // Test: Remove a layer which was not added before.
203 Layer layer = Layer::New();
204 view.RemoveContentLayer( layer );
208 tet_result(TET_FAIL);
211 tet_result(TET_PASS);
215 int UtcDaliViewSetGetBackgroundLayer01(void)
217 ToolkitTestApplication application;
218 tet_infoline(" UtcDaliViewSetGetBackgroundLayer01");
221 Layer layer1, layer2;
223 // Test with an actor.
226 Stage::GetCurrent().Add( view );
228 ImageActor background = CreateSolidColorActor( Color::RED );
230 view.SetBackground( background );
232 layer1 = view.GetBackgroundLayer();
234 DALI_TEST_CHECK( layer1 );
236 background = CreateSolidColorActor( Color::GREEN );
238 view.SetBackground( background );
240 layer2 = view.GetBackgroundLayer();
242 DALI_TEST_CHECK( layer2 );
244 Stage::GetCurrent().Remove( view );
248 int UtcDaliViewSetGetBackgroundLayer02(void)
250 ToolkitTestApplication application;
251 tet_infoline(" UtcDaliViewSetGetBackgroundLayer02");
257 View view = View::New();
259 ImageActor background = CreateSolidColorActor( Color::RED );
261 view.SetBackground( background );
263 catch( DaliException& e )
265 DALI_TEST_PRINT_ASSERT( e );
266 DALI_TEST_EQUALS( e.condition, "mBackgroundLayer.OnStage()", TEST_LOCATION );
270 DALI_TEST_CHECK( assert );
274 int UtcDaliViewSetOrientationFunction(void)
276 ToolkitTestApplication application;
277 tet_infoline(" UtcDaliViewSetOrientationFunction");
279 // Test it doesn't crash
282 View view = View::New();
283 Stage::GetCurrent().Add( view );
285 view.SetSize( 480, 800 );
286 view.SetOrientationFunction( Degree( 0.f ), Degree( 90.f ), Degree( 180.f ), Degree( 270.f ) );
290 tet_result(TET_FAIL);
293 tet_result(TET_PASS);
297 int UtcDaliViewOrientationChanged(void)
299 ToolkitTestApplication application;
300 tet_infoline(" UtcDaliViewOrientationChanged");
302 gAnimationStarted = false;
304 // Test it doesn't crash
307 View view = View::New();
308 Stage::GetCurrent().Add( view );
310 view.SetSize( Vector2( 480, 800 ) );
312 view.OrientationAnimationStartedSignal().Connect( &StartAnimation );
314 application.SendNotification(); // Remove these two lines causes
315 application.Render(); // ToolkitTestApplication destructor to crash
317 //Orientation orientation = application.GetOrientation().GetHandle();
318 //application.GetOrientation().SetDegrees( 90 );
319 //view.OrientationChanged( orientation );
323 tet_result(TET_FAIL);
326 // Check the view animation started.
327 DALI_TEST_CHECK( gAnimationStarted );
331 int UtcSetAutoRotate(void)
333 ToolkitTestApplication application;
334 tet_infoline(" UtcSetAutoRotate");
336 gAnimationStarted = false;
340 // Test it doesn't crash
344 Stage::GetCurrent().Add( view );
346 view.SetSize( 480, 800 );
348 //view.OrientationAnimationStartedSignal().Connect( &StartAnimation );
350 application.SendNotification();
351 application.Render();
353 //Orientation orientation = application.GetOrientation().GetHandle();
354 //application.GetOrientation().SetDegrees( 90 );
355 //view.OrientationChanged( orientation );
359 tet_result(TET_FAIL);
362 // Check the view animation started.
363 //DALI_TEST_CHECK( gAnimationStarted );
366 gAnimationStarted = false;
371 view.SetAutoRotate( false ); // Animation shouldn't start.
372 Stage::GetCurrent().Add( view );
374 view.SetSize( 480, 800 );
376 application.SendNotification();
377 application.Render();
379 //Orientation orientation = application.GetOrientation().GetHandle();
380 //application.GetOrientation().SetDegrees( 180 );
381 //view.OrientationChanged( orientation );
385 tet_result(TET_FAIL);
388 // Check the view animation didn't start.
389 DALI_TEST_CHECK( !gAnimationStarted );