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 UtcDaliRadioButtonActive(void)
112 ToolkitTestApplication application;
114 RadioButton radioButton = RadioButton::New();
117 DALI_TEST_CHECK( radioButton.IsSelected() == false );
120 radioButton.ToggleState();
121 DALI_TEST_CHECK( radioButton.IsSelected() == true );
124 radioButton.ToggleState();
125 DALI_TEST_CHECK( radioButton.IsSelected() == false );
128 radioButton.SetSelected( false );
129 DALI_TEST_CHECK( radioButton.IsSelected() == false );
132 radioButton.SetSelected( true );
133 DALI_TEST_CHECK( radioButton.IsSelected() == true );
136 radioButton.SetSelected( false );
137 DALI_TEST_CHECK( radioButton.IsSelected() == false );
142 int UtcDaliRadioButtonActiveProperty(void)
144 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
145 tet_infoline(" UtcDaliRadioButtonActiveProperty");
147 // Create the RadioButton actor
148 RadioButton radioButton = RadioButton::New();
149 Stage::GetCurrent().Add( radioButton );
150 radioButton.SetParentOrigin(ParentOrigin::TOP_LEFT);
151 radioButton.SetAnchorPoint(ParentOrigin::TOP_LEFT);
152 radioButton.SetPosition( 0.0f, 0.0f );
155 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == false );
157 // Setting false active
158 radioButton.SetProperty( Button::PROPERTY_TOGGLED, false );
159 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == false );
161 // Setting true active
162 radioButton.SetProperty( Button::PROPERTY_TOGGLED, true );
163 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == true );
165 // Setting false again
166 radioButton.SetProperty( Button::PROPERTY_TOGGLED, false );
167 DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == false );
169 // Test selecting radio buttons
170 RadioButton radioButton2 = RadioButton::New( "label" );
171 radioButton2.SetParentOrigin(ParentOrigin::TOP_LEFT);
172 radioButton2.SetAnchorPoint(ParentOrigin::TOP_LEFT);
173 radioButton2.SetPosition( 0.0f, 0.0f );
175 RadioButton radioButton3 = RadioButton::New( "label" );
176 radioButton3.SetParentOrigin(ParentOrigin::TOP_LEFT);
177 radioButton3.SetAnchorPoint(ParentOrigin::TOP_LEFT);
178 radioButton3.SetPosition( 0.0f, 40.0f );
180 Actor radioGroup = Actor::New();
181 Stage::GetCurrent().Add( radioGroup );
182 radioGroup.SetParentOrigin(ParentOrigin::TOP_LEFT);
183 radioGroup.SetAnchorPoint(ParentOrigin::TOP_LEFT);
184 radioGroup.SetPosition( 0.0f, 0.0f );
185 radioGroup.SetSize( 400.0f, 400.0 );
187 radioGroup.Add( radioButton2 );
188 radioGroup.Add( radioButton3 );
190 application.SendNotification();
191 application.Render();
193 // Simulate touch events
194 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == false );
195 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == false );
197 // Select first radio
199 Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
201 const Dali::TouchPoint pointUp( 0, TouchPoint::Up, 10.0f, 10.0f );
202 event.AddPoint( pointUp );
204 application.ProcessEvent( event );
206 application.SendNotification();
207 application.Render();
209 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == true );
210 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == false );
213 // Select an already selected radio
215 Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
217 const Dali::TouchPoint pointDown( 0, TouchPoint::Up, 10.0f, 10.0f );
218 event.AddPoint( pointDown );
220 application.ProcessEvent( event );
222 application.SendNotification();
223 application.Render();
225 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == true );
226 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == false );
229 // Select second radio
231 Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
233 const Dali::TouchPoint pointDown( 0, TouchPoint::Up, 10.0f, 50.0f );
234 event.AddPoint( pointDown );
236 application.ProcessEvent( event );
238 application.SendNotification();
239 application.Render();
241 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == false );
242 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == true );
245 // Select outside radio group
247 Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
249 const Dali::TouchPoint pointDown( 0, TouchPoint::Up, 10.0f, 500.0f );
250 event.AddPoint( pointDown );
252 application.ProcessEvent( event );
254 application.SendNotification();
255 application.Render();
257 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == false );
258 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::PROPERTY_TOGGLED ) == true );