summaryrefslogtreecommitdiff
path: root/src/tests/eio
diff options
context:
space:
mode:
authorVivek Ellur <vivek.ellur@samsung.com>2016-06-06 17:44:38 +0200
committerStefan Schmidt <stefan@osg.samsung.com>2016-06-16 14:15:24 +0200
commite2dbd0c50483d9276dccff12d5219d99ff3a9389 (patch)
treea14d0652be2d147a2da25ac12614d2fd24d4b688 /src/tests/eio
parent0b2602f86d2e27ed6063614683ae0c6a390cc549 (diff)
eio_map: Add test suite for eio map module
Summary: Added test suite for eio map module Signed-off-by: Vivek Ellur <vivek.ellur@samsung.com> Reviewers: cedric Subscribers: stefan_schmidt, raster, cedric Differential Revision: https://phab.enlightenment.org/D3321
Diffstat (limited to 'src/tests/eio')
-rw-r--r--src/tests/eio/eio_suite.c1
-rw-r--r--src/tests/eio/eio_suite.h1
-rw-r--r--src/tests/eio/eio_test_map.c100
3 files changed, 102 insertions, 0 deletions
diff --git a/src/tests/eio/eio_suite.c b/src/tests/eio/eio_suite.c
index 10ff27d531..1c86de8eb2 100644
--- a/src/tests/eio/eio_suite.c
+++ b/src/tests/eio/eio_suite.c
@@ -16,6 +16,7 @@ static const Efl_Test_Case etc[] = {
16 {"Eio_Xattr", eio_test_xattr}, 16 {"Eio_Xattr", eio_test_xattr},
17 {"Eio Job Xattr", eio_test_job_xattr}, 17 {"Eio Job Xattr", eio_test_job_xattr},
18#endif 18#endif
19 {"Eio_Map", eio_test_map},
19 {NULL, NULL} 20 {NULL, NULL}
20}; 21};
21 22
diff --git a/src/tests/eio/eio_suite.h b/src/tests/eio/eio_suite.h
index cdecfd0f09..45a5a325da 100644
--- a/src/tests/eio/eio_suite.h
+++ b/src/tests/eio/eio_suite.h
@@ -11,5 +11,6 @@ void eio_test_file(TCase *tc);
11void eio_test_job(TCase *tc); 11void eio_test_job(TCase *tc);
12void eio_test_job_xattr(TCase *tc); 12void eio_test_job_xattr(TCase *tc);
13void eio_test_xattr(TCase *tc); 13void eio_test_xattr(TCase *tc);
14void eio_test_map(TCase *tc);
14 15
15#endif /* _EIO_SUITE_H */ 16#endif /* _EIO_SUITE_H */
diff --git a/src/tests/eio/eio_test_map.c b/src/tests/eio/eio_test_map.c
new file mode 100644
index 0000000000..9299382690
--- /dev/null
+++ b/src/tests/eio/eio_test_map.c
@@ -0,0 +1,100 @@
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 <Ecore.h>
12#include <Eio.h>
13#include <Eet.h>
14
15#include "eio_suite.h"
16
17Eina_File *ee;
18
19static void
20_done_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED)
21{
22 ecore_main_loop_quit();
23}
24
25static void
26_open_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, Eina_File *ef)
27{
28 ee = ef;
29 ecore_main_loop_quit();
30}
31
32static Eina_Bool
33_filter_cb(void *data, Eio_File *handler EINA_UNUSED, void *map, size_t length)
34{
35 char *str = data;
36 size_t len = strlen(str);
37
38 fail_if(len != length);
39 fail_if(memcmp(data, map, length) != 0);
40 return EINA_TRUE;
41}
42
43static void
44_map_cb(void *data, Eio_File *handler EINA_UNUSED, void *map, size_t length)
45{
46 ecore_main_loop_quit();
47}
48
49static void
50_error_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, int error)
51{
52 fprintf(stderr, "Error:%s\n", strerror(error));
53 ecore_main_loop_quit();
54}
55
56START_TEST(eio_test_map_simple)
57{
58 int fd;
59 char *file = strdup("/tmp/eio_map_example.txt");
60 const char *data = "This is the data to save in file";
61 Eio_File *ef;
62
63 ecore_init();
64 eina_init();
65 eio_init();
66
67 fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG);
68 fail_if(fd == 0);
69 fail_if(write(fd, data, strlen(data)) != (ssize_t)strlen(data));
70 close(fd);
71
72 ef = eio_file_open(file, EINA_FALSE, _open_cb, _error_cb, NULL);
73 ecore_main_loop_begin();
74 fail_if(!ef);
75
76 ef = eio_file_map_all(ee, EINA_FILE_POPULATE, _filter_cb, _map_cb,
77 _error_cb, data);
78 ecore_main_loop_begin();
79 fail_if(!ef);
80
81 ef = eio_file_map_new(ee, EINA_FILE_WILLNEED, 0, strlen(data), _filter_cb,
82 _map_cb, _error_cb, data);
83 ecore_main_loop_begin();
84 fail_if(!ef);
85
86 ef = eio_file_close(ee, _done_cb, _error_cb, NULL);
87 ecore_main_loop_begin();
88 fail_if(!ef);
89
90 eio_shutdown();
91 eina_shutdown();
92 ecore_shutdown();
93}
94END_TEST
95
96void
97eio_test_map(TCase *tc)
98{
99 tcase_add_test(tc, eio_test_map_simple);
100}