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 UtcDaliRadioButtonActive(void)
122 ToolkitTestApplication application;
124 RadioButton radioButton = RadioButton::New();
127 DALI_TEST_CHECK( radioButton.IsActive() == false );
130 radioButton.ToggleState();
131 DALI_TEST_CHECK( radioButton.IsActive() == true );
134 radioButton.ToggleState();
135 DALI_TEST_CHECK( radioButton.IsActive() == false );
138 radioButton.SetActive( false );
139 DALI_TEST_CHECK( radioButton.IsActive() == false );
142 radioButton.SetActive( true );
143 DALI_TEST_CHECK( radioButton.IsActive() == true );
146 radioButton.SetActive( false );
147 DALI_TEST_CHECK( radioButton.IsActive() == false );
152 int UtcDaliRadioButtonActiveProperty(void)
154 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
155 tet_infoline(" UtcDaliRadioButtonActiveProperty");
157 // Create the RadioButton actor
158 RadioButton radioButton = RadioButton::New();
159 Stage::GetCurrent().Add( radioButton );
160 radioButton.SetParentOrigin(ParentOrigin::TOP_LEFT);
161 radioButton.SetAnchorPoint(ParentOrigin::TOP_LEFT);
162 radioButton.SetPosition( 0.0f, 0.0f );
165 DALI_TEST_CHECK( radioButton.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == false );
167 // Setting false active
168 radioButton.SetProperty( RadioButton::PROPERTY_ACTIVE, false );
169 DALI_TEST_CHECK( radioButton.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == false );
171 // Setting true active
172 radioButton.SetProperty( RadioButton::PROPERTY_ACTIVE, true );
173 DALI_TEST_CHECK( radioButton.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == true );
175 // Setting false again
176 radioButton.SetProperty( RadioButton::PROPERTY_ACTIVE, false );
177 DALI_TEST_CHECK( radioButton.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == false );
179 // Test selecting radio buttons
180 RadioButton radioButton2 = RadioButton::New( "label" );
181 radioButton2.SetParentOrigin(ParentOrigin::TOP_LEFT);
182 radioButton2.SetAnchorPoint(ParentOrigin::TOP_LEFT);
183 radioButton2.SetPosition( 0.0f, 0.0f );
185 RadioButton radioButton3 = RadioButton::New( "label" );
186 radioButton3.SetParentOrigin(ParentOrigin::TOP_LEFT);
187 radioButton3.SetAnchorPoint(ParentOrigin::TOP_LEFT);
188 radioButton3.SetPosition( 0.0f, 40.0f );
190 Actor radioGroup = Actor::New();
191 Stage::GetCurrent().Add( radioGroup );
192 radioGroup.SetParentOrigin(ParentOrigin::TOP_LEFT);
193 radioGroup.SetAnchorPoint(ParentOrigin::TOP_LEFT);
194 radioGroup.SetPosition( 0.0f, 0.0f );
195 radioGroup.SetSize( 400.0f, 400.0 );
197 radioGroup.Add( radioButton2 );
198 radioGroup.Add( radioButton3 );
200 application.SendNotification();
201 application.Render();
203 // Simulate touch events
204 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == false );
205 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == false );
207 // Select first radio
209 Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
211 const Dali::TouchPoint pointUp( 0, TouchPoint::Up, 10.0f, 10.0f );
212 event.AddPoint( pointUp );
214 application.ProcessEvent( event );
216 application.SendNotification();
217 application.Render();
219 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == true );
220 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == false );
223 // Select an already selected radio
225 Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
227 const Dali::TouchPoint pointDown( 0, TouchPoint::Up, 10.0f, 10.0f );
228 event.AddPoint( pointDown );
230 application.ProcessEvent( event );
232 application.SendNotification();
233 application.Render();
235 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == true );
236 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == false );
239 // Select second radio
241 Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
243 const Dali::TouchPoint pointDown( 0, TouchPoint::Up, 10.0f, 50.0f );
244 event.AddPoint( pointDown );
246 application.ProcessEvent( event );
248 application.SendNotification();
249 application.Render();
251 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == false );
252 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == true );
255 // Select outside radio group
257 Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
259 const Dali::TouchPoint pointDown( 0, TouchPoint::Up, 10.0f, 500.0f );
260 event.AddPoint( pointDown );
262 application.ProcessEvent( event );
264 application.SendNotification();
265 application.Render();
267 DALI_TEST_CHECK( radioButton2.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == false );
268 DALI_TEST_CHECK( radioButton3.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == true );