summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2016-04-12 16:00:23 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-05-25 21:32:03 -0300
commit7241b7375de1eb4327f5bca21dcfc5a889b9eb72 (patch)
treececbe8991d1b38db8f8c67965ae2a5e6cf2aa503 /src/tests
parentde9be13d458f2739a536e5863aa8caddd3f7f715 (diff)
eio: Adds Eo-based Eio API
The legacy Eio_File factory functions are replaced by an Eo object called Eo_Job that return promises wrapping the async file operations. With this commit, the legacy Eio callbacks are replaced by the following Eo/Promises counterparts : * Done_Cb -> Promise then success callback * Error_Cb -> Promise then error callback * Main_Cb -> Promise progress callback * Filter_Cb -> Job object event (more below) Events are used to deliver and get the filter data. To differentiate between the named and direct versions, they come in "filter,direct" and "filter,name" versions. Monitors were wrapped inside a new class Eo_Sentry. The user creates a sentry object and adds monitoring targets to it, listening to events on it. The sentry event info is composed of two strings. The source string is the path being monitored, i.e. the one passed to eio_sentry_add, and the trigger string is the path that actually triggered the event, e.g. a new file created in a monitored directory.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/eio/eio_model_test_file.c8
-rw-r--r--src/tests/eio/eio_model_test_monitor_add.c4
-rw-r--r--src/tests/eio/eio_suite.c17
-rw-r--r--src/tests/eio/eio_suite.h3
-rw-r--r--src/tests/eio/eio_test_common.c89
-rw-r--r--src/tests/eio/eio_test_common.h16
-rw-r--r--src/tests/eio/eio_test_file.c72
-rw-r--r--src/tests/eio/eio_test_job.c290
-rw-r--r--src/tests/eio/eio_test_job_xattr.c204
-rw-r--r--src/tests/eio/eio_test_sentry.c755
-rw-r--r--src/tests/eio/eio_test_xattr.c17
11 files changed, 1380 insertions, 95 deletions
diff --git a/src/tests/eio/eio_model_test_file.c b/src/tests/eio/eio_model_test_file.c
index 63f7b93716..ec9e6a60e3 100644
--- a/src/tests/eio/eio_model_test_file.c
+++ b/src/tests/eio/eio_model_test_file.c
@@ -58,7 +58,7 @@ static Eina_Bool
58 } 58 }
59 59
60static void 60static void
61promise_then_count(void *data EINA_UNUSED, void *p) 61promise_then_count(void *data EINA_UNUSED, void *p, Eina_Promise* promise EINA_UNUSED)
62{ 62{
63 int *total = p; 63 int *total = p;
64 ck_assert_ptr_ne(total, NULL); 64 ck_assert_ptr_ne(total, NULL);
@@ -67,7 +67,7 @@ promise_then_count(void *data EINA_UNUSED, void *p)
67} 67}
68 68
69static void 69static void
70promise_then_accessor(void *data EINA_UNUSED, void* p) 70promise_then_accessor(void *data EINA_UNUSED, void* p, Eina_Promise* promise EINA_UNUSED)
71{ 71{
72 Eina_Accessor **accessor = (Eina_Accessor**)p; 72 Eina_Accessor **accessor = (Eina_Accessor**)p;
73 ck_assert_ptr_ne(accessor, NULL); 73 ck_assert_ptr_ne(accessor, NULL);
@@ -84,7 +84,7 @@ promise_then_accessor(void *data EINA_UNUSED, void* p)
84} 84}
85 85
86static void 86static void
87promise_then_value(void *user EINA_UNUSED, void *p) 87promise_then_value(void *user EINA_UNUSED, void *p, Eina_Promise* promise EINA_UNUSED)
88{ 88{
89 Eina_Value* value = p; 89 Eina_Value* value = p;
90 ck_assert_ptr_ne(value, NULL); 90 ck_assert_ptr_ne(value, NULL);
@@ -98,7 +98,7 @@ promise_then_value(void *user EINA_UNUSED, void *p)
98} 98}
99 99
100static void 100static void
101error_promise_then(void* data EINA_UNUSED, Eina_Error const* error EINA_UNUSED) 101error_promise_then(void* data EINA_UNUSED, Eina_Error error EINA_UNUSED, Eina_Promise* promise EINA_UNUSED)
102{ 102{
103 ck_abort_msg(0, "Error Promise cb"); 103 ck_abort_msg(0, "Error Promise cb");
104 ecore_main_loop_quit(); 104 ecore_main_loop_quit();
diff --git a/src/tests/eio/eio_model_test_monitor_add.c b/src/tests/eio/eio_model_test_monitor_add.c
index 5ddec2b99c..e8bcd11e51 100644
--- a/src/tests/eio/eio_model_test_monitor_add.c
+++ b/src/tests/eio/eio_model_test_monitor_add.c
@@ -64,7 +64,7 @@ _children_added_cb(void *data EINA_UNUSED, const Eo_Event* event)
64} 64}
65 65
66static void 66static void
67_create_file(void *data EINA_UNUSED, void* value EINA_UNUSED) 67_create_file(void *data EINA_UNUSED, void* value EINA_UNUSED, Eina_Promise* promise EINA_UNUSED)
68{ 68{
69 int fd; 69 int fd;
70 if((fd = eina_file_mkstemp("prefixXXXXXX.ext", &temp_filename)) > 0) 70 if((fd = eina_file_mkstemp("prefixXXXXXX.ext", &temp_filename)) > 0)
@@ -76,7 +76,7 @@ _create_file(void *data EINA_UNUSED, void* value EINA_UNUSED)
76 76
77 77
78static void 78static void
79_create_file_error(void *data EINA_UNUSED, const Eina_Error* value EINA_UNUSED) 79_create_file_error(void *data EINA_UNUSED, Eina_Error value EINA_UNUSED, Eina_Promise* promise EINA_UNUSED)
80{ 80{
81 ck_abort_msg(0, "Error Promise cb called in Create file"); 81 ck_abort_msg(0, "Error Promise cb called in Create file");
82 ecore_main_loop_quit(); 82 ecore_main_loop_quit();
diff --git a/src/tests/eio/eio_suite.c b/src/tests/eio/eio_suite.c
index 39ce8f769a..022a31423b 100644
--- a/src/tests/eio/eio_suite.c
+++ b/src/tests/eio/eio_suite.c
@@ -6,13 +6,16 @@
6#include "../efl_check.h" 6#include "../efl_check.h"
7 7
8static const Efl_Test_Case etc[] = { 8static const Efl_Test_Case etc[] = {
9 {"Eio_Monitor", eio_test_monitor}, 9 /* {"Eio_Monitor", eio_test_monitor}, */
10 {"Eio Model", eio_model_test_file}, 10 /* {"Eio_Sentry", eio_test_sentry}, */
11 {"Eio Model Monitor", eio_model_test_monitor_add}, 11 /* {"Eio Model", eio_model_test_file}, */
12 {"Eio File", eio_test_file}, 12 /* {"Eio Model Monitor", eio_model_test_monitor_add}, */
13#ifdef XATTR_TEST_DIR 13 /* {"Eio File", eio_test_file}, */
14 {"Eio_Xattr", eio_test_xattr}, 14 {"Eio Job", eio_test_job},
15#endif 15/* #ifdef XATTR_TEST_DIR */
16/* {"Eio_Xattr", eio_test_xattr}, */
17/* {"Eio Job Xattr", eio_test_job_xattr}, */
18/* #endif */
16 {NULL, NULL} 19 {NULL, NULL}
17}; 20};
18 21
diff --git a/src/tests/eio/eio_suite.h b/src/tests/eio/eio_suite.h
index 170a060c73..cdecfd0f09 100644
--- a/src/tests/eio/eio_suite.h
+++ b/src/tests/eio/eio_suite.h
@@ -4,9 +4,12 @@
4#include <check.h> 4#include <check.h>
5 5
6void eio_test_monitor(TCase *tc); 6void eio_test_monitor(TCase *tc);
7void eio_test_sentry(TCase *tc);
7void eio_model_test_file(TCase *tc); 8void eio_model_test_file(TCase *tc);
8void eio_model_test_monitor_add(TCase *tc); 9void eio_model_test_monitor_add(TCase *tc);
9void eio_test_file(TCase *tc); 10void eio_test_file(TCase *tc);
11void eio_test_job(TCase *tc);
12void eio_test_job_xattr(TCase *tc);
10void eio_test_xattr(TCase *tc); 13void eio_test_xattr(TCase *tc);
11 14
12#endif /* _EIO_SUITE_H */ 15#endif /* _EIO_SUITE_H */
diff --git a/src/tests/eio/eio_test_common.c b/src/tests/eio/eio_test_common.c
new file mode 100644
index 0000000000..711c5bfac7
--- /dev/null
+++ b/src/tests/eio/eio_test_common.c
@@ -0,0 +1,89 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <stdio.h>
6#include <unistd.h>
7#include <string.h>
8#include <sys/stat.h>
9#include <fcntl.h>
10
11#include "eio_suite.h"
12#include "eio_test_common.h"
13
14#ifndef O_BINARY
15# define O_BINARY 0
16#endif
17
18static const char *good_dirs[] =
19 {
20 "eio_file_ls_simple_dir",
21 "b."
22 };
23
24unsigned int default_rights = DEFAULT_RIGHTS;
25
26const char *files[] =
27 {
28 ".hidden_file",
29 "~$b@:-*$a!{}",
30 "$b$a",
31 "normal_file"
32 };
33
34Eina_Tmpstr*
35get_full_path(const char* tmpdirname, const char* filename)
36{
37 char full_path[PATH_MAX] = "";
38 eina_str_join(full_path, sizeof(full_path), '/', tmpdirname, filename);
39 return eina_tmpstr_add(full_path);
40}
41
42Eina_Tmpstr*
43get_eio_test_file_tmp_dir()
44{
45 Eina_Tmpstr *tmp_dir;
46
47 Eina_Bool created = eina_file_mkdtemp("EioFileTestXXXXXX", &tmp_dir);
48
49 if (!created)
50 {
51 return NULL;
52 }
53
54 return tmp_dir;
55}
56
57Eina_Tmpstr*
58create_test_dirs(Eina_Tmpstr *test_dirname)
59{
60 int i, fd;
61 int count = sizeof(good_dirs) / sizeof(const char *);
62 fail_if(test_dirname == NULL);
63
64 for (i = 0; i != count; ++i)
65 {
66 Eina_Tmpstr *dirname = get_full_path(test_dirname, good_dirs[i]);
67 fail_if(mkdir(dirname, default_rights) != 0);
68 eina_tmpstr_del(dirname);
69 }
70 count = sizeof(files) / sizeof(const char *);
71 for (i = 0; i != count; ++i)
72 {
73 Eina_Tmpstr *filename = get_full_path(test_dirname, files[i]);
74 fd = open(filename, O_RDWR | O_BINARY | O_CREAT, default_rights);
75 fail_if(fd < 0);
76 fail_if(close(fd) != 0);
77 eina_tmpstr_del(filename);
78 }
79 Eina_Tmpstr *nested_dirname = get_full_path(test_dirname, good_dirs[0]);
80 for (i = 0; i != count; ++i)
81 {
82 Eina_Tmpstr *filename = get_full_path(nested_dirname, files[i]);
83 fd = open(filename, O_RDWR | O_BINARY | O_CREAT, default_rights);
84 fail_if(fd < 0);
85 fail_if(close(fd) != 0);
86 eina_tmpstr_del(filename);
87 }
88 return nested_dirname;
89}
diff --git a/src/tests/eio/eio_test_common.h b/src/tests/eio/eio_test_common.h
new file mode 100644
index 0000000000..87d416486c
--- /dev/null
+++ b/src/tests/eio/eio_test_common.h
@@ -0,0 +1,16 @@
1#ifndef _EIO_TEST_COMMON_H
2#define _EIO_TEST_COMMON_H
3
4#include <Eina.h>
5
6#define DEFAULT_RIGHTS 0755;
7extern unsigned int default_rights;
8extern const char *files[];
9
10Eina_Tmpstr* get_full_path(const char* tmpdirname, const char* filename);
11
12Eina_Tmpstr* get_eio_test_file_tmp_dir();
13
14Eina_Tmpstr* create_test_dirs(Eina_Tmpstr *test_dirname);
15
16#endif \ No newline at end of file
diff --git a/src/tests/eio/eio_test_file.c b/src/tests/eio/eio_test_file.c
index d4c71cd11d..b9eedefb96 100644
--- a/src/tests/eio/eio_test_file.c
+++ b/src/tests/eio/eio_test_file.c
@@ -13,25 +13,13 @@
13#include <Eio.h> 13#include <Eio.h>
14 14
15#include "eio_suite.h" 15#include "eio_suite.h"
16#include "eio_test_common.h"
16 17
17#ifndef O_BINARY 18#ifndef O_BINARY
18# define O_BINARY 0 19# define O_BINARY 0
19#endif 20#endif
20 21
21static unsigned int default_rights = 0755;
22static int test_count = 0; 22static int test_count = 0;
23static const char *good_dirs[] =
24 {
25 "eio_file_ls_simple_dir",
26 "b."
27 };
28static const char *files[] =
29 {
30 ".hidden_file",
31 "~$b@:-*$a!{}",
32 "$b$a",
33 "normal_file"
34 };
35 23
36static Eina_Bool 24static Eina_Bool
37_filter_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, const char *file) 25_filter_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, const char *file)
@@ -127,63 +115,6 @@ _open_done_cb(void *data, Eio_File *handler EINA_UNUSED, Eina_File *file)
127 ecore_main_loop_quit(); 115 ecore_main_loop_quit();
128} 116}
129 117
130Eina_Tmpstr*
131get_full_path(const char* tmpdirname, const char* filename)
132{
133 char full_path[PATH_MAX] = "";
134 eina_str_join(full_path, sizeof(full_path), '/', tmpdirname, filename);
135 return eina_tmpstr_add(full_path);
136}
137
138Eina_Tmpstr*
139get_eio_test_file_tmp_dir()
140{
141 Eina_Tmpstr *tmp_dir;
142
143 Eina_Bool created = eina_file_mkdtemp("EioFileTestXXXXXX", &tmp_dir);
144
145 if (!created)
146 {
147 return NULL;
148 }
149
150 return tmp_dir;
151}
152
153Eina_Tmpstr*
154create_test_dirs(Eina_Tmpstr *test_dirname)
155{
156 int i, fd;
157 int count = sizeof(good_dirs) / sizeof(const char *);
158 fail_if(test_dirname == NULL);
159
160 for (i = 0; i != count; ++i)
161 {
162 Eina_Tmpstr *dirname = get_full_path(test_dirname, good_dirs[i]);
163 fail_if(mkdir(dirname, default_rights) != 0);
164 eina_tmpstr_del(dirname);
165 }
166 count = sizeof(files) / sizeof(const char *);
167 for (i = 0; i != count; ++i)
168 {
169 Eina_Tmpstr *filename = get_full_path(test_dirname, files[i]);
170 fd = open(filename, O_RDWR | O_BINARY | O_CREAT, default_rights);
171 fail_if(fd < 0);
172 fail_if(close(fd) != 0);
173 eina_tmpstr_del(filename);
174 }
175 Eina_Tmpstr *nested_dirname = get_full_path(test_dirname, good_dirs[0]);
176 for (i = 0; i != count; ++i)
177 {
178 Eina_Tmpstr *filename = get_full_path(nested_dirname, files[i]);
179 fd = open(filename, O_RDWR | O_BINARY | O_CREAT, default_rights);
180 fail_if(fd < 0);
181 fail_if(close(fd) != 0);
182 eina_tmpstr_del(filename);
183 }
184 return nested_dirname;
185}
186
187START_TEST(eio_file_test_ls) 118START_TEST(eio_file_test_ls)
188{ 119{
189 int number_of_listed_files = 0, ret; 120 int number_of_listed_files = 0, ret;
@@ -297,6 +228,7 @@ START_TEST(eio_file_test_file)
297 is_dir = EINA_FALSE; 228 is_dir = EINA_FALSE;
298 eio_file_direct_stat(nested_filename, _stat_done_cb, _error_cb, &is_dir); 229 eio_file_direct_stat(nested_filename, _stat_done_cb, _error_cb, &is_dir);
299 ecore_main_loop_begin(); 230 ecore_main_loop_begin();
231 default_rights = DEFAULT_RIGHTS;
300 232
301 test_count = 1; 233 test_count = 1;
302 eio_file_move(nested_filename, new_filename, _progress_cb, _done_cb, 234 eio_file_move(nested_filename, new_filename, _progress_cb, _done_cb,
diff --git a/src/tests/eio/eio_test_job.c b/src/tests/eio/eio_test_job.c
new file mode 100644
index 0000000000..9ef8ced03c
--- /dev/null
+++ b/src/tests/eio/eio_test_job.c
@@ -0,0 +1,290 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <Ecore.h>
6#include <Ecore_File.h>
7#include <Eio.h>
8
9#include "eio_suite.h"
10#include "eio_test_common.h"
11
12#ifndef O_BINARY
13# define O_BINARY 0
14#endif
15
16static int test_count = 0;
17
18static int DONE_CALLED = 0xdeadbeef;
19
20static void
21_filter_direct_cb(void *data EINA_UNUSED, const Eo_Event *event)
22{
23 Eio_Filter_Direct_Data *event_info = event->info;
24 char *last_slash = strrchr(event_info->info->path, '/');
25
26 //Check if it is a hidden file
27 if (last_slash != NULL && strlen(last_slash) > 1 && last_slash[1] == '.')
28 event_info->filter = EINA_FALSE;
29 else
30 event_info->filter = EINA_TRUE;
31}
32
33static void
34_main_direct_cb(void *data, const Eina_File_Direct_Info *info, Eina_Promise* promise EINA_UNUSED)
35{
36 int *number_of_listed_files = (int *)data;
37
38 fprintf(stderr, "Processing file:%s\n", info->path);
39 (*number_of_listed_files)++;
40}
41
42static void
43_filter_cb(void *data EINA_UNUSED, const Eo_Event *event)
44{
45 Eio_Filter_Name_Data *event_info = event->info;
46 char *last_slash = strrchr(event_info->file, '/');
47
48 //Check if it is a hidden file
49 if (last_slash != NULL && strlen(last_slash) > 1 && last_slash[1] == '.')
50 event_info->filter = EINA_FALSE;
51 else
52 event_info->filter = EINA_TRUE;
53}
54
55static void
56_main_cb(void *data, const char *file, Eina_Promise* promise EINA_UNUSED)
57{
58 int *number_of_listed_files = (int *)data;
59
60 fprintf(stderr, "Processing file:%s\n", file);
61 (*number_of_listed_files)++;
62}
63
64static void
65_done_cb(void *data, Eio_File *handler EINA_UNUSED, Eina_Promise* promise EINA_UNUSED)
66{
67 int *number_of_listed_files = (int *)data;
68 fail_if((*number_of_listed_files) != test_count);
69 *number_of_listed_files = DONE_CALLED;
70 ecore_main_loop_quit();
71}
72
73static void
74_error_cb(void *data EINA_UNUSED, Eina_Error error, Eina_Promise* promise EINA_UNUSED)
75{
76 const char *msg = eina_error_msg_get(error);
77 EINA_LOG_ERR("error: %s", msg);
78 ecore_main_loop_quit();
79}
80
81static void
82_open_done_cb(void *data, Eina_File **file, Eina_Promise* promise)
83{
84 Eina_Bool *opened = (Eina_Bool *)data;
85 *opened = EINA_TRUE;
86 eina_promise_release_value_ownership(promise);
87 eina_file_close(*file);
88 ecore_main_loop_quit();
89}
90
91static void
92_stat_done_cb(void *data, const Eina_Stat *stat, Eina_Promise* promise EINA_UNUSED)
93{
94 Eina_Bool *is_dir = (Eina_Bool *)data;
95 unsigned int rights;
96 fail_if(eio_file_is_dir(stat) != *is_dir);
97 fail_if(eio_file_is_lnk(stat));
98 rights = stat->mode & (S_IRWXU | S_IRWXG | S_IRWXO);
99 fail_if(rights != default_rights);
100 ecore_main_loop_quit();
101}
102
103typedef Eina_Promise* (*Eio_Job_Test_Stat_Ls_Func)(Eo *job, const char *path);
104
105static void
106_do_ls_test(Eio_Job_Test_Stat_Ls_Func ls_func,
107 const Eo_Event_Description *event,
108 Eo_Event_Cb filter_cb,
109 Eina_Promise_Progress_Cb progress_cb,
110 int expected_test_count,
111 const char* test_dirname)
112{
113 int main_files = 0;
114
115 Eio_Job *job = eo_add(EIO_JOB_CLASS, NULL);
116 Eina_Promise *promise = NULL;
117
118 eo_event_callback_add(job, event, filter_cb, NULL);
119 promise = ls_func(job, test_dirname);
120 test_count = expected_test_count;
121 eina_promise_progress_cb_add(promise, progress_cb, &main_files, NULL);
122 eina_promise_then(promise,
123 (Eina_Promise_Cb)&_done_cb,
124 (Eina_Promise_Error_Cb)&_error_cb,
125 &main_files);
126
127 ecore_main_loop_begin();
128
129 fail_if(main_files != DONE_CALLED);
130
131 eo_unref(job);
132}
133
134static void
135_do_direct_ls_test(Eio_Job_Test_Stat_Ls_Func ls_func,
136 int expected_test_count,
137 const char *test_dirname)
138{
139 _do_ls_test(ls_func,
140 EIO_JOB_EVENT_FILTER_DIRECT,
141 (Eo_Event_Cb)&_filter_direct_cb,
142 (Eina_Promise_Progress_Cb)&_main_direct_cb,
143 expected_test_count,
144 test_dirname);
145}
146
147START_TEST(eio_job_test_file_direct_stat)
148{
149 Eina_Bool is_dir;
150 int ret;
151
152 ret = ecore_init();
153 fail_if(ret < 1);
154 ret = eio_init();
155 fail_if(ret < 1);
156 ret = eina_init();
157 fail_if(ret < 1);
158 ret = ecore_file_init();
159 fail_if(ret < 1);
160
161 Eina_Tmpstr *test_dirname = get_eio_test_file_tmp_dir();
162 Eina_Tmpstr *nested_dirname = create_test_dirs(test_dirname);
163 Eina_Tmpstr *nested_filename = get_full_path(test_dirname, files[3]);
164
165 Eio_Job *job = eo_add(EIO_JOB_CLASS, NULL);
166 Eina_Promise *promise = NULL;
167 // Start testing
168 is_dir = EINA_TRUE;
169
170 promise = eio_job_file_direct_stat(job, nested_dirname);
171 eina_promise_then(promise, (Eina_Promise_Cb)&_stat_done_cb, (Eina_Promise_Error_Cb)&_error_cb, &is_dir);
172 ecore_main_loop_begin();
173
174 is_dir = EINA_FALSE;
175 promise = eio_job_file_direct_stat(job, nested_filename);
176 eina_promise_then(promise, (Eina_Promise_Cb)&_stat_done_cb, (Eina_Promise_Error_Cb)&_error_cb, &is_dir);
177 ecore_main_loop_begin();
178 eo_unref(job);
179
180 // Cleanup
181 fail_if(!ecore_file_recursive_rm(test_dirname));
182
183 eina_tmpstr_del(nested_dirname);
184 eina_tmpstr_del(test_dirname);
185 eina_tmpstr_del(nested_filename);
186 ecore_file_shutdown();
187 eina_shutdown();
188 eio_shutdown();
189 ecore_shutdown();
190}
191END_TEST
192
193START_TEST(eio_job_test_ls_funcs)
194{
195 int ret;
196
197 ret = ecore_init();
198 fail_if(ret < 1);
199 ret = eio_init();
200 fail_if(ret < 1);
201 ret = eina_init();
202 fail_if(ret < 1);
203 ret = ecore_file_init();
204 fail_if(ret < 1);
205
206 Eina_Tmpstr *test_dirname = get_eio_test_file_tmp_dir();
207 Eina_Tmpstr *nested_dirname = create_test_dirs(test_dirname);
208 Eina_Tmpstr *nested_filename = get_full_path(test_dirname, files[3]);
209
210 // Start testing
211
212 fprintf(stderr, __FILE__ ":%d %s\n", __LINE__, __func__); fflush(stderr);
213 _do_ls_test(&eio_job_file_ls,
214 EIO_JOB_EVENT_FILTER_NAME,
215 (Eo_Event_Cb)&_filter_cb,
216 (Eina_Promise_Progress_Cb)&_main_cb,
217 5,
218 test_dirname);
219 fprintf(stderr, __FILE__ ":%d %s\n", __LINE__, __func__); fflush(stderr);
220
221 _do_direct_ls_test(&eio_job_file_stat_ls, 5, test_dirname);
222
223 _do_direct_ls_test(&eio_job_file_direct_ls, 5, test_dirname);
224
225 _do_direct_ls_test(&eio_job_dir_stat_ls, 8, test_dirname);
226
227 _do_direct_ls_test(&eio_job_dir_direct_ls, 8, test_dirname);
228
229 // Cleanup
230 fail_if(!ecore_file_recursive_rm(test_dirname));
231
232 eina_tmpstr_del(nested_dirname);
233 eina_tmpstr_del(test_dirname);
234 eina_tmpstr_del(nested_filename);
235 ecore_file_shutdown();
236 eina_shutdown();
237 eio_shutdown();
238 ecore_shutdown();
239}
240END_TEST
241
242START_TEST(eio_job_test_open)
243{
244 Eina_Bool opened_file;
245 int ret;
246
247 ret = ecore_init();
248 fail_if(ret < 1);
249 ret = eio_init();
250 fail_if(ret < 1);
251 ret = eina_init();
252 fail_if(ret < 1);
253 ret = ecore_file_init();
254 fail_if(ret < 1);
255
256 Eina_Tmpstr *test_dirname = get_eio_test_file_tmp_dir();
257 Eina_Tmpstr *nested_dirname = create_test_dirs(test_dirname);
258 Eina_Tmpstr *nested_filename = get_full_path(test_dirname, files[3]);
259
260 opened_file = EINA_FALSE;
261 Eio_Job *job = eo_add(EIO_JOB_CLASS, NULL);
262 Eina_Promise *promise = NULL;
263
264 promise = eio_job_file_open(job, nested_filename, EINA_FALSE);
265 eina_promise_then(promise, (Eina_Promise_Cb)&_open_done_cb, (Eina_Promise_Error_Cb)&_error_cb, &opened_file);
266 ecore_main_loop_begin();
267 eo_unref(job);
268 fail_if(!opened_file);
269
270 // Cleanup
271 fail_if(!ecore_file_recursive_rm(test_dirname));
272
273 eina_tmpstr_del(nested_dirname);
274 eina_tmpstr_del(test_dirname);
275 eina_tmpstr_del(nested_filename);
276 ecore_file_shutdown();
277 eina_shutdown();
278 eio_shutdown();
279 ecore_shutdown();
280}
281END_TEST
282
283void
284eio_test_job(TCase *tc)
285{
286 tcase_add_test(tc, eio_job_test_ls_funcs);
287 tcase_add_test(tc, eio_job_test_file_direct_stat);
288 tcase_add_test(tc, eio_job_test_open);
289}
290;
diff --git a/src/tests/eio/eio_test_job_xattr.c b/src/tests/eio/eio_test_job_xattr.c
new file mode 100644
index 0000000000..0cf5aca0fe
--- /dev/null
+++ b/src/tests/eio/eio_test_job_xattr.c
@@ -0,0 +1,204 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <stdio.h>
6#include <unistd.h>
7#include <string.h>
8#include <fcntl.h>
9
10#include <Ecore.h>
11#include <Ecore_File.h>
12#include <Eio.h>
13
14#include "eio_suite.h"
15#include "eio_test_common.h"
16
17
18#ifdef XATTR_TEST_DIR
19
20static const char *attribute[] =
21 {
22 "user.comment1",
23 "user.comment2",
24 "user.comment3"
25 };
26static const char *attr_data[] =
27 {
28 "This is a test file",
29 "This line is a comment",
30 "This file has extra attributes"
31 };
32
33struct eina_iterator
34{
35 Eina_Iterator* success_iterator;
36 Eina_Iterator* failure_iterator;
37};
38
39int total_attributes = sizeof(attribute)/sizeof(attribute[0]);
40
41static Eina_Bool
42_filter_cb(void *data EINA_UNUSED, const Eo_Event *event)
43{
44 Eio_Filter_Name_Data *event_info = event->info;
45
46 return event_info->filter = EINA_TRUE;
47}
48
49static void
50_main_cb(void *data, const char *attr)
51{
52 int *num_of_attr = (int *)data;
53 unsigned int i;
54
55 for (i = 0; i < sizeof (attribute) / sizeof (attribute[0]); ++i)
56 if (strcmp(attr, attribute[i]) == 0)
57 {
58 (*num_of_attr)++;
59 break;
60 }
61
62}
63
64static void
65_done_cb(void *data, void *value EINA_UNUSED)
66
67{
68 int *num_of_attr = (int *)data;
69
70 fail_if(*num_of_attr != total_attributes);
71
72 ecore_main_loop_quit();
73}
74
75static void
76_done_get_cb(void *data EINA_UNUSED, struct eina_iterator* it)
77{
78 int i = 0;
79 Eio_Xattr_Data *get_data;
80
81 while (eina_iterator_next(it->success_iterator, (void**)&get_data))
82 {
83 fail_if(!get_data);
84 fail_if(strcmp(get_data->data, attr_data[i]) != 0);
85 i++;
86 }
87
88 fail_if(i != total_attributes);
89
90 ecore_main_loop_quit();
91}
92
93static void
94_done_set_cb(void *data, struct eina_iterator* it)
95{
96 int *placeholder;
97 int *num_of_attr = data;
98 while(eina_iterator_next(it->success_iterator, (void**)&placeholder))
99 *num_of_attr += 1;
100
101 fail_if(*num_of_attr != total_attributes);
102
103 ecore_main_loop_quit();
104}
105
106static void
107_error_cb(void *data EINA_UNUSED, Eina_Error *error)
108
109{
110 fprintf(stderr, "Something has gone wrong:%s\n", strerror(*error));
111 abort();
112
113 ecore_main_loop_quit();
114}
115
116START_TEST(eio_test_job_xattr_set)
117{
118 char *filename = "eio-tmpfile";
119 Eina_Tmpstr *test_file_path;
120 int num_of_attr = 0, fd;
121 unsigned int i;
122 Eo *job;
123 Eina_Promise *list_promise = NULL;
124 Eina_Promise **attrib_promises = NULL;
125
126 ecore_init();
127 eina_init();
128 eio_init();
129
130 job = eo_add(EIO_JOB_CLASS, NULL);
131
132 test_file_path = get_full_path(XATTR_TEST_DIR, filename);
133 fd = open(test_file_path,
134 O_WRONLY | O_CREAT | O_TRUNC,
135 S_IRWXU | S_IRWXG | S_IRWXO);
136 fail_if(fd == 0);
137
138 attrib_promises = (Eina_Promise **)calloc(total_attributes + 1, sizeof(Eina_Promise*));
139 attrib_promises[total_attributes] = NULL;
140
141 for (i = 0; i < sizeof(attribute) / sizeof(attribute[0]); ++i)
142 {
143 eio_job_file_xattr_set(job, test_file_path, attribute[i],
144 attr_data[i], strlen(attr_data[i]),
145 EINA_XATTR_INSERT,
146 &attrib_promises[i]);
147
148 fail_if(num_of_attr != 0); // test asynchronous
149 }
150 eina_promise_then(eina_promise_all(eina_carray_iterator_new((void**)attrib_promises)),
151 (Eina_Promise_Cb)_done_set_cb, (Eina_Promise_Error_Cb)_error_cb, &num_of_attr);
152
153 ecore_main_loop_begin();
154
155 free(attrib_promises);
156
157 num_of_attr = 0;
158
159 attrib_promises = (Eina_Promise **)calloc(total_attributes + 1, sizeof(Eina_Promise*));
160 attrib_promises[total_attributes] = NULL;
161
162 for (i = 0; i < sizeof(attribute) / sizeof(attribute[0]); ++i)
163 {
164 eio_job_file_xattr_get(job, test_file_path, attribute[i], &attrib_promises[i]);
165 }
166
167 eina_promise_then(eina_promise_all(eina_carray_iterator_new((void**)attrib_promises)),
168 (Eina_Promise_Cb)_done_get_cb, (Eina_Promise_Error_Cb)_error_cb, &num_of_attr);
169
170 ecore_main_loop_begin();
171
172 num_of_attr = 0;
173
174 eo_event_callback_add(job, EIO_JOB_EVENT_XATTR, _filter_cb, NULL);
175 eio_job_file_xattr(job, test_file_path, &list_promise);
176 eina_promise_progress_cb_add(list_promise, (Eina_Promise_Progress_Cb)_main_cb, &num_of_attr, NULL);
177 eina_promise_then(list_promise, (Eina_Promise_Cb)_done_cb, (Eina_Promise_Error_Cb)_error_cb, &num_of_attr);
178
179 fail_if(num_of_attr != 0);
180
181 ecore_main_loop_begin();
182
183 free(attrib_promises);
184
185 eo_unref(job);
186 close(fd);
187 unlink(test_file_path);
188 eina_tmpstr_del(test_file_path);
189 eio_shutdown();
190 eina_shutdown();
191 ecore_shutdown();
192}
193END_TEST
194
195#endif
196
197void eio_test_job_xattr(TCase *tc)
198{
199#ifdef XATTR_TEST_DIR
200 tcase_add_test(tc, eio_test_job_xattr_set);
201#else
202 (void)tc;
203#endif
204}
diff --git a/src/tests/eio/eio_test_sentry.c b/src/tests/eio/eio_test_sentry.c
new file mode 100644
index 0000000000..4f3c6c768e
--- /dev/null
+++ b/src/tests/eio/eio_test_sentry.c
@@ -0,0 +1,755 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <stdio.h>
6#include <unistd.h>
7#include <string.h>
8
9#include <Ecore.h>
10#include <Ecore_File.h>
11#include <Eio.h>
12
13#include "eio_suite.h"
14
15/////////////////timeout function
16
17#define TEST_TIMEOUT_SEC 10
18#define TEST_OPERATION_DELAY 0.5
19
20static Ecore_Timer *test_timeout_timer;
21
22static Eina_Bool _test_timeout_cb(void *data EINA_UNUSED)
23{
24 ck_abort_msg("test timeout");
25 ecore_main_loop_quit();
26 return ECORE_CALLBACK_CANCEL;
27}
28
29static void _cancel_timeout()
30{
31 if (test_timeout_timer != NULL)
32 {
33 ecore_timer_del (test_timeout_timer);
34 test_timeout_timer = NULL;
35 }
36}
37
38static Eina_Bool _test_timeout_expected(void *data EINA_UNUSED)
39{
40 if (test_timeout_timer != NULL)
41 {
42 _cancel_timeout();
43 }
44 ecore_main_loop_quit();
45 return ECORE_CALLBACK_CANCEL;
46}
47
48///////////////// file and directory operations
49
50typedef struct {
51 const char *src;
52 const char *dst;
53} RenameOperation;
54
55static Eina_Bool _delete_directory(void *data)
56{
57 const char *dirname = (const char*)data;
58 if (ecore_file_is_dir(dirname))
59 {
60 ecore_file_recursive_rm(dirname);
61 }
62 return ECORE_CALLBACK_CANCEL;
63}
64
65static Eina_Bool _create_directory(void *data)
66{
67 const char *dirname = (const char*)data;
68 ecore_file_mkpath(dirname);
69 return ECORE_CALLBACK_CANCEL;
70}
71
72
73static Eina_Bool _create_file(void *data)
74{
75 FILE *fd = fopen((const char*)data, "wb+");
76 ck_assert_ptr_ne(fd, NULL);
77 fprintf(fd, "test test");
78 fclose(fd);
79 return ECORE_CALLBACK_CANCEL;
80}
81
82static Eina_Bool _delete_file(void *data)
83{
84 Eina_Bool file_removed = ecore_file_remove((const char*)data);
85 ck_assert(file_removed);
86 return ECORE_CALLBACK_CANCEL;
87}
88
89static Eina_Bool _modify_file(void *data)
90{
91 FILE *fd = fopen((const char*)data, "ab");
92 ck_assert_ptr_ne(fd, NULL);
93 fprintf(fd, "appened");
94 fclose(fd);
95 return ECORE_CALLBACK_CANCEL;
96}
97
98static Eina_Bool _modify_attrib_file(void *data)
99{
100 int ret = chmod((const char*)data, 0666);
101 ck_assert_int_eq(ret, 0);
102 return ECORE_CALLBACK_CANCEL;
103}
104
105/////// helper functions
106
107static Eina_Bool _check_event_path(void *data, const Eo_Event *event)
108{
109 Eio_Sentry_Event *event_info = event->info;
110 ck_assert_str_eq((const char*)data, event_info->trigger);
111 return EINA_TRUE;
112}
113
114static Eina_Tmpstr *_common_init()
115{
116 Eina_Tmpstr *dirname;
117 fail_if(eio_init() != 1);
118 ecore_file_init();
119
120 //test timeout
121 test_timeout_timer = ecore_timer_add(TEST_TIMEOUT_SEC, _test_timeout_cb, NULL);
122
123 eina_file_mkdtemp("checkFileCreationXXXXXX", &dirname);
124 return dirname;
125}
126
127static void _common_shutdown(Eina_Tmpstr *dirname)
128{
129 _delete_directory((void*)dirname);
130 ecore_file_shutdown();
131 fail_if(eio_shutdown() != 0);
132 eina_tmpstr_del(dirname);
133}
134
135/////// tests monitoring a directory
136
137START_TEST(eio_test_sentry_add_and_remove)
138{
139 Eina_Tmpstr *dirname = _common_init();
140 Eina_Stringshare *filename;
141 Eo *sentry;
142
143 filename = eina_stringshare_printf("%s/eio_test_sentry_directory_file_created_notify", dirname);
144 _create_directory((void*)filename);
145
146 //sleep to avoid catching event generated by above manipulations
147 usleep(500000);
148
149 //monitor directory
150 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
151 fail_if(!eio_sentry_add(sentry, filename));
152
153 usleep(500000);
154
155 eio_sentry_del(sentry, filename);
156
157 eo_unref(sentry);
158
159 _common_shutdown(dirname);
160}
161END_TEST
162
163START_TEST(eio_test_sentry_add_remove_add)
164{
165 Eina_Tmpstr *dirname = _common_init();
166 Eina_Stringshare *filename;
167 Eo* sentry;
168
169 filename = eina_stringshare_printf("%s/eio_test_sentry_add_remove_add", dirname);
170 _create_directory((void*)filename);
171
172 //sleep to avoid catching event generated by above manipulations
173 usleep(500000);
174
175 //monitor directory
176 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
177 fail_if(!eio_sentry_add(sentry, filename));
178 eio_sentry_del(sentry, filename);
179
180 usleep(500000);
181
182 fail_if(!eio_sentry_add(sentry, filename));
183 eio_sentry_del(sentry, filename);
184
185 eo_unref(sentry);
186
187 _common_shutdown(dirname);
188}
189END_TEST
190
191START_TEST(eio_test_sentry_add_add_remove_remove)
192{
193 Eina_Tmpstr *dirname = _common_init();
194 Eina_Stringshare *filename1;
195 Eina_Stringshare *filename2;
196 Eo *sentry;
197
198 filename1 = eina_stringshare_printf("%s/eio_test_sentry_add_add_remove_remove", dirname);
199 filename2 = eina_stringshare_printf("%s/eio_test_sentry_add_add_remove_remove", dirname);
200 _create_directory((void*)filename1);
201 _create_directory((void*)filename2);
202
203 //sleep to avoid catching event generated by above manipulations
204 usleep(500000);
205
206 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
207
208 //monitor directory
209 fail_if(!eio_sentry_add(sentry, filename1));
210 fail_if(!eio_sentry_add(sentry, filename2));
211 usleep(500000);
212 eio_sentry_del(sentry, filename1);
213 eio_sentry_del(sentry, filename2);
214
215 eo_unref(sentry);
216
217 _common_shutdown(dirname);
218}
219END_TEST
220
221static void _target_notified_cb(void *data, const Eo_Event *event)
222{
223 if (_check_event_path(data, event))
224 {
225 _cancel_timeout();
226 ecore_main_loop_quit();
227 }
228}
229
230
231START_TEST(eio_test_sentry_directory_file_created_notify)
232{
233 Eina_Tmpstr *dirname = _common_init();
234 Eina_Stringshare *filename;
235 Eo* sentry;
236
237 filename = eina_stringshare_printf("%s/eio_test_sentry_directory_file_created_notify", dirname);
238 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
239
240 //sleep to avoid catching event generated by above manipulations
241 usleep(500000);
242
243 //monitor directory
244 fail_if(!eio_sentry_add(sentry, dirname));
245 eo_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_CREATED, (Eo_Event_Cb)_target_notified_cb, filename);
246
247 ecore_timer_add(TEST_OPERATION_DELAY, _create_file, filename);
248
249 ecore_main_loop_begin();
250
251 eo_unref(sentry);
252
253 _common_shutdown(dirname);
254}
255END_TEST
256
257START_TEST(eio_test_sentry_directory_file_deleted_notify)
258{
259 Eina_Tmpstr *dirname = _common_init();
260 Eina_Stringshare *filename;
261 Eo *sentry;
262
263 filename = eina_stringshare_printf("%s/eio_test_sentry_directory_file_deleted_notify", dirname);
264 _create_file((void*)filename);
265 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
266
267 //sleep to avoid catching event generated by above manipulations
268 usleep(500000);
269
270 //monitor directory
271 fail_if(!eio_sentry_add(sentry, dirname));
272 eo_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_DELETED, (Eo_Event_Cb)_target_notified_cb, filename);
273
274 ecore_timer_add(TEST_OPERATION_DELAY, _delete_file, filename);
275
276 ecore_main_loop_begin();
277
278 eo_unref(sentry);
279
280 _common_shutdown(dirname);
281}
282END_TEST
283
284START_TEST(eio_test_sentry_directory_file_modified_notify)
285{
286 Eina_Tmpstr *dirname = _common_init();
287 Eina_Stringshare *filename;
288 Eo *sentry;
289
290 filename = eina_stringshare_printf("%s/eio_test_sentry_directory_file_modified_notify", dirname);
291 _create_file((void*)filename);
292 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
293
294 //sleep to avoid catching event generated by above manipulations
295 usleep(500000);
296
297 //monitor directory
298 fail_if(!eio_sentry_add(sentry, dirname));
299 eo_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_MODIFIED, (Eo_Event_Cb)_target_notified_cb, filename);
300
301 ecore_timer_add(TEST_OPERATION_DELAY, _modify_file, filename);
302
303 ecore_main_loop_begin();
304
305 eo_unref(sentry);
306
307 //cleanup
308 _common_shutdown(dirname);
309}
310END_TEST
311
312START_TEST(eio_test_sentry_directory_file_closed_notify)
313{
314 Eina_Tmpstr *dirname = _common_init();
315 Eina_Stringshare *filename;
316 Eo *sentry;
317
318 filename = eina_stringshare_printf("%s/eio_test_sentry_directory_file_closed_notify", dirname);
319 _create_file((void*)filename);
320 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
321
322 //sleep to avoid catching event generated by above manipulations
323 usleep(500000);
324
325 //monitor directory
326 fail_if(!eio_sentry_add(sentry, dirname));
327 eo_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_CLOSED, (Eo_Event_Cb)_target_notified_cb, filename);
328 ecore_timer_add(TEST_OPERATION_DELAY, _modify_file, filename);
329
330 ecore_main_loop_begin();
331
332 eo_unref(sentry);
333
334 _common_shutdown(dirname);
335}
336END_TEST
337
338START_TEST(eio_test_sentry_directory_directory_created_notify)
339{
340 Eina_Tmpstr *dirname = _common_init();
341 Eina_Stringshare *filename;
342 Eo *sentry;
343
344 filename = eina_stringshare_printf("%s/eio_test_sentry_directory_directory_created_notify", dirname);
345 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
346
347 //sleep to avoid catching event generated by above manipulations
348 usleep(500000);
349
350 //monitor directory
351 fail_if(!eio_sentry_add(sentry, dirname));
352 eo_event_callback_add(sentry, EIO_SENTRY_EVENT_DIRECTORY_CREATED, (Eo_Event_Cb)_target_notified_cb, filename);
353
354 ecore_timer_add(TEST_OPERATION_DELAY, _create_directory, filename);
355
356 ecore_main_loop_begin();
357
358 eo_unref(sentry);
359
360 _common_shutdown(dirname);
361}
362END_TEST
363
364START_TEST(eio_test_sentry_directory_directory_deleted_notify)
365{
366 Eina_Tmpstr *dirname = _common_init();
367 Eina_Stringshare *filename;
368 Eo *sentry;
369
370 filename = eina_stringshare_printf("%s/eio_test_sentry_directory_directory_deleted_notify", dirname);
371 _create_directory((void*)filename);
372 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
373
374 //sleep to avoid catching event generated by above manipulations
375 usleep(500000);
376
377 //monitor directory
378 fail_if(!eio_sentry_add(sentry, dirname));
379 eo_event_callback_add(sentry, EIO_SENTRY_EVENT_DIRECTORY_DELETED, (Eo_Event_Cb)_target_notified_cb, filename);
380
381 ecore_timer_add(TEST_OPERATION_DELAY, _delete_directory, filename);
382
383 ecore_main_loop_begin();
384
385 eo_unref(sentry);
386
387 _common_shutdown(dirname);
388}
389END_TEST
390
391START_TEST(eio_test_sentry_directory_directory_modified_notify)
392{
393 Eina_Tmpstr *dirname = _common_init();
394 Eina_Stringshare *filename;
395 Eo *sentry;
396
397 filename = eina_stringshare_printf("%s/eio_test_sentry_directory_directory_modified_notify", dirname);
398 _create_directory((void*)filename);
399 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
400
401 //sleep to avoid catching event generated by above manipulations
402 usleep(500000);
403
404 //monitor directory
405 fail_if(!eio_sentry_add(sentry, dirname));
406 eo_event_callback_add(sentry, EIO_SENTRY_EVENT_DIRECTORY_MODIFIED, (Eo_Event_Cb)_target_notified_cb, filename);
407
408 ecore_timer_add(TEST_OPERATION_DELAY, _modify_attrib_file, filename);
409
410 ecore_main_loop_begin();
411
412 eo_unref(sentry);
413
414 _common_shutdown(dirname);
415}
416END_TEST
417
418START_TEST(eio_test_sentry_directory_directory_self_deleted_notify)
419{
420 Eina_Tmpstr *dirname = _common_init();
421 Eo *sentry = eo_add(EIO_SENTRY_CLASS, NULL);
422
423 //sleep to avoid catching event generated by above manipulations
424 usleep(500000);
425
426 //monitor directory
427 fail_if(!eio_sentry_add(sentry, dirname));
428 eo_event_callback_add(sentry, EIO_SENTRY_EVENT_SELF_DELETED, (Eo_Event_Cb)_target_notified_cb, dirname);
429
430 ecore_timer_add(TEST_OPERATION_DELAY, _delete_directory, dirname);
431
432 ecore_main_loop_begin();
433
434 eo_unref(sentry);
435
436 _common_shutdown(dirname);
437}
438END_TEST
439
440// //////// test monitoring a single file
441
442START_TEST(eio_test_sentry_file_file_modified_notify)
443{
444 Eina_Tmpstr *dirname = _common_init();
445 Eina_Stringshare *filename;
446 Eo *sentry;
447
448 filename = eina_stringshare_printf("%s/filecreated", dirname);
449 _create_file((void*)filename);
450 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
451
452 //sleep to avoid catching event generated by above manipulations
453 usleep(500000);
454
455 //monitor file
456 fail_if(!eio_sentry_add(sentry, filename));
457 eo_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_MODIFIED, (Eo_Event_Cb)_target_notified_cb, filename);
458
459 ecore_timer_add(TEST_OPERATION_DELAY, _modify_file, filename);
460
461 ecore_main_loop_begin();
462
463 eo_unref(sentry);
464
465 //cleanup
466 _common_shutdown(dirname);
467}
468END_TEST
469
470START_TEST(eio_test_sentry_file_file_attrib_modified_notify)
471{
472 Eina_Tmpstr *dirname = _common_init();
473 Eina_Stringshare *filename;
474 Eo *sentry;
475
476 filename = eina_stringshare_printf("%s/eio_test_sentry_file_file_attrib_modified_notify", dirname);
477 _create_file((void*)filename);
478 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
479
480 //sleep to avoid catching event generated by above manipulations
481 usleep(500000);
482
483 //monitor file
484 fail_if(!eio_sentry_add(sentry, filename));
485 eo_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_MODIFIED, (Eo_Event_Cb)_target_notified_cb, filename);
486
487 ecore_timer_add(TEST_OPERATION_DELAY, _modify_attrib_file, filename);
488
489 ecore_main_loop_begin();
490
491 eo_unref(sentry);
492
493 _common_shutdown(dirname);
494}
495END_TEST
496
497
498START_TEST(eio_test_sentry_file_file_closed_notify)
499{
500 Eina_Tmpstr *dirname = _common_init();
501 Eina_Stringshare *filename;
502 Eo* sentry;
503
504 filename = eina_stringshare_printf("%s/eio_test_sentry_file_file_closed_notify", dirname);
505 _create_file((void*)filename);
506 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
507
508 //sleep to avoid catching event generated by above manipulations
509 usleep(500000);
510
511 //monitor file
512 fail_if(!eio_sentry_add(sentry, dirname));
513 eo_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_CLOSED, (Eo_Event_Cb)_target_notified_cb, filename);
514 ecore_timer_add(TEST_OPERATION_DELAY, _modify_file, filename);
515
516 ecore_main_loop_begin();
517
518 eo_unref(sentry);
519
520 _common_shutdown(dirname);
521}
522END_TEST
523
524START_TEST(eio_test_sentry_file_file_self_deleted_notify)
525{
526 Eina_Tmpstr *dirname = _common_init();
527 Eina_Stringshare *filename;
528 Eo* sentry;
529
530 filename = eina_stringshare_printf("%s/eio_test_sentry_file_file_self_deleted_notify", dirname);
531 _create_file((void*)filename);
532 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
533
534 //sleep to avoid catching event generated by above manipulations
535 usleep(500000);
536
537 //monitor file
538 fail_if(!eio_sentry_add(sentry, filename));
539 eo_event_callback_add(sentry, EIO_SENTRY_EVENT_SELF_DELETED, (Eo_Event_Cb)_target_notified_cb, filename);
540
541 ecore_timer_add(TEST_OPERATION_DELAY, _delete_file, filename);
542
543 ecore_main_loop_begin();
544
545 eo_unref(sentry);
546
547 _common_shutdown(dirname);
548}
549END_TEST
550
551START_TEST(eio_test_sentry_two_monitors_one_event)
552{
553 Eina_Tmpstr *dirname = _common_init();
554 Eina_Tmpstr *dirname2;
555 Eo *sentry;
556
557 Eina_Stringshare *filename;
558
559 eina_file_mkdtemp("checkFileCreationXXXXXX", &dirname2);
560 filename = eina_stringshare_printf("%s/eio_test_sentry_two_monitors_one_event", dirname);
561 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
562
563 //sleep to avoid catching event generated by above manipulations
564 usleep(500000);
565
566 //monitor directory
567 fail_if(!eio_sentry_add(sentry, dirname));
568 fail_if(!eio_sentry_add(sentry, dirname2));
569 eo_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_CREATED, (Eo_Event_Cb)_target_notified_cb, filename);
570
571 ecore_timer_add(TEST_OPERATION_DELAY, _create_file, filename);
572
573 ecore_main_loop_begin();
574
575 eo_unref(sentry);
576
577 _delete_directory((void*)dirname2);
578 _common_shutdown(dirname);
579}
580END_TEST
581
582
583START_TEST(eio_test_sentry_two_monitors_one_removed_one_event)
584{
585 Eina_Tmpstr *dirname = _common_init();
586 Eina_Tmpstr *dirname2;
587 Eo *sentry;
588
589 Eina_Stringshare *filename;
590
591 eina_file_mkdtemp("checkFileCreationXXXXXX", &dirname2);
592 filename = eina_stringshare_printf("%s/eio_test_sentry_two_monitors_one_removed", dirname);
593 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
594
595 //sleep to avoid catching event generated by above manipulations
596 usleep(500000);
597
598 //monitor directory
599 fail_if(!eio_sentry_add(sentry, dirname2));
600 fail_if(!eio_sentry_add(sentry, dirname));
601 eio_sentry_del(sentry, dirname2);
602 eo_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_CREATED, (Eo_Event_Cb)_target_notified_cb, filename);
603
604 ecore_timer_add(TEST_OPERATION_DELAY, _create_file, filename);
605
606 ecore_main_loop_begin();
607
608 eo_unref(sentry);
609
610 _delete_directory((void*)dirname2);
611 _common_shutdown(dirname);
612}
613END_TEST
614
615static void _unexpected_event_cb(void *data EINA_UNUSED, const Eo_Event *event EINA_UNUSED)
616{
617 ck_abort_msg("unexpected event");
618}
619
620START_TEST(eio_test_sentry_two_monitors_one_removed_no_event)
621{
622 Eina_Tmpstr *dirname = _common_init();
623 Eina_Tmpstr *dirname2;
624 Eo *sentry;
625
626 Eina_Stringshare *filename;
627
628 eina_file_mkdtemp("checkFileCreationXXXXXX", &dirname2);
629 filename = eina_stringshare_printf("%s/eio_test_sentry_two_monitors_one_removed", dirname);
630 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
631
632 //sleep to avoid catching event generated by above manipulations
633 usleep(500000);
634
635 //monitor directory
636 fail_if(!eio_sentry_add(sentry, dirname));
637 fail_if(!eio_sentry_add(sentry, dirname2));
638 eio_sentry_del(sentry, dirname);
639 eo_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_CREATED, (Eo_Event_Cb)_unexpected_event_cb, filename);
640
641 ecore_timer_add(TEST_OPERATION_DELAY, _create_file, filename);
642 ecore_timer_add(TEST_TIMEOUT_SEC - 1, _test_timeout_expected, NULL);
643
644 ecore_main_loop_begin();
645
646 eo_unref(sentry);
647
648 _delete_directory((void*)dirname2);
649 _common_shutdown(dirname);
650}
651END_TEST
652
653START_TEST(eio_test_sentry_two_files_in_same_directory)
654{
655 Eina_Tmpstr *dirname = _common_init();
656 Eina_Stringshare *filename;
657 Eina_Stringshare *filename2;
658 Eo *sentry;
659
660 filename = eina_stringshare_printf("%s/eio_test_sentry_two_files_in_same_directory_1", dirname);
661 filename2 = eina_stringshare_printf("%s/eio_test_sentry_two_files_in_same_directory_2", dirname);
662 _create_file((void*)filename);
663 _create_file((void*)filename2);
664 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
665
666 //sleep to avoid catching event generated by above manipulations
667 usleep(500000);
668
669 //monitor file
670 fail_if(!eio_sentry_add(sentry,filename));
671 fail_if(!eio_sentry_add(sentry,filename2));
672 eo_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_MODIFIED, (Eo_Event_Cb)_target_notified_cb, filename);
673
674 ecore_timer_add(TEST_OPERATION_DELAY, _modify_file, filename);
675
676 ecore_main_loop_begin();
677
678 eo_unref(sentry);
679
680 //cleanup
681 _common_shutdown(dirname);
682}
683END_TEST
684
685
686START_TEST(eio_test_sentry_two_files_in_same_directory_one_removed)
687{
688 Eina_Tmpstr *dirname = _common_init();
689 Eina_Stringshare *filename;
690 Eina_Stringshare *filename2;
691 Eo *sentry;
692
693 filename = eina_stringshare_printf("%s/eio_test_sentry_two_files_in_same_directory_one_removed_1", dirname);
694 filename2 = eina_stringshare_printf("%s/eio_test_sentry_two_files_in_same_directory_one_removed_2", dirname);
695 _create_file((void*)filename);
696 _create_file((void*)filename2);
697 sentry = eo_add(EIO_SENTRY_CLASS, NULL);
698
699 //sleep to avoid catching event generated by above manipulations
700 usleep(500000);
701
702 //monitor file
703 fail_if(!eio_sentry_add(sentry,filename));
704 fail_if(!eio_sentry_add(sentry,filename2));
705 eio_sentry_del(sentry, filename);
706
707 eo_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_MODIFIED, (Eo_Event_Cb)_unexpected_event_cb, filename);
708
709 ecore_timer_add(TEST_OPERATION_DELAY, _modify_file, filename);
710 ecore_timer_add(TEST_TIMEOUT_SEC - 1, _test_timeout_expected, NULL);
711
712 ecore_main_loop_begin();
713
714 eo_unref(sentry);
715
716 //cleanup
717 _common_shutdown(dirname);
718}
719END_TEST
720
721
722void eio_test_sentry(TCase *tc)
723{
724 tcase_add_test(tc, eio_test_sentry_add_and_remove);
725 tcase_add_test(tc, eio_test_sentry_add_remove_add);
726 tcase_add_test(tc, eio_test_sentry_add_add_remove_remove);
727
728 tcase_add_test(tc, eio_test_sentry_directory_file_created_notify);
729 tcase_add_test(tc, eio_test_sentry_directory_file_deleted_notify);
730 tcase_add_test(tc, eio_test_sentry_directory_file_modified_notify);
731#if !defined(_WIN32) && !defined(__MACH__)
732 tcase_add_test(tc, eio_test_sentry_directory_file_closed_notify);
733#endif
734 tcase_add_test(tc, eio_test_sentry_directory_directory_created_notify);
735 tcase_add_test(tc, eio_test_sentry_directory_directory_deleted_notify);
736 tcase_add_test(tc, eio_test_sentry_directory_directory_modified_notify);
737#ifndef __MACH__
738 tcase_add_test(tc, eio_test_sentry_directory_directory_self_deleted_notify);
739#endif
740
741 tcase_add_test(tc, eio_test_sentry_file_file_modified_notify);
742 tcase_add_test(tc, eio_test_sentry_file_file_attrib_modified_notify);
743#if !defined(_WIN32) && !defined(__MACH__)
744 tcase_add_test(tc, eio_test_sentry_file_file_closed_notify);
745#endif
746#ifndef __MACH__
747 tcase_add_test(tc, eio_test_sentry_file_file_self_deleted_notify);
748#endif
749
750 tcase_add_test(tc, eio_test_sentry_two_monitors_one_event);
751 tcase_add_test(tc, eio_test_sentry_two_monitors_one_removed_one_event);
752 tcase_add_test(tc, eio_test_sentry_two_monitors_one_removed_no_event);
753 tcase_add_test(tc, eio_test_sentry_two_files_in_same_directory);
754 tcase_add_test(tc, eio_test_sentry_two_files_in_same_directory_one_removed);
755}
diff --git a/src/tests/eio/eio_test_xattr.c b/src/tests/eio/eio_test_xattr.c
index 1a50c125e5..b4a843ea10 100644
--- a/src/tests/eio/eio_test_xattr.c
+++ b/src/tests/eio/eio_test_xattr.c
@@ -12,6 +12,7 @@
12#include <Eio.h> 12#include <Eio.h>
13 13
14#include "eio_suite.h" 14#include "eio_suite.h"
15#include "eio_test_common.h"
15 16
16 17
17#ifdef XATTR_TEST_DIR 18#ifdef XATTR_TEST_DIR
@@ -23,27 +24,19 @@ static int int_data = 1234;
23static char *double_attr = "user.size"; 24static char *double_attr = "user.size";
24static double double_data = 123.456; 25static double double_data = 123.456;
25 26
26const char *attribute[] = 27static const char *attribute[] =
27 { 28 {
28 "user.comment1", 29 "user.comment1",
29 "user.comment2", 30 "user.comment2",
30 "user.comment3" 31 "user.comment3"
31 }; 32 };
32const char *attr_data[] = 33static const char *attr_data[] =
33 { 34 {
34 "This is a test file", 35 "This is a test file",
35 "This line is a comment", 36 "This line is a comment",
36 "This file has extra attributes" 37 "This file has extra attributes"
37 }; 38 };
38 39
39Eina_Tmpstr*
40get_file_path(const char* tmpdirname, const char* filename)
41{
42 char file_path[PATH_MAX] = "";
43 eina_str_join(file_path, sizeof(file_path), '/', tmpdirname, filename);
44 return eina_tmpstr_add(file_path);
45}
46
47static Eina_Bool 40static Eina_Bool
48_filter_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, const char *attr EINA_UNUSED) 41_filter_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, const char *attr EINA_UNUSED)
49{ 42{
@@ -149,7 +142,7 @@ START_TEST(eio_test_xattr_set)
149 eina_init(); 142 eina_init();
150 eio_init(); 143 eio_init();
151 144
152 test_file_path = get_file_path(XATTR_TEST_DIR, filename); 145 test_file_path = get_full_path(XATTR_TEST_DIR, filename);
153 fd = open(test_file_path, 146 fd = open(test_file_path,
154 O_WRONLY | O_CREAT | O_TRUNC, 147 O_WRONLY | O_CREAT | O_TRUNC,
155 S_IRWXU | S_IRWXG | S_IRWXO); 148 S_IRWXU | S_IRWXG | S_IRWXO);
@@ -207,7 +200,7 @@ START_TEST(eio_test_xattr_types_set)
207 eina_init(); 200 eina_init();
208 eio_init(); 201 eio_init();
209 202
210 test_file_path = get_file_path(XATTR_TEST_DIR, filename); 203 test_file_path = get_full_path(XATTR_TEST_DIR, filename);
211 fd = open(test_file_path, 204 fd = open(test_file_path,
212 O_WRONLY | O_CREAT | O_TRUNC, 205 O_WRONLY | O_CREAT | O_TRUNC,
213 S_IRWXU | S_IRWXG | S_IRWXO); 206 S_IRWXU | S_IRWXG | S_IRWXO);