efl

Форк
0
/
elm_test_win.c 
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

16
static const double _timeout1 = 0.1;
17
static const double _timeout2 = 0.2;
18
static const double _timeout3 = 0.3;
19
static const double _timeout_fail = 2.0;
20

21
static void
22
_do_delete_request(Eo *win)
23
{
24
#ifdef HAVE_ELEMENTARY_X
25
   Ecore_X_Window xwin;
26
   xwin = elm_win_xwindow_get(win);
27
   ecore_x_window_delete_request_send(xwin);
28
#endif
29

30
   (void) win;
31
}
32

33

34
static Eina_Bool
35
_timer_delete_request_cb(void *data)
36
{
37
   Eo *win = (Eo*) data;
38
   _do_delete_request(win);
39
   return EINA_FALSE;
40
}
41

42
static Eina_Bool
43
_timer_del_window_cb(void *data)
44
{
45
   Eo *win = (Eo*) data;
46
   evas_object_del(win);
47
   return EINA_FALSE;
48
}
49

50
static Eina_Bool
51
_timer_hide_window_cb(void *data)
52
{
53
   Eo *win = (Eo*) data;
54
   efl_gfx_entity_visible_set(win, EINA_FALSE);
55
   return EINA_FALSE;
56
}
57

58
static Eina_Bool
59
_timer_exit_cb(void *data EINA_UNUSED)
60
{
61
   elm_exit();
62
   return EINA_FALSE;
63
}
64

65
static Eina_Bool
66
_timer_fail_flag_cb(void *data)
67
{
68
   Eina_Bool *fail_flag = (Eina_Bool*) data;
69
   *fail_flag = EINA_TRUE;
70
   elm_exit();
71
   return EINA_FALSE;
72
}
73

74
EFL_START_TEST(elm_win_legacy_type_check)
75
{
76
   Evas_Object *win, *win_socket, *win_inlined;
77
   const char *type;
78

79
   win = win_add(NULL, "win", ELM_WIN_BASIC);
80

81
   type = elm_object_widget_type_get(win);
82
   ck_assert(type != NULL);
83
   ck_assert(!strcmp(type, "Elm_Win"));
84

85
   type = evas_object_type_get(win);
86
   ck_assert(type != NULL);
87
   ck_assert(!strcmp(type, "elm_win"));
88

89
   win_socket = win_add(NULL, "win", ELM_WIN_SOCKET_IMAGE);
90

91
   type = elm_object_widget_type_get(win_socket);
92
   ck_assert(type != NULL);
93
   ck_assert(!strcmp(type, "Elm_Win"));
94

95
   type = evas_object_type_get(win_socket);
96
   ck_assert(type != NULL);
97
   ck_assert(!strcmp(type, "elm_win"));
98

99
   win_inlined = win_add(win, "win", ELM_WIN_INLINED_IMAGE);
100

101
   type = elm_object_widget_type_get(win_inlined);
102
   ck_assert(type != NULL);
103
   ck_assert(!strcmp(type, "Elm_Win"));
104

105
   type = evas_object_type_get(win_inlined);
106
   ck_assert(type != NULL);
107
   ck_assert(!strcmp(type, "elm_win"));
108
}
109
EFL_END_TEST
110

111
EFL_START_TEST(elm_atspi_role_get)
112
{
113
   Evas_Object *win;
114
   Efl_Access_Role role;
115

116
   win = win_add(NULL, "win", ELM_WIN_BASIC);
117

118
   role = efl_access_object_role_get(win);
119

120
   ck_assert(role == EFL_ACCESS_ROLE_WINDOW);
121

122
}
123
EFL_END_TEST
124

125
EFL_START_TEST(elm_atspi_component_screen_position)
126
{
127
   Eina_Bool ret;
128
   int x, y;
129

130
   Eo *win = win_add(NULL, "win", ELM_WIN_BASIC);
131

132
   ret = efl_access_component_screen_position_set(win, 45, 45);
133
   ck_assert(ret == EINA_TRUE);
134

135
   Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas_object_evas_get(win));
136
   ck_assert(ee != NULL);
137
   ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
138

139
   ck_assert((x == 45) && (y == 45));
140

141
}
142
EFL_END_TEST
143

144
EFL_START_TEST(elm_win_autohide)
145
{
146
   Eo *win = win_add(NULL, "win", ELM_WIN_BASIC);
147
   if (elm_win_xwindow_get(win))
148
     {
149
        elm_win_autohide_set(win, EINA_TRUE);
150
        efl_gfx_entity_visible_set(win, EINA_TRUE);
151

152
        Eina_Bool fail_flag = EINA_FALSE;
153
        ecore_timer_add(_timeout1, _timer_delete_request_cb, win);
154
        ecore_timer_add(_timeout2, _timer_exit_cb, &fail_flag);
155

156
        elm_run();
157

158
        Eina_Bool visible;
159
        visible = efl_gfx_entity_visible_get(win);
160
        ck_assert(visible == EINA_FALSE);
161
     }
162
}
163
EFL_END_TEST
164

