eina_xattr: Fixed T2381, eina xattr tests failing
authorvivek <vivek.ellur@samsung.com>
Wed, 6 May 2015 06:32:04 +0000 (08:32 +0200)
committerStefan Schmidt <s.schmidt@samsung.com>
Wed, 6 May 2015 06:42:55 +0000 (08:42 +0200)
Summary:
This fixes the case where the system runs with SELinux enabled and enforced.
In this scenario the system does add a selinux attribute to new files which
we need to handle during our testing.

@Fix

Signed-off-by: vivek <vivek.ellur@samsung.com>
Reviewers: cedric, stefan_schmidt

Subscribers: stefan_schmidt, cedric

Maniphest Tasks: T2381

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

src/tests/eina/eina_test_file.c
src/tests/eina/eina_test_xattr.c
src/tests/eio/eio_test_xattr.c

index 5fa4a6862cbb4adacc283a3358e74bc9a70baec3..766ff46b6722abe3f667ccc8bf647cf5a702a2a0 100644 (file)
@@ -525,7 +525,7 @@ START_TEST(eina_test_file_xattr)
    Eina_Bool ret;
    Eina_Tmpstr *test_file_path;
    Eina_Iterator *it;
-   int fd;
+   int fd, count=0;
    Eina_Xattr *xattr;
 
    eina_init();
@@ -549,20 +549,27 @@ START_TEST(eina_test_file_xattr)
      {
         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]));
+            {
+               count++;
+               break;
+            }
      }
+   fail_if(count != sizeof (attribute) / sizeof (attribute[0]));
    eina_iterator_free(it);
 
+   count = 0;
    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]));
+            {
+               count++;
+               break;
+            }
      }
+   fail_if(count != sizeof (data) / sizeof (data[0]));
    eina_iterator_free(it);
 
    unlink(test_file_path);
index 50e1ad01ebec035659cf5cb8f944de5a634b4dcd..43a315aee3d3233e4fb694ca740526bd9d334849 100644 (file)
@@ -87,6 +87,7 @@ START_TEST(eina_test_xattr_set)
 
    ret = eina_xattr_fd_del(fd, attribute1);
    fail_if(ret != EINA_TRUE);
+
    close(fd);
    unlink(test_file_path);
    eina_tmpstr_del(test_file_path);
@@ -112,7 +113,7 @@ START_TEST(eina_test_xattr_list)
         "This file has extra attributes"
      };
    char *ret_str;
-   int fd, fd1;
+   int fd, fd1, count=0;
    unsigned int i;
    Eina_Bool ret;
    Eina_Tmpstr *test_file_path, *cp_file_path;
@@ -134,61 +135,81 @@ START_TEST(eina_test_xattr_list)
         ret = eina_xattr_set(test_file_path, attribute[i], data[i], strlen(data[i]), EINA_XATTR_INSERT);
         fail_if(ret != EINA_TRUE);
      }
+
    it = eina_xattr_ls(test_file_path);
    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]));
+            {
+               count++;
+               break ;
+            }
      }
+   fail_if(count != sizeof (attribute) / sizeof (attribute[0]));
    eina_iterator_free(it);
 
+   count = 0;
    it = eina_xattr_value_ls(test_file_path);
    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]));
+            {
+               count++;
+               break ;
+            }
      }
+   fail_if(count != sizeof (data) / sizeof (data[0]));
    eina_iterator_free(it);
 
+   count = 0;
    it = eina_xattr_fd_ls(fd);
    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]));
+            {
+               count++;
+               break ;
+            }
      }
+   fail_if(count != sizeof (attribute) / sizeof (attribute[0]));
    eina_iterator_free(it);
 
+   count = 0;
    it = eina_xattr_value_fd_ls(fd);
    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]));
+            {
+               count++;
+               break ;
+            }
      }
+   fail_if(count != sizeof (data) / sizeof (data[0]));
    eina_iterator_free(it);
 
    /* Test case for eina_xattr_copy and eina_xattr_fd_copy */
    ret = eina_xattr_copy(test_file_path, cp_file_path);
    fail_if(ret != EINA_TRUE);
 
+   count = 0;
    it = eina_xattr_value_ls(cp_file_path);
    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]));
+            {
+               count++;
+               break ;
+            }
      }
+   fail_if(count != sizeof (data) / sizeof (data[0]));
    eina_iterator_free(it);
 
    for (i = 0; i < sizeof(attribute) / sizeof(attribute[0]); ++i)
@@ -199,15 +220,20 @@ START_TEST(eina_test_xattr_list)
 
    ret = eina_xattr_fd_copy(fd, fd1);
    fail_if(ret != EINA_TRUE);
+
+   count = 0;
    it = eina_xattr_value_fd_ls(fd1);
    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]));
+            {
+               count++;
+               break ;
+            }
      }
+   fail_if(count != sizeof (data) / sizeof (data[0]));
    eina_iterator_free(it);
 
    close(fd);
index b832eb001ec71b34c3a932622e71673c43c48f0b..dfc5894045ba57cd6a35d889fc743cac1c473a2e 100644 (file)
@@ -58,10 +58,10 @@ _main_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, const char *attr
 
    for (i = 0; i < sizeof (attribute) / sizeof (attribute[0]); ++i)
      if (strcmp(attr, attribute[i]) == 0)
-       break;
-
-   fail_if(i == sizeof (attribute) / sizeof (attribute[0]));
-   (*num_of_attr)++;
+       {
+          (*num_of_attr)++;
+          break;
+       }
 }
 
 static void