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/dali.h>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit-test-suite-utils.h>
28 using namespace Dali::Toolkit;
30 static void Startup();
31 static void Cleanup();
36 static bool gObjectCreatedCallBackCalled;
37 static void TestCallback(BaseHandle handle)
39 gObjectCreatedCallBackCalled = true;
45 void (*tet_startup)() = Startup;
46 void (*tet_cleanup)() = Cleanup;
49 static void UtcDaliNavigationControlNew();
50 static void UtcDaliNavigationControlDownCast();
51 static void UtcDaliNavigationControlPushItem();
52 static void UtcDaliNavigationControlPopItem();
53 static void UtcDaliNavigationControlGetItemCount();
54 static void UtcDaliNavigationControlGetItem();
55 static void UtcDaliNavigationControlGetCurrentItem();
56 static void UtcDaliNavigationControlSetBackground();
57 static void UtcDaliNavigationControlCreateNavigationToolBar();
58 static void UtcDaliNavigationControlCreateNavigationTitleBar();
61 POSITIVE_TC_IDX = 0x01,
65 // Add test functionality for all APIs in the class (Positive and Negative)
67 struct tet_testlist tet_testlist[] = {
68 { UtcDaliNavigationControlNew, POSITIVE_TC_IDX },
69 { UtcDaliNavigationControlDownCast, POSITIVE_TC_IDX },
70 { UtcDaliNavigationControlPushItem, POSITIVE_TC_IDX },
71 { UtcDaliNavigationControlPopItem, POSITIVE_TC_IDX },
72 { UtcDaliNavigationControlGetItemCount, POSITIVE_TC_IDX },
73 { UtcDaliNavigationControlGetItem, POSITIVE_TC_IDX },
74 { UtcDaliNavigationControlGetCurrentItem, POSITIVE_TC_IDX },
75 { UtcDaliNavigationControlSetBackground, POSITIVE_TC_IDX },
76 { UtcDaliNavigationControlCreateNavigationToolBar, POSITIVE_TC_IDX },
77 { UtcDaliNavigationControlCreateNavigationTitleBar, POSITIVE_TC_IDX },
82 // Called only once before first test is run.
87 // Called only once after last test is run
93 static void UtcDaliNavigationControlNew()
95 ToolkitTestApplication application;
96 tet_infoline("UtcDaliNavigationControlNew");
98 NavigationControl naviControl;
99 // Check that this handle is uninitialized
100 DALI_TEST_CHECK( !naviControl );
102 naviControl = NavigationControl::New();
103 // Check that the Dali resource is successfully created
104 DALI_TEST_CHECK( naviControl );
106 NavigationControl naviControl2( naviControl );
107 DALI_TEST_CHECK( naviControl2 == naviControl );
109 //Additional check to ensure object is created by checking whether it is registered
110 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
111 DALI_TEST_CHECK( registry );
112 gObjectCreatedCallBackCalled = false;
113 registry.ObjectCreatedSignal().Connect( TestCallback );
115 NavigationControl naviControl = NavigationControl::New();
117 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
120 static void UtcDaliNavigationControlDownCast()
122 ToolkitTestApplication application;
123 tet_infoline( "UtcDaliNavigationControlDownCast" );
125 NavigationControl naviControl = NavigationControl::New();
126 BaseHandle handle( naviControl );
128 NavigationControl newNaviControl = NavigationControl::DownCast( handle );
129 DALI_TEST_CHECK( naviControl );
130 DALI_TEST_CHECK( newNaviControl == naviControl );
133 static void UtcDaliNavigationControlPushItem()
135 ToolkitTestApplication application;
136 tet_infoline( "UtcDaliNavigationControlPushItem" );
138 // Create a NavigationControl object, and add it to stage
139 NavigationControl naviControl = NavigationControl::New();
140 Stage::GetCurrent().Add(naviControl);
141 // Check there is no item in the stack
142 DALI_TEST_CHECK( naviControl.GetItemCount() == 0 );
144 // Create two NavigationItem objects
145 Page firstItem = Page::New();
146 Page secondItem = Page::New();
148 // Push the first item into stack
149 naviControl.PushItem( firstItem );
150 // Check the item count in stack
151 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
152 // Check the current item
153 DALI_TEST_CHECK( naviControl.GetCurrentItem() == firstItem );
154 // Check that the newly pushed item is displayed on stage
155 DALI_TEST_CHECK( firstItem.OnStage() );
157 // Push the second item into stack
158 naviControl.PushItem( secondItem );
159 // Check the item count in stack
160 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
161 // Check the current item
162 DALI_TEST_CHECK( naviControl.GetCurrentItem() == secondItem );
163 // Check the bottom item in the stack
164 DALI_TEST_CHECK( naviControl.GetItem(0) == firstItem );
165 // Check that the previous item is off stage
166 DALI_TEST_CHECK( !firstItem.OnStage() );
167 // Check that the newly pushed item is displayed on stage
168 DALI_TEST_CHECK( secondItem.OnStage() );
171 Page fourthItem(secondItem);
172 naviControl.PushItem( thirdItem );
173 // Check that an uninitialized item cannot be pushed into the stack
174 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
175 naviControl.PushItem( fourthItem );
176 // Check that an duplicated item with the current item cannot be pushed into the stack
177 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
178 // Check that the current item and the item on the stage is still the secondItem
179 DALI_TEST_CHECK( naviControl.GetCurrentItem() == secondItem );
180 DALI_TEST_CHECK( secondItem.OnStage() );
183 static void UtcDaliNavigationControlPopItem()
185 ToolkitTestApplication application;
186 tet_infoline( "UtcDaliNavigationControlPopItem" );
188 // Create a NavigationControl object, and add it to stage
189 NavigationControl naviControl = NavigationControl::New();
190 Stage::GetCurrent().Add(naviControl);
191 // Create three NavigationItem objects
192 Page firstItem = Page::New();
193 Page secondItem = Page::New();
194 Page thirdItem = Page::New();
195 naviControl.PushItem( firstItem );
196 naviControl.PushItem( secondItem );
197 naviControl.PushItem( thirdItem );
199 DALI_TEST_CHECK( naviControl.GetItemCount() == 3 );
201 // pop an item out from the stack
202 Page poppedItem = naviControl.PopItem();
203 // check that the item count is decrease by one
204 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
205 // check that the item popped out is the thirdItem
206 DALI_TEST_CHECK( poppedItem == thirdItem );
207 // check that the item popped out is disappeared from the stage
208 DALI_TEST_CHECK( !poppedItem.OnStage() );
209 // check that the new top item is displayed on the stage
210 DALI_TEST_CHECK( secondItem.OnStage() );
212 // repeat the above steps again
213 poppedItem = naviControl.PopItem();
214 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
215 DALI_TEST_CHECK( poppedItem == secondItem );
216 DALI_TEST_CHECK( !poppedItem.OnStage() );
217 DALI_TEST_CHECK( firstItem.OnStage() );
219 // check that the bottom-most item can not be popped out from the stack
220 poppedItem = naviControl.PopItem();
221 // when trying to pop the bottom-most item, it returns an uninitialized handle and does nothing else
222 DALI_TEST_CHECK( !poppedItem );
223 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
224 DALI_TEST_CHECK( firstItem.OnStage() );
227 static void UtcDaliNavigationControlGetItemCount()
229 ToolkitTestApplication application;
230 tet_infoline( "UtcDaliNavigationControlGetItemCount" );
232 // Create a NavigationControl object
233 NavigationControl naviControl = NavigationControl::New();
234 // Create three NavigationItem objects
235 Page firstItem = Page::New();
236 Page secondItem = Page::New();
237 Page thirdItem = Page::New();
239 DALI_TEST_CHECK( naviControl.GetItemCount() == 0 );
240 naviControl.PushItem( firstItem );
241 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
242 naviControl.PushItem( secondItem );
243 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
244 naviControl.PushItem( thirdItem );
245 DALI_TEST_CHECK( naviControl.GetItemCount() == 3 );
246 naviControl.PopItem();
247 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
248 naviControl.PopItem();
249 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
252 static void UtcDaliNavigationControlGetItem()
254 ToolkitTestApplication application;
255 tet_infoline( "UtcDaliNavigationControlGetItem" );
257 // Create a NavigationControl object
258 NavigationControl naviControl = NavigationControl::New();
259 // Create three NavigationItem objects and push them into stack
260 Page firstItem = Page::New();
261 Page secondItem = Page::New();
262 Page thirdItem = Page::New();
263 naviControl.PushItem( firstItem );
264 naviControl.PushItem( secondItem );
265 naviControl.PushItem( thirdItem );
267 // check every item by get it by index
268 DALI_TEST_CHECK( naviControl.GetItem(0) == firstItem );
269 DALI_TEST_CHECK( naviControl.GetItem(1) == secondItem );
270 DALI_TEST_CHECK( naviControl.GetItem(2) == thirdItem);
273 static void UtcDaliNavigationControlGetCurrentItem()
275 ToolkitTestApplication application;
276 tet_infoline( "UtcDaliNavigationControlGetCurrentItem" );
278 // Create a NavigationControl object
279 NavigationControl naviControl = NavigationControl::New();
280 // Create three NavigationItem objects
281 Page firstItem = Page::New();
282 Page secondItem = Page::New();
283 Page thirdItem = Page::New();
285 naviControl.PushItem( firstItem );
286 DALI_TEST_CHECK( naviControl.GetCurrentItem() == firstItem );
287 naviControl.PushItem( secondItem );
288 DALI_TEST_CHECK( naviControl.GetCurrentItem() == secondItem );
289 naviControl.PushItem( thirdItem );
290 DALI_TEST_CHECK( naviControl.GetCurrentItem() == thirdItem );
291 naviControl.PopItem();
292 DALI_TEST_CHECK( naviControl.GetCurrentItem() == secondItem );
293 naviControl.PopItem();
294 DALI_TEST_CHECK( naviControl.GetCurrentItem() == firstItem );
297 static void UtcDaliNavigationControlSetBackground()
299 ToolkitTestApplication application;
300 tet_infoline( "UtcDaliNavigationControlSetBackground" );
304 NavigationControl naviControl = NavigationControl::New();
305 Stage::GetCurrent().Add( naviControl );
307 ImageActor background = CreateSolidColorActor( Color::RED );
308 naviControl.SetBackground( background );
310 catch (Dali::DaliException& e)
312 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
313 DALI_TEST_EQUALS(e.mCondition, "segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size()", TEST_LOCATION);
314 tet_result(TET_FAIL);
317 tet_result(TET_PASS);
320 static void UtcDaliNavigationControlCreateNavigationToolBar()
322 ToolkitTestApplication application;
323 tet_infoline( "UtcDaliNavigationControlCreateNavigationToolBar" );
325 ImageActor background = CreateSolidColorActor( Color::RED );
326 Stage stage = Stage::GetCurrent();
328 NavigationControl naviControl = NavigationControl::New();
329 stage.Add( naviControl );
331 Toolkit::NaviToolBarStyle toolbarStyle( background, 720, 98, 496, 182, 72, 16, 63, 26);
333 naviControl.CreateNavigationToolBar( toolbarStyle, toolbarStyle);
335 Page naviItem = Page::New();
336 PushButton firstControl = PushButton::New();
337 naviItem.AddControlToToolBar(firstControl, Alignment::HorizontalLeft);
338 PushButton secondControl = PushButton::New();
339 naviItem.AddControlToToolBar(secondControl, Alignment::HorizontalCenter);
340 PushButton thirdControl = PushButton::New();
341 naviItem.AddControlToToolBar(thirdControl, Alignment::HorizontalCenter);
342 PushButton fourthControl = PushButton::New();
343 naviItem.AddControlToToolBar(fourthControl, Alignment::HorizontalRight);
344 PushButton fifthControl = PushButton::New();
345 naviItem.AddControlToToolBar(fifthControl, Alignment::HorizontalRight);
347 naviControl.PushItem( naviItem );
349 DALI_TEST_CHECK( firstControl.OnStage() );
350 // Can add multiple controls to the central group
351 DALI_TEST_CHECK( secondControl.OnStage() );
352 DALI_TEST_CHECK( thirdControl.OnStage() );
353 // Can only have one control in the side groups
354 DALI_TEST_CHECK( !fourthControl.OnStage() );
355 DALI_TEST_CHECK( fifthControl.OnStage() );
359 static void UtcDaliNavigationControlCreateNavigationTitleBar()
361 ToolkitTestApplication application;
362 tet_infoline( "UtcDaliNavigationControlCreateNavigationTitleBar" );
364 ImageActor background = CreateSolidColorActor( Color::RED );
366 Stage stage = Stage::GetCurrent();
368 NavigationControl naviControl = NavigationControl::New();
369 stage.Add( naviControl );
371 Toolkit::NaviTitleBarStyle titleBarStyle( background, textStyle, textStyle, 720, 111, 68, 48, 34, 16, 11, 45, 63, 26, 14, 22 );
372 naviControl.CreateNavigationTitleBar( titleBarStyle, titleBarStyle );
374 Page naviItem = Page::New();
376 PushButton firstControl = PushButton::New();
377 naviItem.AddControlToTitleBar( firstControl );
378 PushButton secondControl = PushButton::New();
379 naviItem.AddControlToTitleBar( secondControl );
381 Actor titleIcon = Actor::New();
382 naviItem.SetTitleIcon( titleIcon );
384 naviControl.PushItem( naviItem );
386 DALI_TEST_CHECK( firstControl.OnStage() );
387 DALI_TEST_CHECK( secondControl.OnStage() );
388 DALI_TEST_CHECK( titleIcon.OnStage() );