[dali_2.3.19] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ConfirmationPopup.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 <stdlib.h>
19
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>
23
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit/devel-api/controls/popup/confirmation-popup.h>
26
27 using namespace Dali;
28 using namespace Toolkit;
29
30 void utc_dali_toolkit_confirmation_popup_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_toolkit_confirmation_popup_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 namespace
41 {
42 static bool gObjectCreatedCallBackCalled;
43
44 static void TestCallback(BaseHandle handle)
45 {
46   gObjectCreatedCallBackCalled = true;
47 }
48
49 static bool gSignalReceivedOK;
50 static bool gSignalReceivedCancel;
51
52 /**
53  * A connection tracker is required when connecting to a signal with a functor.
54  */
55 class TestConnectionTrackerObject : public ConnectionTracker
56 {
57 };
58
59 /**
60  * This functor is used to test the confirmation popup's OK signal connection.
61  */
62 struct ConfirmationPopupOKTestFunctor
63 {
64   ConfirmationPopupOKTestFunctor()
65   {
66   }
67
68   void operator()()
69   {
70     gSignalReceivedOK = true;
71   }
72 };
73
74 /**
75  * This functor is used to test the confirmation popup's Cancel signal connection.
76  */
77 struct ConfirmationPopupCancelTestFunctor
78 {
79   ConfirmationPopupCancelTestFunctor()
80   {
81   }
82
83   void operator()()
84   {
85     gSignalReceivedCancel = true;
86   }
87 };
88
89 } // unnamed namespace.
90
91 int UtcDaliConfirmationPopupNewP(void)
92 {
93   ToolkitTestApplication application;
94   tet_infoline(" UtcDaliConfirmationPopupNewP");
95
96   // Create the ConfirmationPopup.
97   ConfirmationPopup popup;
98
99   DALI_TEST_CHECK(!popup);
100
101   popup = ConfirmationPopup::New();
102
103   DALI_TEST_CHECK(popup);
104
105   ConfirmationPopup popup2(popup);
106
107   DALI_TEST_CHECK(popup2 == popup);
108
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);
112
113   gObjectCreatedCallBackCalled = false;
114   registry.ObjectCreatedSignal().Connect(&TestCallback);
115   {
116     ConfirmationPopup popup = ConfirmationPopup::New();
117   }
118   DALI_TEST_CHECK(gObjectCreatedCallBackCalled);
119   END_TEST;
120 }
121
122 int UtcDaliConfirmationPopupDestructorP(void)
123 {
124   ToolkitTestApplication application;
125   tet_infoline(" UtcDaliConfirmationPopupDestructorP");
126
127   ConfirmationPopup* popup = new ConfirmationPopup();
128   delete popup;
129
130   DALI_TEST_CHECK(true);
131   END_TEST;
132 }
133
134 int UtcDaliConfirmationPopupDownCastP(void)
135 {
136   ToolkitTestApplication application;
137   tet_infoline(" UtcDaliConfirmationPopupDownCastP");
138
139   Handle handle = ConfirmationPopup::New();
140
141   ConfirmationPopup popup = ConfirmationPopup::DownCast(handle);
142
143   DALI_TEST_CHECK(popup == handle);
144   END_TEST;
145 }
146
147 int UtcDaliConfirmationPopupDynamicSignalGenerationP(void)
148 {
149   ToolkitTestApplication application;
150   tet_infoline(" UtcDaliConfirmationPopupDynamicSignalGenerationP");
151
152   ConfirmationPopup popup = ConfirmationPopup::New();
153
154   TextLabel titleActor = TextLabel::New("Title");
155   popup.SetTitle(titleActor);
156
157   TextLabel contentActor = TextLabel::New("Content");
158   popup.SetContent(contentActor);
159
160   Actor footerActor = Actor::New();
161
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);
167
168   PushButton buttonCancel = PushButton::New();
169   buttonCancel.SetProperty(Dali::Actor::Property::NAME, "controlCancel");
170   footerActor.Add(buttonCancel);
171
172   popup.SetFooter(footerActor);
173
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);
179
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());
185
186   // Check no signal has occurred yet.
187   DALI_TEST_CHECK(!gSignalReceivedOK);
188   DALI_TEST_CHECK(!gSignalReceivedCancel);
189
190   // Provoke the signal.
191   application.GetScene().Add(popup);
192
193   // Check the signal has occurred.
194   DALI_TEST_CHECK(gSignalReceivedOK);
195   DALI_TEST_CHECK(!gSignalReceivedCancel);
196
197   // Remove the popup from the stage, and connect the cancel signal.
198   popup.Unparent();
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);
202
203   popup.ConnectSignal(testTracker, "controlSignalCancel", ConfirmationPopupCancelTestFunctor());
204
205   // Check the cancel signal has not occurred yet.
206   DALI_TEST_CHECK(gSignalReceivedOK);
207   DALI_TEST_CHECK(!gSignalReceivedCancel);
208
209   // Provoke the signal.
210   application.GetScene().Add(popup);
211
212   // Check the cancel signal has occurred.
213   DALI_TEST_CHECK(gSignalReceivedOK);
214   DALI_TEST_CHECK(gSignalReceivedCancel);
215
216   END_TEST;
217 }
218
219 int UtcDaliConfirmationPopupDynamicSignalGenerationN(void)
220 {
221   ToolkitTestApplication application;
222   tet_infoline(" UtcDaliConfirmationPopupDynamicSignalGenerationN");
223
224   ConfirmationPopup popup = ConfirmationPopup::New();
225
226   TextLabel titleActor = TextLabel::New("Title");
227   popup.SetTitle(titleActor);
228
229   TextLabel contentActor = TextLabel::New("Content");
230   popup.SetContent(contentActor);
231
232   Actor footerActor = Actor::New();
233
234   PushButton buttonOK = PushButton::New();
235   buttonOK.SetProperty(Dali::Actor::Property::NAME, "controlOkMisnamed");
236   popup.SetFooter(buttonOK);
237
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");
240
241   // Connect to the confirmation popup's OK signal.
242   gSignalReceivedOK = false;
243
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());
247
248   // Check no signal has occurred yet.
249   DALI_TEST_CHECK(!gSignalReceivedOK);
250
251   // Provoke the signal.
252   application.GetScene().Add(popup);
253
254   // Check the signal has still not occurred, as our button was incorrectly named.
255   DALI_TEST_CHECK(!gSignalReceivedOK);
256
257   END_TEST;
258 }
259
260 int UtcDaliConfirmationPopupTypeRegistryCreation(void)
261 {
262   ToolkitTestApplication application;
263   tet_infoline(" UtcDaliConfirmationPopupTypeRegistryCreation");
264
265   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo("ConfirmationPopup");
266   DALI_TEST_CHECK(typeInfo)
267
268   BaseHandle baseHandle = typeInfo.CreateInstance();
269   DALI_TEST_CHECK(baseHandle)
270
271   Toolkit::Popup popup = Toolkit::Popup::DownCast(baseHandle);
272   popup.SetProperty(Popup::Property::ANIMATION_DURATION, 0.0f);
273
274   application.GetScene().Add(popup);
275   popup.SetDisplayState(Toolkit::Popup::SHOWN);
276
277   application.SendNotification();
278   application.Render();
279
280   // Check the popup is shown.
281   DALI_TEST_EQUALS(popup.GetDisplayState(), Popup::SHOWN, TEST_LOCATION);
282
283   END_TEST;
284 }