Add the logical key to Integration::KeyEvent
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-NavigationView.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 <sstream>
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali-toolkit/devel-api/controls/navigation-view/navigation-view.h>
24
25 using namespace Dali;
26 using namespace Toolkit;
27
28 void dali_navigationView_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 }
32
33 void dali_navigationView_cleanup(void)
34 {
35   test_return_value = TET_PASS;
36 }
37
38 int UtcDaliNavigationTypeRegistry(void)
39 {
40   ToolkitTestApplication application;
41
42   TypeRegistry typeRegistry = TypeRegistry::Get();
43   DALI_TEST_CHECK( typeRegistry );
44
45   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "NavigationView" );
46   DALI_TEST_CHECK( typeInfo );
47
48   BaseHandle handle = typeInfo.CreateInstance();
49   DALI_TEST_CHECK( handle );
50
51   NavigationView view = NavigationView::DownCast( handle );
52   DALI_TEST_CHECK( view );
53
54   END_TEST;
55 }
56
57 int UtcDaliNavigationViewNew(void)
58 {
59   ToolkitTestApplication application;
60
61   NavigationView navigationView;
62   DALI_TEST_CHECK( !navigationView );
63
64   navigationView = NavigationView::New();
65   DALI_TEST_CHECK( navigationView );
66
67   Stage::GetCurrent().Add( navigationView );
68
69   application.SendNotification();
70   application.Render();
71
72   END_TEST;
73 }
74
75 int UtcDaliNavigationViewCopyAndAssignment(void)
76 {
77   ToolkitTestApplication application;
78
79   NavigationView view = NavigationView::New();
80   DALI_TEST_CHECK( view );
81
82   NavigationView copy( view );
83   DALI_TEST_CHECK( copy == view );
84
85   NavigationView assign;
86   DALI_TEST_CHECK( !assign );
87   assign = view;
88   DALI_TEST_CHECK( assign == view );
89
90   // Self assignment
91   assign = assign;
92   DALI_TEST_CHECK( assign );
93   DALI_TEST_CHECK( assign == view );
94
95   END_TEST;
96 }
97
98 int UtcDaliNavigationViewDownCast(void)
99 {
100   ToolkitTestApplication application;
101
102   BaseHandle view = NavigationView::New();
103   DALI_TEST_CHECK( NavigationView::DownCast( view ) );
104
105   BaseHandle empty;
106   DALI_TEST_CHECK( ! NavigationView::DownCast( empty ) );
107
108   BaseHandle another = Actor::New();
109   DALI_TEST_CHECK( ! NavigationView::DownCast( another ) );
110
111   END_TEST;
112 }
113
114 int UtcDaliNavigationViewPush(void)
115 {
116   ToolkitTestApplication application;
117
118   Stage stage = Stage::GetCurrent();
119
120   // 1 Create and Add Navigation View to stage, actor count should be zero
121   NavigationView naviView = NavigationView::New();
122   stage.Add( naviView );
123
124   DALI_TEST_EQUALS( naviView.GetChildCount(), 0,  TEST_LOCATION );
125
126   // 2 Add Actor to Navigation View, actor count should increase to 1
127
128   Actor TestParentActor1 = Actor::New();
129   naviView.Push( TestParentActor1 );
130
131   DALI_TEST_EQUALS( naviView.GetChildCount(), 1,  TEST_LOCATION );
132
133   END_TEST;
134 }
135
136 int UtcDaliNavigationViewPop(void)
137 {
138   ToolkitTestApplication application;
139
140   Stage stage = Stage::GetCurrent();
141
142   // 1 Create Navigation View
143   NavigationView naviView = NavigationView::New();
144   stage.Add( naviView );
145
146   // 2 Push initial Actor
147   Actor testParentActor1 = Actor::New();
148   testParentActor1.SetName("TestParentActor1");
149   naviView.Push( testParentActor1 );
150   DALI_TEST_EQUALS( naviView.GetChildCount(), 1 ,  TEST_LOCATION );
151
152   // 3 Push Second Actor which contains a child actor
153   Actor testParentActor2 = Actor::New();
154   testParentActor2.SetName("TestParentActor2");
155   Actor testChildActor1 = Actor::New();
156   testParentActor2.Add( testChildActor1 );
157   naviView.Push( testParentActor2 );
158
159
160   // 4 Pop head actor, it should be TestParentActor2
161   Actor poppedActor = naviView.Pop();
162   DALI_TEST_EQUALS( poppedActor.GetName() ,  "TestParentActor2", TEST_LOCATION );
163
164   // 5 Navigation View child count should be 1
165   DALI_TEST_EQUALS( naviView.GetChildCount(), 1 ,  TEST_LOCATION );
166
167
168   END_TEST;
169 }
170
171 int UtcDaliNavigationViewPushAndPop(void)
172 {
173   ToolkitTestApplication application;
174
175   Stage stage = Stage::GetCurrent();
176
177   // 1 Create Navigation View
178   NavigationView naviView = NavigationView::New();
179   stage.Add( naviView );
180
181   // 2 Push initial Actor
182   Actor testParentActor1 = Actor::New();
183   testParentActor1.SetName("TestParentActor1");
184   naviView.Push( testParentActor1 );
185   DALI_TEST_EQUALS( naviView.GetChildCount(), 1 ,  TEST_LOCATION );
186
187   // 3 Push Second Actor which contains a child actor
188   Actor testParentActor2 = Actor::New();
189   testParentActor2.SetName("TestParentActor2");
190   Actor testChildActor1 = Actor::New();
191   testParentActor2.Add( testChildActor1 );
192   naviView.Push( testParentActor2 );
193
194   // 3 Push third Actor which contains a child actor
195   Actor testParentActor3 = Actor::New();
196   testParentActor3.SetName("TestParentActor3");
197   Actor testChildActor2 = Actor::New();
198   testParentActor2.Add( testChildActor2 );
199   naviView.Push( testParentActor3 );
200
201   // 4 Pop head actor,  it should be TestParentActor3
202   Actor poppedActor = naviView.Pop();
203   DALI_TEST_EQUALS( poppedActor.GetName() ,  "TestParentActor3", TEST_LOCATION );
204
205   // 5 Pop head actor,  it should be TestParentActor2
206   Actor poppedActor2 = naviView.Pop();
207   DALI_TEST_EQUALS( poppedActor2.GetName() ,  "TestParentActor2", TEST_LOCATION );
208
209
210   END_TEST;
211 }
212
213 int UtcDaliNavigationViewPreventLastPop(void)
214 {
215   ToolkitTestApplication application;
216
217   Stage stage = Stage::GetCurrent();
218
219   // 1 Create Navigation View
220   NavigationView naviView = NavigationView::New();
221   stage.Add( naviView );
222
223   // 2 Push initial Actor
224   Actor testParentActor1 = Actor::New();
225   testParentActor1.SetName("TestParentActor1");
226   naviView.Push( testParentActor1 );
227   DALI_TEST_EQUALS( naviView.GetChildCount(), 1 ,  TEST_LOCATION );
228
229   // 3 Push Second Actor which contains a child actor
230   Actor testParentActor2 = Actor::New();
231   testParentActor2.SetName("TestParentActor2");
232   Actor testChildActor1 = Actor::New();
233   testParentActor2.Add( testChildActor1 );
234   naviView.Push( testParentActor2 );
235
236   // 4 Pop head actor, it should be TestParentActor2
237   Actor poppedActor1 = naviView.Pop();
238   DALI_TEST_EQUALS( poppedActor1.GetName() ,  "TestParentActor2", TEST_LOCATION );
239
240
241   // 5 Try to Pop head actor, Should be empty hence can not get name of Actor
242   Actor poppedActorEmpty = naviView.Pop();
243
244   try
245   {
246     const std::string hasNoName = poppedActorEmpty.GetName();
247     tet_infoline( hasNoName.c_str() );
248     DALI_TEST_CHECK( false ); // should not get here
249   }
250   catch( ... )
251   {
252     DALI_TEST_CHECK( true );
253   }
254
255
256   END_TEST;
257 }