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.
20 // Need to override adaptor classes for toolkit test harness, so include
21 // test harness headers before dali headers.
22 #include <dali-toolkit-test-suite-utils.h>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit/devel-api/controls/popup/confirmation-popup.h>
28 using namespace Toolkit;
30 void utc_dali_toolkit_confirmation_popup_startup(void)
32 test_return_value = TET_UNDEF;
35 void utc_dali_toolkit_confirmation_popup_cleanup(void)
37 test_return_value = TET_PASS;
42 static bool gObjectCreatedCallBackCalled;
44 static void TestCallback(BaseHandle handle)
46 gObjectCreatedCallBackCalled = true;
49 static bool gSignalReceivedOK;
50 static bool gSignalReceivedCancel;
53 * A connection tracker is required when connecting to a signal with a functor.
55 class TestConnectionTrackerObject : public ConnectionTracker
60 * This functor is used to test the confirmation popup's OK signal connection.
62 struct ConfirmationPopupOKTestFunctor
64 ConfirmationPopupOKTestFunctor()
70 gSignalReceivedOK = true;
75 * This functor is used to test the confirmation popup's Cancel signal connection.
77 struct ConfirmationPopupCancelTestFunctor
79 ConfirmationPopupCancelTestFunctor()
85 gSignalReceivedCancel = true;
89 } // unnamed namespace.
91 int UtcDaliConfirmationPopupNewP(void)
93 ToolkitTestApplication application;
94 tet_infoline(" UtcDaliConfirmationPopupNewP");
96 // Create the ConfirmationPopup.
97 ConfirmationPopup popup;
99 DALI_TEST_CHECK(!popup);
101 popup = ConfirmationPopup::New();
103 DALI_TEST_CHECK(popup);
105 ConfirmationPopup popup2(popup);
107 DALI_TEST_CHECK(popup2 == popup);
109 // Additional check to ensure object is created by checking if it's registered.
110 ObjectRegistry registry = application.GetCore().GetObjectRegistry();
111 DALI_TEST_CHECK(registry);
113 gObjectCreatedCallBackCalled = false;
114 registry.ObjectCreatedSignal().Connect(&TestCallback);
116 ConfirmationPopup popup = ConfirmationPopup::New();
118 DALI_TEST_CHECK(gObjectCreatedCallBackCalled);
122 int UtcDaliConfirmationPopupDestructorP(void)
124 ToolkitTestApplication application;
125 tet_infoline(" UtcDaliConfirmationPopupDestructorP");
127 ConfirmationPopup* popup = new ConfirmationPopup();
130 DALI_TEST_CHECK(true);
134 int UtcDaliConfirmationPopupDownCastP(void)
136 ToolkitTestApplication application;
137 tet_infoline(" UtcDaliConfirmationPopupDownCastP");
139 Handle handle = ConfirmationPopup::New();
141 ConfirmationPopup popup = ConfirmationPopup::DownCast(handle);
143 DALI_TEST_CHECK(popup == handle);
147 int UtcDaliConfirmationPopupDynamicSignalGenerationP(void)
149 ToolkitTestApplication application;
150 tet_infoline(" UtcDaliConfirmationPopupDynamicSignalGenerationP");
152 ConfirmationPopup popup = ConfirmationPopup::New();
154 TextLabel titleActor = TextLabel::New("Title");
155 popup.SetTitle(titleActor);
157 TextLabel contentActor = TextLabel::New("Content");
158 popup.SetContent(contentActor);
160 Actor footerActor = Actor::New();
162 // The confirmation popup can use any control type for the ok or cancel buttons.
163 // It requires that the name is "controlOk" to provide the "controlSignalOk" signal.
164 PushButton buttonOK = PushButton::New();
165 buttonOK.SetProperty(Dali::Actor::Property::NAME, "controlOk");
166 footerActor.Add(buttonOK);
168 PushButton buttonCancel = PushButton::New();
169 buttonCancel.SetProperty(Dali::Actor::Property::NAME, "controlCancel");
170 footerActor.Add(buttonCancel);
172 popup.SetFooter(footerActor);
174 // Tell the confirmation popup to connect to the signal in our button called "onScene".
175 popup.SetProperty(Toolkit::ConfirmationPopup::Property::CONNECT_SIGNAL_OK_SELECTED, "onScene");
176 std::string resultProperty;
177 DALI_TEST_CHECK(popup.GetProperty(Toolkit::ConfirmationPopup::Property::CONNECT_SIGNAL_OK_SELECTED).Get(resultProperty));
178 DALI_TEST_EQUALS(resultProperty, "onScene", TEST_LOCATION);
180 // Connect to the confirmation popup's OK signal. This signal is dynamically created upon connection.
181 gSignalReceivedOK = false;
182 gSignalReceivedCancel = false;
183 TestConnectionTrackerObject* testTracker = new TestConnectionTrackerObject();
184 popup.ConnectSignal(testTracker, "controlSignalOk", ConfirmationPopupOKTestFunctor());
186 // Check no signal has occurred yet.
187 DALI_TEST_CHECK(!gSignalReceivedOK);
188 DALI_TEST_CHECK(!gSignalReceivedCancel);
190 // Provoke the signal.
191 application.GetScene().Add(popup);
193 // Check the signal has occurred.
194 DALI_TEST_CHECK(gSignalReceivedOK);
195 DALI_TEST_CHECK(!gSignalReceivedCancel);
197 // Remove the popup from the stage, and connect the cancel signal.
199 popup.SetProperty(Toolkit::ConfirmationPopup::Property::CONNECT_SIGNAL_CANCEL_SELECTED, "onScene");
200 DALI_TEST_CHECK(popup.GetProperty(Toolkit::ConfirmationPopup::Property::CONNECT_SIGNAL_CANCEL_SELECTED).Get(resultProperty));
201 DALI_TEST_EQUALS(resultProperty, "onScene", TEST_LOCATION);
203 popup.ConnectSignal(testTracker, "controlSignalCancel", ConfirmationPopupCancelTestFunctor());
205 // Check the cancel signal has not occurred yet.
206 DALI_TEST_CHECK(gSignalReceivedOK);
207 DALI_TEST_CHECK(!gSignalReceivedCancel);
209 // Provoke the signal.
210 application.GetScene().Add(popup);
212 // Check the cancel signal has occurred.
213 DALI_TEST_CHECK(gSignalReceivedOK);
214 DALI_TEST_CHECK(gSignalReceivedCancel);
219 int UtcDaliConfirmationPopupDynamicSignalGenerationN(void)
221 ToolkitTestApplication application;
222 tet_infoline(" UtcDaliConfirmationPopupDynamicSignalGenerationN");
224 ConfirmationPopup popup = ConfirmationPopup::New();
226 TextLabel titleActor = TextLabel::New("Title");
227 popup.SetTitle(titleActor);
229 TextLabel contentActor = TextLabel::New("Content");
230 popup.SetContent(contentActor);
232 Actor footerActor = Actor::New();
234 PushButton buttonOK = PushButton::New();
235 buttonOK.SetProperty(Dali::Actor::Property::NAME, "controlOkMisnamed");
236 popup.SetFooter(buttonOK);
238 // Tell the confirmation popup to connect to the signal in our button called "onScene".
239 popup.SetProperty(Toolkit::ConfirmationPopup::Property::CONNECT_SIGNAL_OK_SELECTED, "onScene");
241 // Connect to the confirmation popup's OK signal.
242 gSignalReceivedOK = false;
244 // The connection will fail at this point as no actor with the name "controlOk" will be located.
245 TestConnectionTrackerObject* testTracker = new TestConnectionTrackerObject();
246 popup.ConnectSignal(testTracker, "controlSignalOk", ConfirmationPopupOKTestFunctor());
248 // Check no signal has occurred yet.
249 DALI_TEST_CHECK(!gSignalReceivedOK);
251 // Provoke the signal.
252 application.GetScene().Add(popup);
254 // Check the signal has still not occurred, as our button was incorrectly named.
255 DALI_TEST_CHECK(!gSignalReceivedOK);
260 int UtcDaliConfirmationPopupTypeRegistryCreation(void)
262 ToolkitTestApplication application;
263 tet_infoline(" UtcDaliConfirmationPopupTypeRegistryCreation");
265 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo("ConfirmationPopup");
266 DALI_TEST_CHECK(typeInfo)
268 BaseHandle baseHandle = typeInfo.CreateInstance();
269 DALI_TEST_CHECK(baseHandle)
271 Toolkit::Popup popup = Toolkit::Popup::DownCast(baseHandle);
272 popup.SetProperty(Popup::Property::ANIMATION_DURATION, 0.0f);
274 application.GetScene().Add(popup);
275 popup.SetDisplayState(Toolkit::Popup::SHOWN);
277 application.SendNotification();
278 application.Render();
280 // Check the popup is shown.
281 DALI_TEST_EQUALS(popup.GetDisplayState(), Popup::SHOWN, TEST_LOCATION);