[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-NavigationView.cpp
1 /*
2  * Copyright (c) 2022 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 <dali-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/dali-toolkit.h>
20 #include <dali-toolkit/devel-api/controls/navigation-view/navigation-view.h>
21 #include <stdlib.h>
22 #include <iostream>
23 #include <sstream>
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   application.GetScene().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   Integration::Scene stage = application.GetScene();
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   Integration::Scene stage = application.GetScene();
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.SetProperty(Dali::Actor::Property::NAME, "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.SetProperty(Dali::Actor::Property::NAME, "TestParentActor2");
155   Actor testChildActor1 = Actor::New();
156   testParentActor2.Add(testChildActor1);
157   naviView.Push(testParentActor2);
158
159   // 4 Pop head actor, it should be TestParentActor2
160   Actor poppedActor = naviView.Pop();
161   DALI_TEST_EQUALS(poppedActor.GetProperty<std::string>(Dali::Actor::Property::NAME), "TestParentActor2", TEST_LOCATION);
162
163   // 5 Navigation View child count should be 1
164   DALI_TEST_EQUALS(naviView.GetChildCount(), 1, TEST_LOCATION);
165
166   END_TEST;
167 }
168
169 int UtcDaliNavigationViewPushAndPop(void)
170 {
171   ToolkitTestApplication application;
172
173   Integration::Scene stage = application.GetScene();
174
175   // 1 Create Navigation View
176   NavigationView naviView = NavigationView::New();
177   stage.Add(naviView);
178
179   // 2 Push initial Actor
180   Actor testParentActor1 = Actor::New();
181   testParentActor1.SetProperty(Dali::Actor::Property::NAME, "TestParentActor1");
182   naviView.Push(testParentActor1);
183   DALI_TEST_EQUALS(naviView.GetChildCount(), 1, TEST_LOCATION);
184
185   // 3 Push Second Actor which contains a child actor
186   Actor testParentActor2 = Actor::New();
187   testParentActor2.SetProperty(Dali::Actor::Property::NAME, "TestParentActor2");
188   Actor testChildActor1 = Actor::New();
189   testParentActor2.Add(testChildActor1);
190   naviView.Push(testParentActor2);
191
192   // 3 Push third Actor which contains a child actor
193   Actor testParentActor3 = Actor::New();
194   testParentActor3.SetProperty(Dali::Actor::Property::NAME, "TestParentActor3");
195   Actor testChildActor2 = Actor::New();
196   testParentActor2.Add(testChildActor2);
197   naviView.Push(testParentActor3);
198
199   // 4 Pop head actor,  it should be TestParentActor3
200   Actor poppedActor = naviView.Pop();
201   DALI_TEST_EQUALS(poppedActor.GetProperty<std::string>(Dali::Actor::Property::NAME), "TestParentActor3", TEST_LOCATION);
202
203   // 5 Pop head actor,  it should be TestParentActor2
204   Actor poppedActor2 = naviView.Pop();
205   DALI_TEST_EQUALS(poppedActor2.GetProperty<std::string>(Dali::Actor::Property::NAME), "TestParentActor2", TEST_LOCATION);
206
207   END_TEST;
208 }
209
210 int UtcDaliNavigationViewPreventLastPop(void)
211 {
212   ToolkitTestApplication application;
213
214   Integration::Scene stage = application.GetScene();
215
216   // 1 Create Navigation View
217   NavigationView naviView = NavigationView::New();
218   stage.Add(naviView);
219
220   // 2 Push initial Actor
221   Actor testParentActor1 = Actor::New();
222   testParentActor1.SetProperty(Dali::Actor::Property::NAME, "TestParentActor1");
223   naviView.Push(testParentActor1);
224   DALI_TEST_EQUALS(naviView.GetChildCount(), 1, TEST_LOCATION);
225
226   // 3 Push Second Actor which contains a child actor
227   Actor testParentActor2 = Actor::New();
228   testParentActor2.SetProperty(Dali::Actor::Property::NAME, "TestParentActor2");
229   Actor testChildActor1 = Actor::New();
230   testParentActor2.Add(testChildActor1);
231   naviView.Push(testParentActor2);
232
233   // 4 Pop head actor, it should be TestParentActor2
234   Actor poppedActor1 = naviView.Pop();
235   DALI_TEST_EQUALS(poppedActor1.GetProperty<std::string>(Dali::Actor::Property::NAME), "TestParentActor2", TEST_LOCATION);
236
237   // 5 Try to Pop head actor, Should be empty hence can not get name of Actor
238   Actor poppedActorEmpty = naviView.Pop();
239
240   try
241   {
242     const std::string hasNoName = poppedActorEmpty.GetProperty<std::string>(Dali::Actor::Property::NAME);
243     tet_infoline(hasNoName.c_str());
244     DALI_TEST_CHECK(false); // should not get here
245   }
246   catch(...)
247   {
248     DALI_TEST_CHECK(true);
249   }
250
251   END_TEST;
252 }