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)
106 ToolkitTestApplication application;
108 TextView actor1 = TextView::New( "test actor 1" );
110 RadioButton radioButton = RadioButton::New( actor1 );
111 DALI_TEST_CHECK( actor1 == radioButton.GetLabel() );
113 TextView actor2 = TextView::New( "test actor 2" );
114 radioButton.SetLabel( actor2 );
115 DALI_TEST_CHECK( actor2 == radioButton.GetLabel() );
120 int UtcDaliRadioButtonSelected(void)
122 ToolkitTestApplication application;
124 RadioButton radioButton = RadioButton::New();
127 DALI_TEST_CHECK( radioButton.IsSelected() == false );
130 radioButton.SetSelected( false );
131 DALI_TEST_CHECK( radioButton.IsSelected() == false );
134 radioButton.SetSelected( true );
135 DALI_TEST_CHECK( radioButton.IsSelected() == true );
138 radioButton.SetSelected( false );
139 DALI_TEST_CHECK( radioButton.IsSelected() == false );
144 int UtcDaliRadioButtonSelectedProperty(void)
146 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
147 tet_infoline(" UtcDaliRadioButtonSelectedProperty");
149 // Create the RadioButton actor
150 RadioButton radioButton = RadioButton::New();
151 Stage::GetCurrent().Add( radioButton );
152 radioButton.SetParentOrigin(ParentOrigin::TOP_LEFT);
153 radioButton.SetAnchorPoint(ParentOrigin::TOP_LEFT);
154 radioButton.SetPosition( 0.0f, 0.0f );
157 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
159 // Setting false selected
160 radioButton.SetProperty( Button::Property::SELECTED, false );
161 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
163 // Setting true selected
164 radioButton.SetProperty( Button::Property::SELECTED, true );
165 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == true );
167 // Setting false again
168 radioButton.SetProperty( Button::Property::SELECTED, false );
169 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
171 // Test selecting radio buttons
172 RadioButton radioButton2 = RadioButton::New( "label" );
173 radioButton2.SetParentOrigin(ParentOrigin::TOP_LEFT);
174 radioButton2.SetAnchorPoint(ParentOrigin::TOP_LEFT);
175 radioButton2.SetPosition( 0.0f, 0.0f );
177 RadioButton radioButton3 = RadioButton::New( "label" );
178 radioButton3.SetParentOrigin(ParentOrigin::TOP_LEFT);
179 radioButton3.SetAnchorPoint(ParentOrigin::TOP_LEFT);
180 radioButton3.SetPosition( 0.0f, 40.0f );
182 Actor radioGroup = Actor::New();
183 Stage::GetCurrent().Add( radioGroup );
184 radioGroup.SetParentOrigin(ParentOrigin::TOP_LEFT);
185 radioGroup.SetAnchorPoint(ParentOrigin::TOP_LEFT);
186 radioGroup.SetPosition( 0.0f, 0.0f );
187 radioGroup.SetSize( 400.0f, 400.0 );
189 radioGroup.Add( radioButton2 );
190 radioGroup.Add( radioButton3 );
192 application.SendNotification();
193 application.Render();
195 // Simulate touch events
196 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
197 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
199 // Select first radio
201 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
202 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
204 const Dali::TouchPoint pointDown( 0, TouchPoint::Down, 10.0f, 10.0f );
205 const Dali::TouchPoint pointUp( 0, TouchPoint::Up, 10.0f, 10.0f );
207 event1.AddPoint( pointDown );
208 application.ProcessEvent( event1 );
210 event2.AddPoint( pointUp );
211 application.ProcessEvent( event2 );
213 application.SendNotification();
214 application.Render();
216 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == true );
217 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
220 // Select an already selected radio
222 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
223 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
225 const Dali::TouchPoint pointDown( 0, TouchPoint::Down, 10.0f, 10.0f );
226 const Dali::TouchPoint pointUp( 0, TouchPoint::Up, 10.0f, 10.0f );
228 event1.AddPoint( pointDown );
229 application.ProcessEvent( event1 );
231 event2.AddPoint( pointUp );
232 application.ProcessEvent( event2 );
234 application.SendNotification();
235 application.Render();
237 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == true );
238 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
241 // Select second radio
243 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
244 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
246 const Dali::TouchPoint pointDown( 0, TouchPoint::Down, 10.0f, 50.0f );
247 const Dali::TouchPoint pointUp( 0, TouchPoint::Up, 10.0f, 50.0f );
249 event1.AddPoint( pointDown );
250 application.ProcessEvent( event1 );
252 event2.AddPoint( pointUp );
253 application.ProcessEvent( event2 );
255 application.SendNotification();
256 application.Render();
258 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
259 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == true );
262 // Select outside radio group
264 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
265 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
267 const Dali::TouchPoint pointDown( 0, TouchPoint::Down, 10.0f, 500.0f );
268 const Dali::TouchPoint pointUp( 0, TouchPoint::Up, 10.0f, 500.0f );
270 event1.AddPoint( pointDown );
271 application.ProcessEvent( event1 );
273 event2.AddPoint( pointUp );
274 application.ProcessEvent( event2 );
276 application.SendNotification();
277 application.Render();
279 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
280 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == true );