Property refactor in dali-core: Toolkit changes for compiling
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-NavigationControl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22
23
24 using namespace Dali;
25 using namespace Dali::Toolkit;
26
27 namespace
28 {
29
30 static bool gObjectCreatedCallBackCalled;
31 static void TestCallback(BaseHandle handle)
32 {
33   gObjectCreatedCallBackCalled = true;
34 }
35
36 }
37
38
39 void navigation_control_startup(void)
40 {
41   test_return_value = TET_UNDEF;
42 }
43
44 void navigation_control_cleanup(void)
45 {
46   test_return_value = TET_PASS;
47 }
48
49 int UtcDaliNavigationControlNew(void)
50 {
51   ToolkitTestApplication application;
52   tet_infoline("UtcDaliNavigationControlNew");
53
54   NavigationControl naviControl;
55   // Check that this handle is uninitialized
56   DALI_TEST_CHECK( !naviControl );
57
58   naviControl = NavigationControl::New();
59   // Check that the Dali resource is successfully created
60   DALI_TEST_CHECK( naviControl );
61
62   NavigationControl naviControl2( naviControl );
63   DALI_TEST_CHECK( naviControl2 == naviControl );
64
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 );
70   {
71     NavigationControl naviControl = NavigationControl::New();
72   }
73   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
74   END_TEST;
75 }
76
77 int UtcDaliNavigationControlDownCast(void)
78 {
79   ToolkitTestApplication application;
80   tet_infoline( "UtcDaliNavigationControlDownCast" );
81
82   NavigationControl naviControl = NavigationControl::New();
83   BaseHandle handle( naviControl );
84
85   NavigationControl newNaviControl = NavigationControl::DownCast( handle );
86   DALI_TEST_CHECK( naviControl );
87   DALI_TEST_CHECK( newNaviControl == naviControl );
88   END_TEST;
89 }
90
91 int UtcDaliNavigationControlPushItem(void)
92 {
93   ToolkitTestApplication application;
94   tet_infoline( "UtcDaliNavigationControlPushItem" );
95
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 );
101
102   // Create two NavigationItem objects
103   Page firstItem = Page::New();
104   Page secondItem = Page::New();
105
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() );
114
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() );
127
128   Page thirdItem;
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() );
139   END_TEST;
140 }
141
142 int UtcDaliNavigationControlPopItem(void)
143 {
144   ToolkitTestApplication application;
145   tet_infoline( "UtcDaliNavigationControlPopItem" );
146
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 );
157
158   DALI_TEST_CHECK( naviControl.GetItemCount() == 3 );
159
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() );
170
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() );
177
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() );
184   END_TEST;
185 }
186
187 int UtcDaliNavigationControlGetItemCount(void)
188 {
189   ToolkitTestApplication application;
190   tet_infoline( "UtcDaliNavigationControlGetItemCount" );
191
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();
198
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 );
210   END_TEST;
211 }
212
213 int UtcDaliNavigationControlGetItem(void)
214 {
215   ToolkitTestApplication application;
216   tet_infoline( "UtcDaliNavigationControlGetItem" );
217
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 );
227
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);
232   END_TEST;
233 }
234
235 int UtcDaliNavigationControlGetCurrentItem(void)
236 {
237   ToolkitTestApplication application;
238   tet_infoline( "UtcDaliNavigationControlGetCurrentItem" );
239
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();
246
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 );
257   END_TEST;
258 }
259
260 int UtcDaliNavigationControlSetBackground(void)
261 {
262   ToolkitTestApplication application;
263   tet_infoline( "UtcDaliNavigationControlSetBackground" );
264
265   try
266   {
267     NavigationControl naviControl = NavigationControl::New();
268     Stage::GetCurrent().Add( naviControl );
269
270     ImageActor background = CreateSolidColorActor( Color::RED );
271     naviControl.SetBackground( background );
272   }
273   catch (Dali::DaliException& e)
274   {
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);
278   }
279
280   tet_result(TET_PASS);
281   END_TEST;
282 }
283
284 int UtcDaliNavigationControlCreateNavigationToolBar(void)
285 {
286   ToolkitTestApplication application;
287   tet_infoline( "UtcDaliNavigationControlCreateNavigationToolBar" );
288
289   ImageActor background = CreateSolidColorActor( Color::RED );
290   Stage stage = Stage::GetCurrent();
291
292   NavigationControl naviControl = NavigationControl::New();
293   stage.Add( naviControl );
294
295   Toolkit::NaviToolBarStyle toolbarStyle( background, 720, 98, 496, 182, 72, 16, 63, 26);
296
297   naviControl.CreateNavigationToolBar( toolbarStyle, toolbarStyle);
298
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);
310
311   naviControl.PushItem( naviItem );
312
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() );
320
321   END_TEST;
322 }
323
324 int UtcDaliNavigationControlCreateNavigationTitleBar(void)
325 {
326   ToolkitTestApplication application;
327   tet_infoline( "UtcDaliNavigationControlCreateNavigationTitleBar" );
328
329   ImageActor background = CreateSolidColorActor( Color::RED );
330   TextStyle textStyle;
331   Stage stage = Stage::GetCurrent();
332
333   NavigationControl naviControl = NavigationControl::New();
334   stage.Add( naviControl );
335
336   Toolkit::NaviTitleBarStyle titleBarStyle( background, textStyle, textStyle, 720, 111, 68, 48, 34, 16, 11, 45, 63, 26, 14, 22 );
337   naviControl.CreateNavigationTitleBar( titleBarStyle, titleBarStyle );
338
339   Page naviItem = Page::New();
340
341   PushButton firstControl = PushButton::New();
342   naviItem.AddControlToTitleBar( firstControl );
343   PushButton secondControl = PushButton::New();
344   naviItem.AddControlToTitleBar( secondControl );
345
346   Actor titleIcon = Actor::New();
347   naviItem.SetTitleIcon( titleIcon );
348
349   naviControl.PushItem( naviItem );
350
351   DALI_TEST_CHECK( firstControl.OnStage() );
352   DALI_TEST_CHECK( secondControl.OnStage() );
353   DALI_TEST_CHECK( titleIcon.OnStage() );
354   END_TEST;
355 }