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