2 * Copyright (c) 2014 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.
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
26 #include <dali/integration-api/events/touch-event-integ.h>
27 #include <dali-toolkit/dali-toolkit.h>
28 #include <dali-toolkit/devel-api/controls/popup/popup.h>
31 using namespace Toolkit;
33 void utc_dali_toolkit_popup_startup(void)
35 test_return_value = TET_UNDEF;
38 void utc_dali_toolkit_popup_cleanup(void)
40 test_return_value = TET_PASS;
45 static bool gObjectCreatedCallBackCalled;
47 static void TestCallback(BaseHandle handle)
49 gObjectCreatedCallBackCalled = true;
52 const int RENDER_FRAME_INTERVAL = 10; ///< Duration of each frame in ms.
53 const int RENDER_ANIMATION_TEST_DURATION_MS = 1000; ///< 1000ms to test animation
54 const int RENDER_ANIMATION_TEST_DURATION_FRAMES = RENDER_ANIMATION_TEST_DURATION_MS / RENDER_FRAME_INTERVAL; ///< equivalent frames.
55 const Vector3 DEFAULT_BUTTON_SIZE(100.0f, 50.0f, 0.0f);
56 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10.0f, 10.0f );
57 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10.0f, 10.0f );
60 * Counts how many descendents root Actor has, including
63 * @param[in] root The root actor to count from.
64 * @return The number of descendents including root actor itself.
66 int DescendentCount(const Actor& root)
68 unsigned int numChildren = root.GetChildCount();
72 for(unsigned int i=0; i<numChildren; ++i)
74 count += DescendentCount(root.GetChildAt(i));
80 bool HasAncestor(Actor child, Actor ancestor)
82 while(child && child != ancestor)
84 child = child.GetParent();
87 return (child == ancestor);
91 static bool gHidden = false;
93 static void OnPopupHidden()
98 static bool gTouchedOutside;
100 static void OnPopupTouchedOutside()
102 gTouchedOutside = true;
108 int UtcDaliPopupNew(void)
110 ToolkitTestApplication application;
111 tet_infoline(" UtcDaliPopupNew");
113 // Create the Popup actor
116 DALI_TEST_CHECK( !popup );
118 popup = Popup::New();
120 DALI_TEST_CHECK( popup );
124 DALI_TEST_CHECK( popup2 == popup );
126 //Additional check to ensure object is created by checking if it's registered
127 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
128 DALI_TEST_CHECK( registry );
130 gObjectCreatedCallBackCalled = false;
131 registry.ObjectCreatedSignal().Connect( &TestCallback );
133 Popup popup = Popup::New();
135 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
139 int UtcDaliPopupDestructor(void)
141 ToolkitTestApplication application;
143 Popup* popup = new Popup();
146 DALI_TEST_CHECK( true );
150 int UtcDaliPopupDownCast(void)
152 ToolkitTestApplication application;
154 Handle handle = Popup::New();
156 Popup popup = Popup::DownCast( handle );
158 DALI_TEST_CHECK( popup == handle );
162 int UtcDaliPopoupSetProperty(void)
164 tet_infoline("UtcDaliPopoupSetProperty: ");
165 ToolkitTestApplication application;
167 Popup popup = Popup::New();
170 std::string testString = "Hello World";
171 popup.SetProperty(popup.GetPropertyIndex("title"), testString);
172 DALI_TEST_EQUALS( testString, popup.GetTitle(), TEST_LOCATION );
177 int UtcDaliPopupSetBackgroundImage(void)
179 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
180 tet_infoline(" UtcDaliPopupSetBackgroundImage");
182 // Create the Popup actor
183 Popup popup = Popup::New();
184 Stage::GetCurrent().Add( popup );
186 ImageActor image = CreateSolidColorActor( Color::RED );
187 DALI_TEST_CHECK( !image.GetParent() );
188 popup.SetBackgroundImage(image);
189 DALI_TEST_CHECK( image.GetParent() );
193 int UtcDaliPopupSetTitle(void)
195 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
196 tet_infoline(" UtcDaliPopupSetTitle");
198 // Create the Popup actor
199 Popup popup = Popup::New();
200 Stage::GetCurrent().Add( popup );
201 // Put in show state so it's layer is connected to popup (for ancestor check).
202 popup.SetState(Popup::POPUP_SHOW, 0.0f);
204 popup.SetTitle("title");
206 DALI_TEST_CHECK( popup.GetTitle() == "title" );
211 int UtcDaliPopupAddButton(void)
213 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
214 tet_infoline(" UtcDaliPopupAddButton");
216 // Create the Popup actor
217 Popup popup = Popup::New();
218 Stage::GetCurrent().Add( popup );
219 // Put in show state so it's layer is connected to popup (for ancestor check).
220 popup.SetState(Popup::POPUP_SHOW, 0.0f);
222 PushButton button = PushButton::New();
223 DALI_TEST_CHECK( !HasAncestor(button, popup) );
224 popup.AddButton(button);
225 // Hide and then re-show popup to cause button to be rearranged and added to popup.
226 popup.SetState( Popup::POPUP_HIDE, 0.0f );
227 popup.SetState( Popup::POPUP_SHOW, 0.0f );
228 DALI_TEST_CHECK( HasAncestor(button, popup) );
232 int UtcDaliPopupSetState(void)
234 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
235 tet_infoline(" UtcDaliPopupSetState");
237 // Create the Popup actor
238 Popup popup = Popup::New();
240 ImageActor backgroundImage = CreateSolidColorActor( Color::RED );
241 popup.SetBackgroundImage(backgroundImage);
243 // Showing/Hiding popup, results in all child Actors being
244 // connected/disconnected from the stage.
245 DALI_TEST_CHECK( !backgroundImage.OnStage() );
246 popup.SetState(Popup::POPUP_SHOW, 0.0f);
247 DALI_TEST_CHECK( backgroundImage.OnStage() );
248 DALI_TEST_EQUALS( Popup::POPUP_SHOW, popup.GetState(), TEST_LOCATION );
249 popup.SetState(Popup::POPUP_HIDE, 0.0f);
250 DALI_TEST_CHECK( !backgroundImage.OnStage() );
251 DALI_TEST_EQUALS( Popup::POPUP_HIDE, popup.GetState(), TEST_LOCATION );
255 int UtcDaliPopupSetStateSlow(void)
257 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
258 tet_infoline(" UtcDaliPopupSetStateSlow");
260 // Create the Popup actor
261 Popup popup = Popup::New();
263 ImageActor backgroundImage = CreateSolidColorActor( Color::RED );
264 popup.SetBackgroundImage(backgroundImage);
266 // Showing/Hiding popup, results in all child Actors being
267 // connected/disconnected from the stage.
268 DALI_TEST_CHECK( !backgroundImage.OnStage() );
269 popup.SetState(Popup::POPUP_SHOW, 0.0f);
270 DALI_TEST_CHECK( backgroundImage.OnStage() );
273 popup.SetState(Popup::POPUP_HIDE);
275 // Wait for a while (allow animation to complete), and then check state.
276 for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
278 application.SendNotification();
279 application.Render(RENDER_FRAME_INTERVAL);
282 DALI_TEST_CHECK( !backgroundImage.OnStage() );
288 int UtcDaliPopupShowHide(void)
290 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
291 tet_infoline(" UtcDaliPopupShowHide");
293 // Create the Popup actor
294 Popup popup = Popup::New();
295 popup.HiddenSignal().Connect( &OnPopupHidden );
297 ImageActor backgroundImage = CreateSolidColorActor( Color::RED );
298 popup.SetBackgroundImage(backgroundImage);
300 PushButton button1 = PushButton::New();
301 PushButton button2 = PushButton::New();
302 button1.SetSize(DEFAULT_BUTTON_SIZE.GetVectorXY());
303 popup.AddButton(button1);
304 button2.SetSize(DEFAULT_BUTTON_SIZE.GetVectorXY());
305 popup.AddButton(button2);
307 // Showing/Hiding popup, results in all child Actors being
308 // connected/disconnected from the stage.
309 DALI_TEST_CHECK( !backgroundImage.OnStage() );
312 // Note: in most popup animation implementations show would result in
313 // popup being onstage immediately following Show(). However we can't
314 // assume for all. e.g. If one creates a animation with a delay.
317 // Wait for a while (allow animation to complete), and then check state.
318 for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
320 application.SendNotification();
321 application.Render(RENDER_FRAME_INTERVAL);
324 DALI_TEST_CHECK( backgroundImage.OnStage() );
330 // Wait for a while (allow animation to complete), and then check state.
331 for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
333 application.SendNotification();
334 application.Render(RENDER_FRAME_INTERVAL);
337 DALI_TEST_CHECK( !backgroundImage.OnStage() );
338 DALI_TEST_CHECK( gHidden );
342 int UtcDaliPopupShowHideTail(void)
344 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
345 tet_infoline(" UtcDaliPopupShowHideTail");
347 // Create the Popup actor
348 Popup popup = Popup::New();
349 Stage::GetCurrent().Add( popup );
350 popup.SetState(Popup::POPUP_SHOW, 0.0f);
353 int withoutTailCount = DescendentCount(popup);
355 popup.ShowTail(ParentOrigin::BOTTOM_CENTER);
356 int withTailCount = DescendentCount(popup);
358 // There should be more actors if the Tail has been added.
359 DALI_TEST_CHECK( withTailCount > withoutTailCount );
363 int withoutTailCount2 = DescendentCount(popup);
365 DALI_TEST_CHECK( withTailCount > withoutTailCount2 );
369 int UtcDaliPopupOnTouchedOutside(void)
371 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
372 tet_infoline(" UtcDaliPopupOnTouchedOutside");
374 // Create the Popup actor
375 Popup popup = Popup::New();
376 Stage::GetCurrent().Add( popup );
377 popup.SetParentOrigin(ParentOrigin::CENTER);
378 popup.SetAnchorPoint(ParentOrigin::CENTER);
379 popup.SetState(Popup::POPUP_SHOW, 0.0f);
380 popup.OutsideTouchedSignal().Connect( &OnPopupTouchedOutside );
382 application.SendNotification();
383 application.Render();
385 gTouchedOutside = false;
386 Dali::Integration::TouchEvent event;
388 event = Dali::Integration::TouchEvent();
389 event.AddPoint( pointDownOutside );
390 application.ProcessEvent( event );
392 application.SendNotification();
393 application.Render();
395 event = Dali::Integration::TouchEvent();
396 event.AddPoint( pointUpOutside );
397 application.ProcessEvent( event );
399 application.SendNotification();
400 application.Render();
402 DALI_TEST_CHECK(gTouchedOutside);