cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=dab4fb492a0f6689f3f64275945c4214e6a496b3

commit dab4fb492a0f6689f3f64275945c4214e6a496b3
Author: vivek <vivek.el...@samsung.com>
Date:   Wed Apr 22 14:21:36 2015 +0200

    eina: add test cases for eina file xattr functions.
    
    Summary:
    Added test cases for eina_file_xattr_get and eina_file_xattr_value_get 
functions
    
    Signed-off-by: vivek <vivek.el...@samsung.com>
    
    Reviewers: cedric
    
    Subscribers: cedric
    
    Differential Revision: https://phab.enlightenment.org/D2401
    
    Signed-off-by: Cedric BAIL <ced...@osg.samsung.com>
---
 src/tests/eina/eina_test_file.c  | 73 ++++++++++++++++++++++++++++++++++++++++
 src/tests/eina/eina_test_xattr.c |  4 ---
 2 files changed, 73 insertions(+), 4 deletions(-)

diff --git a/src/tests/eina/eina_test_file.c b/src/tests/eina/eina_test_file.c
index fec6054..38525bd 100644
--- a/src/tests/eina/eina_test_file.c
+++ b/src/tests/eina/eina_test_file.c
@@ -503,6 +503,76 @@ START_TEST(eina_test_file_path)
 }
 END_TEST
 
+#ifdef XATTR_TEST_DIR
+START_TEST(eina_test_file_xattr)
+{
+   Eina_File *ef;
+   char *filename = "tmpfile";
+   const char *attribute[] =
+     {
+        "user.comment1",
+        "user.comment2",
+        "user.comment3"
+     };
+   const char *data[] =
+     {
+        "This is a test file",
+        "This line is a comment",
+        "This file has extra attributes"
+     };
+   char *ret_str;
+   unsigned int i;
+   Eina_Bool ret;
+   Eina_Tmpstr *test_file_path;
+   Eina_Iterator *it;
+   int fd;
+   Eina_Xattr *xattr;
+
+   eina_init();
+   test_file_path = get_full_path(XATTR_TEST_DIR, filename);
+
+   fd = open(test_file_path, O_RDONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | 
S_IRWXO);
+   fail_if(fd == 0);
+   close(fd);
+
+   for (i = 0; i < sizeof(attribute) / sizeof(attribute[0]); ++i)
+     {
+        ret = eina_xattr_set(test_file_path, attribute[i], data[i], 
strlen(data[i]), EINA_XATTR_INSERT);
+        fail_if(ret != EINA_TRUE);
+     }
+
+   ef = eina_file_open(test_file_path, EINA_FALSE);
+   fail_if(!ef);
+
+   it = eina_file_xattr_get(ef);
+   EINA_ITERATOR_FOREACH(it, ret_str)
+     {
+        for (i = 0; i < sizeof (attribute) / sizeof (attribute[0]); i++)
+          if (strcmp(attribute[i], ret_str) == 0)
+            break ;
+        fail_if(i == sizeof (attribute) / sizeof (attribute[0]));
+     }
+   eina_iterator_free(it);
+
+   it = eina_file_xattr_value_get(ef);
+   EINA_ITERATOR_FOREACH(it, xattr)
+     {
+        for (i = 0; i < sizeof (data) / sizeof (data[0]); i++)
+          if (strcmp(attribute[i], xattr->name) == 0 &&
+              strcmp(data[i], xattr->value) == 0)
+            break ;
+        fail_if(i == sizeof (data) / sizeof (data[0]));
+     }
+   eina_iterator_free(it);
+
+   unlink(test_file_path);
+   eina_tmpstr_del(test_file_path);
+   eina_file_close(ef);
+   eina_shutdown();
+}
+END_TEST
+#endif
+
 void
 eina_test_file(TCase *tc)
 {
@@ -513,4 +583,7 @@ eina_test_file(TCase *tc)
    tcase_add_test(tc, eina_test_file_virtualize);
    tcase_add_test(tc, eina_test_file_thread);
    tcase_add_test(tc, eina_test_file_path);
+#ifdef XATTR_TEST_DIR
+   tcase_add_test(tc, eina_test_file_xattr);
+#endif
 }
diff --git a/src/tests/eina/eina_test_xattr.c b/src/tests/eina/eina_test_xattr.c
index 72c0c3d..50e1ad0 100644
--- a/src/tests/eina/eina_test_xattr.c
+++ b/src/tests/eina/eina_test_xattr.c
@@ -42,7 +42,6 @@ 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;
@@ -78,9 +77,6 @@ START_TEST(eina_test_xattr_set)
    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);

-- 


Reply via email to