2 * Copyright (c) 2022 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.
18 #include <dali-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/dali-toolkit.h>
20 #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;
39 static bool gObjectCreatedCallBackCalled;
41 static void TestCallback(BaseHandle handle)
43 gObjectCreatedCallBackCalled = true;
48 int UtcDaliSliderNew(void)
50 ToolkitTestApplication application;
51 tet_infoline(" UtcDaliSliderNew");
53 // Create the Slider actor
56 DALI_TEST_CHECK(!slider);
58 slider = Slider::New();
60 DALI_TEST_CHECK(slider);
62 Slider slider2(slider);
64 DALI_TEST_CHECK(slider2 == slider);
66 //Additional check to ensure object is created by checking if it's registered
67 ObjectRegistry registry = application.GetCore().GetObjectRegistry();
68 DALI_TEST_CHECK(registry);
70 gObjectCreatedCallBackCalled = false;
71 registry.ObjectCreatedSignal().Connect(&TestCallback);
73 Slider slider = Slider::New();
75 DALI_TEST_CHECK(gObjectCreatedCallBackCalled);
79 int UtcDaliSliderCopyConstructor(void)
81 ToolkitTestApplication application;
83 Slider slider = Slider::New();
84 DALI_TEST_CHECK(slider);
87 DALI_TEST_CHECK(copy);
92 int UtcDaliSliderCopyAssignment(void)
94 ToolkitTestApplication application;
96 Slider slider = Slider::New();
97 DALI_TEST_CHECK(slider);
101 DALI_TEST_CHECK(copy);
102 DALI_TEST_EQUALS(slider, copy, TEST_LOCATION);
107 int UtcDaliSliderMoveConstructor(void)
109 ToolkitTestApplication application;
111 Slider slider = Slider::New();
112 DALI_TEST_EQUALS(1, slider.GetBaseObject().ReferenceCount(), TEST_LOCATION);
113 slider.SetProperty(Actor::Property::SENSITIVE, false);
114 DALI_TEST_CHECK(false == slider.GetProperty<bool>(Actor::Property::SENSITIVE));
116 Slider moved = std::move(slider);
117 DALI_TEST_CHECK(moved);
118 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
119 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
120 DALI_TEST_CHECK(!slider);
125 int UtcDaliSliderMoveAssignment(void)
127 ToolkitTestApplication application;
129 Slider slider = Slider::New();
130 DALI_TEST_EQUALS(1, slider.GetBaseObject().ReferenceCount(), TEST_LOCATION);
131 slider.SetProperty(Actor::Property::SENSITIVE, false);
132 DALI_TEST_CHECK(false == slider.GetProperty<bool>(Actor::Property::SENSITIVE));
135 moved = std::move(slider);
136 DALI_TEST_CHECK(moved);
137 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
138 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
139 DALI_TEST_CHECK(!slider);
144 int UtcDaliSliderDestructor(void)
146 ToolkitTestApplication application;
148 Slider* slider = new Slider();
151 DALI_TEST_CHECK(true);
155 int UtcDaliSliderDownCast(void)
157 ToolkitTestApplication application;
159 Handle handle = Slider::New();
161 Slider slider = Slider::DownCast(handle);
163 DALI_TEST_CHECK(slider == handle);
167 static bool gSliderValueChangedCallBackCalled = false;
168 static bool OnSliderValueChanged(Slider slider, float value)
170 gSliderValueChangedCallBackCalled = true;
174 static bool gSliderMarkCallBackCalled = false;
175 static bool OnSliderMark(Slider slider, int value)
177 gSliderMarkCallBackCalled = true;
181 static bool gSliderSlidingFinishedCallBackCalled = false;
182 static bool OnSlidingFinished(Slider slider, float value)
184 gSliderSlidingFinishedCallBackCalled = true;
188 int UtcDaliSliderSignals1(void)
190 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
191 tet_infoline(" UtcDaliSliderSignals1");
193 // Create the Popup actor
194 Slider slider = Slider::New();
195 application.GetScene().Add(slider);
196 slider.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
197 slider.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_LEFT);
198 slider.SetProperty(Actor::Property::SIZE, Vector2(application.GetScene().GetSize().x, 20.0f));
199 slider.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
201 const float MIN_BOUND = 0.0f;
202 const float MAX_BOUND = 1.0f;
203 const int NUM_MARKS = 5;
204 Property::Array marks;
205 for(int i = 0; i < NUM_MARKS; ++i)
207 marks.PushBack(MIN_BOUND + (static_cast<float>(i) / (NUM_MARKS - 1)) * (MAX_BOUND - MIN_BOUND));
209 slider.SetProperty(Slider::Property::MARKS, marks);
210 slider.SetProperty(Slider::Property::MARK_TOLERANCE, 0.1f);
212 slider.ValueChangedSignal().Connect(&OnSliderValueChanged);
213 slider.MarkReachedSignal().Connect(&OnSliderMark);
214 slider.SlidingFinishedSignal().Connect(&OnSlidingFinished);
216 application.SendNotification();
217 application.Render();
219 gSliderValueChangedCallBackCalled = false;
220 gSliderMarkCallBackCalled = false;
221 gSliderSlidingFinishedCallBackCalled = false;
224 Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
225 Integration::Point pointDown;
226 pointDown.SetState(PointState::DOWN);
227 pointDown.SetScreenPosition(Vector2(10.0f, 10.0f));
228 event.AddPoint(pointDown);
230 application.ProcessEvent(event);
231 application.SendNotification();
232 application.Render();
235 for(int i = 0; i < 5; ++i)
237 Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
238 Integration::Point pointMotion;
239 pointMotion.SetState(PointState::MOTION);
240 pointMotion.SetScreenPosition(Vector2(10.0f + i * 10.0f, 10.0f));
241 event.AddPoint(pointMotion);
243 application.ProcessEvent(event);
244 application.SendNotification();
245 application.Render();
249 Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
250 Integration::Point pointUp;
251 pointUp.SetState(PointState::UP);
252 pointUp.SetScreenPosition(Vector2(10.0f, 10.0f));
253 event.AddPoint(pointUp);
255 application.ProcessEvent(event);
256 application.SendNotification();
257 application.Render();
260 DALI_TEST_CHECK(gSliderValueChangedCallBackCalled);
261 DALI_TEST_CHECK(gSliderMarkCallBackCalled);
262 DALI_TEST_CHECK(gSliderSlidingFinishedCallBackCalled);
264 UnparentAndReset(slider);
270 bool gSliderSignal = false;
271 struct SliderSignalFunctor
273 SliderSignalFunctor()
279 gSliderSignal = true;
284 int UtcDaliSliderSignals2(void)
286 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
287 tet_infoline(" UtcDaliSliderSignals1");
289 // Create the Popup actor
290 Slider slider = Slider::New();
291 application.GetScene().Add(slider);
292 slider.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
293 slider.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_LEFT);
294 slider.SetProperty(Actor::Property::SIZE, Vector2(application.GetScene().GetSize().x, 20.0f));
295 slider.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
297 const float MIN_BOUND = 0.0f;
298 const float MAX_BOUND = 1.0f;
299 const int NUM_MARKS = 5;
300 Property::Array marks;
301 for(int i = 0; i < NUM_MARKS; ++i)
303 marks.PushBack(MIN_BOUND + (static_cast<float>(i) / (NUM_MARKS - 1)) * (MAX_BOUND - MIN_BOUND));
305 slider.SetProperty(Slider::Property::MARKS, marks);
306 slider.SetProperty(Slider::Property::MARK_TOLERANCE, 0.1f);
308 gSliderSignal = false;
309 ConnectionTracker* testTracker = new ConnectionTracker();
310 slider.ConnectSignal(testTracker, "valueChanged", SliderSignalFunctor());
312 application.SendNotification();
313 application.Render();
315 gSliderValueChangedCallBackCalled = false;
316 gSliderMarkCallBackCalled = false;
318 Dali::Integration::TouchEvent event;
320 event = Dali::Integration::TouchEvent();
322 Integration::Point pointDown;
323 pointDown.SetState(PointState::DOWN);
324 pointDown.SetScreenPosition(Vector2(10.0f, 10.0f));
325 event.AddPoint(pointDown);
327 for(int i = 0; i < 5; ++i)
329 Integration::Point pointMotion;
330 pointMotion.SetState(PointState::MOTION);
331 pointMotion.SetScreenPosition(Vector2(10.0f + i * 10.0f, 10.0f));
332 event.AddPoint(pointMotion);
335 Integration::Point pointUp;
336 pointUp.SetState(PointState::UP);
337 pointUp.SetScreenPosition(Vector2(10.0f, 10.0f));
338 event.AddPoint(pointUp);
340 application.ProcessEvent(event);
342 application.SendNotification();
343 application.Render();
345 DALI_TEST_CHECK(gSliderSignal);
349 int UtcDaliSetPropertyP(void)
351 ToolkitTestApplication application;
352 tet_infoline("UtcDaliSetPropertyP");
354 Slider slider = Slider::New();
355 slider.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
356 slider.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_LEFT);
357 slider.SetProperty(Actor::Property::SIZE, Vector2(application.GetScene().GetSize().x, 20.0f));
358 slider.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
360 application.GetScene().Add(slider);
361 application.SendNotification();
362 application.Render();
364 slider.SetProperty(Slider::Property::LOWER_BOUND, 1.0f);
365 slider.SetProperty(Slider::Property::UPPER_BOUND, 5.0f);
366 slider.SetProperty(Slider::Property::VALUE, 3.0f);
367 slider.SetProperty(Slider::Property::DISABLED_COLOR, Color::BLACK);
368 slider.SetProperty(Slider::Property::VALUE_PRECISION, 4);
369 slider.SetProperty(Slider::Property::SHOW_POPUP, true);
370 slider.SetProperty(Slider::Property::SHOW_VALUE, true);
371 slider.SetProperty(Slider::Property::MARKS, false);
372 slider.SetProperty(Slider::Property::SNAP_TO_MARKS, false);
373 slider.SetProperty(Slider::Property::MARK_TOLERANCE, 0.5f);
375 float lb = slider.GetProperty<float>(Slider::Property::LOWER_BOUND);
376 DALI_TEST_EQUALS(lb, 1.0f, TEST_LOCATION);
377 float ub = slider.GetProperty<float>(Slider::Property::UPPER_BOUND);
378 DALI_TEST_EQUALS(ub, 5.0f, TEST_LOCATION);
379 float val = slider.GetProperty<float>(Slider::Property::VALUE);
380 DALI_TEST_EQUALS(val, 3.0f, TEST_LOCATION);
381 Vector4 color = slider.GetProperty<Vector4>(Slider::Property::DISABLED_COLOR);
382 DALI_TEST_EQUALS(color, Color::BLACK, TEST_LOCATION);
383 int precision = slider.GetProperty<int>(Slider::Property::VALUE_PRECISION);
384 DALI_TEST_EQUALS(precision, 4, TEST_LOCATION);
385 bool showPopup = slider.GetProperty<bool>(Slider::Property::SHOW_POPUP);
386 DALI_TEST_EQUALS(showPopup, true, TEST_LOCATION);
387 bool showValue = slider.GetProperty<bool>(Slider::Property::SHOW_VALUE);
388 DALI_TEST_EQUALS(showValue, true, TEST_LOCATION);
389 bool marks = slider.GetProperty<bool>(Slider::Property::MARKS);
390 DALI_TEST_EQUALS(marks, false, TEST_LOCATION);
391 bool snapToMarks = slider.GetProperty<bool>(Slider::Property::SNAP_TO_MARKS);
392 DALI_TEST_EQUALS(snapToMarks, false, TEST_LOCATION);
393 float tolerance = slider.GetProperty<float>(Slider::Property::MARK_TOLERANCE);
394 DALI_TEST_EQUALS(tolerance, 0.5f, TEST_LOCATION);
398 map["visualType"] = "IMAGE";
399 map["size"] = Vector2(200, 200);
400 map["url"] = "track2.png";
401 slider.SetProperty(Slider::Property::TRACK_VISUAL, map);
402 map["url"] = "handle2.png";
403 slider.SetProperty(Slider::Property::HANDLE_VISUAL, map);
404 map["url"] = "progress2.png";
405 slider.SetProperty(Slider::Property::PROGRESS_VISUAL, map);
406 map["url"] = "popup2.png";
407 slider.SetProperty(Slider::Property::POPUP_VISUAL, map);
408 map["url"] = "popupArrow2.png";
409 slider.SetProperty(Slider::Property::POPUP_ARROW_VISUAL, map);
411 Property::Value value = slider.GetProperty(Slider::Property::TRACK_VISUAL);
412 Property::Map* resultMap = value.GetMap();
413 DALI_TEST_CHECK(resultMap);
414 Property::Value* url = resultMap->Find("url");
415 DALI_TEST_CHECK(url);
416 DALI_TEST_EQUALS(*url, "track2.png", TEST_LOCATION);
418 value = slider.GetProperty(Slider::Property::HANDLE_VISUAL);
419 resultMap = value.GetMap();
420 DALI_TEST_CHECK(resultMap);
421 url = resultMap->Find("url");
422 DALI_TEST_CHECK(url);
423 DALI_TEST_EQUALS(*url, "handle2.png", TEST_LOCATION);
425 value = slider.GetProperty(Slider::Property::PROGRESS_VISUAL);
426 resultMap = value.GetMap();
427 DALI_TEST_CHECK(resultMap);
428 url = resultMap->Find("url");
429 DALI_TEST_CHECK(url);
430 DALI_TEST_EQUALS(*url, "progress2.png", TEST_LOCATION);
432 value = slider.GetProperty(Slider::Property::POPUP_VISUAL);
433 resultMap = value.GetMap();
434 DALI_TEST_CHECK(resultMap);
435 url = resultMap->Find("url");
436 DALI_TEST_CHECK(url);
437 DALI_TEST_EQUALS(*url, "popup2.png", TEST_LOCATION);
439 value = slider.GetProperty(Slider::Property::POPUP_ARROW_VISUAL);
440 resultMap = value.GetMap();
441 DALI_TEST_CHECK(resultMap);
442 url = resultMap->Find("url");
443 DALI_TEST_CHECK(url);
444 DALI_TEST_EQUALS(*url, "popupArrow2.png", TEST_LOCATION);
447 UnparentAndReset(slider);
451 // DestroyHandleVisualDisplay
452 // CreateValueDisplay
453 // SlidingFinishedSignal()
454 // UpdateSkin disabled
462 // DisplayPopup (with set valueText label)