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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali-toolkit/public-api/controls/view/view.h>
24 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
26 #include <dali-toolkit-test-suite-utils.h>
29 using namespace Toolkit;
34 static bool gAnimationStarted = false;
36 void StartAnimation( View, Animation& animation, const Orientation& orientation )
38 gAnimationStarted = true;
42 static bool gObjectCreatedCallBackCalled;
43 static void TestCallback(BaseHandle handle)
45 gObjectCreatedCallBackCalled = true;
51 static void Startup();
52 static void Cleanup();
55 void (*tet_startup)() = Startup;
56 void (*tet_cleanup)() = Cleanup;
60 POSITIVE_TC_IDX = 0x01,
64 #define MAX_NUMBER_OF_TESTS 10000
66 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
69 // Add test functionality for all APIs in the class (Positive and Negative)
70 TEST_FUNCTION( UtcDaliViewNew, POSITIVE_TC_IDX );
71 TEST_FUNCTION( UtcDaliViewAddGetRemoveContentLayer01, POSITIVE_TC_IDX );
72 TEST_FUNCTION( UtcDaliViewAddGetRemoveContentLayer02, NEGATIVE_TC_IDX );
73 TEST_FUNCTION( UtcDaliViewSetGetBackgroundLayer01, POSITIVE_TC_IDX );
74 TEST_FUNCTION( UtcDaliViewSetGetBackgroundLayer02, NEGATIVE_TC_IDX );
75 TEST_FUNCTION( UtcDaliViewSetOrientationFunction, POSITIVE_TC_IDX );
76 TEST_FUNCTION( UtcDaliViewOrientationChanged, POSITIVE_TC_IDX );
77 TEST_FUNCTION( UtcSetAutoRotate, POSITIVE_TC_IDX );
79 // Called only once before first test is run.
84 // Called only once after last test is run
89 static void UtcDaliViewNew()
91 ToolkitTestApplication application;
92 tet_infoline(" UtcDaliViewNew");
95 DALI_TEST_CHECK( !view1 );
98 DALI_TEST_CHECK( view1 );
101 DALI_TEST_CHECK( view2 );
104 DALI_TEST_CHECK( view3 );
110 //Additional check to ensure object is created by checking if it's registered
111 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
112 DALI_TEST_CHECK( registry );
114 gObjectCreatedCallBackCalled = false;
115 registry.ObjectCreatedSignal().Connect( &TestCallback );
117 View view = View::New();
119 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
122 static void UtcDaliViewAddGetRemoveContentLayer01()
124 ToolkitTestApplication application;
125 tet_infoline(" UtcDaliViewAddGetRemoveContentLayer01");
127 View view = View::New();
133 // Test: add and get layers.
136 layer1 = Layer::New();
137 layer1.SetName( "Layer1" );
138 layer2 = Layer::New();
139 layer2.SetName( "Layer2" );
141 unsigned int layerId1 = view.AddContentLayer( layer1 );
142 unsigned int layerId2 = view.AddContentLayer( layer2 );
144 layer3 = view.GetContentLayer( layerId1 );
145 layer4 = view.GetContentLayer( layerId2 );
147 DALI_TEST_EQUALS( layer1.GetName(), layer3.GetName(), TEST_LOCATION );
148 DALI_TEST_EQUALS( layer2.GetName(), layer4.GetName(), TEST_LOCATION );
152 tet_printf( "UtcDaliViewAddGetRemoveContentLayer: Exception while adding and geting layers to/from view.\n" );
153 tet_result(TET_FAIL);
158 // Test: remove layers.
161 view.RemoveContentLayer( layer3 );
162 view.RemoveContentLayer( layer4 );
167 tet_printf( "UtcDaliViewAddGetRemoveContentLayer: Exception while removing layers from view.\n" );
168 tet_result(TET_FAIL);
171 // Test: add same layers again.
174 view.AddContentLayer( layer1 );
175 view.AddContentLayer( layer2 );
180 tet_printf( "UtcDaliViewAddGetRemoveContentLayer: Exception while adding layers from view after have been removed.\n" );
181 tet_result(TET_FAIL);
184 DALI_TEST_CHECK( test1 && test2 );
187 static void UtcDaliViewAddGetRemoveContentLayer02()
189 ToolkitTestApplication application;
190 tet_infoline(" UtcDaliViewAddGetRemoveContentLayer02");
192 View view = View::New();
194 Layer layer1 = Layer::New();
195 layer1.SetName( "Layer1" );
196 Layer layer2 = Layer::New();
197 layer2.SetName( "Layer2" );
199 view.AddContentLayer( layer1 );
200 view.AddContentLayer( layer2 );
202 // Test: add a layer twice.
205 view.AddContentLayer( layer1 );
209 tet_result(TET_FAIL);
212 // Test: add an unitialized layer.
216 view.AddContentLayer( layer );
218 catch( DaliException& e )
220 tet_printf("Assertion %s failed at %s when an unitialized layer is added.\n", e.mCondition.c_str(), e.mLocation.c_str());
221 DALI_TEST_EQUALS( e.mCondition, "layer", TEST_LOCATION );
224 // Test: get a layer which was not added before.
225 Layer layer = view.GetContentLayer( 100 );
226 DALI_TEST_CHECK( !layer );
228 // Test: Remove a layer which was not added before.
231 Layer layer = Layer::New();
232 view.RemoveContentLayer( layer );
236 tet_result(TET_FAIL);
239 tet_result(TET_PASS);
242 static void UtcDaliViewSetGetBackgroundLayer01()
244 ToolkitTestApplication application;
245 tet_infoline(" UtcDaliViewSetGetBackgroundLayer01");
248 Layer layer1, layer2;
250 // Test with an actor.
253 Stage::GetCurrent().Add( view );
255 ImageActor background = CreateSolidColorActor( Color::RED );
257 view.SetBackground( background );
259 layer1 = view.GetBackgroundLayer();
261 DALI_TEST_CHECK( layer1 );
263 background = CreateSolidColorActor( Color::GREEN );
265 view.SetBackground( background );
267 layer2 = view.GetBackgroundLayer();
269 DALI_TEST_CHECK( layer2 );
271 Stage::GetCurrent().Remove( view );
274 static void UtcDaliViewSetGetBackgroundLayer02()
276 ToolkitTestApplication application;
277 tet_infoline(" UtcDaliViewSetGetBackgroundLayer02");
283 View view = View::New();
285 ImageActor background = CreateSolidColorActor( Color::RED );
287 view.SetBackground( background );
289 catch( DaliException& e )
291 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());
292 DALI_TEST_EQUALS( e.mCondition, "mBackgroundLayer.OnStage()", TEST_LOCATION );
296 DALI_TEST_CHECK( assert );
299 static void UtcDaliViewSetOrientationFunction()
301 ToolkitTestApplication application;
302 tet_infoline(" UtcDaliViewSetOrientationFunction");
304 // Test it doesn't crash
307 View view = View::New();
308 Stage::GetCurrent().Add( view );
310 view.SetSize( 480, 800 );
311 view.SetOrientationFunction( Degree( 0.f ), Degree( 90.f ), Degree( 180.f ), Degree( 270.f ) );
315 tet_result(TET_FAIL);
318 tet_result(TET_PASS);
321 static void UtcDaliViewOrientationChanged()
323 ToolkitTestApplication application;
324 tet_infoline(" UtcDaliViewOrientationChanged");
326 gAnimationStarted = false;
328 // Test it doesn't crash
331 View view = View::New();
332 Stage::GetCurrent().Add( view );
334 view.SetSize( 480, 800 );
336 view.OrientationAnimationStartedSignal().Connect( &StartAnimation );
338 application.SendNotification(); // Remove these two lines causes
339 application.Render(); // ToolkitTestApplication destructor to crash
341 Orientation orientation = application.GetOrientation().GetHandle();
342 application.GetOrientation().SetDegrees( 90 );
343 view.OrientationChanged( orientation );
347 tet_result(TET_FAIL);
350 // Check the view animation started.
351 DALI_TEST_CHECK( gAnimationStarted );
354 static void UtcSetAutoRotate()
356 ToolkitTestApplication application;
357 tet_infoline(" UtcSetAutoRotate");
359 gAnimationStarted = false;
363 // Test it doesn't crash
367 Stage::GetCurrent().Add( view );
369 view.SetSize( 480, 800 );
371 view.OrientationAnimationStartedSignal().Connect( &StartAnimation );
373 application.SendNotification();
374 application.Render();
376 Orientation orientation = application.GetOrientation().GetHandle();
377 application.GetOrientation().SetDegrees( 90 );
378 view.OrientationChanged( orientation );
382 tet_result(TET_FAIL);
385 // Check the view animation started.
386 DALI_TEST_CHECK( gAnimationStarted );
389 gAnimationStarted = false;
394 view.SetAutoRotate( false ); // Animation shouldn't start.
395 Stage::GetCurrent().Add( view );
397 view.SetSize( 480, 800 );
399 application.SendNotification();
400 application.Render();
402 Orientation orientation = application.GetOrientation().GetHandle();
403 application.GetOrientation().SetDegrees( 180 );
404 view.OrientationChanged( orientation );
408 tet_result(TET_FAIL);
411 // Check the view animation didn't start.
412 DALI_TEST_CHECK( !gAnimationStarted );