2 * Copyright (c) 2020 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>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/devel-api/controls/popup/confirmation-popup.h>
27 using namespace Toolkit;
29 void utc_dali_toolkit_confirmation_popup_startup(void)
31 test_return_value = TET_UNDEF;
34 void utc_dali_toolkit_confirmation_popup_cleanup(void)
36 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.
92 int UtcDaliConfirmationPopupNewP( void )
94 ToolkitTestApplication application;
95 tet_infoline( " UtcDaliConfirmationPopupNewP" );
97 // Create the ConfirmationPopup.
98 ConfirmationPopup popup;
100 DALI_TEST_CHECK( !popup );
102 popup = ConfirmationPopup::New();
104 DALI_TEST_CHECK( popup );
106 ConfirmationPopup popup2( popup );
108 DALI_TEST_CHECK( popup2 == popup );
110 // Additional check to ensure object is created by checking if it's registered.
111 ObjectRegistry registry = application.GetCore().GetObjectRegistry();
112 DALI_TEST_CHECK( registry );
114 gObjectCreatedCallBackCalled = false;
115 registry.ObjectCreatedSignal().Connect( &TestCallback );
117 ConfirmationPopup popup = ConfirmationPopup::New();
119 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
123 int UtcDaliConfirmationPopupDestructorP( void )
125 ToolkitTestApplication application;
126 tet_infoline( " UtcDaliConfirmationPopupDestructorP" );
128 ConfirmationPopup* popup = new ConfirmationPopup();
131 DALI_TEST_CHECK( true );
135 int UtcDaliConfirmationPopupDownCastP(void)
137 ToolkitTestApplication application;
138 tet_infoline( " UtcDaliConfirmationPopupDownCastP" );
140 Handle handle = ConfirmationPopup::New();
142 ConfirmationPopup popup = ConfirmationPopup::DownCast( handle );
144 DALI_TEST_CHECK( popup == handle );
148 int UtcDaliConfirmationPopupDynamicSignalGenerationP(void)
150 ToolkitTestApplication application;
151 tet_infoline( " UtcDaliConfirmationPopupDynamicSignalGenerationP" );
153 ConfirmationPopup popup = ConfirmationPopup::New();
155 TextLabel titleActor = TextLabel::New( "Title" );
156 popup.SetTitle( titleActor );
158 TextLabel contentActor = TextLabel::New( "Content" );
159 popup.SetContent( contentActor );
161 Actor footerActor = Actor::New();
163 // The confirmation popup can use any control type for the ok or cancel buttons.
164 // It requires that the name is "controlOk" to provide the "controlSignalOk" signal.
165 PushButton buttonOK = PushButton::New();
166 buttonOK.SetProperty( Dali::Actor::Property::NAME, "controlOk" );
167 footerActor.Add( buttonOK );
169 PushButton buttonCancel = PushButton::New();
170 buttonCancel.SetProperty( Dali::Actor::Property::NAME, "controlCancel" );
171 footerActor.Add( buttonCancel );
173 popup.SetFooter( footerActor );
175 // Tell the confirmation popup to connect to the signal in our button called "onScene".
176 popup.SetProperty( Toolkit::ConfirmationPopup::Property::CONNECT_SIGNAL_OK_SELECTED, "onScene" );
177 std::string resultProperty;
178 DALI_TEST_CHECK( popup.GetProperty( Toolkit::ConfirmationPopup::Property::CONNECT_SIGNAL_OK_SELECTED ).Get( resultProperty ) );
179 DALI_TEST_EQUALS( resultProperty, "onScene", TEST_LOCATION );
181 // Connect to the confirmation popup's OK signal. This signal is dynamically created upon connection.
182 gSignalReceivedOK = false;
183 gSignalReceivedCancel = false;
184 TestConnectionTrackerObject* testTracker = new TestConnectionTrackerObject();
185 popup.ConnectSignal( testTracker, "controlSignalOk", ConfirmationPopupOKTestFunctor() );
187 // Check no signal has occurred yet.
188 DALI_TEST_CHECK( !gSignalReceivedOK );
189 DALI_TEST_CHECK( !gSignalReceivedCancel );
191 // Provoke the signal.
192 application.GetScene().Add( popup );
194 // Check the signal has occurred.
195 DALI_TEST_CHECK( gSignalReceivedOK );
196 DALI_TEST_CHECK( !gSignalReceivedCancel );
198 // Remove the popup from the stage, and connect the cancel signal.
200 popup.SetProperty( Toolkit::ConfirmationPopup::Property::CONNECT_SIGNAL_CANCEL_SELECTED, "onScene" );
201 DALI_TEST_CHECK( popup.GetProperty( Toolkit::ConfirmationPopup::Property::CONNECT_SIGNAL_CANCEL_SELECTED ).Get( resultProperty ) );
202 DALI_TEST_EQUALS( resultProperty, "onScene", TEST_LOCATION );
204 popup.ConnectSignal( testTracker, "controlSignalCancel", ConfirmationPopupCancelTestFunctor() );
206 // Check the cancel signal has not occurred yet.
207 DALI_TEST_CHECK( gSignalReceivedOK );
208 DALI_TEST_CHECK( !gSignalReceivedCancel );
210 // Provoke the signal.
211 application.GetScene().Add( popup );
213 // Check the cancel signal has occurred.
214 DALI_TEST_CHECK( gSignalReceivedOK );
215 DALI_TEST_CHECK( gSignalReceivedCancel );
220 int UtcDaliConfirmationPopupDynamicSignalGenerationN(void)
222 ToolkitTestApplication application;
223 tet_infoline( " UtcDaliConfirmationPopupDynamicSignalGenerationN" );
225 ConfirmationPopup popup = ConfirmationPopup::New();
227 TextLabel titleActor = TextLabel::New( "Title" );
228 popup.SetTitle( titleActor );
230 TextLabel contentActor = TextLabel::New( "Content" );
231 popup.SetContent( contentActor );
233 Actor footerActor = Actor::New();
235 PushButton buttonOK = PushButton::New();
236 buttonOK.SetProperty( Dali::Actor::Property::NAME, "controlOkMisnamed" );
237 popup.SetFooter( buttonOK );
239 // Tell the confirmation popup to connect to the signal in our button called "onScene".
240 popup.SetProperty( Toolkit::ConfirmationPopup::Property::CONNECT_SIGNAL_OK_SELECTED, "onScene" );
242 // Connect to the confirmation popup's OK signal.
243 gSignalReceivedOK = false;
245 // The connection will fail at this point as no actor with the name "controlOk" will be located.
246 TestConnectionTrackerObject* testTracker = new TestConnectionTrackerObject();
247 popup.ConnectSignal( testTracker, "controlSignalOk", ConfirmationPopupOKTestFunctor() );
249 // Check no signal has occurred yet.
250 DALI_TEST_CHECK( !gSignalReceivedOK );
252 // Provoke the signal.
253 application.GetScene().Add( popup );
255 // Check the signal has still not occurred, as our button was incorrectly named.
256 DALI_TEST_CHECK( !gSignalReceivedOK );
261 int UtcDaliConfirmationPopupTypeRegistryCreation(void)
263 ToolkitTestApplication application;
264 tet_infoline( " UtcDaliConfirmationPopupTypeRegistryCreation" );
266 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "ConfirmationPopup" );
267 DALI_TEST_CHECK( typeInfo )
269 BaseHandle baseHandle = typeInfo.CreateInstance();
270 DALI_TEST_CHECK( baseHandle )
272 Toolkit::Popup popup = Toolkit::Popup::DownCast( baseHandle );
273 popup.SetProperty( Popup::Property::ANIMATION_DURATION, 0.0f );
275 application.GetScene().Add( popup );
276 popup.SetDisplayState( Toolkit::Popup::SHOWN );
278 application.SendNotification();
279 application.Render();
281 // Check the popup is shown.
282 DALI_TEST_EQUALS( popup.GetDisplayState(), Popup::SHOWN, TEST_LOCATION );