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.
23 #include <dali/public-api/dali-core.h>
24 #include <dali-toolkit/public-api/controls/view/view.h>
25 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
27 #include <dali-toolkit-test-suite-utils.h>
30 using namespace Toolkit;
35 static bool gAnimationStarted = false;
37 void StartAnimation( View, Animation& animation, const Orientation& orientation )
39 gAnimationStarted = true;
43 static bool gObjectCreatedCallBackCalled;
44 static void TestCallback(BaseHandle handle)
46 gObjectCreatedCallBackCalled = true;
52 static void Startup();
53 static void Cleanup();
56 void (*tet_startup)() = Startup;
57 void (*tet_cleanup)() = Cleanup;
61 POSITIVE_TC_IDX = 0x01,
65 #define MAX_NUMBER_OF_TESTS 10000
67 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
70 // Add test functionality for all APIs in the class (Positive and Negative)
71 TEST_FUNCTION( UtcDaliViewNew, POSITIVE_TC_IDX );
72 TEST_FUNCTION( UtcDaliViewAddGetRemoveContentLayer01, POSITIVE_TC_IDX );
73 TEST_FUNCTION( UtcDaliViewAddGetRemoveContentLayer02, NEGATIVE_TC_IDX );
74 TEST_FUNCTION( UtcDaliViewSetGetBackgroundLayer01, POSITIVE_TC_IDX );
75 TEST_FUNCTION( UtcDaliViewSetGetBackgroundLayer02, NEGATIVE_TC_IDX );
76 TEST_FUNCTION( UtcDaliViewSetOrientationFunction, POSITIVE_TC_IDX );
77 TEST_FUNCTION( UtcDaliViewOrientationChanged, POSITIVE_TC_IDX );
78 TEST_FUNCTION( UtcSetAutoRotate, POSITIVE_TC_IDX );
80 // Called only once before first test is run.
85 // Called only once after last test is run
90 static void UtcDaliViewNew()
92 ToolkitTestApplication application;
93 tet_infoline(" UtcDaliViewNew");
96 DALI_TEST_CHECK( !view1 );
99 DALI_TEST_CHECK( view1 );
102 DALI_TEST_CHECK( view2 );
105 DALI_TEST_CHECK( view3 );
111 //Additional check to ensure object is created by checking if it's registered
112 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
113 DALI_TEST_CHECK( registry );
115 gObjectCreatedCallBackCalled = false;
116 registry.ObjectCreatedSignal().Connect( &TestCallback );
118 View view = View::New();
120 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
123 static void UtcDaliViewAddGetRemoveContentLayer01()
125 ToolkitTestApplication application;
126 tet_infoline(" UtcDaliViewAddGetRemoveContentLayer01");
128 View view = View::New();
134 // Test: add and get layers.
137 layer1 = Layer::New();
138 layer1.SetName( "Layer1" );
139 layer2 = Layer::New();
140 layer2.SetName( "Layer2" );
142 unsigned int layerId1 = view.AddContentLayer( layer1 );
143 unsigned int layerId2 = view.AddContentLayer( layer2 );
145 layer3 = view.GetContentLayer( layerId1 );
146 layer4 = view.GetContentLayer( layerId2 );
148 DALI_TEST_EQUALS( layer1.GetName(), layer3.GetName(), TEST_LOCATION );
149 DALI_TEST_EQUALS( layer2.GetName(), layer4.GetName(), TEST_LOCATION );
153 tet_printf( "UtcDaliViewAddGetRemoveContentLayer: Exception while adding and geting layers to/from view.\n" );
154 tet_result(TET_FAIL);
159 // Test: remove layers.
162 view.RemoveContentLayer( layer3 );
163 view.RemoveContentLayer( layer4 );
168 tet_printf( "UtcDaliViewAddGetRemoveContentLayer: Exception while removing layers from view.\n" );
169 tet_result(TET_FAIL);
172 // Test: add same layers again.
175 view.AddContentLayer( layer1 );
176 view.AddContentLayer( layer2 );
181 tet_printf( "UtcDaliViewAddGetRemoveContentLayer: Exception while adding layers from view after have been removed.\n" );
182 tet_result(TET_FAIL);
185 DALI_TEST_CHECK( test1 && test2 );
188 static void UtcDaliViewAddGetRemoveContentLayer02()
190 ToolkitTestApplication application;
191 tet_infoline(" UtcDaliViewAddGetRemoveContentLayer02");
193 View view = View::New();
195 Layer layer1 = Layer::New();
196 layer1.SetName( "Layer1" );
197 Layer layer2 = Layer::New();
198 layer2.SetName( "Layer2" );
200 view.AddContentLayer( layer1 );
201 view.AddContentLayer( layer2 );
203 // Test: add a layer twice.
206 view.AddContentLayer( layer1 );
210 tet_result(TET_FAIL);
213 // Test: add an unitialized layer.
217 view.AddContentLayer( layer );
219 catch( DaliException& e )
221 tet_printf("Assertion %s failed at %s when an unitialized layer is added.\n", e.mCondition.c_str(), e.mLocation.c_str());
222 DALI_TEST_EQUALS( e.mCondition, "layer", TEST_LOCATION );
225 // Test: get a layer which was not added before.
226 Layer layer = view.GetContentLayer( 100 );
227 DALI_TEST_CHECK( !layer );
229 // Test: Remove a layer which was not added before.
232 Layer layer = Layer::New();
233 view.RemoveContentLayer( layer );
237 tet_result(TET_FAIL);
240 tet_result(TET_PASS);
243 static void UtcDaliViewSetGetBackgroundLayer01()
245 ToolkitTestApplication application;
246 tet_infoline(" UtcDaliViewSetGetBackgroundLayer01");
249 Layer layer1, layer2;
251 // Test with an actor.
254 Stage::GetCurrent().Add( view );
256 ImageActor background = CreateSolidColorActor( Color::RED );
258 view.SetBackground( background );
260 layer1 = view.GetBackgroundLayer();
262 DALI_TEST_CHECK( layer1 );
264 background = CreateSolidColorActor( Color::GREEN );
266 view.SetBackground( background );
268 layer2 = view.GetBackgroundLayer();
270 DALI_TEST_CHECK( layer2 );
272 Stage::GetCurrent().Remove( view );
275 static void UtcDaliViewSetGetBackgroundLayer02()
277 ToolkitTestApplication application;
278 tet_infoline(" UtcDaliViewSetGetBackgroundLayer02");
284 View view = View::New();
286 ImageActor background = CreateSolidColorActor( Color::RED );
288 view.SetBackground( background );
290 catch( DaliException& e )
292 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());
293 DALI_TEST_EQUALS( e.mCondition, "mBackgroundLayer.OnStage()", TEST_LOCATION );
297 DALI_TEST_CHECK( assert );
300 static void UtcDaliViewSetOrientationFunction()
302 ToolkitTestApplication application;
303 tet_infoline(" UtcDaliViewSetOrientationFunction");
305 // Test it doesn't crash
308 View view = View::New();
309 Stage::GetCurrent().Add( view );
311 view.SetSize( 480, 800 );
312 view.SetOrientationFunction( Degree( 0.f ), Degree( 90.f ), Degree( 180.f ), Degree( 270.f ) );
316 tet_result(TET_FAIL);
319 tet_result(TET_PASS);
322 static void UtcDaliViewOrientationChanged()
324 ToolkitTestApplication application;
325 tet_infoline(" UtcDaliViewOrientationChanged");
327 gAnimationStarted = false;
329 // Test it doesn't crash
332 View view = View::New();
333 Stage::GetCurrent().Add( view );
335 view.SetSize( 480, 800 );
337 view.OrientationAnimationStartedSignal().Connect( &StartAnimation );
339 application.SendNotification(); // Remove these two lines causes
340 application.Render(); // ToolkitTestApplication destructor to crash
342 Orientation orientation = application.GetOrientation().GetHandle();
343 application.GetOrientation().SetDegrees( 90 );
344 view.OrientationChanged( orientation );
348 tet_result(TET_FAIL);
351 // Check the view animation started.
352 DALI_TEST_CHECK( gAnimationStarted );
355 static void UtcSetAutoRotate()
357 ToolkitTestApplication application;
358 tet_infoline(" UtcSetAutoRotate");
360 gAnimationStarted = false;
364 // Test it doesn't crash
368 Stage::GetCurrent().Add( view );
370 view.SetSize( 480, 800 );
372 view.OrientationAnimationStartedSignal().Connect( &StartAnimation );
374 application.SendNotification();
375 application.Render();
377 Orientation orientation = application.GetOrientation().GetHandle();
378 application.GetOrientation().SetDegrees( 90 );
379 view.OrientationChanged( orientation );
383 tet_result(TET_FAIL);
386 // Check the view animation started.
387 DALI_TEST_CHECK( gAnimationStarted );
390 gAnimationStarted = false;
395 view.SetAutoRotate( false ); // Animation shouldn't start.
396 Stage::GetCurrent().Add( view );
398 view.SetSize( 480, 800 );
400 application.SendNotification();
401 application.Render();
403 Orientation orientation = application.GetOrientation().GetHandle();
404 application.GetOrientation().SetDegrees( 180 );
405 view.OrientationChanged( orientation );
409 tet_result(TET_FAIL);
412 // Check the view animation didn't start.
413 DALI_TEST_CHECK( !gAnimationStarted );