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.
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
24 #include "dali-toolkit-test-utils/toolkit-timer.h"
26 #include <dali-toolkit/dali-toolkit.h>
28 #include <dali/integration-api/events/touch-event-integ.h>
30 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
33 using namespace Toolkit;
35 void utc_dali_toolkit_button_startup(void)
37 test_return_value = TET_UNDEF;
40 void utc_dali_toolkit_button_cleanup(void)
42 test_return_value = TET_PASS;
47 static bool gIsCalledButtonCallback = false;
48 static bool gIsCalledChildButtonCallback = false;
50 static bool ButtonCallback(Button button)
52 gIsCalledButtonCallback = true;
56 static bool ChildButtonCallback(Button button)
58 gIsCalledChildButtonCallback = true;
62 static std::string GetButtonText(Button button)
64 Property::Value value = button.GetProperty(Toolkit::Button::Property::LABEL);
66 Property::Map* labelProperty = value.GetMap();
68 std::string textLabel;
72 Property::Value* value = labelProperty->Find(Toolkit::TextVisual::Property::TEXT);
73 value->Get(textLabel);
79 struct CallbackFunctor
81 CallbackFunctor(bool* callbackFlag)
82 : mCallbackFlag(callbackFlag)
88 *mCallbackFlag = true;
93 Dali::Integration::Point GetPointDownInside()
95 Dali::Integration::Point point;
96 point.SetState(PointState::DOWN);
97 point.SetScreenPosition(Vector2(240, 400));
101 Dali::Integration::Point GetPointUpInside()
103 Dali::Integration::Point point;
104 point.SetState(PointState::UP);
105 point.SetScreenPosition(Vector2(240, 400));
109 Dali::Integration::Point GetPointLeave()
111 Dali::Integration::Point point;
112 point.SetState(PointState::LEAVE);
113 point.SetScreenPosition(Vector2(240, 400));
117 Dali::Integration::Point GetPointEnter()
119 Dali::Integration::Point point;
120 point.SetState(PointState::MOTION);
121 point.SetScreenPosition(Vector2(240, 400));
125 Dali::Integration::Point GetPointDownOutside()
127 Dali::Integration::Point point;
128 point.SetState(PointState::DOWN);
129 point.SetScreenPosition(Vector2(10, 10));
133 Dali::Integration::Point GetPointUpOutside()
135 Dali::Integration::Point point;
136 point.SetState(PointState::UP);
137 point.SetScreenPosition(Vector2(10, 10));
143 int UtcDaliButtonConstructorP(void)
145 ToolkitTestApplication application;
149 DALI_TEST_CHECK(!button);
153 int UtcDaliButtonCopyConstructorP(void)
155 ToolkitTestApplication application;
157 // Initialize an object, ref count == 1
158 Button button = PushButton::New();
161 DALI_TEST_CHECK(copy);
165 int UtcDaliButtonMoveConstructor(void)
167 ToolkitTestApplication application;
169 Button button = PushButton::New();
170 DALI_TEST_EQUALS(1, button.GetBaseObject().ReferenceCount(), TEST_LOCATION);
171 DALI_TEST_EQUALS(button.GetProperty<bool>(Button::Property::TOGGLABLE), false, TEST_LOCATION);
172 button.SetProperty(Button::Property::TOGGLABLE, true);
173 DALI_TEST_EQUALS(button.GetProperty<bool>(Button::Property::TOGGLABLE), true, TEST_LOCATION);
175 Button moved = std::move(button);
176 DALI_TEST_CHECK(moved);
177 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
178 DALI_TEST_EQUALS(moved.GetProperty<bool>(Button::Property::TOGGLABLE), true, TEST_LOCATION);
179 DALI_TEST_CHECK(!button);
184 int UtcDaliButtonAssignmentOperatorP(void)
186 ToolkitTestApplication application;
188 Button button = PushButton::New();
191 DALI_TEST_CHECK(copy);
193 DALI_TEST_CHECK(button == copy);
197 int UtcDaliButtonMoveAssignment(void)
199 ToolkitTestApplication application;
201 Button button = PushButton::New();
202 DALI_TEST_EQUALS(1, button.GetBaseObject().ReferenceCount(), TEST_LOCATION);
203 DALI_TEST_EQUALS(button.GetProperty<bool>(Button::Property::TOGGLABLE), false, TEST_LOCATION);
204 button.SetProperty(Button::Property::TOGGLABLE, true);
205 DALI_TEST_EQUALS(button.GetProperty<bool>(Button::Property::TOGGLABLE), true, TEST_LOCATION);
208 moved = std::move(button);
209 DALI_TEST_CHECK(moved);
210 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
211 DALI_TEST_EQUALS(moved.GetProperty<bool>(Button::Property::TOGGLABLE), true, TEST_LOCATION);
212 DALI_TEST_CHECK(!button);
217 int UtcDaliButtonDownCastP(void)
219 ToolkitTestApplication application;
221 Button button = PushButton::New();
223 BaseHandle object(button);
225 Button button2 = Button::DownCast(object);
226 DALI_TEST_CHECK(button2);
228 Button button3 = DownCast<Button>(object);
229 DALI_TEST_CHECK(button3);
233 int UtcDaliButtonDownCastN(void)
235 ToolkitTestApplication application;
237 BaseHandle unInitializedObject;
239 Button button1 = Button::DownCast(unInitializedObject);
240 DALI_TEST_CHECK(!button1);
242 Button button2 = DownCast<Button>(unInitializedObject);
243 DALI_TEST_CHECK(!button2);
247 int UtcDaliButtonDisabledPropertyP(void)
249 ToolkitTestApplication application;
251 Button button = PushButton::New();
253 button.SetProperty(button.GetPropertyIndex("disabled"), true);
255 DALI_TEST_EQUALS(button.GetProperty<bool>(button.GetPropertyIndex("disabled")), true, TEST_LOCATION);
257 button.SetProperty(button.GetPropertyIndex("disabled"), false);
259 DALI_TEST_EQUALS(button.GetProperty<bool>(button.GetPropertyIndex("disabled")), false, TEST_LOCATION);
261 button.SetProperty(button.GetPropertyIndex("disabled"), true);
263 DALI_TEST_EQUALS(button.GetProperty<bool>(button.GetPropertyIndex("disabled")), true, TEST_LOCATION);
265 button.SetProperty(button.GetPropertyIndex("disabled"), false);
267 DALI_TEST_EQUALS(button.GetProperty<bool>(button.GetPropertyIndex("disabled")), false, TEST_LOCATION);
272 int UtcDaliButtonSetDisabledWithDifferentStates01P(void)
274 ToolkitTestApplication application;
276 tet_infoline("UtcDaliButtonSetDisabledWithDifferentStates01P\n");
278 Button button = PushButton::New();
280 bool SELECTED = true;
282 button.SetProperty(Button::Property::TOGGLABLE, true);
283 button.SetProperty(Button::Property::SELECTED, SELECTED);
285 button.SetProperty(Button::Property::DISABLED, true);
287 tet_infoline("Set button to SELECTED = false whilst disabled, should not change to false\n");
288 button.SetProperty(Button::Property::SELECTED, !SELECTED);
290 bool isSelected = button.GetProperty<bool>(Button::Property::SELECTED);
292 DALI_TEST_EQUALS(isSelected, SELECTED, TEST_LOCATION);
297 int UtcDaliButtonSetDisabledWithDifferentStates02P(void)
299 ToolkitTestApplication application;
301 tet_infoline("UtcDaliButtonSetDisabledWithDifferentStates02\n");
303 Button button = PushButton::New();
305 bool SELECTED = true;
307 button.SetProperty(Button::Property::TOGGLABLE, true);
308 button.SetProperty(Button::Property::SELECTED, SELECTED);
309 button.SetProperty(Button::Property::DISABLED, true);
311 bool isSelected = button.GetProperty<bool>(Button::Property::SELECTED);
312 DALI_TEST_EQUALS(isSelected, SELECTED, TEST_LOCATION);
313 tet_infoline("Set button to DISABLED = false whilst disabled and then set to unselected\n");
315 button.SetProperty(Button::Property::DISABLED, false);
316 button.SetProperty(Button::Property::SELECTED, !SELECTED);
318 isSelected = button.GetProperty<bool>(Button::Property::SELECTED);
319 DALI_TEST_EQUALS(isSelected, !SELECTED, TEST_LOCATION);
324 int UtcDaliButtonPropertyGetLabelAlignment(void)
326 ToolkitTestApplication application;
327 tet_infoline(" UtcDaliPushButtonPropertyGetLabelAlignment\n");
329 Button button = PushButton::New();
330 button.SetProperty(Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "END");
331 DALI_TEST_EQUALS(button.GetProperty<std::string>(Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT), "END", TEST_LOCATION);
336 int UtcDaliButtonIsDisabledP(void)
338 ToolkitTestApplication application;
340 Button button = PushButton::New();
342 button.SetProperty(Button::Property::DISABLED, true);
344 DALI_TEST_EQUALS(button.GetProperty<bool>(Button::Property::DISABLED), true, TEST_LOCATION);
346 button.SetProperty(Button::Property::DISABLED, false);
348 DALI_TEST_EQUALS(button.GetProperty<bool>(Button::Property::DISABLED), false, TEST_LOCATION);
352 int UtcDaliButtonAutoRepeatingPropertyP(void)
354 ToolkitTestApplication application;
356 Button button = PushButton::New();
358 button.SetProperty(button.GetPropertyIndex("autoRepeating"), true);
360 DALI_TEST_EQUALS(button.GetProperty<bool>(button.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION);
362 button.SetProperty(button.GetPropertyIndex("autoRepeating"), false);
364 DALI_TEST_EQUALS(button.GetProperty<bool>(button.GetPropertyIndex("autoRepeating")), false, TEST_LOCATION);
366 button.SetProperty(button.GetPropertyIndex("autoRepeating"), true);
368 DALI_TEST_EQUALS(button.GetProperty<bool>(button.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION);
373 int UtcDaliButtonIsAutoRepeatingP(void)
375 ToolkitTestApplication application;
377 Button button = PushButton::New();
379 button.SetProperty(Button::Property::AUTO_REPEATING, true);
381 DALI_TEST_EQUALS(button.GetProperty<bool>(Button::Property::AUTO_REPEATING), true, TEST_LOCATION);
383 button.SetProperty(Button::Property::AUTO_REPEATING, false);
385 DALI_TEST_EQUALS(button.GetProperty<bool>(Button::Property::AUTO_REPEATING), false, TEST_LOCATION);
390 int UtcDaliButtonAutoRepeatingP(void)
392 ToolkitTestApplication application;
393 tet_infoline(" UtcDaliButtonPressedSignalP Setup Autorepeating and check multiple clicked signals received\n");
395 const float AUTO_REPEATING_DELAY = 0.15f;
397 Button button = PushButton::New();
398 button.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
399 button.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
400 button.SetProperty(Actor::Property::POSITION, Vector2(240, 400));
401 button.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
402 application.GetScene().Add(button);
404 application.SendNotification();
405 application.Render();
407 button.SetProperty(Toolkit::Button::Property::AUTO_REPEATING, true);
408 button.SetProperty(Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY, AUTO_REPEATING_DELAY);
409 // connect to its touch signal
410 ConnectionTracker* testTracker = new ConnectionTracker();
411 button.PressedSignal().Connect(&ButtonCallback);
412 button.ClickedSignal().Connect(&ButtonCallback);
413 bool clickedSignal = false;
414 bool pressedSignal = false;
415 button.ConnectSignal(testTracker, "pressed", CallbackFunctor(&pressedSignal));
416 button.ConnectSignal(testTracker, "clicked", CallbackFunctor(&clickedSignal));
418 Dali::Integration::TouchEvent event;
420 // Touch point down and up inside the button.
422 gIsCalledButtonCallback = false;
423 event = Dali::Integration::TouchEvent();
424 event.AddPoint(GetPointDownInside());
425 application.ProcessEvent(event);
427 DALI_TEST_EQUALS(gIsCalledButtonCallback, true, TEST_LOCATION);
428 DALI_TEST_EQUALS(pressedSignal, true, TEST_LOCATION);
429 tet_infoline("Consume first clicked signal then wait\n");
431 gIsCalledButtonCallback = false;
432 Dali::Timer timer = Timer::New(AUTO_REPEATING_DELAY);
433 timer.MockEmitSignal();
434 application.Wait(AUTO_REPEATING_DELAY * 2);
435 DALI_TEST_EQUALS(clickedSignal, true, TEST_LOCATION);
436 tet_infoline("Check gIsCalledButtonCallback was called again after last consumption of it.\n");
438 DALI_TEST_EQUALS(gIsCalledButtonCallback, true, TEST_LOCATION);
440 gIsCalledButtonCallback = false;
441 event = Dali::Integration::TouchEvent();
442 event.AddPoint(GetPointUpInside());
443 application.ProcessEvent(event);
445 DALI_TEST_EQUALS(gIsCalledButtonCallback, true, TEST_LOCATION);
450 int UtcDaliButtonInitialAutoRepeatingDelayPropertyP(void)
452 ToolkitTestApplication application;
454 Button button = PushButton::New();
456 button.SetProperty(button.GetPropertyIndex("initialAutoRepeatingDelay"), 0.5f);
458 DALI_TEST_EQUALS(button.GetProperty<float>(button.GetPropertyIndex("initialAutoRepeatingDelay")), 0.5f, TEST_LOCATION);
460 button.SetProperty(button.GetPropertyIndex("initialAutoRepeatingDelay"), 0.2f);
462 DALI_TEST_EQUALS(button.GetProperty<float>(button.GetPropertyIndex("initialAutoRepeatingDelay")), 0.2f, TEST_LOCATION);
467 int UtcDaliButtonNextAutoRepeatingDelayPropertyP(void)
469 ToolkitTestApplication application;
471 Button button = PushButton::New();
473 button.SetProperty(button.GetPropertyIndex("nextAutoRepeatingDelay"), 0.5f);
475 DALI_TEST_EQUALS(button.GetProperty<float>(button.GetPropertyIndex("nextAutoRepeatingDelay")), 0.5f, TEST_LOCATION);
477 button.SetProperty(button.GetPropertyIndex("nextAutoRepeatingDelay"), 0.2f);
479 DALI_TEST_EQUALS(button.GetProperty<float>(button.GetPropertyIndex("nextAutoRepeatingDelay")), 0.2f, TEST_LOCATION);
483 int UtcDaliButtonTogglableButtonPropertyP(void)
485 ToolkitTestApplication application;
487 Button button = PushButton::New();
489 button.SetProperty(button.GetPropertyIndex("togglable"), true);
491 DALI_TEST_EQUALS(button.GetProperty<bool>(button.GetPropertyIndex("togglable")), true, TEST_LOCATION);
493 button.SetProperty(button.GetPropertyIndex("togglable"), false);
495 DALI_TEST_EQUALS(button.GetProperty<bool>(button.GetPropertyIndex("togglable")), false, TEST_LOCATION);
499 int UtcDaliButtonSelectedPropertyP(void)
501 ToolkitTestApplication application;
503 Button button = PushButton::New();
504 button.SetProperty(button.GetPropertyIndex("togglable"), true);
506 button.SetProperty(button.GetPropertyIndex("selected"), true);
508 DALI_TEST_EQUALS(button.GetProperty<bool>(button.GetPropertyIndex("selected")), true, TEST_LOCATION);
510 button.SetProperty(button.GetPropertyIndex("selected"), false);
512 DALI_TEST_EQUALS(button.GetProperty<bool>(button.GetPropertyIndex("selected")), false, TEST_LOCATION);
516 int UtcDaliButtonSetLabelStringWithPropertyMapP(void)
518 ToolkitTestApplication application;
520 Button button = PushButton::New();
521 button.SetProperty(Toolkit::Button::Property::LABEL,
522 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT).Add(Toolkit::TextVisual::Property::POINT_SIZE, 15.0f).Add(Toolkit::TextVisual::Property::TEXT, "Button Label"));
524 DALI_TEST_EQUALS(GetButtonText(button), "Button Label", TEST_LOCATION);
528 int UtcDaliButtonSetLabelStringWithPropertyMapStringsP(void)
530 ToolkitTestApplication application;
532 Button button = PushButton::New();
534 tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Setting Button text using String then replacing with Enum then string");
536 Property::Map textVisualMapInitial;
537 textVisualMapInitial["visualType"] = "TEXT";
538 textVisualMapInitial["pointSize"] = 15.0f;
539 textVisualMapInitial["text"] = "button label initial";
541 button.SetProperty(Button::Property::LABEL, textVisualMapInitial);
543 DALI_TEST_EQUALS(GetButtonText(button), "button label initial", TEST_LOCATION);
545 tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Intermediate part of test");
547 Property::Map propertyMap;
548 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT);
549 propertyMap.Insert(Toolkit::TextVisual::Property::TEXT, "error if this is the final text");
550 propertyMap.Insert(Toolkit::TextVisual::Property::POINT_SIZE, 15.0f);
552 button.SetProperty(Button::Property::LABEL, propertyMap);
554 DALI_TEST_EQUALS(GetButtonText(button), "error if this is the final text", TEST_LOCATION);
556 tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Final part of test");
558 Property::Map textVisualMap;
559 textVisualMap["visualType"] = "TEXT";
560 textVisualMap["pointSize"] = 15.0f;
561 textVisualMap["text"] = "Button Label";
563 button.SetProperty(Toolkit::Button::Property::LABEL, textVisualMap);
565 DALI_TEST_EQUALS(GetButtonText(button), "Button Label", TEST_LOCATION);
569 int UtcDaliButtonSetLabelWithStringP(void)
571 ToolkitTestApplication application;
573 Button button = PushButton::New();
575 // Set default point size for text visual as style sheet not available.
576 button.SetProperty(Toolkit::Button::Property::LABEL,
577 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT).Add(Toolkit::TextVisual::Property::POINT_SIZE, 15.0f));
579 button.SetProperty(Toolkit::Button::Property::LABEL, "Button Label");
581 DALI_TEST_EQUALS(GetButtonText(button), "Button Label", TEST_LOCATION);
585 int UtcDaliButtonSetLabelPropertyP(void)
587 ToolkitTestApplication application;
589 tet_infoline(" UtcDaliButtonSetLabelPropertyP Set text label and then set again with new text");
591 const std::string TEST_LABEL1 = "test label one";
592 const std::string TEST_LABEL2 = "test label two";
594 Button button = PushButton::New();
596 button.SetProperty(Toolkit::Button::Property::LABEL,
597 Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT).Add(Toolkit::TextVisual::Property::POINT_SIZE, 15.0f).Add(Toolkit::TextVisual::Property::TEXT, TEST_LABEL1));
599 DALI_TEST_EQUALS(GetButtonText(button), TEST_LABEL1, TEST_LOCATION);
601 Property::Map propertyMap;
602 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT);
603 propertyMap.Insert(Toolkit::TextVisual::Property::TEXT, TEST_LABEL2);
604 propertyMap.Insert(Toolkit::TextVisual::Property::TEXT_COLOR, Color::BLUE);
605 propertyMap.Insert(Toolkit::TextVisual::Property::POINT_SIZE, 15.0f);
606 button.SetProperty(Button::Property::LABEL, propertyMap);
608 DALI_TEST_EQUALS(GetButtonText(button), TEST_LABEL2, TEST_LOCATION);
613 int UtcDaliButtonPressedSignalP(void)
615 ToolkitTestApplication application;
616 tet_infoline(" UtcDaliButtonPressedSignalP");
618 Button button = PushButton::New();
619 button.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
620 button.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
621 button.SetProperty(Actor::Property::POSITION, Vector2(240, 400));
622 button.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
624 application.GetScene().Add(button);
626 application.SendNotification();
627 application.Render();
629 // connect to its touch signal
630 ConnectionTracker* testTracker = new ConnectionTracker();
631 button.PressedSignal().Connect(&ButtonCallback);
632 button.ReleasedSignal().Connect(&ButtonCallback);
633 bool pressedSignal = false;
634 bool releasedSignal = false;
635 button.ConnectSignal(testTracker, "pressed", CallbackFunctor(&pressedSignal));
636 button.ConnectSignal(testTracker, "released", CallbackFunctor(&releasedSignal));
638 Dali::Integration::TouchEvent event;
640 // Test1. Touch point down and up inside the button.
642 gIsCalledButtonCallback = false;
643 event = Dali::Integration::TouchEvent();
644 event.AddPoint(GetPointDownInside());
645 application.ProcessEvent(event);
647 DALI_TEST_CHECK(gIsCalledButtonCallback);
648 DALI_TEST_CHECK(pressedSignal);
650 gIsCalledButtonCallback = false;
651 event = Dali::Integration::TouchEvent();
652 event.AddPoint(GetPointUpInside());
653 application.ProcessEvent(event);
655 DALI_TEST_CHECK(gIsCalledButtonCallback);
656 DALI_TEST_CHECK(releasedSignal);
658 // Test2. Touch point down and up outside the button.
660 pressedSignal = false;
661 releasedSignal = false;
662 gIsCalledButtonCallback = false;
663 event = Dali::Integration::TouchEvent();
664 event.AddPoint(GetPointDownOutside());
665 application.ProcessEvent(event);
667 DALI_TEST_CHECK(!gIsCalledButtonCallback);
668 DALI_TEST_CHECK(!pressedSignal);
670 gIsCalledButtonCallback = false;
671 event = Dali::Integration::TouchEvent();
672 event.AddPoint(GetPointUpOutside());
673 application.ProcessEvent(event);
675 DALI_TEST_CHECK(!gIsCalledButtonCallback);
676 DALI_TEST_CHECK(!releasedSignal);
678 // Test3. Touch point down inside and up outside the button.
680 gIsCalledButtonCallback = false;
681 event = Dali::Integration::TouchEvent();
682 event.AddPoint(GetPointDownInside());
683 application.ProcessEvent(event);
685 DALI_TEST_CHECK(gIsCalledButtonCallback);
687 gIsCalledButtonCallback = false;
688 event = Dali::Integration::TouchEvent();
689 event.AddPoint(GetPointLeave());
690 application.ProcessEvent(event);
692 event = Dali::Integration::TouchEvent();
693 event.AddPoint(GetPointUpOutside());
694 application.ProcessEvent(event);
696 DALI_TEST_CHECK(gIsCalledButtonCallback);
698 // Test4. Touch point down outside and up inside the button.
700 gIsCalledButtonCallback = false;
701 event = Dali::Integration::TouchEvent();
702 event.AddPoint(GetPointDownOutside());
703 application.ProcessEvent(event);
705 DALI_TEST_CHECK(!gIsCalledButtonCallback);
707 gIsCalledButtonCallback = false;
708 event = Dali::Integration::TouchEvent();
709 event.AddPoint(GetPointEnter());
710 application.ProcessEvent(event);
712 event = Dali::Integration::TouchEvent();
713 event.AddPoint(GetPointUpInside());
714 application.ProcessEvent(event);
716 DALI_TEST_CHECK(!gIsCalledButtonCallback);
720 int UtcDaliButtonClickedSignalP(void)
722 ToolkitTestApplication application;
723 tet_infoline(" UtcDaliButtonClickedSignalP");
725 Button button = PushButton::New();
726 button.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
727 button.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
728 button.SetProperty(Actor::Property::POSITION, Vector2(240, 400));
729 button.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
731 application.GetScene().Add(button);
733 application.SendNotification();
734 application.Render();
736 // connect to its touch signal
737 button.ClickedSignal().Connect(&ButtonCallback);
738 bool clickedSignal = false;
739 ConnectionTracker* testTracker = new ConnectionTracker();
740 button.ConnectSignal(testTracker, "clicked", CallbackFunctor(&clickedSignal));
742 Dali::Integration::TouchEvent event;
744 // Test1. Touch point down and up inside the button.
746 gIsCalledButtonCallback = false;
747 event = Dali::Integration::TouchEvent();
748 event.AddPoint(GetPointDownInside());
749 application.ProcessEvent(event);
751 event = Dali::Integration::TouchEvent();
752 event.AddPoint(GetPointUpInside());
753 application.ProcessEvent(event);
755 DALI_TEST_CHECK(gIsCalledButtonCallback);
756 DALI_TEST_CHECK(clickedSignal);
758 // Test2. Touch point down and up outside the button.
760 gIsCalledButtonCallback = false;
761 clickedSignal = false;
762 event = Dali::Integration::TouchEvent();
763 event.AddPoint(GetPointDownOutside());
764 application.ProcessEvent(event);
766 event = Dali::Integration::TouchEvent();
767 event.AddPoint(GetPointUpOutside());
768 application.ProcessEvent(event);
770 DALI_TEST_CHECK(!gIsCalledButtonCallback);
771 DALI_TEST_CHECK(!clickedSignal);
773 // Test3. Touch point down inside and up outside the button.
775 gIsCalledButtonCallback = false;
776 clickedSignal = false;
777 event = Dali::Integration::TouchEvent();
778 event.AddPoint(GetPointDownInside());
779 application.ProcessEvent(event);
781 event = Dali::Integration::TouchEvent();
782 event.AddPoint(GetPointLeave());
783 application.ProcessEvent(event);
785 event = Dali::Integration::TouchEvent();
786 event.AddPoint(GetPointUpOutside());
787 application.ProcessEvent(event);
789 DALI_TEST_CHECK(!gIsCalledButtonCallback);
790 DALI_TEST_CHECK(!clickedSignal);
792 // Test4. Touch point down outside and up inside the button.
794 gIsCalledButtonCallback = false;
795 clickedSignal = false;
796 event = Dali::Integration::TouchEvent();
797 event.AddPoint(GetPointDownOutside());
798 application.ProcessEvent(event);
800 event = Dali::Integration::TouchEvent();
801 event.AddPoint(GetPointEnter());
802 application.ProcessEvent(event);
804 event = Dali::Integration::TouchEvent();
805 event.AddPoint(GetPointUpInside());
806 application.ProcessEvent(event);
808 DALI_TEST_CHECK(!gIsCalledButtonCallback);
809 DALI_TEST_CHECK(!clickedSignal);
813 int UtcDaliButtonStateChangedSignalP(void)
815 ToolkitTestApplication application;
816 tet_infoline(" UtcDaliButtonStateChangedSignalP");
818 Button button = PushButton::New();
820 button.SetProperty(Button::Property::TOGGLABLE, true);
822 application.GetScene().Add(button);
824 application.SendNotification();
825 application.Render();
827 // connect to its signal
828 button.StateChangedSignal().Connect(&ButtonCallback);
829 bool stateChangedSignal = false;
830 ConnectionTracker* testTracker = new ConnectionTracker();
831 button.ConnectSignal(testTracker, "stateChanged", CallbackFunctor(&stateChangedSignal));
833 gIsCalledButtonCallback = false;
834 button.SetProperty(Button::Property::SELECTED, true);
836 DALI_TEST_CHECK(gIsCalledButtonCallback);
837 DALI_TEST_CHECK(stateChangedSignal);
839 gIsCalledButtonCallback = false;
840 stateChangedSignal = false;
842 button.SetProperty(Button::Property::SELECTED, false);
843 DALI_TEST_CHECK(gIsCalledButtonCallback);
844 DALI_TEST_CHECK(stateChangedSignal);
848 int UtcDaliButtonSetProperty(void)
850 tet_infoline("UtcDaliButtonSetProperty: ");
851 ToolkitTestApplication application;
853 PushButton pushButton = PushButton::New();
855 pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), false);
857 DALI_TEST_EQUALS(pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("disabled")), false, TEST_LOCATION);
859 pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), true);
860 DALI_TEST_EQUALS(pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("disabled")), true, TEST_LOCATION);
865 int UtcDaliButtonEventConsumption(void)
871 * Child parented and positioned under parent.
872 * Touch up and down performed on child.
873 * Should only trigger signal on child.
876 ToolkitTestApplication application;
878 Button parentButton = PushButton::New();
879 parentButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
880 parentButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
881 parentButton.SetProperty(Actor::Property::SIZE, Vector2(20, 20));
882 application.GetScene().Add(parentButton);
884 Button childButton = PushButton::New();
885 childButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
886 childButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT);
887 childButton.SetProperty(Actor::Property::SIZE, Vector2(20, 20));
888 parentButton.Add(childButton);
890 // Reset signal flags
891 gIsCalledChildButtonCallback = false;
892 gIsCalledButtonCallback = false;
894 parentButton.ClickedSignal().Connect(&ButtonCallback);
895 childButton.ClickedSignal().Connect(&ChildButtonCallback);
897 // Peform a button click at coordinates (10,30) which is the child.
898 Dali::Integration::TouchEvent event;
899 event = Dali::Integration::TouchEvent();
900 Dali::Integration::Point point;
901 point.SetState(PointState::DOWN);
902 point.SetScreenPosition(Vector2(10, 30));
903 event.AddPoint(point);
904 // flush the queue and render once
905 application.SendNotification();
906 application.Render();
907 application.ProcessEvent(event);
909 event = Dali::Integration::TouchEvent();
910 point.SetState(PointState::UP);
911 point.SetScreenPosition(Vector2(10, 30));
912 event.AddPoint(point);
913 // flush the queue and render once
914 application.SendNotification();
915 application.Render();
916 application.ProcessEvent(event);
918 DALI_TEST_EQUALS(gIsCalledChildButtonCallback, true, TEST_LOCATION);
919 DALI_TEST_EQUALS(!gIsCalledButtonCallback, true, TEST_LOCATION);
924 int UtcDaliButtonRelease(void)
927 * Down event followed by interrupted event should signal Release.
930 ToolkitTestApplication application;
932 Button parentButton = PushButton::New();
933 parentButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
934 parentButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
935 parentButton.SetProperty(Actor::Property::SIZE, Vector2(20, 20));
936 application.GetScene().Add(parentButton);
937 parentButton.ReleasedSignal().Connect(&ButtonCallback);
939 // Reset signal flags
940 gIsCalledButtonCallback = false;
942 // Peform a button down and then button interrupted at coordinates (10,10).
943 Dali::Integration::TouchEvent event;
944 event = Dali::Integration::TouchEvent();
945 Dali::Integration::Point point;
946 point.SetState(PointState::DOWN);
947 point.SetScreenPosition(Vector2(10, 10));
948 event.AddPoint(point);
949 // flush the queue and render once
950 application.SendNotification();
951 application.Render();
952 application.ProcessEvent(event);
954 event = Dali::Integration::TouchEvent();
955 point.SetState(PointState::INTERRUPTED);
956 event.AddPoint(point);
957 // flush the queue and render once
958 application.SendNotification();
959 application.Render();
960 application.ProcessEvent(event);
962 DALI_TEST_EQUALS(gIsCalledButtonCallback, true, TEST_LOCATION);
967 int UtcDaliButtonMultiTouch(void)
970 * Down event followed by a multi touch point event should signal Release.
973 ToolkitTestApplication application;
975 Button button = PushButton::New();
976 button.SetProperty(Button::Property::TOGGLABLE, true);
978 button.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
979 button.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
980 button.SetProperty(Actor::Property::SIZE, Vector2(20, 20));
981 application.GetScene().Add(button);
982 button.ReleasedSignal().Connect(&ButtonCallback);
984 // Reset signal flags
985 gIsCalledButtonCallback = false;
987 // Peform a button down and then button interrupted at coordinates (10,10).
988 Dali::Integration::TouchEvent downEvent;
989 downEvent = Dali::Integration::TouchEvent();
990 Dali::Integration::Point point;
993 point.SetState(PointState::DOWN);
994 point.SetScreenPosition(Vector2(15, 15));
995 downEvent.AddPoint(point);
996 // flush the queue and render once
997 application.SendNotification();
998 application.Render();
999 application.ProcessEvent(downEvent);
1002 Dali::Integration::TouchEvent upEvent;
1003 upEvent = Dali::Integration::TouchEvent();
1004 point.SetState(PointState::UP);
1005 point.SetScreenPosition(Vector2(15, 15));
1006 upEvent.AddPoint(point);
1007 // flush the queue and render once
1008 application.SendNotification();
1009 application.Render();
1010 application.ProcessEvent(upEvent);
1012 tet_infoline("Button should now be selected\n");
1013 bool isSelected = button.GetProperty<bool>(Button::Property::SELECTED);
1014 DALI_TEST_EQUALS(isSelected, true, TEST_LOCATION);
1017 Dali::Integration::TouchEvent multiEvent;
1018 multiEvent = Dali::Integration::TouchEvent();
1019 point.SetState(PointState::DOWN);
1020 point.SetScreenPosition(Vector2(10, 10));
1021 multiEvent.AddPoint(point);
1024 point.SetState(PointState::DOWN);
1025 point.SetScreenPosition(Vector2(15, 15));
1026 multiEvent.AddPoint(point);
1028 tet_infoline("Before a multi touch event\n");
1030 // flush the queue and render once
1031 application.SendNotification();
1032 application.Render();
1033 application.ProcessEvent(multiEvent);
1035 DALI_TEST_EQUALS(gIsCalledButtonCallback, true, TEST_LOCATION);