Dali 3D User Interface Engine
utc-Dali-ConfirmationPopup.cpp
Go to the documentation of this file.
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.
25 
26 using namespace Dali;
27 using namespace Toolkit;
28 
30 {
32 }
33 
35 {
37 }
38 
39 namespace
40 {
41 
43 
44 static void TestCallback(BaseHandle handle)
45 {
46  gObjectCreatedCallBackCalled = true;
47 }
48 
49 static bool gSignalReceivedOK;
51 
56 {
57 };
58 
63 {
65  {
66  }
67 
68  void operator()()
69  {
70  gSignalReceivedOK = true;
71  }
72 };
73 
78 {
80  {
81  }
82 
83  void operator()()
84  {
85  gSignalReceivedCancel = true;
86  }
87 };
88 
89 } // unnamed namespace.
90 
91 
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.
112  DALI_TEST_CHECK( registry );
113 
115  registry.ObjectCreatedSignal().Connect( &TestCallback );
116  {
118  }
120  END_TEST;
121 }
122 
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 
136 {
137  ToolkitTestApplication application;
138  tet_infoline( " UtcDaliConfirmationPopupDownCastP" );
139 
140  Handle handle = ConfirmationPopup::New();
141 
143 
144  DALI_TEST_CHECK( popup == handle );
145  END_TEST;
146 }
147 
149 {
150  ToolkitTestApplication application;
151  tet_infoline( " UtcDaliConfirmationPopupDynamicSignalGenerationP" );
152 
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".
177  std::string 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;
185  popup.ConnectSignal( testTracker, "controlSignalOk", ConfirmationPopupOKTestFunctor() );
186 
187  // Check no signal has occurred yet.
190 
191  // Provoke the signal.
192  Stage::GetCurrent().Add( popup );
193 
194  // Check the signal has occurred.
197 
198  // Remove the popup from the stage, and connect the cancel signal.
199  popup.Unparent();
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.
209 
210  // Provoke the signal.
211  Stage::GetCurrent().Add( popup );
212 
213  // Check the cancel signal has occurred.
216 
217  END_TEST;
218 }
219 
221 {
222  ToolkitTestApplication application;
223  tet_infoline( " UtcDaliConfirmationPopupDynamicSignalGenerationN" );
224 
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".
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.
247  popup.ConnectSignal( testTracker, "controlSignalOk", ConfirmationPopupOKTestFunctor() );
248 
249  // Check no signal has occurred yet.
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.
257 
258  END_TEST;
259 }
260 
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 );
274 
275  Stage::GetCurrent().Add( popup );
277 
278  application.SendNotification();
279  application.Render();
280 
281  // Check the popup is shown.
283 
284  END_TEST;
285 }
286 
287 
288 
Dali Docs Home
Read more about Dali