Dali 3D User Interface Engine
utc-Dali-Popup.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.
24 
25 #include <dali.h>
31 
32 using namespace Dali;
33 using namespace Toolkit;
34 
36 {
38 }
39 
41 {
43 }
44 
45 namespace
46 {
48 
49 static void TestCallback(BaseHandle handle)
50 {
51  gObjectCreatedCallBackCalled = true;
52 }
53 
54 const int RENDER_FRAME_INTERVAL = 10;
56 const int RENDER_ANIMATION_TEST_DURATION_FRAMES = RENDER_ANIMATION_TEST_DURATION_MS / RENDER_FRAME_INTERVAL;
57 const Vector3 DEFAULT_BUTTON_SIZE(100.0f, 50.0f, 0.0f);
58 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10.0f, 10.0f );
59 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10.0f, 10.0f );
60 
68 int DescendentCount( const Actor& root )
69 {
70  unsigned int numChildren = root.GetChildCount();
71 
72  int count = 1;
73 
74  for( unsigned int i = 0; i < numChildren; ++i )
75  {
76  count += DescendentCount( root.GetChildAt( i ) );
77  }
78 
79  return count;
80 }
81 
82 bool HasAncestor( Actor child, Actor ancestor )
83 {
84  while( child && child != ancestor )
85  {
86  child = child.GetParent();
87  }
88 
89  return ( child == ancestor );
90 }
91 
93 static bool gTouchedOutside;
94 
95 // Signal callbacks
96 
97 static void OnPopupTouchedOutside()
98 {
99  gTouchedOutside = true;
100 }
101 
102 static void OnPopupShowing()
103 {
104  gPopupState = Toolkit::Popup::SHOWING;
105 }
106 
107 static void OnPopupShown()
108 {
109  gPopupState = Toolkit::Popup::SHOWN;
110 }
111 
112 static void OnPopupHiding()
113 {
114  gPopupState = Toolkit::Popup::HIDING;
115 }
116 
117 static void OnPopupHidden()
118 {
119  gPopupState = Toolkit::Popup::HIDDEN;
120 }
121 
123 {
125  popup.ShownSignal().Connect( &OnPopupShown );
126  popup.HidingSignal().Connect( &OnPopupHiding );
127  popup.HiddenSignal().Connect( &OnPopupHidden );
128 }
129 
131 {
132  // Wait for a while (allow animation to complete), and then check state.
133  for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++ )
134  {
135  application.SendNotification();
136  application.Render( RENDER_FRAME_INTERVAL );
137  }
138 }
139 
144 {
145 };
146 
151 {
153  {
154  }
155 
156  void operator()()
157  {
158  }
159 };
160 
161 // Generate a KeyEvent to send to Core.
162 Integration::KeyEvent GenerateKey( const std::string& keyName,
163  const std::string& keyString,
164  int keyCode,
165  int keyModifier,
166  unsigned long timeStamp,
167  const Integration::KeyEvent::State& keyState )
168 {
169  return Integration::KeyEvent( keyName,
170  keyString,
171  keyCode,
172  keyModifier,
173  timeStamp,
174  keyState );
175 }
176 
177 } // Anonymous namespace
178 
179 /*
180  * This test checks popup creation.
181  */
182 int UtcDaliPopupNewP( void )
183 {
184  ToolkitTestApplication application;
185  tet_infoline( " UtcDaliPopupNewP" );
186 
187  // Create the Popup actor.
188  Popup popup;
189 
190  DALI_TEST_CHECK( !popup );
191 
192  popup = Popup::New();
193 
194  DALI_TEST_CHECK( popup );
195 
196  Popup popup2( popup );
197 
198  DALI_TEST_CHECK( popup2 == popup );
199 
200  // Additional check to ensure object is created by checking if it's registered.
202  DALI_TEST_CHECK( registry );
203 
205  registry.ObjectCreatedSignal().Connect( &TestCallback );
206  {
207  Popup popup = Popup::New();
208  }
210  END_TEST;
211 }
212 
213 /*
214  * This test checks popup destruction.
215  */
217 {
218  ToolkitTestApplication application;
219  tet_infoline( " UtcDaliPopupDestructorP" );
220 
221  Popup* popup = new Popup();
222  delete popup;
223 
224  DALI_TEST_CHECK( true );
225  END_TEST;
226 }
227 
229 {
230  ToolkitTestApplication application;
231  tet_infoline( " UtcDaliPopupDownCastP" );
232 
233  Handle handle = Popup::New();
234 
235  Popup popup = Popup::DownCast( handle );
236 
237  DALI_TEST_CHECK( popup == handle );
238  END_TEST;
239 }
240 
242 {
243  ToolkitTestApplication application;
244  tet_infoline( " UtcDaliPopupSetProperty" );
245 
246  Popup popup = Popup::New();
247 
248  //Test properties
249  std::string testString = "Hello World";
250 
251  TextLabel textActorIn = TextLabel::New( testString );
252  Property::Map map;
253  Scripting::CreatePropertyMap( textActorIn, map );
254  popup.SetProperty( popup.GetPropertyIndex( "title" ), map );
255  TextLabel textActorOut = TextLabel::DownCast( popup.GetTitle() );
256  std::string resultText;
257  DALI_TEST_CHECK( textActorOut.GetProperty( Toolkit::TextLabel::Property::TEXT ).Get( resultText ) );
258  DALI_TEST_EQUALS( testString, resultText, TEST_LOCATION );
259 
260  END_TEST;
261 }
262 
264 {
265  ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
266  tet_infoline( " UtcDaliPopupSetTitleP" );
267 
268  // Create the Popup actor
269  Popup popup = Popup::New();
270 
271  // Put in show state so it's layer is connected to popup (for ancestor check).
272  popup.SetDisplayState( Popup::SHOWN );
273 
274  TextLabel titleActor = TextLabel::New();
275  titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, "title" );
276 
277  DALI_TEST_CHECK( !popup.GetTitle() );
278  popup.SetTitle( titleActor );
279  TextLabel textActor = TextLabel::DownCast( popup.GetTitle() );
280  DALI_TEST_CHECK( textActor == titleActor );
281 
282  std::string resultText;
283  DALI_TEST_CHECK( textActor.GetProperty( Toolkit::TextLabel::Property::TEXT ).Get( resultText ) );
284 
285  DALI_TEST_CHECK( ( popup.GetTitle() ) && ( resultText == "title" ) );
286  // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
287  DALI_TEST_CHECK( HasAncestor( titleActor, popup ) );
288 
289  TextLabel titleActor2 = TextLabel::New();
290  titleActor2.SetProperty( Toolkit::TextLabel::Property::TEXT, "anothertitle" );
291  popup.SetTitle( titleActor2 );
292  DALI_TEST_CHECK( popup.GetTitle() != titleActor );
293  DALI_TEST_CHECK( popup.GetTitle() == titleActor2 );
295 
296  DALI_TEST_CHECK( ( popup.GetTitle() ) && ( resultText == "anothertitle" ) );
297 
298  // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
299  DALI_TEST_CHECK( HasAncestor( titleActor2, popup ) );
300  END_TEST;
301 }
302 
304 {
305  ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
306  tet_infoline( " UtcDaliPopupSetTitleN" );
307 
308  // Create the Popup actor
309  Popup popup = Popup::New();
310 
311  TextLabel titleActor = TextLabel::New( "text" );
312  popup.SetTitle( titleActor );
313 
314  DALI_TEST_CHECK( popup.GetTitle() );
315 
316  // Set a bad title value.
317  // Confirm this has disabled the title.
318  Actor badActor;
319  popup.SetTitle( badActor );
320 
321  DALI_TEST_CHECK( !popup.GetTitle() );
322 
323  END_TEST;
324 }
325 
327 {
328  ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
329  tet_infoline( " UtcDaliPopupSetContentP" );
330 
331  // Create the Popup actor
332  Popup popup = Popup::New();
333  Stage::GetCurrent().Add( popup );
335 
336  // Put in show state so it's layer is connected to popup (for ancestor check).
337  popup.SetDisplayState( Popup::SHOWN );
338 
339  PushButton button = PushButton::New();
340  DALI_TEST_CHECK( !HasAncestor( button, popup ) );
341  popup.SetFooter( button );
342  // Hide and then re-show popup to cause button to be rearranged and added to popup.
344  popup.SetDisplayState( Popup::SHOWN );
345  DALI_TEST_CHECK( HasAncestor( button, popup ) );
346  END_TEST;
347 }
348 
350 {
351  ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
352  tet_infoline( " UtcDaliPopupSetContentN" );
353 
354  // Create the Popup actor
355  Popup popup = Popup::New();
356 
357  TextLabel content = TextLabel::New( "text" );
358  popup.SetContent( content );
359 
360  DALI_TEST_CHECK( popup.GetContent() );
361 
362  // Set a bad title value.
363  Actor badActor;
364  popup.SetContent( badActor );
365 
366  DALI_TEST_CHECK( !popup.GetContent() );
367 
368  END_TEST;
369 }
370 
372 {
373  ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
374  tet_infoline(" UtcDaliPopupSetFooterP");
375 
376  // Create the Popup actor
377  Popup popup = Popup::New();
378  Stage::GetCurrent().Add( popup );
380  // Put in show state so it's layer is connected to popup (for ancestor check).
381  popup.SetDisplayState( Popup::SHOWN );
382 
383  PushButton button = PushButton::New();
384  DALI_TEST_CHECK( !HasAncestor(button, popup) );
385  popup.SetFooter( button );
386  // Hide and then re-show popup to cause button to be rearranged and added to popup.
388  popup.SetDisplayState( Popup::SHOWN );
389  DALI_TEST_CHECK( HasAncestor( button, popup ) );
390  END_TEST;
391 }
392 
394 {
395  ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
396  tet_infoline(" UtcDaliPopupSetFooterN");
397 
398  // Create the Popup actor
399  Popup popup = Popup::New();
400 
401  PushButton button = PushButton::New();
402  popup.SetFooter( button );
403 
404  DALI_TEST_CHECK( popup.GetFooter() );
405 
406  // Set a bad title value.
407  Actor badActor;
408  popup.SetFooter( badActor );
409 
410  DALI_TEST_CHECK( !popup.GetFooter() );
411 
412  END_TEST;
413 }
414 
416 {
417  ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
418  tet_infoline(" UtcDaliPopupSetControlFooterMultiple");
419 
420  // Create the Popup actor
421  Popup popup = Popup::New();
422  Stage::GetCurrent().Add( popup );
424  // Put in show state so it's layer is connected to popup (for ancestor check).
425  popup.SetDisplayState( Popup::SHOWN );
426 
427  Actor container = Actor::New();
428  PushButton button1 = PushButton::New();
429  PushButton button2 = PushButton::New();
430  DALI_TEST_CHECK( !HasAncestor( button1, popup ) );
431  DALI_TEST_CHECK( !HasAncestor( button2, popup ) );
432  container.Add( button1 );
433  container.Add( button2 );
434  popup.SetFooter( container );
435 
436  // Hide and then re-show popup to cause button to be rearranged and added to popup.
438  popup.SetDisplayState( Popup::SHOWN );
439  DALI_TEST_CHECK( HasAncestor( button1, popup ) );
440  DALI_TEST_CHECK( HasAncestor( button2, popup ) );
441  END_TEST;
442 }
443 
445 {
446  ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
447  tet_infoline(" UtcDaliPopupSetStateP");
448 
449  // Create the Popup actor
450  Popup popup = Popup::New();
451 
453 
455 
456  popup.SetDisplayState( Popup::SHOWN );
458 
461  END_TEST;
462 }
463 
465 {
466  ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
467  tet_infoline(" UtcDaliPopupSetStateN");
468 
469  // Create the Popup actor
470  Popup popup = Popup::New();
471 
473 
475 
476  popup.SetDisplayState( Popup::SHOWN );
478 
479  // Test cancelling a show before it has finished.
482  END_TEST;
483 }
484 
486 {
487  ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
488  tet_infoline( " UtcDaliPopupDisplayStateSignal" );
489 
490  // Create the Popup actor
491  Popup popup = Popup::New();
492  ConnectStateSignals( popup );
493 
495  popup.SetDisplayState( Popup::SHOWN );
498 
499  // Wait for a while (allow animation to complete), and then check state.
500  for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
501  {
502  application.SendNotification();
503  application.Render( RENDER_FRAME_INTERVAL );
504  }
505 
508 
509  // Hide slowly
513 
514  // Wait for a while (allow animation to complete), and then check state.
515  for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
516  {
517  application.SendNotification();
518  application.Render( RENDER_FRAME_INTERVAL );
519  }
520 
523 
524  END_TEST;
525 }
526 
528 {
529  ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
530  tet_infoline(" UtcDaliPopupShowHide");
531 
532  // Create the Popup actor
533  Popup popup = Popup::New();
534  ConnectStateSignals( popup );
535 
536  Actor container = Actor::New();
537  PushButton button1 = PushButton::New();
538  PushButton button2 = PushButton::New();
541  container.Add( button1 );
542  container.Add( button2 );
543  popup.SetFooter( container );
544 
545  // Show
546  // Note: in most popup animation implementations show would result in
547  // popup being onstage immediately following Show(). However we can't
548  // assume for all. e.g. If one creates a animation with a delay.
549  popup.SetDisplayState( Popup::SHOWN );
550 
551  // Wait for a while (allow animation to complete), and then check state.
552  for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
553  {
554  application.SendNotification();
555  application.Render( RENDER_FRAME_INTERVAL );
556  }
557 
558  // Hide
560 
561  // Wait for a while (allow animation to complete), and then check state.
562  for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
563  {
564  application.SendNotification();
565  application.Render(RENDER_FRAME_INTERVAL);
566  }
567 
569  END_TEST;
570 }
571 
573 {
574  ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
575  tet_infoline(" UtcDaliPopupShowHideTail");
576 
577  // Create the Popup actor
578  Popup popup = Popup::New();
579  Stage::GetCurrent().Add( popup );
580 
582  popup.SetDisplayState( Popup::SHOWN );
583 
584  int withoutTailCount = DescendentCount( popup );
585 
587 
588  popup.SetProperty( Popup::Property::TAIL_POSITION, "BOTTOM_CENTER" );
590  popup.SetDisplayState( Popup::SHOWN );
591 
592  int withTailCount = DescendentCount( popup );
593 
594  // There should be more actors if the Tail has been added.
595  DALI_TEST_CHECK( withTailCount > withoutTailCount );
596 
597  // Hide again
600  popup.SetDisplayState( Popup::SHOWN );
601  int withoutTailCount2 = DescendentCount(popup);
602 
603  DALI_TEST_CHECK( withTailCount > withoutTailCount2 );
604  END_TEST;
605 }
606 
608 {
609  ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
610  tet_infoline(" UtcDaliPopupOnTouchedOutside");
611 
612  // Create the Popup actor
613  Popup popup = Popup::New();
617  popup.SetSize( 50.0f, 50.0f );
619  Stage::GetCurrent().Add( popup );
621  popup.SetDisplayState( Popup::SHOWN );
622 
623  application.SendNotification();
624  application.Render();
625 
626  gTouchedOutside = false;
627  Dali::Integration::TouchEvent event;
628 
629  event = Dali::Integration::TouchEvent();
630  event.AddPoint( pointDownOutside );
631  application.ProcessEvent( event );
632 
633  application.SendNotification();
634  application.Render();
635 
636  event = Dali::Integration::TouchEvent();
637  event.AddPoint( pointUpOutside );
638  application.ProcessEvent( event );
639 
640  application.SendNotification();
641  application.Render();
642 
643  // Confirm the signal is ignored if touch_transparent.
644  gTouchedOutside = false;
646 
647  event = Dali::Integration::TouchEvent();
648  event.AddPoint( pointDownOutside );
649  application.ProcessEvent( event );
650 
651  application.SendNotification();
652  application.Render();
653 
654  event = Dali::Integration::TouchEvent();
655  event.AddPoint( pointUpOutside );
656  application.ProcessEvent( event );
657 
658  application.SendNotification();
659  application.Render();
660 
662 
663  END_TEST;
664 }
665 
667 {
668  ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
669  tet_infoline( " UtcDaliPopupPropertyAutoHide" );
670 
671  // Create the Popup actor
672  Popup popup = Popup::New();
673  ConnectStateSignals( popup );
674 
675  Actor container = Actor::New();
676  PushButton button1 = PushButton::New();
678  container.Add( button1 );
679  popup.SetFooter( container );
680 
682  float getAnimationDuration = 0.0f;
683  DALI_TEST_CHECK( popup.GetProperty( Popup::Property::ANIMATION_DURATION ).Get( getAnimationDuration ) );
684  DALI_TEST_EQUALS( getAnimationDuration, 0.0f, Math::MACHINE_EPSILON_0, TEST_LOCATION );
685 
687  int getAutoHideDelay = 0;
688  DALI_TEST_CHECK( popup.GetProperty( Popup::Property::AUTO_HIDE_DELAY ).Get( getAutoHideDelay ) );
689  DALI_TEST_EQUALS( getAutoHideDelay, 200, TEST_LOCATION );
690 
691  Stage::GetCurrent().Add( popup );
692 
694 
695  // Show
696  // Note: in most popup animation implementations show would result in
697  // popup being onstage immediately following Show(). However we can't
698  // assume for all. e.g. If one creates a animation with a delay.
699  popup.SetDisplayState( Popup::SHOWN );
700 
702 
703  for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++ )
704  {
705  application.SendNotification();
706  application.Render( RENDER_FRAME_INTERVAL );
707  }
708 
709  // Force the timer used by the popup to expire,
710  // this will cause the popup to hide automatically.
711  Dali::Timer timer = Timer::New( 0 );
712  timer.MockEmitSignal();
713 
715 
716  END_TEST;
717 }
718 
719 /*
720  * This test checks all animation modes to confirm they all trigger all display states at the expected times.
721  */
723 {
724  ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
725  tet_infoline( " UtcDaliPopupPropertyAnimationMode" );
726 
727  // Create the Popup actor
728  Popup popup = Popup::New();
729  ConnectStateSignals( popup );
730  popup.SetTitle( TextLabel::New( "Title" ) );
731  Stage::GetCurrent().Add( popup );
732 
733  std::string animationModes[] = { "NONE", "ZOOM", "FADE", "CUSTOM" };
734 
735  // Try both default and zero animation duration, as zero has a special case for some animation types.
736  for( int j = 0; j <= 1; j++ )
737  {
738  // On the second loop, set duration to zero.
739  if( j == 1 )
740  {
742  }
743 
744  // Loop through 4 animation modes.
745  for( int i = 0; i < 4; i++ )
746  {
747  popup.SetProperty( Popup::Property::ANIMATION_MODE, animationModes[i] );
748 
749  std::string checkMode;
750  DALI_TEST_CHECK( popup.GetProperty( Popup::Property::ANIMATION_MODE ).Get( checkMode ) )
751 
752  DALI_TEST_EQUALS( checkMode, animationModes[i], TEST_LOCATION );
753 
755  std::string resultState;
756 
757  // Only wait for animation if it isn't instant.
758  if( j == 0 )
759  {
762  DALI_TEST_EQUALS( resultState, "SHOWING", TEST_LOCATION );
763  WaitAnimation( application );
764  }
765 
768  DALI_TEST_EQUALS( resultState, "SHOWN", TEST_LOCATION );
770 
771  if( j == 0 )
772  {
775  DALI_TEST_EQUALS( resultState, "HIDING", TEST_LOCATION );
776  WaitAnimation( application );
777  }
778 
781  DALI_TEST_EQUALS( resultState, "HIDDEN", TEST_LOCATION );
782  }
783  }
784 
785  END_TEST;
786 }
787 
789 {
790  ToolkitTestApplication application;
791  tet_infoline( " UtcDaliPopupPropertyTitle" );
792 
793  // Create the Popup actor
794  Popup popup = Popup::New();
795 
796  std::string testLabelText = "TitleTest";
797  TextLabel titleLabel = TextLabel::New();
798  titleLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, testLabelText );
799  Actor title = titleLabel;
800  Property::Map map;
801  Scripting::CreatePropertyMap( title, map );
803 
804  Property::Map resultMap;
805  DALI_TEST_CHECK( popup.GetProperty( Toolkit::Popup::Property::TITLE ).Get( resultMap ) );
806 
807  Property::Value* resultProperty = resultMap.Find( "text" );
808  DALI_TEST_CHECK( resultProperty );
809 
810  std::string resultText;
811  DALI_TEST_CHECK( resultProperty->Get( resultText ) );
812 
813  DALI_TEST_EQUALS( resultText, testLabelText, TEST_LOCATION );
814 
815  END_TEST;
816 }
817 
819 {
820  ToolkitTestApplication application;
821  tet_infoline( " UtcDaliPopupPropertyContent" );
822 
823  // Create the Popup actor
824  Popup popup = Popup::New();
825 
826  std::string testLabelText = "ContentTest";
827  TextLabel contentLabel = TextLabel::New();
828  contentLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, testLabelText );
829  Actor content = contentLabel;
830  Property::Map map;
831  Scripting::CreatePropertyMap( content, map );
833 
834  Property::Map resultMap;
836 
837  Property::Value* resultProperty = resultMap.Find( "text" );
838  DALI_TEST_CHECK( resultProperty );
839 
840  std::string resultText;
841  DALI_TEST_CHECK( resultProperty->Get( resultText ) );
842 
843  DALI_TEST_EQUALS( resultText, testLabelText, TEST_LOCATION );
844 
845  END_TEST;
846 }
847 
849 {
850  ToolkitTestApplication application;
851  tet_infoline( " UtcDaliPopupPropertyFooter" );
852 
853  // Create the Popup actor
854  Popup popup = Popup::New();
855 
856  std::string testLabelText = "FooterTest";
857  TextLabel footerLabel = TextLabel::New();
858  footerLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, testLabelText );
859  Actor footer = footerLabel;
860  Property::Map map;
861  Scripting::CreatePropertyMap( footer, map );
863 
864  Property::Map resultMap;
865  DALI_TEST_CHECK( popup.GetProperty( Toolkit::Popup::Property::FOOTER ).Get( resultMap ) );
866 
867  Property::Value* resultProperty = resultMap.Find( "text" );
868  DALI_TEST_CHECK( resultProperty );
869 
870  std::string resultText;
871  DALI_TEST_CHECK( resultProperty->Get( resultText ) );
872 
873  DALI_TEST_EQUALS( resultText, testLabelText, TEST_LOCATION );
874 
875  END_TEST;
876 }
877 
879 {
880  ToolkitTestApplication application;
881  tet_infoline( " UtcDaliPopupPropertyContextualMode" );
882 
883  // Create the Popup actor
884  Popup popup = Popup::New();
886  std::string testLabelText = "ContentTest";
887 
888  TextLabel contentLabel = TextLabel::New();
889 
890  popup.SetContent( contentLabel );
891 
892  // Placement actor to parent the popup from so the popup's contextual position can be relative to it.
893  Actor placement = Actor::New();
895  placement.SetAnchorPoint( AnchorPoint::CENTER );
896  placement.SetSize( 1.0f, 1.0f );
898  Stage::GetCurrent().Add( placement );
899 
900  placement.Add( popup );
901 
902  // Test all contextual modes.
903  const char* mode[5] = { "NON_CONTEXTUAL", "ABOVE", "RIGHT", "BELOW", "LEFT" };
904  Vector2 offsetValues[5];
905  offsetValues[0] = Vector2( 0.0f, 0.0f );
906  offsetValues[1] = Vector2( 0.0f, -10.0f );
907  offsetValues[2] = Vector2( 10.0f, 0.0f );
908  offsetValues[3] = Vector2( 0.0f, 10.0f );
909  offsetValues[4] = Vector2( -10.0f, 0.0f );
910 
911  for( int i = 0; i < 5; ++i )
912  {
914 
915  std::string propertyResult;
917  DALI_TEST_EQUALS( propertyResult, std::string( mode[i] ), TEST_LOCATION );
918 
919  popup.SetDisplayState( Popup::SHOWN );
920  application.SendNotification();
921  application.Render();
922 
923  // Check the position of the label within the popup.
924  DALI_TEST_EQUALS( contentLabel.GetCurrentWorldPosition().GetVectorXY(), offsetValues[i], TEST_LOCATION );
925 
927  application.SendNotification();
928  application.Render();
929  }
930 
931  END_TEST;
932 }
933 
935 {
936  ToolkitTestApplication application;
937  tet_infoline( " UtcDaliPopupPropertyBacking" );
938 
939  // Create the Popup actor
940  Popup popup = Popup::New();
942  Stage::GetCurrent().Add( popup );
943 
944  Actor backing = popup.FindChildByName( "popupBacking" );
945  DALI_TEST_CHECK( backing );
946 
948 
949  // Check enabled property.
950  popup.SetDisplayState( Popup::SHOWN );
951  application.SendNotification();
952  application.Render();
953 
955 
957  application.SendNotification();
958  application.Render();
959 
961 
963  bool propertyResult;
964  DALI_TEST_CHECK( popup.GetProperty( Popup::Property::BACKING_ENABLED ).Get( propertyResult ) );
965  DALI_TEST_EQUALS( propertyResult, false, TEST_LOCATION );
966 
967  popup.SetDisplayState( Popup::SHOWN );
968  application.SendNotification();
969  application.Render();
970 
972 
974  application.SendNotification();
975  application.Render();
976 
978 
979  // Check color property.
981  popup.SetProperty( Popup::Property::BACKING_COLOR, Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
982 
983  popup.SetDisplayState( Popup::SHOWN );
984  application.SendNotification();
985  application.Render();
986 
987  Vector4 resultColor;
988  popup.GetProperty( Popup::Property::BACKING_COLOR ).Get( resultColor );
989  DALI_TEST_EQUALS( resultColor, Vector4( 1.0f, 0.0f, 0.0f, 1.0f ), Math::MACHINE_EPSILON_0, TEST_LOCATION );
990 
991  END_TEST;
992 }
993 
995 {
996  ToolkitTestApplication application;
997  tet_infoline( " UtcDaliPopupPropertyBackgroundImage" );
998 
999  // Create the Popup actor
1000  Popup popup = Popup::New();
1001  Stage::GetCurrent().Add( popup );
1002 
1003  // Check setting an invalid image.
1004  popup.SetProperty( Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE, "invalid-image.png" );
1005  std::string resultString;
1007  DALI_TEST_EQUALS( resultString, std::string(""), TEST_LOCATION );
1008 
1009  END_TEST;
1010 }
1011 
1013 {
1014  ToolkitTestApplication application;
1015  tet_infoline( " UtcDaliPopupPropertyCustomAnimation" );
1016 
1017  // Create the Popup actor
1018  Popup popup = Popup::New();
1019  TextLabel content = TextLabel::New( "text" );
1020  popup.SetContent( content );
1021 
1023  popup.SetProperty( Popup::Property::ANIMATION_MODE, "CUSTOM" );
1024 
1025  Actor popupContainer = popup.FindChildByName( "popupContainer" );
1026  DALI_TEST_CHECK( popupContainer );
1027 
1028  Vector3 entryAnimationDestination( 300.0f, 200.0f, 0.0f );
1029  Vector3 exitAnimationDestination( -300.0f, -200.0f, 0.0f );
1030 
1031  Property::Map animationMapEntry;
1032  animationMapEntry.Insert( "actor", "customAnimationPopup" );
1033  animationMapEntry.Insert( "property", "position" );
1034  animationMapEntry.Insert( "value", entryAnimationDestination );
1035  animationMapEntry.Insert( "alphaFunction", "EASE_OUT" );
1036 
1037  Property::Array timePeriodMapEntry;
1038  timePeriodMapEntry.PushBack( 0.0f );
1039  timePeriodMapEntry.PushBack( 1.0f );
1040 
1041  animationMapEntry.Insert( "timePeriod", timePeriodMapEntry );
1042 
1043  Property::Map animationMapExit;
1044  animationMapExit.Insert( "actor", "customAnimationPopup" );
1045  animationMapExit.Insert( "property", "position" );
1046  animationMapExit.Insert( "value", exitAnimationDestination );
1047  animationMapExit.Insert( "alphaFunction", "EASE_IN" );
1048 
1049  Property::Array timePeriodMapExit;
1050  timePeriodMapExit.PushBack( 0.0f );
1051  timePeriodMapExit.PushBack( 1.0f );
1052 
1053  animationMapExit.Insert( "timePeriod", timePeriodMapExit );
1054 
1055  popup.SetProperty( Toolkit::Popup::Property::ENTRY_ANIMATION, animationMapEntry );
1056  popup.SetProperty( Toolkit::Popup::Property::EXIT_ANIMATION, animationMapExit );
1057 
1058  Property::Map resultMap;
1060  DALI_TEST_EQUALS( resultMap.Count(), 0u, TEST_LOCATION );
1062  DALI_TEST_EQUALS( resultMap.Count(), 0u, TEST_LOCATION );
1063 
1064  Stage::GetCurrent().Add( popup );
1065  popup.SetDisplayState( Popup::SHOWN );
1066 
1067  for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++ )
1068  {
1069  application.SendNotification();
1070  application.Render( RENDER_FRAME_INTERVAL );
1071  }
1072 
1073  // Test the popup has animated to it's entry-transition destination.
1074  DALI_TEST_EQUALS( popupContainer.GetCurrentWorldPosition(), entryAnimationDestination, 0.1f, TEST_LOCATION );
1075 
1076  popup.SetDisplayState( Popup::HIDDEN );
1077 
1078  for( int j = 0; j < RENDER_ANIMATION_TEST_DURATION_FRAMES; j++ )
1079  {
1080  application.SendNotification();
1081  application.Render( RENDER_FRAME_INTERVAL );
1082  }
1083 
1084  DALI_TEST_EQUALS( popupContainer.GetCurrentWorldPosition(), exitAnimationDestination, 0.1f, TEST_LOCATION );
1085 
1086  END_TEST;
1087 }
1088 
1090 static bool PushButtonClicked( Button button )
1091 {
1092  gPushButtonClicked = true;
1093  return true;
1094 }
1095 
1097 {
1098  ToolkitTestApplication application;
1099  tet_infoline( " UtcDaliPopupPropertyTouchTransparent" );
1100 
1101  // Create the Popup actor
1102  Popup popup = Popup::New();
1103  TextLabel content = TextLabel::New( "text" );
1104  popup.SetContent( content );
1108  popup.SetSize( 100, 100 );
1110 
1111  // Create a button (to go underneath the popup).
1115  button.SetSize( 100, 100 );
1117 
1118  button.ClickedSignal().Connect( &PushButtonClicked );
1119 
1120  Stage::GetCurrent().Add( button );
1121 
1122  button.Add( popup );
1123 
1124  popup.SetDisplayState( Popup::SHOWN );
1125  application.SendNotification();
1126  application.Render();
1127 
1128  gPushButtonClicked = false;
1129  Dali::Integration::TouchEvent event;
1130  const Dali::TouchPoint pointDown( 0, TouchPoint::Down, 10.0f, 10.0f );
1131  const Dali::TouchPoint pointUp( 0, TouchPoint::Up, 10.0f, 10.0f );
1132 
1133  // Perform a click, the popup should block the click from hitting the button.
1134  event = Dali::Integration::TouchEvent();
1135  event.AddPoint( pointDown );
1136  application.ProcessEvent( event );
1137  application.SendNotification();
1138  application.Render();
1139 
1140  event = Dali::Integration::TouchEvent();
1141  event.AddPoint( pointUp );
1142  application.ProcessEvent( event );
1143  application.SendNotification();
1144  application.Render();
1145 
1147 
1148  // Enable touch transparency.
1150  bool propertyResult;
1151  DALI_TEST_CHECK( popup.GetProperty( Popup::Property::TOUCH_TRANSPARENT ).Get( propertyResult ) );
1152  DALI_TEST_EQUALS( propertyResult, true, TEST_LOCATION );
1153 
1154  // Perform a click, the popup should allow the click to travel through to the button.
1155  event = Dali::Integration::TouchEvent();
1156  event.AddPoint( pointDown );
1157  application.ProcessEvent( event );
1158  application.SendNotification();
1159  application.Render();
1160 
1161  event = Dali::Integration::TouchEvent();
1162  event.AddPoint( pointUp );
1163  application.ProcessEvent( event );
1164  application.SendNotification();
1165  application.Render();
1166 
1168 
1169  END_TEST;
1170 }
1171 
1173 {
1174  ToolkitTestApplication application;
1175  tet_infoline( " UtcDaliPopupPropertyTail" );
1176 
1177  // Create the Popup actor
1178  Popup popup = Popup::New();
1181  popup.SetSize( 100, 100 );
1183  TextLabel content = TextLabel::New( "text" );
1184  popup.SetContent( content );
1185 
1186  std::string imageFilename = "invalid-image.jpg";
1187  popup.SetProperty( Popup::Property::TAIL_DOWN_IMAGE, imageFilename );
1188  popup.SetProperty( Popup::Property::TAIL_UP_IMAGE, imageFilename );
1189  popup.SetProperty( Popup::Property::TAIL_RIGHT_IMAGE, imageFilename );
1190  popup.SetProperty( Popup::Property::TAIL_LEFT_IMAGE, imageFilename );
1191 
1192  std::string resultString;
1193  popup.GetProperty( Toolkit::Popup::Property::TAIL_DOWN_IMAGE ).Get( resultString );
1194  DALI_TEST_EQUALS( resultString, imageFilename, TEST_LOCATION );
1195  popup.GetProperty( Toolkit::Popup::Property::TAIL_UP_IMAGE ).Get( resultString );
1196  DALI_TEST_EQUALS( resultString, imageFilename, TEST_LOCATION );
1197  popup.GetProperty( Toolkit::Popup::Property::TAIL_RIGHT_IMAGE ).Get( resultString );
1198  DALI_TEST_EQUALS( resultString, imageFilename, TEST_LOCATION );
1199  popup.GetProperty( Toolkit::Popup::Property::TAIL_LEFT_IMAGE ).Get( resultString );
1200  DALI_TEST_EQUALS( resultString, imageFilename, TEST_LOCATION );
1201 
1203  bool boolResult;
1204  DALI_TEST_CHECK( popup.GetProperty( Popup::Property::TAIL_VISIBILITY ).Get( boolResult ) );
1205  DALI_TEST_EQUALS( boolResult, true, TEST_LOCATION );
1206 
1207  Actor tailActor;
1208  Vector3 tailPosition( ParentOrigin::TOP_CENTER );
1209 
1210  popup.SetProperty( Popup::Property::TAIL_POSITION, tailPosition );
1211  Vector3 vectorResult;
1212  DALI_TEST_CHECK( popup.GetProperty( Popup::Property::TAIL_POSITION ).Get( vectorResult ) );
1213  DALI_TEST_EQUALS( vectorResult, tailPosition, TEST_LOCATION );
1214 
1215  Stage::GetCurrent().Add( popup );
1216 
1217  popup.SetDisplayState( Popup::SHOWN );
1218  application.SendNotification();
1219  application.Render();
1220  tailActor = popup.FindChildByName( "tailImage" );
1221  DALI_TEST_CHECK( tailActor );
1222 
1223  float baseValX = tailActor.GetCurrentWorldPosition().x;
1224 
1225  DALI_TEST_GREATER( baseValX, tailActor.GetCurrentWorldPosition().y, TEST_LOCATION );
1226 
1227  popup.SetDisplayState( Popup::HIDDEN );
1228  application.SendNotification();
1229  application.Render();
1230 
1231  tailPosition = ParentOrigin::CENTER_LEFT;
1232  popup.SetProperty( Popup::Property::TAIL_POSITION, tailPosition );
1233 
1234  popup.SetDisplayState( Popup::SHOWN );
1235  application.SendNotification();
1236  application.Render();
1237  tailActor = popup.FindChildByName( "tailImage" );
1238  DALI_TEST_CHECK( tailActor );
1239 
1240  float baseValY = tailActor.GetCurrentWorldPosition().y;
1241  DALI_TEST_GREATER( baseValX, tailActor.GetCurrentWorldPosition().x, TEST_LOCATION );
1242 
1243  popup.SetDisplayState( Popup::HIDDEN );
1244  application.SendNotification();
1245  application.Render();
1246 
1247  tailPosition = ParentOrigin::BOTTOM_CENTER;
1248  popup.SetProperty( Popup::Property::TAIL_POSITION, tailPosition );
1249 
1250  popup.SetDisplayState( Popup::SHOWN );
1251  application.SendNotification();
1252  application.Render();
1253  tailActor = popup.FindChildByName( "tailImage" );
1254  DALI_TEST_CHECK( tailActor );
1255  DALI_TEST_EQUALS( tailActor.GetCurrentWorldPosition().x, baseValX, TEST_LOCATION );
1256  DALI_TEST_GREATER( tailActor.GetCurrentWorldPosition().y, baseValY, TEST_LOCATION );
1257 
1258  popup.SetDisplayState( Popup::HIDDEN );
1259  application.SendNotification();
1260  application.Render();
1261 
1262  tailPosition = ParentOrigin::CENTER_RIGHT;
1263  popup.SetProperty( Popup::Property::TAIL_POSITION, tailPosition );
1264 
1265  popup.SetDisplayState( Popup::SHOWN );
1266  application.SendNotification();
1267  application.Render();
1268  tailActor = popup.FindChildByName( "tailImage" );
1269  DALI_TEST_CHECK( tailActor );
1270  DALI_TEST_GREATER( tailActor.GetCurrentWorldPosition().x, baseValX, TEST_LOCATION );
1271  DALI_TEST_EQUALS( tailActor.GetCurrentWorldPosition().y, baseValY, TEST_LOCATION );
1272 
1273  popup.SetDisplayState( Popup::HIDDEN );
1274  application.SendNotification();
1275  application.Render();
1276 
1277  END_TEST;
1278 }
1279 
1281 {
1282  ToolkitTestApplication application;
1283  tet_infoline( " UtcDaliPopupTypeToast" );
1284 
1285  TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "PopupToast" );
1286  DALI_TEST_CHECK( typeInfo )
1287 
1288  BaseHandle baseHandle = typeInfo.CreateInstance();
1289  DALI_TEST_CHECK( baseHandle )
1290 
1291  Toolkit::Popup popup = Toolkit::Popup::DownCast( baseHandle );
1293  ConnectStateSignals( popup );
1295 
1296  popup.SetTitle( Toolkit::TextLabel::New( "This is a Toast Popup.\nIt will auto-hide itself" ) );
1297  Stage::GetCurrent().Add( popup );
1299 
1300  for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++ )
1301  {
1302  application.SendNotification();
1303  application.Render( RENDER_FRAME_INTERVAL );
1304  }
1305 
1306  // Check the toast popup is shown.
1308 
1309  for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++ )
1310  {
1311  application.SendNotification();
1312  application.Render( RENDER_FRAME_INTERVAL );
1313  }
1314 
1315  // Check the toast popup hides.
1316  Dali::Timer timer = Timer::New( 0 );
1317  timer.MockEmitSignal();
1318 
1319  for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++ )
1320  {
1321  application.SendNotification();
1322  application.Render( RENDER_FRAME_INTERVAL );
1323  }
1324 
1326 
1327  END_TEST;
1328 }
1329 
1331 {
1332  ToolkitTestApplication application;
1333  tet_infoline( " UtcDaliPopupTypeRegistryCreation" );
1334 
1335  TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "Popup" );
1336  DALI_TEST_CHECK( typeInfo )
1337 
1338  BaseHandle baseHandle = typeInfo.CreateInstance();
1339  DALI_TEST_CHECK( baseHandle )
1340 
1341  Toolkit::Popup popup = Toolkit::Popup::DownCast( baseHandle );
1343  ConnectStateSignals( popup );
1345 
1346  Stage::GetCurrent().Add( popup );
1348 
1349  application.SendNotification();
1350  application.Render();
1351 
1352  // Check the popup is shown.
1354 
1355  END_TEST;
1356 }
1357 
1359 {
1360  ToolkitTestApplication application;
1361  tet_infoline( " UtcDaliPopupPropertyTypeRegistryConnectSignal" );
1362 
1363  // Create the Popup actor
1364  Popup popup = Popup::New();
1365 
1367  // Note: The emmision of this signals has already been tested in other tests.
1368  DALI_TEST_CHECK( popup.ConnectSignal( testTracker, "touchedOutside", PopupTestFunctor() ) );
1369  DALI_TEST_CHECK( popup.ConnectSignal( testTracker, "showing", PopupTestFunctor() ) );
1370  DALI_TEST_CHECK( popup.ConnectSignal( testTracker, "shown", PopupTestFunctor() ) );
1371  DALI_TEST_CHECK( popup.ConnectSignal( testTracker, "hiding", PopupTestFunctor() ) );
1372  DALI_TEST_CHECK( popup.ConnectSignal( testTracker, "hidden", PopupTestFunctor() ) );
1373 
1374  // Test connecting to an invalid signal does not work.
1375  DALI_TEST_CHECK( !popup.ConnectSignal( testTracker, "invalid", PopupTestFunctor() ) );
1376 
1377  END_TEST;
1378 }
1379 
1381 {
1382  ToolkitTestApplication application;
1383  tet_infoline( " UtcDaliPopupOnControlChildAdd" );
1384 
1385  // Create the Popup actor
1386  Popup popup = Popup::New();
1388  std::string testLabelText = "ContentTest";
1389  TextLabel contentLabel = TextLabel::New( testLabelText );
1390 
1391  popup.Add( contentLabel );
1392 
1393  DALI_TEST_CHECK( HasAncestor( contentLabel, popup ) );
1394 
1395  END_TEST;
1396 }
1397 
1399 {
1400  ToolkitTestApplication application;
1401  tet_infoline( " UtcDaliPopupOnKeyEvent" );
1402 
1403  // Create the Popup actor
1404  Popup popup = Popup::New();
1406  Stage::GetCurrent().Add( popup );
1407 
1408  popup.SetDisplayState( Popup::SHOWN );
1409  application.SendNotification();
1410  application.Render();
1411 
1413 
1414  popup.SetKeyInputFocus();
1415 
1416  application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Down ) );
1417  application.SendNotification();
1418  application.Render();
1419 
1421 
1422  END_TEST;
1423 }
Dali Docs Home
Read more about Dali