ImageVisual Action::Reload added
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ConfirmationPopup.cpp
1 /*
2  * Copyright (c) 2015 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 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/devel-api/controls/popup/confirmation-popup.h>
25
26 using namespace Dali;
27 using namespace Toolkit;
28
29 void utc_dali_toolkit_confirmation_popup_startup(void)
30 {
31   test_return_value = TET_UNDEF;
32 }
33
34 void utc_dali_toolkit_confirmation_popup_cleanup(void)
35 {
36   test_return_value = TET_PASS;
37 }
38
39 namespace
40 {
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
92 int UtcDaliConfirmationPopupNewP( void )
93 {
94   ToolkitTestApplication application;
95   tet_infoline( " UtcDaliConfirmationPopupNewP" );
96
97   // Create the ConfirmationPopup.
98   ConfirmationPopup popup;
99
100   DALI_TEST_CHECK( !popup );
101
102   popup = ConfirmationPopup::New();
103
104   DALI_TEST_CHECK( popup );
105
106   ConfirmationPopup popup2( popup );
107
108   DALI_TEST_CHECK( popup2 == popup );
109
110   // Additional check to ensure object is created by checking if it's registered.
111   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
112   DALI_TEST_CHECK( registry );
113
114   gObjectCreatedCallBackCalled = false;
115   registry.ObjectCreatedSignal().Connect( &TestCallback );
116   {
117     ConfirmationPopup popup = ConfirmationPopup::New();
118   }
119   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
120   END_TEST;
121 }
122
123 int UtcDaliConfirmationPopupDestructorP( void )
124 {
125   ToolkitTestApplication application;
126   tet_infoline( " UtcDaliConfirmationPopupDestructorP" );
127
128   ConfirmationPopup* popup = new ConfirmationPopup();
129   delete popup;
130
131   DALI_TEST_CHECK( true );
132   END_TEST;
133 }
134
135 int UtcDaliConfirmationPopupDownCastP(void)
136 {
137   ToolkitTestApplication application;
138   tet_infoline( " UtcDaliConfirmationPopupDownCastP" );
139
140   Handle handle = ConfirmationPopup::New();
141
142   ConfirmationPopup popup = ConfirmationPopup::DownCast( handle );
143
144   DALI_TEST_CHECK( popup == handle );
145   END_TEST;
146 }
147
148 int UtcDaliConfirmationPopupDynamicSignalGenerationP(void)
149 {
150   ToolkitTestApplication application;
151   tet_infoline( " UtcDaliConfirmationPopupDynamicSignalGenerationP" );
152
153   ConfirmationPopup popup = ConfirmationPopup::New();
154
155   TextLabel titleActor = TextLabel::New( "Title" );
156   popup.SetTitle( titleActor );
157
158   TextLabel contentActor = TextLabel::New( "Content" );
159   popup.SetContent( contentActor );
160
161   Actor footerActor = Actor::New();
162
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.SetName( "controlOk" );
167   footerActor.Add( buttonOK );
168
169   PushButton buttonCancel = PushButton::New();
170   buttonCancel.SetName( "controlCancel" );
171   footerActor.Add( buttonCancel );
172
173   popup.SetFooter( footerActor );
174
175   // Tell the confirmation popup to connect to the signal in our button called "onStage".
176   popup.SetProperty( Toolkit::ConfirmationPopup::Property::CONNECT_SIGNAL_OK_SELECTED, "onStage" );
177   std::string resultProperty;
178   DALI_TEST_CHECK( popup.GetProperty( Toolkit::ConfirmationPopup::Property::CONNECT_SIGNAL_OK_SELECTED ).Get( resultProperty ) );
179   DALI_TEST_EQUALS( resultProperty, "onStage",  TEST_LOCATION );
180
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() );
186
187   // Check no signal has occurred yet.
188   DALI_TEST_CHECK( !gSignalReceivedOK );
189   DALI_TEST_CHECK( !gSignalReceivedCancel );
190
191   // Provoke the signal.
192   Stage::GetCurrent().Add( popup );
193
194   // Check the signal has occurred.
195   DALI_TEST_CHECK( gSignalReceivedOK );
196   DALI_TEST_CHECK( !gSignalReceivedCancel );
197
198   // Remove the popup from the stage, and connect the cancel signal.
199   popup.Unparent();
200   popup.SetProperty( Toolkit::ConfirmationPopup::Property::CONNECT_SIGNAL_CANCEL_SELECTED, "onStage" );
201   DALI_TEST_CHECK( popup.GetProperty( Toolkit::ConfirmationPopup::Property::CONNECT_SIGNAL_CANCEL_SELECTED ).Get( resultProperty ) );
202   DALI_TEST_EQUALS( resultProperty, "onStage",  TEST_LOCATION );
203
204   popup.ConnectSignal( testTracker, "controlSignalCancel",   ConfirmationPopupCancelTestFunctor() );
205
206   // Check the cancel signal has not occurred yet.
207   DALI_TEST_CHECK( gSignalReceivedOK );
208   DALI_TEST_CHECK( !gSignalReceivedCancel );
209
210   // Provoke the signal.
211   Stage::GetCurrent().Add( popup );
212
213   // Check the cancel signal has occurred.
214   DALI_TEST_CHECK( gSignalReceivedOK );
215   DALI_TEST_CHECK( gSignalReceivedCancel );
216
217   END_TEST;
218 }
219
220 int UtcDaliConfirmationPopupDynamicSignalGenerationN(void)
221 {
222   ToolkitTestApplication application;
223    tet_infoline( " UtcDaliConfirmationPopupDynamicSignalGenerationN" );
224
225    ConfirmationPopup popup = ConfirmationPopup::New();
226
227    TextLabel titleActor = TextLabel::New( "Title" );
228    popup.SetTitle( titleActor );
229
230    TextLabel contentActor = TextLabel::New( "Content" );
231    popup.SetContent( contentActor );
232
233    Actor footerActor = Actor::New();
234
235    PushButton buttonOK = PushButton::New();
236    buttonOK.SetName( "controlOkMisnamed" );
237    popup.SetFooter( buttonOK );
238
239    // Tell the confirmation popup to connect to the signal in our button called "onStage".
240    popup.SetProperty( Toolkit::ConfirmationPopup::Property::CONNECT_SIGNAL_OK_SELECTED, "onStage" );
241
242    // Connect to the confirmation popup's OK signal.
243    gSignalReceivedOK = false;
244
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() );
248
249    // Check no signal has occurred yet.
250    DALI_TEST_CHECK( !gSignalReceivedOK );
251
252    // Provoke the signal.
253    Stage::GetCurrent().Add( popup );
254
255    // Check the signal has still not occurred, as our button was incorrectly named.
256    DALI_TEST_CHECK( !gSignalReceivedOK );
257
258    END_TEST;
259 }
260
261 int UtcDaliConfirmationPopupTypeRegistryCreation(void)
262 {
263   ToolkitTestApplication application;
264   tet_infoline( " UtcDaliConfirmationPopupTypeRegistryCreation" );
265
266   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "ConfirmationPopup" );
267   DALI_TEST_CHECK( typeInfo )
268
269   BaseHandle baseHandle = typeInfo.CreateInstance();
270   DALI_TEST_CHECK( baseHandle )
271
272   Toolkit::Popup popup = Toolkit::Popup::DownCast( baseHandle );
273   popup.SetProperty( Popup::Property::ANIMATION_DURATION, 0.0f );
274
275   Stage::GetCurrent().Add( popup );
276   popup.SetDisplayState( Toolkit::Popup::SHOWN );
277
278   application.SendNotification();
279   application.Render();
280
281   // Check the popup is shown.
282   DALI_TEST_EQUALS( popup.GetDisplayState(), Popup::SHOWN, TEST_LOCATION );
283
284   END_TEST;
285 }
286
287
288