2 * Copyright (c) 2014 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>
24 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
25 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
28 using namespace Dali::Toolkit;
30 void dali_radio_button_startup(void)
32 test_return_value = TET_UNDEF;
35 void dali_radio_button_cleanup(void)
37 test_return_value = TET_PASS;
43 static bool gObjectCreatedCallBackCalled;
45 static void TestCallback(BaseHandle handle)
47 gObjectCreatedCallBackCalled = true;
50 static std::string GetButtonText( Button button )
52 Property::Value value = button.GetProperty( Toolkit::Button::Property::LABEL );
54 Property::Map *labelProperty = value.GetMap();
56 std::string textLabel;
60 Property::Value* value = labelProperty->Find( Toolkit::TextVisual::Property::TEXT );
61 value->Get( textLabel );
69 int UtcDaliRadioButtonConstructorP(void)
71 TestApplication application;
75 DALI_TEST_CHECK( !button );
79 int UtcDaliRadioButtonCopyConstructorP(void)
81 TestApplication application;
83 // Initialize an object, ref count == 1
84 RadioButton button = RadioButton::New();
86 RadioButton copy( button );
87 DALI_TEST_CHECK( copy );
91 int UtcDaliRadioButtonAssignmentOperatorP(void)
93 TestApplication application;
95 RadioButton button = RadioButton::New();
97 RadioButton copy( button );
98 DALI_TEST_CHECK( copy );
100 DALI_TEST_CHECK( button == copy );
104 int UtcDaliRadioButtonNewP(void)
106 ToolkitTestApplication application;
107 tet_infoline(" UtcDaliRadioButtonNewP");
109 // Create the Slider actor
110 RadioButton radioButton;
112 DALI_TEST_CHECK( !radioButton );
114 radioButton = RadioButton::New();
116 DALI_TEST_CHECK( radioButton );
118 RadioButton radioButton2(radioButton);
120 DALI_TEST_CHECK( radioButton2 == radioButton );
122 //Additional check to ensure object is created by checking if it's registered
123 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
124 DALI_TEST_CHECK( registry );
126 gObjectCreatedCallBackCalled = false;
127 registry.ObjectCreatedSignal().Connect( &TestCallback );
129 RadioButton radioButton = RadioButton::New();
131 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
135 int UtcDaliRadioButtonDestructorP(void)
137 ToolkitTestApplication application;
139 RadioButton* radioButton = new RadioButton();
142 DALI_TEST_CHECK( true );
146 int UtcDaliRadioButtonDownCast(void)
148 ToolkitTestApplication application;
150 Handle handle = RadioButton::New();
152 RadioButton radioButton = RadioButton::DownCast( handle );
154 DALI_TEST_CHECK( radioButton == handle );
158 int UtcDaliRadioButtonLabelProperty(void)
160 ToolkitTestApplication application;
162 const std::string labelText = "test actor 1";
164 RadioButton radioButton = RadioButton::New();
166 radioButton.SetProperty( Toolkit::Button::Property::LABEL,
167 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
168 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
171 radioButton.SetProperty( Toolkit::Button::Property::LABEL, labelText );
172 DALI_TEST_EQUALS( GetButtonText( radioButton ), labelText, TEST_LOCATION );
175 std::string labelText2 = "test actor 2";
176 radioButton.SetProperty( Toolkit::Button::Property::LABEL, labelText2 );
178 DALI_TEST_EQUALS( GetButtonText( radioButton ), labelText2, TEST_LOCATION );
183 int UtcDaliRadioButtonSelectedProperty(void)
185 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
186 tet_infoline(" UtcDaliRadioButtonSelectedProperty");
188 // Create the RadioButton actor
189 RadioButton radioButton = RadioButton::New();
190 Stage::GetCurrent().Add( radioButton );
191 radioButton.SetParentOrigin(ParentOrigin::TOP_LEFT);
192 radioButton.SetAnchorPoint(ParentOrigin::TOP_LEFT);
193 radioButton.SetPosition( 0.0f, 0.0f );
196 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
198 // Setting false selected
199 radioButton.SetProperty( Button::Property::SELECTED, false );
200 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
202 // Setting true selected
203 radioButton.SetProperty( Button::Property::SELECTED, true );
204 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == true );
206 // Setting false again
207 radioButton.SetProperty( Button::Property::SELECTED, false );
208 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
210 // Test selecting radio buttons
211 RadioButton radioButton2 = RadioButton::New( "label" );
212 radioButton2.SetParentOrigin(ParentOrigin::TOP_LEFT);
213 radioButton2.SetAnchorPoint(ParentOrigin::TOP_LEFT);
214 radioButton2.SetPosition( 0.0f, 0.0f );
216 RadioButton radioButton3 = RadioButton::New( "label" );
217 radioButton3.SetParentOrigin(ParentOrigin::TOP_LEFT);
218 radioButton3.SetAnchorPoint(ParentOrigin::TOP_LEFT);
219 radioButton3.SetPosition( 0.0f, 40.0f );
221 Actor radioGroup = Actor::New();
222 Stage::GetCurrent().Add( radioGroup );
223 radioGroup.SetParentOrigin(ParentOrigin::TOP_LEFT);
224 radioGroup.SetAnchorPoint(ParentOrigin::TOP_LEFT);
225 radioGroup.SetPosition( 0.0f, 0.0f );
226 radioGroup.SetSize( 400.0f, 400.0 );
228 radioGroup.Add( radioButton2 );
229 radioGroup.Add( radioButton3 );
231 application.SendNotification();
232 application.Render();
234 // Simulate touch events
235 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
236 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
238 // Select first radio
240 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
241 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
243 Dali::Integration::Point pointDown;
244 pointDown.SetState( PointState::DOWN );
245 pointDown.SetScreenPosition( Vector2( 1.0f, 1.0f ) );
247 Dali::Integration::Point pointUp( pointDown );
248 pointUp.SetState( PointState::UP );
250 event1.AddPoint( pointDown );
251 application.ProcessEvent( event1 );
253 event2.AddPoint( pointUp );
254 application.ProcessEvent( event2 );
256 application.SendNotification();
257 application.Render();
259 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == true );
260 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
263 // Select an already selected radio
265 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
266 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
268 Dali::Integration::Point pointDown;
269 pointDown.SetState( PointState::DOWN );
270 pointDown.SetScreenPosition( Vector2( 1.0f, 1.0f ) );
272 Dali::Integration::Point pointUp( pointDown );
273 pointUp.SetState( PointState::UP );
275 event1.AddPoint( pointDown );
276 application.ProcessEvent( event1 );
278 event2.AddPoint( pointUp );
279 application.ProcessEvent( event2 );
281 application.SendNotification();
282 application.Render();
284 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == true );
285 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
288 // Select second radio
290 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
291 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
293 Dali::Integration::Point pointDown;
294 pointDown.SetState( PointState::DOWN );
295 pointDown.SetScreenPosition( Vector2( 1.0f, 41.0f ) );
297 Dali::Integration::Point pointUp( pointDown );
298 pointUp.SetState( PointState::UP );
300 event1.AddPoint( pointDown );
301 application.ProcessEvent( event1 );
303 event2.AddPoint( pointUp );
304 application.ProcessEvent( event2 );
306 application.SendNotification();
307 application.Render();
309 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
310 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == true );
313 // Select outside radio group
315 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
316 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
318 Dali::Integration::Point pointDown;
319 pointDown.SetState( PointState::DOWN );
320 pointDown.SetScreenPosition( Vector2( 1.0f, 500.0f ) );
322 Dali::Integration::Point pointUp( pointDown );
323 pointUp.SetState( PointState::UP );
325 event1.AddPoint( pointDown );
326 application.ProcessEvent( event1 );
328 event2.AddPoint( pointUp );
329 application.ProcessEvent( event2 );
331 application.SendNotification();
332 application.Render();
334 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
335 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == true );
342 // Deprecated API Tests
344 int UtcDaliRadioButtonLabelActor(void)
346 ToolkitTestApplication application;
348 std::string labelText = "test actor 1";
350 RadioButton radioButton = RadioButton::New();
352 radioButton.SetProperty( Toolkit::Button::Property::LABEL,
353 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
354 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
357 radioButton.SetLabelText( labelText );
359 DALI_TEST_EQUALS( radioButton.GetLabelText(), labelText, TEST_LOCATION );
361 std::string labelText2 = "test actor 2";
362 radioButton.SetLabelText( labelText2 );
363 DALI_TEST_EQUALS( radioButton.GetLabelText(), labelText2, TEST_LOCATION );
368 int UtcDaliRadioButtonSelected(void)
370 ToolkitTestApplication application;
372 RadioButton radioButton = RadioButton::New();
375 DALI_TEST_CHECK( radioButton.IsSelected() == false );
378 radioButton.SetSelected( false );
379 DALI_TEST_CHECK( radioButton.IsSelected() == false );
382 radioButton.SetSelected( true );
383 DALI_TEST_CHECK( radioButton.IsSelected() == true );
386 radioButton.SetSelected( false );
387 DALI_TEST_CHECK( radioButton.IsSelected() == false );