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>
25 using namespace Dali::Toolkit;
30 static bool gObjectCreatedCallBackCalled;
31 static void TestCallback(BaseHandle handle)
33 gObjectCreatedCallBackCalled = true;
39 void navigation_control_startup(void)
41 test_return_value = TET_UNDEF;
44 void navigation_control_cleanup(void)
46 test_return_value = TET_PASS;
49 int UtcDaliNavigationControlNew(void)
51 ToolkitTestApplication application;
52 tet_infoline("UtcDaliNavigationControlNew");
54 NavigationControl naviControl;
55 // Check that this handle is uninitialized
56 DALI_TEST_CHECK( !naviControl );
58 naviControl = NavigationControl::New();
59 // Check that the Dali resource is successfully created
60 DALI_TEST_CHECK( naviControl );
62 NavigationControl naviControl2( naviControl );
63 DALI_TEST_CHECK( naviControl2 == naviControl );
65 //Additional check to ensure object is created by checking whether it is registered
66 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
67 DALI_TEST_CHECK( registry );
68 gObjectCreatedCallBackCalled = false;
69 registry.ObjectCreatedSignal().Connect( TestCallback );
71 NavigationControl naviControl = NavigationControl::New();
73 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
77 int UtcDaliNavigationControlDownCast(void)
79 ToolkitTestApplication application;
80 tet_infoline( "UtcDaliNavigationControlDownCast" );
82 NavigationControl naviControl = NavigationControl::New();
83 BaseHandle handle( naviControl );
85 NavigationControl newNaviControl = NavigationControl::DownCast( handle );
86 DALI_TEST_CHECK( naviControl );
87 DALI_TEST_CHECK( newNaviControl == naviControl );
91 int UtcDaliNavigationControlPushItem(void)
93 ToolkitTestApplication application;
94 tet_infoline( "UtcDaliNavigationControlPushItem" );
96 // Create a NavigationControl object, and add it to stage
97 NavigationControl naviControl = NavigationControl::New();
98 Stage::GetCurrent().Add(naviControl);
99 // Check there is no item in the stack
100 DALI_TEST_CHECK( naviControl.GetItemCount() == 0 );
102 // Create two NavigationItem objects
103 Page firstItem = Page::New();
104 Page secondItem = Page::New();
106 // Push the first item into stack
107 naviControl.PushItem( firstItem );
108 // Check the item count in stack
109 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
110 // Check the current item
111 DALI_TEST_CHECK( naviControl.GetCurrentItem() == firstItem );
112 // Check that the newly pushed item is displayed on stage
113 DALI_TEST_CHECK( firstItem.OnStage() );
115 // Push the second item into stack
116 naviControl.PushItem( secondItem );
117 // Check the item count in stack
118 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
119 // Check the current item
120 DALI_TEST_CHECK( naviControl.GetCurrentItem() == secondItem );
121 // Check the bottom item in the stack
122 DALI_TEST_CHECK( naviControl.GetItem(0) == firstItem );
123 // Check that the previous item is off stage
124 DALI_TEST_CHECK( !firstItem.OnStage() );
125 // Check that the newly pushed item is displayed on stage
126 DALI_TEST_CHECK( secondItem.OnStage() );
129 Page fourthItem(secondItem);
130 naviControl.PushItem( thirdItem );
131 // Check that an uninitialized item cannot be pushed into the stack
132 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
133 naviControl.PushItem( fourthItem );
134 // Check that an duplicated item with the current item cannot be pushed into the stack
135 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
136 // Check that the current item and the item on the stage is still the secondItem
137 DALI_TEST_CHECK( naviControl.GetCurrentItem() == secondItem );
138 DALI_TEST_CHECK( secondItem.OnStage() );
142 int UtcDaliNavigationControlPopItem(void)
144 ToolkitTestApplication application;
145 tet_infoline( "UtcDaliNavigationControlPopItem" );
147 // Create a NavigationControl object, and add it to stage
148 NavigationControl naviControl = NavigationControl::New();
149 Stage::GetCurrent().Add(naviControl);
150 // Create three NavigationItem objects
151 Page firstItem = Page::New();
152 Page secondItem = Page::New();
153 Page thirdItem = Page::New();
154 naviControl.PushItem( firstItem );
155 naviControl.PushItem( secondItem );
156 naviControl.PushItem( thirdItem );
158 DALI_TEST_CHECK( naviControl.GetItemCount() == 3 );
160 // pop an item out from the stack
161 Page poppedItem = naviControl.PopItem();
162 // check that the item count is decrease by one
163 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
164 // check that the item popped out is the thirdItem
165 DALI_TEST_CHECK( poppedItem == thirdItem );
166 // check that the item popped out is disappeared from the stage
167 DALI_TEST_CHECK( !poppedItem.OnStage() );
168 // check that the new top item is displayed on the stage
169 DALI_TEST_CHECK( secondItem.OnStage() );
171 // repeat the above steps again
172 poppedItem = naviControl.PopItem();
173 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
174 DALI_TEST_CHECK( poppedItem == secondItem );
175 DALI_TEST_CHECK( !poppedItem.OnStage() );
176 DALI_TEST_CHECK( firstItem.OnStage() );
178 // check that the bottom-most item can not be popped out from the stack
179 poppedItem = naviControl.PopItem();
180 // when trying to pop the bottom-most item, it returns an uninitialized handle and does nothing else
181 DALI_TEST_CHECK( !poppedItem );
182 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
183 DALI_TEST_CHECK( firstItem.OnStage() );
187 int UtcDaliNavigationControlGetItemCount(void)
189 ToolkitTestApplication application;
190 tet_infoline( "UtcDaliNavigationControlGetItemCount" );
192 // Create a NavigationControl object
193 NavigationControl naviControl = NavigationControl::New();
194 // Create three NavigationItem objects
195 Page firstItem = Page::New();
196 Page secondItem = Page::New();
197 Page thirdItem = Page::New();
199 DALI_TEST_CHECK( naviControl.GetItemCount() == 0 );
200 naviControl.PushItem( firstItem );
201 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
202 naviControl.PushItem( secondItem );
203 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
204 naviControl.PushItem( thirdItem );
205 DALI_TEST_CHECK( naviControl.GetItemCount() == 3 );
206 naviControl.PopItem();
207 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
208 naviControl.PopItem();
209 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
213 int UtcDaliNavigationControlGetItem(void)
215 ToolkitTestApplication application;
216 tet_infoline( "UtcDaliNavigationControlGetItem" );
218 // Create a NavigationControl object
219 NavigationControl naviControl = NavigationControl::New();
220 // Create three NavigationItem objects and push them into stack
221 Page firstItem = Page::New();
222 Page secondItem = Page::New();
223 Page thirdItem = Page::New();
224 naviControl.PushItem( firstItem );
225 naviControl.PushItem( secondItem );
226 naviControl.PushItem( thirdItem );
228 // check every item by get it by index
229 DALI_TEST_CHECK( naviControl.GetItem(0) == firstItem );
230 DALI_TEST_CHECK( naviControl.GetItem(1) == secondItem );
231 DALI_TEST_CHECK( naviControl.GetItem(2) == thirdItem);
235 int UtcDaliNavigationControlGetCurrentItem(void)
237 ToolkitTestApplication application;
238 tet_infoline( "UtcDaliNavigationControlGetCurrentItem" );
240 // Create a NavigationControl object
241 NavigationControl naviControl = NavigationControl::New();
242 // Create three NavigationItem objects
243 Page firstItem = Page::New();
244 Page secondItem = Page::New();
245 Page thirdItem = Page::New();
247 naviControl.PushItem( firstItem );
248 DALI_TEST_CHECK( naviControl.GetCurrentItem() == firstItem );
249 naviControl.PushItem( secondItem );
250 DALI_TEST_CHECK( naviControl.GetCurrentItem() == secondItem );
251 naviControl.PushItem( thirdItem );
252 DALI_TEST_CHECK( naviControl.GetCurrentItem() == thirdItem );
253 naviControl.PopItem();
254 DALI_TEST_CHECK( naviControl.GetCurrentItem() == secondItem );
255 naviControl.PopItem();
256 DALI_TEST_CHECK( naviControl.GetCurrentItem() == firstItem );
260 int UtcDaliNavigationControlSetBackground(void)
262 ToolkitTestApplication application;
263 tet_infoline( "UtcDaliNavigationControlSetBackground" );
267 NavigationControl naviControl = NavigationControl::New();
268 Stage::GetCurrent().Add( naviControl );
270 ImageActor background = CreateSolidColorActor( Color::RED );
271 naviControl.SetBackground( background );
273 catch (Dali::DaliException& e)
275 DALI_TEST_PRINT_ASSERT( e );
276 DALI_TEST_EQUALS(e.condition, "segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size()", TEST_LOCATION);
277 tet_result(TET_FAIL);
280 tet_result(TET_PASS);
284 int UtcDaliNavigationControlCreateNavigationToolBar(void)
286 ToolkitTestApplication application;
287 tet_infoline( "UtcDaliNavigationControlCreateNavigationToolBar" );
289 ImageActor background = CreateSolidColorActor( Color::RED );
290 Stage stage = Stage::GetCurrent();
292 NavigationControl naviControl = NavigationControl::New();
293 stage.Add( naviControl );
295 Toolkit::NaviToolBarStyle toolbarStyle( background, 720, 98, 496, 182, 72, 16, 63, 26);
297 naviControl.CreateNavigationToolBar( toolbarStyle, toolbarStyle);
299 Page naviItem = Page::New();
300 PushButton firstControl = PushButton::New();
301 naviItem.AddControlToToolBar(firstControl, Alignment::HorizontalLeft);
302 PushButton secondControl = PushButton::New();
303 naviItem.AddControlToToolBar(secondControl, Alignment::HorizontalCenter);
304 PushButton thirdControl = PushButton::New();
305 naviItem.AddControlToToolBar(thirdControl, Alignment::HorizontalCenter);
306 PushButton fourthControl = PushButton::New();
307 naviItem.AddControlToToolBar(fourthControl, Alignment::HorizontalRight);
308 PushButton fifthControl = PushButton::New();
309 naviItem.AddControlToToolBar(fifthControl, Alignment::HorizontalRight);
311 naviControl.PushItem( naviItem );
313 DALI_TEST_CHECK( firstControl.OnStage() );
314 // Can add multiple controls to the central group
315 DALI_TEST_CHECK( secondControl.OnStage() );
316 DALI_TEST_CHECK( thirdControl.OnStage() );
317 // Can only have one control in the side groups
318 DALI_TEST_CHECK( !fourthControl.OnStage() );
319 DALI_TEST_CHECK( fifthControl.OnStage() );
324 int UtcDaliNavigationControlCreateNavigationTitleBar(void)
326 ToolkitTestApplication application;
327 tet_infoline( "UtcDaliNavigationControlCreateNavigationTitleBar" );
329 ImageActor background = CreateSolidColorActor( Color::RED );
331 Stage stage = Stage::GetCurrent();
333 NavigationControl naviControl = NavigationControl::New();
334 stage.Add( naviControl );
336 Toolkit::NaviTitleBarStyle titleBarStyle( background, textStyle, textStyle, 720, 111, 68, 48, 34, 16, 11, 45, 63, 26, 14, 22 );
337 naviControl.CreateNavigationTitleBar( titleBarStyle, titleBarStyle );
339 Page naviItem = Page::New();
341 PushButton firstControl = PushButton::New();
342 naviItem.AddControlToTitleBar( firstControl );
343 PushButton secondControl = PushButton::New();
344 naviItem.AddControlToTitleBar( secondControl );
346 Actor titleIcon = Actor::New();
347 naviItem.SetTitleIcon( titleIcon );
349 naviControl.PushItem( naviItem );
351 DALI_TEST_CHECK( firstControl.OnStage() );
352 DALI_TEST_CHECK( secondControl.OnStage() );
353 DALI_TEST_CHECK( titleIcon.OnStage() );