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