2 * Copyright (c) 2020 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 = application.GetCore().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 UtcDaliSliderCopyConstructor(void)
82 ToolkitTestApplication application;
84 Slider slider = Slider::New();
85 DALI_TEST_CHECK( slider );
87 Slider copy( slider );
88 DALI_TEST_CHECK( copy );
93 int UtcDaliSliderCopyAssignment(void)
95 ToolkitTestApplication application;
97 Slider slider = Slider::New();
98 DALI_TEST_CHECK( slider );
102 DALI_TEST_CHECK( copy );
103 DALI_TEST_EQUALS( slider, copy, TEST_LOCATION );
108 int UtcDaliSliderMoveConstructor(void)
110 ToolkitTestApplication application;
112 Slider slider = Slider::New();
113 DALI_TEST_EQUALS( 1, slider.GetBaseObject().ReferenceCount(), TEST_LOCATION );
114 slider.SetProperty( Actor::Property::SENSITIVE, false );
115 DALI_TEST_CHECK( false == slider.GetProperty< bool >( Actor::Property::SENSITIVE ) );
117 Slider moved = std::move( slider );
118 DALI_TEST_CHECK( moved );
119 DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
120 DALI_TEST_CHECK( false == moved.GetProperty< bool >( Actor::Property::SENSITIVE ) );
121 DALI_TEST_CHECK( !slider );
126 int UtcDaliSliderMoveAssignment(void)
128 ToolkitTestApplication application;
130 Slider slider = Slider::New();
131 DALI_TEST_EQUALS( 1, slider.GetBaseObject().ReferenceCount(), TEST_LOCATION );
132 slider.SetProperty( Actor::Property::SENSITIVE, false );
133 DALI_TEST_CHECK( false == slider.GetProperty< bool >( Actor::Property::SENSITIVE ) );
136 moved = std::move( slider );
137 DALI_TEST_CHECK( moved );
138 DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
139 DALI_TEST_CHECK( false == moved.GetProperty< bool >( Actor::Property::SENSITIVE ) );
140 DALI_TEST_CHECK( !slider );
145 int UtcDaliSliderDestructor(void)
147 ToolkitTestApplication application;
149 Slider* slider = new Slider();
152 DALI_TEST_CHECK( true );
156 int UtcDaliSliderDownCast(void)
158 ToolkitTestApplication application;
160 Handle handle = Slider::New();
162 Slider slider = Slider::DownCast( handle );
164 DALI_TEST_CHECK( slider == handle );
168 static bool gSliderValueChangedCallBackCalled=false;
169 static bool OnSliderValueChanged( Slider slider, float value )
171 gSliderValueChangedCallBackCalled = true;
175 static bool gSliderMarkCallBackCalled=false;
176 static bool OnSliderMark( Slider slider, int value )
178 gSliderMarkCallBackCalled = true;
182 static bool gSliderSlidingFinishedCallBackCalled=false;
183 static bool OnSlidingFinished( Slider slider, float value )
185 gSliderSlidingFinishedCallBackCalled = true;
189 int UtcDaliSliderSignals1(void)
191 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
192 tet_infoline(" UtcDaliSliderSignals1");
194 // Create the Popup actor
195 Slider slider = Slider::New();
196 application.GetScene().Add( slider );
197 slider.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
198 slider.SetProperty( Actor::Property::ANCHOR_POINT,ParentOrigin::TOP_LEFT);
199 slider.SetProperty( Actor::Property::SIZE, Vector2( application.GetScene().GetSize().x, 20.0f ) );
200 slider.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
202 const float MIN_BOUND = 0.0f;
203 const float MAX_BOUND = 1.0f;
204 const int NUM_MARKS = 5;
205 Property::Array marks;
206 for( int i = 0; i < NUM_MARKS; ++i )
208 marks.PushBack( MIN_BOUND + ( static_cast<float>(i) / ( NUM_MARKS - 1) ) * ( MAX_BOUND - MIN_BOUND ) );
210 slider.SetProperty( Slider::Property::MARKS, marks );
211 slider.SetProperty( Slider::Property::MARK_TOLERANCE, 0.1f );
213 slider.ValueChangedSignal().Connect( &OnSliderValueChanged );
214 slider.MarkReachedSignal().Connect( &OnSliderMark );
215 slider.SlidingFinishedSignal().Connect( &OnSlidingFinished );
217 application.SendNotification();
218 application.Render();
220 gSliderValueChangedCallBackCalled = false;
221 gSliderMarkCallBackCalled = false;
222 gSliderSlidingFinishedCallBackCalled = false;
225 Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
226 Integration::Point pointDown;
227 pointDown.SetState( PointState::DOWN );
228 pointDown.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
229 event.AddPoint( pointDown );
231 application.ProcessEvent( event );
232 application.SendNotification();
233 application.Render();
236 for( int i = 0; i < 5; ++i )
238 Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
239 Integration::Point pointMotion;
240 pointMotion.SetState( PointState::MOTION );
241 pointMotion.SetScreenPosition( Vector2( 10.0f + i * 10.0f, 10.0f ) );
242 event.AddPoint( pointMotion );
244 application.ProcessEvent( event );
245 application.SendNotification();
246 application.Render();
250 Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
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 );
257 application.SendNotification();
258 application.Render();
261 DALI_TEST_CHECK(gSliderValueChangedCallBackCalled);
262 DALI_TEST_CHECK(gSliderMarkCallBackCalled);
263 DALI_TEST_CHECK(gSliderSlidingFinishedCallBackCalled);
270 bool gSliderSignal=false;
271 struct SliderSignalFunctor
273 SliderSignalFunctor()
279 gSliderSignal = true;
286 int UtcDaliSliderSignals2(void)
288 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
289 tet_infoline(" UtcDaliSliderSignals1");
291 // Create the Popup actor
292 Slider slider = Slider::New();
293 application.GetScene().Add( slider );
294 slider.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
295 slider.SetProperty( Actor::Property::ANCHOR_POINT,ParentOrigin::TOP_LEFT);
296 slider.SetProperty( Actor::Property::SIZE, Vector2( application.GetScene().GetSize().x, 20.0f ) );
297 slider.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
299 const float MIN_BOUND = 0.0f;
300 const float MAX_BOUND = 1.0f;
301 const int NUM_MARKS = 5;
302 Property::Array marks;
303 for( int i = 0; i < NUM_MARKS; ++i )
305 marks.PushBack( MIN_BOUND + ( static_cast<float>(i) / ( NUM_MARKS - 1) ) * ( MAX_BOUND - MIN_BOUND ) );
307 slider.SetProperty( Slider::Property::MARKS, marks );
308 slider.SetProperty( Slider::Property::MARK_TOLERANCE, 0.1f );
310 gSliderSignal = false;
311 ConnectionTracker* testTracker = new ConnectionTracker();
312 slider.ConnectSignal( testTracker, "valueChanged", SliderSignalFunctor() );
314 application.SendNotification();
315 application.Render();
317 gSliderValueChangedCallBackCalled = false;
318 gSliderMarkCallBackCalled = false;
320 Dali::Integration::TouchEvent event;
322 event = Dali::Integration::TouchEvent();
324 Integration::Point pointDown;
325 pointDown.SetState( PointState::DOWN );
326 pointDown.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
327 event.AddPoint( pointDown );
329 for( int i = 0; i < 5; ++i )
331 Integration::Point pointMotion;
332 pointMotion.SetState( PointState::MOTION );
333 pointMotion.SetScreenPosition( Vector2( 10.0f + i * 10.0f, 10.0f ) );
334 event.AddPoint( pointMotion );
337 Integration::Point pointUp;
338 pointUp.SetState( PointState::UP );
339 pointUp.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
340 event.AddPoint( pointUp );
342 application.ProcessEvent( event );
344 application.SendNotification();
345 application.Render();
347 DALI_TEST_CHECK(gSliderSignal);
351 int UtcDaliSetPropertyP(void)
353 ToolkitTestApplication application;
354 tet_infoline( "UtcDaliSetPropertyP" );
356 Slider slider = Slider::New();
357 slider.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
358 slider.SetProperty( Actor::Property::ANCHOR_POINT,ParentOrigin::TOP_LEFT);
359 slider.SetProperty( Actor::Property::SIZE, Vector2( application.GetScene().GetSize().x, 20.0f ) );
360 slider.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
362 application.GetScene().Add(slider);
363 application.SendNotification();
364 application.Render();
366 slider.SetProperty(Slider::Property::LOWER_BOUND, 1.0f);
367 slider.SetProperty(Slider::Property::UPPER_BOUND, 5.0f);
368 slider.SetProperty(Slider::Property::VALUE, 3.0f);
369 slider.SetProperty(Slider::Property::DISABLED_COLOR, Color::BLACK);
370 slider.SetProperty(Slider::Property::VALUE_PRECISION, 4);
371 slider.SetProperty(Slider::Property::SHOW_POPUP, true);
372 slider.SetProperty(Slider::Property::SHOW_VALUE, true);
373 slider.SetProperty(Slider::Property::MARKS, false);
374 slider.SetProperty(Slider::Property::SNAP_TO_MARKS, false);
375 slider.SetProperty(Slider::Property::MARK_TOLERANCE, 0.5f);
377 float lb = slider.GetProperty<float>(Slider::Property::LOWER_BOUND);
378 DALI_TEST_EQUALS(lb, 1.0f, TEST_LOCATION);
379 float ub = slider.GetProperty<float>(Slider::Property::UPPER_BOUND);
380 DALI_TEST_EQUALS(ub, 5.0f, TEST_LOCATION);
381 float val = slider.GetProperty<float>(Slider::Property::VALUE);
382 DALI_TEST_EQUALS(val, 3.0f, TEST_LOCATION);
383 Vector4 color = slider.GetProperty<Vector4>(Slider::Property::DISABLED_COLOR);
384 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
385 int precision = slider.GetProperty<int>(Slider::Property::VALUE_PRECISION);
386 DALI_TEST_EQUALS( precision, 4, TEST_LOCATION);
387 bool showPopup = slider.GetProperty<bool>(Slider::Property::SHOW_POPUP);
388 DALI_TEST_EQUALS( showPopup, true , TEST_LOCATION);
389 bool showValue = slider.GetProperty<bool>(Slider::Property::SHOW_VALUE);
390 DALI_TEST_EQUALS( showValue, true, TEST_LOCATION );
391 bool marks = slider.GetProperty<bool>(Slider::Property::MARKS);
392 DALI_TEST_EQUALS( marks, false, TEST_LOCATION );
393 bool snapToMarks = slider.GetProperty<bool>(Slider::Property::SNAP_TO_MARKS);
394 DALI_TEST_EQUALS( snapToMarks, false, TEST_LOCATION );
395 float tolerance = slider.GetProperty<float>(Slider::Property::MARK_TOLERANCE);
396 DALI_TEST_EQUALS( tolerance, 0.5f, TEST_LOCATION );
400 map["visualType"] = "IMAGE";
401 map["size"] = Vector2(200, 200);
402 map["url"] = "track2.png";
403 slider.SetProperty(Slider::Property::TRACK_VISUAL, map);
404 map["url"] = "handle2.png";
405 slider.SetProperty(Slider::Property::HANDLE_VISUAL, map);
406 map["url"] = "progress2.png";
407 slider.SetProperty(Slider::Property::PROGRESS_VISUAL, map);
408 map["url"] = "popup2.png";
409 slider.SetProperty(Slider::Property::POPUP_VISUAL, map);
410 map["url"] = "popupArrow2.png";
411 slider.SetProperty(Slider::Property::POPUP_ARROW_VISUAL, map);
413 Property::Value value = slider.GetProperty(Slider::Property::TRACK_VISUAL);
414 Property::Map* resultMap = value.GetMap();
415 DALI_TEST_CHECK( resultMap );
416 Property::Value* url = resultMap->Find("url");
417 DALI_TEST_CHECK( url ) ;
418 DALI_TEST_EQUALS( *url, "track2.png", TEST_LOCATION );
420 value = slider.GetProperty(Slider::Property::HANDLE_VISUAL);
421 resultMap = value.GetMap();
422 DALI_TEST_CHECK( resultMap );
423 url = resultMap->Find("url");
424 DALI_TEST_CHECK( url ) ;
425 DALI_TEST_EQUALS( *url, "handle2.png", TEST_LOCATION );
427 value = slider.GetProperty(Slider::Property::PROGRESS_VISUAL);
428 resultMap = value.GetMap();
429 DALI_TEST_CHECK( resultMap );
430 url = resultMap->Find("url");
431 DALI_TEST_CHECK( url ) ;
432 DALI_TEST_EQUALS( *url, "progress2.png", TEST_LOCATION );
434 value = slider.GetProperty(Slider::Property::POPUP_VISUAL);
435 resultMap = value.GetMap();
436 DALI_TEST_CHECK( resultMap );
437 url = resultMap->Find("url");
438 DALI_TEST_CHECK( url ) ;
439 DALI_TEST_EQUALS( *url, "popup2.png", TEST_LOCATION );
441 value = slider.GetProperty(Slider::Property::POPUP_ARROW_VISUAL);
442 resultMap = value.GetMap();
443 DALI_TEST_CHECK( resultMap );
444 url = resultMap->Find("url");
445 DALI_TEST_CHECK( url ) ;
446 DALI_TEST_EQUALS( *url, "popupArrow2.png", TEST_LOCATION );
453 // DestroyHandleVisualDisplay
454 // CreateValueDisplay
455 // SlidingFinishedSignal()
456 // UpdateSkin disabled
464 // DisplayPopup (with set valueText label)