eina: add test cases for eina_xattr functions.
authorvivek <vivek.ellur@samsung.com>
Fri, 6 Mar 2015 15:19:13 +0000 (16:19 +0100)
committerCedric BAIL <cedric@osg.samsung.com>
Fri, 6 Mar 2015 19:19:21 +0000 (20:19 +0100)
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 <vivek.ellur@samsung.com>
Reviewers: cedric

Subscribers: cedric

Differential Revision: https://phab.enlightenment.org/D2090

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
configure.ac
src/Makefile_Eina.am
src/tests/eina/eina_suite.c
src/tests/eina/eina_suite.h
src/tests/eina/eina_test_xattr.c [new file with mode: 0644]

index 90a5c6d..82da49d 100644 (file)
@@ -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
index 539eadb..6341cd1 100644 (file)
@@ -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\" \
index 26e3048..6e16d8e 100644 (file)
@@ -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 }
 };
 
index bc81a7c..433d95a 100644 (file)
@@ -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 (file)
index 0000000..a7f4728
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#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
+}