165
EFL_START_TEST (elm_win_test_app_exit_on_windows_close)
166
{
167
   Eo *win = win_add(NULL, "win", ELM_WIN_BASIC);
168
   Eina_Value val, *exit_val;
169
   int code;
170

171
   val = eina_value_int_init(66);
172
   efl_ui_win_exit_on_all_windows_closed_set(&val);
173
   efl_gfx_entity_visible_set(win, EINA_TRUE);
174

175
   Eina_Bool fail_flag = EINA_FALSE;
176
   ecore_timer_add(_timeout1, _timer_del_window_cb, win);
177
   ecore_timer_add(_timeout_fail, _timer_fail_flag_cb, &fail_flag);
178

179
   exit_val = efl_loop_begin(efl_loop_get(win));
180
   ck_assert(eina_value_int_get(exit_val, &code));
181
   ck_assert_int_eq(code, 66);
182
   efl_ui_win_exit_on_all_windows_closed_set(&EINA_VALUE_EMPTY);
183
}
184
EFL_END_TEST
185

186

187
EFL_START_TEST(elm_win_policy_quit_last_window_hidden)
188
{
189
   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN);
190

191
   Eo *win = win_add(NULL, "win", ELM_WIN_BASIC);
192
   efl_gfx_entity_visible_set(win, EINA_TRUE);
193

194
   Eina_Bool fail_flag = EINA_FALSE;
195
   ecore_timer_add(_timeout1, _timer_hide_window_cb, win);
196
   ecore_timer_add(_timeout_fail, _timer_fail_flag_cb, &fail_flag);
197

198
   elm_run();
199

200
   Eina_Bool visible;
201
   visible = efl_gfx_entity_visible_get(win);
202

203
   ck_assert(fail_flag == EINA_FALSE);
204
   ck_assert(efl_ref_count(win) >= 1);
205
   ck_assert(visible == EINA_FALSE);
206

207
}
208
EFL_END_TEST
209

210
EFL_START_TEST(elm_win_test_exit_on_close)
211
{
212
   Eo *win = win_add(NULL, "win", ELM_WIN_BASIC);
213
   Eina_Value val, *exit_val;
214
   int code;
215

216
   val = eina_value_int_init(66);
217
   efl_ui_win_exit_on_close_set(win, &val);
218
   efl_gfx_entity_visible_set(win, EINA_TRUE);
219

220
   Eina_Bool fail_flag = EINA_FALSE;
221
   ecore_timer_add(_timeout1, _timer_del_window_cb, win);
222
   ecore_timer_add(_timeout_fail, _timer_fail_flag_cb, &fail_flag);
223

224
   exit_val = efl_loop_begin(efl_loop_get(win));
225
   ck_assert(eina_value_int_get(exit_val, &code));
226
   ck_assert_int_eq(code, 66);
227
}
228
EFL_END_TEST
229

230
EFL_START_TEST(elm_win_autohide_and_policy_quit_last_window_hidden)
231
{
232
   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN);
233

234
   Eo *win = win_add(NULL, "win", ELM_WIN_BASIC);
235
   if (elm_win_xwindow_get(win))
236
     {
237
        elm_win_autohide_set(win, EINA_TRUE);
238
        efl_gfx_entity_visible_set(win, EINA_TRUE);
239

240
        Eina_Bool fail_flag = EINA_FALSE;
241
        ecore_timer_add(_timeout1, _timer_delete_request_cb, win);
242
        ecore_timer_add(_timeout_fail, _timer_fail_flag_cb, &fail_flag);
243

244
        elm_run();
245

246
        Eina_Bool visible;
247
        visible = efl_gfx_entity_visible_get(win);
248

249
        ck_assert(fail_flag == EINA_FALSE);
250
        ck_assert(efl_ref_count(win) >= 1);
251
        ck_assert(visible == EINA_FALSE);
252
     }
253
}
254
EFL_END_TEST
255

256
/* a very lax definition of == for doubles */
257
#define VALEQ(a, b) ((fabs((a) - (b))) <= 0.001)
258

259
static 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

