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>
25 using namespace Dali::Toolkit;
27 void dali_slider_startup(void)
29 test_return_value = TET_UNDEF;
32 void dali_slider_cleanup(void)
34 test_return_value = TET_PASS;
40 static bool gObjectCreatedCallBackCalled;
42 static void TestCallback(BaseHandle handle)
44 gObjectCreatedCallBackCalled = true;
49 int UtcDaliSliderNew(void)
51 ToolkitTestApplication application;
52 tet_infoline(" UtcDaliSliderNew");
54 // Create the Slider actor
57 DALI_TEST_CHECK( !slider );
59 slider = Slider::New();
61 DALI_TEST_CHECK( slider );
63 Slider slider2(slider);
65 DALI_TEST_CHECK( slider2 == slider );
67 //Additional check to ensure object is created by checking if it's registered
68 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
69 DALI_TEST_CHECK( registry );
71 gObjectCreatedCallBackCalled = false;
72 registry.ObjectCreatedSignal().Connect( &TestCallback );
74 Slider slider = Slider::New();
76 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
80 int UtcDaliSliderDestructor(void)
82 ToolkitTestApplication application;
84 Slider* slider = new Slider();
87 DALI_TEST_CHECK( true );
91 int UtcDaliSliderDownCast(void)
93 ToolkitTestApplication application;
95 Handle handle = Slider::New();
97 Slider slider = Slider::DownCast( handle );
99 DALI_TEST_CHECK( slider == handle );
103 static bool gSliderValueChangedCallBackCalled;
104 static bool OnSliderValueChanged( Slider slider, float value )
106 gSliderValueChangedCallBackCalled = true;
110 static bool gSliderMarkCallBackCalled;
111 static bool OnSliderMark( Slider slider, int value )
113 gSliderMarkCallBackCalled = true;
117 int UtcDaliSliderSignals(void)
119 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
120 tet_infoline(" UtcDaliSliderSignals");
122 // Create the Popup actor
123 Slider slider = Slider::New();
124 Stage::GetCurrent().Add( slider );
125 slider.SetParentOrigin(ParentOrigin::TOP_LEFT);
126 slider.SetAnchorPoint(ParentOrigin::TOP_LEFT);
127 slider.SetSize( Vector2( Stage::GetCurrent().GetSize().x, 20.0f ) );
128 slider.SetPosition( 0.0f, 0.0f );
130 const float MIN_BOUND = 0.0f;
131 const float MAX_BOUND = 1.0f;
132 const int NUM_MARKS = 5;
133 Property::Array marks;
134 for( int i = 0; i < NUM_MARKS; ++i )
136 marks.PushBack( MIN_BOUND + ( static_cast<float>(i) / ( NUM_MARKS - 1) ) * ( MAX_BOUND - MIN_BOUND ) );
138 slider.SetProperty( Slider::Property::MARKS, marks );
139 slider.SetProperty( Slider::Property::MARK_TOLERANCE, 0.1f );
141 slider.ValueChangedSignal().Connect( &OnSliderValueChanged );
142 slider.MarkReachedSignal().Connect( &OnSliderMark );
144 application.SendNotification();
145 application.Render();
147 gSliderValueChangedCallBackCalled = false;
148 gSliderMarkCallBackCalled = false;
150 Dali::Integration::TouchEvent event;
152 event = Dali::Integration::TouchEvent();
154 Integration::Point pointDown;
155 pointDown.SetState( PointState::DOWN );
156 pointDown.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
157 event.AddPoint( pointDown );
159 for( int i = 0; i < 5; ++i )
161 Integration::Point pointMotion;
162 pointMotion.SetState( PointState::MOTION );
163 pointMotion.SetScreenPosition( Vector2( 10.0f + i * 10.0f, 10.0f ) );
164 event.AddPoint( pointMotion );
167 Integration::Point pointUp;
168 pointUp.SetState( PointState::UP );
169 pointUp.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
170 event.AddPoint( pointUp );
172 application.ProcessEvent( event );
174 application.SendNotification();
175 application.Render();
177 DALI_TEST_CHECK(gSliderValueChangedCallBackCalled);
178 DALI_TEST_CHECK(gSliderMarkCallBackCalled);
184 bool gSliderSignal=false;
185 struct SliderSignalFunctor
187 SliderSignalFunctor()
193 gSliderSignal = true;
200 int UtcDaliSliderSignals2(void)
202 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
203 tet_infoline(" UtcDaliSliderSignals1");
205 // Create the Popup actor
206 Slider slider = Slider::New();
207 Stage::GetCurrent().Add( slider );
208 slider.SetParentOrigin(ParentOrigin::TOP_LEFT);
209 slider.SetAnchorPoint(ParentOrigin::TOP_LEFT);
210 slider.SetSize( Vector2( Stage::GetCurrent().GetSize().x, 20.0f ) );
211 slider.SetPosition( 0.0f, 0.0f );
213 const float MIN_BOUND = 0.0f;
214 const float MAX_BOUND = 1.0f;
215 const int NUM_MARKS = 5;
216 Property::Array marks;
217 for( int i = 0; i < NUM_MARKS; ++i )
219 marks.PushBack( MIN_BOUND + ( static_cast<float>(i) / ( NUM_MARKS - 1) ) * ( MAX_BOUND - MIN_BOUND ) );
221 slider.SetProperty( Slider::Property::MARKS, marks );
222 slider.SetProperty( Slider::Property::MARK_TOLERANCE, 0.1f );
224 gSliderSignal = false;
225 ConnectionTracker* testTracker = new ConnectionTracker();
226 slider.ConnectSignal( testTracker, "valueChanged", SliderSignalFunctor() );
228 application.SendNotification();
229 application.Render();
231 gSliderValueChangedCallBackCalled = false;
232 gSliderMarkCallBackCalled = false;
234 Dali::Integration::TouchEvent event;
236 event = Dali::Integration::TouchEvent();
238 Integration::Point pointDown;
239 pointDown.SetState( PointState::DOWN );
240 pointDown.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
241 event.AddPoint( pointDown );
243 for( int i = 0; i < 5; ++i )
245 Integration::Point pointMotion;
246 pointMotion.SetState( PointState::MOTION );
247 pointMotion.SetScreenPosition( Vector2( 10.0f + i * 10.0f, 10.0f ) );
248 event.AddPoint( pointMotion );
251 Integration::Point pointUp;
252 pointUp.SetState( PointState::UP );
253 pointUp.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
254 event.AddPoint( pointUp );
256 application.ProcessEvent( event );
258 application.SendNotification();
259 application.Render();
261 DALI_TEST_CHECK(gSliderSignal);
265 int UtcDaliSetPropertyP(void)
267 ToolkitTestApplication application;
268 tet_infoline( "UtcDaliSetPropertyP" );
270 Slider slider = Slider::New();
271 slider.SetParentOrigin(ParentOrigin::TOP_LEFT);
272 slider.SetAnchorPoint(ParentOrigin::TOP_LEFT);
273 slider.SetSize( Vector2( Stage::GetCurrent().GetSize().x, 20.0f ) );
274 slider.SetPosition( 0.0f, 0.0f );
276 Stage::GetCurrent().Add(slider);
277 application.SendNotification();
278 application.Render();
280 slider.SetProperty(Slider::Property::LOWER_BOUND, 1.0f);
281 slider.SetProperty(Slider::Property::UPPER_BOUND, 5.0f);
282 slider.SetProperty(Slider::Property::VALUE, 3.0f);
283 slider.SetProperty(Slider::Property::DISABLED_COLOR, Color::BLACK);
284 slider.SetProperty(Slider::Property::VALUE_PRECISION, 4);
285 slider.SetProperty(Slider::Property::SHOW_POPUP, true);
286 slider.SetProperty(Slider::Property::SHOW_VALUE, true);
287 slider.SetProperty(Slider::Property::MARKS, false);
288 slider.SetProperty(Slider::Property::SNAP_TO_MARKS, false);
289 slider.SetProperty(Slider::Property::MARK_TOLERANCE, 0.5f);
291 float lb = slider.GetProperty<float>(Slider::Property::LOWER_BOUND);
292 DALI_TEST_EQUALS(lb, 1.0f, TEST_LOCATION);
293 float ub = slider.GetProperty<float>(Slider::Property::UPPER_BOUND);
294 DALI_TEST_EQUALS(ub, 5.0f, TEST_LOCATION);
295 float val = slider.GetProperty<float>(Slider::Property::VALUE);
296 DALI_TEST_EQUALS(val, 3.0f, TEST_LOCATION);
297 Vector4 color = slider.GetProperty<Vector4>(Slider::Property::DISABLED_COLOR);
298 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
299 int precision = slider.GetProperty<int>(Slider::Property::VALUE_PRECISION);
300 DALI_TEST_EQUALS( precision, 4, TEST_LOCATION);
301 bool showPopup = slider.GetProperty<bool>(Slider::Property::SHOW_POPUP);
302 DALI_TEST_EQUALS( showPopup, true , TEST_LOCATION);
303 bool showValue = slider.GetProperty<bool>(Slider::Property::SHOW_VALUE);
304 DALI_TEST_EQUALS( showValue, true, TEST_LOCATION );
305 bool marks = slider.GetProperty<bool>(Slider::Property::MARKS);
306 DALI_TEST_EQUALS( marks, false, TEST_LOCATION );
307 bool snapToMarks = slider.GetProperty<bool>(Slider::Property::SNAP_TO_MARKS);
308 DALI_TEST_EQUALS( snapToMarks, false, TEST_LOCATION );
309 float tolerance = slider.GetProperty<float>(Slider::Property::MARK_TOLERANCE);
310 DALI_TEST_EQUALS( tolerance, 0.5f, TEST_LOCATION );
314 map["rendererType"] = "image";
315 map["size"] = Vector2(200, 200);
316 map["url"] = "track2.png";
317 slider.SetProperty(Slider::Property::TRACK_VISUAL, map);
318 map["url"] = "handle2.png";
319 slider.SetProperty(Slider::Property::HANDLE_VISUAL, map);
320 map["url"] = "progress2.png";
321 slider.SetProperty(Slider::Property::PROGRESS_VISUAL, map);
322 map["url"] = "popup2.png";
323 slider.SetProperty(Slider::Property::POPUP_VISUAL, map);
324 map["url"] = "popupArrow2.png";
325 slider.SetProperty(Slider::Property::POPUP_ARROW_VISUAL, map);
327 Property::Value value = slider.GetProperty(Slider::Property::TRACK_VISUAL);
328 Property::Map* resultMap = value.GetMap();
329 DALI_TEST_CHECK( resultMap );
330 Property::Value* url = resultMap->Find("url");
331 DALI_TEST_CHECK( url ) ;
332 DALI_TEST_EQUALS( *url, "track2.png", TEST_LOCATION );
334 value = slider.GetProperty(Slider::Property::HANDLE_VISUAL);
335 resultMap = value.GetMap();
336 DALI_TEST_CHECK( resultMap );
337 url = resultMap->Find("url");
338 DALI_TEST_CHECK( url ) ;
339 DALI_TEST_EQUALS( *url, "handle2.png", TEST_LOCATION );
341 value = slider.GetProperty(Slider::Property::PROGRESS_VISUAL);
342 resultMap = value.GetMap();
343 DALI_TEST_CHECK( resultMap );
344 url = resultMap->Find("url");
345 DALI_TEST_CHECK( url ) ;
346 DALI_TEST_EQUALS( *url, "progress2.png", TEST_LOCATION );
348 value = slider.GetProperty(Slider::Property::POPUP_VISUAL);
349 resultMap = value.GetMap();
350 DALI_TEST_CHECK( resultMap );
351 url = resultMap->Find("url");
352 DALI_TEST_CHECK( url ) ;
353 DALI_TEST_EQUALS( *url, "popup2.png", TEST_LOCATION );
355 value = slider.GetProperty(Slider::Property::POPUP_ARROW_VISUAL);
356 resultMap = value.GetMap();
357 DALI_TEST_CHECK( resultMap );
358 url = resultMap->Find("url");
359 DALI_TEST_CHECK( url ) ;
360 DALI_TEST_EQUALS( *url, "popupArrow2.png", TEST_LOCATION );