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-toolkit/devel-api/controls/buttons/toggle-button.h>
21 #include <dali/integration-api/events/touch-event-integ.h>
26 using namespace Dali::Toolkit;
28 void dali_toggle_button_startup(void)
30 test_return_value = TET_UNDEF;
33 void dali_toggle_button_cleanup(void)
35 test_return_value = TET_PASS;
40 static const char* TEST_IMAGE_ONE = TEST_RESOURCE_DIR "/icon-delete.png";
41 static const char* TEST_IMAGE_TWO = TEST_RESOURCE_DIR "/icon-edit.png";
42 static const char* TEST_IMAGE_THREE = TEST_RESOURCE_DIR "/popup_tail_down.png";
43 static const char* TEST_IMAGE_FOUR = TEST_RESOURCE_DIR "/popup_tail_up.png";
45 static const Vector2 INSIDE_TOUCH_POINT_POSITON = Vector2(240, 400);
46 static const Vector3 BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS = Vector3(200, 360, 0);
47 static const Size BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS = Size(100, 100);
49 static bool gObjectCreatedCallBackCalled;
51 static void TestCallback(BaseHandle handle)
53 gObjectCreatedCallBackCalled = true;
56 Dali::Integration::Point GetPointDownInside()
58 Dali::Integration::Point point;
59 point.SetState(PointState::DOWN);
60 point.SetScreenPosition(INSIDE_TOUCH_POINT_POSITON);
64 Dali::Integration::Point GetPointUpInside()
66 Dali::Integration::Point point;
67 point.SetState(PointState::UP);
68 point.SetScreenPosition(INSIDE_TOUCH_POINT_POSITON);
74 int UtcDaliToggleButtonConstructorP(void)
76 ToolkitTestApplication application;
77 tet_infoline(" UtcDaliToggleButtonConstructorP");
80 DALI_TEST_CHECK(!button);
84 int UtcDaliToggleButtonCopyConstructorP(void)
86 ToolkitTestApplication application;
87 tet_infoline(" UtcDaliToggleButtonCopyConstructorP");
89 // Initialize an object, ref count == 1
90 ToggleButton button = ToggleButton::New();
92 ToggleButton copy(button);
93 DALI_TEST_CHECK(copy);
97 int UtcDaliToggleButtonAssignmentOperatorP(void)
99 ToolkitTestApplication application;
100 tet_infoline(" UtcDaliToggleButtonAssignmentOperatorP");
102 ToggleButton button = ToggleButton::New();
104 ToggleButton copy(button);
105 DALI_TEST_CHECK(copy);
107 DALI_TEST_CHECK(button == copy);
111 int UtcDaliToggleButtonNewP(void)
113 ToolkitTestApplication application;
114 tet_infoline(" UtcDaliToggleButtonNewP");
116 // Create the Slider actor
117 ToggleButton toggleButton;
119 DALI_TEST_CHECK(!toggleButton);
121 toggleButton = ToggleButton::New();
123 DALI_TEST_CHECK(toggleButton);
125 ToggleButton toggleButton2(toggleButton);
127 DALI_TEST_CHECK(toggleButton2 == toggleButton);
129 //Additional check to ensure object is created by checking if it's registered
130 ObjectRegistry registry = application.GetCore().GetObjectRegistry();
131 DALI_TEST_CHECK(registry);
133 gObjectCreatedCallBackCalled = false;
134 registry.ObjectCreatedSignal().Connect(&TestCallback);
136 ToggleButton toggleButton = ToggleButton::New();
138 DALI_TEST_CHECK(gObjectCreatedCallBackCalled);
142 int UtcDaliToggleButtonDestructorP(void)
144 ToolkitTestApplication application;
145 tet_infoline("UtcDaliToggleButtonDestructorP");
147 ToggleButton* toggleButton = new ToggleButton();
150 DALI_TEST_CHECK(true);
154 int UtcDaliToggleButtonDownCast(void)
156 ToolkitTestApplication application;
157 tet_infoline("UtcDaliToggleButtonDownCast");
159 Handle handle = ToggleButton::New();
160 ToggleButton toggleButton = ToggleButton::DownCast(handle);
162 DALI_TEST_CHECK(toggleButton == handle);
166 int UtcDaliToggleButtonToggleStatesProperty(void)
168 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
169 tet_infoline(" UtcDaliToggleButtonToggleStatesProperty");
171 // Create the ToggleButton actor
172 ToggleButton toggleButton = ToggleButton::New();
173 application.GetScene().Add(toggleButton);
174 toggleButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
175 toggleButton.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_LEFT);
176 toggleButton.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
178 { // Check empty array
179 Property::Array toggleIcons;
180 toggleButton.SetProperty(Toolkit::ToggleButton::Property::STATE_VISUALS, toggleIcons);
182 application.SendNotification();
183 application.Render();
185 Property::Array resultIcons;
186 resultIcons = toggleButton.GetProperty(Toolkit::ToggleButton::Property::STATE_VISUALS).Get<Property::Array>();
187 DALI_TEST_CHECK(resultIcons.Count() == 0);
190 { // Check non-empty Array
191 Property::Array toggleIcons;
192 toggleIcons.PushBack(TEST_IMAGE_ONE); //Icons path
193 toggleIcons.PushBack(TEST_IMAGE_TWO);
194 toggleIcons.PushBack(TEST_IMAGE_THREE);
195 toggleIcons.PushBack(TEST_IMAGE_FOUR);
196 toggleButton.SetProperty(Toolkit::ToggleButton::Property::STATE_VISUALS, toggleIcons);
198 application.SendNotification();
199 application.Render();
201 Property::Array resultIcons;
202 resultIcons = toggleButton.GetProperty(Toolkit::ToggleButton::Property::STATE_VISUALS).Get<Property::Array>();
204 // Check that the result is the same as
205 DALI_TEST_EQUALS(toggleIcons.Count(), resultIcons.Count(), TEST_LOCATION);
206 DALI_TEST_CHECK(toggleIcons[0].Get<std::string>() == resultIcons[0].Get<std::string>());
207 DALI_TEST_CHECK(toggleIcons[1].Get<std::string>() == resultIcons[1].Get<std::string>());
208 DALI_TEST_CHECK(toggleIcons[2].Get<std::string>() == resultIcons[2].Get<std::string>());
209 DALI_TEST_CHECK(toggleIcons[3].Get<std::string>() == resultIcons[3].Get<std::string>());
212 { // Check property::map
213 Property::Map propertyMap1;
214 Vector4 testColor1(1.f, 0.5f, 0.3f, 0.2f);
215 propertyMap1.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR);
216 propertyMap1.Insert(Toolkit::ColorVisual::Property::MIX_COLOR, testColor1);
218 Property::Map propertyMap2;
219 Vector4 testColor2(0.5f, 1.f, 0.3f, 0.2f);
220 propertyMap2.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR);
221 propertyMap2.Insert(Toolkit::ColorVisual::Property::MIX_COLOR, testColor2);
223 Property::Map propertyMap3;
224 Vector4 testColor3(1.f, 0.5f, 1.f, 0.2f);
225 propertyMap3.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR);
226 propertyMap3.Insert(Toolkit::ColorVisual::Property::MIX_COLOR, testColor3);
228 Property::Array toggleMaps;
229 toggleMaps.Add(propertyMap1);
230 toggleMaps.Add(propertyMap2);
231 toggleMaps.Add(propertyMap3);
232 toggleButton.SetProperty(Toolkit::ToggleButton::Property::STATE_VISUALS, toggleMaps);
234 application.SendNotification();
235 application.Render();
237 Property::Array resultMaps;
238 resultMaps = toggleButton.GetProperty(Toolkit::ToggleButton::Property::STATE_VISUALS).Get<Property::Array>();
240 // Check that the result
241 DALI_TEST_EQUALS(toggleMaps.Count(), resultMaps.Count(), TEST_LOCATION);
247 int UtcDaliToggleButtonToggleTipsProperty(void)
249 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
250 tet_infoline(" UtcDaliToggleButtonToggleTipsProperty");
252 // Create the ToggleButton actor
253 ToggleButton toggleButton = ToggleButton::New();
254 application.GetScene().Add(toggleButton);
255 toggleButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
256 toggleButton.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_LEFT);
257 toggleButton.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
259 { // Check empty tip array
260 Property::Array toggleIcons;
261 toggleIcons.PushBack(TEST_IMAGE_ONE); //Icons path
262 toggleIcons.PushBack(TEST_IMAGE_TWO);
263 toggleIcons.PushBack(TEST_IMAGE_THREE);
264 toggleButton.SetProperty(Toolkit::ToggleButton::Property::STATE_VISUALS, toggleIcons);
266 Property::Array toggleTips;
267 toggleButton.SetProperty(Toolkit::ToggleButton::Property::TOOLTIPS, toggleTips);
269 application.SendNotification();
270 application.Render();
272 Property::Array resultTips;
273 resultTips = toggleButton.GetProperty(Toolkit::ToggleButton::Property::TOOLTIPS).Get<Property::Array>();
274 DALI_TEST_CHECK(resultTips.Count() == 0);
277 { // Check non-empty tip array
278 Property::Array toggleIcons;
279 toggleIcons.PushBack(TEST_IMAGE_ONE); //Icons path
280 toggleIcons.PushBack(TEST_IMAGE_TWO);
281 toggleIcons.PushBack(TEST_IMAGE_THREE);
282 toggleButton.SetProperty(Toolkit::ToggleButton::Property::STATE_VISUALS, toggleIcons);
284 Property::Array toggleTips;
285 toggleTips.PushBack("Button State A"); //Tooltip string
286 toggleTips.PushBack("Button State B");
287 toggleTips.PushBack("Button State C");
288 toggleButton.SetProperty(Toolkit::ToggleButton::Property::TOOLTIPS, toggleTips);
290 application.SendNotification();
291 application.Render();
293 Property::Array resultTips;
294 resultTips = toggleButton.GetProperty(Toolkit::ToggleButton::Property::TOOLTIPS).Get<Property::Array>();
296 //Check that the result is the same as
297 DALI_TEST_EQUALS(toggleTips.Count(), resultTips.Count(), TEST_LOCATION);
298 DALI_TEST_CHECK(toggleTips[0].Get<std::string>() == resultTips[0].Get<std::string>());
299 DALI_TEST_CHECK(toggleTips[1].Get<std::string>() == resultTips[1].Get<std::string>());
300 DALI_TEST_CHECK(toggleTips[2].Get<std::string>() == resultTips[2].Get<std::string>());
301 DALI_TEST_CHECK(toggleTips[3].Get<std::string>() == resultTips[3].Get<std::string>());
306 int UtcDaliToggleButtonStateChange(void)
308 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
309 tet_infoline(" UtcDaliToggleButtonStateChange");
311 // Create the ToggleButton actor
312 ToggleButton toggleButton = ToggleButton::New();
313 application.GetScene().Add(toggleButton);
314 toggleButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
315 toggleButton.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_LEFT);
316 toggleButton.SetProperty(Actor::Property::POSITION, BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS);
317 toggleButton.SetProperty(Actor::Property::SIZE, BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS);
319 Property::Array toggleIcons;
320 toggleIcons.PushBack(TEST_IMAGE_ONE); //Icons path
321 toggleIcons.PushBack(TEST_IMAGE_TWO);
322 toggleIcons.PushBack(TEST_IMAGE_THREE);
323 toggleButton.SetProperty(Toolkit::ToggleButton::Property::STATE_VISUALS, toggleIcons);
325 Property::Array toggleTips;
326 toggleTips.PushBack("Button State A"); //Tooltip string
327 toggleTips.PushBack("Button State B");
328 toggleTips.PushBack("Button State C");
329 toggleButton.SetProperty(Toolkit::ToggleButton::Property::TOOLTIPS, toggleTips);
331 application.SendNotification();
332 application.Render();
334 Property::Array resultIcons;
335 resultIcons = toggleButton.GetProperty(Toolkit::ToggleButton::Property::STATE_VISUALS).Get<Property::Array>();
336 DALI_TEST_EQUALS(toggleIcons.Count(), resultIcons.Count(), TEST_LOCATION);
338 Property::Array resultTips;
339 resultTips = toggleButton.GetProperty(Toolkit::ToggleButton::Property::TOOLTIPS).Get<Property::Array>();
340 DALI_TEST_EQUALS(toggleTips.Count(), resultTips.Count(), TEST_LOCATION);
343 DALI_TEST_CHECK(toggleButton.GetProperty(Toolkit::ToggleButton::Property::CURRENT_STATE_INDEX).Get(index));
344 DALI_TEST_EQUALS(index, 0, TEST_LOCATION);
346 Dali::Integration::TouchEvent event;
348 // Touch point down and up inside the button 3 times.
349 event = Dali::Integration::TouchEvent();
350 event.AddPoint(GetPointDownInside());
351 application.ProcessEvent(event);
353 event = Dali::Integration::TouchEvent();
354 event.AddPoint(GetPointUpInside());
355 application.ProcessEvent(event);
357 DALI_TEST_CHECK(toggleButton.GetProperty(Toolkit::ToggleButton::Property::CURRENT_STATE_INDEX).Get(index));
358 DALI_TEST_EQUALS(index, 1, TEST_LOCATION);
360 event = Dali::Integration::TouchEvent();
361 event.AddPoint(GetPointDownInside());
362 application.ProcessEvent(event);
364 event = Dali::Integration::TouchEvent();
365 event.AddPoint(GetPointUpInside());
366 application.ProcessEvent(event);
368 DALI_TEST_CHECK(toggleButton.GetProperty(Toolkit::ToggleButton::Property::CURRENT_STATE_INDEX).Get(index));
369 DALI_TEST_EQUALS(index, 2, TEST_LOCATION);
371 event = Dali::Integration::TouchEvent();
372 event.AddPoint(GetPointDownInside());
373 application.ProcessEvent(event);
375 event = Dali::Integration::TouchEvent();
376 event.AddPoint(GetPointUpInside());
377 application.ProcessEvent(event);
379 DALI_TEST_CHECK(toggleButton.GetProperty(Toolkit::ToggleButton::Property::CURRENT_STATE_INDEX).Get(index));
380 DALI_TEST_EQUALS(index, 0, TEST_LOCATION);