forked from enlightenment/efl
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
This commit is contained in:
parent
0b2602f86d
commit
e2dbd0c504
|
@ -88,6 +88,7 @@ tests/eio/eio_test_job_xattr.c \
|
|||
tests/eio/eio_test_xattr.c \
|
||||
tests/eio/eio_test_common.c \
|
||||
tests/eio/eio_test_common.h \
|
||||
tests/eio/eio_test_map.c \
|
||||
tests/eio/eio_suite.h
|
||||
|
||||
tests_eio_eio_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
|
||||
|
|
|
@ -16,6 +16,7 @@ static const Efl_Test_Case etc[] = {
|
|||
{"Eio_Xattr", eio_test_xattr},
|
||||
{"Eio Job Xattr", eio_test_job_xattr},
|
||||
#endif
|
||||
{"Eio_Map", eio_test_map},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
|
|
@ -11,5 +11,6 @@ void eio_test_file(TCase *tc);
|
|||
void eio_test_job(TCase *tc);
|
||||
void eio_test_job_xattr(TCase *tc);
|
||||
void eio_test_xattr(TCase *tc);
|
||||
void eio_test_map(TCase *tc);
|
||||
|
||||
#endif /* _EIO_SUITE_H */
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <Ecore.h>
|
||||
#include <Eio.h>
|
||||
#include <Eet.h>
|
||||
|
||||
#include "eio_suite.h"
|
||||
|
||||
Eina_File *ee;
|
||||
|
||||
static void
|
||||
_done_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED)
|
||||
{
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
static void
|
||||
_open_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, Eina_File *ef)
|
||||
{
|
||||
ee = ef;
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_filter_cb(void *data, Eio_File *handler EINA_UNUSED, void *map, size_t length)
|
||||
{
|
||||
char *str = data;
|
||||
size_t len = strlen(str);
|
||||
|
||||
fail_if(len != length);
|
||||
fail_if(memcmp(data, map, length) != 0);
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_map_cb(void *data, Eio_File *handler EINA_UNUSED, void *map, size_t length)
|
||||
{
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
static void
|
||||
_error_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, int error)
|
||||
{
|
||||
fprintf(stderr, "Error:%s\n", strerror(error));
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
START_TEST(eio_test_map_simple)
|
||||
{
|
||||
int fd;
|
||||
char *file = strdup("/tmp/eio_map_example.txt");
|
||||
const char *data = "This is the data to save in file";
|
||||
Eio_File *ef;
|
||||
|
||||
ecore_init();
|
||||
eina_init();
|
||||
eio_init();
|
||||
|
||||
fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG);
|
||||
fail_if(fd == 0);
|
||||
fail_if(write(fd, data, strlen(data)) != (ssize_t)strlen(data));
|
||||
close(fd);
|
||||
|
||||
ef = eio_file_open(file, EINA_FALSE, _open_cb, _error_cb, NULL);
|
||||
ecore_main_loop_begin();
|
||||
fail_if(!ef);
|
||||
|
||||
ef = eio_file_map_all(ee, EINA_FILE_POPULATE, _filter_cb, _map_cb,
|
||||
_error_cb, data);
|
||||
ecore_main_loop_begin();
|
||||
fail_if(!ef);
|
||||
|
||||
ef = eio_file_map_new(ee, EINA_FILE_WILLNEED, 0, strlen(data), _filter_cb,
|
||||
_map_cb, _error_cb, data);
|
||||
ecore_main_loop_begin();
|
||||
fail_if(!ef);
|
||||
|
||||
ef = eio_file_close(ee, _done_cb, _error_cb, NULL);
|
||||
ecore_main_loop_begin();
|
||||
fail_if(!ef);
|
||||
|
||||
eio_shutdown();
|
||||
eina_shutdown();
|
||||
ecore_shutdown();
|
||||
}
|
||||
END_TEST
|
||||
|
||||
void
|
||||
eio_test_map(TCase *tc)
|
||||
{
|
||||
tcase_add_test(tc, eio_test_map_simple);
|
||||
}
|
Loading…
Reference in New Issue