2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
26 using namespace Dali::Toolkit;
28 void dali_slider_startup(void)
30 test_return_value = TET_UNDEF;
33 void dali_slider_cleanup(void)
35 test_return_value = TET_PASS;
41 static bool gObjectCreatedCallBackCalled;
43 static void TestCallback(BaseHandle handle)
45 gObjectCreatedCallBackCalled = true;
50 int UtcDaliSliderNew(void)
52 ToolkitTestApplication application;
53 tet_infoline(" UtcDaliSliderNew");
55 // Create the Slider actor
58 DALI_TEST_CHECK( !slider );
60 slider = Slider::New();
62 DALI_TEST_CHECK( slider );
64 Slider slider2(slider);
66 DALI_TEST_CHECK( slider2 == slider );
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 );
72 gObjectCreatedCallBackCalled = false;
73 registry.ObjectCreatedSignal().Connect( &TestCallback );
75 Slider slider = Slider::New();
77 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
81 int UtcDaliSliderDestructor(void)
83 ToolkitTestApplication application;
85 Slider* slider = new Slider();
88 DALI_TEST_CHECK( true );
92 int UtcDaliSliderDownCast(void)
94 ToolkitTestApplication application;
96 Handle handle = Slider::New();
98 Slider slider = Slider::DownCast( handle );
100 DALI_TEST_CHECK( slider == handle );
104 static bool gSliderValueChangedCallBackCalled;
105 static bool OnSliderValueChanged( Slider slider, float value )
107 gSliderValueChangedCallBackCalled = true;
111 static bool gSliderMarkCallBackCalled;
112 static bool OnSliderMark( Slider slider, int value )
114 gSliderMarkCallBackCalled = true;
118 int UtcDaliSliderSignals1(void)
120 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
121 tet_infoline(" UtcDaliSliderSignals1");
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 );
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 )
137 marks.PushBack( MIN_BOUND + ( static_cast<float>(i) / ( NUM_MARKS - 1) ) * ( MAX_BOUND - MIN_BOUND ) );
139 slider.SetProperty( Slider::Property::MARKS, marks );
140 slider.SetProperty( Slider::Property::MARK_TOLERANCE, 0.1f );
142 slider.ValueChangedSignal().Connect( &OnSliderValueChanged );
143 slider.MarkReachedSignal().Connect( &OnSliderMark );
145 application.SendNotification();
146 application.Render();
148 gSliderValueChangedCallBackCalled = false;
149 gSliderMarkCallBackCalled = false;
151 Dali::Integration::TouchEvent event;
153 event = Dali::Integration::TouchEvent();
155 Integration::Point pointDown;
156 pointDown.SetState( PointState::DOWN );
157 pointDown.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
158 event.AddPoint( pointDown );
160 for( int i = 0; i < 5; ++i )
162 Integration::Point pointMotion;
163 pointMotion.SetState( PointState::MOTION );
164 pointMotion.SetScreenPosition( Vector2( 10.0f + i * 10.0f, 10.0f ) );
165 event.AddPoint( pointMotion );
168 Integration::Point pointUp;
169 pointUp.SetState( PointState::UP );
170 pointUp.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
171 event.AddPoint( pointUp );
173 application.ProcessEvent( event );
175 application.SendNotification();
176 application.Render();
178 DALI_TEST_CHECK(gSliderValueChangedCallBackCalled);
179 DALI_TEST_CHECK(gSliderMarkCallBackCalled);
186 bool gSliderSignal=false;
187 struct SliderSignalFunctor
189 SliderSignalFunctor()
195 gSliderSignal = true;
202 int UtcDaliSliderSignals2(void)
204 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
205 tet_infoline(" UtcDaliSliderSignals1");
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 );
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 )
221 marks.PushBack( MIN_BOUND + ( static_cast<float>(i) / ( NUM_MARKS - 1) ) * ( MAX_BOUND - MIN_BOUND ) );
223 slider.SetProperty( Slider::Property::MARKS, marks );
224 slider.SetProperty( Slider::Property::MARK_TOLERANCE, 0.1f );
226 gSliderSignal = false;
227 ConnectionTracker* testTracker = new ConnectionTracker();
228 slider.ConnectSignal( testTracker, "valueChanged", SliderSignalFunctor() );
230 application.SendNotification();
231 application.Render();
233 gSliderValueChangedCallBackCalled = false;
234 gSliderMarkCallBackCalled = false;
236 Dali::Integration::TouchEvent event;
238 event = Dali::Integration::TouchEvent();
240 Integration::Point pointDown;
241 pointDown.SetState( PointState::DOWN );
242 pointDown.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
243 event.AddPoint( pointDown );
245 for( int i = 0; i < 5; ++i )
247 Integration::Point pointMotion;
248 pointMotion.SetState( PointState::MOTION );
249 pointMotion.SetScreenPosition( Vector2( 10.0f + i * 10.0f, 10.0f ) );
250 event.AddPoint( pointMotion );
253 Integration::Point pointUp;
254 pointUp.SetState( PointState::UP );
255 pointUp.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
256 event.AddPoint( pointUp );
258 application.ProcessEvent( event );
260 application.SendNotification();
261 application.Render();
263 DALI_TEST_CHECK(gSliderSignal);
267 int UtcDaliSetPropertyP(void)
269 ToolkitTestApplication application;
270 tet_infoline( "UtcDaliSetPropertyP" );
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 );
278 Stage::GetCurrent().Add(slider);
279 application.SendNotification();
280 application.Render();
282 slider.SetProperty(Slider::Property::LOWER_BOUND, 1.0f);
283 slider.SetProperty(Slider::Property::UPPER_BOUND, 5.0f);
284 slider.SetProperty(Slider::Property::VALUE, 3.0f);
285 slider.SetProperty(Slider::Property::DISABLED_COLOR, Color::BLACK);
286 slider.SetProperty(Slider::Property::VALUE_PRECISION, 4);
287 slider.SetProperty(Slider::Property::SHOW_POPUP, true);
288 slider.SetProperty(Slider::Property::SHOW_VALUE, true);
289 slider.SetProperty(Slider::Property::MARKS, false);
290 slider.SetProperty(Slider::Property::SNAP_TO_MARKS, false);
291 slider.SetProperty(Slider::Property::MARK_TOLERANCE, 0.5f);
293 float lb = slider.GetProperty<float>(Slider::Property::LOWER_BOUND);
294 DALI_TEST_EQUALS(lb, 1.0f, TEST_LOCATION);
295 float ub = slider.GetProperty<float>(Slider::Property::UPPER_BOUND);
296 DALI_TEST_EQUALS(ub, 5.0f, TEST_LOCATION);
297 float val = slider.GetProperty<float>(Slider::Property::VALUE);
298 DALI_TEST_EQUALS(val, 3.0f, TEST_LOCATION);
299 Vector4 color = slider.GetProperty<Vector4>(Slider::Property::DISABLED_COLOR);
300 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
301 int precision = slider.GetProperty<int>(Slider::Property::VALUE_PRECISION);
302 DALI_TEST_EQUALS( precision, 4, TEST_LOCATION);
303 bool showPopup = slider.GetProperty<bool>(Slider::Property::SHOW_POPUP);
304 DALI_TEST_EQUALS( showPopup, true , TEST_LOCATION);
305 bool showValue = slider.GetProperty<bool>(Slider::Property::SHOW_VALUE);
306 DALI_TEST_EQUALS( showValue, true, TEST_LOCATION );
307 bool marks = slider.GetProperty<bool>(Slider::Property::MARKS);
308 DALI_TEST_EQUALS( marks, false, TEST_LOCATION );
309 bool snapToMarks = slider.GetProperty<bool>(Slider::Property::SNAP_TO_MARKS);
310 DALI_TEST_EQUALS( snapToMarks, false, TEST_LOCATION );
311 float tolerance = slider.GetProperty<float>(Slider::Property::MARK_TOLERANCE);
312 DALI_TEST_EQUALS( tolerance, 0.5f, TEST_LOCATION );
316 map["rendererType"] = "image";
317 map["size"] = Vector2(200, 200);
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);
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 );
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 );
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 );
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 );
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 );
369 // DestroyHandleVisualDisplay
370 // CreateValueDisplay
371 // SlidingFinishedSignal()
372 // UpdateSkin disabled
380 // DisplayPopup (with set valueText label)