summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac67
-rw-r--r--src/Makefile_Eio.am7
-rw-r--r--src/lib/eio/Eio.h8
-rw-r--r--src/lib/eio/eio_monitor_cocoa.c405
-rw-r--r--src/lib/eio/eio_monitor_poll.c2
-rw-r--r--src/tests/eio/eio_test_monitor.c404
6 files changed, 784 insertions, 109 deletions
diff --git a/configure.ac b/configure.ac
index 82da49dc8d..2996474d90 100644
--- a/configure.ac
+++ b/configure.ac
@@ -417,19 +417,8 @@ sys/mman.h \
417netinet/in.h \ 417netinet/in.h \
418]) 418])
419 419
420have_inotify="${ac_cv_header_sys_inotify_h}"
421AM_CONDITIONAL([HAVE_INOTIFY], [test "x${have_inotify}" = "xyes"])
422
423have_notify_win32="${have_win32}"
424AC_DEFINE_IF([HAVE_NOTIFY_WIN32],
425 [test "x${have_notify_win32}" = "xyes"], [1],
426 [File monitoring with Windows notification])
427AM_CONDITIONAL([HAVE_NOTIFY_WIN32], [test "x${have_notify_win32}" = "xyes"])
428
429
430EFL_CHECK_PATH_MAX 420EFL_CHECK_PATH_MAX
431 421
432
433#### Checks for types 422#### Checks for types
434 423
435# wchar_t 424# wchar_t
@@ -1329,11 +1318,11 @@ AC_ARG_ENABLE([cocoa],
1329 ], 1318 ],
1330 [want_cocoa="no"]) 1319 [want_cocoa="no"])
1331 1320
1332 if test "${want_cocoa}" = "yes"; then 1321if test "${want_cocoa}" = "yes"; then
1333 #test cocoa requirements (objc and Cocoa/Cocoa.h) 1322 #test cocoa requirements (objc and Cocoa/Cocoa.h)
1334 cocoa_ldflags="" 1323 cocoa_ldflags=""
1335 have_cocoa="no" 1324 have_cocoa="no"
1336 m4_ifdef([AC_PROG_OBJC], 1325 m4_ifdef([AC_PROG_OBJC],
1337 [ 1326 [
1338 if test "x${have_gnu_objc}" = "xyes" ; then 1327 if test "x${have_gnu_objc}" = "xyes" ; then
1339 AC_LANG_PUSH([Objective C]) 1328 AC_LANG_PUSH([Objective C])
@@ -1368,6 +1357,38 @@ window = [[NSWindow alloc]
1368fi 1357fi
1369AC_SUBST(cocoa_ldflags) 1358AC_SUBST(cocoa_ldflags)
1370 1359
1360if test "x${want_cocoa}" = "xyes"; then
1361 #test cocoa requirements (objc and Cocoa/Cocoa.h)
1362 cocoa_coreservices_ldflags=""
1363 have_cocoa_coreservices="no"
1364 m4_ifdef([AC_PROG_OBJC],
1365 [
1366 if test "x${have_gnu_objc}" = "xyes" ; then
1367 AC_LANG_PUSH([Objective C])
1368 LIBS_save="$LIBS"
1369 LIBS="$LIBS -framework CoreServices"
1370 AC_LINK_IFELSE(
1371 [AC_LANG_PROGRAM(
1372 [[
1373#include <CoreServices/CoreServices.h>
1374 ]],
1375 [[
1376//test function here
1377 ]])],
1378 [
1379 have_cocoa_coreservices="yes"
1380 cocoa_coreservices_ldflags="-framework CoreServices"
1381 ],
1382 [have_cocoa_coreservices="no"])
1383 LIBS="$LIBS_save"
1384 AC_MSG_CHECKING([whether Cocoa CoreServices framework is supported])
1385 AC_MSG_RESULT([${have_cocoa_coreservices}])
1386 AC_LANG_POP([Objective C])
1387 fi
1388 ])
1389fi
1390AC_SUBST(cocoa_coreservices_ldflags)
1391
1371# Drm 1392# Drm
1372AC_ARG_ENABLE([drm], 1393AC_ARG_ENABLE([drm],
1373 [AS_HELP_STRING([--enable-drm],[enable drm engine. @<:@default=disabled@:>@])], 1394 [AS_HELP_STRING([--enable-drm],[enable drm engine. @<:@default=disabled@:>@])],
@@ -3969,6 +3990,20 @@ EFL_ADD_LIBS([EIO], [-lm])
3969### Checks for linker characteristics 3990### Checks for linker characteristics
3970 3991
3971### Checks for library functions 3992### Checks for library functions
3993have_inotify="${ac_cv_header_sys_inotify_h}"
3994AM_CONDITIONAL([HAVE_INOTIFY], [test "x${have_inotify}" = "xyes"])
3995
3996have_notify_win32="${have_win32}"
3997AC_DEFINE_IF([HAVE_NOTIFY_WIN32],
3998 [test "x${have_notify_win32}" = "xyes"], [1],
3999 [File monitoring with Windows notification])
4000AM_CONDITIONAL([HAVE_NOTIFY_WIN32], [test "x${have_notify_win32}" = "xyes"])
4001
4002AC_DEFINE_IF([HAVE_NOTIFY_COCOA],
4003 [test "x${have_darwin}" = "xyes"], [1],
4004 [File monitoring with fsevent notification])
4005AM_CONDITIONAL([HAVE_NOTIFY_COCOA], [test "x${have_darwin}" = "xyes"])
4006
3972 4007
3973EFL_LIB_END([Eio]) 4008EFL_LIB_END([Eio])
3974dnl TODO: remove these ifdefs from code! 4009dnl TODO: remove these ifdefs from code!
diff --git a/src/Makefile_Eio.am b/src/Makefile_Eio.am
index d3144391a0..ee118a35ab 100644
--- a/src/Makefile_Eio.am
+++ b/src/Makefile_Eio.am
@@ -23,6 +23,10 @@ lib_eio_libeio_la_SOURCES += lib/eio/eio_monitor_inotify.c
23else 23else
24if HAVE_NOTIFY_WIN32 24if HAVE_NOTIFY_WIN32
25lib_eio_libeio_la_SOURCES += lib/eio/eio_monitor_win32.c 25lib_eio_libeio_la_SOURCES += lib/eio/eio_monitor_win32.c
26else
27if HAVE_NOTIFY_COCOA
28lib_eio_libeio_la_SOURCES += lib/eio/eio_monitor_cocoa.c
29endif
26endif 30endif
27endif 31endif
28 32
@@ -30,6 +34,9 @@ lib_eio_libeio_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl @EIO_CFLAGS@
30lib_eio_libeio_la_LIBADD = @EIO_LIBS@ 34lib_eio_libeio_la_LIBADD = @EIO_LIBS@
31lib_eio_libeio_la_DEPENDENCIES = @EIO_INTERNAL_LIBS@ 35lib_eio_libeio_la_DEPENDENCIES = @EIO_INTERNAL_LIBS@
32lib_eio_libeio_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@ 36lib_eio_libeio_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@
37if HAVE_NOTIFY_COCOA
38lib_eio_libeio_la_LDFLAGS += -framework CoreServices
39endif
33 40
34if EFL_ENABLE_TESTS 41if EFL_ENABLE_TESTS
35 42
diff --git a/src/lib/eio/Eio.h b/src/lib/eio/Eio.h
index 0eb38c88b0..8edd4abc86 100644
--- a/src/lib/eio/Eio.h
+++ b/src/lib/eio/Eio.h
@@ -1219,13 +1219,13 @@ EAPI Eio_File *eio_eet_write_cipher(Eet_File *ef,
1219EAPI extern int EIO_MONITOR_FILE_CREATED; /**< A new file was created in a watched directory */ 1219EAPI extern int EIO_MONITOR_FILE_CREATED; /**< A new file was created in a watched directory */
1220EAPI extern int EIO_MONITOR_FILE_DELETED; /**< A watched file was deleted, or a file in a watched directory was deleted */ 1220EAPI extern int EIO_MONITOR_FILE_DELETED; /**< A watched file was deleted, or a file in a watched directory was deleted */
1221EAPI extern int EIO_MONITOR_FILE_MODIFIED; /**< A file was modified in a watched directory */ 1221EAPI extern int EIO_MONITOR_FILE_MODIFIED; /**< A file was modified in a watched directory */
1222EAPI extern int EIO_MONITOR_FILE_CLOSED; /**< A file was closed in a watched directory. This event is never sent on Windows */ 1222EAPI extern int EIO_MONITOR_FILE_CLOSED; /**< A file was closed in a watched directory. This event is never sent on Windows and OSX */
1223EAPI extern int EIO_MONITOR_DIRECTORY_CREATED; /**< A new directory was created in a watched directory */ 1223EAPI extern int EIO_MONITOR_DIRECTORY_CREATED; /**< A new directory was created in a watched directory */
1224EAPI extern int EIO_MONITOR_DIRECTORY_DELETED; /**< A directory has been deleted: this can be either a watched directory or one of its subdirectories */ 1224EAPI extern int EIO_MONITOR_DIRECTORY_DELETED; /**< A directory has been deleted: this can be either a watched directory or one of its subdirectories */
1225EAPI extern int EIO_MONITOR_DIRECTORY_MODIFIED; /**< A directory has been modified in a watched directory */ 1225EAPI extern int EIO_MONITOR_DIRECTORY_MODIFIED; /**< A directory has been modified in a watched directory */
1226EAPI extern int EIO_MONITOR_DIRECTORY_CLOSED; /**< A directory has been closed in a watched directory. This event is never sent on Windows */ 1226EAPI extern int EIO_MONITOR_DIRECTORY_CLOSED; /**< A directory has been closed in a watched directory. This event is never sent on Windows and OSX */
1227EAPI extern int EIO_MONITOR_SELF_RENAME; /**< The monitored path has been renamed, an error could happen just after if the renamed path doesn't exist */ 1227EAPI extern int EIO_MONITOR_SELF_RENAME; /**< The monitored path has been renamed, an error could happen just after if the renamed path doesn't exist. This event is never sent on OSX */
1228EAPI extern int EIO_MONITOR_SELF_DELETED; /**< The monitored path has been removed */ 1228EAPI extern int EIO_MONITOR_SELF_DELETED; /**< The monitored path has been removed. This event is never sent on OSX */
1229EAPI extern int EIO_MONITOR_ERROR; /**< During operation the monitor failed and will no longer work. eio_monitor_del must be called on it. */ 1229EAPI extern int EIO_MONITOR_ERROR; /**< During operation the monitor failed and will no longer work. eio_monitor_del must be called on it. */
1230 1230
1231typedef struct _Eio_Monitor Eio_Monitor; 1231typedef struct _Eio_Monitor Eio_Monitor;
diff --git a/src/lib/eio/eio_monitor_cocoa.c b/src/lib/eio/eio_monitor_cocoa.c
new file mode 100644
index 0000000000..ea1d793bab
--- /dev/null
+++ b/src/lib/eio/eio_monitor_cocoa.c
@@ -0,0 +1,405 @@
1/* EIO - EFL data type library
2 * Copyright (C) 2015 Enlightenment Developers:
3 * Pierre Lamot <pierre.lamot@openwide.fr>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library;
17 * if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "eio_private.h"
21#include "Eio.h"
22
23#import <CoreServices/CoreServices.h>
24
25static CFTimeInterval _latency = 0.1;
26
27/*============================================================================*
28 * Local *
29 *============================================================================*/
30
31/**
32 * @cond LOCAL
33 */
34
35struct _Eio_Monitor_Backend
36{
37 Eio_Monitor *parent;
38 ///the monitored path
39 char *mon_path;
40 ///the actual file path
41 char *real_path;
42};
43
44typedef struct _FSEvent_Info FSEvent_Info;
45
46struct _FSEvent_Info {
47 char *path;
48 FSEventStreamEventFlags flags;
49
50};
51
52typedef struct _Eio_FSEvent_Table Eio_FSEvent_Table;
53
54struct _Eio_FSEvent_Table
55{
56 int mask;
57 int *ev_file_code;
58 int *ev_dir_code;
59};
60
61#define EIO_FSEVENT_LINE(FSe, Ef, Ed) \
62 { kFSEventStreamEventFlag##FSe, &EIO_MONITOR_##Ef, &EIO_MONITOR_##Ed }
63
64static const Eio_FSEvent_Table match[] = {
65 EIO_FSEVENT_LINE(ItemChangeOwner, FILE_MODIFIED, DIRECTORY_MODIFIED),
66 EIO_FSEVENT_LINE(ItemInodeMetaMod, FILE_MODIFIED, DIRECTORY_MODIFIED),
67 EIO_FSEVENT_LINE(ItemXattrMod, FILE_MODIFIED, DIRECTORY_MODIFIED),
68 EIO_FSEVENT_LINE(ItemModified, FILE_MODIFIED, DIRECTORY_MODIFIED),
69 EIO_FSEVENT_LINE(ItemRemoved, FILE_DELETED, DIRECTORY_DELETED),
70 EIO_FSEVENT_LINE(ItemCreated, FILE_CREATED, DIRECTORY_CREATED),
71 EIO_FSEVENT_LINE(RootChanged, SELF_DELETED, SELF_DELETED)
72};
73
74static FSEventStreamRef _stream = NULL;
75static Eina_Hash *_fsevent_monitors = NULL;
76static CFMutableArrayRef _paths_to_watch = NULL;
77static dispatch_queue_t _dispatch_queue;
78
79static Eina_Bool
80_handle_fsevent_with_monitor(const Eina_Hash *hash EINA_UNUSED,
81 const void *key EINA_UNUSED,
82 void *data,
83 void *fdata)
84{
85 FSEvent_Info *event_info = (FSEvent_Info*)fdata;
86 Eio_Monitor_Backend *backend = (Eio_Monitor_Backend*)data;
87 FSEventStreamEventFlags flags = event_info->flags;
88 unsigned int i;
89 Eina_Bool is_dir;
90 unsigned int length, tmp_length;
91
92 char *tmp = NULL;
93
94 if (backend->parent->delete_me)
95 return 1;
96
97 if (!eina_str_has_prefix(event_info->path, backend->real_path))
98 {
99 return 1;
100 }
101
102 length = strlen(event_info->path) - strlen(backend->real_path);
103 if (length == 0)
104 {
105 tmp = strdup(backend->parent->path);
106 }
107 else
108 {
109 tmp_length =
110 eina_stringshare_strlen(backend->parent->path) + length + 2;
111
112 tmp = malloc(sizeof(char) * tmp_length);
113 snprintf(tmp, tmp_length, "%s/%s",
114 backend->parent->path,
115 &(event_info->path[strlen(backend->real_path) + 1]));
116 }
117
118 is_dir = !!(flags & kFSEventStreamEventFlagItemIsDir);
119
120 for (i = 0; i < sizeof (match) / sizeof (Eio_FSEvent_Table); ++i)
121 if (match[i].mask & flags)
122 {
123 DBG("send event from %s with event %X\n", event_info->path, flags);
124 _eio_monitor_send(backend->parent,
125 tmp,
126 is_dir ? *match[i].ev_dir_code : *match[i].ev_file_code);
127 }
128
129 free(tmp);
130 //we have found the right event, no need to continue
131 return 0;
132}
133
134
135static void
136_main_loop_send_event(void *data)
137{
138 FSEvent_Info *info = (FSEvent_Info*)data;
139
140 if (!_stream)
141 {
142 //this can happen, when eio_shutdown is called
143 goto cleanup;
144 }
145
146 if ((info->flags & kFSEventStreamEventFlagKernelDropped) != 0)
147 {
148 _eio_monitor_send(NULL, "", EIO_MONITOR_ERROR);
149 goto cleanup;
150 }
151
152 eina_hash_foreach(_fsevent_monitors,
153 _handle_fsevent_with_monitor,
154 info);
155
156 cleanup:
157 free(info->path);
158 free(info);
159}
160
161
162static void
163_eio_fsevent_cb(ConstFSEventStreamRef stream_ref EINA_UNUSED,
164 void *ctx EINA_UNUSED,
165 size_t count,
166 void *event_paths,
167 const FSEventStreamEventFlags event_flags[],
168 const FSEventStreamEventId event_ids[] EINA_UNUSED
169 )
170{
171 size_t i;
172 FSEvent_Info *event_info;
173
174 for (i = 0; i < count; i++)
175 {
176 event_info = malloc(sizeof(FSEvent_Info));
177 event_info->path = strdup(((char**)event_paths)[i]);
178 event_info->flags = event_flags[i];
179
180 ecore_main_loop_thread_safe_call_async(_main_loop_send_event,
181 event_info);
182 }
183}
184
185static void
186_eio_fsevent_del(void *data)
187{
188 Eio_Monitor_Backend *backend = (Eio_Monitor_Backend *)data;
189 free(backend);
190}
191
192static void
193_eio_get_monitor_path(const char *path, char **monpath, char **fullpath)
194{
195 char realPath[PATH_MAX];
196 char *realPathOk;
197 char *dname = NULL;
198 char *fname = NULL;
199 struct stat sb;
200
201 realPathOk = realpath(path, realPath);
202 if (realPathOk == NULL)
203 {
204 dname = dirname((char*)path);
205 if (strcmp(dname, ".") == 0)
206 {
207 realPathOk = realpath("./", realPath);
208 }
209 else
210 {
211 realPathOk = realpath(dname, realPath);
212 }
213
214 if (realPathOk == NULL)
215 return;
216 }
217
218 if (stat(realPath, &sb) < 0)
219 {
220 return;
221 }
222
223 if (S_ISDIR(sb.st_mode))
224 {
225 if (fullpath)
226 *fullpath = strdup(realPath);
227 if (monpath)
228 *monpath = strdup(realPath);
229 }
230 else
231 {
232 //not a directory, monitor parent
233 if (fullpath)
234 *fullpath = strdup(realPath);
235 dname = dirname(realPath);
236 if (monpath)
237 *monpath = strdup(dname);
238 }
239}
240
241/**
242 * @endcond
243 */
244
245
246/*============================================================================*
247 * Global *
248 *============================================================================*/
249
250/**
251 * @cond LOCAL
252 */
253
254/**
255 * @endcond
256 */
257
258void eio_monitor_backend_init(void)
259{
260 _dispatch_queue = dispatch_queue_create("org.elf.fseventqueue", NULL);
261 _fsevent_monitors = eina_hash_string_small_new(_eio_fsevent_del);
262 _paths_to_watch = CFArrayCreateMutable(kCFAllocatorDefault,
263 0,
264 &kCFTypeArrayCallBacks);
265}
266
267void eio_monitor_backend_shutdown(void)
268{
269 if (_stream)
270 {
271 FSEventStreamStop(_stream);
272 FSEventStreamInvalidate(_stream);
273 FSEventStreamRelease(_stream);
274 _stream = NULL;
275 }
276 dispatch_release(_dispatch_queue);
277 eina_hash_free(_fsevent_monitors);
278 CFRelease(_paths_to_watch);
279}
280
281
282void eio_monitor_backend_add(Eio_Monitor *monitor)
283{
284 Eio_Monitor_Backend *backend;
285
286 FSEventStreamEventId eventid;
287
288 CFStringRef path = NULL;
289
290 //the path we should monitor
291 char *monitor_path = NULL;
292 //the real file path
293 char *real_path = NULL;
294
295 _eio_get_monitor_path(monitor->path, &monitor_path, &real_path);
296
297 backend = calloc(1, sizeof (Eio_Monitor_Backend));
298 if (!backend)
299 {
300 free(monitor_path);
301 eio_monitor_fallback_add(monitor);
302 return;
303 }
304
305 path = CFStringCreateWithCString(NULL,
306 monitor_path,
307 kCFStringEncodingUTF8);
308
309 CFArrayAppendValue(_paths_to_watch, path);
310
311 if (_stream)
312 {
313 eventid = FSEventStreamGetLatestEventId(_stream);
314 FSEventStreamRelease(_stream);
315 _stream = NULL;
316 }
317 else
318 {
319 eventid = kFSEventStreamEventIdSinceNow;
320 }
321
322 _stream = FSEventStreamCreate(NULL,
323 _eio_fsevent_cb,
324 NULL,
325 _paths_to_watch,
326 eventid,
327 _latency,
328 kFSEventStreamCreateFlagFileEvents
329 | kFSEventStreamCreateFlagNoDefer
330 );
331
332 if (!_stream)
333 {
334 eio_monitor_fallback_add(monitor);
335 return;
336 }
337
338 backend->parent = monitor;
339 backend->mon_path = monitor_path;
340 backend->real_path = real_path;
341 monitor->backend = backend;
342
343 eina_hash_direct_add(_fsevent_monitors, monitor->path, backend);
344
345 FSEventStreamSetDispatchQueue(_stream, _dispatch_queue);
346 FSEventStreamStart(_stream);
347
348
349}
350
351void eio_monitor_backend_del(Eio_Monitor *monitor)
352{
353 Eio_Monitor_Backend *backend;
354 CFStringRef path = NULL;
355 FSEventStreamEventId eventid;
356 char *monitor_path;
357
358 if (!_stream)
359 {
360 eio_monitor_fallback_del(monitor);
361 return;
362 }
363
364 _eio_get_monitor_path(monitor->path, &monitor_path, NULL);
365
366 eventid = FSEventStreamGetLatestEventId(_stream);
367 FSEventStreamRelease(_stream);
368 _stream = NULL;
369
370 path = CFStringCreateWithCString(NULL,
371 monitor_path,
372 kCFStringEncodingUTF8);
373
374 CFIndex idx =
375 CFArrayGetFirstIndexOfValue(_paths_to_watch,
376 CFRangeMake(0,
377 CFArrayGetCount(_paths_to_watch)
378 ),
379 path);
380
381 if (idx != -1)
382 {
383 CFArrayRemoveValueAtIndex(_paths_to_watch, idx);
384 }
385
386 _stream = FSEventStreamCreate(NULL,
387 _eio_fsevent_cb,
388 NULL,
389 _paths_to_watch,
390 eventid,
391 _latency,
392 kFSEventStreamCreateFlagFileEvents
393 | kFSEventStreamCreateFlagNoDefer
394 );
395 backend = monitor->backend;
396 monitor->backend = NULL;
397 if (!backend) return;
398
399 eina_hash_del(_fsevent_monitors, monitor->path, backend);
400}
401
402
403/*============================================================================*
404 * API *
405 *============================================================================*/
diff --git a/src/lib/eio/eio_monitor_poll.c b/src/lib/eio/eio_monitor_poll.c
index c93ac4d579..0e222f5bc8 100644
--- a/src/lib/eio/eio_monitor_poll.c
+++ b/src/lib/eio/eio_monitor_poll.c
@@ -270,7 +270,7 @@ _eio_monitor_fallback_timer_cb(void *data)
270 * @cond LOCAL 270 * @cond LOCAL
271 */ 271 */
272 272
273#if !defined HAVE_SYS_INOTIFY_H && !defined HAVE_NOTIFY_WIN32 273#if !defined HAVE_SYS_INOTIFY_H && !defined HAVE_NOTIFY_WIN32 && !defined HAVE_NOTIFY_COCOA
274void eio_monitor_backend_init(void) 274void eio_monitor_backend_init(void)
275{ 275{
276} 276}
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}