2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali-toolkit/dali-toolkit.h>
23 using namespace Toolkit;
26 void dali_view_startup(void)
28 test_return_value = TET_UNDEF;
31 void dali_view_cleanup(void)
33 test_return_value = TET_PASS;
40 static bool gAnimationStarted = false;
42 void StartAnimation( View, Animation& animation, const Orientation& orientation )
44 gAnimationStarted = true;
48 static bool gObjectCreatedCallBackCalled;
49 static void TestCallback(BaseHandle handle)
51 gObjectCreatedCallBackCalled = true;
58 int UtcDaliViewNew(void)
60 ToolkitTestApplication application;
61 tet_infoline(" UtcDaliViewNew");
64 DALI_TEST_CHECK( !view1 );
67 DALI_TEST_CHECK( view1 );
70 DALI_TEST_CHECK( view2 );
73 DALI_TEST_CHECK( view3 );
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 );
83 gObjectCreatedCallBackCalled = false;
84 registry.ObjectCreatedSignal().Connect( &TestCallback );
86 View view = View::New();
88 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
92 int UtcDaliViewAddGetRemoveContentLayer01(void)
94 ToolkitTestApplication application;
95 tet_infoline(" UtcDaliViewAddGetRemoveContentLayer01");
97 View view = View::New();
103 // Test: add and get layers.
106 layer1 = Layer::New();
107 layer1.SetName( "Layer1" );
108 layer2 = Layer::New();
109 layer2.SetName( "Layer2" );
111 unsigned int layerId1 = view.AddContentLayer( layer1 );
112 unsigned int layerId2 = view.AddContentLayer( layer2 );
114 layer3 = view.GetContentLayer( layerId1 );
115 layer4 = view.GetContentLayer( layerId2 );
117 DALI_TEST_EQUALS( layer1.GetName(), layer3.GetName(), TEST_LOCATION );
118 DALI_TEST_EQUALS( layer2.GetName(), layer4.GetName(), TEST_LOCATION );
122 tet_printf( "UtcDaliViewAddGetRemoveContentLayer: Exception while adding and geting layers to/from view.\n" );
123 tet_result(TET_FAIL);
128 // Test: remove layers.
131 view.RemoveContentLayer( layer3 );
132 view.RemoveContentLayer( layer4 );
137 tet_printf( "UtcDaliViewAddGetRemoveContentLayer: Exception while removing layers from view.\n" );
138 tet_result(TET_FAIL);
141 // Test: add same layers again.
144 view.AddContentLayer( layer1 );
145 view.AddContentLayer( layer2 );
150 tet_printf( "UtcDaliViewAddGetRemoveContentLayer: Exception while adding layers from view after have been removed.\n" );
151 tet_result(TET_FAIL);
154 DALI_TEST_CHECK( test1 && test2 );
158 int UtcDaliViewAddGetRemoveContentLayer02(void)
160 ToolkitTestApplication application;
161 tet_infoline(" UtcDaliViewAddGetRemoveContentLayer02");
163 View view = View::New();
165 Layer layer1 = Layer::New();
166 layer1.SetName( "Layer1" );
167 Layer layer2 = Layer::New();
168 layer2.SetName( "Layer2" );
170 view.AddContentLayer( layer1 );
171 view.AddContentLayer( layer2 );
173 // Test: add a layer twice.
176 view.AddContentLayer( layer1 );
180 tet_result(TET_FAIL);
183 // Test: add an unitialized layer.
187 view.AddContentLayer( layer );
189 catch( DaliException& e )
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 );
195 // Test: get a layer which was not added before.
196 Layer layer = view.GetContentLayer( 100 );
197 DALI_TEST_CHECK( !layer );
199 // Test: Remove a layer which was not added before.
202 Layer layer = Layer::New();
203 view.RemoveContentLayer( layer );
207 tet_result(TET_FAIL);
210 tet_result(TET_PASS);
214 int UtcDaliViewSetGetBackgroundLayer01(void)
216 ToolkitTestApplication application;
217 tet_infoline(" UtcDaliViewSetGetBackgroundLayer01");
220 Layer layer1, layer2;
222 // Test with an actor.
225 Stage::GetCurrent().Add( view );
227 ImageActor background = CreateSolidColorActor( Color::RED );
229 view.SetBackground( background );
231 layer1 = view.GetBackgroundLayer();
233 DALI_TEST_CHECK( layer1 );
235 background = CreateSolidColorActor( Color::GREEN );
237 view.SetBackground( background );
239 layer2 = view.GetBackgroundLayer();
241 DALI_TEST_CHECK( layer2 );
243 Stage::GetCurrent().Remove( view );
247 int UtcDaliViewSetGetBackgroundLayer02(void)
249 ToolkitTestApplication application;
250 tet_infoline(" UtcDaliViewSetGetBackgroundLayer02");
256 View view = View::New();
258 ImageActor background = CreateSolidColorActor( Color::RED );
260 view.SetBackground( background );
262 catch( DaliException& e )
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 );
269 DALI_TEST_CHECK( assert );
273 int UtcDaliViewSetOrientationFunction(void)
275 ToolkitTestApplication application;
276 tet_infoline(" UtcDaliViewSetOrientationFunction");
278 // Test it doesn't crash
281 View view = View::New();
282 Stage::GetCurrent().Add( view );
284 view.SetSize( 480, 800 );
285 view.SetOrientationFunction( Degree( 0.f ), Degree( 90.f ), Degree( 180.f ), Degree( 270.f ) );
289 tet_result(TET_FAIL);
292 tet_result(TET_PASS);
296 int UtcDaliViewOrientationChanged(void)
298 ToolkitTestApplication application;
299 tet_infoline(" UtcDaliViewOrientationChanged");
301 gAnimationStarted = false;
303 // Test it doesn't crash
306 View view = View::New();
307 Stage::GetCurrent().Add( view );
309 view.SetSize( 480, 800 );
311 view.OrientationAnimationStartedSignal().Connect( &StartAnimation );
313 application.SendNotification(); // Remove these two lines causes
314 application.Render(); // ToolkitTestApplication destructor to crash
316 //Orientation orientation = application.GetOrientation().GetHandle();
317 //application.GetOrientation().SetDegrees( 90 );
318 //view.OrientationChanged( orientation );
322 tet_result(TET_FAIL);
325 // Check the view animation started.
326 DALI_TEST_CHECK( gAnimationStarted );
330 int UtcSetAutoRotate(void)
332 ToolkitTestApplication application;
333 tet_infoline(" UtcSetAutoRotate");
335 gAnimationStarted = false;
339 // Test it doesn't crash
343 Stage::GetCurrent().Add( view );
345 view.SetSize( 480, 800 );
347 //view.OrientationAnimationStartedSignal().Connect( &StartAnimation );
349 application.SendNotification();
350 application.Render();
352 //Orientation orientation = application.GetOrientation().GetHandle();
353 //application.GetOrientation().SetDegrees( 90 );
354 //view.OrientationChanged( orientation );
358 tet_result(TET_FAIL);
361 // Check the view animation started.
362 //DALI_TEST_CHECK( gAnimationStarted );
365 gAnimationStarted = false;
370 view.SetAutoRotate( false ); // Animation shouldn't start.
371 Stage::GetCurrent().Add( view );
373 view.SetSize( 480, 800 );
375 application.SendNotification();
376 application.Render();
378 //Orientation orientation = application.GetOrientation().GetHandle();
379 //application.GetOrientation().SetDegrees( 180 );
380 //view.OrientationChanged( orientation );
384 tet_result(TET_FAIL);
387 // Check the view animation didn't start.
388 DALI_TEST_CHECK( !gAnimationStarted );