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>
24 using namespace Dali::Toolkit;
29 static bool gObjectCreatedCallBackCalled;
30 static void TestCallback(BaseHandle handle)
32 gObjectCreatedCallBackCalled = true;
38 void navigation_control_startup(void)
40 test_return_value = TET_UNDEF;
43 void navigation_control_cleanup(void)
45 test_return_value = TET_PASS;
48 int UtcDaliNavigationControlNew(void)
50 ToolkitTestApplication application;
51 tet_infoline("UtcDaliNavigationControlNew");
53 NavigationControl naviControl;
54 // Check that this handle is uninitialized
55 DALI_TEST_CHECK( !naviControl );
57 naviControl = NavigationControl::New();
58 // Check that the Dali resource is successfully created
59 DALI_TEST_CHECK( naviControl );
61 NavigationControl naviControl2( naviControl );
62 DALI_TEST_CHECK( naviControl2 == naviControl );
64 //Additional check to ensure object is created by checking whether it is registered
65 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
66 DALI_TEST_CHECK( registry );
67 gObjectCreatedCallBackCalled = false;
68 registry.ObjectCreatedSignal().Connect( TestCallback );
70 NavigationControl naviControl = NavigationControl::New();
72 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
76 int UtcDaliNavigationControlDownCast(void)
78 ToolkitTestApplication application;
79 tet_infoline( "UtcDaliNavigationControlDownCast" );
81 NavigationControl naviControl = NavigationControl::New();
82 BaseHandle handle( naviControl );
84 NavigationControl newNaviControl = NavigationControl::DownCast( handle );
85 DALI_TEST_CHECK( naviControl );
86 DALI_TEST_CHECK( newNaviControl == naviControl );
90 int UtcDaliNavigationControlPushItem(void)
92 ToolkitTestApplication application;
93 tet_infoline( "UtcDaliNavigationControlPushItem" );
95 // Create a NavigationControl object, and add it to stage
96 NavigationControl naviControl = NavigationControl::New();
97 Stage::GetCurrent().Add(naviControl);
98 // Check there is no item in the stack
99 DALI_TEST_CHECK( naviControl.GetItemCount() == 0 );
101 // Create two NavigationItem objects
102 Page firstItem = Page::New();
103 Page secondItem = Page::New();
105 // Push the first item into stack
106 naviControl.PushItem( firstItem );
107 // Check the item count in stack
108 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
109 // Check the current item
110 DALI_TEST_CHECK( naviControl.GetCurrentItem() == firstItem );
111 // Check that the newly pushed item is displayed on stage
112 DALI_TEST_CHECK( firstItem.OnStage() );
114 // Push the second item into stack
115 naviControl.PushItem( secondItem );
116 // Check the item count in stack
117 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
118 // Check the current item
119 DALI_TEST_CHECK( naviControl.GetCurrentItem() == secondItem );
120 // Check the bottom item in the stack
121 DALI_TEST_CHECK( naviControl.GetItem(0) == firstItem );
122 // Check that the previous item is off stage
123 DALI_TEST_CHECK( !firstItem.OnStage() );
124 // Check that the newly pushed item is displayed on stage
125 DALI_TEST_CHECK( secondItem.OnStage() );
128 Page fourthItem(secondItem);
129 naviControl.PushItem( thirdItem );
130 // Check that an uninitialized item cannot be pushed into the stack
131 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
132 naviControl.PushItem( fourthItem );
133 // Check that an duplicated item with the current item cannot be pushed into the stack
134 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
135 // Check that the current item and the item on the stage is still the secondItem
136 DALI_TEST_CHECK( naviControl.GetCurrentItem() == secondItem );
137 DALI_TEST_CHECK( secondItem.OnStage() );
141 int UtcDaliNavigationControlPopItem(void)
143 ToolkitTestApplication application;
144 tet_infoline( "UtcDaliNavigationControlPopItem" );
146 // Create a NavigationControl object, and add it to stage
147 NavigationControl naviControl = NavigationControl::New();
148 Stage::GetCurrent().Add(naviControl);
149 // Create three NavigationItem objects
150 Page firstItem = Page::New();
151 Page secondItem = Page::New();
152 Page thirdItem = Page::New();
153 naviControl.PushItem( firstItem );
154 naviControl.PushItem( secondItem );
155 naviControl.PushItem( thirdItem );
157 DALI_TEST_CHECK( naviControl.GetItemCount() == 3 );
159 // pop an item out from the stack
160 Page poppedItem = naviControl.PopItem();
161 // check that the item count is decrease by one
162 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
163 // check that the item popped out is the thirdItem
164 DALI_TEST_CHECK( poppedItem == thirdItem );
165 // check that the item popped out is disappeared from the stage
166 DALI_TEST_CHECK( !poppedItem.OnStage() );
167 // check that the new top item is displayed on the stage
168 DALI_TEST_CHECK( secondItem.OnStage() );
170 // repeat the above steps again
171 poppedItem = naviControl.PopItem();
172 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
173 DALI_TEST_CHECK( poppedItem == secondItem );
174 DALI_TEST_CHECK( !poppedItem.OnStage() );
175 DALI_TEST_CHECK( firstItem.OnStage() );
177 // check that the bottom-most item can not be popped out from the stack
178 poppedItem = naviControl.PopItem();
179 // when trying to pop the bottom-most item, it returns an uninitialized handle and does nothing else
180 DALI_TEST_CHECK( !poppedItem );
181 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
182 DALI_TEST_CHECK( firstItem.OnStage() );
186 int UtcDaliNavigationControlGetItemCount(void)
188 ToolkitTestApplication application;
189 tet_infoline( "UtcDaliNavigationControlGetItemCount" );
191 // Create a NavigationControl object
192 NavigationControl naviControl = NavigationControl::New();
193 // Create three NavigationItem objects
194 Page firstItem = Page::New();
195 Page secondItem = Page::New();
196 Page thirdItem = Page::New();
198 DALI_TEST_CHECK( naviControl.GetItemCount() == 0 );
199 naviControl.PushItem( firstItem );
200 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
201 naviControl.PushItem( secondItem );
202 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
203 naviControl.PushItem( thirdItem );
204 DALI_TEST_CHECK( naviControl.GetItemCount() == 3 );
205 naviControl.PopItem();
206 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
207 naviControl.PopItem();
208 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
212 int UtcDaliNavigationControlGetItem(void)
214 ToolkitTestApplication application;
215 tet_infoline( "UtcDaliNavigationControlGetItem" );
217 // Create a NavigationControl object
218 NavigationControl naviControl = NavigationControl::New();
219 // Create three NavigationItem objects and push them into stack
220 Page firstItem = Page::New();
221 Page secondItem = Page::New();
222 Page thirdItem = Page::New();
223 naviControl.PushItem( firstItem );
224 naviControl.PushItem( secondItem );
225 naviControl.PushItem( thirdItem );
227 // check every item by get it by index
228 DALI_TEST_CHECK( naviControl.GetItem(0) == firstItem );
229 DALI_TEST_CHECK( naviControl.GetItem(1) == secondItem );
230 DALI_TEST_CHECK( naviControl.GetItem(2) == thirdItem);
234 int UtcDaliNavigationControlGetCurrentItem(void)
236 ToolkitTestApplication application;
237 tet_infoline( "UtcDaliNavigationControlGetCurrentItem" );
239 // Create a NavigationControl object
240 NavigationControl naviControl = NavigationControl::New();
241 // Create three NavigationItem objects
242 Page firstItem = Page::New();
243 Page secondItem = Page::New();
244 Page thirdItem = Page::New();
246 naviControl.PushItem( firstItem );
247 DALI_TEST_CHECK( naviControl.GetCurrentItem() == firstItem );
248 naviControl.PushItem( secondItem );
249 DALI_TEST_CHECK( naviControl.GetCurrentItem() == secondItem );
250 naviControl.PushItem( thirdItem );
251 DALI_TEST_CHECK( naviControl.GetCurrentItem() == thirdItem );
252 naviControl.PopItem();
253 DALI_TEST_CHECK( naviControl.GetCurrentItem() == secondItem );
254 naviControl.PopItem();
255 DALI_TEST_CHECK( naviControl.GetCurrentItem() == firstItem );
259 int UtcDaliNavigationControlSetBackground(void)
261 ToolkitTestApplication application;
262 tet_infoline( "UtcDaliNavigationControlSetBackground" );
266 NavigationControl naviControl = NavigationControl::New();
267 Stage::GetCurrent().Add( naviControl );
269 ImageActor background = CreateSolidColorActor( Color::RED );
270 naviControl.SetBackground( background );
272 catch (Dali::DaliException& e)
274 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
275 DALI_TEST_EQUALS(e.mCondition, "segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size()", TEST_LOCATION);
276 tet_result(TET_FAIL);
279 tet_result(TET_PASS);
283 int UtcDaliNavigationControlCreateNavigationToolBar(void)
285 ToolkitTestApplication application;
286 tet_infoline( "UtcDaliNavigationControlCreateNavigationToolBar" );
288 ImageActor background = CreateSolidColorActor( Color::RED );
289 Stage stage = Stage::GetCurrent();
291 NavigationControl naviControl = NavigationControl::New();
292 stage.Add( naviControl );
294 Toolkit::NaviToolBarStyle toolbarStyle( background, 720, 98, 496, 182, 72, 16, 63, 26);
296 naviControl.CreateNavigationToolBar( toolbarStyle, toolbarStyle);
298 Page naviItem = Page::New();
299 PushButton firstControl = PushButton::New();
300 naviItem.AddControlToToolBar(firstControl, Alignment::HorizontalLeft);
301 PushButton secondControl = PushButton::New();
302 naviItem.AddControlToToolBar(secondControl, Alignment::HorizontalCenter);
303 PushButton thirdControl = PushButton::New();
304 naviItem.AddControlToToolBar(thirdControl, Alignment::HorizontalCenter);
305 PushButton fourthControl = PushButton::New();
306 naviItem.AddControlToToolBar(fourthControl, Alignment::HorizontalRight);
307 PushButton fifthControl = PushButton::New();
308 naviItem.AddControlToToolBar(fifthControl, Alignment::HorizontalRight);
310 naviControl.PushItem( naviItem );
312 DALI_TEST_CHECK( firstControl.OnStage() );
313 // Can add multiple controls to the central group
314 DALI_TEST_CHECK( secondControl.OnStage() );
315 DALI_TEST_CHECK( thirdControl.OnStage() );
316 // Can only have one control in the side groups
317 DALI_TEST_CHECK( !fourthControl.OnStage() );
318 DALI_TEST_CHECK( fifthControl.OnStage() );
323 int UtcDaliNavigationControlCreateNavigationTitleBar(void)
325 ToolkitTestApplication application;
326 tet_infoline( "UtcDaliNavigationControlCreateNavigationTitleBar" );
328 ImageActor background = CreateSolidColorActor( Color::RED );
330 Stage stage = Stage::GetCurrent();
332 NavigationControl naviControl = NavigationControl::New();
333 stage.Add( naviControl );
335 Toolkit::NaviTitleBarStyle titleBarStyle( background, textStyle, textStyle, 720, 111, 68, 48, 34, 16, 11, 45, 63, 26, 14, 22 );
336 naviControl.CreateNavigationTitleBar( titleBarStyle, titleBarStyle );
338 Page naviItem = Page::New();
340 PushButton firstControl = PushButton::New();
341 naviItem.AddControlToTitleBar( firstControl );
342 PushButton secondControl = PushButton::New();
343 naviItem.AddControlToTitleBar( secondControl );
345 Actor titleIcon = Actor::New();
346 naviItem.SetTitleIcon( titleIcon );
348 naviControl.PushItem( naviItem );
350 DALI_TEST_CHECK( firstControl.OnStage() );
351 DALI_TEST_CHECK( secondControl.OnStage() );
352 DALI_TEST_CHECK( titleIcon.OnStage() );