summaryrefslogtreecommitdiff
path: root/src/tests/elementary/elm_test_gengrid.c
blob: 77a4eb46f7fc6d1340a06300a48799ec5c563a35 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

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

static Elm_Gengrid_Item_Class *gic = NULL;

EFL_START_TEST(elm_gengrid_legacy_type_check)
{
   Evas_Object *win, *gengrid;
   const char *type;

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

   gengrid = elm_gengrid_add(win);

   type = elm_object_widget_type_get(gengrid);
   ck_assert(type != NULL);
   ck_assert(!strcmp(type, "Elm_Gengrid"));

   type = evas_object_type_get(gengrid);
   ck_assert(type != NULL);
   ck_assert(!strcmp(type, "elm_gengrid"));

}
EFL_END_TEST

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

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

   gengrid = elm_gengrid_add(win);
   role = efl_access_object_role_get(gengrid);

   ck_assert(role == EFL_ACCESS_ROLE_TREE_TABLE);

}
EFL_END_TEST

// Temporary commnted since gengrid fields_update function do not call content callbacks
// (different behaviour then genlist - which calls)
#if 0
static Evas_Object *content;

static Evas_Object *
gl_content_get(void *data EINA_UNUSED, Evas_Object *obj, const char *part EINA_UNUSED)
{
   content = elm_gengrid_add(obj);
   evas_object_show(content);
   return content;
}

/**
 * Validate if gengrid implementation properly reset AT-SPI parent to Elm_Gengrid_Item
 * from Elm_Gengrid
 */
EFL_START_TEST(elm_atspi_children_parent)
{
   elm_config_atspi_mode_set(EINA_TRUE);
   static Elm_Gengrid_Item_Class itc;

   Evas_Object *win = win_add(NULL, "gengrid", ELM_WIN_BASIC);
   evas_object_resize(win, 100, 100);
   Evas_Object *gengrid = elm_gengrid_add(win);
   evas_object_resize(gengrid, 100, 100);

   Efl_Access_Object *parent;
   content = NULL;

   itc.item_style = "default";
   itc.func.content_get = gl_content_get;

   evas_object_show(win);
   evas_object_show(gengrid);

   Elm_Object_Item *it = elm_gengrid_item_append(gengrid, &itc, NULL, NULL, NULL);
   elm_gengrid_item_fields_update(it, "*.", ELM_GENGRID_ITEM_FIELD_CONTENT);

   ck_assert(content != NULL);
   parent = efl_provider_find(efl_parent_get(content), EFL_ACCESS_OBJECT_MIXIN);
   ck_assert(it == parent);

}
EFL_END_TEST
#endif

static void
_realized(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   static int i = 0;

   i++;
   //we have two items - each of them are getting realized unrealized and again realized.
   if (i == 4)
     ecore_main_loop_quit();
}

EFL_START_TEST(elm_gengrid_focus)
{
   Evas_Object *win, *grid, *bx, *bt;
   Elm_Object_Item *it;

   win = win_add_focused();

   bx = elm_box_add(win);
   evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_win_resize_object_add(win, bx);
   evas_object_show(bx);

   grid = elm_gengrid_add(win);
   elm_gengrid_item_size_set(grid, 10, 10);
   evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
   evas_object_size_hint_min_set(grid, 600, 600);

   elm_box_pack_end(bx, grid);
   evas_object_show(grid);

   gic = elm_gengrid_item_class_new();
   gic->item_style = "default";

   elm_gengrid_item_append(grid, gic, NULL, NULL, NULL);
   elm_gengrid_item_append(grid, gic, NULL, NULL, NULL);
   elm_gengrid_item_append(grid, gic, NULL, NULL, NULL);
   it = elm_gengrid_item_append(grid, gic, NULL, NULL, NULL);
   evas_object_smart_callback_add(grid, "realized", _realized, NULL);

   elm_object_item_focus_set(it, EINA_TRUE);
   elm_object_focus_set(grid, EINA_TRUE);

   bt = elm_button_add(win);
   elm_box_pack_end(bx, bt);
   evas_object_show(bt);

   evas_object_resize(win, 600, 600);
   evas_object_show(win);

   ecore_main_loop_begin();

   ck_assert_ptr_eq(elm_object_focused_item_get(grid), it);
   elm_object_focus_set(bt, EINA_TRUE);
   ck_assert_ptr_eq(elm_object_focused_item_get(grid), NULL);
   ck_assert_int_eq(elm_object_focus_get(grid), EINA_FALSE);
   elm_object_focus_set(grid, EINA_TRUE);
   ck_assert_ptr_eq(elm_object_focused_item_get(grid), it);
   ck_assert_int_eq(elm_object_focus_get(grid), EINA_TRUE);
}
EFL_END_TEST

static void
_gengrid_item_content_test_realize(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   ecore_main_loop_quit();
}

static Evas_Object *
_item_content_get(void *data EINA_UNUSED, Evas_Object *obj, const char *part EINA_UNUSED)
{
   Evas_Object *ic = elm_button_add(obj);
   return ic;
}

EFL_START_TEST(elm_gengrid_item_content)
{
   Evas_Object *win, *gengrid;
   Elm_Genlist_Item_Class *gtc;
   Evas_Object *content, *parent;
   Elm_Object_Item *it;

   gtc = elm_gengrid_item_class_new();
   gtc->item_style = "default";
   gtc->func.content_get = _item_content_get;
   gtc->func.state_get = NULL;
   gtc->func.del = NULL;

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

   gengrid = elm_gengrid_add(win);
   evas_object_smart_callback_add(gengrid, "realized", _gengrid_item_content_test_realize, NULL);

   it = elm_gengrid_item_append(gengrid, gtc, NULL, NULL, NULL);

   evas_object_resize(gengrid, 100, 100);
   evas_object_resize(win, 150, 150);
   evas_object_show(gengrid);
   evas_object_show(win);

   ecore_main_loop_begin();

   content = elm_object_item_part_content_get(it, "elm.swallow.end");
   parent = elm_object_parent_widget_get(content);
   ck_assert_ptr_eq(parent, gengrid);

   elm_gengrid_item_all_contents_unset(it, NULL);
   parent = elm_object_parent_widget_get(content);
   ck_assert_ptr_eq(parent, win);
}
EFL_END_TEST

void elm_test_gengrid(TCase *tc)
{
   tcase_add_test(tc, elm_gengrid_legacy_type_check);
   tcase_add_test(tc, elm_atspi_role_get);
   tcase_add_test(tc, elm_gengrid_focus);
   tcase_add_test(tc, elm_gengrid_item_content);
#if 0
   tcase_add_test(tc, elm_atspi_children_parent);
#endif
}