2 * Copyright (c) 2015 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.
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-test-utils/toolkit-timer.h"
26 #include <dali/integration-api/events/touch-event-integ.h>
27 #include <dali/devel-api/scripting/scripting.h>
28 #include <dali-toolkit/dali-toolkit.h>
29 #include <dali-toolkit/devel-api/controls/popup/popup.h>
32 using namespace Toolkit;
34 void utc_dali_toolkit_popup_startup(void)
36 test_return_value = TET_UNDEF;
39 void utc_dali_toolkit_popup_cleanup(void)
41 test_return_value = TET_PASS;
46 static bool gObjectCreatedCallBackCalled;
48 static void TestCallback(BaseHandle handle)
50 gObjectCreatedCallBackCalled = true;
53 const int RENDER_FRAME_INTERVAL = 10; ///< Duration of each frame in ms.
54 const int RENDER_ANIMATION_TEST_DURATION_MS = 2000; ///< 2000ms to test animation.
55 const int RENDER_ANIMATION_TEST_DURATION_FRAMES = RENDER_ANIMATION_TEST_DURATION_MS / RENDER_FRAME_INTERVAL; ///< equivalent frames.
56 const Vector3 DEFAULT_BUTTON_SIZE(100.0f, 50.0f, 0.0f);
57 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10.0f, 10.0f );
58 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10.0f, 10.0f );
61 * Counts how many descendants root Actor has, including
64 * @param[in] root The root actor to count from.
65 * @return The number of descendants including root actor itself.
67 int DescendentCount(const Actor& root)
69 unsigned int numChildren = root.GetChildCount();
73 for(unsigned int i=0; i<numChildren; ++i)
75 count += DescendentCount(root.GetChildAt(i));
81 bool HasAncestor(Actor child, Actor ancestor)
83 while(child && child != ancestor)
85 child = child.GetParent();
88 return (child == ancestor);
91 static Toolkit::Popup::DisplayState gPopupState = Toolkit::Popup::HIDDEN;
92 static bool gTouchedOutside;
96 static void OnPopupTouchedOutside()
98 gTouchedOutside = true;
101 static void OnPopupShowing()
103 gPopupState = Toolkit::Popup::SHOWING;
106 static void OnPopupShown()
108 gPopupState = Toolkit::Popup::SHOWN;
111 static void OnPopupHiding()
113 gPopupState = Toolkit::Popup::HIDING;
116 static void OnPopupHidden()
118 gPopupState = Toolkit::Popup::HIDDEN;
121 void ConnectStateSignals( Toolkit::Popup popup )
123 popup.ShowingSignal().Connect( &OnPopupShowing );
124 popup.ShownSignal().Connect( &OnPopupShown );
125 popup.HidingSignal().Connect( &OnPopupHiding );
126 popup.HiddenSignal().Connect( &OnPopupHidden );
129 void WaitAnimation( ToolkitTestApplication& application )
131 // Wait for a while (allow animation to complete), and then check state.
132 for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++ )
134 application.SendNotification();
135 application.Render( RENDER_FRAME_INTERVAL );
139 } // Anonymous namespace
142 * This test checks popup creation.
144 int UtcDaliPopupNewP( void )
146 ToolkitTestApplication application;
147 tet_infoline( " UtcDaliPopupNewP" );
149 // Create the Popup actor.
152 DALI_TEST_CHECK( !popup );
154 popup = Popup::New();
156 DALI_TEST_CHECK( popup );
158 Popup popup2( popup );
160 DALI_TEST_CHECK( popup2 == popup );
162 // Additional check to ensure object is created by checking if it's registered.
163 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
164 DALI_TEST_CHECK( registry );
166 gObjectCreatedCallBackCalled = false;
167 registry.ObjectCreatedSignal().Connect( &TestCallback );
169 Popup popup = Popup::New();
171 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
176 * This test checks popup destruction.
178 int UtcDaliPopupDestructorP( void )
180 ToolkitTestApplication application;
181 tet_infoline( " UtcDaliPopupDestructorP" );
183 Popup* popup = new Popup();
186 DALI_TEST_CHECK( true );
190 int UtcDaliPopupDownCastP(void)
192 ToolkitTestApplication application;
193 tet_infoline( " UtcDaliPopupDownCastP" );
195 Handle handle = Popup::New();
197 Popup popup = Popup::DownCast( handle );
199 DALI_TEST_CHECK( popup == handle );
203 int UtcDaliPopupSetPropertyP(void)
205 ToolkitTestApplication application;
206 tet_infoline( " UtcDaliPopupSetProperty" );
208 Popup popup = Popup::New();
211 std::string testString = "Hello World";
213 TextLabel textActorIn = TextLabel::New( testString );
215 Scripting::CreatePropertyMap( textActorIn, map );
216 popup.SetProperty( popup.GetPropertyIndex( "title" ), map );
217 TextLabel textActorOut = TextLabel::DownCast( popup.GetTitle() );
218 std::string resultText;
219 DALI_TEST_CHECK( textActorOut.GetProperty( Toolkit::TextLabel::Property::TEXT ).Get( resultText ) );
220 DALI_TEST_EQUALS( testString, resultText, TEST_LOCATION );
225 int UtcDaliPopupSetTitleP(void)
227 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
228 tet_infoline( " UtcDaliPopupSetTitleP" );
230 // Create the Popup actor
231 Popup popup = Popup::New();
233 // Put in show state so it's layer is connected to popup (for ancestor check).
234 popup.SetDisplayState( Popup::SHOWN );
236 TextLabel titleActor = TextLabel::New();
237 titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, "title" );
239 DALI_TEST_CHECK( !popup.GetTitle() );
240 popup.SetTitle( titleActor );
241 TextLabel textActor = TextLabel::DownCast( popup.GetTitle() );
242 DALI_TEST_CHECK( textActor == titleActor );
244 std::string resultText;
245 DALI_TEST_CHECK( textActor.GetProperty( Toolkit::TextLabel::Property::TEXT ).Get( resultText ) );
247 DALI_TEST_CHECK( ( popup.GetTitle() ) && ( resultText == "title" ) );
248 // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
249 DALI_TEST_CHECK( HasAncestor( titleActor, popup ) );
251 TextLabel titleActor2 = TextLabel::New();
252 titleActor2.SetProperty( Toolkit::TextLabel::Property::TEXT, "anothertitle" );
253 popup.SetTitle( titleActor2 );
254 DALI_TEST_CHECK( popup.GetTitle() != titleActor );
255 DALI_TEST_CHECK( popup.GetTitle() == titleActor2 );
256 DALI_TEST_CHECK( TextLabel::DownCast( popup.GetTitle() ).GetProperty( Toolkit::TextLabel::Property::TEXT ).Get( resultText ) );
258 DALI_TEST_CHECK( ( popup.GetTitle() ) && ( resultText == "anothertitle" ) );
260 // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
261 DALI_TEST_CHECK( HasAncestor( titleActor2, popup ) );
265 int UtcDaliPopupSetTitleN(void)
267 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
268 tet_infoline( " UtcDaliPopupSetTitleN" );
270 // Create the Popup actor
271 Popup popup = Popup::New();
273 TextLabel titleActor = TextLabel::New( "text" );
274 popup.SetTitle( titleActor );
276 DALI_TEST_CHECK( popup.GetTitle() );
278 // Set a bad title value.
279 // Confirm this has disabled the title.
281 popup.SetTitle( badActor );
283 DALI_TEST_CHECK( !popup.GetTitle() );
288 int UtcDaliPopupSetContentP(void)
290 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
291 tet_infoline( " UtcDaliPopupSetContentP" );
293 // Create the Popup actor
294 Popup popup = Popup::New();
295 Stage::GetCurrent().Add( popup );
296 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, 0.0f );
298 // Put in show state so it's layer is connected to popup (for ancestor check).
299 popup.SetDisplayState( Popup::SHOWN );
301 PushButton button = PushButton::New();
302 DALI_TEST_CHECK( !HasAncestor( button, popup ) );
303 popup.SetFooter( button );
304 // Hide and then re-show popup to cause button to be rearranged and added to popup.
305 popup.SetDisplayState( Popup::HIDDEN );
306 popup.SetDisplayState( Popup::SHOWN );
307 DALI_TEST_CHECK( HasAncestor( button, popup ) );
311 int UtcDaliPopupSetContentN(void)
313 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
314 tet_infoline( " UtcDaliPopupSetContentN" );
316 // Create the Popup actor
317 Popup popup = Popup::New();
319 TextLabel content = TextLabel::New( "text" );
320 popup.SetContent( content );
322 DALI_TEST_CHECK( popup.GetContent() );
324 // Set a bad title value.
326 popup.SetContent( badActor );
328 DALI_TEST_CHECK( !popup.GetContent() );
333 int UtcDaliPopupSetFooterP(void)
335 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
336 tet_infoline(" UtcDaliPopupSetFooterP");
338 // Create the Popup actor
339 Popup popup = Popup::New();
340 Stage::GetCurrent().Add( popup );
341 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, 0.0f );
342 // Put in show state so it's layer is connected to popup (for ancestor check).
343 popup.SetDisplayState( Popup::SHOWN );
345 PushButton button = PushButton::New();
346 DALI_TEST_CHECK( !HasAncestor(button, popup) );
347 popup.SetFooter( button );
348 // Hide and then re-show popup to cause button to be rearranged and added to popup.
349 popup.SetDisplayState( Popup::HIDDEN );
350 popup.SetDisplayState( Popup::SHOWN );
351 DALI_TEST_CHECK( HasAncestor( button, popup ) );
355 int UtcDaliPopupSetFooterN(void)
357 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
358 tet_infoline(" UtcDaliPopupSetFooterN");
360 // Create the Popup actor
361 Popup popup = Popup::New();
363 PushButton button = PushButton::New();
364 popup.SetFooter( button );
366 DALI_TEST_CHECK( popup.GetFooter() );
368 // Set a bad title value.
370 popup.SetFooter( badActor );
372 DALI_TEST_CHECK( !popup.GetFooter() );
377 int UtcDaliPopupSetControlFooterMultiple(void)
379 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
380 tet_infoline(" UtcDaliPopupSetControlFooterMultiple");
382 // Create the Popup actor
383 Popup popup = Popup::New();
384 Stage::GetCurrent().Add( popup );
385 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, 0.0f );
386 // Put in show state so it's layer is connected to popup (for ancestor check).
387 popup.SetDisplayState( Popup::SHOWN );
389 Actor container = Actor::New();
390 PushButton button1 = PushButton::New();
391 PushButton button2 = PushButton::New();
392 DALI_TEST_CHECK( !HasAncestor( button1, popup ) );
393 DALI_TEST_CHECK( !HasAncestor( button2, popup ) );
394 container.Add( button1 );
395 container.Add( button2 );
396 popup.SetFooter( container );
398 // Hide and then re-show popup to cause button to be rearranged and added to popup.
399 popup.SetDisplayState( Popup::HIDDEN );
400 popup.SetDisplayState( Popup::SHOWN );
401 DALI_TEST_CHECK( HasAncestor( button1, popup ) );
402 DALI_TEST_CHECK( HasAncestor( button2, popup ) );
406 int UtcDaliPopupSetStateP(void)
408 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
409 tet_infoline(" UtcDaliPopupSetStateP");
411 // Create the Popup actor
412 Popup popup = Popup::New();
414 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, 0.0f );
416 DALI_TEST_EQUALS( popup.GetDisplayState(), Popup::HIDDEN, TEST_LOCATION );
418 popup.SetDisplayState( Popup::SHOWN );
419 DALI_TEST_EQUALS( Popup::SHOWN, popup.GetDisplayState(), TEST_LOCATION );
421 popup.SetDisplayState( Popup::HIDDEN );
422 DALI_TEST_EQUALS( Popup::HIDDEN, popup.GetDisplayState(), TEST_LOCATION );
426 int UtcDaliPopupSetStateN(void)
428 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
429 tet_infoline(" UtcDaliPopupSetStateN");
431 // Create the Popup actor
432 Popup popup = Popup::New();
434 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, 1.0f );
436 DALI_TEST_EQUALS( popup.GetDisplayState(), Popup::HIDDEN, TEST_LOCATION );
438 popup.SetDisplayState( Popup::SHOWN );
439 DALI_TEST_EQUALS( Popup::SHOWING, popup.GetDisplayState(), TEST_LOCATION );
441 // Test cancelling a show before it has finished.
442 popup.SetDisplayState( Popup::HIDDEN );
443 DALI_TEST_EQUALS( Popup::HIDING, popup.GetDisplayState(), TEST_LOCATION );
447 int UtcDaliPopupDisplayStateSignal(void)
449 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
450 tet_infoline( " UtcDaliPopupDisplayStateSignal" );
452 // Create the Popup actor
453 Popup popup = Popup::New();
454 ConnectStateSignals( popup );
456 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, 1.0f );
457 popup.SetDisplayState( Popup::SHOWN );
458 DALI_TEST_EQUALS( Popup::SHOWING, popup.GetDisplayState(), TEST_LOCATION );
459 DALI_TEST_EQUALS( gPopupState, Popup::SHOWING, TEST_LOCATION );
461 // Wait for a while (allow animation to complete), and then check state.
462 for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
464 application.SendNotification();
465 application.Render( RENDER_FRAME_INTERVAL );
468 DALI_TEST_EQUALS( Popup::SHOWN, popup.GetDisplayState(), TEST_LOCATION );
469 DALI_TEST_EQUALS( gPopupState, Popup::SHOWN, TEST_LOCATION );
472 popup.SetDisplayState( Popup::HIDDEN );
473 DALI_TEST_EQUALS( Popup::HIDING, popup.GetDisplayState(), TEST_LOCATION );
474 DALI_TEST_EQUALS( gPopupState, Popup::HIDING, TEST_LOCATION );
476 // Wait for a while (allow animation to complete), and then check state.
477 for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
479 application.SendNotification();
480 application.Render( RENDER_FRAME_INTERVAL );
483 DALI_TEST_EQUALS( Popup::HIDDEN, popup.GetDisplayState(), TEST_LOCATION );
484 DALI_TEST_EQUALS( gPopupState, Popup::HIDDEN, TEST_LOCATION );
489 int UtcDaliPopupShowHide(void)
491 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
492 tet_infoline(" UtcDaliPopupShowHide");
494 // Create the Popup actor
495 Popup popup = Popup::New();
496 ConnectStateSignals( popup );
498 Actor container = Actor::New();
499 PushButton button1 = PushButton::New();
500 PushButton button2 = PushButton::New();
501 button1.SetSize( DEFAULT_BUTTON_SIZE.GetVectorXY() );
502 button2.SetSize( DEFAULT_BUTTON_SIZE.GetVectorXY() );
503 container.Add( button1 );
504 container.Add( button2 );
505 popup.SetFooter( container );
508 // Note: in most popup animation implementations show would result in
509 // popup being onstage immediately following Show(). However we can't
510 // assume for all. e.g. If one creates a animation with a delay.
511 popup.SetDisplayState( Popup::SHOWN );
513 // Wait for a while (allow animation to complete), and then check state.
514 for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
516 application.SendNotification();
517 application.Render( RENDER_FRAME_INTERVAL );
521 popup.SetDisplayState( Popup::HIDDEN );
523 // Wait for a while (allow animation to complete), and then check state.
524 for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
526 application.SendNotification();
527 application.Render(RENDER_FRAME_INTERVAL);
530 DALI_TEST_EQUALS( gPopupState, Popup::HIDDEN, TEST_LOCATION );
534 int UtcDaliPopupPropertyTailVisibility(void)
536 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
537 tet_infoline(" UtcDaliPopupShowHideTail");
539 // Create the Popup actor
540 Popup popup = Popup::New();
541 Stage::GetCurrent().Add( popup );
543 popup.SetProperty( Popup::Property::TAIL_VISIBILITY, false );
544 popup.SetDisplayState( Popup::SHOWN );
546 int withoutTailCount = DescendentCount( popup );
548 popup.SetDisplayState( Popup::HIDDEN );
550 popup.SetProperty( Popup::Property::TAIL_POSITION, "BOTTOM_CENTER" );
551 popup.SetProperty( Popup::Property::TAIL_VISIBILITY, true );
552 popup.SetDisplayState( Popup::SHOWN );
554 int withTailCount = DescendentCount( popup );
556 // There should be more actors if the Tail has been added.
557 DALI_TEST_CHECK( withTailCount > withoutTailCount );
560 popup.SetDisplayState( Popup::HIDDEN );
561 popup.SetProperty( Popup::Property::TAIL_VISIBILITY, false );
562 popup.SetDisplayState( Popup::SHOWN );
563 int withoutTailCount2 = DescendentCount(popup);
565 DALI_TEST_CHECK( withTailCount > withoutTailCount2 );
569 int UtcDaliPopupOnTouchedOutsideSignal(void)
571 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
572 tet_infoline(" UtcDaliPopupOnTouchedOutside");
574 // Create the Popup actor
575 Popup popup = Popup::New();
576 popup.SetParentOrigin( ParentOrigin::CENTER );
577 popup.SetAnchorPoint( ParentOrigin::CENTER );
578 popup.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
579 popup.SetSize( 50.0f, 50.0f );
580 popup.SetProperty( Popup::Property::ANIMATION_DURATION, 0.0f );
581 Stage::GetCurrent().Add( popup );
582 popup.OutsideTouchedSignal().Connect( &OnPopupTouchedOutside );
583 popup.SetDisplayState( Popup::SHOWN );
585 application.SendNotification();
586 application.Render();
588 gTouchedOutside = false;
589 Dali::Integration::TouchEvent event;
591 event = Dali::Integration::TouchEvent();
592 event.AddPoint( pointDownOutside );
593 application.ProcessEvent( event );
595 application.SendNotification();
596 application.Render();
598 event = Dali::Integration::TouchEvent();
599 event.AddPoint( pointUpOutside );
600 application.ProcessEvent( event );
602 application.SendNotification();
603 application.Render();
605 DALI_TEST_CHECK( gTouchedOutside );
609 int UtcDaliPopupPropertyAutoHide(void)
611 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
612 tet_infoline( " UtcDaliPopupPropertyAutoHide" );
614 // Create the Popup actor
615 Popup popup = Popup::New();
616 ConnectStateSignals( popup );
618 Actor container = Actor::New();
619 PushButton button1 = PushButton::New();
620 button1.SetSize( DEFAULT_BUTTON_SIZE.GetVectorXY() );
621 container.Add( button1 );
622 popup.SetFooter( container );
624 popup.SetProperty( Popup::Property::ANIMATION_DURATION, 0.0f );
625 popup.SetProperty( Popup::Property::AUTO_HIDE_DELAY, 200 );
627 Stage::GetCurrent().Add( popup );
629 DALI_TEST_EQUALS( gPopupState, Popup::HIDDEN, TEST_LOCATION );
632 // Note: in most popup animation implementations show would result in
633 // popup being onstage immediately following Show(). However we can't
634 // assume for all. e.g. If one creates a animation with a delay.
635 popup.SetDisplayState( Popup::SHOWN );
637 DALI_TEST_EQUALS( gPopupState, Popup::SHOWN, TEST_LOCATION );
639 for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++ )
641 application.SendNotification();
642 application.Render( RENDER_FRAME_INTERVAL );
645 // Force the timer used by the popup to expire,
646 // this will cause the popup to hide automatically.
647 Dali::Timer timer = Timer::New( 0 );
648 timer.MockEmitSignal();
650 DALI_TEST_EQUALS( gPopupState, Popup::HIDDEN, TEST_LOCATION );
656 * This test checks all animation modes to confirm they all trigger all display states at the expected times.
658 int UtcDaliPopupPropertyAnimationMode(void)
660 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
661 tet_infoline( " UtcDaliPopupPropertyAnimationMode" );
663 // Create the Popup actor
664 Popup popup = Popup::New();
665 ConnectStateSignals( popup );
666 popup.SetTitle( TextLabel::New( "Title" ) );
667 Stage::GetCurrent().Add( popup );
669 std::string animationModes[] = { "NONE", "ZOOM", "FADE", "CUSTOM" };
671 // Try both default and zero animation duration, as zero has a special case for some animation types.
672 for( int j = 0; j <= 1; j++ )
674 // On the second loop, set duration to zero.
677 popup.SetProperty( Popup::Property::ANIMATION_DURATION, 0.0f );
680 // Loop through 4 animation modes.
681 for( int i = 0; i < 4; i++ )
683 popup.SetProperty( Popup::Property::ANIMATION_MODE, animationModes[i] );
685 std::string checkMode;
686 DALI_TEST_CHECK( popup.GetProperty( Popup::Property::ANIMATION_MODE ).Get( checkMode ) )
688 DALI_TEST_EQUALS( checkMode, animationModes[i], TEST_LOCATION );
690 popup.SetDisplayState( Popup::SHOWN );
692 // Only wait for animation if it isn't instant.
695 DALI_TEST_EQUALS( gPopupState, Popup::SHOWING, TEST_LOCATION );
696 WaitAnimation( application );
699 DALI_TEST_EQUALS( gPopupState, Popup::SHOWN, TEST_LOCATION );
700 popup.SetDisplayState( Popup::HIDDEN );
704 DALI_TEST_EQUALS( gPopupState, Popup::HIDING, TEST_LOCATION );
705 WaitAnimation( application );
708 DALI_TEST_EQUALS( gPopupState, Popup::HIDDEN, TEST_LOCATION );