Dali 3D User Interface Engine
utc-Dali-RadioButton.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 
18 #include <iostream>
19 #include <stdlib.h>
23 
24 
25 using namespace Dali;
26 using namespace Dali::Toolkit;
27 
29 {
31 }
32 
34 {
36 }
37 
38 namespace
39 {
40 
42 
43 static void TestCallback(BaseHandle handle)
44 {
45  gObjectCreatedCallBackCalled = true;
46 }
47 
48 }
49 
51 {
52  TestApplication application;
53 
54  RadioButton button;
55 
56  DALI_TEST_CHECK( !button );
57  END_TEST;
58 }
59 
61 {
62  TestApplication application;
63 
64  // Initialize an object, ref count == 1
65  RadioButton button = RadioButton::New();
66 
67  RadioButton copy( button );
68  DALI_TEST_CHECK( copy );
69  END_TEST;
70 }
71 
73 {
74  TestApplication application;
75 
76  RadioButton button = RadioButton::New();
77 
78  RadioButton copy( button );
79  DALI_TEST_CHECK( copy );
80 
81  DALI_TEST_CHECK( button == copy );
82  END_TEST;
83 }
84 
86 {
87  ToolkitTestApplication application;
88  tet_infoline(" UtcDaliRadioButtonNewP");
89 
90  // Create the Slider actor
91  RadioButton radioButton;
92 
93  DALI_TEST_CHECK( !radioButton );
94 
95  radioButton = RadioButton::New();
96 
97  DALI_TEST_CHECK( radioButton );
98 
99  RadioButton radioButton2(radioButton);
100 
101  DALI_TEST_CHECK( radioButton2 == radioButton );
102 
103  //Additional check to ensure object is created by checking if it's registered
105  DALI_TEST_CHECK( registry );
106 
108  registry.ObjectCreatedSignal().Connect( &TestCallback );
109  {
110  RadioButton radioButton = RadioButton::New();
111  }
113  END_TEST;
114 }
115 
117 {
118  ToolkitTestApplication application;
119 
120  RadioButton* radioButton = new RadioButton();
121  delete radioButton;
122 
123  DALI_TEST_CHECK( true );
124  END_TEST;
125 }
126 
128 {
129  ToolkitTestApplication application;
130 
131  Handle handle = RadioButton::New();
132 
133  RadioButton radioButton = RadioButton::DownCast( handle );
134 
135  DALI_TEST_CHECK( radioButton == handle );
136  END_TEST;
137 }
138 
140 {
141  ToolkitTestApplication application;
142 
143  std::string labelText = "test actor 1";
144 
145  RadioButton radioButton = RadioButton::New( labelText );
146  DALI_TEST_EQUALS( radioButton.GetLabelText(), labelText, TEST_LOCATION );
147 
148  std::string labelText2 = "test actor 2";
149  radioButton.SetLabelText( labelText2 );
150  DALI_TEST_EQUALS( radioButton.GetLabelText(), labelText2, TEST_LOCATION );
151 
152  END_TEST;
153 }
154 
156 {
157  ToolkitTestApplication application;
158 
159  RadioButton radioButton = RadioButton::New();
160 
161  // Default selected
162  DALI_TEST_CHECK( radioButton.IsSelected() == false );
163 
164  // False
165  radioButton.SetSelected( false );
166  DALI_TEST_CHECK( radioButton.IsSelected() == false );
167 
168  // True
169  radioButton.SetSelected( true );
170  DALI_TEST_CHECK( radioButton.IsSelected() == true );
171 
172  // False
173  radioButton.SetSelected( false );
174  DALI_TEST_CHECK( radioButton.IsSelected() == false );
175 
176  END_TEST;
177 }
178 
180 {
181  ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
182  tet_infoline(" UtcDaliRadioButtonSelectedProperty");
183 
184  // Create the RadioButton actor
185  RadioButton radioButton = RadioButton::New();
186  Stage::GetCurrent().Add( radioButton );
189  radioButton.SetPosition( 0.0f, 0.0f );
190 
191  // Default selected
192  DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
193 
194  // Setting false selected
195  radioButton.SetProperty( Button::Property::SELECTED, false );
196  DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
197 
198  // Setting true selected
199  radioButton.SetProperty( Button::Property::SELECTED, true );
200  DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == true );
201 
202  // Setting false again
203  radioButton.SetProperty( Button::Property::SELECTED, false );
204  DALI_TEST_CHECK( radioButton.GetProperty<bool>( Button::Property::SELECTED ) == false );
205 
206  // Test selecting radio buttons
207  RadioButton radioButton2 = RadioButton::New( "label" );
210  radioButton2.SetPosition( 0.0f, 0.0f );
211 
212  RadioButton radioButton3 = RadioButton::New( "label" );
215  radioButton3.SetPosition( 0.0f, 40.0f );
216 
217  Actor radioGroup = Actor::New();
218  Stage::GetCurrent().Add( radioGroup );
221  radioGroup.SetPosition( 0.0f, 0.0f );
222  radioGroup.SetSize( 400.0f, 400.0 );
223 
224  radioGroup.Add( radioButton2 );
225  radioGroup.Add( radioButton3 );
226 
227  application.SendNotification();
228  application.Render();
229 
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 );
233 
234  // Select first radio
235  {
236  Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
237  Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
238 
239  const Dali::TouchPoint pointDown( 0, TouchPoint::Down, 1.0f, 1.0f );
240  const Dali::TouchPoint pointUp( 0, TouchPoint::Up, 1.0f, 1.0f );
241 
242  event1.AddPoint( pointDown );
243  application.ProcessEvent( event1 );
244 
245  event2.AddPoint( pointUp );
246  application.ProcessEvent( event2 );
247 
248  application.SendNotification();
249  application.Render();
250 
251  DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == true );
252  DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
253  }
254 
255  // Select an already selected radio
256  {
257  Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
258  Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
259 
260  const Dali::TouchPoint pointDown( 0, TouchPoint::Down, 1.0f, 1.0f );
261  const Dali::TouchPoint pointUp( 0, TouchPoint::Up, 1.0f, 1.0f );
262 
263  event1.AddPoint( pointDown );
264  application.ProcessEvent( event1 );
265 
266  event2.AddPoint( pointUp );
267  application.ProcessEvent( event2 );
268 
269  application.SendNotification();
270  application.Render();
271 
272  DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == true );
273  DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == false );
274  }
275 
276  // Select second radio
277  {
278  Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
279  Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
280 
281  const Dali::TouchPoint pointDown( 0, TouchPoint::Down, 1.0f, 41.0f );
282  const Dali::TouchPoint pointUp( 0, TouchPoint::Up, 1.0f, 41.0f );
283 
284  event1.AddPoint( pointDown );
285  application.ProcessEvent( event1 );
286 
287  event2.AddPoint( pointUp );
288  application.ProcessEvent( event2 );
289 
290  application.SendNotification();
291  application.Render();
292 
293  DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
294  DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == true );
295  }
296 
297  // Select outside radio group
298  {
299  Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
300  Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
301 
302  const Dali::TouchPoint pointDown( 0, TouchPoint::Down, 1.0f, 500.0f );
303  const Dali::TouchPoint pointUp( 0, TouchPoint::Up, 1.0f, 500.0f );
304 
305  event1.AddPoint( pointDown );
306  application.ProcessEvent( event1 );
307 
308  event2.AddPoint( pointUp );
309  application.ProcessEvent( event2 );
310 
311  application.SendNotification();
312  application.Render();
313 
314  DALI_TEST_CHECK( radioButton2.GetProperty<bool>( Button::Property::SELECTED ) == false );
315  DALI_TEST_CHECK( radioButton3.GetProperty<bool>( Button::Property::SELECTED ) == true );
316  }
317 
318  END_TEST;
319 }
Dali Docs Home
Read more about Dali