Merge "New Popup implementation" into devel/master
[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 "control-ok" to provide the "control-signal-ok" signal.
165   PushButton buttonOK = PushButton::New();
166   buttonOK.SetName( "control-ok" );
167   footerActor.Add( buttonOK );
168
169   PushButton buttonCancel = PushButton::New();
170   buttonCancel.SetName( "control-cancel" );
171   footerActor.Add( buttonCancel );
172
173   popup.SetFooter( footerActor );
174
175   // Tell the confirmation popup to connect to the signal in our button called "on-stage".
176   popup.SetProperty( Toolkit::ConfirmationPopup::Property::CONNECT_SIGNAL_OK_SELECTED, "on-stage" );
177
178   // Connect to the confirmation popup's OK signal. This signal is dynamically created upon connection.
179   gSignalReceivedOK = false;
180   gSignalReceivedCancel = false;
181   TestConnectionTrackerObject* testTracker = new TestConnectionTrackerObject();
182   popup.ConnectSignal( testTracker, "control-signal-ok", ConfirmationPopupOKTestFunctor() );
183
184   // Check no signal has occurred yet.
185   DALI_TEST_CHECK( !gSignalReceivedOK );
186   DALI_TEST_CHECK( !gSignalReceivedCancel );
187
188   // Provoke the signal.
189   Stage::GetCurrent().Add( popup );
190
191   // Check the signal has occurred.
192   DALI_TEST_CHECK( gSignalReceivedOK );
193   DALI_TEST_CHECK( !gSignalReceivedCancel );
194
195   // Remove the popup from the stage, and connect the cancel signal.
196   popup.Unparent();
197   popup.SetProperty( Toolkit::ConfirmationPopup::Property::CONNECT_SIGNAL_CANCEL_SELECTED, "on-stage" );
198   popup.ConnectSignal( testTracker, "control-signal-cancel", ConfirmationPopupCancelTestFunctor() );
199
200   // Check the cancel signal has not occurred yet.
201   DALI_TEST_CHECK( gSignalReceivedOK );
202   DALI_TEST_CHECK( !gSignalReceivedCancel );
203
204   // Provoke the signal.
205   Stage::GetCurrent().Add( popup );
206
207   // Check the cancel signal has occurred.
208   DALI_TEST_CHECK( gSignalReceivedOK );
209   DALI_TEST_CHECK( gSignalReceivedCancel );
210
211   END_TEST;
212 }
213
214 int UtcDaliConfirmationPopupDynamicSignalGenerationN(void)
215 {
216   ToolkitTestApplication application;
217    tet_infoline( " UtcDaliConfirmationPopupDynamicSignalGenerationN" );
218
219    ConfirmationPopup popup = ConfirmationPopup::New();
220
221    TextLabel titleActor = TextLabel::New( "Title" );
222    popup.SetTitle( titleActor );
223
224    TextLabel contentActor = TextLabel::New( "Content" );
225    popup.SetContent( contentActor );
226
227    Actor footerActor = Actor::New();
228
229    PushButton buttonOK = PushButton::New();
230    buttonOK.SetName( "control-ok-misnamed" );
231    popup.SetFooter( buttonOK );
232
233    // Tell the confirmation popup to connect to the signal in our button called "on-stage".
234    popup.SetProperty( Toolkit::ConfirmationPopup::Property::CONNECT_SIGNAL_OK_SELECTED, "on-stage" );
235
236    // Connect to the confirmation popup's OK signal.
237    gSignalReceivedOK = false;
238
239    // The connection will fail at this point as no actor with the name "control-ok" will be located.
240    TestConnectionTrackerObject* testTracker = new TestConnectionTrackerObject();
241    popup.ConnectSignal( testTracker, "control-signal-ok", ConfirmationPopupOKTestFunctor() );
242
243    // Check no signal has occurred yet.
244    DALI_TEST_CHECK( !gSignalReceivedOK );
245
246    // Provoke the signal.
247    Stage::GetCurrent().Add( popup );
248
249    // Check the signal has still not occurred, as our button was incorrectly named.
250    DALI_TEST_CHECK( !gSignalReceivedOK );
251
252    END_TEST;
253 }
254
255
256