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;
52 int UtcDaliRadioButtonConstructorP(void)
54 TestApplication application;
58 DALI_TEST_CHECK( !button );
62 int UtcDaliRadioButtonCopyConstructorP(void)
64 TestApplication application;
66 // Initialize an object, ref count == 1
67 RadioButton button = RadioButton::New();
69 RadioButton copy( button );
70 DALI_TEST_CHECK( copy );
74 int UtcDaliRadioButtonAssignmentOperatorP(void)
76 TestApplication application;
78 RadioButton button = RadioButton::New();
80 RadioButton copy( button );
81 DALI_TEST_CHECK( copy );
83 DALI_TEST_CHECK( button == copy );
87 int UtcDaliRadioButtonNewP(void)
89 ToolkitTestApplication application;
90 tet_infoline(" UtcDaliRadioButtonNewP");
92 // Create the Slider actor
93 RadioButton radioButton;
95 DALI_TEST_CHECK( !radioButton );
97 radioButton = RadioButton::New();
99 DALI_TEST_CHECK( radioButton );
101 RadioButton radioButton2(radioButton);
103 DALI_TEST_CHECK( radioButton2 == radioButton );
105 //Additional check to ensure object is created by checking if it's registered
106 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
107 DALI_TEST_CHECK( registry );
109 gObjectCreatedCallBackCalled = false;
110 registry.ObjectCreatedSignal().Connect( &TestCallback );
112 RadioButton radioButton = RadioButton::New();
114 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
118 int UtcDaliRadioButtonDestructorP(void)
120 ToolkitTestApplication application;
122 RadioButton* radioButton = new RadioButton();
125 DALI_TEST_CHECK( true );
129 int UtcDaliRadioButtonDownCast(void)
131 ToolkitTestApplication application;
133 Handle handle = RadioButton::New();
135 RadioButton radioButton = RadioButton::DownCast( handle );
137 DALI_TEST_CHECK( radioButton == handle );
141 int UtcDaliRadioButtonLabelActor(void)
143 ToolkitTestApplication application;
145 std::string labelText = "test actor 1";
147 RadioButton radioButton = RadioButton::New();
149 radioButton.SetProperty( Toolkit::Button::Property::LABEL,
150 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
151 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
154 radioButton.SetLabelText( labelText );
156 DALI_TEST_EQUALS( radioButton.GetLabelText(), labelText, TEST_LOCATION );
158 std::string labelText2 = "test actor 2";
159 radioButton.SetLabelText( labelText2 );
160 DALI_TEST_EQUALS( radioButton.GetLabelText(), labelText2, TEST_LOCATION );
165 int UtcDaliRadioButtonSelected(void)
167 ToolkitTestApplication application;
169 RadioButton radioButton = RadioButton::New();
172 DALI_TEST_CHECK( radioButton.IsSelected() == false );
175 radioButton.SetSelected( false );
176 DALI_TEST_CHECK( radioButton.IsSelected() == false );
179 radioButton.SetSelected( true );
180 DALI_TEST_CHECK( radioButton.IsSelected() == true );
183 radioButton.SetSelected( false );
184 DALI_TEST_CHECK( radioButton.IsSelected() == false );
189 int UtcDaliRadioButtonSelectedProperty(void)
191 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
192 tet_infoline(" UtcDaliRadioButtonSelectedProperty");
194 // Create the RadioButton actor
195 RadioButton radioButton = RadioButton::New();
196 Stage::GetCurrent().Add( radioButton );
197 radioButton.SetParentOrigin(ParentOrigin::TOP_LEFT);
198 radioButton.SetAnchorPoint(ParentOrigin::TOP_LEFT);
199 radioButton.SetPosition( 0.0f, 0.0f );
202 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
204 // Setting false selected
205 radioButton.SetProperty( Button::Property::SELECTED, false );
206 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
208 // Setting true selected
209 radioButton.SetProperty( Button::Property::SELECTED, true );
210 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == true );
212 // Setting false again
213 radioButton.SetProperty( Button::Property::SELECTED, false );
214 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
216 // Test selecting radio buttons
217 RadioButton radioButton2 = RadioButton::New( "label" );
218 radioButton2.SetParentOrigin(ParentOrigin::TOP_LEFT);
219 radioButton2.SetAnchorPoint(ParentOrigin::TOP_LEFT);
220 radioButton2.SetPosition( 0.0f, 0.0f );
222 RadioButton radioButton3 = RadioButton::New( "label" );
223 radioButton3.SetParentOrigin(ParentOrigin::TOP_LEFT);
224 radioButton3.SetAnchorPoint(ParentOrigin::TOP_LEFT);
225 radioButton3.SetPosition( 0.0f, 40.0f );
227 Actor radioGroup = Actor::New();
228 Stage::GetCurrent().Add( radioGroup );
229 radioGroup.SetParentOrigin(ParentOrigin::TOP_LEFT);
230 radioGroup.SetAnchorPoint(ParentOrigin::TOP_LEFT);
231 radioGroup.SetPosition( 0.0f, 0.0f );
232 radioGroup.SetSize( 400.0f, 400.0 );
234 radioGroup.Add( radioButton2 );
235 radioGroup.Add( radioButton3 );
237 application.SendNotification();
238 application.Render();
240 // Simulate touch events
241 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
242 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
244 // Select first radio
246 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
247 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
249 Dali::Integration::Point pointDown;
250 pointDown.SetState( PointState::DOWN );
251 pointDown.SetScreenPosition( Vector2( 1.0f, 1.0f ) );
253 Dali::Integration::Point pointUp( pointDown );
254 pointUp.SetState( PointState::UP );
256 event1.AddPoint( pointDown );
257 application.ProcessEvent( event1 );
259 event2.AddPoint( pointUp );
260 application.ProcessEvent( event2 );
262 application.SendNotification();
263 application.Render();
265 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == true );
266 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
269 // Select an already selected radio
271 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
272 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
274 Dali::Integration::Point pointDown;
275 pointDown.SetState( PointState::DOWN );
276 pointDown.SetScreenPosition( Vector2( 1.0f, 1.0f ) );
278 Dali::Integration::Point pointUp( pointDown );
279 pointUp.SetState( PointState::UP );
281 event1.AddPoint( pointDown );
282 application.ProcessEvent( event1 );
284 event2.AddPoint( pointUp );
285 application.ProcessEvent( event2 );
287 application.SendNotification();
288 application.Render();
290 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == true );
291 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
294 // Select second radio
296 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
297 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
299 Dali::Integration::Point pointDown;
300 pointDown.SetState( PointState::DOWN );
301 pointDown.SetScreenPosition( Vector2( 1.0f, 41.0f ) );
303 Dali::Integration::Point pointUp( pointDown );
304 pointUp.SetState( PointState::UP );
306 event1.AddPoint( pointDown );
307 application.ProcessEvent( event1 );
309 event2.AddPoint( pointUp );
310 application.ProcessEvent( event2 );
312 application.SendNotification();
313 application.Render();
315 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
316 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == true );
319 // Select outside radio group
321 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
322 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
324 Dali::Integration::Point pointDown;
325 pointDown.SetState( PointState::DOWN );
326 pointDown.SetScreenPosition( Vector2( 1.0f, 500.0f ) );
328 Dali::Integration::Point pointUp( pointDown );
329 pointUp.SetState( PointState::UP );
331 event1.AddPoint( pointDown );
332 application.ProcessEvent( event1 );
334 event2.AddPoint( pointUp );
335 application.ProcessEvent( event2 );
337 application.SendNotification();
338 application.Render();
340 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
341 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == true );