Merge "DALi Version 1.2.49" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ScrollBar.cpp
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 <iostream>
19 #include <stdlib.h>
20 #include <string>
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali/integration-api/events/pan-gesture-event.h>
24 #include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar-devel.h>
25
26 using namespace Dali;
27 using namespace Toolkit;
28
29 void dali_scrollbar_startup(void)
30 {
31   test_return_value = TET_UNDEF;
32 }
33
34 void dali_scrollbar_cleanup(void)
35 {
36   test_return_value = TET_PASS;
37 }
38
39 namespace
40 {
41
42 const int RENDER_FRAME_INTERVAL = 16;                       ///< Duration of each frame in ms. (at approx 60FPS)
43
44 // Generate a PanGestureEvent to send to Core
45 Integration::PanGestureEvent GeneratePan(
46     Gesture::State state,
47     const Vector2& previousPosition,
48     const Vector2& currentPosition,
49     unsigned long timeDelta,
50     unsigned int numberOfTouches = 1)
51 {
52   Integration::PanGestureEvent pan(state);
53
54   pan.previousPosition = previousPosition;
55   pan.currentPosition = currentPosition;
56   pan.timeDelta = timeDelta;
57   pan.numberOfTouches = numberOfTouches;
58
59   return pan;
60 }
61
62 /**
63  * Helper to generate PanGestureEvent
64  *
65  * @param[in] application Application instance
66  * @param[in] state The Gesture State
67  * @param[in] pos The current position of touch.
68  */
69 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
70 {
71   static Vector2 last;
72
73   if( (state == Gesture::Started) ||
74       (state == Gesture::Possible) )
75   {
76     last.x = pos.x;
77     last.y = pos.y;
78   }
79
80   application.ProcessEvent(GeneratePan(state, last, pos, RENDER_FRAME_INTERVAL));
81
82   last.x = pos.x;
83   last.y = pos.y;
84 }
85
86 /*
87  * Simulate time passed by.
88  *
89  * @note this will always process at least 1 frame (1/60 sec)
90  *
91  * @param application Test application instance
92  * @param duration Time to pass in milliseconds.
93  * @return The actual time passed in milliseconds
94  */
95 int Wait(ToolkitTestApplication& application, int duration = 0)
96 {
97   int time = 0;
98
99   for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
100   {
101     application.SendNotification();
102     application.Render(RENDER_FRAME_INTERVAL);
103     time += RENDER_FRAME_INTERVAL;
104   }
105
106   return time;
107 }
108
109 // Callback probes.
110
111 static bool gOnPanFinishedCalled;                         ///< Whether the PanFinished signal was invoked.
112 static bool gOnScrollPositionIntervalReachedSignalCalled;        ///< Whether the ScrollPositionIntervalReached signal was invoked.
113
114 /**
115  * Invoked when pan gesture is finished on the scroll indicator.
116  */
117 static void OnPanFinished()
118 {
119   gOnPanFinishedCalled = true;
120 }
121
122 struct CallbackFunctor
123 {
124   CallbackFunctor(bool* callbackFlag)
125   : mCallbackFlag( callbackFlag )
126   {
127   }
128
129   void operator()()
130   {
131     *mCallbackFlag = true;
132   }
133   bool* mCallbackFlag;
134 };
135
136 /**
137  * Invoked when the current scroll position of the scrollable content goes above or below the values
138  * specified by SCROLL_POSITION_INTERVALS property.
139  *
140  * @param[in] position The current scroll position.
141  */
142 static void OnScrollPositionIntervalReached( float position )
143 {
144   gOnScrollPositionIntervalReachedSignalCalled = true;
145 }
146
147 static Vector2 PerformGestureSwipe(ToolkitTestApplication& application, Vector2 start, Vector2 direction, int frames)
148 {
149   gOnPanFinishedCalled = false;
150
151   // Now do a pan starting from (start) and heading (direction)
152   Vector2 pos(start);
153   SendPan(application, Gesture::Possible, pos);
154   SendPan(application, Gesture::Started, pos);
155   Wait(application);
156
157   for(int i = 0; i < frames; i++)
158   {
159     pos += direction; // Move in this direction
160     SendPan(application, Gesture::Continuing, pos);
161     Wait(application);
162   }
163
164   pos += direction; // Move in this direction.
165   SendPan(application, Gesture::Finished, pos);
166   Wait(application);
167
168   return pos;
169 }
170
171 } // namespace
172
173 int UtcDaliToolkitScrollBarConstructorP(void)
174 {
175   ToolkitTestApplication application;
176
177   ScrollBar scrollBar;
178   DALI_TEST_CHECK( !scrollBar );
179   END_TEST;
180 }
181
182 int UtcDaliToolkitScrollBarCopyConstructorP(void)
183 {
184   ToolkitTestApplication application;
185
186   ScrollBar scrollBar = ScrollBar::New();
187   scrollBar.SetProperty( ScrollBar::Property::INDICATOR_FIXED_HEIGHT, 38.2f );
188
189   ScrollBar copy( scrollBar );
190   DALI_TEST_CHECK( copy );
191   DALI_TEST_CHECK( copy.GetProperty<float>( ScrollBar::Property::INDICATOR_FIXED_HEIGHT ) == scrollBar.GetProperty<float>( ScrollBar::Property::INDICATOR_FIXED_HEIGHT ) );
192   END_TEST;
193 }
194
195 int UtcDaliToolkitScrollBarAssignmentOperatorP(void)
196 {
197   ToolkitTestApplication application;
198
199   ScrollBar scrollBar = ScrollBar::New();
200   scrollBar.SetProperty( ScrollBar::Property::INDICATOR_FIXED_HEIGHT, 38.2f );
201
202   ScrollBar copy = scrollBar;
203   DALI_TEST_CHECK( copy );
204   DALI_TEST_CHECK( copy.GetProperty<float>( ScrollBar::Property::INDICATOR_FIXED_HEIGHT ) == scrollBar.GetProperty<float>( ScrollBar::Property::INDICATOR_FIXED_HEIGHT ) );
205   END_TEST;
206 }
207
208 int UtcDaliScrollBarDestructorP(void)
209 {
210   ToolkitTestApplication application;
211
212   ScrollBar* scrollBar = new ScrollBar();
213   delete scrollBar;
214
215   DALI_TEST_CHECK( true );
216   END_TEST;
217 }
218
219 int UtcDaliToolkitScrollBarNewP(void)
220 {
221   ToolkitTestApplication application;
222
223   ScrollBar scrollBar = ScrollBar::New();
224   DALI_TEST_CHECK( scrollBar );
225   END_TEST;
226
227   ScrollBar vertical = ScrollBar::New(ScrollBar::Vertical);
228   DALI_TEST_CHECK( vertical );
229   DALI_TEST_CHECK( vertical.GetScrollDirection() == ScrollBar::Vertical );
230
231   Property::Value value = vertical.GetProperty(ScrollBar::Property::SCROLL_DIRECTION);
232   std::string scrollDirection = value.Get<std::string>();
233   DALI_TEST_EQUALS( scrollDirection, "Vertical", TEST_LOCATION );
234
235   ScrollBar horizontal = ScrollBar::New(ScrollBar::Horizontal);
236   DALI_TEST_CHECK( horizontal );
237   DALI_TEST_CHECK( horizontal.GetScrollDirection() == ScrollBar::Horizontal );
238   value = vertical.GetProperty(ScrollBar::Property::SCROLL_DIRECTION);
239   scrollDirection = value.Get<std::string>();
240   DALI_TEST_EQUALS( scrollDirection, "Horizontal", TEST_LOCATION );
241
242   END_TEST;
243 }
244
245 int UtcDaliToolkitScrollBarCreateP(void)
246 {
247   ToolkitTestApplication application;
248
249   TypeRegistry typeRegistry = TypeRegistry::Get();
250   DALI_TEST_CHECK( typeRegistry );
251
252   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ScrollBar" );
253   DALI_TEST_CHECK( typeInfo );
254
255   BaseHandle handle = typeInfo.CreateInstance();
256   DALI_TEST_CHECK( handle );
257
258   ScrollBar scrollBar = ScrollBar::DownCast( handle );
259   DALI_TEST_CHECK( scrollBar );
260
261   scrollBar.SetProperty(ScrollBar::Property::SCROLL_DIRECTION, "Vertical");
262   scrollBar.SetProperty(ScrollBar::Property::INDICATOR_HEIGHT_POLICY, "Fixed");
263
264   DALI_TEST_EQUALS( scrollBar.GetScrollDirection(), Toolkit::ScrollBar::Vertical, TEST_LOCATION );
265   DALI_TEST_EQUALS( scrollBar.GetIndicatorHeightPolicy(), Toolkit::ScrollBar::Fixed, TEST_LOCATION );
266
267   scrollBar.SetProperty(ScrollBar::Property::SCROLL_DIRECTION, "Horizontal");
268   scrollBar.SetProperty(ScrollBar::Property::INDICATOR_HEIGHT_POLICY, "Variable");
269
270   DALI_TEST_EQUALS( scrollBar.GetScrollDirection(), Toolkit::ScrollBar::Horizontal, TEST_LOCATION );
271   DALI_TEST_EQUALS( scrollBar.GetIndicatorHeightPolicy(), Toolkit::ScrollBar::Variable, TEST_LOCATION );
272
273   END_TEST;
274 }
275
276 int UtcDaliToolkitScrollBarDownCastP(void)
277 {
278   ToolkitTestApplication application;
279
280   ScrollBar scrollBar1 = ScrollBar::New();
281   BaseHandle object( scrollBar1 );
282
283   ScrollBar scrollBar2 = ScrollBar::DownCast( object );
284   DALI_TEST_CHECK( scrollBar2 );
285
286   ScrollBar scrollBar3 = DownCast< ScrollBar >( object );
287   DALI_TEST_CHECK( scrollBar3 );
288   END_TEST;
289 }
290
291 int UtcDaliToolkitScrollBarDownCastN(void)
292 {
293   ToolkitTestApplication application;
294
295   BaseHandle uninitializedObject;
296   ScrollBar scrollBar1 = ScrollBar::DownCast( uninitializedObject );
297   DALI_TEST_CHECK( !scrollBar1 );
298
299   ScrollBar scrollBar2 = DownCast< ScrollBar >( uninitializedObject );
300   DALI_TEST_CHECK( !scrollBar2 );
301   END_TEST;
302 }
303
304 int UtcDaliToolkitScrollBarSetScrollPropertySourceP(void)
305 {
306   ToolkitTestApplication application;
307
308   // Create a vertical scroll bar
309   ScrollBar scrollBar = ScrollBar::New(ScrollBar::Vertical);
310   DALI_TEST_CHECK( scrollBar );
311   DALI_TEST_CHECK( scrollBar.GetScrollDirection() == ScrollBar::Vertical );
312
313   float scrollBarHeight = 100.0f;
314   scrollBar.SetSize(20.0f, scrollBarHeight, 0.0f);
315   Stage::GetCurrent().Add( scrollBar );
316
317   // Create a source actor that owns the scroll properties required by the scroll bar
318   Actor sourceActor = Actor::New();
319   Stage::GetCurrent().Add( sourceActor );
320
321   // Register the scroll properties
322   Property::Index propertyScrollPosition = sourceActor.RegisterProperty( "sourcePosition",  0.0f );
323   Property::Index propertyMinScrollPosition = sourceActor.RegisterProperty( "sourcePositionMin",   0.0f );
324   Property::Index propertyMaxScrollPosition = sourceActor.RegisterProperty( "sourcePositionMax",   100.0f );
325   Property::Index propertyScrollContentSize = sourceActor.RegisterProperty( "sourceContentSize",   500.0f );
326
327   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePosition" ), propertyScrollPosition, TEST_LOCATION );
328   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePositionMin" ), propertyMinScrollPosition, TEST_LOCATION );
329   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePositionMax" ), propertyMaxScrollPosition, TEST_LOCATION );
330   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourceContentSize" ), propertyScrollContentSize, TEST_LOCATION );
331
332   // Set the source of the scroll position properties.
333   scrollBar.SetScrollPropertySource(sourceActor, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
334
335   // Render and notify
336   application.SendNotification();
337   application.Render();
338
339   Actor indicator = scrollBar.GetScrollIndicator();
340   DALI_TEST_CHECK( indicator );
341
342   // Check that the indicator size should be: scroll bar size * (scroll bar size / content size).
343   // i.e. The bigger the content size, the smaller the indicator size
344   float indicatorHeight = indicator.GetCurrentSize().y;
345   DALI_TEST_EQUALS( indicatorHeight, scrollBarHeight * scrollBarHeight / 500.0f, TEST_LOCATION );
346
347   // Decrease the content length
348   sourceActor.SetProperty( propertyScrollContentSize, 250.0f );
349
350   // Render and notify
351   application.SendNotification();
352   application.Render();
353
354   // Check that the indicator size is changed accordingly
355   indicatorHeight = indicator.GetCurrentSize().y;
356   DALI_TEST_EQUALS( indicatorHeight, scrollBarHeight * scrollBarHeight / 250.0f, TEST_LOCATION );
357
358   // As scroll position is 0, check that the indicator position should be 0.0f.
359   float indicatorPosition = indicator.GetCurrentPosition().y;
360   DALI_TEST_EQUALS( indicatorPosition, 0.0f, TEST_LOCATION );
361
362   // Set the scroll position to the middle
363   sourceActor.SetProperty( propertyScrollPosition, -50.0f );
364
365   // Render and notify
366   application.SendNotification();
367   application.Render();
368
369   // Check that the indicator should be in the middle of the scroll bar
370   indicatorPosition = indicator.GetCurrentPosition().y;
371   DALI_TEST_EQUALS( indicatorPosition, (scrollBarHeight - indicatorHeight) * 0.5f, TEST_LOCATION );
372
373   // Set the scroll position to the maximum
374   sourceActor.SetProperty( propertyScrollPosition, -100.0f );
375
376   // Render and notify
377   application.SendNotification();
378   application.Render();
379
380   // Check that the indicator should be in the end of the scroll bar
381   indicatorPosition = indicator.GetCurrentPosition().y;
382   DALI_TEST_EQUALS( indicatorPosition, scrollBarHeight - indicatorHeight, TEST_LOCATION );
383
384   // Increase the maximum scroll position to double
385   sourceActor.SetProperty( propertyMaxScrollPosition, 200.0f );
386
387   // Render and notify
388   application.SendNotification();
389   application.Render();
390
391   // Check that the indicator should be now in the middle of the scroll bar
392   indicatorPosition = indicator.GetCurrentPosition().y;
393   DALI_TEST_EQUALS( indicatorPosition, (scrollBarHeight - indicatorHeight) * 0.5f, TEST_LOCATION );
394
395   // Create another source actor
396   Actor newSourceActor = Actor::New();
397   Stage::GetCurrent().Add( newSourceActor );
398
399   // Register the scroll properties
400   Property::Index newPropertyScrollPosition = newSourceActor.RegisterProperty( "sourcePosition",  0.0f );
401   Property::Index newPropertyMinScrollPosition = newSourceActor.RegisterProperty( "sourcePositionMin",   0.0f );
402   Property::Index newPropertyMaxScrollPosition = newSourceActor.RegisterProperty( "sourcePositionMax",   200.0f );
403   Property::Index newPropertyScrollContentSize = newSourceActor.RegisterProperty( "sourceContentSize",   400.0f );
404
405   DALI_TEST_EQUALS( newSourceActor.GetPropertyIndex( "sourcePosition" ), newPropertyScrollPosition, TEST_LOCATION );
406   DALI_TEST_EQUALS( newSourceActor.GetPropertyIndex( "sourcePositionMin" ), newPropertyMinScrollPosition, TEST_LOCATION );
407   DALI_TEST_EQUALS( newSourceActor.GetPropertyIndex( "sourcePositionMax" ), newPropertyMaxScrollPosition, TEST_LOCATION );
408   DALI_TEST_EQUALS( newSourceActor.GetPropertyIndex( "sourceContentSize" ), newPropertyScrollContentSize, TEST_LOCATION );
409
410   // Change the source of the scroll position properties to be the new source actor.
411   scrollBar.SetScrollPropertySource(newSourceActor, newPropertyScrollPosition, newPropertyMinScrollPosition, newPropertyMaxScrollPosition, newPropertyScrollContentSize);
412
413   // Render and notify
414   application.SendNotification();
415   application.Render();
416
417   // Check that the indicator size is changed accordingly
418   indicatorHeight = indicator.GetCurrentSize().y;
419   DALI_TEST_EQUALS( indicatorHeight, scrollBarHeight * scrollBarHeight / 400.0f, TEST_LOCATION );
420
421   // Check that the indicator position goes back to the beginning of the scroll bar
422   indicatorPosition = indicator.GetCurrentPosition().y;
423   DALI_TEST_EQUALS( indicatorPosition, 0.0f, TEST_LOCATION );
424
425   // Set the scroll position to one fifth of the maximum
426   newSourceActor.SetProperty( propertyScrollPosition, -40.0f );
427
428   // Render and notify
429   application.SendNotification();
430   application.Render();
431
432   // Check that the indicator should be in one fifth from the beginning of the scroll bar
433   indicatorPosition = indicator.GetCurrentPosition().y;
434   DALI_TEST_EQUALS( indicatorPosition, (scrollBarHeight - indicatorHeight) * 0.2f, TEST_LOCATION );
435
436   END_TEST;
437 }
438
439 int UtcDaliToolkitScrollBarSetScrollPropertySourceN(void)
440 {
441   ToolkitTestApplication application;
442
443   // Create a scroll bar
444   ScrollBar scrollBar = ScrollBar::New();
445   DALI_TEST_CHECK( scrollBar );
446
447   // Set empty handle of source object and invalid source property index.
448   Actor sourceActor;
449   scrollBar.SetScrollPropertySource(sourceActor, Property::INVALID_INDEX, Property::INVALID_INDEX, Property::INVALID_INDEX, Property::INVALID_INDEX);
450
451   DALI_TEST_CHECK( true );
452   END_TEST;
453 }
454
455 int UtcDaliToolkitScrollBarSetScrollIndicatorP(void)
456 {
457   ToolkitTestApplication application;
458
459   // Create a scroll bar
460   ScrollBar scrollBar = ScrollBar::New();
461   DALI_TEST_CHECK( scrollBar );
462
463   Actor indicator = scrollBar.GetScrollIndicator();
464   DALI_TEST_CHECK( indicator );
465
466   // Set a new indicator
467   Actor newIndicator = Actor::New();
468   scrollBar.SetScrollIndicator(newIndicator);
469
470   // Check that the new indicator is successfully set
471   DALI_TEST_CHECK( indicator != scrollBar.GetScrollIndicator() );
472   DALI_TEST_CHECK( newIndicator == scrollBar.GetScrollIndicator() );
473
474   // Check that the new control indicator is successfully set
475   Control controlIndicator = Control::New();
476   scrollBar.SetScrollIndicator(controlIndicator);
477
478   DALI_TEST_CHECK( controlIndicator == Control::DownCast( scrollBar.GetScrollIndicator() ) );
479   END_TEST;
480 }
481
482 int UtcDaliToolkitScrollBarSetScrollIndicatorN(void)
483 {
484   ToolkitTestApplication application;
485
486   // Create a scroll bar
487   ScrollBar scrollBar = ScrollBar::New();
488   DALI_TEST_CHECK( scrollBar );
489
490   Actor indicator = scrollBar.GetScrollIndicator();
491   DALI_TEST_CHECK( indicator );
492
493   // Try to set an uninitialized actor as the indicator
494   Actor uninitializedIndicator;
495   scrollBar.SetScrollIndicator(uninitializedIndicator);
496
497   // Check that the uninitialized actor can not be set as the indicator
498   DALI_TEST_CHECK( indicator == scrollBar.GetScrollIndicator() );
499   DALI_TEST_CHECK( uninitializedIndicator != scrollBar.GetScrollIndicator() );
500
501   END_TEST;
502 }
503
504 int UtcDaliToolkitScrollBarGetScrollIndicatorP(void)
505 {
506   ToolkitTestApplication application;
507
508   // Create a scroll bar
509   ScrollBar scrollBar = ScrollBar::New();
510   DALI_TEST_CHECK( scrollBar );
511
512   Actor indicator = scrollBar.GetScrollIndicator();
513   DALI_TEST_CHECK( indicator );
514
515   // Set a new indicator
516   Actor newIndicator = Actor::New();
517   scrollBar.SetScrollIndicator(newIndicator);
518
519   // Check that the new indicator is successfully set
520   DALI_TEST_CHECK( scrollBar.GetScrollIndicator() );
521   DALI_TEST_CHECK( indicator != scrollBar.GetScrollIndicator() );
522   DALI_TEST_CHECK( newIndicator == scrollBar.GetScrollIndicator() );
523
524   END_TEST;
525 }
526
527 int UtcDaliToolkitScrollBarGetScrollIndicatorN(void)
528 {
529   ToolkitTestApplication application;
530
531   // Create a scroll bar
532   ScrollBar scrollBar = ScrollBar::New();
533   DALI_TEST_CHECK( scrollBar );
534
535   Actor indicator = scrollBar.GetScrollIndicator();
536   DALI_TEST_CHECK( indicator );
537
538   // Try to set an uninitialized actor as the indicator
539   Actor uninitializedIndicator;
540   scrollBar.SetScrollIndicator(uninitializedIndicator);
541
542   // Check that the indicator has not been changed
543   DALI_TEST_CHECK( indicator == scrollBar.GetScrollIndicator() );
544   DALI_TEST_CHECK( uninitializedIndicator != scrollBar.GetScrollIndicator() );
545
546   END_TEST;
547 }
548
549 int UtcDaliToolkitScrollBarSetScrollPositionIntervalsP(void)
550 {
551   ToolkitTestApplication application;
552
553   // Create a vertical scroll bar
554   ScrollBar scrollBar = ScrollBar::New(ScrollBar::Vertical);
555   DALI_TEST_CHECK( scrollBar );
556
557   scrollBar.SetParentOrigin(ParentOrigin::TOP_LEFT);
558   scrollBar.SetAnchorPoint(AnchorPoint::TOP_LEFT);
559   scrollBar.SetSize(20.0f, 800.0f, 0.0f);
560
561   Stage::GetCurrent().Add( scrollBar );
562
563   // Connect to the ScrollPositionIntervalReached signal
564   scrollBar.ScrollPositionIntervalReachedSignal().Connect( &OnScrollPositionIntervalReached );
565
566   // Render and notify
567   application.SendNotification();
568   application.Render();
569
570   // Create a source actor that owns the scroll properties required by the scroll bar
571   Actor sourceActor = Actor::New();
572   Stage::GetCurrent().Add( sourceActor );
573
574   // Register the scroll properties
575   Property::Index propertyScrollPosition = sourceActor.RegisterProperty( "sourcePosition",  0.0f );
576   Property::Index propertyMinScrollPosition = sourceActor.RegisterProperty( "sourcePositionMin",   0.0f );
577   Property::Index propertyMaxScrollPosition = sourceActor.RegisterProperty( "sourcePositionMax",   800.0f );
578   Property::Index propertyScrollContentSize = sourceActor.RegisterProperty( "sourceContentSize",   2000.0f );
579
580   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePosition" ), propertyScrollPosition, TEST_LOCATION );
581   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePositionMin" ), propertyMinScrollPosition, TEST_LOCATION );
582   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePositionMax" ), propertyMaxScrollPosition, TEST_LOCATION );
583   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourceContentSize" ), propertyScrollContentSize, TEST_LOCATION );
584
585   // Set the source of the scroll position properties.
586   scrollBar.SetScrollPropertySource(sourceActor, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
587
588   // Render and notify
589   application.SendNotification();
590   application.Render();
591
592   // Set the values to get notified when the scroll positions of the source actor goes above or below these values
593   Dali::Vector<float> positionIntervals;
594   for( size_t i = 0; i != 10; ++i )
595   {
596     positionIntervals.PushBack( -80.0f * i ); // should get notified for each 80 pixels
597   }
598   scrollBar.SetScrollPositionIntervals(positionIntervals);
599
600   // Get the list of scroll position intervals for notification
601   Dali::Vector<float> results = scrollBar.GetScrollPositionIntervals();
602
603   // Check that the result is the same as the list previously set.
604   DALI_TEST_EQUALS( positionIntervals.Count(), results.Count(), TEST_LOCATION );
605   DALI_TEST_EQUALS( positionIntervals[0], results[0], TEST_LOCATION );
606   DALI_TEST_EQUALS( positionIntervals[1], results[1], TEST_LOCATION );
607   DALI_TEST_EQUALS( positionIntervals[2], results[2], TEST_LOCATION );
608   DALI_TEST_EQUALS( positionIntervals[3], results[3], TEST_LOCATION );
609   DALI_TEST_EQUALS( positionIntervals[4], results[4], TEST_LOCATION );
610   DALI_TEST_EQUALS( positionIntervals[5], results[5], TEST_LOCATION );
611   DALI_TEST_EQUALS( positionIntervals[6], results[6], TEST_LOCATION );
612   DALI_TEST_EQUALS( positionIntervals[7], results[7], TEST_LOCATION );
613   DALI_TEST_EQUALS( positionIntervals[8], results[8], TEST_LOCATION );
614   DALI_TEST_EQUALS( positionIntervals[9], results[9], TEST_LOCATION );
615
616   // Reset the flag
617   gOnScrollPositionIntervalReachedSignalCalled = false;
618
619   // Animate the scroll position to cross the specified value
620   Animation animation = Animation::New(0.1f);
621   animation.AnimateTo( Property( sourceActor, propertyScrollPosition ), -85.0f );
622   animation.Play();
623
624   // Wait for 0.1 second
625   Wait(application, 100);
626
627   // Check that the signal callback is called
628   DALI_TEST_EQUALS( gOnScrollPositionIntervalReachedSignalCalled, true, TEST_LOCATION );
629
630   // Reset the flag
631   gOnScrollPositionIntervalReachedSignalCalled = false;
632
633   // Rest and clear the animation
634   animation.Clear();
635   animation.Reset();
636
637   // Animate the scroll position to cross another specified value
638   animation = Animation::New(0.1f);
639   animation.AnimateTo( Property( sourceActor, propertyScrollPosition ), -170.0f );
640   animation.Play();
641
642   // Wait for 0.1 second
643   Wait(application, 100);
644
645   // Check that the signal callback is called
646   DALI_TEST_EQUALS( gOnScrollPositionIntervalReachedSignalCalled, true, TEST_LOCATION );
647
648   // Reset the flag
649   gOnScrollPositionIntervalReachedSignalCalled = false;
650
651   // Rest and clear the animation
652   animation.Clear();
653   animation.Reset();
654
655   // Animate the scroll position back to the previous value
656   animation = Animation::New(0.1f);
657   animation.AnimateTo( Property( sourceActor, propertyScrollPosition ), -85.0f );
658   animation.Play();
659
660   // Wait for 0.1 second
661   Wait(application, 100);
662
663   // Check that the signal callback is called
664   DALI_TEST_EQUALS( gOnScrollPositionIntervalReachedSignalCalled, true, TEST_LOCATION );
665
666   END_TEST;
667 }
668
669 int UtcDaliToolkitScrollBarGetScrollPositionIntervalsP(void)
670 {
671   ToolkitTestApplication application;
672
673   // Create a vertical scroll bar
674   ScrollBar scrollBar = ScrollBar::New(ScrollBar::Vertical);
675   DALI_TEST_CHECK( scrollBar );
676
677   // Set the values to get notified when the scroll positions of the source actor goes above or below these values
678   Dali::Vector<float> positionIntervals;
679   for( size_t i = 0; i != 10; ++i )
680   {
681     positionIntervals.PushBack( -80.0f * i ); // should get notified for each 80 pixels
682   }
683   scrollBar.SetScrollPositionIntervals(positionIntervals);
684
685   // Get the list of scroll position intervals for notification
686   Dali::Vector<float> results = scrollBar.GetScrollPositionIntervals();
687
688   // Check that the result is the same as the list previously set.
689   DALI_TEST_EQUALS( positionIntervals.Count(), results.Count(), TEST_LOCATION );
690   DALI_TEST_EQUALS( positionIntervals[0], results[0], TEST_LOCATION );
691   DALI_TEST_EQUALS( positionIntervals[1], results[1], TEST_LOCATION );
692   DALI_TEST_EQUALS( positionIntervals[2], results[2], TEST_LOCATION );
693   DALI_TEST_EQUALS( positionIntervals[3], results[3], TEST_LOCATION );
694   DALI_TEST_EQUALS( positionIntervals[4], results[4], TEST_LOCATION );
695   DALI_TEST_EQUALS( positionIntervals[5], results[5], TEST_LOCATION );
696   DALI_TEST_EQUALS( positionIntervals[6], results[6], TEST_LOCATION );
697   DALI_TEST_EQUALS( positionIntervals[7], results[7], TEST_LOCATION );
698   DALI_TEST_EQUALS( positionIntervals[8], results[8], TEST_LOCATION );
699   DALI_TEST_EQUALS( positionIntervals[9], results[9], TEST_LOCATION );
700
701   Property::Array resultArray = scrollBar.GetProperty<Property::Array>(Toolkit::ScrollBar::Property::SCROLL_POSITION_INTERVALS);
702
703   DALI_TEST_EQUALS( positionIntervals.Count(), resultArray.Count(), TEST_LOCATION );
704   DALI_TEST_EQUALS( positionIntervals[0], resultArray[0].Get<float>(), TEST_LOCATION );
705   DALI_TEST_EQUALS( positionIntervals[1], resultArray[1].Get<float>(), TEST_LOCATION );
706   DALI_TEST_EQUALS( positionIntervals[2], resultArray[2].Get<float>(), TEST_LOCATION );
707   DALI_TEST_EQUALS( positionIntervals[3], resultArray[3].Get<float>(), TEST_LOCATION );
708   DALI_TEST_EQUALS( positionIntervals[4], resultArray[4].Get<float>(), TEST_LOCATION );
709   DALI_TEST_EQUALS( positionIntervals[5], resultArray[5].Get<float>(), TEST_LOCATION );
710   DALI_TEST_EQUALS( positionIntervals[6], resultArray[6].Get<float>(), TEST_LOCATION );
711   DALI_TEST_EQUALS( positionIntervals[7], resultArray[7].Get<float>(), TEST_LOCATION );
712   DALI_TEST_EQUALS( positionIntervals[8], resultArray[8].Get<float>(), TEST_LOCATION );
713   DALI_TEST_EQUALS( positionIntervals[9], resultArray[9].Get<float>(), TEST_LOCATION );
714
715   END_TEST;
716 }
717
718 int UtcDaliToolkitScrollBarGetScrollDirectionP(void)
719 {
720   ToolkitTestApplication application;
721
722   // Create a vertical scroll bar
723   ScrollBar scrollBar = ScrollBar::New(ScrollBar::Vertical);
724   DALI_TEST_CHECK( scrollBar );
725   DALI_TEST_CHECK( scrollBar.GetScrollDirection() == ScrollBar::Vertical );
726
727   // Change the direction of scroll bar to horizontal
728   scrollBar.SetScrollDirection(ScrollBar::Horizontal);
729   DALI_TEST_CHECK( scrollBar.GetScrollDirection() == ScrollBar::Horizontal );
730
731   END_TEST;
732 }
733
734 int UtcDaliToolkitScrollBarSetIndicatorHeightPolicyP(void)
735 {
736   ToolkitTestApplication application;
737
738   // Create a scroll bar
739   ScrollBar scrollBar = ScrollBar::New();
740   DALI_TEST_CHECK( scrollBar );
741
742   float scrollBarHeight = 100.0f;
743   scrollBar.SetSize(20.0f, scrollBarHeight, 0.0f);
744   Stage::GetCurrent().Add( scrollBar );
745
746   // Create a source actor that owns the scroll properties required by the scroll bar
747   Actor sourceActor = Actor::New();
748   Stage::GetCurrent().Add( sourceActor );
749
750   // Register the scroll properties
751   Property::Index propertyScrollPosition = sourceActor.RegisterProperty( "sourcePosition",  0.0f );
752   Property::Index propertyMinScrollPosition = sourceActor.RegisterProperty( "sourcePositionMin",   0.0f );
753   Property::Index propertyMaxScrollPosition = sourceActor.RegisterProperty( "sourcePositionMax",   100.0f );
754   Property::Index propertyScrollContentSize = sourceActor.RegisterProperty( "sourceContentSize",   500.0f );
755
756   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePosition" ), propertyScrollPosition, TEST_LOCATION );
757   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePositionMin" ), propertyMinScrollPosition, TEST_LOCATION );
758   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePositionMax" ), propertyMaxScrollPosition, TEST_LOCATION );
759   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourceContentSize" ), propertyScrollContentSize, TEST_LOCATION );
760
761   // Set the source of the scroll position properties.
762   scrollBar.SetScrollPropertySource(sourceActor, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
763
764   // Render and notify
765   application.SendNotification();
766   application.Render();
767
768   Actor indicator = scrollBar.GetScrollIndicator();
769   DALI_TEST_CHECK( indicator );
770
771   // Check that the indicator size should be: scroll bar size * (scroll bar size / content size).
772   // i.e. The bigger the content size, the smaller the indicator size
773   float indicatorHeight = indicator.GetCurrentSize().y;
774   DALI_TEST_EQUALS( indicatorHeight, scrollBarHeight * scrollBarHeight / 500.0f, TEST_LOCATION );
775
776   // Set the indicator height to be fixed to 50.0f
777   scrollBar.SetIndicatorHeightPolicy(Toolkit::ScrollBar::Fixed);
778   scrollBar.SetIndicatorFixedHeight(50.0f);
779
780   Property::Value value = scrollBar.GetProperty(ScrollBar::Property::INDICATOR_HEIGHT_POLICY);
781   DALI_TEST_EQUALS(value.Get<std::string>(), "Fixed", TEST_LOCATION );
782
783   // Render and notify
784   application.SendNotification();
785   application.Render();
786
787   // Check that the indicator size should be 50.0f
788   indicatorHeight = indicator.GetCurrentSize().y;
789   DALI_TEST_EQUALS( indicatorHeight, 50.0f, TEST_LOCATION );
790
791   // Set the indicator height to be variable
792   scrollBar.SetIndicatorHeightPolicy(Toolkit::ScrollBar::Variable);
793   value = scrollBar.GetProperty(ScrollBar::Property::INDICATOR_HEIGHT_POLICY);
794   DALI_TEST_EQUALS(value.Get<std::string>(), "Variable", TEST_LOCATION );
795
796   // Render and notify
797   application.SendNotification();
798   application.Render();
799
800   // Check that the indicator size should be: scroll bar size * (scroll bar size / content size).
801   indicatorHeight = indicator.GetCurrentSize().y;
802   DALI_TEST_EQUALS( indicatorHeight, scrollBarHeight * scrollBarHeight / 500.0f, TEST_LOCATION );
803
804   END_TEST;
805 }
806
807 int UtcDaliToolkitScrollBarGetIndicatorHeightPolicyP(void)
808 {
809   ToolkitTestApplication application;
810
811   // Create a scroll bar
812   ScrollBar scrollBar = ScrollBar::New();
813   DALI_TEST_CHECK( scrollBar );
814
815   // Set the indicator height to be fixed
816   scrollBar.SetIndicatorHeightPolicy(Toolkit::ScrollBar::Fixed);
817   DALI_TEST_EQUALS( scrollBar.GetIndicatorHeightPolicy(), Toolkit::ScrollBar::Fixed, TEST_LOCATION );
818
819   // Set the indicator height to be variable
820   scrollBar.SetIndicatorHeightPolicy(Toolkit::ScrollBar::Variable);
821   DALI_TEST_EQUALS( scrollBar.GetIndicatorHeightPolicy(), Toolkit::ScrollBar::Variable, TEST_LOCATION );
822
823   END_TEST;
824 }
825
826 int UtcDaliToolkitScrollBarSetIndicatorFixedHeightP(void)
827 {
828   ToolkitTestApplication application;
829
830   // Create a scroll bar
831   ScrollBar scrollBar = ScrollBar::New();
832   DALI_TEST_CHECK( scrollBar );
833
834   float scrollBarHeight = 100.0f;
835   scrollBar.SetSize(20.0f, scrollBarHeight, 0.0f);
836   Stage::GetCurrent().Add( scrollBar );
837
838   Actor indicator = scrollBar.GetScrollIndicator();
839   DALI_TEST_CHECK( indicator );
840
841   // Set the indicator height to be fixed to 50.0f
842   scrollBar.SetIndicatorHeightPolicy(Toolkit::ScrollBar::Fixed);
843   scrollBar.SetIndicatorFixedHeight(50.0f);
844
845   // Render and notify
846   application.SendNotification();
847   application.Render();
848
849   // Check that the indicator size should be 50.0f
850   DALI_TEST_EQUALS( indicator.GetCurrentSize().y, 50.0f, TEST_LOCATION );
851
852   // Set the indicator height to be fixed to 25.0f
853   scrollBar.SetIndicatorFixedHeight(25.0f);
854
855   // Render and notify
856   application.SendNotification();
857   application.Render();
858
859   // Check that the indicator size should be 25.0f
860   DALI_TEST_EQUALS( indicator.GetCurrentSize().y, 25.0f, TEST_LOCATION );
861
862   END_TEST;
863 }
864
865 int UtcDaliToolkitScrollBarGetIndicatorFixedHeightP(void)
866 {
867   ToolkitTestApplication application;
868
869   // Create a scroll bar
870   ScrollBar scrollBar = ScrollBar::New();
871   DALI_TEST_CHECK( scrollBar );
872
873   // Set the fixed indicator height to be 50.0f
874   scrollBar.SetIndicatorFixedHeight(50.0f);
875
876   // Check that the indicator size should be 50.0f
877   DALI_TEST_EQUALS( scrollBar.GetIndicatorFixedHeight(), 50.0f, TEST_LOCATION );
878
879   // Set the indicator height to be fixed to 25.0f
880   scrollBar.SetIndicatorFixedHeight(25.0f);
881
882   // Check that the indicator size should be 50.0f
883   DALI_TEST_EQUALS( scrollBar.GetIndicatorFixedHeight(), 25.0f, TEST_LOCATION );
884
885   END_TEST;
886 }
887
888 int UtcDaliToolkitScrollBarSetIndicatorShowDurationP(void)
889 {
890   ToolkitTestApplication application;
891
892   // Create a scroll bar
893   ScrollBar scrollBar = ScrollBar::New();
894   DALI_TEST_CHECK( scrollBar );
895
896   Stage::GetCurrent().Add( scrollBar );
897
898   Actor indicator = scrollBar.GetScrollIndicator();
899   DALI_TEST_CHECK( indicator );
900
901   // Set the duration to show the indicator to be 0.35 second
902   scrollBar.SetIndicatorShowDuration(0.35);
903   DALI_TEST_EQUALS( scrollBar.GetIndicatorShowDuration(), 0.35f, TEST_LOCATION );
904
905   // Make the indicator invisible
906   indicator.SetOpacity(0.0f);
907
908   // Render and notify
909   application.SendNotification();
910   application.Render();
911
912   // Check that the indicator is invisible
913   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
914
915   // Show the indicator
916   scrollBar.ShowIndicator();
917
918   // Wait for 0.35 second
919   Wait(application, 350);
920
921   // Render and notify
922   application.SendNotification();
923   application.Render();
924
925   // Check that the indicator is now visible
926   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
927
928   // Set the duration to show the indicator to be 0.75 second
929   scrollBar.SetIndicatorShowDuration(0.75);
930   DALI_TEST_EQUALS( scrollBar.GetIndicatorShowDuration(), 0.75f, TEST_LOCATION );
931
932   // Make the indicator invisible
933   indicator.SetOpacity(0.0f);
934
935   // Render and notify
936   application.SendNotification();
937   application.Render();
938
939   // Check that the indicator is invisible
940   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
941
942   // Show the indicator
943   scrollBar.ShowIndicator();
944
945   // Wait for 0.35 second first
946   Wait(application, 350);
947
948   // Render and notify
949   application.SendNotification();
950   application.Render();
951
952   // Check that the indicator is not fully visible yet
953   DALI_TEST_CHECK( indicator.GetCurrentOpacity() != 1.0f );
954
955   // Wait for another 0.4 second
956   Wait(application, 400);
957
958   // Render and notify
959   application.SendNotification();
960   application.Render();
961
962   // Check that the indicator is now fully visible
963   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
964
965   END_TEST;
966 }
967
968 int UtcDaliToolkitScrollBarSetIndicatorShowDurationN(void)
969 {
970   ToolkitTestApplication application;
971
972   // Create a scroll bar
973   ScrollBar scrollBar = ScrollBar::New();
974   DALI_TEST_CHECK( scrollBar );
975
976   Stage::GetCurrent().Add( scrollBar );
977
978   Actor indicator = scrollBar.GetScrollIndicator();
979   DALI_TEST_CHECK( indicator );
980
981   // Get the default duration to show the indicator
982   float duration = scrollBar.GetIndicatorShowDuration();
983
984   // Check that the default duration is greater than 0
985   DALI_TEST_CHECK( duration > 0.0f );
986
987   // Make the indicator invisible
988   indicator.SetOpacity(0.0f);
989
990   // Render and notify
991   application.SendNotification();
992   application.Render();
993
994   // Check that the indicator is invisible
995   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
996
997   // Show the indicator
998   scrollBar.ShowIndicator();
999
1000   // Wait for the specified duration
1001   Wait(application, duration * 1000);
1002
1003   // Render and notify
1004   application.SendNotification();
1005   application.Render();
1006
1007   // Check that the indicator is now visible
1008   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1009
1010   // Now set the duration to show the indicator to be a negative value (which should be ignored and therefore means instant)
1011   scrollBar.SetIndicatorShowDuration(-0.25f);
1012   DALI_TEST_EQUALS( scrollBar.GetIndicatorShowDuration(), -0.25f, TEST_LOCATION );
1013
1014   // Make the indicator invisible
1015   indicator.SetOpacity(0.0f);
1016
1017   // Render and notify
1018   application.SendNotification();
1019   application.Render();
1020
1021   // Check that the indicator is invisible
1022   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
1023
1024   // Show the indicator
1025   scrollBar.ShowIndicator();
1026
1027   // Render and notify
1028   application.SendNotification();
1029   application.Render();
1030
1031   // Check that the indicator becomes instantly visible in the next frame
1032   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1033
1034   END_TEST;
1035 }
1036
1037 int UtcDaliToolkitScrollBarGetIndicatorShowDurationP(void)
1038 {
1039   ToolkitTestApplication application;
1040
1041   // Create a scroll bar
1042   ScrollBar scrollBar = ScrollBar::New();
1043   DALI_TEST_CHECK( scrollBar );
1044
1045   // Set the duration to show the indicator to be 0.35 second
1046   scrollBar.SetIndicatorShowDuration(0.35f);
1047
1048   // Check that the duration to show the indicator is 0.35 second
1049   DALI_TEST_EQUALS( scrollBar.GetIndicatorShowDuration(), 0.35f, TEST_LOCATION );
1050
1051   // Set the duration to show the indicator to be 0.75 second
1052   scrollBar.SetIndicatorShowDuration(0.75f);
1053
1054   // Check that the duration to show the indicator is 0.75 second
1055   DALI_TEST_EQUALS( scrollBar.GetIndicatorShowDuration(), 0.75f, TEST_LOCATION );
1056
1057   END_TEST;
1058 }
1059
1060 int UtcDaliToolkitScrollBarSetIndicatorHideDurationP(void)
1061 {
1062   ToolkitTestApplication application;
1063
1064   // Create a scroll bar
1065   ScrollBar scrollBar = ScrollBar::New();
1066   DALI_TEST_CHECK( scrollBar );
1067
1068   Stage::GetCurrent().Add( scrollBar );
1069
1070   Actor indicator = scrollBar.GetScrollIndicator();
1071   DALI_TEST_CHECK( indicator );
1072
1073   // Set the duration to hide the indicator to be 0.15 second
1074   scrollBar.SetIndicatorHideDuration(0.15f);
1075   DALI_TEST_EQUALS( scrollBar.GetIndicatorHideDuration(), 0.15f, TEST_LOCATION );
1076
1077   // Make the indicator visible
1078   indicator.SetOpacity(1.0f);
1079
1080   // Render and notify
1081   application.SendNotification();
1082   application.Render();
1083
1084   // Check that the indicator is visible
1085   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1086
1087   // Hide the indicator
1088   scrollBar.HideIndicator();
1089
1090   // Wait for 0.15 second
1091   Wait(application, 150);
1092
1093   // Render and notify
1094   application.SendNotification();
1095   application.Render();
1096
1097   // Check that the indicator is now invisible
1098   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
1099
1100   // Set the duration to hide the indicator to be 0.65 second
1101   scrollBar.SetIndicatorHideDuration(0.65f);
1102   DALI_TEST_EQUALS( scrollBar.GetIndicatorHideDuration(), 0.65f, TEST_LOCATION );
1103
1104   // Make the indicator visible
1105   indicator.SetOpacity(1.0f);
1106
1107   // Render and notify
1108   application.SendNotification();
1109   application.Render();
1110
1111   // Check that the indicator is visible
1112   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1113
1114   // Hide the indicator
1115   scrollBar.HideIndicator();
1116
1117   // Wait for 0.15 second first
1118   Wait(application, 150);
1119
1120   // Render and notify
1121   application.SendNotification();
1122   application.Render();
1123
1124   // Check that the indicator is not fully invisible yet
1125   DALI_TEST_CHECK( indicator.GetCurrentOpacity() != 0.0f );
1126
1127   // Wait for another 0.5 second
1128   Wait(application, 500);
1129
1130   // Render and notify
1131   application.SendNotification();
1132   application.Render();
1133
1134   // Check that the indicator is now fully invisible
1135   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
1136
1137   END_TEST;
1138 }
1139
1140 int UtcDaliToolkitScrollBarSetIndicatorHideDurationN(void)
1141 {
1142   ToolkitTestApplication application;
1143
1144   // Create a scroll bar
1145   ScrollBar scrollBar = ScrollBar::New();
1146   DALI_TEST_CHECK( scrollBar );
1147
1148   Stage::GetCurrent().Add( scrollBar );
1149
1150   Actor indicator = scrollBar.GetScrollIndicator();
1151   DALI_TEST_CHECK( indicator );
1152
1153   // Get the default duration to hide the indicator
1154   float duration = scrollBar.GetIndicatorHideDuration();
1155
1156   // Check that the default duration is greater than 0
1157   DALI_TEST_CHECK( duration > 0.0f );
1158
1159   // Make the indicator visible
1160   indicator.SetOpacity(1.0f);
1161
1162   // Render and notify
1163   application.SendNotification();
1164   application.Render();
1165
1166   // Check that the indicator is visible
1167   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1168
1169   // Hide the indicator
1170   scrollBar.HideIndicator();
1171
1172   // Wait for the specified duration
1173   Wait(application, duration * 1000);
1174
1175   // Render and notify
1176   application.SendNotification();
1177   application.Render();
1178
1179   // Check that the indicator is now invisible
1180   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
1181
1182   // Now set the duration to hide the indicator to be a negative value (which should be ignored and therefore means instant)
1183   scrollBar.SetIndicatorHideDuration(-0.25f);
1184   DALI_TEST_EQUALS( scrollBar.GetIndicatorHideDuration(), -0.25f, TEST_LOCATION );
1185
1186   // Make the indicator visible
1187   indicator.SetOpacity(1.0f);
1188
1189   // Render and notify
1190   application.SendNotification();
1191   application.Render();
1192
1193   // Check that the indicator is visible
1194   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1195
1196   // Hide the indicator
1197   scrollBar.HideIndicator();
1198
1199   // Render and notify
1200   application.SendNotification();
1201   application.Render();
1202
1203   // Check that the indicator becomes instantly invisible in the next frame
1204   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
1205
1206   END_TEST;
1207 }
1208
1209 int UtcDaliToolkitScrollBarGetIndicatorHideDurationP(void)
1210 {
1211   ToolkitTestApplication application;
1212
1213   // Create a scroll bar
1214   ScrollBar scrollBar = ScrollBar::New();
1215   DALI_TEST_CHECK( scrollBar );
1216
1217   // Set the duration to hide the indicator to be 0.15 second
1218   scrollBar.SetIndicatorHideDuration(0.15f);
1219
1220   // Check that the duration to hide the indicator is 0.15 second
1221   DALI_TEST_EQUALS( scrollBar.GetIndicatorHideDuration(), 0.15f, TEST_LOCATION );
1222
1223   // Set the duration to hide the indicator to be 0.65 second
1224   scrollBar.SetIndicatorHideDuration(0.65f);
1225
1226   // Check that the duration to hide the indicator is 0.65 second
1227   DALI_TEST_EQUALS( scrollBar.GetIndicatorHideDuration(), 0.65f, TEST_LOCATION );
1228
1229   END_TEST;
1230 }
1231
1232 int UtcDaliToolkitScrollBarShowIndicatorP(void)
1233 {
1234   ToolkitTestApplication application;
1235
1236   // Create a scroll bar
1237   ScrollBar scrollBar = ScrollBar::New();
1238   DALI_TEST_CHECK( scrollBar );
1239
1240   Stage::GetCurrent().Add( scrollBar );
1241
1242   Actor indicator = scrollBar.GetScrollIndicator();
1243   DALI_TEST_CHECK( indicator );
1244
1245   // Get the default duration to show the indicator
1246   float duration = scrollBar.GetIndicatorShowDuration();
1247
1248   // Check that the default duration is greater than 0
1249   DALI_TEST_CHECK( duration > 0.0f );
1250
1251   // Make the indicator invisible
1252   indicator.SetOpacity(0.0f);
1253
1254   // Render and notify
1255   application.SendNotification();
1256   application.Render();
1257
1258   // Check that the indicator is invisible
1259   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
1260
1261   // Show the indicator
1262   scrollBar.ShowIndicator();
1263
1264   // Wait for the specified duration
1265   Wait(application, duration * 1000);
1266
1267   // Render and notify
1268   application.SendNotification();
1269   application.Render();
1270
1271   // Check that the indicator is now visible
1272   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1273
1274   END_TEST;
1275 }
1276
1277 int UtcDaliToolkitScrollBarShowIndicatorN(void)
1278 {
1279   ToolkitTestApplication application;
1280
1281   // Create a scroll bar
1282   ScrollBar scrollBar = ScrollBar::New();
1283   DALI_TEST_CHECK( scrollBar );
1284
1285   Stage::GetCurrent().Add( scrollBar );
1286
1287   Actor indicator = scrollBar.GetScrollIndicator();
1288   DALI_TEST_CHECK( indicator );
1289
1290   // Make the indicator initially visible
1291   indicator.SetOpacity(1.0f);
1292
1293   // Render and notify
1294   application.SendNotification();
1295   application.Render();
1296
1297   // Check that the indicator is initially visible
1298   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1299
1300   // Get the default duration to show the indicator
1301   float duration = scrollBar.GetIndicatorShowDuration();
1302
1303   // Check that the default duration is greater than 0
1304   DALI_TEST_CHECK( duration > 0.0f );
1305
1306   // Show the indicator
1307   scrollBar.ShowIndicator();
1308
1309   // Render and notify
1310   application.SendNotification();
1311   application.Render();
1312
1313   // Check that the indicator is still visible in the very next frame
1314   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1315
1316   END_TEST;
1317 }
1318
1319 int UtcDaliToolkitScrollBarHideIndicatorP(void)
1320 {
1321   ToolkitTestApplication application;
1322
1323   // Create a scroll bar
1324   ScrollBar scrollBar = ScrollBar::New();
1325   DALI_TEST_CHECK( scrollBar );
1326
1327   Stage::GetCurrent().Add( scrollBar );
1328
1329   Actor indicator = scrollBar.GetScrollIndicator();
1330   DALI_TEST_CHECK( indicator );
1331
1332   // Get the default duration to hide the indicator
1333   float duration = scrollBar.GetIndicatorHideDuration();
1334
1335   // Check that the default duration is greater than 0
1336   DALI_TEST_CHECK( duration > 0.0f );
1337
1338   // Make the indicator visible
1339   indicator.SetOpacity(1.0f);
1340
1341   // Render and notify
1342   application.SendNotification();
1343   application.Render();
1344
1345   // Check that the indicator is visible
1346   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1347
1348   // Hide the indicator
1349   scrollBar.HideIndicator();
1350
1351   // Wait for the specified duration
1352   Wait(application, duration * 1000);
1353
1354   // Render and notify
1355   application.SendNotification();
1356   application.Render();
1357
1358   // Check that the indicator is now invisible
1359   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
1360
1361   END_TEST;
1362 }
1363
1364 int UtcDaliToolkitScrollBarHideIndicatorN(void)
1365 {
1366   ToolkitTestApplication application;
1367
1368   // Create a scroll bar
1369   ScrollBar scrollBar = ScrollBar::New();
1370   DALI_TEST_CHECK( scrollBar );
1371
1372   Stage::GetCurrent().Add( scrollBar );
1373
1374   Actor indicator = scrollBar.GetScrollIndicator();
1375   DALI_TEST_CHECK( indicator );
1376
1377   // Make the indicator initially invisible
1378   indicator.SetOpacity(0.0f);
1379
1380   // Render and notify
1381   application.SendNotification();
1382   application.Render();
1383
1384   // Check that the indicator is initially invisible
1385   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
1386
1387   // Get the default duration to hide the indicator
1388   float duration = scrollBar.GetIndicatorHideDuration();
1389
1390   // Check that the default duration is greater than 0
1391   DALI_TEST_CHECK( duration > 0.0f );
1392
1393   // Hide the indicator
1394   scrollBar.HideIndicator();
1395
1396   // Render and notify
1397   application.SendNotification();
1398   application.Render();
1399
1400   // Check that the indicator is still invisible in the very next frame
1401   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
1402
1403   END_TEST;
1404 }
1405
1406 int UtcDaliToolkitScrollBarActionShowIndicator(void)
1407 {
1408   ToolkitTestApplication application;
1409
1410   // Create a scroll bar
1411   ScrollBar scrollBar = ScrollBar::New();
1412   DALI_TEST_CHECK( scrollBar );
1413
1414   Stage::GetCurrent().Add( scrollBar );
1415
1416   Actor indicator = scrollBar.GetScrollIndicator();
1417   DALI_TEST_CHECK( indicator );
1418
1419   // Get the default duration to hide the indicator
1420   float duration = scrollBar.GetProperty<float>( ScrollBar::Property::INDICATOR_SHOW_DURATION );
1421
1422   // Check that the default duration is greater than 0
1423   DALI_TEST_CHECK( duration > 0.0f );
1424
1425   // Make the indicator invisible
1426   indicator.SetOpacity(0.0f);
1427
1428   // Render and notify
1429   application.SendNotification();
1430   application.Render();
1431
1432   // Check that the indicator is invisible
1433   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
1434
1435   // Do the "ShowIndicator" action
1436   Property::Map emptyMap;
1437   scrollBar.DoAction( "ShowIndicator", emptyMap );
1438
1439   // Wait for the specified duration
1440   Wait(application, duration * 1000);
1441
1442   // Render and notify
1443   application.SendNotification();
1444   application.Render();
1445
1446   // Check that the indicator is now visible
1447   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1448
1449   END_TEST;
1450 }
1451
1452 int UtcDaliToolkitScrollBarActionHideIndicator(void)
1453 {
1454   ToolkitTestApplication application;
1455
1456   // Create a scroll bar
1457   ScrollBar scrollBar = ScrollBar::New();
1458   DALI_TEST_CHECK( scrollBar );
1459
1460   Stage::GetCurrent().Add( scrollBar );
1461
1462   Actor indicator = scrollBar.GetScrollIndicator();
1463   DALI_TEST_CHECK( indicator );
1464
1465   // Get the default duration to hide the indicator
1466   float duration = scrollBar.GetProperty<float>( ScrollBar::Property::INDICATOR_HIDE_DURATION );
1467
1468   // Check that the default duration is greater than 0
1469   DALI_TEST_CHECK( duration > 0.0f );
1470
1471   // Make the indicator visible
1472   indicator.SetOpacity(1.0f);
1473
1474   // Render and notify
1475   application.SendNotification();
1476   application.Render();
1477
1478   // Check that the indicator is visible
1479   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1480
1481   // Do the "HideIndicator" action
1482   Property::Map emptyMap;
1483   scrollBar.DoAction( "HideIndicator", emptyMap );
1484
1485   // Wait for the specified duration
1486   Wait(application, duration * 1000);
1487
1488   // Render and notify
1489   application.SendNotification();
1490   application.Render();
1491
1492   // Check that the indicator is now invisible
1493   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
1494
1495   END_TEST;
1496 }
1497
1498 int UtcDaliToolkitScrollBarActionShowTransientIndicator(void)
1499 {
1500   ToolkitTestApplication application;
1501
1502   // Create a scroll bar
1503   ScrollBar scrollBar = ScrollBar::New();
1504   DALI_TEST_CHECK( scrollBar );
1505
1506   Stage::GetCurrent().Add( scrollBar );
1507
1508   Actor indicator = scrollBar.GetScrollIndicator();
1509   DALI_TEST_CHECK( indicator );
1510
1511   // Get the default duration to hide the indicator
1512   float duration = scrollBar.GetProperty<float>( ScrollBar::Property::INDICATOR_SHOW_DURATION );
1513
1514   // Check that the default duration is greater than 0
1515   DALI_TEST_CHECK( duration > 0.0f );
1516
1517   // Make the indicator invisible
1518   indicator.SetOpacity(0.0f);
1519
1520   // Render and notify
1521   application.SendNotification();
1522   application.Render();
1523
1524   // Check that the indicator is invisible
1525   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
1526
1527   // Do the "ShowIndicator" action
1528   Property::Map emptyMap;
1529   scrollBar.DoAction( "ShowTransientIndicator", emptyMap );
1530
1531   // Wait for the specified duration
1532   Wait(application, duration * 1000);
1533
1534   // Render and notify
1535   application.SendNotification();
1536   application.Render();
1537
1538   // Check that the indicator is now visible
1539   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1540
1541   // Get the default duration to hide the indicator
1542   float hideDuration = scrollBar.GetProperty<float>( ScrollBar::Property::INDICATOR_HIDE_DURATION );
1543   float transientDuration = scrollBar.GetProperty<float>( DevelScrollBar::Property::INDICATOR_TRANSIENT_DURATION );
1544   float totalVisibleDuration = hideDuration + transientDuration;
1545
1546   // Check that the default duration is greater than 0
1547   DALI_TEST_CHECK( totalVisibleDuration > 0.0f );
1548
1549   // Wait for the specified duration
1550   Wait(application, totalVisibleDuration * 1000);
1551
1552   // Render and notify
1553   application.SendNotification();
1554   application.Render();
1555
1556   // Check that the indicator is now invisible
1557   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
1558
1559   END_TEST;
1560 }
1561
1562 int UtcDaliToolkitScrollBarActionShowTransientIndicatorImmediate(void)
1563 {
1564   ToolkitTestApplication application;
1565
1566   // Create a scroll bar
1567   ScrollBar scrollBar = ScrollBar::New();
1568   DALI_TEST_CHECK( scrollBar );
1569
1570   Stage::GetCurrent().Add( scrollBar );
1571
1572   Actor indicator = scrollBar.GetScrollIndicator();
1573   DALI_TEST_CHECK( indicator );
1574
1575   // Make the indicator invisible
1576   indicator.SetOpacity(0.0f);
1577
1578   // Don't use a show animation; the indicator should appear immediately
1579   scrollBar.SetProperty( ScrollBar::Property::INDICATOR_SHOW_DURATION, 0.0f );
1580   float duration = scrollBar.GetProperty<float>( ScrollBar::Property::INDICATOR_SHOW_DURATION );
1581   DALI_TEST_EQUALS( duration, 0.0f, TEST_LOCATION );
1582
1583   // Render and notify
1584   application.SendNotification();
1585   application.Render();
1586
1587   // Do the "ShowIndicator" action
1588   Property::Map emptyMap;
1589   scrollBar.DoAction( "ShowTransientIndicator", emptyMap );
1590
1591   // Wait for the specified duration
1592   Wait(application);
1593
1594   // Render and notify
1595   application.SendNotification();
1596   application.Render();
1597
1598   // Check that the indicator is now visible
1599   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1600
1601   // Get the default duration to hide the indicator
1602   float hideDuration = scrollBar.GetProperty<float>( ScrollBar::Property::INDICATOR_HIDE_DURATION );
1603   float transientDuration = scrollBar.GetProperty<float>( DevelScrollBar::Property::INDICATOR_TRANSIENT_DURATION );
1604   float totalVisibleDuration = hideDuration + transientDuration;
1605
1606   // Check that the default duration is greater than 0
1607   DALI_TEST_CHECK( totalVisibleDuration > 0.0f );
1608
1609   // Wait for the specified duration
1610   Wait(application, totalVisibleDuration * 1000);
1611
1612   // Render and notify
1613   application.SendNotification();
1614   application.Render();
1615
1616   // Check that the indicator is now invisible
1617   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
1618
1619   END_TEST;
1620 }
1621
1622 int UtcDaliToolkitScrollBarActionShowTransientIndicatorDuringHide(void)
1623 {
1624   ToolkitTestApplication application;
1625
1626   // Create a scroll bar
1627   ScrollBar scrollBar = ScrollBar::New();
1628   DALI_TEST_CHECK( scrollBar );
1629
1630   Stage::GetCurrent().Add( scrollBar );
1631
1632   Actor indicator = scrollBar.GetScrollIndicator();
1633   DALI_TEST_CHECK( indicator );
1634
1635   // Get the default duration to hide the indicator
1636   float duration = scrollBar.GetIndicatorHideDuration();
1637
1638   // Check that the default duration is greater than 0
1639   DALI_TEST_CHECK( duration > 0.0f );
1640
1641   // Make the indicator visible
1642   indicator.SetOpacity(1.0f);
1643
1644   // Render and notify
1645   application.SendNotification();
1646   application.Render();
1647
1648   // Check that the indicator is visible
1649   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1650
1651   // Hide the indicator
1652   scrollBar.HideIndicator();
1653
1654   // Wait for half the specified duration
1655   Wait(application, duration * 0.5f * 1000);
1656
1657   // Render and notify
1658   application.SendNotification();
1659   application.Render();
1660
1661   // Check that the indicator is now partially hidden
1662   DALI_TEST_CHECK( indicator.GetCurrentOpacity() < 1.0f );
1663
1664   // Now interrupt the Hide with a DoAction( "ShowTransientIndicator" )
1665
1666   // Get the default duration to hide the indicator
1667   duration = scrollBar.GetProperty<float>( ScrollBar::Property::INDICATOR_SHOW_DURATION );
1668
1669   // Check that the default duration is greater than 0
1670   DALI_TEST_CHECK( duration > 0.0f );
1671
1672   // Do the "ShowIndicator" action
1673   Property::Map emptyMap;
1674   scrollBar.DoAction( "ShowTransientIndicator", emptyMap );
1675
1676   // Wait for the specified duration
1677   Wait(application, duration * 1000);
1678
1679   // Render and notify
1680   application.SendNotification();
1681   application.Render();
1682
1683   // Check that the indicator is now visible
1684   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1685
1686   // Get the default duration to hide the indicator
1687   float hideDuration = scrollBar.GetProperty<float>( ScrollBar::Property::INDICATOR_HIDE_DURATION );
1688   float transientDuration = scrollBar.GetProperty<float>( DevelScrollBar::Property::INDICATOR_TRANSIENT_DURATION );
1689   float totalVisibleDuration = hideDuration + transientDuration;
1690
1691   // Check that the default duration is greater than 0
1692   DALI_TEST_CHECK( totalVisibleDuration > 0.0f );
1693
1694   // Wait for the specified duration
1695   Wait(application, totalVisibleDuration * 1000);
1696
1697   // Render and notify
1698   application.SendNotification();
1699   application.Render();
1700
1701   // Check that the indicator is now invisible
1702   DALI_TEST_EQUALS( indicator.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
1703
1704   END_TEST;
1705 }
1706
1707 int UtcDaliToolkitScrollBarPanFinishedSignalP(void)
1708 {
1709   ToolkitTestApplication application;
1710
1711   // Create a vertical scroll bar
1712   ScrollBar scrollBar = ScrollBar::New(ScrollBar::Vertical);
1713   DALI_TEST_CHECK( scrollBar );
1714
1715   scrollBar.SetParentOrigin(ParentOrigin::TOP_LEFT);
1716   scrollBar.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1717   scrollBar.SetSize(20.0f, 800.0f, 0.0f);
1718
1719   // Set the indicator height to be fixed to 50.0f
1720   scrollBar.SetIndicatorHeightPolicy(Toolkit::ScrollBar::Fixed);
1721   scrollBar.SetIndicatorFixedHeight(50.0f);
1722
1723   Stage::GetCurrent().Add( scrollBar );
1724
1725   // Connect the pan finished signal
1726   ConnectionTracker connectionTracker;
1727   bool panFinished = false;
1728   scrollBar.PanFinishedSignal().Connect( &OnPanFinished );
1729   scrollBar.ConnectSignal( &connectionTracker, "panFinished", CallbackFunctor(&panFinished));
1730
1731   // Render and notify
1732   application.SendNotification();
1733   application.Render();
1734
1735   // Create a source actor that owns the scroll properties required by the scroll bar
1736   Actor sourceActor = Actor::New();
1737   Stage::GetCurrent().Add( sourceActor );
1738
1739   // Register the scroll properties
1740   Property::Index propertyScrollPosition = sourceActor.RegisterProperty( "sourcePosition",  0.0f );
1741   Property::Index propertyMinScrollPosition = sourceActor.RegisterProperty( "sourcePositionMin",   0.0f );
1742   Property::Index propertyMaxScrollPosition = sourceActor.RegisterProperty( "sourcePositionMax",   100.0f );
1743   Property::Index propertyScrollContentSize = sourceActor.RegisterProperty( "sourceContentSize",   500.0f );
1744
1745   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePosition" ), propertyScrollPosition, TEST_LOCATION );
1746   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePositionMin" ), propertyMinScrollPosition, TEST_LOCATION );
1747   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePositionMax" ), propertyMaxScrollPosition, TEST_LOCATION );
1748   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourceContentSize" ), propertyScrollContentSize, TEST_LOCATION );
1749
1750   // Set the source of the scroll position properties.
1751   scrollBar.SetScrollPropertySource(sourceActor, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
1752
1753   // Render and notify
1754   application.SendNotification();
1755   application.Render();
1756
1757   // Perform a swipe gesture on the indicator
1758   PerformGestureSwipe(application, Vector2(1.0f, 1.0f), Vector2(Vector2::YAXIS * 1.0f), 20);
1759   DALI_TEST_EQUALS( gOnPanFinishedCalled, true, TEST_LOCATION );
1760   DALI_TEST_EQUALS( panFinished, true, TEST_LOCATION );
1761
1762   END_TEST;
1763 }
1764
1765 int UtcDaliToolkitScrollBarPanFinishedSignalN(void)
1766 {
1767   ToolkitTestApplication application;
1768
1769   // Create a vertical scroll bar
1770   ScrollBar scrollBar = ScrollBar::New(ScrollBar::Vertical);
1771   DALI_TEST_CHECK( scrollBar );
1772
1773   scrollBar.SetParentOrigin(ParentOrigin::TOP_LEFT);
1774   scrollBar.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1775   scrollBar.SetSize(20.0f, 800.0f, 0.0f);
1776
1777   // Set the indicator height to be fixed to 50.0f
1778   scrollBar.SetIndicatorHeightPolicy(Toolkit::ScrollBar::Fixed);
1779   scrollBar.SetIndicatorFixedHeight(50.0f);
1780
1781   Stage::GetCurrent().Add( scrollBar );
1782
1783   // Connect the pan finished signal
1784   ConnectionTracker connectionTracker;
1785   bool panFinished = false;
1786   scrollBar.PanFinishedSignal().Connect( &OnPanFinished );
1787   scrollBar.ConnectSignal( &connectionTracker, "panFinished", CallbackFunctor(&panFinished));
1788
1789   // Render and notify
1790   application.SendNotification();
1791   application.Render();
1792
1793   // Perform a vertical swipe gesture on the indicator when there is no source object set on the scroll bar
1794   PerformGestureSwipe(application, Vector2(1.0f, 1.0f), Vector2(Vector2::YAXIS * 1.0f), 20);
1795   DALI_TEST_EQUALS( gOnPanFinishedCalled, false, TEST_LOCATION );
1796
1797   // Create a source actor that owns the scroll properties required by the scroll bar
1798   Actor sourceActor = Actor::New();
1799   Stage::GetCurrent().Add( sourceActor );
1800
1801   // Register the scroll properties
1802   Property::Index propertyScrollPosition = sourceActor.RegisterProperty( "sourcePosition",  0.0f );
1803   Property::Index propertyMinScrollPosition = sourceActor.RegisterProperty( "sourcePositionMin",   0.0f );
1804   Property::Index propertyMaxScrollPosition = sourceActor.RegisterProperty( "sourcePositionMax",   100.0f );
1805   Property::Index propertyScrollContentSize = sourceActor.RegisterProperty( "sourceContentSize",   500.0f );
1806
1807   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePosition" ), propertyScrollPosition, TEST_LOCATION );
1808   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePositionMin" ), propertyMinScrollPosition, TEST_LOCATION );
1809   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePositionMax" ), propertyMaxScrollPosition, TEST_LOCATION );
1810   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourceContentSize" ), propertyScrollContentSize, TEST_LOCATION );
1811
1812   // Set the source of the scroll position properties.
1813   scrollBar.SetScrollPropertySource(sourceActor, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
1814
1815   // Render and notify
1816   application.SendNotification();
1817   application.Render();
1818
1819   // Perform a swipe gesture on the scroll bar but not on the indicator
1820   PerformGestureSwipe(application, Vector2(1.0f, 780.0f), Vector2(Vector2::YAXIS * -1.0f), 20);
1821   DALI_TEST_EQUALS( gOnPanFinishedCalled, false, TEST_LOCATION );
1822   DALI_TEST_EQUALS( panFinished, false, TEST_LOCATION );
1823
1824   // Perform a swipe gesture on the indicator
1825   PerformGestureSwipe(application, Vector2(1.0f, 1.0f), Vector2(Vector2::YAXIS * 1.0f), 20);
1826   DALI_TEST_EQUALS( gOnPanFinishedCalled, true, TEST_LOCATION );
1827   DALI_TEST_EQUALS( panFinished, true, TEST_LOCATION );
1828
1829   END_TEST;
1830 }
1831
1832 int UtcDaliToolkitScrollBarScrollPositionIntervalReachedSignalP(void)
1833 {
1834   ToolkitTestApplication application;
1835
1836   // Create a vertical scroll bar
1837   ScrollBar scrollBar = ScrollBar::New(ScrollBar::Vertical);
1838   DALI_TEST_CHECK( scrollBar );
1839
1840   scrollBar.SetParentOrigin(ParentOrigin::TOP_LEFT);
1841   scrollBar.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1842   scrollBar.SetSize(20.0f, 800.0f, 0.0f);
1843
1844   Stage::GetCurrent().Add( scrollBar );
1845   ConnectionTracker connectionTracker;
1846
1847   // Connect to the ScrollPositionIntervalReached signal
1848   bool intervalReached = false;
1849   scrollBar.ScrollPositionIntervalReachedSignal().Connect( &OnScrollPositionIntervalReached );
1850   scrollBar.ConnectSignal( &connectionTracker, "scrollPositionIntervalReached", CallbackFunctor(&intervalReached));
1851
1852   // Render and notify
1853   application.SendNotification();
1854   application.Render();
1855
1856   // Create a source actor that owns the scroll properties required by the scroll bar
1857   Actor sourceActor = Actor::New();
1858   Stage::GetCurrent().Add( sourceActor );
1859
1860   // Register the scroll properties
1861   Property::Index propertyScrollPosition = sourceActor.RegisterProperty( "sourcePosition",  0.0f );
1862   Property::Index propertyMinScrollPosition = sourceActor.RegisterProperty( "sourcePositionMin",   0.0f );
1863   Property::Index propertyMaxScrollPosition = sourceActor.RegisterProperty( "sourcePositionMax",   800.0f );
1864   Property::Index propertyScrollContentSize = sourceActor.RegisterProperty( "sourceContentSize",   2000.0f );
1865
1866   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePosition" ), propertyScrollPosition, TEST_LOCATION );
1867   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePositionMin" ), propertyMinScrollPosition, TEST_LOCATION );
1868   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePositionMax" ), propertyMaxScrollPosition, TEST_LOCATION );
1869   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourceContentSize" ), propertyScrollContentSize, TEST_LOCATION );
1870
1871   // Set the source of the scroll position properties.
1872   scrollBar.SetScrollPropertySource(sourceActor, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
1873
1874   // Render and notify
1875   application.SendNotification();
1876   application.Render();
1877
1878   // Set the values to get notified when the scroll positions of the source actor goes above or below these values
1879   Dali::Vector<float> positionIntervals;
1880   for( size_t i = 0; i != 10; ++i )
1881   {
1882     positionIntervals.PushBack( -80.0f * i ); // should get notified for each 80 pixels
1883   }
1884   scrollBar.SetScrollPositionIntervals(positionIntervals);
1885
1886   // Render and notify
1887   application.SendNotification();
1888   application.Render();
1889
1890   // Reset the flag
1891   gOnScrollPositionIntervalReachedSignalCalled = false;
1892
1893   // Animate the scroll position to cross the specified value
1894   Animation animation = Animation::New(0.1f);
1895   animation.AnimateTo( Property( sourceActor, propertyScrollPosition ), -85.0f );
1896   animation.Play();
1897
1898   // Wait for 0.1 second
1899   Wait(application, 100);
1900
1901   // Check that the signal callback is called
1902   DALI_TEST_EQUALS( gOnScrollPositionIntervalReachedSignalCalled, true, TEST_LOCATION );
1903   DALI_TEST_EQUALS( intervalReached, true, TEST_LOCATION );
1904
1905   // Reset the flag
1906   gOnScrollPositionIntervalReachedSignalCalled = false;
1907   intervalReached = false;
1908
1909   // Rest and clear the animation
1910   animation.Clear();
1911   animation.Reset();
1912
1913   // Animate the scroll position to cross another specified value
1914   animation = Animation::New(0.1f);
1915   animation.AnimateTo( Property( sourceActor, propertyScrollPosition ), -170.0f );
1916   animation.Play();
1917
1918   // Wait for 0.1 second
1919   Wait(application, 100);
1920
1921   // Check that the signal callback is called
1922   DALI_TEST_EQUALS( gOnScrollPositionIntervalReachedSignalCalled, true, TEST_LOCATION );
1923   DALI_TEST_EQUALS( intervalReached, true, TEST_LOCATION );
1924
1925   // Reset the flag
1926   gOnScrollPositionIntervalReachedSignalCalled = false;
1927   intervalReached = false;
1928
1929   // Rest and clear the animation
1930   animation.Clear();
1931   animation.Reset();
1932
1933   // Animate the scroll position back to the previous value
1934   animation = Animation::New(0.1f);
1935   animation.AnimateTo( Property( sourceActor, propertyScrollPosition ), -85.0f );
1936   animation.Play();
1937
1938   // Wait for 0.1 second
1939   Wait(application, 100);
1940
1941   // Check that the signal callback is called
1942   DALI_TEST_EQUALS( gOnScrollPositionIntervalReachedSignalCalled, true, TEST_LOCATION );
1943   DALI_TEST_EQUALS( intervalReached, true, TEST_LOCATION );
1944
1945   END_TEST;
1946 }
1947
1948 int UtcDaliToolkitScrollBarScrollPositionIntervalReachedSignalN(void)
1949 {
1950   ToolkitTestApplication application;
1951
1952   // Create a vertical scroll bar
1953   ScrollBar scrollBar = ScrollBar::New(ScrollBar::Vertical);
1954   DALI_TEST_CHECK( scrollBar );
1955
1956   scrollBar.SetParentOrigin(ParentOrigin::TOP_LEFT);
1957   scrollBar.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1958   scrollBar.SetSize(20.0f, 800.0f, 0.0f);
1959
1960   Stage::GetCurrent().Add( scrollBar );
1961
1962   // Connect to the ScrollPositionIntervalReached signal
1963   scrollBar.ScrollPositionIntervalReachedSignal().Connect( &OnScrollPositionIntervalReached );
1964
1965   // Render and notify
1966   application.SendNotification();
1967   application.Render();
1968
1969   // Create a source actor that owns the scroll properties required by the scroll bar
1970   Actor sourceActor = Actor::New();
1971   Stage::GetCurrent().Add( sourceActor );
1972
1973   // Register the scroll properties
1974   Property::Index propertyScrollPosition = sourceActor.RegisterProperty( "sourcePosition",  0.0f );
1975   Property::Index propertyMinScrollPosition = sourceActor.RegisterProperty( "sourcePositionMin",   0.0f );
1976   Property::Index propertyMaxScrollPosition = sourceActor.RegisterProperty( "sourcePositionMax",   800.0f );
1977   Property::Index propertyScrollContentSize = sourceActor.RegisterProperty( "sourceContentSize",   2000.0f );
1978
1979   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePosition" ), propertyScrollPosition, TEST_LOCATION );
1980   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePositionMin" ), propertyMinScrollPosition, TEST_LOCATION );
1981   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourcePositionMax" ), propertyMaxScrollPosition, TEST_LOCATION );
1982   DALI_TEST_EQUALS( sourceActor.GetPropertyIndex( "sourceContentSize" ), propertyScrollContentSize, TEST_LOCATION );
1983
1984   // Set the source of the scroll position properties.
1985   scrollBar.SetScrollPropertySource(sourceActor, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
1986
1987   // Render and notify
1988   application.SendNotification();
1989   application.Render();
1990
1991   // Set the values to get notified when the scroll positions of the source actor goes above or below these values
1992   Dali::Vector<float> positionIntervals;
1993   for( size_t i = 0; i != 10; ++i )
1994   {
1995     positionIntervals.PushBack( -80.0f * i ); // should get notified for each 80 pixels
1996   }
1997   scrollBar.SetScrollPositionIntervals(positionIntervals);
1998
1999   // Render and notify
2000   application.SendNotification();
2001   application.Render();
2002
2003   // Reset the flag
2004   gOnScrollPositionIntervalReachedSignalCalled = false;
2005
2006   // Animate the scroll position not to cross the specified value
2007   Animation animation = Animation::New(0.1f);
2008   animation.AnimateTo( Property( sourceActor, propertyScrollPosition ), -70.0f );
2009   animation.Play();
2010
2011   // Wait for 0.1 second
2012   Wait(application, 100);
2013
2014   // Check that the signal callback is not called
2015   DALI_TEST_EQUALS( gOnScrollPositionIntervalReachedSignalCalled, false, TEST_LOCATION );
2016
2017   // Rest and clear the animation
2018   animation.Clear();
2019   animation.Reset();
2020
2021   // Animate the scroll position to cross another specified value
2022   animation = Animation::New(0.1f);
2023   animation.AnimateTo( Property( sourceActor, propertyScrollPosition ), -85.0f );
2024   animation.Play();
2025
2026   // Wait for 0.1 second
2027   Wait(application, 100);
2028
2029   // Check that the signal callback is called
2030   DALI_TEST_EQUALS( gOnScrollPositionIntervalReachedSignalCalled, true, TEST_LOCATION );
2031
2032   END_TEST;
2033 }