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