Merge "Fix documentation for Text::EditableControlInterface interface override functi...
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Slider.cpp
1 /*
2  * Copyright (c) 2020 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
24 using namespace Dali;
25 using namespace Dali::Toolkit;
26
27 void dali_slider_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void dali_slider_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37 namespace
38 {
39
40 static bool gObjectCreatedCallBackCalled;
41
42 static void TestCallback(BaseHandle handle)
43 {
44   gObjectCreatedCallBackCalled = true;
45 }
46
47 }
48
49 int UtcDaliSliderNew(void)
50 {
51   ToolkitTestApplication application;
52   tet_infoline(" UtcDaliSliderNew");
53
54   // Create the Slider actor
55   Slider slider;
56
57   DALI_TEST_CHECK( !slider );
58
59   slider = Slider::New();
60
61   DALI_TEST_CHECK( slider );
62
63   Slider slider2(slider);
64
65   DALI_TEST_CHECK( slider2 == slider );
66
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 );
70
71   gObjectCreatedCallBackCalled = false;
72   registry.ObjectCreatedSignal().Connect( &TestCallback );
73   {
74     Slider slider = Slider::New();
75   }
76   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
77   END_TEST;
78 }
79
80 int UtcDaliSliderCopyConstructor(void)
81 {
82   ToolkitTestApplication application;
83
84   Slider slider = Slider::New();
85   DALI_TEST_CHECK( slider );
86
87   Slider copy( slider );
88   DALI_TEST_CHECK( copy );
89
90   END_TEST;
91 }
92
93 int UtcDaliSliderCopyAssignment(void)
94 {
95   ToolkitTestApplication application;
96
97   Slider slider = Slider::New();
98   DALI_TEST_CHECK( slider );
99
100   Slider copy;
101   copy = slider;
102   DALI_TEST_CHECK( copy );
103   DALI_TEST_EQUALS( slider, copy, TEST_LOCATION );
104
105   END_TEST;
106 }
107
108 int UtcDaliSliderMoveConstructor(void)
109 {
110   ToolkitTestApplication application;
111
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 ) );
116
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 );
122
123   END_TEST;
124 }
125
126 int UtcDaliSliderMoveAssignment(void)
127 {
128   ToolkitTestApplication application;
129
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 ) );
134
135   Slider moved;
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 );
141
142   END_TEST;
143 }
144
145 int UtcDaliSliderDestructor(void)
146 {
147   ToolkitTestApplication application;
148
149   Slider* slider = new Slider();
150   delete slider;
151
152   DALI_TEST_CHECK( true );
153   END_TEST;
154 }
155
156 int UtcDaliSliderDownCast(void)
157 {
158   ToolkitTestApplication application;
159
160   Handle handle = Slider::New();
161
162   Slider slider = Slider::DownCast( handle );
163
164   DALI_TEST_CHECK( slider == handle );
165   END_TEST;
166 }
167
168 static bool gSliderValueChangedCallBackCalled=false;
169 static bool OnSliderValueChanged( Slider slider, float value )
170 {
171   gSliderValueChangedCallBackCalled = true;
172   return true;
173 }
174
175 static bool gSliderMarkCallBackCalled=false;
176 static bool OnSliderMark( Slider slider, int value )
177 {
178   gSliderMarkCallBackCalled = true;
179   return true;
180 }
181
182 static bool gSliderSlidingFinishedCallBackCalled=false;
183 static bool OnSlidingFinished( Slider slider, float value )
184 {
185   gSliderSlidingFinishedCallBackCalled = true;
186   return true;
187 }
188
189 int UtcDaliSliderSignals1(void)
190 {
191   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
192   tet_infoline(" UtcDaliSliderSignals1");
193
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 ));
201
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 )
207   {
208     marks.PushBack( MIN_BOUND + ( static_cast<float>(i) / ( NUM_MARKS - 1) ) * ( MAX_BOUND - MIN_BOUND ) );
209   }
210   slider.SetProperty( Slider::Property::MARKS, marks );
211   slider.SetProperty( Slider::Property::MARK_TOLERANCE, 0.1f );
212
213   slider.ValueChangedSignal().Connect( &OnSliderValueChanged );
214   slider.MarkReachedSignal().Connect( &OnSliderMark );
215   slider.SlidingFinishedSignal().Connect( &OnSlidingFinished );
216
217   application.SendNotification();
218   application.Render();
219
220   gSliderValueChangedCallBackCalled = false;
221   gSliderMarkCallBackCalled = false;
222   gSliderSlidingFinishedCallBackCalled = false;
223
224   {
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 );
230
231     application.ProcessEvent( event );
232     application.SendNotification();
233     application.Render();
234   }
235
236   for( int i = 0; i < 5; ++i )
237   {
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 );
243
244     application.ProcessEvent( event );
245     application.SendNotification();
246     application.Render();
247   }
248
249   {
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 );
255
256     application.ProcessEvent( event );
257     application.SendNotification();
258     application.Render();
259   }
260
261   DALI_TEST_CHECK(gSliderValueChangedCallBackCalled);
262   DALI_TEST_CHECK(gSliderMarkCallBackCalled);
263   DALI_TEST_CHECK(gSliderSlidingFinishedCallBackCalled);
264   END_TEST;
265 }
266
267
268 namespace
269 {
270 bool gSliderSignal=false;
271 struct SliderSignalFunctor
272 {
273   SliderSignalFunctor()
274   {
275   }
276
277   void operator()()
278   {
279     gSliderSignal = true;
280   }
281 };
282 } // anonymous
283
284
285
286 int UtcDaliSliderSignals2(void)
287 {
288   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
289   tet_infoline(" UtcDaliSliderSignals1");
290
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 ));
298
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 )
304   {
305     marks.PushBack( MIN_BOUND + ( static_cast<float>(i) / ( NUM_MARKS - 1) ) * ( MAX_BOUND - MIN_BOUND ) );
306   }
307   slider.SetProperty( Slider::Property::MARKS, marks );
308   slider.SetProperty( Slider::Property::MARK_TOLERANCE, 0.1f );
309
310   gSliderSignal = false;
311   ConnectionTracker* testTracker = new ConnectionTracker();
312   slider.ConnectSignal( testTracker, "valueChanged",   SliderSignalFunctor() );
313
314   application.SendNotification();
315   application.Render();
316
317   gSliderValueChangedCallBackCalled = false;
318   gSliderMarkCallBackCalled = false;
319
320   Dali::Integration::TouchEvent event;
321
322   event = Dali::Integration::TouchEvent();
323
324   Integration::Point pointDown;
325   pointDown.SetState( PointState::DOWN );
326   pointDown.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
327   event.AddPoint( pointDown );
328
329   for( int i = 0; i < 5; ++i )
330   {
331     Integration::Point pointMotion;
332     pointMotion.SetState( PointState::MOTION );
333     pointMotion.SetScreenPosition( Vector2( 10.0f + i * 10.0f, 10.0f ) );
334     event.AddPoint( pointMotion );
335   }
336
337   Integration::Point pointUp;
338   pointUp.SetState( PointState::UP );
339   pointUp.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
340   event.AddPoint( pointUp );
341
342   application.ProcessEvent( event );
343
344   application.SendNotification();
345   application.Render();
346
347   DALI_TEST_CHECK(gSliderSignal);
348   END_TEST;
349 }
350
351 int UtcDaliSetPropertyP(void)
352 {
353   ToolkitTestApplication application;
354   tet_infoline( "UtcDaliSetPropertyP" );
355
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 ));
361
362   application.GetScene().Add(slider);
363   application.SendNotification();
364   application.Render();
365
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);
376
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 );
397
398   {
399     Property::Map map;
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);
412
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 );
419
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 );
426
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 );
433
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 );
440
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 );
447   }
448
449   END_TEST;
450 }
451
452
453 // DestroyHandleVisualDisplay
454 // CreateValueDisplay
455 // SlidingFinishedSignal()
456 // UpdateSkin disabled
457 // AddPopup
458 // RemovePopup
459 // SnapToMark
460 // HideValueView
461 // GetDisabledColor
462 // GetShowPopup
463 // GetShowVisual
464 // DisplayPopup (with set valueText label)