aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/ecore/efl_app_test_loop_fd.c
blob: 4403933aa8a179cd899e44d348ca9a796cfcbd30 (plain) (blame)
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
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdio.h>
#include <unistd.h>
#define EFL_NOLEGACY_API_SUPPORT
#include <Efl_Core.h>
#include <Efl_Net.h>
#include "efl_app_suite.h"
#include "../efl_check.h"


static void
_eo_read_cb(void *data, const Efl_Event *info EINA_UNUSED)
{
   Eina_Bool *did = data;

   *did = EINA_TRUE;
   ecore_main_loop_quit();
}

EFL_START_TEST(ecore_test_efl_loop_fd)
{
   Eina_Bool did = EINA_FALSE;
   Eo *fd;
   int comm[2];
   int ret;

   ret = pipe(comm);
   fail_if(ret != 0);

   fd = efl_add(EFL_LOOP_FD_CLASS, efl_main_loop_get(),
               efl_loop_fd_set(efl_added, comm[0]),
               efl_event_callback_add(efl_added, EFL_LOOP_FD_EVENT_READ, _eo_read_cb, &did));
   fail_if(fd == NULL);

   ret = write(comm[1], &did, 1);
   fail_if(ret != 1);

   efl_loop_begin(efl_main_loop_get());

   close(comm[0]);
   close(comm[1]);

   fail_if(did == EINA_FALSE);

}
EFL_END_TEST

static void
_efl_del_cb(void *data, const Efl_Event *ev EINA_UNUSED)
{
   Eina_Bool *dead = data;

   *dead = EINA_TRUE;
}

EFL_START_TEST(ecore_test_efl_loop_fd_lifecycle)
{
   Eina_Bool did = EINA_FALSE;
   Eina_Bool dead = EINA_FALSE;
   Eo *fd;
   int comm[2];
   int ret;

   ret = pipe(comm);
   fail_if(ret != 0);

   fd = efl_add(EFL_LOOP_FD_CLASS, efl_main_loop_get(),
               efl_loop_fd_set(efl_added, comm[0]),
               efl_event_callback_add(efl_added, EFL_LOOP_FD_EVENT_READ, _eo_read_cb, &did),
               efl_event_callback_add(efl_added, EFL_EVENT_DEL, _efl_del_cb, &dead));
   fail_if(fd == NULL);

   ret = write(comm[1], &did, 1);
   fail_if(ret != 1);

   efl_loop_begin(efl_main_loop_get());

   close(comm[0]);
   close(comm[1]);

   fail_if(did == EINA_FALSE);
   fail_if(dead == EINA_TRUE);

   efl_del(fd);
   fail_if(dead == EINA_FALSE);
}
EFL_END_TEST


void efl_app_test_efl_loop_fd(TCase *tc)
{
   tcase_add_test(tc, ecore_test_efl_loop_fd);
   tcase_add_test(tc, ecore_test_efl_loop_fd_lifecycle);
}