2 * Copyright (c) 2022 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.
18 #include <dali-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/dali-toolkit.h>
20 #include <dali/integration-api/events/touch-event-integ.h>
25 using namespace Dali::Toolkit;
27 void dali_radio_button_startup(void)
29 test_return_value = TET_UNDEF;
32 void dali_radio_button_cleanup(void)
34 test_return_value = TET_PASS;
39 static bool gObjectCreatedCallBackCalled;
41 static void TestCallback(BaseHandle handle)
43 gObjectCreatedCallBackCalled = true;
46 static std::string GetButtonText(Button button)
48 Property::Value value = button.GetProperty(Toolkit::Button::Property::LABEL);
50 Property::Map* labelProperty = value.GetMap();
52 std::string textLabel;
56 Property::Value* value = labelProperty->Find(Toolkit::TextVisual::Property::TEXT);
57 value->Get(textLabel);
65 int UtcDaliRadioButtonConstructorP(void)
67 ToolkitTestApplication application;
71 DALI_TEST_CHECK(!button);
75 int UtcDaliRadioButtonCopyConstructorP(void)
77 ToolkitTestApplication application;
79 // Initialize an object, ref count == 1
80 RadioButton button = RadioButton::New();
82 RadioButton copy(button);
83 DALI_TEST_CHECK(copy);
87 int UtcDaliRadioButtonMoveConstructor(void)
89 ToolkitTestApplication application;
91 RadioButton button = RadioButton::New();
92 DALI_TEST_EQUALS(1, button.GetBaseObject().ReferenceCount(), TEST_LOCATION);
93 DALI_TEST_EQUALS(button.GetProperty<bool>(Button::Property::TOGGLABLE), true, TEST_LOCATION);
94 button.SetProperty(Button::Property::TOGGLABLE, false);
95 DALI_TEST_EQUALS(button.GetProperty<bool>(Button::Property::TOGGLABLE), false, TEST_LOCATION);
97 RadioButton moved = std::move(button);
98 DALI_TEST_CHECK(moved);
99 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
100 DALI_TEST_EQUALS(moved.GetProperty<bool>(Button::Property::TOGGLABLE), false, TEST_LOCATION);
101 DALI_TEST_CHECK(!button);
106 int UtcDaliRadioButtonAssignmentOperatorP(void)
108 ToolkitTestApplication application;
110 RadioButton button = RadioButton::New();
112 RadioButton copy(button);
113 DALI_TEST_CHECK(copy);
115 DALI_TEST_CHECK(button == copy);
119 int UtcDaliRadioButtonMoveAssignment(void)
121 ToolkitTestApplication application;
123 RadioButton button = RadioButton::New();
124 DALI_TEST_EQUALS(1, button.GetBaseObject().ReferenceCount(), TEST_LOCATION);
125 DALI_TEST_EQUALS(button.GetProperty<bool>(Button::Property::TOGGLABLE), true, TEST_LOCATION);
126 button.SetProperty(Button::Property::TOGGLABLE, false);
127 DALI_TEST_EQUALS(button.GetProperty<bool>(Button::Property::TOGGLABLE), false, TEST_LOCATION);
130 moved = std::move(button);
131 DALI_TEST_CHECK(moved);
132 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
133 DALI_TEST_EQUALS(moved.GetProperty<bool>(Button::Property::TOGGLABLE), false, TEST_LOCATION);
134 DALI_TEST_CHECK(!button);
139 int UtcDaliRadioButtonNewP(void)
141 ToolkitTestApplication application;
142 tet_infoline(" UtcDaliRadioButtonNewP");
144 // Create the Slider actor
145 RadioButton radioButton;
147 DALI_TEST_CHECK(!radioButton);
149 radioButton = RadioButton::New();
151 DALI_TEST_CHECK(radioButton);
153 RadioButton radioButton2(radioButton);
155 DALI_TEST_CHECK(radioButton2 == radioButton);
157 //Additional check to ensure object is created by checking if it's registered
158 ObjectRegistry registry = application.GetCore().GetObjectRegistry();
159 DALI_TEST_CHECK(registry);
161 gObjectCreatedCallBackCalled = false;
162 registry.ObjectCreatedSignal().Connect(&TestCallback);
164 RadioButton radioButton = RadioButton::New();
166 DALI_TEST_CHECK(gObjectCreatedCallBackCalled);
170 int UtcDaliRadioButtonDestructorP(void)
172 ToolkitTestApplication application;
174 RadioButton* radioButton = new RadioButton();
177 DALI_TEST_CHECK(true);
181 int UtcDaliRadioButtonDownCast(void)
183 ToolkitTestApplication application;
185 Handle handle = RadioButton::New();
187 RadioButton radioButton = RadioButton::DownCast(handle);
189 DALI_TEST_CHECK(radioButton == handle);
193 int UtcDaliRadioButtonLabelProperty(void)
195 ToolkitTestApplication application;
197 const std::string labelText = "test actor 1";
199 RadioButton radioButton = RadioButton::New();
201 radioButton.SetProperty(Toolkit::Button::Property::LABEL,
202 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT).Add(Toolkit::TextVisual::Property::POINT_SIZE, 15.0f));
204 radioButton.SetProperty(Toolkit::Button::Property::LABEL, labelText);
205 DALI_TEST_EQUALS(GetButtonText(radioButton), labelText, TEST_LOCATION);
207 std::string labelText2 = "test actor 2";
208 radioButton.SetProperty(Toolkit::Button::Property::LABEL, labelText2);
210 DALI_TEST_EQUALS(GetButtonText(radioButton), labelText2, TEST_LOCATION);
215 int UtcDaliRadioButtonSelectedProperty(void)
217 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
218 tet_infoline(" UtcDaliRadioButtonSelectedProperty");
220 // Create the RadioButton actor
221 RadioButton radioButton = RadioButton::New();
222 application.GetScene().Add(radioButton);
223 radioButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
224 radioButton.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_LEFT);
225 radioButton.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
228 DALI_TEST_CHECK(radioButton.GetProperty<bool>(Button::Property::SELECTED) == false);
230 // Setting false selected
231 radioButton.SetProperty(Button::Property::SELECTED, false);
232 DALI_TEST_CHECK(radioButton.GetProperty<bool>(Button::Property::SELECTED) == false);
234 // Setting true selected
235 radioButton.SetProperty(Button::Property::SELECTED, true);
236 DALI_TEST_CHECK(radioButton.GetProperty<bool>(Button::Property::SELECTED) == true);
238 // Setting false again
239 radioButton.SetProperty(Button::Property::SELECTED, false);
240 DALI_TEST_CHECK(radioButton.GetProperty<bool>(Button::Property::SELECTED) == false);
242 // Test selecting radio buttons
243 RadioButton radioButton2 = RadioButton::New("label");
244 radioButton2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
245 radioButton2.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_LEFT);
246 radioButton2.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
248 RadioButton radioButton3 = RadioButton::New("label");
249 radioButton3.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
250 radioButton3.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_LEFT);
251 radioButton3.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 40.0f));
253 Actor radioGroup = Actor::New();
254 application.GetScene().Add(radioGroup);
255 radioGroup.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
256 radioGroup.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_LEFT);
257 radioGroup.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
258 radioGroup.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0));
260 radioGroup.Add(radioButton2);
261 radioGroup.Add(radioButton3);
263 application.SendNotification();
264 application.Render();
266 // Simulate touch events
267 DALI_TEST_CHECK(radioButton2.GetProperty<bool>(Button::Property::SELECTED) == false);
268 DALI_TEST_CHECK(radioButton3.GetProperty<bool>(Button::Property::SELECTED) == false);
270 // Select first radio
272 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
273 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
275 Dali::Integration::Point pointDown;
276 pointDown.SetState(PointState::DOWN);
277 pointDown.SetScreenPosition(Vector2(1.0f, 1.0f));
279 Dali::Integration::Point pointUp(pointDown);
280 pointUp.SetState(PointState::UP);
282 event1.AddPoint(pointDown);
283 application.ProcessEvent(event1);
285 event2.AddPoint(pointUp);
286 application.ProcessEvent(event2);
288 application.SendNotification();
289 application.Render();
291 DALI_TEST_CHECK(radioButton2.GetProperty<bool>(Button::Property::SELECTED) == true);
292 DALI_TEST_CHECK(radioButton3.GetProperty<bool>(Button::Property::SELECTED) == false);
295 // Select an already selected radio
297 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
298 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
300 Dali::Integration::Point pointDown;
301 pointDown.SetState(PointState::DOWN);
302 pointDown.SetScreenPosition(Vector2(1.0f, 1.0f));
304 Dali::Integration::Point pointUp(pointDown);
305 pointUp.SetState(PointState::UP);
307 event1.AddPoint(pointDown);
308 application.ProcessEvent(event1);
310 event2.AddPoint(pointUp);
311 application.ProcessEvent(event2);
313 application.SendNotification();
314 application.Render();
316 DALI_TEST_CHECK(radioButton2.GetProperty<bool>(Button::Property::SELECTED) == true);
317 DALI_TEST_CHECK(radioButton3.GetProperty<bool>(Button::Property::SELECTED) == false);
320 // Select second radio
322 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
323 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
325 Dali::Integration::Point pointDown;
326 pointDown.SetState(PointState::DOWN);
327 pointDown.SetScreenPosition(Vector2(1.0f, 41.0f));
329 Dali::Integration::Point pointUp(pointDown);
330 pointUp.SetState(PointState::UP);
332 event1.AddPoint(pointDown);
333 application.ProcessEvent(event1);
335 event2.AddPoint(pointUp);
336 application.ProcessEvent(event2);
338 application.SendNotification();
339 application.Render();
341 DALI_TEST_CHECK(radioButton2.GetProperty<bool>(Button::Property::SELECTED) == false);
342 DALI_TEST_CHECK(radioButton3.GetProperty<bool>(Button::Property::SELECTED) == true);
345 // Select outside radio group
347 Dali::Integration::TouchEvent event1 = Dali::Integration::TouchEvent();
348 Dali::Integration::TouchEvent event2 = Dali::Integration::TouchEvent();
350 Dali::Integration::Point pointDown;
351 pointDown.SetState(PointState::DOWN);
352 pointDown.SetScreenPosition(Vector2(1.0f, 500.0f));
354 Dali::Integration::Point pointUp(pointDown);
355 pointUp.SetState(PointState::UP);
357 event1.AddPoint(pointDown);
358 application.ProcessEvent(event1);
360 event2.AddPoint(pointUp);
361 application.ProcessEvent(event2);
363 application.SendNotification();
364 application.Render();
366 DALI_TEST_CHECK(radioButton2.GetProperty<bool>(Button::Property::SELECTED) == false);
367 DALI_TEST_CHECK(radioButton3.GetProperty<bool>(Button::Property::SELECTED) == true);