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>
23 #include <dali-toolkit/devel-api/controls/buttons/toggle-button.h>
27 using namespace Dali::Toolkit;
29 void dali_toggle_button_startup(void)
31 test_return_value = TET_UNDEF;
34 void dali_toggle_button_cleanup(void)
36 test_return_value = TET_PASS;
41 static const char* TEST_IMAGE_ONE = TEST_RESOURCE_DIR "/icon-delete.png";
42 static const char* TEST_IMAGE_TWO = TEST_RESOURCE_DIR "/icon-edit.png";
43 static const char* TEST_IMAGE_THREE = TEST_RESOURCE_DIR "/popup_tail_down.png";
44 static const char* TEST_IMAGE_FOUR = TEST_RESOURCE_DIR "/popup_tail_up.png";
46 static const Vector2 INSIDE_TOUCH_POINT_POSITON = Vector2( 240, 400 );
47 static const Vector3 BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS = Vector3( 200, 360, 0 );
48 static const Size BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS = Size( 100, 100 );
50 static bool gObjectCreatedCallBackCalled;
52 static void TestCallback(BaseHandle handle)
54 gObjectCreatedCallBackCalled = true;
57 Dali::Integration::Point GetPointDownInside()
59 Dali::Integration::Point point;
60 point.SetState( PointState::DOWN );
61 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
65 Dali::Integration::Point GetPointUpInside()
67 Dali::Integration::Point point;
68 point.SetState( PointState::UP );
69 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
75 int UtcDaliToggleButtonConstructorP(void)
77 TestApplication application;
78 tet_infoline(" UtcDaliToggleButtonConstructorP");
81 DALI_TEST_CHECK( !button );
85 int UtcDaliToggleButtonCopyConstructorP(void)
87 TestApplication application;
88 tet_infoline(" UtcDaliToggleButtonCopyConstructorP");
90 // Initialize an object, ref count == 1
91 ToggleButton button = ToggleButton::New();
93 ToggleButton copy( button );
94 DALI_TEST_CHECK( copy );
98 int UtcDaliToggleButtonAssignmentOperatorP(void)
100 TestApplication application;
101 tet_infoline(" UtcDaliToggleButtonAssignmentOperatorP");
103 ToggleButton button = ToggleButton::New();
105 ToggleButton copy( button );
106 DALI_TEST_CHECK( copy );
108 DALI_TEST_CHECK( button == copy );
112 int UtcDaliToggleButtonNewP(void)
114 ToolkitTestApplication application;
115 tet_infoline(" UtcDaliToggleButtonNewP");
117 // Create the Slider actor
118 ToggleButton toggleButton;
120 DALI_TEST_CHECK( !toggleButton );
122 toggleButton = ToggleButton::New();
124 DALI_TEST_CHECK( toggleButton );
126 ToggleButton toggleButton2(toggleButton);
128 DALI_TEST_CHECK( toggleButton2 == toggleButton );
130 //Additional check to ensure object is created by checking if it's registered
131 ObjectRegistry registry = application.GetCore().GetObjectRegistry();
132 DALI_TEST_CHECK( registry );
134 gObjectCreatedCallBackCalled = false;
135 registry.ObjectCreatedSignal().Connect( &TestCallback );
137 ToggleButton toggleButton = ToggleButton::New();
139 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
143 int UtcDaliToggleButtonDestructorP(void)
145 ToolkitTestApplication application;
146 tet_infoline("UtcDaliToggleButtonDestructorP");
148 ToggleButton* toggleButton = new ToggleButton();
151 DALI_TEST_CHECK( true );
155 int UtcDaliToggleButtonDownCast(void)
157 ToolkitTestApplication application;
158 tet_infoline("UtcDaliToggleButtonDownCast");
160 Handle handle = ToggleButton::New();
161 ToggleButton toggleButton = ToggleButton::DownCast( handle );
163 DALI_TEST_CHECK( toggleButton == handle );
167 int UtcDaliToggleButtonToggleStatesProperty(void)
169 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
170 tet_infoline(" UtcDaliToggleButtonToggleStatesProperty");
172 // Create the ToggleButton actor
173 ToggleButton toggleButton = ToggleButton::New();
174 application.GetScene().Add( toggleButton );
175 toggleButton.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
176 toggleButton.SetProperty( Actor::Property::ANCHOR_POINT,ParentOrigin::TOP_LEFT);
177 toggleButton.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
179 {// Check empty array
180 Property::Array toggleIcons;
181 toggleButton.SetProperty( Toolkit::ToggleButton::Property::STATE_VISUALS, toggleIcons );
183 application.SendNotification();
184 application.Render();
186 Property::Array resultIcons;
187 resultIcons = toggleButton.GetProperty( Toolkit::ToggleButton::Property::STATE_VISUALS ).Get<Property::Array>();
188 DALI_TEST_CHECK( resultIcons.Count() == 0 );
191 {// Check non-empty Array
192 Property::Array toggleIcons;
193 toggleIcons.PushBack( TEST_IMAGE_ONE ); //Icons path
194 toggleIcons.PushBack( TEST_IMAGE_TWO );
195 toggleIcons.PushBack( TEST_IMAGE_THREE );
196 toggleIcons.PushBack( TEST_IMAGE_FOUR );
197 toggleButton.SetProperty( Toolkit::ToggleButton::Property::STATE_VISUALS, toggleIcons );
199 application.SendNotification();
200 application.Render();
202 Property::Array resultIcons;
203 resultIcons = toggleButton.GetProperty( Toolkit::ToggleButton::Property::STATE_VISUALS ).Get<Property::Array>();
205 // Check that the result is the same as
206 DALI_TEST_EQUALS( toggleIcons.Count(), resultIcons.Count(), TEST_LOCATION );
207 DALI_TEST_CHECK( toggleIcons[0].Get<std::string>() == resultIcons[0].Get<std::string>() );
208 DALI_TEST_CHECK( toggleIcons[1].Get<std::string>() == resultIcons[1].Get<std::string>() );
209 DALI_TEST_CHECK( toggleIcons[2].Get<std::string>() == resultIcons[2].Get<std::string>() );
210 DALI_TEST_CHECK( toggleIcons[3].Get<std::string>() == resultIcons[3].Get<std::string>() );
213 {// Check property::map
214 Property::Map propertyMap1;
215 Vector4 testColor1( 1.f, 0.5f, 0.3f, 0.2f );
216 propertyMap1.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR);
217 propertyMap1.Insert(Toolkit::ColorVisual::Property::MIX_COLOR, testColor1);
219 Property::Map propertyMap2;
220 Vector4 testColor2( 0.5f, 1.f, 0.3f, 0.2f );
221 propertyMap2.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR);
222 propertyMap2.Insert(Toolkit::ColorVisual::Property::MIX_COLOR, testColor2);
224 Property::Map propertyMap3;
225 Vector4 testColor3( 1.f, 0.5f, 1.f, 0.2f );
226 propertyMap3.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR);
227 propertyMap3.Insert(Toolkit::ColorVisual::Property::MIX_COLOR, testColor3);
229 Property::Array toggleMaps;
230 toggleMaps.Add( propertyMap1 );
231 toggleMaps.Add( propertyMap2 );
232 toggleMaps.Add( propertyMap3 );
233 toggleButton.SetProperty( Toolkit::ToggleButton::Property::STATE_VISUALS, toggleMaps );
235 application.SendNotification();
236 application.Render();
238 Property::Array resultMaps;
239 resultMaps = toggleButton.GetProperty( Toolkit::ToggleButton::Property::STATE_VISUALS ).Get<Property::Array>();
241 // Check that the result
242 DALI_TEST_EQUALS( toggleMaps.Count(), resultMaps.Count(), TEST_LOCATION );
248 int UtcDaliToggleButtonToggleTipsProperty( void )
250 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
251 tet_infoline(" UtcDaliToggleButtonToggleTipsProperty");
253 // Create the ToggleButton actor
254 ToggleButton toggleButton = ToggleButton::New();
255 application.GetScene().Add( toggleButton );
256 toggleButton.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
257 toggleButton.SetProperty( Actor::Property::ANCHOR_POINT,ParentOrigin::TOP_LEFT);
258 toggleButton.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
260 { // Check empty tip array
261 Property::Array toggleIcons;
262 toggleIcons.PushBack( TEST_IMAGE_ONE ); //Icons path
263 toggleIcons.PushBack( TEST_IMAGE_TWO );
264 toggleIcons.PushBack( TEST_IMAGE_THREE );
265 toggleButton.SetProperty( Toolkit::ToggleButton::Property::STATE_VISUALS, toggleIcons );
267 Property::Array toggleTips;
268 toggleButton.SetProperty( Toolkit::ToggleButton::Property::TOOLTIPS, toggleTips );
270 application.SendNotification();
271 application.Render();
273 Property::Array resultTips;
274 resultTips = toggleButton.GetProperty( Toolkit::ToggleButton::Property::TOOLTIPS ).Get<Property::Array>();
275 DALI_TEST_CHECK( resultTips.Count() == 0 );
278 { // Check non-empty tip array
279 Property::Array toggleIcons;
280 toggleIcons.PushBack( TEST_IMAGE_ONE ); //Icons path
281 toggleIcons.PushBack( TEST_IMAGE_TWO );
282 toggleIcons.PushBack( TEST_IMAGE_THREE );
283 toggleButton.SetProperty( Toolkit::ToggleButton::Property::STATE_VISUALS, toggleIcons );
285 Property::Array toggleTips;
286 toggleTips.PushBack( "Button State A" ); //Tooltip string
287 toggleTips.PushBack( "Button State B" );
288 toggleTips.PushBack( "Button State C" );
289 toggleButton.SetProperty( Toolkit::ToggleButton::Property::TOOLTIPS, toggleTips );
291 application.SendNotification();
292 application.Render();
294 Property::Array resultTips;
295 resultTips = toggleButton.GetProperty( Toolkit::ToggleButton::Property::TOOLTIPS ).Get<Property::Array>();
297 //Check that the result is the same as
298 DALI_TEST_EQUALS( toggleTips.Count(), resultTips.Count(), TEST_LOCATION );
299 DALI_TEST_CHECK( toggleTips[0].Get<std::string>() == resultTips[0].Get<std::string>() );
300 DALI_TEST_CHECK( toggleTips[1].Get<std::string>() == resultTips[1].Get<std::string>() );
301 DALI_TEST_CHECK( toggleTips[2].Get<std::string>() == resultTips[2].Get<std::string>() );
302 DALI_TEST_CHECK( toggleTips[3].Get<std::string>() == resultTips[3].Get<std::string>() );
307 int UtcDaliToggleButtonStateChange(void)
309 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
310 tet_infoline(" UtcDaliToggleButtonStateChange");
312 // Create the ToggleButton actor
313 ToggleButton toggleButton = ToggleButton::New();
314 application.GetScene().Add( toggleButton );
315 toggleButton.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
316 toggleButton.SetProperty( Actor::Property::ANCHOR_POINT,ParentOrigin::TOP_LEFT);
317 toggleButton.SetProperty( Actor::Property::POSITION, BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
318 toggleButton.SetProperty( Actor::Property::SIZE, BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
320 Property::Array toggleIcons;
321 toggleIcons.PushBack( TEST_IMAGE_ONE ); //Icons path
322 toggleIcons.PushBack( TEST_IMAGE_TWO );
323 toggleIcons.PushBack( TEST_IMAGE_THREE );
324 toggleButton.SetProperty( Toolkit::ToggleButton::Property::STATE_VISUALS, toggleIcons );
326 Property::Array toggleTips;
327 toggleTips.PushBack( "Button State A" ); //Tooltip string
328 toggleTips.PushBack( "Button State B" );
329 toggleTips.PushBack( "Button State C" );
330 toggleButton.SetProperty( Toolkit::ToggleButton::Property::TOOLTIPS, toggleTips );
332 application.SendNotification();
333 application.Render();
335 Property::Array resultIcons;
336 resultIcons = toggleButton.GetProperty( Toolkit::ToggleButton::Property::STATE_VISUALS ).Get<Property::Array>();
337 DALI_TEST_EQUALS( toggleIcons.Count(), resultIcons.Count(), TEST_LOCATION );
339 Property::Array resultTips;
340 resultTips = toggleButton.GetProperty( Toolkit::ToggleButton::Property::TOOLTIPS ).Get<Property::Array>();
341 DALI_TEST_EQUALS( toggleTips.Count(), resultTips.Count(), TEST_LOCATION );
344 DALI_TEST_CHECK( toggleButton.GetProperty( Toolkit::ToggleButton::Property::CURRENT_STATE_INDEX ).Get( index ) );
345 DALI_TEST_EQUALS( index, 0, TEST_LOCATION );
347 Dali::Integration::TouchEvent event;
349 // Touch point down and up inside the button 3 times.
350 event = Dali::Integration::TouchEvent();
351 event.AddPoint( GetPointDownInside() );
352 application.ProcessEvent( event );
354 event = Dali::Integration::TouchEvent();
355 event.AddPoint( GetPointUpInside() );
356 application.ProcessEvent( event );
358 DALI_TEST_CHECK( toggleButton.GetProperty( Toolkit::ToggleButton::Property::CURRENT_STATE_INDEX ).Get( index ) );
359 DALI_TEST_EQUALS( index, 1, TEST_LOCATION );
361 event = Dali::Integration::TouchEvent();
362 event.AddPoint( GetPointDownInside() );
363 application.ProcessEvent( event );
365 event = Dali::Integration::TouchEvent();
366 event.AddPoint( GetPointUpInside() );
367 application.ProcessEvent( event );
369 DALI_TEST_CHECK( toggleButton.GetProperty( Toolkit::ToggleButton::Property::CURRENT_STATE_INDEX ).Get( index ) );
370 DALI_TEST_EQUALS( index, 2, TEST_LOCATION );
372 event = Dali::Integration::TouchEvent();
373 event.AddPoint( GetPointDownInside() );
374 application.ProcessEvent( event );
376 event = Dali::Integration::TouchEvent();
377 event.AddPoint( GetPointUpInside() );
378 application.ProcessEvent( event );
380 DALI_TEST_CHECK( toggleButton.GetProperty( Toolkit::ToggleButton::Property::CURRENT_STATE_INDEX ).Get( index ) );
381 DALI_TEST_EQUALS( index, 0, TEST_LOCATION );