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>
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;
50 int UtcDaliRadioButtonConstructorP(void)
52 TestApplication application;
56 DALI_TEST_CHECK( !button );
60 int UtcDaliRadioButtonCopyConstructorP(void)
62 TestApplication application;
64 // Initialize an object, ref count == 1
65 RadioButton button = RadioButton::New();
67 RadioButton copy( button );
68 DALI_TEST_CHECK( copy );
72 int UtcDaliRadioButtonAssignmentOperatorP(void)
74 TestApplication application;
76 RadioButton button = RadioButton::New();
78 RadioButton copy( button );
79 DALI_TEST_CHECK( copy );
81 DALI_TEST_CHECK( button == copy );
85 int UtcDaliRadioButtonNewP(void)
87 ToolkitTestApplication application;
88 tet_infoline(" UtcDaliRadioButtonNewP");
90 // Create the Slider actor
91 RadioButton radioButton;
93 DALI_TEST_CHECK( !radioButton );
95 radioButton = RadioButton::New();
97 DALI_TEST_CHECK( radioButton );
99 RadioButton radioButton2(radioButton);
101 DALI_TEST_CHECK( radioButton2 == radioButton );
103 //Additional check to ensure object is created by checking if it's registered
104 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
105 DALI_TEST_CHECK( registry );
107 gObjectCreatedCallBackCalled = false;
108 registry.ObjectCreatedSignal().Connect( &TestCallback );
110 RadioButton radioButton = RadioButton::New();
112 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
116 int UtcDaliRadioButtonDestructorP(void)
118 ToolkitTestApplication application;
120 RadioButton* radioButton = new RadioButton();
123 DALI_TEST_CHECK( true );
127 int UtcDaliRadioButtonDownCast(void)
129 ToolkitTestApplication application;
131 Handle handle = RadioButton::New();
133 RadioButton radioButton = RadioButton::DownCast( handle );
135 DALI_TEST_CHECK( radioButton == handle );
139 int UtcDaliRadioButtonLabelActor(void)
141 ToolkitTestApplication application;
143 std::string labelText = "test actor 1";
145 RadioButton radioButton = RadioButton::New( labelText );
146 DALI_TEST_EQUALS( radioButton.GetLabelText(), labelText, TEST_LOCATION );
148 std::string labelText2 = "test actor 2";
149 radioButton.SetLabelText( labelText2 );
150 DALI_TEST_EQUALS( radioButton.GetLabelText(), labelText2, TEST_LOCATION );
155 int UtcDaliRadioButtonSelected(void)
157 ToolkitTestApplication application;
159 RadioButton radioButton = RadioButton::New();
162 DALI_TEST_CHECK( radioButton.IsSelected() == false );
165 radioButton.SetSelected( false );
166 DALI_TEST_CHECK( radioButton.IsSelected() == false );
169 radioButton.SetSelected( true );
170 DALI_TEST_CHECK( radioButton.IsSelected() == true );
173 radioButton.SetSelected( false );
174 DALI_TEST_CHECK( radioButton.IsSelected() == false );
179 int UtcDaliRadioButtonSelectedProperty(void)
181 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
182 tet_infoline(" UtcDaliRadioButtonSelectedProperty");
184 // Create the RadioButton actor
185 RadioButton radioButton = RadioButton::New();
186 Stage::GetCurrent().Add( radioButton );
187 radioButton.SetParentOrigin(ParentOrigin::TOP_LEFT);
188 radioButton.SetAnchorPoint(ParentOrigin::TOP_LEFT);
189 radioButton.SetPosition( 0.0f, 0.0f );
192 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
194 // Setting false selected
195 radioButton.SetProperty( Button::Property::SELECTED, false );
196 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
198 // Setting true selected
199 radioButton.SetProperty( Button::Property::SELECTED, true );
200 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == true );
202 // Setting false again
203 radioButton.SetProperty( Button::Property::SELECTED, false );
204 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
206 // Test selecting radio buttons
207 RadioButton radioButton2 = RadioButton::New( "label" );
208 radioButton2.SetParentOrigin(ParentOrigin::TOP_LEFT);
209 radioButton2.SetAnchorPoint(ParentOrigin::TOP_LEFT);
210 radioButton2.SetPosition( 0.0f, 0.0f );
212 RadioButton radioButton3 = RadioButton::New( "label" );
213 radioButton3.SetParentOrigin(ParentOrigin::TOP_LEFT);
214 radioButton3.SetAnchorPoint(ParentOrigin::TOP_LEFT);
215 radioButton3.SetPosition( 0.0f, 40.0f );
217 Actor radioGroup = Actor::New();
218 Stage::GetCurrent().Add( radioGroup );
219 radioGroup.SetParentOrigin(ParentOrigin::TOP_LEFT);
220 radioGroup.SetAnchorPoint(ParentOrigin::TOP_LEFT);
221 radioGroup.SetPosition( 0.0f, 0.0f );
222 radioGroup.SetSize( 400.0f, 400.0 );
224 radioGroup.Add( radioButton2 );
225 radioGroup.Add( radioButton3 );
227 application.SendNotification();
228 application.Render();
230 // Simulate touch events
231 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
232 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
234 // Select first radio
236 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
237 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
239 Dali::Integration::Point pointDown;
240 pointDown.SetState( PointState::DOWN );
241 pointDown.SetScreenPosition( Vector2( 1.0f, 1.0f ) );
243 Dali::Integration::Point pointUp( pointDown );
244 pointUp.SetState( PointState::UP );
246 event1.AddPoint( pointDown );
247 application.ProcessEvent( event1 );
249 event2.AddPoint( pointUp );
250 application.ProcessEvent( event2 );
252 application.SendNotification();
253 application.Render();
255 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == true );
256 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
259 // Select an already selected radio
261 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
262 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
264 Dali::Integration::Point pointDown;
265 pointDown.SetState( PointState::DOWN );
266 pointDown.SetScreenPosition( Vector2( 1.0f, 1.0f ) );
268 Dali::Integration::Point pointUp( pointDown );
269 pointUp.SetState( PointState::UP );
271 event1.AddPoint( pointDown );
272 application.ProcessEvent( event1 );
274 event2.AddPoint( pointUp );
275 application.ProcessEvent( event2 );
277 application.SendNotification();
278 application.Render();
280 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == true );
281 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
284 // Select second radio
286 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
287 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
289 Dali::Integration::Point pointDown;
290 pointDown.SetState( PointState::DOWN );
291 pointDown.SetScreenPosition( Vector2( 1.0f, 41.0f ) );
293 Dali::Integration::Point pointUp( pointDown );
294 pointUp.SetState( PointState::UP );
296 event1.AddPoint( pointDown );
297 application.ProcessEvent( event1 );
299 event2.AddPoint( pointUp );
300 application.ProcessEvent( event2 );
302 application.SendNotification();
303 application.Render();
305 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
306 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == true );
309 // Select outside radio group
311 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
312 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
314 Dali::Integration::Point pointDown;
315 pointDown.SetState( PointState::DOWN );
316 pointDown.SetScreenPosition( Vector2( 1.0f, 500.0f ) );
318 Dali::Integration::Point pointUp( pointDown );
319 pointUp.SetState( PointState::UP );
321 event1.AddPoint( pointDown );
322 application.ProcessEvent( event1 );
324 event2.AddPoint( pointUp );
325 application.ProcessEvent( event2 );
327 application.SendNotification();
328 application.Render();
330 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
331 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == true );