Merge "Fix Svace issue" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Slider.cpp
1 /*
2  * Copyright (c) 2014 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/touch-event-integ.h>
23 #include <dali/integration-api/events/pan-gesture-event.h>
24
25 using namespace Dali;
26 using namespace Dali::Toolkit;
27
28 void dali_slider_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 }
32
33 void dali_slider_cleanup(void)
34 {
35   test_return_value = TET_PASS;
36 }
37
38 namespace
39 {
40
41 static bool gObjectCreatedCallBackCalled;
42
43 static void TestCallback(BaseHandle handle)
44 {
45   gObjectCreatedCallBackCalled = true;
46 }
47
48 }
49
50 int UtcDaliSliderNew(void)
51 {
52   ToolkitTestApplication application;
53   tet_infoline(" UtcDaliSliderNew");
54
55   // Create the Slider actor
56   Slider slider;
57
58   DALI_TEST_CHECK( !slider );
59
60   slider = Slider::New();
61
62   DALI_TEST_CHECK( slider );
63
64   Slider slider2(slider);
65
66   DALI_TEST_CHECK( slider2 == slider );
67
68   //Additional check to ensure object is created by checking if it's registered
69   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
70   DALI_TEST_CHECK( registry );
71
72   gObjectCreatedCallBackCalled = false;
73   registry.ObjectCreatedSignal().Connect( &TestCallback );
74   {
75     Slider slider = Slider::New();
76   }
77   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
78   END_TEST;
79 }
80
81 int UtcDaliSliderDestructor(void)
82 {
83   ToolkitTestApplication application;
84
85   Slider* slider = new Slider();
86   delete slider;
87
88   DALI_TEST_CHECK( true );
89   END_TEST;
90 }
91
92 int UtcDaliSliderDownCast(void)
93 {
94   ToolkitTestApplication application;
95
96   Handle handle = Slider::New();
97
98   Slider slider = Slider::DownCast( handle );
99
100   DALI_TEST_CHECK( slider == handle );
101   END_TEST;
102 }
103
104 static bool gSliderValueChangedCallBackCalled;
105 static bool OnSliderValueChanged( Slider slider, float value )
106 {
107   gSliderValueChangedCallBackCalled = true;
108   return true;
109 }
110
111 static bool gSliderMarkCallBackCalled;
112 static bool OnSliderMark( Slider slider, int value )
113 {
114   gSliderMarkCallBackCalled = true;
115   return true;
116 }
117
118 int UtcDaliSliderSignals1(void)
119 {
120   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
121   tet_infoline(" UtcDaliSliderSignals1");
122
123   // Create the Popup actor
124   Slider slider = Slider::New();
125   Stage::GetCurrent().Add( slider );
126   slider.SetParentOrigin(ParentOrigin::TOP_LEFT);
127   slider.SetAnchorPoint(ParentOrigin::TOP_LEFT);
128   slider.SetSize( Vector2( Stage::GetCurrent().GetSize().x, 20.0f ) );
129   slider.SetPosition( 0.0f, 0.0f );
130
131   const float MIN_BOUND = 0.0f;
132   const float MAX_BOUND = 1.0f;
133   const int NUM_MARKS = 5;
134   Property::Array marks;
135   for( int i = 0; i < NUM_MARKS; ++i )
136   {
137     marks.PushBack( MIN_BOUND + ( static_cast<float>(i) / ( NUM_MARKS - 1) ) * ( MAX_BOUND - MIN_BOUND ) );
138   }
139   slider.SetProperty( Slider::Property::MARKS, marks );
140   slider.SetProperty( Slider::Property::MARK_TOLERANCE, 0.1f );
141
142   slider.ValueChangedSignal().Connect( &OnSliderValueChanged );
143   slider.MarkReachedSignal().Connect( &OnSliderMark );
144
145   application.SendNotification();
146   application.Render();
147
148   gSliderValueChangedCallBackCalled = false;
149   gSliderMarkCallBackCalled = false;
150
151   Dali::Integration::TouchEvent event;
152
153   event = Dali::Integration::TouchEvent();
154
155   Integration::Point pointDown;
156   pointDown.SetState( PointState::DOWN );
157   pointDown.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
158   event.AddPoint( pointDown );
159
160   for( int i = 0; i < 5; ++i )
161   {
162     Integration::Point pointMotion;
163     pointMotion.SetState( PointState::MOTION );
164     pointMotion.SetScreenPosition( Vector2( 10.0f + i * 10.0f, 10.0f ) );
165     event.AddPoint( pointMotion );
166   }
167
168   Integration::Point pointUp;
169   pointUp.SetState( PointState::UP );
170   pointUp.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
171   event.AddPoint( pointUp );
172
173   application.ProcessEvent( event );
174
175   application.SendNotification();
176   application.Render();
177
178   DALI_TEST_CHECK(gSliderValueChangedCallBackCalled);
179   DALI_TEST_CHECK(gSliderMarkCallBackCalled);
180   END_TEST;
181 }
182
183
184 namespace
185 {
186 bool gSliderSignal=false;
187 struct SliderSignalFunctor
188 {
189   SliderSignalFunctor()
190   {
191   }
192
193   void operator()()
194   {
195     gSliderSignal = true;
196   }
197 };
198 } // anonymous
199
200
201
202 int UtcDaliSliderSignals2(void)
203 {
204   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
205   tet_infoline(" UtcDaliSliderSignals1");
206
207   // Create the Popup actor
208   Slider slider = Slider::New();
209   Stage::GetCurrent().Add( slider );
210   slider.SetParentOrigin(ParentOrigin::TOP_LEFT);
211   slider.SetAnchorPoint(ParentOrigin::TOP_LEFT);
212   slider.SetSize( Vector2( Stage::GetCurrent().GetSize().x, 20.0f ) );
213   slider.SetPosition( 0.0f, 0.0f );
214
215   const float MIN_BOUND = 0.0f;
216   const float MAX_BOUND = 1.0f;
217   const int NUM_MARKS = 5;
218   Property::Array marks;
219   for( int i = 0; i < NUM_MARKS; ++i )
220   {
221     marks.PushBack( MIN_BOUND + ( static_cast<float>(i) / ( NUM_MARKS - 1) ) * ( MAX_BOUND - MIN_BOUND ) );
222   }
223   slider.SetProperty( Slider::Property::MARKS, marks );
224   slider.SetProperty( Slider::Property::MARK_TOLERANCE, 0.1f );
225
226   gSliderSignal = false;
227   ConnectionTracker* testTracker = new ConnectionTracker();
228   slider.ConnectSignal( testTracker, "valueChanged",   SliderSignalFunctor() );
229
230   application.SendNotification();
231   application.Render();
232
233   gSliderValueChangedCallBackCalled = false;
234   gSliderMarkCallBackCalled = false;
235
236   Dali::Integration::TouchEvent event;
237
238   event = Dali::Integration::TouchEvent();
239
240   Integration::Point pointDown;
241   pointDown.SetState( PointState::DOWN );
242   pointDown.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
243   event.AddPoint( pointDown );
244
245   for( int i = 0; i < 5; ++i )
246   {
247     Integration::Point pointMotion;
248     pointMotion.SetState( PointState::MOTION );
249     pointMotion.SetScreenPosition( Vector2( 10.0f + i * 10.0f, 10.0f ) );
250     event.AddPoint( pointMotion );
251   }
252
253   Integration::Point pointUp;
254   pointUp.SetState( PointState::UP );
255   pointUp.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
256   event.AddPoint( pointUp );
257
258   application.ProcessEvent( event );
259
260   application.SendNotification();
261   application.Render();
262
263   DALI_TEST_CHECK(gSliderSignal);
264   END_TEST;
265 }
266
267 int UtcDaliSetPropertyP(void)
268 {
269   ToolkitTestApplication application;
270   tet_infoline( "UtcDaliSetPropertyP" );
271
272   Slider slider = Slider::New();
273   slider.SetParentOrigin(ParentOrigin::TOP_LEFT);
274   slider.SetAnchorPoint(ParentOrigin::TOP_LEFT);
275   slider.SetSize( Vector2( Stage::GetCurrent().GetSize().x, 20.0f ) );
276   slider.SetPosition( 0.0f, 0.0f );
277
278   Stage::GetCurrent().Add(slider);
279   application.SendNotification();
280   application.Render();
281
282   Property::Map map;
283   map["rendererType"] = "image";
284   map["url"] = "url";
285   slider.SetProperty(Slider::Property::LOWER_BOUND,        1.0f);
286   slider.SetProperty(Slider::Property::UPPER_BOUND,        5.0f);
287   slider.SetProperty(Slider::Property::VALUE,              3.0f);
288   slider.SetProperty(Slider::Property::DISABLED_COLOR,     Color::BLACK);
289   slider.SetProperty(Slider::Property::VALUE_PRECISION,    4);
290   slider.SetProperty(Slider::Property::SHOW_POPUP,         true);
291   slider.SetProperty(Slider::Property::SHOW_VALUE,         true);
292   slider.SetProperty(Slider::Property::MARKS,              false);
293   slider.SetProperty(Slider::Property::SNAP_TO_MARKS,      false);
294   slider.SetProperty(Slider::Property::MARK_TOLERANCE,     0.5f);
295
296   float lb = slider.GetProperty<float>(Slider::Property::LOWER_BOUND);
297   DALI_TEST_EQUALS(lb, 1.0f, TEST_LOCATION);
298   float ub = slider.GetProperty<float>(Slider::Property::UPPER_BOUND);
299   DALI_TEST_EQUALS(ub, 5.0f, TEST_LOCATION);
300   float val = slider.GetProperty<float>(Slider::Property::VALUE);
301   DALI_TEST_EQUALS(val, 3.0f, TEST_LOCATION);
302   Vector4 color = slider.GetProperty<Vector4>(Slider::Property::DISABLED_COLOR);
303   DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
304   int precision = slider.GetProperty<int>(Slider::Property::VALUE_PRECISION);
305   DALI_TEST_EQUALS( precision, 4, TEST_LOCATION);
306   bool showPopup = slider.GetProperty<bool>(Slider::Property::SHOW_POPUP);
307   DALI_TEST_EQUALS( showPopup, true , TEST_LOCATION);
308   bool showValue = slider.GetProperty<bool>(Slider::Property::SHOW_VALUE);
309   DALI_TEST_EQUALS( showValue, true, TEST_LOCATION );
310   bool marks = slider.GetProperty<bool>(Slider::Property::MARKS);
311   DALI_TEST_EQUALS( marks, false, TEST_LOCATION );
312   bool snapToMarks = slider.GetProperty<bool>(Slider::Property::SNAP_TO_MARKS);
313   DALI_TEST_EQUALS( snapToMarks, false, TEST_LOCATION );
314   float tolerance = slider.GetProperty<float>(Slider::Property::MARK_TOLERANCE);
315   DALI_TEST_EQUALS( tolerance, 0.5f, TEST_LOCATION );
316
317   {
318     map["url"] = "track2.png";
319     slider.SetProperty(Slider::Property::TRACK_VISUAL,       map);
320     map["url"] = "handle2.png";
321     slider.SetProperty(Slider::Property::HANDLE_VISUAL,      map);
322     map["url"] = "progress2.png";
323     slider.SetProperty(Slider::Property::PROGRESS_VISUAL,    map);
324     map["url"] = "popup2.png";
325     slider.SetProperty(Slider::Property::POPUP_VISUAL,       map);
326     map["url"] = "popupArrow2.png";
327     slider.SetProperty(Slider::Property::POPUP_ARROW_VISUAL, map);
328
329     Property::Value value = slider.GetProperty(Slider::Property::TRACK_VISUAL);
330     Property::Map* resultMap = value.GetMap();
331     DALI_TEST_CHECK( resultMap );
332     Property::Value* url = resultMap->Find("url");
333     DALI_TEST_CHECK( url ) ;
334     DALI_TEST_EQUALS( *url, "track2.png", TEST_LOCATION );
335
336     value = slider.GetProperty(Slider::Property::HANDLE_VISUAL);
337     resultMap = value.GetMap();
338     DALI_TEST_CHECK( resultMap );
339     url = resultMap->Find("url");
340     DALI_TEST_CHECK( url ) ;
341     DALI_TEST_EQUALS( *url, "handle2.png", TEST_LOCATION );
342
343     value = slider.GetProperty(Slider::Property::PROGRESS_VISUAL);
344     resultMap = value.GetMap();
345     DALI_TEST_CHECK( resultMap );
346     url = resultMap->Find("url");
347     DALI_TEST_CHECK( url ) ;
348     DALI_TEST_EQUALS( *url, "progress2.png", TEST_LOCATION );
349
350     value = slider.GetProperty(Slider::Property::POPUP_VISUAL);
351     resultMap = value.GetMap();
352     DALI_TEST_CHECK( resultMap );
353     url = resultMap->Find("url");
354     DALI_TEST_CHECK( url ) ;
355     DALI_TEST_EQUALS( *url, "popup2.png", TEST_LOCATION );
356
357     value = slider.GetProperty(Slider::Property::POPUP_ARROW_VISUAL);
358     resultMap = value.GetMap();
359     DALI_TEST_CHECK( resultMap );
360     url = resultMap->Find("url");
361     DALI_TEST_CHECK( url ) ;
362     DALI_TEST_EQUALS( *url, "popupArrow2.png", TEST_LOCATION );
363   }
364
365   END_TEST;
366 }
367
368
369 // DestroyHandleVisualDisplay
370 // CreateValueDisplay
371 // SlidingFinishedSignal()
372 // UpdateSkin disabled
373 // AddPopup
374 // RemovePopup
375 // SnapToMark
376 // HideValueView
377 // GetDisabledColor
378 // GetShowPopup
379 // GetShowVisual
380 // DisplayPopup (with set valueText label)