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 UtcDaliRadioButtonNew(void)
52 ToolkitTestApplication application;
53 tet_infoline(" UtcDaliRadioButtonNew");
55 // Create the Slider actor
56 RadioButton radioButton;
58 DALI_TEST_CHECK( !radioButton );
60 radioButton = RadioButton::New();
62 DALI_TEST_CHECK( radioButton );
64 RadioButton radioButton2(radioButton);
66 DALI_TEST_CHECK( radioButton2 == radioButton );
68 //Additional check to ensure object is created by checking if it's registered
69 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
70 DALI_TEST_CHECK( registry );
72 gObjectCreatedCallBackCalled = false;
73 registry.ObjectCreatedSignal().Connect( &TestCallback );
75 RadioButton radioButton = RadioButton::New();
77 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
81 int UtcDaliRadioButtonDestructor(void)
83 ToolkitTestApplication application;
85 RadioButton* radioButton = new RadioButton();
88 DALI_TEST_CHECK( true );
92 int UtcDaliRadioButtonDownCast(void)
94 ToolkitTestApplication application;
96 Handle handle = RadioButton::New();
98 RadioButton radioButton = RadioButton::DownCast( handle );
100 DALI_TEST_CHECK( radioButton == handle );
104 int UtcDaliRadioButtonLabelActor(void)
110 int UtcDaliRadioButtonSelected(void)
112 ToolkitTestApplication application;
114 RadioButton radioButton = RadioButton::New();
117 DALI_TEST_CHECK( radioButton.IsSelected() == false );
120 radioButton.SetSelected( false );
121 DALI_TEST_CHECK( radioButton.IsSelected() == false );
124 radioButton.SetSelected( true );
125 DALI_TEST_CHECK( radioButton.IsSelected() == true );
128 radioButton.SetSelected( false );
129 DALI_TEST_CHECK( radioButton.IsSelected() == false );
134 int UtcDaliRadioButtonSelectedProperty(void)
136 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
137 tet_infoline(" UtcDaliRadioButtonSelectedProperty");
139 // Create the RadioButton actor
140 RadioButton radioButton = RadioButton::New();
141 Stage::GetCurrent().Add( radioButton );
142 radioButton.SetParentOrigin(ParentOrigin::TOP_LEFT);
143 radioButton.SetAnchorPoint(ParentOrigin::TOP_LEFT);
144 radioButton.SetPosition( 0.0f, 0.0f );
147 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::PROPERTY_SELECTED ) == false );
149 // Setting false selected
150 radioButton.SetProperty( Button::PROPERTY_SELECTED, false );
151 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::PROPERTY_SELECTED ) == false );
153 // Setting true selected
154 radioButton.SetProperty( Button::PROPERTY_SELECTED, true );
155 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::PROPERTY_SELECTED ) == true );
157 // Setting false again
158 radioButton.SetProperty( Button::PROPERTY_SELECTED, false );
159 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::PROPERTY_SELECTED ) == false );
161 // Test selecting radio buttons
162 RadioButton radioButton2 = RadioButton::New( "label" );
163 radioButton2.SetParentOrigin(ParentOrigin::TOP_LEFT);
164 radioButton2.SetAnchorPoint(ParentOrigin::TOP_LEFT);
165 radioButton2.SetPosition( 0.0f, 0.0f );
167 RadioButton radioButton3 = RadioButton::New( "label" );
168 radioButton3.SetParentOrigin(ParentOrigin::TOP_LEFT);
169 radioButton3.SetAnchorPoint(ParentOrigin::TOP_LEFT);
170 radioButton3.SetPosition( 0.0f, 40.0f );
172 Actor radioGroup = Actor::New();
173 Stage::GetCurrent().Add( radioGroup );
174 radioGroup.SetParentOrigin(ParentOrigin::TOP_LEFT);
175 radioGroup.SetAnchorPoint(ParentOrigin::TOP_LEFT);
176 radioGroup.SetPosition( 0.0f, 0.0f );
177 radioGroup.SetSize( 400.0f, 400.0 );
179 radioGroup.Add( radioButton2 );
180 radioGroup.Add( radioButton3 );
182 application.SendNotification();
183 application.Render();
185 // Simulate touch events
186 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::PROPERTY_SELECTED ) == false );
187 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::PROPERTY_SELECTED ) == false );
189 // Select first radio
191 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
192 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
194 const Dali::TouchPoint pointDown( 0, TouchPoint::Down, 10.0f, 10.0f );
195 const Dali::TouchPoint pointUp( 0, TouchPoint::Up, 10.0f, 10.0f );
197 event1.AddPoint( pointDown );
198 application.ProcessEvent( event1 );
200 event2.AddPoint( pointUp );
201 application.ProcessEvent( event2 );
203 application.SendNotification();
204 application.Render();
206 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::PROPERTY_SELECTED ) == true );
207 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::PROPERTY_SELECTED ) == false );
210 // Select an already selected radio
212 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
213 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
215 const Dali::TouchPoint pointDown( 0, TouchPoint::Down, 10.0f, 10.0f );
216 const Dali::TouchPoint pointUp( 0, TouchPoint::Up, 10.0f, 10.0f );
218 event1.AddPoint( pointDown );
219 application.ProcessEvent( event1 );
221 event2.AddPoint( pointUp );
222 application.ProcessEvent( event2 );
224 application.SendNotification();
225 application.Render();
227 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::PROPERTY_SELECTED ) == true );
228 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::PROPERTY_SELECTED ) == false );
231 // Select second radio
233 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
234 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
236 const Dali::TouchPoint pointDown( 0, TouchPoint::Down, 10.0f, 50.0f );
237 const Dali::TouchPoint pointUp( 0, TouchPoint::Up, 10.0f, 50.0f );
239 event1.AddPoint( pointDown );
240 application.ProcessEvent( event1 );
242 event2.AddPoint( pointUp );
243 application.ProcessEvent( event2 );
245 application.SendNotification();
246 application.Render();
248 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::PROPERTY_SELECTED ) == false );
249 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::PROPERTY_SELECTED ) == true );
252 // Select outside radio group
254 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
255 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
257 const Dali::TouchPoint pointDown( 0, TouchPoint::Down, 10.0f, 500.0f );
258 const Dali::TouchPoint pointUp( 0, TouchPoint::Up, 10.0f, 500.0f );
260 event1.AddPoint( pointDown );
261 application.ProcessEvent( event1 );
263 event2.AddPoint( pointUp );
264 application.ProcessEvent( event2 );
266 application.SendNotification();
267 application.Render();
269 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::PROPERTY_SELECTED ) == false );
270 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::PROPERTY_SELECTED ) == true );