275
static Eina_Bool
276
_inputs_timer1_cb(void *data)
277
{
278
   Efl_Input_Pointer *ptr;
279
   Eo *win = data;
280

281
   /* Send down events first (note: stupid, all at once) */
282
   for (size_t i = 0; i < 4; i++)
283
     {
284
        ptr = efl_add(EFL_INPUT_POINTER_CLASS, win);
285
        efl_input_pointer_position_set(ptr, points[0][i]);
286
        efl_input_pointer_touch_id_set(ptr, i);
287
        efl_input_pointer_button_set(ptr, 1);
288

289
        if (i == 0)
290
          {
291
             /* in first */
292
             efl_input_pointer_action_set(ptr, EFL_POINTER_ACTION_IN);
293
             efl_event_callback_call(win, EFL_EVENT_POINTER_IN, ptr);
294

295
             /* move second */
296
             efl_input_pointer_position_set(ptr, points[0][i]);
297
             efl_input_pointer_action_set(ptr, EFL_POINTER_ACTION_MOVE);
298
             efl_event_callback_call(win, EFL_EVENT_POINTER_MOVE, ptr);
299
          }
300

301
        /* down finally */
302
        efl_input_pointer_action_set(ptr, EFL_POINTER_ACTION_DOWN);
303
        efl_event_callback_call(win, EFL_EVENT_POINTER_DOWN, ptr);
304
     }
305

306
   return ECORE_CALLBACK_DONE;
307
}
308

309
static Eina_Bool
310
_inputs_timer2_cb(void *data)
311
{
312
   Efl_Input_Pointer *ptr;
313
   Eina_Iterator *it;
314
   Eo *win = data;
315
   size_t cnt = 0;
316
   int i = 0;
317

318
   it = efl_ui_win_pointer_iterate(win, 0);
319
   EINA_ITERATOR_FOREACH(it, ptr)
320
     {
321
        double x, y;
322
        int tool, ok = 0;
323

324
        fail_if(!efl_input_pointer_value_has_get(ptr, EFL_INPUT_VALUE_X));
325
        fail_if(!efl_input_pointer_value_has_get(ptr, EFL_INPUT_VALUE_Y));
326
        fail_if(!efl_input_pointer_value_has_get(ptr, EFL_INPUT_VALUE_TOUCH_ID));
327
        fail_if(efl_input_pointer_action_get(ptr) != EFL_POINTER_ACTION_DOWN);
328

329
        x = efl_input_pointer_value_get(ptr, EFL_INPUT_VALUE_X);
330
        y = efl_input_pointer_value_get(ptr, EFL_INPUT_VALUE_Y);
331
        tool = efl_input_pointer_touch_id_get(ptr);
332

333
        for (i = 0; i < 4; i++)
334
          if (tool == i)
335
            {
336
               fail_if(!VALEQ(x, points[0][i].x));
337
               fail_if(!VALEQ(y, points[0][i].y));
338
               ok = 1;
339
               break;
340
            }
341
        fail_if(!ok);
342

343
        cnt++;
344
     }
345
   eina_iterator_free(it);
346
   fail_if(cnt != 4);
347

348
   /* Send some moves */
349
   for (i = 0; i < 4; i++)
350
     {
351
        ptr = efl_add(EFL_INPUT_POINTER_CLASS, win);
352
        efl_input_pointer_position_set(ptr, points[1][i]);
353
        efl_input_pointer_touch_id_set(ptr, i);
354
        efl_input_pointer_button_set(ptr, 1);
355

356
        /* move first */
357
        efl_input_pointer_action_set(ptr, EFL_POINTER_ACTION_MOVE);
358
        efl_event_callback_call(win, EFL_EVENT_POINTER_MOVE, ptr);
359

360
        /* then up (one 2 fingers up: #1 and #3) */
361
        if ((i % 2) == 1)
362
          {
363
             efl_input_pointer_action_set(ptr, EFL_POINTER_ACTION_UP);
364
             efl_event_callback_call(win, EFL_EVENT_POINTER_UP, ptr);
365
          }
366
     }
367

368
   return ECORE_CALLBACK_DONE;
369
}
370

