summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2019-08-08 14:37:39 -0400
committerCedric BAIL <cedric.bail@free.fr>2019-08-09 10:25:35 -0700
commit189ddd9c818e58ca8679a4c0b722ab487c8a55cc (patch)
tree2e9b9837af27acc23e4275216695544f9e6f9bc1 /src/tests
parent2c33744a8adb6c13f041fa7581ab4e808034541e (diff)
tests/popup: add (extremely) comprehensive test for anchor popups
this verifies all align settings, different anchor points, changing anchors and aligns on-the-fly, unsetting anchors, and changing popup sizes Reviewed-by: Cedric BAIL <cedric.bail@free.fr> Differential Revision: https://phab.enlightenment.org/D9526
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/elementary/efl_ui_test_popup.c343
1 files changed, 343 insertions, 0 deletions
diff --git a/src/tests/elementary/efl_ui_test_popup.c b/src/tests/elementary/efl_ui_test_popup.c
index 8537549f9d..844520357f 100644
--- a/src/tests/elementary/efl_ui_test_popup.c
+++ b/src/tests/elementary/efl_ui_test_popup.c
@@ -10,6 +10,12 @@
10#define POPUP_SIZE 160 10#define POPUP_SIZE 160
11#define POPUP_SIZE_EXPAND POPUP_SIZE * 2 11#define POPUP_SIZE_EXPAND POPUP_SIZE * 2
12 12
13#define POPUP_ANCHOR_BUTTON_SIZE_VERT 35
14/* top row */
15#define POPUP_ANCHOR_BUTTON_SIZE_HORIZ1 70
16/* middle and bottom row */
17#define POPUP_ANCHOR_BUTTON_SIZE_HORIZ2 100
18
13static Eo * 19static Eo *
14_popup_layout_create(Eo *popup) 20_popup_layout_create(Eo *popup)
15{ 21{
@@ -540,6 +546,342 @@ EFL_START_TEST(efl_ui_test_popup_text_alert)
540} 546}
541EFL_END_TEST 547EFL_END_TEST
542 548
549static void
550_align_cb(void *data, const Efl_Event *ev)
551{
552 Efl_Ui_Popup_Align align = (uintptr_t)data;
553 Eo *popup = efl_ui_widget_parent_get(efl_ui_widget_parent_get(ev->object));
554 efl_ui_popup_align_set(popup, align);
555}
556
557typedef enum
558{
559 ALIGN_CENTER = 0,
560 ALIGN_TOP,
561 ALIGN_BOTTOM,
562 ALIGN_LEFT,
563 ALIGN_RIGHT,
564 ALIGN_POSITION,
565 ALIGN_RESIZE,
566} Align;
567
568static inline Align
569popup_prio_to_align(Efl_Ui_Popup_Align pa)
570{
571 switch (pa)
572 {
573 case EFL_UI_POPUP_ALIGN_CENTER:
574 return ALIGN_CENTER;
575 case EFL_UI_POPUP_ALIGN_LEFT:
576 return ALIGN_LEFT;
577 case EFL_UI_POPUP_ALIGN_RIGHT:
578 return ALIGN_RIGHT;
579 case EFL_UI_POPUP_ALIGN_TOP:
580 return ALIGN_TOP;
581 case EFL_UI_POPUP_ALIGN_BOTTOM:
582 return ALIGN_BOTTOM;
583 default: break;
584 }
585 printf("FAIL\n");
586 abort();
587}
588
589static Eina_Bool
590can_move_x(Align align)
591{
592 if (align == ALIGN_LEFT) return EINA_FALSE;
593 if (align == ALIGN_RIGHT) return EINA_FALSE;
594 return EINA_TRUE;
595}
596
597static Eina_Bool
598can_move_y(Align align)
599{
600 if (align == ALIGN_TOP) return EINA_FALSE;
601 if (align == ALIGN_BOTTOM) return EINA_FALSE;
602 return EINA_TRUE;
603}
604
605#undef COORDS_INSIDE
606#define COORDS_INSIDE(x, y, xx, yy, ww, hh) \
607 (((x) < ((xx) + (ww))) && ((y) < ((yy) + (hh))) && ((x) >= (xx)) && ((y) >= (yy)))
608#define CONTAINS(x, y, w, h, xx, yy, ww, hh) \
609 (((xx) >= (x)) && (((x) + (w)) >= ((xx) + (ww))) && ((yy) >= (y)) && (((y) + (h)) >= ((yy) + (hh))))
610#define INTERSECTS(x, y, w, h, xx, yy, ww, hh) \
611 (((x) < ((xx) + (ww))) && ((y) < ((yy) + (hh))) && (((x) + (w)) > (xx)) && (((y) + (h)) > (yy)))
612
613#define OFF_LEFT(x) \
614 ((x) < 0)
615#define OFF_TOP(y) \
616 ((y) < 0)
617#define OFF_RIGHT(x, w, ww) \
618 ((x) + (w) > (ww))
619#define OFF_BOTTOM(y, h, hh) \
620 ((y) + (h) > (hh))
621
622static void
623verify_anchor(Eo *popup, Eo **align_buttons, Align align, Eina_Size2D *popup_sz)
624{
625 Eo *anchor = efl_ui_anchor_popup_anchor_get(popup);
626 Eo *win = efl_provider_find(popup, EFL_UI_WIN_CLASS);
627 Eina_Rect anchor_geom;
628 Efl_Ui_Popup_Align cur_prio;
629
630 Eina_Rect win_geom = efl_gfx_entity_geometry_get(win);
631
632 if (anchor)
633 anchor_geom = efl_gfx_entity_geometry_get(anchor);
634 else
635 anchor_geom = win_geom;
636
637 Evas_Coord x, y;
638
639 /* click the button to trigger changing the align on the popup
640 * this could be done manually, but we're trying to copy the elm_test case
641 */
642 click_object(align_buttons[align]);
643 /* spin main loop to ensure edje signal and event propagation */
644 ecore_main_loop_iterate();
645 /* manually calc popup to verify */
646 efl_canvas_group_calculate(popup);
647
648 cur_prio = efl_ui_popup_align_get(popup);
649
650 Efl_Ui_Popup_Align prio[] =
651 {
652 cur_prio,
653 EFL_UI_POPUP_ALIGN_TOP,
654 EFL_UI_POPUP_ALIGN_BOTTOM,
655 EFL_UI_POPUP_ALIGN_LEFT,
656 EFL_UI_POPUP_ALIGN_RIGHT,
657 EFL_UI_POPUP_ALIGN_CENTER
658 };
659 unsigned int i;
660
661 /* popup anchor (currently) attempts to apply an align using the existing anchor
662 * constraint checking fails in two cases:
663 * - popup is outside the window
664 * - popup is not exactly aligned to anchor
665 *
666 * if either of these cases occur, the next priority in the priority list will be used
667 * UNLESS the align is CENTER, in which case the popup may be adjusted
668 */
669 for (i = 0; i < EINA_C_ARRAY_LENGTH(prio); i++)
670 {
671 if (i && (prio[i] == cur_prio)) continue;
672 Align cur_align = popup_prio_to_align(prio[i]);
673 switch (cur_align)
674 {
675 /* allow x/y adjust, permit covering anchor */
676 case ALIGN_CENTER:
677 x = anchor_geom.x + ((anchor_geom.w - popup_sz->w) / 2);
678 y = anchor_geom.y + ((anchor_geom.h - popup_sz->h) / 2);
679 break;
680
681 /* allow x adjust, do not permit covering anchor */
682 case ALIGN_TOP:
683 x = anchor_geom.x + ((anchor_geom.w - popup_sz->w) / 2);
684 y = anchor_geom.y - popup_sz->h;
685 break;
686 /* allow x adjust, do not permit covering anchor */
687 case ALIGN_BOTTOM:
688 x = anchor_geom.x + ((anchor_geom.w - popup_sz->w) / 2);
689 y = anchor_geom.y + anchor_geom.h;
690 break;
691 /* allow y adjust, do not permit covering anchor */
692 case ALIGN_LEFT:
693 x = anchor_geom.x - popup_sz->w;
694 y = anchor_geom.y + ((anchor_geom.h - popup_sz->h) / 2);
695 break;
696 /* allow y adjust, do not permit covering anchor */
697 case ALIGN_RIGHT:
698 x = anchor_geom.x + anchor_geom.w;
699 y = anchor_geom.y + ((anchor_geom.h - popup_sz->h) / 2);
700 break;
701 default: break;
702 }
703 if ((!anchor) || can_move_x(cur_align))
704 {
705 /* verify that popups not anchored to the win object are inside the window;
706 * clamp to window if necessary
707 */
708 if (!CONTAINS(0, 0, win_geom.w, win_geom.h, x, y, popup_sz->w, popup_sz->h))
709 { if (OFF_LEFT(x)) x = 0; }
710 if (!CONTAINS(0, 0, win_geom.w, win_geom.h, x, y, popup_sz->w, popup_sz->h))
711 { if (OFF_RIGHT(x, popup_sz->w, win_geom.w)) x = win_geom.w - popup_sz->w; }
712 }
713 if ((!anchor) || can_move_y(cur_align))
714 {
715 /* verify that popups not anchored to the win object are inside the window;
716 * clamp to window if necessary
717 */
718 if (!CONTAINS(0, 0, win_geom.w, win_geom.h, x, y, popup_sz->w, popup_sz->h))
719 { if (OFF_TOP(y)) y = 0; }
720 if (!CONTAINS(0, 0, win_geom.w, win_geom.h, x, y, popup_sz->w, popup_sz->h))
721 { if (OFF_BOTTOM(y, popup_sz->h, win_geom.h)) y = win_geom.h - popup_sz->h; }
722 }
723 /* if the popup is not allowed to be clamped on a given axis, try a different align */
724 if (!CONTAINS(0, 0, win_geom.w, win_geom.h, x, y, popup_sz->w, popup_sz->h)) continue;
725 /* no further clamping for center aligns since this permits popups to be placed over the anchor */
726 if (align == ALIGN_CENTER) break;
727 /* no further clamping if the anchor is the win object since the popup will always be placed in the window */
728 if (!anchor) break;
729 /* verify clamping on X-axis */
730 if (can_move_x(cur_align))
731 {
732 if ((x > anchor_geom.x + anchor_geom.w) || (x + popup_sz->w < anchor_geom.x)) continue;
733 }
734 /* verify clamping on Y-axis */
735 if (can_move_y(cur_align))
736 {
737 if ((y > anchor_geom.y + anchor_geom.h) || (y + popup_sz->h < anchor_geom.y)) continue;
738 }
739 break;
740 }
741
742 Eina_Position2D popup_pos = efl_gfx_entity_position_get(popup);
743 ck_assert_int_eq(x, popup_pos.x);
744 ck_assert_int_eq(y, popup_pos.y);
745}
746
747EFL_START_TEST(efl_ui_test_popup_text_anchor)
748{
749 Eo *win, *popup, *layout;
750 char buf[PATH_MAX];
751 int i, num_anchors = 6;
752
753 win = win_add();
754 efl_gfx_entity_size_set(win, EINA_SIZE2D(WIN_SIZE, WIN_SIZE));
755
756 layout = efl_add(EFL_UI_LAYOUT_CLASS, win);
757 snprintf(buf, sizeof(buf), "%s/objects/test.edj", ELM_TEST_DATA_DIR);
758 ck_assert(efl_file_simple_load(layout, buf, "efl_ui_popup_anchor_layout"));
759 efl_content_set(win, layout);
760
761 popup = efl_add(EFL_UI_ANCHOR_POPUP_CLASS, win);
762 efl_ui_popup_part_backwall_repeat_events_set(efl_part(popup, "backwall"), EINA_TRUE);
763 //Default align priority order is top, left, right, bottom, center.
764 efl_ui_anchor_popup_align_priority_set(popup, EFL_UI_POPUP_ALIGN_TOP,
765 EFL_UI_POPUP_ALIGN_BOTTOM,
766 EFL_UI_POPUP_ALIGN_LEFT,
767 EFL_UI_POPUP_ALIGN_RIGHT,
768 EFL_UI_POPUP_ALIGN_CENTER);
769
770 Eo *btn, *bganchors[num_anchors], *aligns[7];
771 for (i = 0; i < num_anchors; i++)
772 {
773 btn = bganchors[i] = efl_add(EFL_UI_BUTTON_CLASS, win);
774 efl_text_set(btn, "anchor");
775 //efl_event_callback_add(btn, EFL_INPUT_EVENT_CLICKED, _anchor_set_cb, popup);
776
777 snprintf(buf, sizeof(buf), "anchor%d", i+1);
778 efl_content_set(efl_part(layout, buf), btn);
779 }
780
781 btn = efl_add(EFL_UI_BUTTON_CLASS, win);
782 efl_text_set(btn, "anchor none");
783 //efl_event_callback_add(btn, EFL_INPUT_EVENT_CLICKED, _anchor_unset_cb, popup);
784 efl_content_set(efl_part(layout, "anchor_none"), btn);
785
786 Eo *table = efl_add(EFL_UI_TABLE_CLASS, popup);
787 efl_gfx_hint_weight_set(table, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
788
789 i = 0;
790
791 aligns[i++] = btn = efl_add(EFL_UI_BUTTON_CLASS, popup);
792 efl_text_set(btn, "Center Align");
793 efl_gfx_hint_size_min_set(btn, EINA_SIZE2D(POPUP_ANCHOR_BUTTON_SIZE_HORIZ1, POPUP_ANCHOR_BUTTON_SIZE_VERT));
794 efl_event_callback_add(btn, EFL_INPUT_EVENT_CLICKED, _align_cb, (intptr_t*)EFL_UI_POPUP_ALIGN_CENTER);
795 efl_pack_table(table, btn, 0, 0, 2, 1);
796
797 aligns[i++] = btn = efl_add(EFL_UI_BUTTON_CLASS, popup);
798 efl_text_set(btn, "Top Align");
799 efl_gfx_hint_size_min_set(btn, EINA_SIZE2D(POPUP_ANCHOR_BUTTON_SIZE_HORIZ1, POPUP_ANCHOR_BUTTON_SIZE_VERT));
800 efl_event_callback_add(btn, EFL_INPUT_EVENT_CLICKED, _align_cb, (intptr_t*)EFL_UI_POPUP_ALIGN_TOP);
801 efl_pack_table(table, btn, 2, 0, 2, 1);
802
803 aligns[i++] = btn = efl_add(EFL_UI_BUTTON_CLASS, popup);
804 efl_text_set(btn, "Bottom Align");
805 efl_gfx_hint_size_min_set(btn, EINA_SIZE2D(POPUP_ANCHOR_BUTTON_SIZE_HORIZ1, POPUP_ANCHOR_BUTTON_SIZE_VERT));
806 efl_event_callback_add(btn, EFL_INPUT_EVENT_CLICKED, _align_cb, (intptr_t*)EFL_UI_POPUP_ALIGN_BOTTOM);
807 efl_pack_table(table, btn, 4, 0, 2, 1);
808
809 aligns[i++] = btn = efl_add(EFL_UI_BUTTON_CLASS, popup);
810 efl_text_set(btn, "Left Align");
811 efl_gfx_hint_size_min_set(btn, EINA_SIZE2D(POPUP_ANCHOR_BUTTON_SIZE_HORIZ2, POPUP_ANCHOR_BUTTON_SIZE_VERT));
812 efl_event_callback_add(btn, EFL_INPUT_EVENT_CLICKED, _align_cb, (intptr_t*)EFL_UI_POPUP_ALIGN_LEFT);
813 efl_pack_table(table, btn, 0, 1, 3, 1);
814
815 aligns[i++] = btn = efl_add(EFL_UI_BUTTON_CLASS, popup);
816 efl_text_set(btn, "Right Align");
817 efl_gfx_hint_size_min_set(btn, EINA_SIZE2D(POPUP_ANCHOR_BUTTON_SIZE_HORIZ2, POPUP_ANCHOR_BUTTON_SIZE_VERT));
818 efl_event_callback_add(btn, EFL_INPUT_EVENT_CLICKED, _align_cb, (intptr_t*)EFL_UI_POPUP_ALIGN_RIGHT);
819 efl_pack_table(table, btn, 3, 1, 3, 1);
820
821 aligns[i++] = btn = efl_add(EFL_UI_BUTTON_CLASS, popup);
822 efl_text_set(btn, "Position Set");
823 efl_gfx_hint_size_min_set(btn, EINA_SIZE2D(POPUP_ANCHOR_BUTTON_SIZE_HORIZ2, POPUP_ANCHOR_BUTTON_SIZE_VERT));
824 /* this is done manually */
825 //efl_event_callback_add(btn, EFL_INPUT_EVENT_CLICKED, _position_set_cb, popup);
826 efl_pack_table(table, btn, 0, 2, 3, 1);
827
828 aligns[i++] = btn = efl_add(EFL_UI_BUTTON_CLASS, popup);
829 efl_text_set(btn, "Resize");
830 efl_gfx_hint_size_min_set(btn, EINA_SIZE2D(POPUP_ANCHOR_BUTTON_SIZE_HORIZ2, POPUP_ANCHOR_BUTTON_SIZE_VERT));
831 /* this is done manually */
832 //efl_event_callback_add(btn, EFL_INPUT_EVENT_CLICKED, _popup_resize_cb, popup);
833 efl_pack_table(table, btn, 3, 2, 3, 1);
834
835 efl_content_set(popup, table);
836
837 get_me_to_those_events(popup);
838
839 Eina_Size2D popup_sz = efl_gfx_entity_size_get(popup);
840 /* popup should be at least the size of the table, which is the size of the buttons */
841 ck_assert_int_ge(popup_sz.w, 2 * POPUP_ANCHOR_BUTTON_SIZE_HORIZ2);
842 ck_assert_int_ge(popup_sz.h, 3 * POPUP_ANCHOR_BUTTON_SIZE_VERT);
843
844 for (unsigned int sizes = 0; sizes < 2; sizes++)
845 {
846 if (sizes > 0)
847 {
848 /* increase size of buttons to make popup larger and test different constrain codepaths */
849 for (unsigned int j = 0; j < ALIGN_RESIZE; j++)
850 {
851 Eina_Size2D min_sz = efl_gfx_hint_size_min_get(aligns[j]);
852 min_sz.w += min_sz.w / 2;
853 min_sz.h += min_sz.h / 2;
854 efl_gfx_hint_size_min_set(aligns[j], min_sz);
855 }
856 efl_canvas_group_calculate(table);
857 efl_canvas_group_calculate(popup);
858
859 popup_sz = efl_gfx_entity_size_get(popup);
860 /* popup should be at least the size of the table, which is the size of the buttons */
861 ck_assert_int_ge(popup_sz.w, 2 * (POPUP_ANCHOR_BUTTON_SIZE_HORIZ2 + sizes * (POPUP_ANCHOR_BUTTON_SIZE_HORIZ2 / 2)));
862 ck_assert_int_ge(popup_sz.h, 3 * (POPUP_ANCHOR_BUTTON_SIZE_VERT + sizes * (POPUP_ANCHOR_BUTTON_SIZE_VERT / 2)));
863 }
864 for (i = -1; i < num_anchors; i++)
865 {
866 if (i >= 0) efl_ui_anchor_popup_anchor_set(popup, bganchors[i]);
867 /* -1 is anchored to win object */
868 else efl_ui_anchor_popup_anchor_set(popup, NULL);
869 for (unsigned int j = 0; j < ALIGN_RESIZE; j++)
870 {
871 verify_anchor(popup, aligns, j, &popup_sz);
872 }
873 }
874 }
875 /* this should unset the anchor completely */
876 efl_gfx_entity_position_set(popup, EINA_POSITION2D(0, 0));
877 efl_canvas_group_calculate(popup);
878 /* verify that the popup doesn't reuse its previous anchor */
879 Eina_Position2D popup_pos = efl_gfx_entity_position_get(popup);
880 ck_assert_int_eq(popup_pos.x, 0);
881 ck_assert_int_eq(popup_pos.y, 0);
882}
883EFL_END_TEST
884
543void efl_ui_test_popup(TCase *tc) 885void efl_ui_test_popup(TCase *tc)
544{ 886{
545 tcase_add_test(tc, efl_ui_test_popup_events); 887 tcase_add_test(tc, efl_ui_test_popup_events);
@@ -550,4 +892,5 @@ void efl_ui_test_popup(TCase *tc)
550 tcase_add_test(tc, efl_ui_test_popup_scroll_alert); 892 tcase_add_test(tc, efl_ui_test_popup_scroll_alert);
551 tcase_add_test(tc, efl_ui_test_popup_scroll_alert_expand); 893 tcase_add_test(tc, efl_ui_test_popup_scroll_alert_expand);
552 tcase_add_test(tc, efl_ui_test_popup_text_alert); 894 tcase_add_test(tc, efl_ui_test_popup_text_alert);
895 tcase_add_test(tc, efl_ui_test_popup_text_anchor);
553} 896}