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/dali.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit-test-suite-utils.h>
27 using namespace Dali::Toolkit;
29 static void Startup();
30 static void Cleanup();
35 static bool gObjectCreatedCallBackCalled;
36 static void TestCallback(BaseHandle handle)
38 gObjectCreatedCallBackCalled = true;
44 void (*tet_startup)() = Startup;
45 void (*tet_cleanup)() = Cleanup;
48 static void UtcDaliNavigationControlNew();
49 static void UtcDaliNavigationControlDownCast();
50 static void UtcDaliNavigationControlPushItem();
51 static void UtcDaliNavigationControlPopItem();
52 static void UtcDaliNavigationControlGetItemCount();
53 static void UtcDaliNavigationControlGetItem();
54 static void UtcDaliNavigationControlGetCurrentItem();
55 static void UtcDaliNavigationControlSetBackground();
56 static void UtcDaliNavigationControlCreateNavigationToolBar();
57 static void UtcDaliNavigationControlCreateNavigationTitleBar();
60 POSITIVE_TC_IDX = 0x01,
64 // Add test functionality for all APIs in the class (Positive and Negative)
66 struct tet_testlist tet_testlist[] = {
67 { UtcDaliNavigationControlNew, POSITIVE_TC_IDX },
68 { UtcDaliNavigationControlDownCast, POSITIVE_TC_IDX },
69 { UtcDaliNavigationControlPushItem, POSITIVE_TC_IDX },
70 { UtcDaliNavigationControlPopItem, POSITIVE_TC_IDX },
71 { UtcDaliNavigationControlGetItemCount, POSITIVE_TC_IDX },
72 { UtcDaliNavigationControlGetItem, POSITIVE_TC_IDX },
73 { UtcDaliNavigationControlGetCurrentItem, POSITIVE_TC_IDX },
74 { UtcDaliNavigationControlSetBackground, POSITIVE_TC_IDX },
75 { UtcDaliNavigationControlCreateNavigationToolBar, POSITIVE_TC_IDX },
76 { UtcDaliNavigationControlCreateNavigationTitleBar, POSITIVE_TC_IDX },
81 // Called only once before first test is run.
86 // Called only once after last test is run
92 static void UtcDaliNavigationControlNew()
94 ToolkitTestApplication application;
95 tet_infoline("UtcDaliNavigationControlNew");
97 NavigationControl naviControl;
98 // Check that this handle is uninitialized
99 DALI_TEST_CHECK( !naviControl );
101 naviControl = NavigationControl::New();
102 // Check that the Dali resource is successfully created
103 DALI_TEST_CHECK( naviControl );
105 NavigationControl naviControl2( naviControl );
106 DALI_TEST_CHECK( naviControl2 == naviControl );
108 //Additional check to ensure object is created by checking whether it is registered
109 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
110 DALI_TEST_CHECK( registry );
111 gObjectCreatedCallBackCalled = false;
112 registry.ObjectCreatedSignal().Connect( TestCallback );
114 NavigationControl naviControl = NavigationControl::New();
116 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
119 static void UtcDaliNavigationControlDownCast()
121 ToolkitTestApplication application;
122 tet_infoline( "UtcDaliNavigationControlDownCast" );
124 NavigationControl naviControl = NavigationControl::New();
125 BaseHandle handle( naviControl );
127 NavigationControl newNaviControl = NavigationControl::DownCast( handle );
128 DALI_TEST_CHECK( naviControl );
129 DALI_TEST_CHECK( newNaviControl == naviControl );
132 static void UtcDaliNavigationControlPushItem()
134 ToolkitTestApplication application;
135 tet_infoline( "UtcDaliNavigationControlPushItem" );
137 // Create a NavigationControl object, and add it to stage
138 NavigationControl naviControl = NavigationControl::New();
139 Stage::GetCurrent().Add(naviControl);
140 // Check there is no item in the stack
141 DALI_TEST_CHECK( naviControl.GetItemCount() == 0 );
143 // Create two NavigationItem objects
144 Page firstItem = Page::New();
145 Page secondItem = Page::New();
147 // Push the first item into stack
148 naviControl.PushItem( firstItem );
149 // Check the item count in stack
150 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
151 // Check the current item
152 DALI_TEST_CHECK( naviControl.GetCurrentItem() == firstItem );
153 // Check that the newly pushed item is displayed on stage
154 DALI_TEST_CHECK( firstItem.OnStage() );
156 // Push the second item into stack
157 naviControl.PushItem( secondItem );
158 // Check the item count in stack
159 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
160 // Check the current item
161 DALI_TEST_CHECK( naviControl.GetCurrentItem() == secondItem );
162 // Check the bottom item in the stack
163 DALI_TEST_CHECK( naviControl.GetItem(0) == firstItem );
164 // Check that the previous item is off stage
165 DALI_TEST_CHECK( !firstItem.OnStage() );
166 // Check that the newly pushed item is displayed on stage
167 DALI_TEST_CHECK( secondItem.OnStage() );
170 Page fourthItem(secondItem);
171 naviControl.PushItem( thirdItem );
172 // Check that an uninitialized item cannot be pushed into the stack
173 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
174 naviControl.PushItem( fourthItem );
175 // Check that an duplicated item with the current item cannot be pushed into the stack
176 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
177 // Check that the current item and the item on the stage is still the secondItem
178 DALI_TEST_CHECK( naviControl.GetCurrentItem() == secondItem );
179 DALI_TEST_CHECK( secondItem.OnStage() );
182 static void UtcDaliNavigationControlPopItem()
184 ToolkitTestApplication application;
185 tet_infoline( "UtcDaliNavigationControlPopItem" );
187 // Create a NavigationControl object, and add it to stage
188 NavigationControl naviControl = NavigationControl::New();
189 Stage::GetCurrent().Add(naviControl);
190 // Create three NavigationItem objects
191 Page firstItem = Page::New();
192 Page secondItem = Page::New();
193 Page thirdItem = Page::New();
194 naviControl.PushItem( firstItem );
195 naviControl.PushItem( secondItem );
196 naviControl.PushItem( thirdItem );
198 DALI_TEST_CHECK( naviControl.GetItemCount() == 3 );
200 // pop an item out from the stack
201 Page poppedItem = naviControl.PopItem();
202 // check that the item count is decrease by one
203 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
204 // check that the item popped out is the thirdItem
205 DALI_TEST_CHECK( poppedItem == thirdItem );
206 // check that the item popped out is disappeared from the stage
207 DALI_TEST_CHECK( !poppedItem.OnStage() );
208 // check that the new top item is displayed on the stage
209 DALI_TEST_CHECK( secondItem.OnStage() );
211 // repeat the above steps again
212 poppedItem = naviControl.PopItem();
213 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
214 DALI_TEST_CHECK( poppedItem == secondItem );
215 DALI_TEST_CHECK( !poppedItem.OnStage() );
216 DALI_TEST_CHECK( firstItem.OnStage() );
218 // check that the bottom-most item can not be popped out from the stack
219 poppedItem = naviControl.PopItem();
220 // when trying to pop the bottom-most item, it returns an uninitialized handle and does nothing else
221 DALI_TEST_CHECK( !poppedItem );
222 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
223 DALI_TEST_CHECK( firstItem.OnStage() );
226 static void UtcDaliNavigationControlGetItemCount()
228 ToolkitTestApplication application;
229 tet_infoline( "UtcDaliNavigationControlGetItemCount" );
231 // Create a NavigationControl object
232 NavigationControl naviControl = NavigationControl::New();
233 // Create three NavigationItem objects
234 Page firstItem = Page::New();
235 Page secondItem = Page::New();
236 Page thirdItem = Page::New();
238 DALI_TEST_CHECK( naviControl.GetItemCount() == 0 );
239 naviControl.PushItem( firstItem );
240 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
241 naviControl.PushItem( secondItem );
242 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
243 naviControl.PushItem( thirdItem );
244 DALI_TEST_CHECK( naviControl.GetItemCount() == 3 );
245 naviControl.PopItem();
246 DALI_TEST_CHECK( naviControl.GetItemCount() == 2 );
247 naviControl.PopItem();
248 DALI_TEST_CHECK( naviControl.GetItemCount() == 1 );
251 static void UtcDaliNavigationControlGetItem()
253 ToolkitTestApplication application;
254 tet_infoline( "UtcDaliNavigationControlGetItem" );
256 // Create a NavigationControl object
257 NavigationControl naviControl = NavigationControl::New();
258 // Create three NavigationItem objects and push them into stack
259 Page firstItem = Page::New();
260 Page secondItem = Page::New();
261 Page thirdItem = Page::New();
262 naviControl.PushItem( firstItem );
263 naviControl.PushItem( secondItem );
264 naviControl.PushItem( thirdItem );
266 // check every item by get it by index
267 DALI_TEST_CHECK( naviControl.GetItem(0) == firstItem );
268 DALI_TEST_CHECK( naviControl.GetItem(1) == secondItem );
269 DALI_TEST_CHECK( naviControl.GetItem(2) == thirdItem);
272 static void UtcDaliNavigationControlGetCurrentItem()
274 ToolkitTestApplication application;
275 tet_infoline( "UtcDaliNavigationControlGetCurrentItem" );
277 // Create a NavigationControl object
278 NavigationControl naviControl = NavigationControl::New();
279 // Create three NavigationItem objects
280 Page firstItem = Page::New();
281 Page secondItem = Page::New();
282 Page thirdItem = Page::New();
284 naviControl.PushItem( firstItem );
285 DALI_TEST_CHECK( naviControl.GetCurrentItem() == firstItem );
286 naviControl.PushItem( secondItem );
287 DALI_TEST_CHECK( naviControl.GetCurrentItem() == secondItem );
288 naviControl.PushItem( thirdItem );
289 DALI_TEST_CHECK( naviControl.GetCurrentItem() == thirdItem );
290 naviControl.PopItem();
291 DALI_TEST_CHECK( naviControl.GetCurrentItem() == secondItem );
292 naviControl.PopItem();
293 DALI_TEST_CHECK( naviControl.GetCurrentItem() == firstItem );
296 static void UtcDaliNavigationControlSetBackground()
298 ToolkitTestApplication application;
299 tet_infoline( "UtcDaliNavigationControlSetBackground" );
303 NavigationControl naviControl = NavigationControl::New();
304 Stage::GetCurrent().Add( naviControl );
306 ImageActor background = CreateSolidColorActor( Color::RED );
307 naviControl.SetBackground( background );
309 catch (Dali::DaliException& e)
311 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
312 DALI_TEST_EQUALS(e.mCondition, "segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size()", TEST_LOCATION);
313 tet_result(TET_FAIL);
316 tet_result(TET_PASS);
319 static void UtcDaliNavigationControlCreateNavigationToolBar()
321 ToolkitTestApplication application;
322 tet_infoline( "UtcDaliNavigationControlCreateNavigationToolBar" );
324 ImageActor background = CreateSolidColorActor( Color::RED );
325 Stage stage = Stage::GetCurrent();
327 NavigationControl naviControl = NavigationControl::New();
328 stage.Add( naviControl );
330 Toolkit::NaviToolBarStyle toolbarStyle( background, 720, 98, 496, 182, 72, 16, 63, 26);
332 naviControl.CreateNavigationToolBar( toolbarStyle, toolbarStyle);
334 Page naviItem = Page::New();
335 PushButton firstControl = PushButton::New();
336 naviItem.AddControlToToolBar(firstControl, Alignment::HorizontalLeft);
337 PushButton secondControl = PushButton::New();
338 naviItem.AddControlToToolBar(secondControl, Alignment::HorizontalCenter);
339 PushButton thirdControl = PushButton::New();
340 naviItem.AddControlToToolBar(thirdControl, Alignment::HorizontalCenter);
341 PushButton fourthControl = PushButton::New();
342 naviItem.AddControlToToolBar(fourthControl, Alignment::HorizontalRight);
343 PushButton fifthControl = PushButton::New();
344 naviItem.AddControlToToolBar(fifthControl, Alignment::HorizontalRight);
346 naviControl.PushItem( naviItem );
348 DALI_TEST_CHECK( firstControl.OnStage() );
349 // Can add multiple controls to the central group
350 DALI_TEST_CHECK( secondControl.OnStage() );
351 DALI_TEST_CHECK( thirdControl.OnStage() );
352 // Can only have one control in the side groups
353 DALI_TEST_CHECK( !fourthControl.OnStage() );
354 DALI_TEST_CHECK( fifthControl.OnStage() );
358 static void UtcDaliNavigationControlCreateNavigationTitleBar()
360 ToolkitTestApplication application;
361 tet_infoline( "UtcDaliNavigationControlCreateNavigationTitleBar" );
363 ImageActor background = CreateSolidColorActor( Color::RED );
365 Stage stage = Stage::GetCurrent();
367 NavigationControl naviControl = NavigationControl::New();
368 stage.Add( naviControl );
370 Toolkit::NaviTitleBarStyle titleBarStyle( background, textStyle, textStyle, 720, 111, 68, 48, 34, 16, 11, 45, 63, 26, 14, 22 );
371 naviControl.CreateNavigationTitleBar( titleBarStyle, titleBarStyle );
373 Page naviItem = Page::New();
375 PushButton firstControl = PushButton::New();
376 naviItem.AddControlToTitleBar( firstControl );
377 PushButton secondControl = PushButton::New();
378 naviItem.AddControlToTitleBar( secondControl );
380 Actor titleIcon = Actor::New();
381 naviItem.SetTitleIcon( titleIcon );
383 naviControl.PushItem( naviItem );
385 DALI_TEST_CHECK( firstControl.OnStage() );
386 DALI_TEST_CHECK( secondControl.OnStage() );
387 DALI_TEST_CHECK( titleIcon.OnStage() );