371
static Eina_Bool
372
_inputs_timer3_cb(void *data)
373
{
374
   Efl_Input_Pointer *ptr;
375
   Eina_Position2D pos;
376
   Eina_Iterator *it;
377
   Eo *win = data;
378
   size_t cnt = 0;
379
   int i = 0;
380

381
   it = efl_ui_win_pointer_iterate(win, 0);
382
   EINA_ITERATOR_FOREACH(it, ptr)
383
     {
384
        int tool, ok = 0;
385
        double x, y;
386

387
        fail_if(!efl_input_pointer_value_has_get(ptr, EFL_INPUT_VALUE_X));
388
        fail_if(!efl_input_pointer_value_has_get(ptr, EFL_INPUT_VALUE_Y));
389
        fail_if(!efl_input_pointer_value_has_get(ptr, EFL_INPUT_VALUE_TOUCH_ID));
390
        fail_if(efl_input_pointer_action_get(ptr) != EFL_POINTER_ACTION_MOVE);
391

392
        x = efl_input_pointer_value_get(ptr, EFL_INPUT_VALUE_X);
393
        y = efl_input_pointer_value_get(ptr, EFL_INPUT_VALUE_Y);
394
        tool = efl_input_pointer_touch_id_get(ptr);
395

396
        for (i = 0; i < 4; i++)
397
          if (tool == i)
398
            {
399
               fail_if(!VALEQ(x, points[1][i].x));
400
               fail_if(!VALEQ(y, points[1][i].y));
401
               ok = 1;
402
               break;
403
            }
404
        fail_if(!ok);
405

406
        cnt++;
407
     }
408
   eina_iterator_free(it);
409
   fail_if(cnt != 2); // 2 moves (in the list), 2 ups (gone)
410

411
   fail_if(!efl_canvas_pointer_inside_get(win, NULL));
412
   efl_canvas_scene_pointer_position_get(win, NULL, &pos);
413
   ck_assert_int_eq(pos.x, points[1][0].x);
414
   ck_assert_int_eq(pos.y, points[1][0].y);
415

416
   elm_exit();
417

418
   return ECORE_CALLBACK_DONE;
419
}
420

421
EFL_START_TEST(efl_ui_win_multi_touch_inputs)
422
{
423
   Eina_Bool fail_flag = EINA_FALSE;
424
   Eo *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

433
   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
434

435
   win = win_add(NULL, "win", ELM_WIN_BASIC);
436
   elm_win_autohide_set(win, EINA_TRUE);
437
   efl_gfx_entity_visible_set(win, EINA_TRUE);
438
   efl_gfx_entity_size_set(win, EINA_SIZE2D(100,  100));
439

440
   ecore_timer_add(_timeout1, _inputs_timer1_cb, win);
441
   ecore_timer_add(_timeout2, _inputs_timer2_cb, win);
442
   ecore_timer_add(_timeout3, _inputs_timer3_cb, win);
443
   ecore_timer_add(_timeout_fail, _timer_fail_flag_cb, &fail_flag);
444

445
   elm_run();
446

447
   fail_if(fail_flag != EINA_FALSE);
448

449
}
450
EFL_END_TEST
451

452
EFL_START_TEST(elm_win_test_rotation)
453
{
454
   Evas_Object *win;
455

456
   win = win_add(NULL, "win", ELM_WIN_BASIC);
457

458
   elm_win_rotation_set(win, 90);
459
   ck_assert_int_eq(elm_win_rotation_get(win), 90);
460
   elm_win_rotation_with_resize_set(win, 180);
461
   ck_assert_int_eq(elm_win_rotation_get(win), 180);
462
   DISABLE_ABORT_ON_CRITICAL_START;
463
   ck_assert_int_eq(elm_win_rotation_get(NULL), -1);
464
   DISABLE_ABORT_ON_CRITICAL_END;
465
}
466
EFL_END_TEST
467

468
EFL_START_TEST(elm_win_test_default_type)
469
{
470
   Evas_Object *win;
471

472
   win = elm_win_add(NULL, "test win default type", ELM_WIN_UNKNOWN);
473
   ck_assert_int_eq(elm_win_type_get(win), ELM_WIN_UNKNOWN);
474

475
   win = elm_win_util_standard_add("test win default type", "test");
476
   ck_assert_int_eq(elm_win_type_get(win), ELM_WIN_BASIC);
477
}
478
EFL_END_TEST
479

480
void elm_test_win(TCase *tc)
481
{
482
   tcase_add_test(tc, elm_win_legacy_type_check);
483
   tcase_add_test(tc, elm_atspi_role_get);
484
   tcase_add_test(tc, elm_atspi_component_screen_position);
485
   tcase_add_test(tc, elm_win_policy_quit_last_window_hidden);
486
   tcase_add_test(tc, elm_win_test_exit_on_close);
487
   tcase_add_test(tc, elm_win_test_app_exit_on_windows_close);
488
   tcase_add_test(tc, efl_ui_win_multi_touch_inputs);
489
   tcase_add_test(tc, elm_win_test_rotation);
490
   tcase_add_test(tc, elm_win_test_default_type);
491
#ifdef HAVE_ELEMENTARY_X
492
   tcase_add_test(tc, elm_win_autohide);
493
   tcase_add_test(tc, elm_win_autohide_and_policy_quit_last_window_hidden);
494
#endif
495
}
496

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.