summaryrefslogtreecommitdiff
path: root/src/tests/elementary/elm_test_image.c
blob: 6d6ff52f6fd4ea294e02cb72ed9869bb112b8868 (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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

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

static const char pathfmt[] =  ELM_IMAGE_DATA_DIR"/images/icon_%02d.png";
static const char invalid[] = "thereisnosuchimage.png";
#define MAX_IMAGE_ID 23

typedef struct _Test_Data Test_Data;
struct _Test_Data
{
   int image_id;
   int success;
};

EFL_START_TEST(elm_image_legacy_type_check)
{
   Evas_Object *win, *image;
   const char *type;

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

   image = elm_image_add(win);

   type = elm_object_widget_type_get(image);
   ck_assert(type != NULL);
   ck_assert(!strcmp(type, "Elm_Image"));

   type = evas_object_type_get(image);
   ck_assert(type != NULL);
   ck_assert(!strcmp(type, "elm_image"));

}
EFL_END_TEST

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

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

   image = elm_image_add(win);
   role = efl_access_object_role_get(image);

   ck_assert(role == EFL_ACCESS_ROLE_IMAGE);

}
EFL_END_TEST

static void
_async_error_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   Test_Data *td = data;
   char path[PATH_MAX];
   sprintf(path, pathfmt, td->image_id);
   elm_image_file_set(obj, path, NULL);

   td->success = 1;
}

static void
_async_opened_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   Test_Data *td = data;
   const char *ff, *kk, *r1, *r2;
   char path[PATH_MAX];

   sprintf(path, pathfmt, td->image_id);
   elm_image_file_get(obj, &ff, &kk);
   r1 = strrchr(ff, '/');
   r2 = strrchr(path, '/');
   ck_assert(eina_streq(r1, r2));
   ck_assert(!kk);

   fprintf(stderr, "opened: %s\n", ff);

   if (td->image_id < MAX_IMAGE_ID / 2)
     {
        td->image_id++;
        sprintf(path, pathfmt, td->image_id);
        elm_image_file_set(obj, path, NULL);
        return;
     }
   else if (td->image_id < MAX_IMAGE_ID)
     {
        // mini stress-test
        for (; td->image_id < MAX_IMAGE_ID;)
          {
             sprintf(path, pathfmt, ++td->image_id);
             elm_image_file_set(obj, path, NULL);
          }
        return;
     }

   if (td->success == 1)
     td->success = 2;
}

static void
_async_ready_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   Test_Data *td = data;

   const char *ff;
   elm_image_file_get(obj, &ff, 0);
   fprintf(stderr, "ready : %s\n", ff);
   if (td->success == 2)
     {
        td->success = 3;
        ecore_main_loop_quit();
     }
}

static Eina_Bool
_timeout_cb(void *data)
{
   Test_Data *td = data;

   td->success = 0;
   ecore_main_loop_quit();

   return ECORE_CALLBACK_CANCEL;
}

EFL_START_TEST(elm_image_async_path)
{
   Evas_Object *win, *image;
   Ecore_Timer *t;
   Eina_Bool ok;
   Test_Data td;

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

   td.success = 0;
   td.image_id = 0;

   image = elm_image_add(win);
   elm_image_async_open_set(image, 1);
   evas_object_smart_callback_add(image, "load,error", _async_error_cb, &td);
   evas_object_smart_callback_add(image, "load,open", _async_opened_cb, &td);
   evas_object_smart_callback_add(image, "load,ready", _async_ready_cb, &td);
   evas_object_show(image);
   ok = elm_image_file_set(image, invalid, NULL);
   ck_assert(ok);

   t = ecore_timer_add(10.0, _timeout_cb, &td);

   elm_run();
   ck_assert(td.success == 3);

   ecore_timer_del(t);
}
EFL_END_TEST

EFL_START_TEST(elm_image_async_mmap)
{
   Evas_Object *win, *image;
   Ecore_Timer *t;
   Eina_Bool ok;
   Test_Data td;
   Eina_File *f;
   char path[PATH_MAX];

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

   td.success = 1; // skip "error" case
   td.image_id = 1;

   sprintf(path, pathfmt, td.image_id);
   f = eina_file_open(path, 0);
   ck_assert(f);

   image = elm_image_add(win);
   elm_image_async_open_set(image, 1);
   evas_object_smart_callback_add(image, "load,error", _async_error_cb, &td);
   evas_object_smart_callback_add(image, "load,open", _async_opened_cb, &td);
   evas_object_smart_callback_add(image, "load,ready", _async_ready_cb, &td);
   evas_object_show(image);
   ok = elm_image_mmap_set(image, f, NULL);
   ck_assert(ok);

   t = ecore_timer_add(10.0, _timeout_cb, &td);

   elm_run();
   ck_assert(td.success == 3);

   eina_file_close(f);

   ecore_timer_del(t);
}
EFL_END_TEST

EFL_START_TEST(elm_image_evas_object_color_set)
{
   Evas_Object *win, *image;
   int r = 128, g = 99, b = 3, a = 230;
   int rr = 0, gg = 0, bb = 0, aa = 0;

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

   image = elm_image_add(win);
   evas_object_color_set(image, r, g, b, a);
   evas_object_color_get(image, &rr, &gg, &bb, &aa);
   ck_assert(r == rr);
   ck_assert(g == gg);
   ck_assert(b == bb);
   ck_assert(a == aa);
}
EFL_END_TEST

EFL_START_TEST(elm_image_evas_image_get)
{
   Evas_Object *win, *image, *obj;

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

   image = elm_image_add(win);
   obj = elm_image_object_get(image);

   ck_assert(obj);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_image_icon)
{
   Evas_Object *win, *image;
   Eina_Bool ok;
   const char *icon_name;

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

   image = efl_add(EFL_UI_IMAGE_CLASS, win);
   evas_object_show(image);

   ok = efl_ui_image_icon_set(image, "folder");
   ck_assert(ok);
   icon_name = efl_ui_image_icon_get(image);
   ck_assert_str_eq(icon_name, "folder");

   ok = efl_ui_image_icon_set(image, "None");
   ck_assert(ok == 0);
   icon_name = efl_ui_image_icon_get(image);
   ck_assert(icon_name == NULL);

}
EFL_END_TEST

void elm_test_image(TCase *tc)
{
   tcase_add_test(tc, elm_image_legacy_type_check);
   tcase_add_test(tc, elm_atspi_role_get);
   tcase_add_test(tc, elm_image_async_path);
   tcase_add_test(tc, elm_image_async_mmap);
   tcase_add_test(tc, elm_image_evas_object_color_set);
   tcase_add_test(tc, elm_image_evas_image_get);
   tcase_add_test(tc, efl_ui_image_icon);
}