2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
26 using namespace Toolkit;
28 void dali_navigationView_startup(void)
30 test_return_value = TET_UNDEF;
33 void dali_navigationView_cleanup(void)
35 test_return_value = TET_PASS;
38 int UtcDaliNavigationTypeRegistry(void)
40 ToolkitTestApplication application;
42 TypeRegistry typeRegistry = TypeRegistry::Get();
43 DALI_TEST_CHECK(typeRegistry);
45 TypeInfo typeInfo = typeRegistry.GetTypeInfo("NavigationView");
46 DALI_TEST_CHECK(typeInfo);
48 BaseHandle handle = typeInfo.CreateInstance();
49 DALI_TEST_CHECK(handle);
51 NavigationView view = NavigationView::DownCast(handle);
52 DALI_TEST_CHECK(view);
57 int UtcDaliNavigationViewNew(void)
59 ToolkitTestApplication application;
61 NavigationView navigationView;
62 DALI_TEST_CHECK(!navigationView);
64 navigationView = NavigationView::New();
65 DALI_TEST_CHECK(navigationView);
67 application.GetScene().Add(navigationView);
69 application.SendNotification();
75 int UtcDaliNavigationViewCopyAndAssignment(void)
77 ToolkitTestApplication application;
79 NavigationView view = NavigationView::New();
80 DALI_TEST_CHECK(view);
82 NavigationView copy(view);
83 DALI_TEST_CHECK(copy == view);
85 NavigationView assign;
86 DALI_TEST_CHECK(!assign);
88 DALI_TEST_CHECK(assign == view);
92 DALI_TEST_CHECK(assign);
93 DALI_TEST_CHECK(assign == view);
98 int UtcDaliNavigationViewDownCast(void)
100 ToolkitTestApplication application;
102 BaseHandle view = NavigationView::New();
103 DALI_TEST_CHECK(NavigationView::DownCast(view));
106 DALI_TEST_CHECK(!NavigationView::DownCast(empty));
108 BaseHandle another = Actor::New();
109 DALI_TEST_CHECK(!NavigationView::DownCast(another));
114 int UtcDaliNavigationViewPush(void)
116 ToolkitTestApplication application;
118 Integration::Scene stage = application.GetScene();
120 // 1 Create and Add Navigation View to stage, actor count should be zero
121 NavigationView naviView = NavigationView::New();
124 DALI_TEST_EQUALS(naviView.GetChildCount(), 0, TEST_LOCATION);
126 // 2 Add Actor to Navigation View, actor count should increase to 1
128 Actor TestParentActor1 = Actor::New();
129 naviView.Push(TestParentActor1);
131 DALI_TEST_EQUALS(naviView.GetChildCount(), 1, TEST_LOCATION);
136 int UtcDaliNavigationViewPop(void)
138 ToolkitTestApplication application;
140 Integration::Scene stage = application.GetScene();
142 // 1 Create Navigation View
143 NavigationView naviView = NavigationView::New();
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);
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);
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);
163 // 5 Navigation View child count should be 1
164 DALI_TEST_EQUALS(naviView.GetChildCount(), 1, TEST_LOCATION);
169 int UtcDaliNavigationViewPushAndPop(void)
171 ToolkitTestApplication application;
173 Integration::Scene stage = application.GetScene();
175 // 1 Create Navigation View
176 NavigationView naviView = NavigationView::New();
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);
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);
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);
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);
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);
210 int UtcDaliNavigationViewPreventLastPop(void)
212 ToolkitTestApplication application;
214 Integration::Scene stage = application.GetScene();
216 // 1 Create Navigation View
217 NavigationView naviView = NavigationView::New();
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);
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);
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);
237 // 5 Try to Pop head actor, Should be empty hence can not get name of Actor
238 Actor poppedActorEmpty = naviView.Pop();
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
248 DALI_TEST_CHECK(true);