eina_xattr: Fixed T2381, eina xattr tests failing

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
This commit is contained in:
vivek 2015-05-06 08:32:04 +02:00 committed by Stefan Schmidt
parent 26ebd007af
commit 400436cd1a
3 changed files with 55 additions and 22 deletions

View 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);

View 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);

View 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