summaryrefslogtreecommitdiff
path: root/src/tests/elementary/elm_test_widget_focus.c
blob: 46814d092b6aa8e70294e75672d0b5345ac70285 (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
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

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

typedef struct _Simple_Test_Widget
{
   Evas_Object* (*constructor)(Evas_Object *win);
   const char *name;
} Simple_Test_Widget;

static Evas_Object*
_custom_clock(Evas_Object *win)
{
   Evas_Object *o = elm_clock_add(win);
   elm_clock_edit_set(o, EINA_TRUE);
   return o;
}

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 == 2)
     ecore_main_loop_quit();
}

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

static Evas_Object*
_custom_gengrid(Evas_Object *win)
{
   Evas_Object *o;
   Elm_Object_Item *it;
   Elm_Gengrid_Item_Class *itc;

   o = elm_gengrid_add(win);
   evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);

   itc = elm_gengrid_item_class_new();
   itc->func.content_get = _content_get;

   it = elm_gengrid_item_append(o, itc, NULL, NULL, NULL);
   evas_object_smart_callback_add(o, "realized", _realized, it);
   evas_object_size_hint_min_set(o, 200, 200);

   elm_object_item_focus_set(it, EINA_TRUE);
   return o;
}

static Evas_Object*
_custom_genlist(Evas_Object *win)
{
   Evas_Object *o;
   Elm_Object_Item *it;
   Elm_Genlist_Item_Class *itc;

   o = elm_genlist_add(win);
   evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_genlist_mode_set(o, ELM_LIST_COMPRESS);

   itc = elm_genlist_item_class_new();
   itc->func.content_get = _content_get;

   it = elm_genlist_item_append(o, itc, NULL, NULL, 0, NULL, NULL);
   evas_object_smart_callback_add(o, "realized", _realized, it);
   evas_object_size_hint_min_set(o, 200, 200);

   elm_object_item_focus_set(it, EINA_TRUE);
   return o;
}

static Evas_Object*
_custom_list(Evas_Object *win)
{
   Evas_Object *o = elm_list_add(win);
   elm_list_item_append(o, "test", NULL, NULL, NULL, NULL);
   return o;
}

static Evas_Object*
_custom_progressbar(Evas_Object *win)
{
   Evas_Object *o = elm_progressbar_add(win);
   efl_ui_widget_focus_allow_set(o, EINA_TRUE);
   return o;
}

static Evas_Object*
_custom_colorselector_add(Evas_Object *win)
{
   Evas_Object *o = elm_colorselector_add(win);
   Elm_Object_Item *item = elm_colorselector_palette_color_add(o, 0, 0, 0, 255);
   elm_colorselector_palette_color_add(o, 255, 255, 255, 255);
   elm_colorselector_palette_item_selected_set(item, EINA_TRUE);
   return o;
}

static const Simple_Test_Widget simple_widgets[] = {
  {elm_button_add, "button"},
  {elm_check_add, "check"},
  {elm_radio_add, "radio"},
  {elm_diskselector_add, "diskselector"},
  {elm_entry_add, "entry"},
  {elm_flipselector_add, "flipselector"},
  {elm_video_add, "video"},
  {elm_spinner_add, "spinner"},
  {elm_multibuttonentry_add, "mbe"},
  {elm_fileselector_add, "fileselector"},
  {elm_fileselector_button_add, "fileselector_button"},
  {elm_fileselector_entry_add, "fileselector_entry"},
  {_custom_clock, "clock"},
  {elm_toolbar_add, "toolbar"},
  {elm_gengrid_add, "gengrid1"},
  {elm_genlist_add, "genlist1"},
  {_custom_gengrid, "gengrid2"},
  {_custom_genlist, "genlist2"},
  {elm_list_add, "list1"},
  {_custom_list, "list2"},
  {elm_scroller_add, "scroller"},
  {elm_photocam_add, "photocam"},
  {_custom_progressbar, "progressbar"},
  {elm_web_add, "web"},
  {elm_colorselector_add, "colorselector"},
  {_custom_colorselector_add, "colorselector2"},
  {elm_slideshow_add, "slideshow"},
  {elm_map_add, "map"},
  {NULL, NULL},
};

static void
_eventing_test(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Eina_Bool *val = data;

   *val = EINA_TRUE;
}

EFL_START_TEST(elm_test_widget_focus_simple_widget)
{
   Evas_Object *win, *box, *resettor, *o;
   Eina_Hash *map;

   map = eina_hash_string_small_new(NULL);
   win = win_add_focused(NULL, "focus test", ELM_WIN_BASIC);

   box = elm_box_add(win);
   elm_win_resize_object_add(win, box);
   evas_object_show(box);

   resettor = o = elm_button_add(win);
   elm_box_pack_end(box, o);
   evas_object_show(o);
   elm_object_focus_set(o, EINA_TRUE);

   for (int i = 0; simple_widgets[i].name; ++i)
     {
        o = simple_widgets[i].constructor(win);
        evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
        elm_box_pack_end(box, o);
        evas_object_show(o);

        eina_hash_add(map, &simple_widgets[i].name, o);
      }
   evas_object_resize(win, 200, 200);

   evas_object_show(win);

   get_me_to_those_events(win);

   for (int i = 0; simple_widgets[i].name; ++i)
      {
         Eina_Bool flag_focused = EINA_FALSE, flag_unfocused = EINA_FALSE;

         printf("Testing %s\n", simple_widgets[i].name);

         o = eina_hash_find(map, &simple_widgets[i].name);
         evas_object_smart_callback_add(o, "focused", _eventing_test, &flag_focused);
         evas_object_smart_callback_add(o, "unfocused", _eventing_test, &flag_unfocused);
         elm_object_focus_set(o, EINA_TRUE);

         ck_assert_int_eq(flag_focused, EINA_TRUE);
         ck_assert_int_eq(flag_unfocused, EINA_FALSE);
         ck_assert_int_eq(elm_object_focus_get(o), EINA_TRUE);
         ck_assert_int_eq(elm_object_focus_get(resettor), EINA_FALSE);

         elm_object_focus_set(resettor, EINA_TRUE);
         ck_assert_int_eq(flag_focused, EINA_TRUE);
         ck_assert_int_eq(flag_unfocused, EINA_TRUE);
         ck_assert_int_eq(elm_object_focus_get(resettor), EINA_TRUE);
         ck_assert_int_eq(elm_object_focus_get(o), EINA_FALSE);
      }

   eina_hash_free(map);
}
EFL_END_TEST


void elm_test_widget_focus(TCase *tc)
{
   tcase_add_test(tc, elm_test_widget_focus_simple_widget);
}