From a6b5ee94f0b4f01f88a038574ee75ed8ab98694b Mon Sep 17 00:00:00 2001 From: vivek Date: Fri, 6 Mar 2015 16:19:13 +0100 Subject: [PATCH] eina: add test cases for eina_xattr functions. Summary: Add eina_test_xattr.c file for testing eina xattr functions and added test cases for eina_xattr_set and eina_xattr_fd_set functions. Those tests need a directory where the underlying file system allow xattr. Usually /tmp is running on tmpfs that doesn't support today xattr. This test won't be run if we are not provided with an existing proper directory. Signed-off-by: vivek Reviewers: cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2090 Signed-off-by: Cedric BAIL --- configure.ac | 3 + src/Makefile_Eina.am | 4 +- src/tests/eina/eina_suite.c | 3 + src/tests/eina/eina_suite.h | 1 + src/tests/eina/eina_test_xattr.c | 111 +++++++++++++++++++++++++++++++ 5 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 src/tests/eina/eina_test_xattr.c diff --git a/configure.ac b/configure.ac index 90a5c6d85b..82da49dc8d 100644 --- a/configure.ac +++ b/configure.ac @@ -854,6 +854,9 @@ AC_ARG_ENABLE([magic-debug], EINA_CONFIG([MAGIC_DEBUG], [test "x${have_magic_debug}" = "xyes"]) +AC_ARG_WITH([xattr-tests-path], + [AS_HELP_STRING([--with-xattr-tests-path=DIR],[path of xattr enabled directory to create test files])],[XATTR_TEST_DIR=${withval}][AC_DEFINE_UNQUOTED([XATTR_TEST_DIR],["$withval"], [xattr enabled directory])]) + ### Checks for programs ### Checks for libraries diff --git a/src/Makefile_Eina.am b/src/Makefile_Eina.am index 539eadbf39..6341cd1268 100644 --- a/src/Makefile_Eina.am +++ b/src/Makefile_Eina.am @@ -282,9 +282,11 @@ tests/eina/eina_test_cow.c \ tests/eina/eina_test_barrier.c \ tests/eina/eina_test_tmpstr.c \ tests/eina/eina_test_trash.c \ -tests/eina/eina_test_lock.c +tests/eina/eina_test_lock.c \ +tests/eina/eina_test_xattr.c # tests/eina/eina_test_model.c + tests_eina_eina_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \ -DTESTS_WD=\"`pwd`\" \ -DTESTS_SRC_DIR=\"$(top_srcdir)/src/tests/eina\" \ diff --git a/src/tests/eina/eina_suite.c b/src/tests/eina/eina_suite.c index 26e30482e3..6e16d8ecb8 100644 --- a/src/tests/eina/eina_suite.c +++ b/src/tests/eina/eina_suite.c @@ -76,6 +76,9 @@ static const Eina_Test_Case etc[] = { { "Locking", eina_test_locking }, { "ABI", eina_test_abi }, { "Trash", eina_test_trash }, +#ifdef XATTR_TEST_DIR + { "Xattr", eina_test_xattr }, +#endif { NULL, NULL } }; diff --git a/src/tests/eina/eina_suite.h b/src/tests/eina/eina_suite.h index bc81a7c61a..433d95a6e3 100644 --- a/src/tests/eina/eina_suite.h +++ b/src/tests/eina/eina_suite.h @@ -63,5 +63,6 @@ void eina_test_tmpstr(TCase *tc); void eina_test_locking(TCase *tc); void eina_test_abi(TCase *tc); void eina_test_trash(TCase *tc); +void eina_test_xattr(TCase *tc); #endif /* EINA_SUITE_H_ */ diff --git a/src/tests/eina/eina_test_xattr.c b/src/tests/eina/eina_test_xattr.c new file mode 100644 index 0000000000..a7f4728417 --- /dev/null +++ b/src/tests/eina/eina_test_xattr.c @@ -0,0 +1,111 @@ +/* EINA - EFL data type library + * Copyright (C) 2015 Vivek Ellur + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include + +#include "eina_suite.h" +#include "Eina.h" + +Eina_Tmpstr* +get_file_path(const char* tmpdirname, const char* filename) +{ + char file_path[PATH_MAX] = ""; + eina_str_join(file_path, sizeof(file_path), '/', tmpdirname, filename); + return eina_tmpstr_add(file_path); +} + +#ifdef XATTR_TEST_DIR +START_TEST(eina_test_xattr_set) +{ + char *filename = "tmpfile"; + char *attribute1 = "user.comment1"; + char *data1 = "This is comment 1"; + char *attribute2 = "user.comment2"; + char *data2 = "This is comment 2"; + char *ret_str; + int fd, len; + Eina_Bool ret; + Eina_Tmpstr *test_file_path; + + eina_init(); + + test_file_path = get_file_path(XATTR_TEST_DIR, filename); + fd = open(test_file_path, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); + fail_if(fd == 0); + + ret = eina_xattr_set(test_file_path, attribute1, data1, strlen(data1), EINA_XATTR_INSERT); + fail_if(ret != EINA_TRUE); + ret_str = eina_xattr_get(test_file_path, attribute1, &len); + fail_if(ret_str == NULL); + fail_if(len == 0); + fail_if(strcmp(ret_str, data1) != 0); + free(ret_str); + + ret = eina_xattr_set(test_file_path, attribute1, data1, strlen(data1), EINA_XATTR_CREATED); + fail_if(ret != EINA_FALSE); + + ret = eina_xattr_set(test_file_path, attribute1, data2, strlen(data2), EINA_XATTR_REPLACE); + fail_if(ret != EINA_TRUE); + ret_str = eina_xattr_get(test_file_path, attribute1, &len); + fail_if(ret_str == NULL); + fail_if(len == 0); + fail_if(strcmp(ret_str, data2) != 0); + free(ret_str); + + ret = eina_xattr_set(test_file_path, attribute2, data2, strlen(data2), EINA_XATTR_REPLACE); + fail_if(ret != EINA_FALSE); + + ret = eina_xattr_del(test_file_path, attribute1); + fail_if(ret != EINA_TRUE); + + ret = eina_xattr_del(test_file_path, attribute2); + fail_if(ret != EINA_FALSE); + + ret = eina_xattr_fd_set(fd, attribute1, data1, strlen(data1), EINA_XATTR_CREATED); + fail_if(ret != EINA_TRUE); + ret_str = eina_xattr_fd_get(fd, attribute1, &len); + fail_if(ret_str == NULL); + fail_if(len == 0); + fail_if(strcmp(ret_str, data1) != 0); + free(ret_str); + + ret = eina_xattr_fd_del(fd, attribute1); + fail_if(ret != EINA_TRUE); + close(fd); + unlink(test_file_path); + eina_tmpstr_del(test_file_path); + + eina_shutdown(); +} +END_TEST +#endif + +void +eina_test_xattr(TCase *tc) +{ +#ifdef XATTR_TEST_DIR + tcase_add_test(tc, eina_test_xattr_set); +#endif +}