summaryrefslogtreecommitdiff
path: root/src/tests/eio
diff options
context:
space:
mode:
authorpierre lamot <pierre.lamot@openwide.fr>2015-02-26 14:37:45 +0100
committerCedric BAIL <cedric@osg.samsung.com>2015-03-12 07:43:59 +0100
commitd958afd9fd7078a6eaee17df0a0b1e71504fc3b1 (patch)
treef514b4f3cb5d7cec654371fc6f029800695e4648 /src/tests/eio
parentae4389a7bd8a6807c3df041cde7c1357b0c13a0c (diff)
eio: add OSX implementation of eio_monitor based on FSEvent
this patch adds an implementation of eio_monitor based on FSEvent for OSX. This implentation has some limitations compared to inotify implementation. Folowing events are not detected: - EIO_MONITOR_FILE_CLOSED - EIO_MONITOR_SELF_RENAME - EIO_MONITOR_SELF_DELETED It should be noted that some events that happend before the call to eio_monitor_add can be catched. This is why sleep timers have been added in the test suite. Tests have been added to check uncovered scenarios. some things might still be improved: - self_deleted events for files might be handled by checking the file_name manually - self_deleted events for directories might be handled by setting kFSEventStreamCreateFlagWatchRoot. I've noticed by doing so that a lot more unwanted event are raised Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/tests/eio')
-rw-r--r--src/tests/eio/eio_test_monitor.c404
1 files changed, 316 insertions, 88 deletions
diff --git a/src/tests/eio/eio_test_monitor.c b/src/tests/eio/eio_test_monitor.c
index c1f10a45b1..378c427a3c 100644
--- a/src/tests/eio/eio_test_monitor.c
+++ b/src/tests/eio/eio_test_monitor.c
@@ -17,9 +17,9 @@
17#define TEST_TIMEOUT_SEC 10 17#define TEST_TIMEOUT_SEC 10
18#define TEST_OPERATION_DELAY 0.5 18#define TEST_OPERATION_DELAY 0.5
19 19
20static Ecore_Timer * test_timeout_timer; 20static Ecore_Timer *test_timeout_timer;
21 21
22static Eina_Bool _test_timeout_cb(void* data EINA_UNUSED) 22static Eina_Bool _test_timeout_cb(void *data EINA_UNUSED)
23{ 23{
24 ck_abort_msg("test timeout"); 24 ck_abort_msg("test timeout");
25 ecore_main_loop_quit(); 25 ecore_main_loop_quit();
@@ -35,16 +35,26 @@ static void _cancel_timeout()
35 } 35 }
36} 36}
37 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
38///////////////// file and directory operations 48///////////////// file and directory operations
39 49
40typedef struct { 50typedef struct {
41 const char* src; 51 const char *src;
42 const char* dst; 52 const char *dst;
43} RenameOperation; 53} RenameOperation;
44 54
45static Eina_Bool _delete_directory(void* data) 55static Eina_Bool _delete_directory(void *data)
46{ 56{
47 const char* dirname = (const char*)data; 57 const char *dirname = (const char*)data;
48 if (ecore_file_is_dir(dirname)) 58 if (ecore_file_is_dir(dirname))
49 { 59 {
50 ecore_file_recursive_rm(dirname); 60 ecore_file_recursive_rm(dirname);
@@ -52,40 +62,40 @@ static Eina_Bool _delete_directory(void* data)
52 return ECORE_CALLBACK_CANCEL; 62 return ECORE_CALLBACK_CANCEL;
53} 63}
54 64
55static Eina_Bool _create_directory(void* data) 65static Eina_Bool _create_directory(void *data)
56{ 66{
57 const char* dirname = (const char*)data; 67 const char *dirname = (const char*)data;
58 ecore_file_mkpath(dirname); 68 ecore_file_mkpath(dirname);
59 return ECORE_CALLBACK_CANCEL; 69 return ECORE_CALLBACK_CANCEL;
60} 70}
61 71
62 72
63static Eina_Bool _create_file(void* data) 73static Eina_Bool _create_file(void *data)
64{ 74{
65 FILE* fd = fopen((const char*)data, "w+"); 75 FILE *fd = fopen((const char*)data, "w+");
66 ck_assert_ptr_ne(fd, NULL); 76 ck_assert_ptr_ne(fd, NULL);
67 fprintf(fd, "test test"); 77 fprintf(fd, "test test");
68 fclose(fd); 78 fclose(fd);
69 return ECORE_CALLBACK_CANCEL; 79 return ECORE_CALLBACK_CANCEL;
70} 80}
71 81
72static Eina_Bool _delete_file(void* data) 82static Eina_Bool _delete_file(void *data)
73{ 83{
74 Eina_Bool file_removed = ecore_file_remove((const char*)data); 84 Eina_Bool file_removed = ecore_file_remove((const char*)data);
75 ck_assert(file_removed); 85 ck_assert(file_removed);
76 return ECORE_CALLBACK_CANCEL; 86 return ECORE_CALLBACK_CANCEL;
77} 87}
78 88
79static Eina_Bool _modify_file(void* data) 89static Eina_Bool _modify_file(void *data)
80{ 90{
81 FILE* fd = fopen((const char*)data, "a"); 91 FILE *fd = fopen((const char*)data, "a");
82 ck_assert_ptr_ne(fd, NULL); 92 ck_assert_ptr_ne(fd, NULL);
83 fprintf(fd, "appened"); 93 fprintf(fd, "appened");
84 fclose(fd); 94 fclose(fd);
85 return ECORE_CALLBACK_CANCEL; 95 return ECORE_CALLBACK_CANCEL;
86} 96}
87 97
88static Eina_Bool _modify_attrib_file(void* data) 98static Eina_Bool _modify_attrib_file(void *data)
89{ 99{
90 int ret = chmod((const char*)data, 0666); 100 int ret = chmod((const char*)data, 0666);
91 ck_assert_int_eq(ret, 0); 101 ck_assert_int_eq(ret, 0);
@@ -94,16 +104,17 @@ static Eina_Bool _modify_attrib_file(void* data)
94 104
95/////// helper functions 105/////// helper functions
96 106
97static void _check_event_path(void* data, void* event) 107static Eina_Bool _check_event_path(void *data, void *event)
98{ 108{
99 const char* expected_path = ecore_file_realpath((const char*)data); 109 const char *expected_path = (const char*)data;
100 const char* actual_path = ecore_file_realpath(((Eio_Monitor_Event*)event)->filename); 110 const char *actual_path = ((Eio_Monitor_Event*)event)->filename;
101 ck_assert_str_eq(actual_path, expected_path); 111 ck_assert_str_eq((const char*)data, ((Eio_Monitor_Event*)event)->filename);
112 return EINA_TRUE;
102} 113}
103 114
104static Eina_Tmpstr* _common_init() 115static Eina_Tmpstr *_common_init()
105{ 116{
106 Eina_Tmpstr* dirname; 117 Eina_Tmpstr *dirname;
107 fail_if(eio_init() != 1); 118 fail_if(eio_init() != 1);
108 ecore_file_init(); 119 ecore_file_init();
109 120
@@ -114,7 +125,7 @@ static Eina_Tmpstr* _common_init()
114 return dirname; 125 return dirname;
115} 126}
116 127
117static void _common_shutdown(Eina_Tmpstr* dirname) 128static void _common_shutdown(Eina_Tmpstr *dirname)
118{ 129{
119 _delete_directory((void*)dirname); 130 _delete_directory((void*)dirname);
120 ecore_file_shutdown(); 131 ecore_file_shutdown();
@@ -124,21 +135,26 @@ static void _common_shutdown(Eina_Tmpstr* dirname)
124 135
125/////// tests monitoring a directory 136/////// tests monitoring a directory
126 137
127static void _file_created_cb(void* data, int type, void* event) 138static void _file_created_cb(void *data, int type, void *event)
128{ 139{
129 ck_assert_int_eq(type, (int)EIO_MONITOR_FILE_CREATED); 140 ck_assert_int_eq(type, (int)EIO_MONITOR_FILE_CREATED);
130 _check_event_path(data, event); 141 if (_check_event_path(data, event))
131 _cancel_timeout(); 142 {
132 ecore_main_loop_quit(); 143 _cancel_timeout();
144 ecore_main_loop_quit();
145 }
133} 146}
134 147
135 148
136START_TEST(eio_test_monitor_directory_file_created_notify) 149START_TEST(eio_test_monitor_directory_file_created_notify)
137{ 150{
138 Eina_Tmpstr* dirname = _common_init(); 151 Eina_Tmpstr *dirname = _common_init();
139 Eina_Stringshare* filename; 152 Eina_Stringshare *filename;
140 153
141 filename = eina_stringshare_printf("%s/filecreated", dirname); 154 filename = eina_stringshare_printf("%s/eio_test_monitor_directory_file_created_notify", dirname);
155
156 //sleep to avoid catching event generated by above manipulations
157 usleep(500000);
142 158
143 //monitor directory 159 //monitor directory
144 eio_monitor_add(dirname); 160 eio_monitor_add(dirname);
@@ -152,22 +168,27 @@ START_TEST(eio_test_monitor_directory_file_created_notify)
152} 168}
153END_TEST 169END_TEST
154 170
155static void _file_deleted_cb(void* data, int type, void* event) 171static void _file_deleted_cb(void *data, int type, void *event)
156{ 172{
157 ck_assert_int_eq(type, (int)EIO_MONITOR_FILE_DELETED); 173 ck_assert_int_eq(type, (int)EIO_MONITOR_FILE_DELETED);
158 _check_event_path(data, event); 174 if (_check_event_path(data, event))
159 _cancel_timeout(); 175 {
160 ecore_main_loop_quit(); 176 _cancel_timeout();
177 ecore_main_loop_quit();
178 }
161} 179}
162 180
163START_TEST(eio_test_monitor_directory_file_deleted_notify) 181START_TEST(eio_test_monitor_directory_file_deleted_notify)
164{ 182{
165 Eina_Tmpstr* dirname = _common_init(); 183 Eina_Tmpstr *dirname = _common_init();
166 Eina_Stringshare* filename; 184 Eina_Stringshare *filename;
167 185
168 filename = eina_stringshare_printf("%s/filecreated", dirname); 186 filename = eina_stringshare_printf("%s/eio_test_monitor_directory_file_deleted_notify", dirname);
169 _create_file((void*)filename); 187 _create_file((void*)filename);
170 188
189 //sleep to avoid catching event generated by above manipulations
190 usleep(500000);
191
171 //monitor directory 192 //monitor directory
172 eio_monitor_add(dirname); 193 eio_monitor_add(dirname);
173 ecore_event_handler_add(EIO_MONITOR_FILE_DELETED, (Ecore_Event_Handler_Cb)_file_deleted_cb, filename); 194 ecore_event_handler_add(EIO_MONITOR_FILE_DELETED, (Ecore_Event_Handler_Cb)_file_deleted_cb, filename);
@@ -180,22 +201,27 @@ START_TEST(eio_test_monitor_directory_file_deleted_notify)
180} 201}
181END_TEST 202END_TEST
182 203
183static void _file_modified_cb(void* data, int type, void* event) 204static void _file_modified_cb(void *data, int type, void *event)
184{ 205{
185 ck_assert_int_eq(type, (int)EIO_MONITOR_FILE_MODIFIED); 206 ck_assert_int_eq(type, (int)EIO_MONITOR_FILE_MODIFIED);
186 _check_event_path(data, event); 207 if(_check_event_path(data, event))
187 _cancel_timeout(); 208 {
188 ecore_main_loop_quit(); 209 _cancel_timeout();
210 ecore_main_loop_quit();
211 }
189} 212}
190 213
191START_TEST(eio_test_monitor_directory_file_modified_notify) 214START_TEST(eio_test_monitor_directory_file_modified_notify)
192{ 215{
193 Eina_Tmpstr* dirname = _common_init(); 216 Eina_Tmpstr *dirname = _common_init();
194 Eina_Stringshare* filename; 217 Eina_Stringshare *filename;
195 218
196 filename = eina_stringshare_printf("%s/filecreated", dirname); 219 filename = eina_stringshare_printf("%s/eio_test_monitor_directory_file_modified_notify", dirname);
197 _create_file((void*)filename); 220 _create_file((void*)filename);
198 221
222 //sleep to avoid catching event generated by above manipulations
223 usleep(500000);
224
199 //monitor directory 225 //monitor directory
200 eio_monitor_add(dirname); 226 eio_monitor_add(dirname);
201 ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, (Ecore_Event_Handler_Cb)_file_modified_cb, filename); 227 ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, (Ecore_Event_Handler_Cb)_file_modified_cb, filename);
@@ -209,22 +235,27 @@ START_TEST(eio_test_monitor_directory_file_modified_notify)
209} 235}
210END_TEST 236END_TEST
211 237
212static void _file_closed_cb(void* data, int type, void* event) 238static void _file_closed_cb(void *data, int type, void *event)
213{ 239{
214 ck_assert_int_eq(type, (int)EIO_MONITOR_FILE_CLOSED); 240 ck_assert_int_eq(type, (int)EIO_MONITOR_FILE_CLOSED);
215 _check_event_path(data, event); 241 if (_check_event_path(data, event))
216 _cancel_timeout(); 242 {
217 ecore_main_loop_quit(); 243 _cancel_timeout();
244 ecore_main_loop_quit();
245 }
218} 246}
219 247
220START_TEST(eio_test_monitor_directory_file_closed_notify) 248START_TEST(eio_test_monitor_directory_file_closed_notify)
221{ 249{
222 Eina_Tmpstr* dirname = _common_init(); 250 Eina_Tmpstr *dirname = _common_init();
223 Eina_Stringshare* filename; 251 Eina_Stringshare *filename;
224 252
225 filename = eina_stringshare_printf("%s/filecreated", dirname); 253 filename = eina_stringshare_printf("%s/eio_test_monitor_directory_file_closed_notify", dirname);
226 _create_file((void*)filename); 254 _create_file((void*)filename);
227 255
256 //sleep to avoid catching event generated by above manipulations
257 usleep(500000);
258
228 //monitor directory 259 //monitor directory
229 eio_monitor_add(dirname); 260 eio_monitor_add(dirname);
230 ecore_event_handler_add(EIO_MONITOR_FILE_CLOSED, (Ecore_Event_Handler_Cb)_file_closed_cb, filename); 261 ecore_event_handler_add(EIO_MONITOR_FILE_CLOSED, (Ecore_Event_Handler_Cb)_file_closed_cb, filename);
@@ -236,20 +267,25 @@ START_TEST(eio_test_monitor_directory_file_closed_notify)
236} 267}
237END_TEST 268END_TEST
238 269
239static void _directory_created_cb(void* data, int type, void* event) 270static void _directory_created_cb(void *data, int type, void *event)
240{ 271{
241 ck_assert_int_eq(type, (int)EIO_MONITOR_DIRECTORY_CREATED); 272 ck_assert_int_eq(type, (int)EIO_MONITOR_DIRECTORY_CREATED);
242 _check_event_path(data, event); 273 if (_check_event_path(data, event))
243 _cancel_timeout(); 274 {
244 ecore_main_loop_quit(); 275 _cancel_timeout();
276 ecore_main_loop_quit();
277 }
245} 278}
246 279
247START_TEST(eio_test_monitor_directory_directory_created_notify) 280START_TEST(eio_test_monitor_directory_directory_created_notify)
248{ 281{
249 Eina_Tmpstr* dirname = _common_init(); 282 Eina_Tmpstr *dirname = _common_init();
250 Eina_Stringshare* filename; 283 Eina_Stringshare *filename;
251 284
252 filename = eina_stringshare_printf("%s/dircreated", dirname); 285 filename = eina_stringshare_printf("%s/eio_test_monitor_directory_directory_created_notify", dirname);
286
287 //sleep to avoid catching event generated by above manipulations
288 usleep(500000);
253 289
254 //monitor directory 290 //monitor directory
255 eio_monitor_add(dirname); 291 eio_monitor_add(dirname);
@@ -263,22 +299,27 @@ START_TEST(eio_test_monitor_directory_directory_created_notify)
263} 299}
264END_TEST 300END_TEST
265 301
266static void _directory_deleted_cb(void* data, int type, void* event) 302static void _directory_deleted_cb(void *data, int type, void *event)
267{ 303{
268 ck_assert_int_eq(type, (int)EIO_MONITOR_DIRECTORY_DELETED); 304 ck_assert_int_eq(type, (int)EIO_MONITOR_DIRECTORY_DELETED);
269 _check_event_path(data, event); 305 if (_check_event_path(data, event))
270 _cancel_timeout(); 306 {
271 ecore_main_loop_quit(); 307 _cancel_timeout();
308 ecore_main_loop_quit();
309 }
272} 310}
273 311
274START_TEST(eio_test_monitor_directory_directory_deleted_notify) 312START_TEST(eio_test_monitor_directory_directory_deleted_notify)
275{ 313{
276 Eina_Tmpstr* dirname = _common_init(); 314 Eina_Tmpstr *dirname = _common_init();
277 Eina_Stringshare* filename; 315 Eina_Stringshare *filename;
278 316
279 filename = eina_stringshare_printf("%s/dircreated", dirname); 317 filename = eina_stringshare_printf("%s/eio_test_monitor_directory_directory_deleted_notify", dirname);
280 _create_directory((void*)filename); 318 _create_directory((void*)filename);
281 319
320 //sleep to avoid catching event generated by above manipulations
321 usleep(500000);
322
282 //monitor directory 323 //monitor directory
283 eio_monitor_add(dirname); 324 eio_monitor_add(dirname);
284 ecore_event_handler_add(EIO_MONITOR_DIRECTORY_DELETED, (Ecore_Event_Handler_Cb)_directory_deleted_cb, filename); 325 ecore_event_handler_add(EIO_MONITOR_DIRECTORY_DELETED, (Ecore_Event_Handler_Cb)_directory_deleted_cb, filename);
@@ -291,23 +332,28 @@ START_TEST(eio_test_monitor_directory_directory_deleted_notify)
291} 332}
292END_TEST 333END_TEST
293 334
294static void _directory_modified_cb(void* data, int type, void* event) 335static void _directory_modified_cb(void *data, int type, void *event)
295{ 336{
296 ck_assert_int_eq(type, (int)EIO_MONITOR_DIRECTORY_MODIFIED); 337 ck_assert_int_eq(type, (int)EIO_MONITOR_DIRECTORY_MODIFIED);
297 _check_event_path(data, event); 338 if (_check_event_path(data, event))
298 _cancel_timeout(); 339 {
299 ecore_main_loop_quit(); 340 _cancel_timeout();
341 ecore_main_loop_quit();
342 }
300} 343}
301 344
302 345
303START_TEST(eio_test_monitor_directory_directory_modified_notify) 346START_TEST(eio_test_monitor_directory_directory_modified_notify)
304{ 347{
305 Eina_Tmpstr* dirname = _common_init(); 348 Eina_Tmpstr *dirname = _common_init();
306 Eina_Stringshare* filename; 349 Eina_Stringshare *filename;
307 350
308 filename = eina_stringshare_printf("%s/filecreated", dirname); 351 filename = eina_stringshare_printf("%s/eio_test_monitor_directory_directory_modified_notify", dirname);
309 _create_directory((void*)filename); 352 _create_directory((void*)filename);
310 353
354 //sleep to avoid catching event generated by above manipulations
355 usleep(500000);
356
311 //monitor directory 357 //monitor directory
312 eio_monitor_add(dirname); 358 eio_monitor_add(dirname);
313 ecore_event_handler_add(EIO_MONITOR_DIRECTORY_MODIFIED, (Ecore_Event_Handler_Cb)_directory_modified_cb, filename); 359 ecore_event_handler_add(EIO_MONITOR_DIRECTORY_MODIFIED, (Ecore_Event_Handler_Cb)_directory_modified_cb, filename);
@@ -321,18 +367,23 @@ START_TEST(eio_test_monitor_directory_directory_modified_notify)
321END_TEST 367END_TEST
322 368
323 369
324static void _directory_self_deleted_cb(void* data, int type, void* event) 370static void _directory_self_deleted_cb(void *data, int type, void *event)
325{ 371{
326 ck_assert_int_eq(type, (int)EIO_MONITOR_SELF_DELETED); 372 ck_assert_int_eq(type, (int)EIO_MONITOR_SELF_DELETED);
327 _check_event_path(data, event); 373 if (_check_event_path(data, event))
328 _cancel_timeout(); 374 {
329 ecore_main_loop_quit(); 375 _cancel_timeout();
376 ecore_main_loop_quit();
377 }
330} 378}
331 379
332 380
333START_TEST(eio_test_monitor_directory_directory_self_deleted_notify) 381START_TEST(eio_test_monitor_directory_directory_self_deleted_notify)
334{ 382{
335 Eina_Tmpstr* dirname = _common_init(); 383 Eina_Tmpstr *dirname = _common_init();
384
385 //sleep to avoid catching event generated by above manipulations
386 usleep(500000);
336 387
337 //monitor directory 388 //monitor directory
338 eio_monitor_add(dirname); 389 eio_monitor_add(dirname);
@@ -350,12 +401,15 @@ END_TEST
350 401
351START_TEST(eio_test_monitor_file_file_modified_notify) 402START_TEST(eio_test_monitor_file_file_modified_notify)
352{ 403{
353 Eina_Tmpstr* dirname = _common_init(); 404 Eina_Tmpstr *dirname = _common_init();
354 Eina_Stringshare* filename; 405 Eina_Stringshare *filename;
355 406
356 filename = eina_stringshare_printf("%s/filecreated", dirname); 407 filename = eina_stringshare_printf("%s/filecreated", dirname);
357 _create_file((void*)filename); 408 _create_file((void*)filename);
358 409
410 //sleep to avoid catching event generated by above manipulations
411 usleep(500000);
412
359 //monitor file 413 //monitor file
360 eio_monitor_add(filename); 414 eio_monitor_add(filename);
361 ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, (Ecore_Event_Handler_Cb)_file_modified_cb, filename); 415 ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, (Ecore_Event_Handler_Cb)_file_modified_cb, filename);
@@ -371,12 +425,15 @@ END_TEST
371 425
372START_TEST(eio_test_monitor_file_file_attrib_modified_notify) 426START_TEST(eio_test_monitor_file_file_attrib_modified_notify)
373{ 427{
374 Eina_Tmpstr* dirname = _common_init(); 428 Eina_Tmpstr *dirname = _common_init();
375 Eina_Stringshare* filename; 429 Eina_Stringshare *filename;
376 430
377 filename = eina_stringshare_printf("%s/filecreated", dirname); 431 filename = eina_stringshare_printf("%s/eio_test_monitor_file_file_attrib_modified_notify", dirname);
378 _create_file((void*)filename); 432 _create_file((void*)filename);
379 433
434 //sleep to avoid catching event generated by above manipulations
435 usleep(500000);
436
380 //monitor file 437 //monitor file
381 eio_monitor_add(filename); 438 eio_monitor_add(filename);
382 ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, (Ecore_Event_Handler_Cb)_file_modified_cb, filename); 439 ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, (Ecore_Event_Handler_Cb)_file_modified_cb, filename);
@@ -392,12 +449,15 @@ END_TEST
392 449
393START_TEST(eio_test_monitor_file_file_closed_notify) 450START_TEST(eio_test_monitor_file_file_closed_notify)
394{ 451{
395 Eina_Tmpstr* dirname = _common_init(); 452 Eina_Tmpstr *dirname = _common_init();
396 Eina_Stringshare* filename; 453 Eina_Stringshare *filename;
397 454
398 filename = eina_stringshare_printf("%s/filecreated", dirname); 455 filename = eina_stringshare_printf("%s/eio_test_monitor_file_file_closed_notify", dirname);
399 _create_file((void*)filename); 456 _create_file((void*)filename);
400 457
458 //sleep to avoid catching event generated by above manipulations
459 usleep(500000);
460
401 //monitor file 461 //monitor file
402 eio_monitor_add(dirname); 462 eio_monitor_add(dirname);
403 ecore_event_handler_add(EIO_MONITOR_FILE_CLOSED, (Ecore_Event_Handler_Cb)_file_closed_cb, filename); 463 ecore_event_handler_add(EIO_MONITOR_FILE_CLOSED, (Ecore_Event_Handler_Cb)_file_closed_cb, filename);
@@ -411,12 +471,15 @@ END_TEST
411 471
412START_TEST(eio_test_monitor_file_file_self_deleted_notify) 472START_TEST(eio_test_monitor_file_file_self_deleted_notify)
413{ 473{
414 Eina_Tmpstr* dirname = _common_init(); 474 Eina_Tmpstr *dirname = _common_init();
415 Eina_Stringshare* filename; 475 Eina_Stringshare *filename;
416 476
417 filename = eina_stringshare_printf("%s/filecreated", dirname); 477 filename = eina_stringshare_printf("%s/eio_test_monitor_file_file_self_deleted_notify", dirname);
418 _create_file((void*)filename); 478 _create_file((void*)filename);
419 479
480 //sleep to avoid catching event generated by above manipulations
481 usleep(500000);
482
420 //monitor file 483 //monitor file
421 eio_monitor_add(filename); 484 eio_monitor_add(filename);
422 ecore_event_handler_add(EIO_MONITOR_SELF_DELETED, (Ecore_Event_Handler_Cb)_directory_self_deleted_cb, filename); 485 ecore_event_handler_add(EIO_MONITOR_SELF_DELETED, (Ecore_Event_Handler_Cb)_directory_self_deleted_cb, filename);
@@ -429,24 +492,189 @@ START_TEST(eio_test_monitor_file_file_self_deleted_notify)
429} 492}
430END_TEST 493END_TEST
431 494
495START_TEST(eio_test_monitor_two_monitors_one_event)
496{
497 Eina_Tmpstr *dirname = _common_init();
498 Eina_Tmpstr *dirname2;
499
500 Eina_Stringshare *filename;
501
502 eina_file_mkdtemp("checkFileCreationXXXXXX", &dirname2);
503 filename = eina_stringshare_printf("%s/eio_test_monitor_two_monitors_one_event", dirname);
504
505 //sleep to avoid catching event generated by above manipulations
506 usleep(500000);
507
508 //monitor directory
509 eio_monitor_add(dirname);
510 eio_monitor_add(dirname2);
511 ecore_event_handler_add(EIO_MONITOR_FILE_CREATED, (Ecore_Event_Handler_Cb)_file_created_cb, filename);
512
513 ecore_timer_add(TEST_OPERATION_DELAY, _create_file, filename);
514
515 ecore_main_loop_begin();
516
517 _delete_directory((void*)dirname2);
518 _common_shutdown(dirname);
519}
520END_TEST
521
522
523START_TEST(eio_test_monitor_two_monitors_one_removed_one_event)
524{
525 Eina_Tmpstr *dirname = _common_init();
526 Eina_Tmpstr *dirname2;
527
528 Eina_Stringshare *filename;
529
530 Eio_Monitor *monitor;
531
532 eina_file_mkdtemp("checkFileCreationXXXXXX", &dirname2);
533 filename = eina_stringshare_printf("%s/eio_test_monitor_two_monitors_one_removed", dirname);
534
535 //sleep to avoid catching event generated by above manipulations
536 usleep(500000);
537
538 //monitor directory
539 monitor = eio_monitor_add(dirname2);
540 eio_monitor_add(dirname);
541 eio_monitor_del(monitor);
542 ecore_event_handler_add(EIO_MONITOR_FILE_CREATED, (Ecore_Event_Handler_Cb)_file_created_cb, filename);
543
544 ecore_timer_add(TEST_OPERATION_DELAY, _create_file, filename);
545
546 ecore_main_loop_begin();
547
548 _delete_directory((void*)dirname2);
549 _common_shutdown(dirname);
550}
551END_TEST
552
553static void _unexpected_event_cb(void *data, int type, void *event)
554{
555 ck_abort_msg("unexpected event");
556}
557
558START_TEST(eio_test_monitor_two_monitors_one_removed_no_event)
559{
560 Eina_Tmpstr *dirname = _common_init();
561 Eina_Tmpstr *dirname2;
562
563 Eina_Stringshare *filename;
564
565 Eio_Monitor *monitor;
566
567 eina_file_mkdtemp("checkFileCreationXXXXXX", &dirname2);
568 filename = eina_stringshare_printf("%s/eio_test_monitor_two_monitors_one_removed", dirname);
569
570 //sleep to avoid catching event generated by above manipulations
571 usleep(500000);
572
573 //monitor directory
574 monitor = eio_monitor_add(dirname);
575 eio_monitor_add(dirname2);
576 eio_monitor_del(monitor);
577 ecore_event_handler_add(EIO_MONITOR_FILE_CREATED, (Ecore_Event_Handler_Cb)_unexpected_event_cb, filename);
578
579 ecore_timer_add(TEST_OPERATION_DELAY, _create_file, filename);
580 ecore_timer_add(TEST_TIMEOUT_SEC - 1, _test_timeout_expected, NULL);
581
582 ecore_main_loop_begin();
583
584 _delete_directory((void*)dirname2);
585 _common_shutdown(dirname);
586}
587END_TEST
588
589START_TEST(eio_test_monitor_two_files_in_same_directory)
590{
591 Eina_Tmpstr *dirname = _common_init();
592 Eina_Stringshare *filename;
593 Eina_Stringshare *filename2;
594
595 filename = eina_stringshare_printf("%s/eio_test_monitor_two_files_in_same_directory_1", dirname);
596 filename2 = eina_stringshare_printf("%s/eio_test_monitor_two_files_in_same_directory_2", dirname);
597 _create_file((void*)filename);
598 _create_file((void*)filename2);
599
600 //sleep to avoid catching event generated by above manipulations
601 usleep(500000);
602
603 //monitor file
604 eio_monitor_add(filename);
605 eio_monitor_add(filename2);
606 ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, (Ecore_Event_Handler_Cb)_file_modified_cb, filename);
607
608 ecore_timer_add(TEST_OPERATION_DELAY, _modify_file, filename);
609
610 ecore_main_loop_begin();
611
612 //cleanup
613 _common_shutdown(dirname);
614}
615END_TEST
616
617
618START_TEST(eio_test_monitor_two_files_in_same_directory_one_removed)
619{
620 Eina_Tmpstr *dirname = _common_init();
621 Eina_Stringshare *filename;
622 Eina_Stringshare *filename2;
623 Eio_Monitor *monitor;
624
625 filename = eina_stringshare_printf("%s/eio_test_monitor_two_files_in_same_directory_one_removed_1", dirname);
626 filename2 = eina_stringshare_printf("%s/eio_test_monitor_two_files_in_same_directory_one_removed_2", dirname);
627 _create_file((void*)filename);
628 _create_file((void*)filename2);
629
630 //sleep to avoid catching event generated by above manipulations
631 usleep(500000);
632
633 //monitor file
634 monitor = eio_monitor_add(filename);
635 eio_monitor_add(filename2);
636 eio_monitor_del(monitor);
637
638 ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, (Ecore_Event_Handler_Cb)_unexpected_event_cb, filename);
639
640 ecore_timer_add(TEST_OPERATION_DELAY, _modify_file, filename);
641 ecore_timer_add(TEST_TIMEOUT_SEC - 1, _test_timeout_expected, NULL);
642
643 ecore_main_loop_begin();
644
645 //cleanup
646 _common_shutdown(dirname);
647}
648END_TEST
649
650
432void eio_test_monitor(TCase *tc) 651void eio_test_monitor(TCase *tc)
433{ 652{
434 tcase_add_test(tc, eio_test_monitor_directory_file_created_notify); 653 tcase_add_test(tc, eio_test_monitor_directory_file_created_notify);
435 tcase_add_test(tc, eio_test_monitor_directory_file_deleted_notify); 654 tcase_add_test(tc, eio_test_monitor_directory_file_deleted_notify);
436 tcase_add_test(tc, eio_test_monitor_directory_file_modified_notify); 655 tcase_add_test(tc, eio_test_monitor_directory_file_modified_notify);
437#ifndef _WIN32 656#if !defined(_WIN32) && !defined(__MACH__)
438 tcase_add_test(tc, eio_test_monitor_directory_file_closed_notify); 657 tcase_add_test(tc, eio_test_monitor_directory_file_closed_notify);
439#endif 658#endif
440 tcase_add_test(tc, eio_test_monitor_directory_directory_created_notify); 659 tcase_add_test(tc, eio_test_monitor_directory_directory_created_notify);
441 tcase_add_test(tc, eio_test_monitor_directory_directory_deleted_notify); 660 tcase_add_test(tc, eio_test_monitor_directory_directory_deleted_notify);
442 tcase_add_test(tc, eio_test_monitor_directory_directory_modified_notify); 661 tcase_add_test(tc, eio_test_monitor_directory_directory_modified_notify);
662#ifndef __MACH__
443 tcase_add_test(tc, eio_test_monitor_directory_directory_self_deleted_notify); 663 tcase_add_test(tc, eio_test_monitor_directory_directory_self_deleted_notify);
664#endif
444 665
445 tcase_add_test(tc, eio_test_monitor_file_file_modified_notify); 666 tcase_add_test(tc, eio_test_monitor_file_file_modified_notify);
446 tcase_add_test(tc, eio_test_monitor_file_file_attrib_modified_notify); 667 tcase_add_test(tc, eio_test_monitor_file_file_attrib_modified_notify);
447#ifndef _WIN32 668#if !defined(_WIN32) && !defined(__MACH__)
448 tcase_add_test(tc, eio_test_monitor_file_file_closed_notify); 669 tcase_add_test(tc, eio_test_monitor_file_file_closed_notify);
449#endif 670#endif
671#ifndef __MACH__
450 tcase_add_test(tc, eio_test_monitor_file_file_self_deleted_notify); 672 tcase_add_test(tc, eio_test_monitor_file_file_self_deleted_notify);
673#endif
451 674
675 tcase_add_test(tc, eio_test_monitor_two_monitors_one_event);
676 tcase_add_test(tc, eio_test_monitor_two_monitors_one_removed_one_event);
677 tcase_add_test(tc, eio_test_monitor_two_monitors_one_removed_no_event);
678 tcase_add_test(tc, eio_test_monitor_two_files_in_same_directory);
679 tcase_add_test(tc, eio_test_monitor_two_files_in_same_directory_one_removed);
452} 680}