summaryrefslogtreecommitdiff
path: root/src/tests/elementary/elm_test_layout.c
blob: d08b9cb0d876811466a68e2be9e4b44dfcf18b6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#define EFL_ACCESS_OBJECT_BETA
#include <Elementary.h>
#include "elm_suite.h"

EFL_START_TEST(elm_layout_test_legacy_type_check)
{
   Evas_Object *win, *layout;
   const char *type;

   win = win_add(NULL, "layout", ELM_WIN_BASIC);

   layout = elm_layout_add(win);

   type = elm_object_widget_type_get(layout);
   ck_assert(type != NULL);
   ck_assert(!strcmp(type, "Elm_Layout"));

   type = evas_object_type_get(layout);
   ck_assert(type != NULL);
   ck_assert(!strcmp(type, "elm_layout"));

}
EFL_END_TEST

EFL_START_TEST(elm_atspi_role_get)
{
   Evas_Object *win, *layout;
   Efl_Access_Role role;

   win = win_add(NULL, "layout", ELM_WIN_BASIC);

   layout = elm_layout_add(win);
   role = efl_access_object_role_get(layout);

   ck_assert(role == EFL_ACCESS_ROLE_FILLER);

}
EFL_END_TEST

EFL_START_TEST(elm_layout_test_swallows)
{
   char buf[PATH_MAX];
   Evas_Object *win, *ly, *bt, *bt2;

   win = win_add(NULL, "layout", ELM_WIN_BASIC);

   ly = elm_layout_add(win);
   snprintf(buf, sizeof(buf), "%s/objects/test.edj", ELM_TEST_DATA_DIR);
   elm_layout_file_set(ly, buf, "layout");
   evas_object_show(ly);

   bt = elm_button_add(ly);
   fail_if(!elm_layout_content_set(ly, "element1", bt));
   ck_assert_ptr_eq(efl_parent_get(bt), ly);

   bt = elm_object_part_content_unset(ly, "element1");
   ck_assert_ptr_eq(efl_parent_get(bt), evas_object_evas_get(bt));

   fail_if(!elm_layout_content_set(ly, "element1", bt));
   ck_assert_ptr_eq(efl_parent_get(bt), ly);

   bt2 = elm_button_add(ly);
   fail_if(!elm_layout_content_set(ly, "element1", bt2));
   ck_assert_ptr_eq(efl_parent_get(bt2), ly);

}
EFL_END_TEST

EFL_START_TEST(elm_layout_test_sizing)
{
   Evas_Object *win, *ly, *rect;
   int w, h;

   win = win_add(NULL, "layout", ELM_WIN_BASIC);
   evas_object_show(win);

   rect = evas_object_rectangle_add(evas_object_evas_get(win));

   ly = elm_button_add(win);
   elm_object_text_set(ly, "test");
   elm_object_content_set(ly, rect);
   evas_object_show(ly);

   /* verify that the button calc is the size of the text */
   evas_object_smart_need_recalculate_set(ly, 1);
   evas_object_smart_calculate(ly);
   evas_object_size_hint_min_get(ly, &w, &h);
   ck_assert_int_lt(w, 100);
   ck_assert_int_gt(w, 0);
   ck_assert_int_lt(h, 100);
   ck_assert_int_gt(h, 0);

   /* verify that the button calc is the size of the text + minsize of rect */
   evas_object_size_hint_min_set(rect, 100, 100);
   evas_object_smart_need_recalculate_set(ly, 1);
   evas_object_smart_calculate(ly);
   evas_object_size_hint_min_get(ly, &w, &h);
   ck_assert_int_ge(w, 100);
   ck_assert_int_ge(h, 100);

   /* verify that the button calc is once again the size of the text */
   evas_object_size_hint_min_set(rect, 0, 0);
   evas_object_smart_need_recalculate_set(ly, 1);
   evas_object_smart_calculate(ly);
   evas_object_size_hint_min_get(ly, &w, &h);
   ck_assert_int_lt(w, 100);
   ck_assert_int_gt(w, 0);
   ck_assert_int_lt(h, 100);
   ck_assert_int_gt(h, 0);
}
EFL_END_TEST

EFL_START_TEST(elm_layout_test_theme_changed_callback)
{
   Evas_Object *win, *ly;
   int called = 0;

   win = win_add(NULL, "layout", ELM_WIN_BASIC);
   evas_object_show(win);

   ly = elm_button_add(win);
   evas_object_smart_callback_add(ly, "theme,changed", event_callback_single_call_int_data, &called);
   evas_object_show(ly);
   elm_object_style_set(ly, "anchor");
   ck_assert_int_eq(called, 1);
}
EFL_END_TEST

void elm_test_layout(TCase *tc)
{
   tcase_add_test(tc, elm_layout_test_legacy_type_check);
   tcase_add_test(tc, elm_atspi_role_get);
   tcase_add_test(tc, elm_layout_test_swallows);
   tcase_add_test(tc, elm_layout_test_sizing);
   tcase_add_test(tc, elm_layout_test_theme_changed_callback);
}