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>
30 using namespace Toolkit;
32 void utc_dali_toolkit_popup_startup(void)
34 test_return_value = TET_UNDEF;
37 void utc_dali_toolkit_popup_cleanup(void)
39 test_return_value = TET_PASS;
44 static bool gObjectCreatedCallBackCalled;
46 static void TestCallback(BaseHandle handle)
48 gObjectCreatedCallBackCalled = true;
51 const int RENDER_FRAME_INTERVAL = 10; ///< Duration of each frame in ms.
52 const int RENDER_ANIMATION_TEST_DURATION_MS = 1000; ///< 1000ms to test animation
53 const int RENDER_ANIMATION_TEST_DURATION_FRAMES = RENDER_ANIMATION_TEST_DURATION_MS / RENDER_FRAME_INTERVAL; ///< equivalent frames.
54 const Vector3 DEFAULT_BUTTON_SIZE(100.0f, 50.0f, 0.0f);
55 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10.0f, 10.0f );
56 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10.0f, 10.0f );
59 * Counts how many descendents root Actor has, including
62 * @param[in] root The root actor to count from.
63 * @return The number of descendents including root actor itself.
65 int DescendentCount(const Actor& root)
67 unsigned int numChildren = root.GetChildCount();
71 for(unsigned int i=0; i<numChildren; ++i)
73 count += DescendentCount(root.GetChildAt(i));
79 bool HasAncestor(Actor child, Actor ancestor)
81 while(child && child != ancestor)
83 child = child.GetParent();
86 return (child == ancestor);
90 static bool gHidden = false;
92 static void OnPopupHidden()
97 static bool gTouchedOutside;
99 static void OnPopupTouchedOutside()
101 gTouchedOutside = true;
107 int UtcDaliPopupNew(void)
109 ToolkitTestApplication application;
110 tet_infoline(" UtcDaliPopupNew");
112 // Create the Popup actor
115 DALI_TEST_CHECK( !popup );
117 popup = Popup::New();
119 DALI_TEST_CHECK( popup );
123 DALI_TEST_CHECK( popup2 == popup );
125 //Additional check to ensure object is created by checking if it's registered
126 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
127 DALI_TEST_CHECK( registry );
129 gObjectCreatedCallBackCalled = false;
130 registry.ObjectCreatedSignal().Connect( &TestCallback );
132 Popup popup = Popup::New();
134 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
138 int UtcDaliPopupDestructor(void)
140 ToolkitTestApplication application;
142 Popup* popup = new Popup();
145 DALI_TEST_CHECK( true );
149 int UtcDaliPopupDownCast(void)
151 ToolkitTestApplication application;
153 Handle handle = Popup::New();
155 Popup popup = Popup::DownCast( handle );
157 DALI_TEST_CHECK( popup == handle );
161 int UtcDaliPopoupSetProperty(void)
163 tet_infoline("UtcDaliPopoupSetProperty: ");
164 ToolkitTestApplication application;
166 Popup popup = Popup::New();
169 std::string testString = "Hello World";
170 popup.SetProperty(popup.GetPropertyIndex("title"), testString);
171 DALI_TEST_EQUALS( testString, popup.GetTitle().GetText(), TEST_LOCATION );
176 int UtcDaliPopupSetBackgroundImage(void)
178 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
179 tet_infoline(" UtcDaliPopupSetBackgroundImage");
181 // Create the Popup actor
182 Popup popup = Popup::New();
183 Stage::GetCurrent().Add( popup );
185 ImageActor image = CreateSolidColorActor( Color::RED );
186 DALI_TEST_CHECK( !image.GetParent() );
187 popup.SetBackgroundImage(image);
188 DALI_TEST_CHECK( image.GetParent() );
192 int UtcDaliPopupSetTitle(void)
194 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
195 tet_infoline(" UtcDaliPopupSetTitle");
197 // Create the Popup actor
198 Popup popup = Popup::New();
199 Stage::GetCurrent().Add( popup );
200 // Put in show state so it's layer is connected to popup (for ancestor check).
201 popup.SetState(Popup::POPUP_SHOW, 0.0f);
203 TextView titleActor = TextView::New();
204 titleActor.SetText("title");
206 DALI_TEST_CHECK( !popup.GetTitle() );
207 popup.SetTitle(titleActor);
208 DALI_TEST_CHECK( popup.GetTitle() == titleActor );
209 DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "title") );
210 // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
211 DALI_TEST_CHECK( HasAncestor(titleActor, popup) );
213 TextView titleActor2 = TextView::New();
214 titleActor2.SetText("anothertitle");
215 popup.SetTitle(titleActor2);
216 DALI_TEST_CHECK( popup.GetTitle() != titleActor );
217 DALI_TEST_CHECK( popup.GetTitle() == titleActor2 );
218 DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "anothertitle") );
219 // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
220 DALI_TEST_CHECK( HasAncestor(titleActor2, popup) );
224 int UtcDaliPopupSetTitleText(void)
226 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
227 tet_infoline(" UtcDaliPopupSetTitleText");
229 // Create the Popup actor
230 Popup popup = Popup::New();
231 Stage::GetCurrent().Add( popup );
232 // Put in show state so it's layer is connected to popup (for ancestor check).
233 popup.SetState(Popup::POPUP_SHOW, 0.0f);
235 TextView titleActor = TextView::New();
236 titleActor.SetText("title");
238 DALI_TEST_CHECK( !popup.GetTitle() );
239 popup.SetTitle(titleActor);
240 DALI_TEST_CHECK( popup.GetTitle() == titleActor );
241 DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "title") );
242 // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
243 DALI_TEST_CHECK( HasAncestor(titleActor, popup) );
245 // this text should replace titleImage actor.
246 popup.SetTitle("newtext");
247 DALI_TEST_CHECK( popup.GetTitle() != titleActor );
248 DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "newtext") );
249 // verify titleActor is no longer inside popup. (been displaced by newtext actor)
250 DALI_TEST_CHECK( !HasAncestor(titleActor, popup) );
254 int UtcDaliPopupAddButton(void)
256 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
257 tet_infoline(" UtcDaliPopupAddButton");
259 // Create the Popup actor
260 Popup popup = Popup::New();
261 Stage::GetCurrent().Add( popup );
262 // Put in show state so it's layer is connected to popup (for ancestor check).
263 popup.SetState(Popup::POPUP_SHOW, 0.0f);
265 PushButton button = PushButton::New();
266 DALI_TEST_CHECK( !HasAncestor(button, popup) );
267 popup.AddButton(button);
268 // Hide and then re-show popup to cause button to be rearranged and added to popup.
269 popup.SetState( Popup::POPUP_HIDE, 0.0f );
270 popup.SetState( Popup::POPUP_SHOW, 0.0f );
271 DALI_TEST_CHECK( HasAncestor(button, popup) );
275 int UtcDaliPopupSetState(void)
277 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
278 tet_infoline(" UtcDaliPopupSetState");
280 // Create the Popup actor
281 Popup popup = Popup::New();
283 ImageActor backgroundImage = CreateSolidColorActor( Color::RED );
284 popup.SetBackgroundImage(backgroundImage);
286 // Showing/Hiding popup, results in all child Actors being
287 // connected/disconnected from the stage.
288 DALI_TEST_CHECK( !backgroundImage.OnStage() );
289 popup.SetState(Popup::POPUP_SHOW, 0.0f);
290 DALI_TEST_CHECK( backgroundImage.OnStage() );
291 DALI_TEST_EQUALS( Popup::POPUP_SHOW, popup.GetState(), TEST_LOCATION );
292 popup.SetState(Popup::POPUP_HIDE, 0.0f);
293 DALI_TEST_CHECK( !backgroundImage.OnStage() );
294 DALI_TEST_EQUALS( Popup::POPUP_HIDE, popup.GetState(), TEST_LOCATION );
298 int UtcDaliPopupSetStateSlow(void)
300 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
301 tet_infoline(" UtcDaliPopupSetStateSlow");
303 // Create the Popup actor
304 Popup popup = Popup::New();
306 ImageActor backgroundImage = CreateSolidColorActor( Color::RED );
307 popup.SetBackgroundImage(backgroundImage);
309 // Showing/Hiding popup, results in all child Actors being
310 // connected/disconnected from the stage.
311 DALI_TEST_CHECK( !backgroundImage.OnStage() );
312 popup.SetState(Popup::POPUP_SHOW, 0.0f);
313 DALI_TEST_CHECK( backgroundImage.OnStage() );
316 popup.SetState(Popup::POPUP_HIDE);
318 // Wait for a while (allow animation to complete), and then check state.
319 for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
321 application.SendNotification();
322 application.Render(RENDER_FRAME_INTERVAL);
325 DALI_TEST_CHECK( !backgroundImage.OnStage() );
331 int UtcDaliPopupShowHide(void)
333 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
334 tet_infoline(" UtcDaliPopupShowHide");
336 // Create the Popup actor
337 Popup popup = Popup::New();
338 popup.HiddenSignal().Connect( &OnPopupHidden );
340 ImageActor backgroundImage = CreateSolidColorActor( Color::RED );
341 popup.SetBackgroundImage(backgroundImage);
343 PushButton button1 = PushButton::New();
344 PushButton button2 = PushButton::New();
345 button1.SetPreferredSize(DEFAULT_BUTTON_SIZE.GetVectorXY());
346 popup.AddButton(button1);
347 button2.SetPreferredSize(DEFAULT_BUTTON_SIZE.GetVectorXY());
348 popup.AddButton(button2);
350 // Showing/Hiding popup, results in all child Actors being
351 // connected/disconnected from the stage.
352 DALI_TEST_CHECK( !backgroundImage.OnStage() );
355 // Note: in most popup animation implementations show would result in
356 // popup being onstage immediately following Show(). However we can't
357 // assume for all. e.g. If one creates a animation with a delay.
360 // Wait for a while (allow animation to complete), and then check state.
361 for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
363 application.SendNotification();
364 application.Render(RENDER_FRAME_INTERVAL);
367 DALI_TEST_CHECK( backgroundImage.OnStage() );
373 // Wait for a while (allow animation to complete), and then check state.
374 for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
376 application.SendNotification();
377 application.Render(RENDER_FRAME_INTERVAL);
380 DALI_TEST_CHECK( !backgroundImage.OnStage() );
381 DALI_TEST_CHECK( gHidden );
385 int UtcDaliPopupShowHideTail(void)
387 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
388 tet_infoline(" UtcDaliPopupShowHideTail");
390 // Create the Popup actor
391 Popup popup = Popup::New();
392 Stage::GetCurrent().Add( popup );
393 popup.SetState(Popup::POPUP_SHOW, 0.0f);
396 int withoutTailCount = DescendentCount(popup);
398 popup.ShowTail(ParentOrigin::BOTTOM_CENTER);
399 int withTailCount = DescendentCount(popup);
401 // There should be more actors if the Tail has been added.
402 DALI_TEST_CHECK( withTailCount > withoutTailCount );
406 int withoutTailCount2 = DescendentCount(popup);
408 DALI_TEST_CHECK( withTailCount > withoutTailCount2 );
412 int UtcDaliPopupOnTouchedOutside(void)
414 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
415 tet_infoline(" UtcDaliPopupOnTouchedOutside");
417 // Create the Popup actor
418 Popup popup = Popup::New();
419 Stage::GetCurrent().Add( popup );
420 popup.SetParentOrigin(ParentOrigin::CENTER);
421 popup.SetAnchorPoint(ParentOrigin::CENTER);
422 popup.SetState(Popup::POPUP_SHOW, 0.0f);
423 popup.OutsideTouchedSignal().Connect( &OnPopupTouchedOutside );
425 application.SendNotification();
426 application.Render();
428 gTouchedOutside = false;
429 Dali::Integration::TouchEvent event;
431 event = Dali::Integration::TouchEvent();
432 event.AddPoint( pointDownOutside );
433 application.ProcessEvent( event );
435 application.SendNotification();
436 application.Render();
438 event = Dali::Integration::TouchEvent();
439 event.AddPoint( pointUpOutside );
440 application.ProcessEvent( event );
442 application.SendNotification();
443 application.Render();
445 DALI_TEST_CHECK(gTouchedOutside);