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>
26 using namespace Dali::Toolkit;
28 void dali_radio_button_startup(void)
30 test_return_value = TET_UNDEF;
33 void dali_radio_button_cleanup(void)
35 test_return_value = TET_PASS;
41 static bool gObjectCreatedCallBackCalled;
43 static void TestCallback(BaseHandle handle)
45 gObjectCreatedCallBackCalled = true;
48 static std::string GetButtonText( Button button )
50 Property::Value value = button.GetProperty( Toolkit::Button::Property::LABEL );
52 Property::Map *labelProperty = value.GetMap();
54 std::string textLabel;
58 Property::Value* value = labelProperty->Find( Toolkit::TextVisual::Property::TEXT );
59 value->Get( textLabel );
67 int UtcDaliRadioButtonConstructorP(void)
69 TestApplication application;
73 DALI_TEST_CHECK( !button );
77 int UtcDaliRadioButtonCopyConstructorP(void)
79 TestApplication application;
81 // Initialize an object, ref count == 1
82 RadioButton button = RadioButton::New();
84 RadioButton copy( button );
85 DALI_TEST_CHECK( copy );
89 int UtcDaliRadioButtonMoveConstructor(void)
91 ToolkitTestApplication application;
93 RadioButton button = RadioButton::New();
94 DALI_TEST_EQUALS( 1, button.GetBaseObject().ReferenceCount(), TEST_LOCATION );
95 DALI_TEST_EQUALS( button.GetProperty<bool>( Button::Property::TOGGLABLE ), true , TEST_LOCATION );
96 button.SetProperty( Button::Property::TOGGLABLE, false );
97 DALI_TEST_EQUALS( button.GetProperty<bool>( Button::Property::TOGGLABLE ), false , TEST_LOCATION );
99 RadioButton moved = std::move( button );
100 DALI_TEST_CHECK( moved );
101 DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
102 DALI_TEST_EQUALS( moved.GetProperty<bool>( Button::Property::TOGGLABLE ), false , TEST_LOCATION );
103 DALI_TEST_CHECK( !button );
108 int UtcDaliRadioButtonAssignmentOperatorP(void)
110 TestApplication application;
112 RadioButton button = RadioButton::New();
114 RadioButton copy( button );
115 DALI_TEST_CHECK( copy );
117 DALI_TEST_CHECK( button == copy );
121 int UtcDaliRadioButtonMoveAssignment(void)
123 ToolkitTestApplication application;
125 RadioButton button = RadioButton::New();
126 DALI_TEST_EQUALS( 1, button.GetBaseObject().ReferenceCount(), TEST_LOCATION );
127 DALI_TEST_EQUALS( button.GetProperty<bool>( Button::Property::TOGGLABLE ), true , TEST_LOCATION );
128 button.SetProperty( Button::Property::TOGGLABLE, false );
129 DALI_TEST_EQUALS( button.GetProperty<bool>( Button::Property::TOGGLABLE ), false , TEST_LOCATION );
132 moved = std::move( button );
133 DALI_TEST_CHECK( moved );
134 DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
135 DALI_TEST_EQUALS( moved.GetProperty<bool>( Button::Property::TOGGLABLE ), false , TEST_LOCATION );
136 DALI_TEST_CHECK( !button );
141 int UtcDaliRadioButtonNewP(void)
143 ToolkitTestApplication application;
144 tet_infoline(" UtcDaliRadioButtonNewP");
146 // Create the Slider actor
147 RadioButton radioButton;
149 DALI_TEST_CHECK( !radioButton );
151 radioButton = RadioButton::New();
153 DALI_TEST_CHECK( radioButton );
155 RadioButton radioButton2(radioButton);
157 DALI_TEST_CHECK( radioButton2 == radioButton );
159 //Additional check to ensure object is created by checking if it's registered
160 ObjectRegistry registry = application.GetCore().GetObjectRegistry();
161 DALI_TEST_CHECK( registry );
163 gObjectCreatedCallBackCalled = false;
164 registry.ObjectCreatedSignal().Connect( &TestCallback );
166 RadioButton radioButton = RadioButton::New();
168 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
172 int UtcDaliRadioButtonDestructorP(void)
174 ToolkitTestApplication application;
176 RadioButton* radioButton = new RadioButton();
179 DALI_TEST_CHECK( true );
183 int UtcDaliRadioButtonDownCast(void)
185 ToolkitTestApplication application;
187 Handle handle = RadioButton::New();
189 RadioButton radioButton = RadioButton::DownCast( handle );
191 DALI_TEST_CHECK( radioButton == handle );
195 int UtcDaliRadioButtonLabelProperty(void)
197 ToolkitTestApplication application;
199 const std::string labelText = "test actor 1";
201 RadioButton radioButton = RadioButton::New();
203 radioButton.SetProperty( Toolkit::Button::Property::LABEL,
204 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
205 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
208 radioButton.SetProperty( Toolkit::Button::Property::LABEL, labelText );
209 DALI_TEST_EQUALS( GetButtonText( radioButton ), labelText, TEST_LOCATION );
212 std::string labelText2 = "test actor 2";
213 radioButton.SetProperty( Toolkit::Button::Property::LABEL, labelText2 );
215 DALI_TEST_EQUALS( GetButtonText( radioButton ), labelText2, TEST_LOCATION );
220 int UtcDaliRadioButtonSelectedProperty(void)
222 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
223 tet_infoline(" UtcDaliRadioButtonSelectedProperty");
225 // Create the RadioButton actor
226 RadioButton radioButton = RadioButton::New();
227 application.GetScene().Add( radioButton );
228 radioButton.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
229 radioButton.SetProperty( Actor::Property::ANCHOR_POINT,ParentOrigin::TOP_LEFT);
230 radioButton.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
233 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
235 // Setting false selected
236 radioButton.SetProperty( Button::Property::SELECTED, false );
237 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
239 // Setting true selected
240 radioButton.SetProperty( Button::Property::SELECTED, true );
241 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == true );
243 // Setting false again
244 radioButton.SetProperty( Button::Property::SELECTED, false );
245 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
247 // Test selecting radio buttons
248 RadioButton radioButton2 = RadioButton::New( "label" );
249 radioButton2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
250 radioButton2.SetProperty( Actor::Property::ANCHOR_POINT,ParentOrigin::TOP_LEFT);
251 radioButton2.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
253 RadioButton radioButton3 = RadioButton::New( "label" );
254 radioButton3.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
255 radioButton3.SetProperty( Actor::Property::ANCHOR_POINT,ParentOrigin::TOP_LEFT);
256 radioButton3.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 40.0f ));
258 Actor radioGroup = Actor::New();
259 application.GetScene().Add( radioGroup );
260 radioGroup.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
261 radioGroup.SetProperty( Actor::Property::ANCHOR_POINT,ParentOrigin::TOP_LEFT);
262 radioGroup.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
263 radioGroup.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0 ) );
265 radioGroup.Add( radioButton2 );
266 radioGroup.Add( radioButton3 );
268 application.SendNotification();
269 application.Render();
271 // Simulate touch events
272 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
273 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
275 // Select first radio
277 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
278 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
280 Dali::Integration::Point pointDown;
281 pointDown.SetState( PointState::DOWN );
282 pointDown.SetScreenPosition( Vector2( 1.0f, 1.0f ) );
284 Dali::Integration::Point pointUp( pointDown );
285 pointUp.SetState( PointState::UP );
287 event1.AddPoint( pointDown );
288 application.ProcessEvent( event1 );
290 event2.AddPoint( pointUp );
291 application.ProcessEvent( event2 );
293 application.SendNotification();
294 application.Render();
296 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == true );
297 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
300 // Select an already selected radio
302 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
303 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
305 Dali::Integration::Point pointDown;
306 pointDown.SetState( PointState::DOWN );
307 pointDown.SetScreenPosition( Vector2( 1.0f, 1.0f ) );
309 Dali::Integration::Point pointUp( pointDown );
310 pointUp.SetState( PointState::UP );
312 event1.AddPoint( pointDown );
313 application.ProcessEvent( event1 );
315 event2.AddPoint( pointUp );
316 application.ProcessEvent( event2 );
318 application.SendNotification();
319 application.Render();
321 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == true );
322 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
325 // Select second radio
327 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
328 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
330 Dali::Integration::Point pointDown;
331 pointDown.SetState( PointState::DOWN );
332 pointDown.SetScreenPosition( Vector2( 1.0f, 41.0f ) );
334 Dali::Integration::Point pointUp( pointDown );
335 pointUp.SetState( PointState::UP );
337 event1.AddPoint( pointDown );
338 application.ProcessEvent( event1 );
340 event2.AddPoint( pointUp );
341 application.ProcessEvent( event2 );
343 application.SendNotification();
344 application.Render();
346 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
347 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == true );
350 // Select outside radio group
352 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
353 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
355 Dali::Integration::Point pointDown;
356 pointDown.SetState( PointState::DOWN );
357 pointDown.SetScreenPosition( Vector2( 1.0f, 500.0f ) );
359 Dali::Integration::Point pointUp( pointDown );
360 pointUp.SetState( PointState::UP );
362 event1.AddPoint( pointDown );
363 application.ProcessEvent( event1 );
365 event2.AddPoint( pointUp );
366 application.ProcessEvent( event2 );
368 application.SendNotification();
369 application.Render();
371 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
372 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == true );