efl
495 строк · 12.8 Кб
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#define EFL_ACCESS_OBJECT_BETA
6#define EFL_ACCESS_COMPONENT_BETA
7#define EFL_ACCESS_COMPONENT_PROTECTED
8#define EFL_CANVAS_SCENE_BETA
9
10#include <Elementary.h>
11#ifdef HAVE_ELEMENTARY_X
12# include <Ecore_X.h>
13#endif
14#include "elm_suite.h"
15
16static const double _timeout1 = 0.1;
17static const double _timeout2 = 0.2;
18static const double _timeout3 = 0.3;
19static const double _timeout_fail = 2.0;
20
21static void
22_do_delete_request(Eo *win)
23{
24#ifdef HAVE_ELEMENTARY_X
25Ecore_X_Window xwin;
26xwin = elm_win_xwindow_get(win);
27ecore_x_window_delete_request_send(xwin);
28#endif
29
30(void) win;
31}
32
33
34static Eina_Bool
35_timer_delete_request_cb(void *data)
36{
37Eo *win = (Eo*) data;
38_do_delete_request(win);
39return EINA_FALSE;
40}
41
42static Eina_Bool
43_timer_del_window_cb(void *data)
44{
45Eo *win = (Eo*) data;
46evas_object_del(win);
47return EINA_FALSE;
48}
49
50static Eina_Bool
51_timer_hide_window_cb(void *data)
52{
53Eo *win = (Eo*) data;
54efl_gfx_entity_visible_set(win, EINA_FALSE);
55return EINA_FALSE;
56}
57
58static Eina_Bool
59_timer_exit_cb(void *data EINA_UNUSED)
60{
61elm_exit();
62return EINA_FALSE;
63}
64
65static Eina_Bool
66_timer_fail_flag_cb(void *data)
67{
68Eina_Bool *fail_flag = (Eina_Bool*) data;
69*fail_flag = EINA_TRUE;
70elm_exit();
71return EINA_FALSE;
72}
73
74EFL_START_TEST(elm_win_legacy_type_check)
75{
76Evas_Object *win, *win_socket, *win_inlined;
77const char *type;
78
79win = win_add(NULL, "win", ELM_WIN_BASIC);
80
81type = elm_object_widget_type_get(win);
82ck_assert(type != NULL);
83ck_assert(!strcmp(type, "Elm_Win"));
84
85type = evas_object_type_get(win);
86ck_assert(type != NULL);
87ck_assert(!strcmp(type, "elm_win"));
88
89win_socket = win_add(NULL, "win", ELM_WIN_SOCKET_IMAGE);
90
91type = elm_object_widget_type_get(win_socket);
92ck_assert(type != NULL);
93ck_assert(!strcmp(type, "Elm_Win"));
94
95type = evas_object_type_get(win_socket);
96ck_assert(type != NULL);
97ck_assert(!strcmp(type, "elm_win"));
98
99win_inlined = win_add(win, "win", ELM_WIN_INLINED_IMAGE);
100
101type = elm_object_widget_type_get(win_inlined);
102ck_assert(type != NULL);
103ck_assert(!strcmp(type, "Elm_Win"));
104
105type = evas_object_type_get(win_inlined);
106ck_assert(type != NULL);
107ck_assert(!strcmp(type, "elm_win"));
108}
109EFL_END_TEST
110
111EFL_START_TEST(elm_atspi_role_get)
112{
113Evas_Object *win;
114Efl_Access_Role role;
115
116win = win_add(NULL, "win", ELM_WIN_BASIC);
117
118role = efl_access_object_role_get(win);
119
120ck_assert(role == EFL_ACCESS_ROLE_WINDOW);
121
122}
123EFL_END_TEST
124
125EFL_START_TEST(elm_atspi_component_screen_position)
126{
127Eina_Bool ret;
128int x, y;
129
130Eo *win = win_add(NULL, "win", ELM_WIN_BASIC);
131
132ret = efl_access_component_screen_position_set(win, 45, 45);
133ck_assert(ret == EINA_TRUE);
134
135Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas_object_evas_get(win));
136ck_assert(ee != NULL);
137ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
138
139ck_assert((x == 45) && (y == 45));
140
141}
142EFL_END_TEST
143
144EFL_START_TEST(elm_win_autohide)
145{
146Eo *win = win_add(NULL, "win", ELM_WIN_BASIC);
147if (elm_win_xwindow_get(win))
148{
149elm_win_autohide_set(win, EINA_TRUE);
150efl_gfx_entity_visible_set(win, EINA_TRUE);
151
152Eina_Bool fail_flag = EINA_FALSE;
153ecore_timer_add(_timeout1, _timer_delete_request_cb, win);
154ecore_timer_add(_timeout2, _timer_exit_cb, &fail_flag);
155
156elm_run();
157
158Eina_Bool visible;
159visible = efl_gfx_entity_visible_get(win);
160ck_assert(visible == EINA_FALSE);
161}
162}
163EFL_END_TEST
164
165EFL_START_TEST (elm_win_test_app_exit_on_windows_close)
166{
167Eo *win = win_add(NULL, "win", ELM_WIN_BASIC);
168Eina_Value val, *exit_val;
169int code;
170
171val = eina_value_int_init(66);
172efl_ui_win_exit_on_all_windows_closed_set(&val);
173efl_gfx_entity_visible_set(win, EINA_TRUE);
174
175Eina_Bool fail_flag = EINA_FALSE;
176ecore_timer_add(_timeout1, _timer_del_window_cb, win);
177ecore_timer_add(_timeout_fail, _timer_fail_flag_cb, &fail_flag);
178
179exit_val = efl_loop_begin(efl_loop_get(win));
180ck_assert(eina_value_int_get(exit_val, &code));
181ck_assert_int_eq(code, 66);
182efl_ui_win_exit_on_all_windows_closed_set(&EINA_VALUE_EMPTY);
183}
184EFL_END_TEST
185
186
187EFL_START_TEST(elm_win_policy_quit_last_window_hidden)
188{
189elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN);
190
191Eo *win = win_add(NULL, "win", ELM_WIN_BASIC);
192efl_gfx_entity_visible_set(win, EINA_TRUE);
193
194Eina_Bool fail_flag = EINA_FALSE;
195ecore_timer_add(_timeout1, _timer_hide_window_cb, win);
196ecore_timer_add(_timeout_fail, _timer_fail_flag_cb, &fail_flag);
197
198elm_run();
199
200Eina_Bool visible;
201visible = efl_gfx_entity_visible_get(win);
202
203ck_assert(fail_flag == EINA_FALSE);
204ck_assert(efl_ref_count(win) >= 1);
205ck_assert(visible == EINA_FALSE);
206
207}
208EFL_END_TEST
209
210EFL_START_TEST(elm_win_test_exit_on_close)
211{
212Eo *win = win_add(NULL, "win", ELM_WIN_BASIC);
213Eina_Value val, *exit_val;
214int code;
215
216val = eina_value_int_init(66);
217efl_ui_win_exit_on_close_set(win, &val);
218efl_gfx_entity_visible_set(win, EINA_TRUE);
219
220Eina_Bool fail_flag = EINA_FALSE;
221ecore_timer_add(_timeout1, _timer_del_window_cb, win);
222ecore_timer_add(_timeout_fail, _timer_fail_flag_cb, &fail_flag);
223
224exit_val = efl_loop_begin(efl_loop_get(win));
225ck_assert(eina_value_int_get(exit_val, &code));
226ck_assert_int_eq(code, 66);
227}
228EFL_END_TEST
229
230EFL_START_TEST(elm_win_autohide_and_policy_quit_last_window_hidden)
231{
232elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN);
233
234Eo *win = win_add(NULL, "win", ELM_WIN_BASIC);
235if (elm_win_xwindow_get(win))
236{
237elm_win_autohide_set(win, EINA_TRUE);
238efl_gfx_entity_visible_set(win, EINA_TRUE);
239
240Eina_Bool fail_flag = EINA_FALSE;
241ecore_timer_add(_timeout1, _timer_delete_request_cb, win);
242ecore_timer_add(_timeout_fail, _timer_fail_flag_cb, &fail_flag);
243
244elm_run();
245
246Eina_Bool visible;
247visible = efl_gfx_entity_visible_get(win);
248
249ck_assert(fail_flag == EINA_FALSE);
250ck_assert(efl_ref_count(win) >= 1);
251ck_assert(visible == EINA_FALSE);
252}
253}
254EFL_END_TEST
255
256/* a very lax definition of == for doubles */
257#define VALEQ(a, b) ((fabs((a) - (b))) <= 0.001)
258
259static const Eina_Position2D points[2][4] =
260{
261{
262{ 20, 20 },
263{ 40, 10 },
264{ 60, 120 },
265{ 80, 80 }
266},
267{
268{ 30, 30 },
269{ 50, 50 },
270{ 70, 60 },
271{ 80, 80 }
272},
273};
274
275static Eina_Bool
276_inputs_timer1_cb(void *data)
277{
278Efl_Input_Pointer *ptr;
279Eo *win = data;
280
281/* Send down events first (note: stupid, all at once) */
282for (size_t i = 0; i < 4; i++)
283{
284ptr = efl_add(EFL_INPUT_POINTER_CLASS, win);
285efl_input_pointer_position_set(ptr, points[0][i]);
286efl_input_pointer_touch_id_set(ptr, i);
287efl_input_pointer_button_set(ptr, 1);
288
289if (i == 0)
290{
291/* in first */
292efl_input_pointer_action_set(ptr, EFL_POINTER_ACTION_IN);
293efl_event_callback_call(win, EFL_EVENT_POINTER_IN, ptr);
294
295/* move second */
296efl_input_pointer_position_set(ptr, points[0][i]);
297efl_input_pointer_action_set(ptr, EFL_POINTER_ACTION_MOVE);
298efl_event_callback_call(win, EFL_EVENT_POINTER_MOVE, ptr);
299}
300
301/* down finally */
302efl_input_pointer_action_set(ptr, EFL_POINTER_ACTION_DOWN);
303efl_event_callback_call(win, EFL_EVENT_POINTER_DOWN, ptr);
304}
305
306return ECORE_CALLBACK_DONE;
307}
308
309static Eina_Bool
310_inputs_timer2_cb(void *data)
311{
312Efl_Input_Pointer *ptr;
313Eina_Iterator *it;
314Eo *win = data;
315size_t cnt = 0;
316int i = 0;
317
318it = efl_ui_win_pointer_iterate(win, 0);
319EINA_ITERATOR_FOREACH(it, ptr)
320{
321double x, y;
322int tool, ok = 0;
323
324fail_if(!efl_input_pointer_value_has_get(ptr, EFL_INPUT_VALUE_X));
325fail_if(!efl_input_pointer_value_has_get(ptr, EFL_INPUT_VALUE_Y));
326fail_if(!efl_input_pointer_value_has_get(ptr, EFL_INPUT_VALUE_TOUCH_ID));
327fail_if(efl_input_pointer_action_get(ptr) != EFL_POINTER_ACTION_DOWN);
328
329x = efl_input_pointer_value_get(ptr, EFL_INPUT_VALUE_X);
330y = efl_input_pointer_value_get(ptr, EFL_INPUT_VALUE_Y);
331tool = efl_input_pointer_touch_id_get(ptr);
332
333for (i = 0; i < 4; i++)
334if (tool == i)
335{
336fail_if(!VALEQ(x, points[0][i].x));
337fail_if(!VALEQ(y, points[0][i].y));
338ok = 1;
339break;
340}
341fail_if(!ok);
342
343cnt++;
344}
345eina_iterator_free(it);
346fail_if(cnt != 4);
347
348/* Send some moves */
349for (i = 0; i < 4; i++)
350{
351ptr = efl_add(EFL_INPUT_POINTER_CLASS, win);
352efl_input_pointer_position_set(ptr, points[1][i]);
353efl_input_pointer_touch_id_set(ptr, i);
354efl_input_pointer_button_set(ptr, 1);
355
356/* move first */
357efl_input_pointer_action_set(ptr, EFL_POINTER_ACTION_MOVE);
358efl_event_callback_call(win, EFL_EVENT_POINTER_MOVE, ptr);
359
360/* then up (one 2 fingers up: #1 and #3) */
361if ((i % 2) == 1)
362{
363efl_input_pointer_action_set(ptr, EFL_POINTER_ACTION_UP);
364efl_event_callback_call(win, EFL_EVENT_POINTER_UP, ptr);
365}
366}
367
368return ECORE_CALLBACK_DONE;
369}
370
371static Eina_Bool
372_inputs_timer3_cb(void *data)
373{
374Efl_Input_Pointer *ptr;
375Eina_Position2D pos;
376Eina_Iterator *it;
377Eo *win = data;
378size_t cnt = 0;
379int i = 0;
380
381it = efl_ui_win_pointer_iterate(win, 0);
382EINA_ITERATOR_FOREACH(it, ptr)
383{
384int tool, ok = 0;
385double x, y;
386
387fail_if(!efl_input_pointer_value_has_get(ptr, EFL_INPUT_VALUE_X));
388fail_if(!efl_input_pointer_value_has_get(ptr, EFL_INPUT_VALUE_Y));
389fail_if(!efl_input_pointer_value_has_get(ptr, EFL_INPUT_VALUE_TOUCH_ID));
390fail_if(efl_input_pointer_action_get(ptr) != EFL_POINTER_ACTION_MOVE);
391
392x = efl_input_pointer_value_get(ptr, EFL_INPUT_VALUE_X);
393y = efl_input_pointer_value_get(ptr, EFL_INPUT_VALUE_Y);
394tool = efl_input_pointer_touch_id_get(ptr);
395
396for (i = 0; i < 4; i++)
397if (tool == i)
398{
399fail_if(!VALEQ(x, points[1][i].x));
400fail_if(!VALEQ(y, points[1][i].y));
401ok = 1;
402break;
403}
404fail_if(!ok);
405
406cnt++;
407}
408eina_iterator_free(it);
409fail_if(cnt != 2); // 2 moves (in the list), 2 ups (gone)
410
411fail_if(!efl_canvas_pointer_inside_get(win, NULL));
412efl_canvas_scene_pointer_position_get(win, NULL, &pos);
413ck_assert_int_eq(pos.x, points[1][0].x);
414ck_assert_int_eq(pos.y, points[1][0].y);
415
416elm_exit();
417
418return ECORE_CALLBACK_DONE;
419}
420
421EFL_START_TEST(efl_ui_win_multi_touch_inputs)
422{
423Eina_Bool fail_flag = EINA_FALSE;
424Eo *win;
425
426/* this tests only multi touch inputs - a lot of code but quite basic
427* faking events is quite hard, as an exact sequence must be followed:
428*
429* pointer 0: in, move, down, move, move, ...
430* pointer x: down, move, move, ...
431*/
432
433elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
434
435win = win_add(NULL, "win", ELM_WIN_BASIC);
436elm_win_autohide_set(win, EINA_TRUE);
437efl_gfx_entity_visible_set(win, EINA_TRUE);
438efl_gfx_entity_size_set(win, EINA_SIZE2D(100, 100));
439
440ecore_timer_add(_timeout1, _inputs_timer1_cb, win);
441ecore_timer_add(_timeout2, _inputs_timer2_cb, win);
442ecore_timer_add(_timeout3, _inputs_timer3_cb, win);
443ecore_timer_add(_timeout_fail, _timer_fail_flag_cb, &fail_flag);
444
445elm_run();
446
447fail_if(fail_flag != EINA_FALSE);
448
449}
450EFL_END_TEST
451
452EFL_START_TEST(elm_win_test_rotation)
453{
454Evas_Object *win;
455
456win = win_add(NULL, "win", ELM_WIN_BASIC);
457
458elm_win_rotation_set(win, 90);
459ck_assert_int_eq(elm_win_rotation_get(win), 90);
460elm_win_rotation_with_resize_set(win, 180);
461ck_assert_int_eq(elm_win_rotation_get(win), 180);
462DISABLE_ABORT_ON_CRITICAL_START;
463ck_assert_int_eq(elm_win_rotation_get(NULL), -1);
464DISABLE_ABORT_ON_CRITICAL_END;
465}
466EFL_END_TEST
467
468EFL_START_TEST(elm_win_test_default_type)
469{
470Evas_Object *win;
471
472win = elm_win_add(NULL, "test win default type", ELM_WIN_UNKNOWN);
473ck_assert_int_eq(elm_win_type_get(win), ELM_WIN_UNKNOWN);
474
475win = elm_win_util_standard_add("test win default type", "test");
476ck_assert_int_eq(elm_win_type_get(win), ELM_WIN_BASIC);
477}
478EFL_END_TEST
479
480void elm_test_win(TCase *tc)
481{
482tcase_add_test(tc, elm_win_legacy_type_check);
483tcase_add_test(tc, elm_atspi_role_get);
484tcase_add_test(tc, elm_atspi_component_screen_position);
485tcase_add_test(tc, elm_win_policy_quit_last_window_hidden);
486tcase_add_test(tc, elm_win_test_exit_on_close);
487tcase_add_test(tc, elm_win_test_app_exit_on_windows_close);
488tcase_add_test(tc, efl_ui_win_multi_touch_inputs);
489tcase_add_test(tc, elm_win_test_rotation);
490tcase_add_test(tc, elm_win_test_default_type);
491#ifdef HAVE_ELEMENTARY_X
492tcase_add_test(tc, elm_win_autohide);
493tcase_add_test(tc, elm_win_autohide_and_policy_quit_last_window_hidden);
494#endif
495}
496