2 * Copyright (c) 2017 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 UtcDaliRadioButtonAssignmentOperatorP(void)
91 TestApplication application;
93 RadioButton button = RadioButton::New();
95 RadioButton copy( button );
96 DALI_TEST_CHECK( copy );
98 DALI_TEST_CHECK( button == copy );
102 int UtcDaliRadioButtonNewP(void)
104 ToolkitTestApplication application;
105 tet_infoline(" UtcDaliRadioButtonNewP");
107 // Create the Slider actor
108 RadioButton radioButton;
110 DALI_TEST_CHECK( !radioButton );
112 radioButton = RadioButton::New();
114 DALI_TEST_CHECK( radioButton );
116 RadioButton radioButton2(radioButton);
118 DALI_TEST_CHECK( radioButton2 == radioButton );
120 //Additional check to ensure object is created by checking if it's registered
121 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
122 DALI_TEST_CHECK( registry );
124 gObjectCreatedCallBackCalled = false;
125 registry.ObjectCreatedSignal().Connect( &TestCallback );
127 RadioButton radioButton = RadioButton::New();
129 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
133 int UtcDaliRadioButtonDestructorP(void)
135 ToolkitTestApplication application;
137 RadioButton* radioButton = new RadioButton();
140 DALI_TEST_CHECK( true );
144 int UtcDaliRadioButtonDownCast(void)
146 ToolkitTestApplication application;
148 Handle handle = RadioButton::New();
150 RadioButton radioButton = RadioButton::DownCast( handle );
152 DALI_TEST_CHECK( radioButton == handle );
156 int UtcDaliRadioButtonLabelProperty(void)
158 ToolkitTestApplication application;
160 const std::string labelText = "test actor 1";
162 RadioButton radioButton = RadioButton::New();
164 radioButton.SetProperty( Toolkit::Button::Property::LABEL,
165 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
166 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
169 radioButton.SetProperty( Toolkit::Button::Property::LABEL, labelText );
170 DALI_TEST_EQUALS( GetButtonText( radioButton ), labelText, TEST_LOCATION );
173 std::string labelText2 = "test actor 2";
174 radioButton.SetProperty( Toolkit::Button::Property::LABEL, labelText2 );
176 DALI_TEST_EQUALS( GetButtonText( radioButton ), labelText2, TEST_LOCATION );
181 int UtcDaliRadioButtonSelectedProperty(void)
183 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
184 tet_infoline(" UtcDaliRadioButtonSelectedProperty");
186 // Create the RadioButton actor
187 RadioButton radioButton = RadioButton::New();
188 Stage::GetCurrent().Add( radioButton );
189 radioButton.SetParentOrigin(ParentOrigin::TOP_LEFT);
190 radioButton.SetAnchorPoint(ParentOrigin::TOP_LEFT);
191 radioButton.SetPosition( 0.0f, 0.0f );
194 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
196 // Setting false selected
197 radioButton.SetProperty( Button::Property::SELECTED, false );
198 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
200 // Setting true selected
201 radioButton.SetProperty( Button::Property::SELECTED, true );
202 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == true );
204 // Setting false again
205 radioButton.SetProperty( Button::Property::SELECTED, false );
206 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
208 // Test selecting radio buttons
209 RadioButton radioButton2 = RadioButton::New( "label" );
210 radioButton2.SetParentOrigin(ParentOrigin::TOP_LEFT);
211 radioButton2.SetAnchorPoint(ParentOrigin::TOP_LEFT);
212 radioButton2.SetPosition( 0.0f, 0.0f );
214 RadioButton radioButton3 = RadioButton::New( "label" );
215 radioButton3.SetParentOrigin(ParentOrigin::TOP_LEFT);
216 radioButton3.SetAnchorPoint(ParentOrigin::TOP_LEFT);
217 radioButton3.SetPosition( 0.0f, 40.0f );
219 Actor radioGroup = Actor::New();
220 Stage::GetCurrent().Add( radioGroup );
221 radioGroup.SetParentOrigin(ParentOrigin::TOP_LEFT);
222 radioGroup.SetAnchorPoint(ParentOrigin::TOP_LEFT);
223 radioGroup.SetPosition( 0.0f, 0.0f );
224 radioGroup.SetSize( 400.0f, 400.0 );
226 radioGroup.Add( radioButton2 );
227 radioGroup.Add( radioButton3 );
229 application.SendNotification();
230 application.Render();
232 // Simulate touch events
233 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
234 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
236 // Select first radio
238 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
239 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
241 Dali::Integration::Point pointDown;
242 pointDown.SetState( PointState::DOWN );
243 pointDown.SetScreenPosition( Vector2( 1.0f, 1.0f ) );
245 Dali::Integration::Point pointUp( pointDown );
246 pointUp.SetState( PointState::UP );
248 event1.AddPoint( pointDown );
249 application.ProcessEvent( event1 );
251 event2.AddPoint( pointUp );
252 application.ProcessEvent( event2 );
254 application.SendNotification();
255 application.Render();
257 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == true );
258 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
261 // Select an already selected radio
263 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
264 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
266 Dali::Integration::Point pointDown;
267 pointDown.SetState( PointState::DOWN );
268 pointDown.SetScreenPosition( Vector2( 1.0f, 1.0f ) );
270 Dali::Integration::Point pointUp( pointDown );
271 pointUp.SetState( PointState::UP );
273 event1.AddPoint( pointDown );
274 application.ProcessEvent( event1 );
276 event2.AddPoint( pointUp );
277 application.ProcessEvent( event2 );
279 application.SendNotification();
280 application.Render();
282 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == true );
283 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
286 // Select second radio
288 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
289 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
291 Dali::Integration::Point pointDown;
292 pointDown.SetState( PointState::DOWN );
293 pointDown.SetScreenPosition( Vector2( 1.0f, 41.0f ) );
295 Dali::Integration::Point pointUp( pointDown );
296 pointUp.SetState( PointState::UP );
298 event1.AddPoint( pointDown );
299 application.ProcessEvent( event1 );
301 event2.AddPoint( pointUp );
302 application.ProcessEvent( event2 );
304 application.SendNotification();
305 application.Render();
307 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
308 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == true );
311 // Select outside radio group
313 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
314 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
316 Dali::Integration::Point pointDown;
317 pointDown.SetState( PointState::DOWN );
318 pointDown.SetScreenPosition( Vector2( 1.0f, 500.0f ) );
320 Dali::Integration::Point pointUp( pointDown );
321 pointUp.SetState( PointState::UP );
323 event1.AddPoint( pointDown );
324 application.ProcessEvent( event1 );
326 event2.AddPoint( pointUp );
327 application.ProcessEvent( event2 );
329 application.SendNotification();
330 application.Render();
332 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
333 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == true );