| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include <check.h> |
| 22 |
#include <stdlib.h> |
| 23 |
|
| 24 |
#include "attributes.h" |
| 25 |
|
| 26 |
typedef struct { |
| 27 |
DB_ATTR_TYPE a; |
| 28 |
DB_ATTR_TYPE b; |
| 29 |
const char *expected_string; |
| 30 |
} diff_attributes_t; |
| 31 |
|
| 32 |
static diff_attributes_t diff_attributes_tests[] = { |
| 33 |
{ 0, 0, "" }, |
| 34 |
|
| 35 |
{ 0, ATTR(attr_linkname), "l" }, |
| 36 |
{ 0, ATTR(attr_perm), "p" }, |
| 37 |
{ 0, ATTR(attr_uid), "u" }, |
| 38 |
{ 0, ATTR(attr_gid), "g" }, |
| 39 |
{ 0, ATTR(attr_size), "s" }, |
| 40 |
{ 0, ATTR(attr_atime), "a" }, |
| 41 |
{ 0, ATTR(attr_ctime), "c" }, |
| 42 |
{ 0, ATTR(attr_mtime), "m" }, |
| 43 |
{ 0, ATTR(attr_inode), "i" }, |
| 44 |
{ 0, ATTR(attr_bcount), "b" }, |
| 45 |
{ 0, ATTR(attr_linkcount), "n" }, |
| 46 |
{ 0, ATTR(attr_md5), "md5" }, |
| 47 |
{ 0, ATTR(attr_sha1), "sha1" }, |
| 48 |
{ 0, ATTR(attr_rmd160), "rmd160" }, |
| 49 |
{ 0, ATTR(attr_tiger), "tiger" }, |
| 50 |
{ 0, ATTR(attr_crc32), "crc32" }, |
| 51 |
{ 0, ATTR(attr_haval), "haval" }, |
| 52 |
{ 0, ATTR(attr_gostr3411_94), "gost" }, |
| 53 |
{ 0, ATTR(attr_crc32b), "crc32b" }, |
| 54 |
|
| 55 |
{ 0, ATTR(attr_acl), "acl" }, |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
{ 0, ATTR(attr_sizeg), "S" }, |
| 61 |
{ 0, ATTR(attr_checkinode), "I" }, |
| 62 |
{ 0, ATTR(attr_allownewfile) , "ANF" }, |
| 63 |
{ 0, ATTR(attr_allowrmfile), "ARF" }, |
| 64 |
{ 0, ATTR(attr_sha256), "sha256" }, |
| 65 |
{ 0, ATTR(attr_sha512), "sha512" }, |
| 66 |
{ 0, ATTR(attr_selinux), "selinux" }, |
| 67 |
{ 0, ATTR(attr_xattrs), "xattrs" }, |
| 68 |
{ 0, ATTR(attr_whirlpool), "whirlpool" }, |
| 69 |
{ 0, ATTR(attr_ftype), "ftype" }, |
| 70 |
{ 0, ATTR(attr_e2fsattrs), "e2fsattrs" }, |
| 71 |
{ 0, ATTR(attr_capabilities), "caps" }, |
| 72 |
|
| 73 |
{ 0, ATTR(attr_linkname)|ATTR(attr_perm), "l+p" }, |
| 74 |
{ 0, ATTR(attr_ctime)|ATTR(attr_ftype), "c+ftype" }, |
| 75 |
{ 0, ATTR(attr_linkname)|ATTR(attr_perm)|ATTR(attr_uid)|ATTR(attr_gid)|ATTR(attr_size)|ATTR(attr_bcount)|ATTR(attr_linkcount)|ATTR(attr_sha256)|ATTR(attr_tiger)|ATTR(attr_haval)|ATTR(attr_sha512)|ATTR(attr_ftype), "l+p+u+g+s+b+n+tiger+haval+sha256+sha512+ftype" }, |
| 76 |
|
| 77 |
{ ATTR(attr_linkname), 0 , "-l" }, |
| 78 |
{ ATTR(attr_linkname), ATTR(attr_linkname) , "" }, |
| 79 |
{ ATTR(attr_linkname), ATTR(attr_linkname)|ATTR(attr_perm) , "+p" }, |
| 80 |
{ ATTR(attr_linkname)|ATTR(attr_perm), ATTR(attr_linkname) , "-p" }, |
| 81 |
{ ATTR(attr_perm)|ATTR(attr_mtime), ATTR(attr_perm)|ATTR(attr_uid)|ATTR(attr_gid)|ATTR(attr_size)|ATTR(attr_bcount)|ATTR(attr_linkcount), "+u+g+s-m+b+n" }, |
| 82 |
}; |
| 83 |
|
| 84 |
static int num_diff_attributes_tests = sizeof diff_attributes_tests / sizeof(diff_attributes_t); |
| 85 |
|
| 86 |
START_TEST (test_diff_attributes) { |
| 87 |
char *str = diff_attributes(diff_attributes_tests[_i].a, diff_attributes_tests[_i].b); |
| 88 |
ck_assert_msg(strcmp(diff_attributes_tests[_i].expected_string, str) == 0, "diff_attributes: %llu %llu: string returned '%s' != '%s'", diff_attributes_tests[_i].a, diff_attributes_tests[_i].b, str, diff_attributes_tests[_i].expected_string); |
| 89 |
free(str); |
| 90 |
} |
| 91 |
END_TEST |
| 92 |
|
| 93 |
Suite *make_attributes_suite(void) { |
| 94 |
|
| 95 |
Suite *s = suite_create ("attributes"); |
| 96 |
|
| 97 |
TCase *tc_diff_attributes = tcase_create ("diff_attributes"); |
| 98 |
|
| 99 |
tcase_add_loop_test (tc_diff_attributes, test_diff_attributes, 0, num_diff_attributes_tests); |
| 100 |
|
| 101 |
suite_add_tcase (s, tc_diff_attributes); |
| 102 |
|
| 103 |
return s; |
| 104 |
} |