| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#include "tests.h" |
| 28 |
|
| 29 |
static pool *p = NULL; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
static void set_up(void) { |
| 34 |
if (p == NULL) { |
| 35 |
p = permanent_pool = make_sub_pool(NULL); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
static void tear_down(void) { |
| 40 |
if (p) { |
| 41 |
destroy_pool(p); |
| 42 |
p = NULL; |
| 43 |
permanent_pool = NULL; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
START_TEST (feat_add_test) { |
| 50 |
int res; |
| 51 |
const char *key; |
| 52 |
|
| 53 |
res = pr_feat_add(NULL); |
| 54 |
ck_assert_msg(res == -1, "Failed to handle null feat"); |
| 55 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL"); |
| 56 |
|
| 57 |
key = "foo"; |
| 58 |
|
| 59 |
res = pr_feat_add(key); |
| 60 |
ck_assert_msg(res == 0, "Failed to add feat: %s", strerror(errno)); |
| 61 |
|
| 62 |
res = pr_feat_add(key); |
| 63 |
ck_assert_msg(res == -1, "Failed to handle duplicate feat"); |
| 64 |
ck_assert_msg(errno == EEXIST, "Failed to set errno to EEXIST"); |
| 65 |
} |
| 66 |
END_TEST |
| 67 |
|
| 68 |
START_TEST (feat_get_test) { |
| 69 |
int ok; |
| 70 |
const char *res; |
| 71 |
|
| 72 |
res = pr_feat_get(); |
| 73 |
ck_assert_msg(res == NULL, "Failed to handle empty feat"); |
| 74 |
ck_assert_msg(errno == EPERM, "Failed to set errno to EPERM"); |
| 75 |
|
| 76 |
ok = pr_feat_add("foo"); |
| 77 |
ck_assert_msg(ok == 0, "Failed to add feat: %s", strerror(errno)); |
| 78 |
|
| 79 |
res = pr_feat_get(); |
| 80 |
ck_assert_msg(res != NULL, "Failed to get feat: %s", strerror(errno)); |
| 81 |
ck_assert_msg(strcmp(res, "foo") == 0, "Expected '%s', got '%s'", "foo", res); |
| 82 |
|
| 83 |
res = pr_feat_get(); |
| 84 |
ck_assert_msg(res != NULL, "Failed to get feat: %s", strerror(errno)); |
| 85 |
ck_assert_msg(strcmp(res, "foo") == 0, "Expected '%s', got '%s'", "foo", res); |
| 86 |
} |
| 87 |
END_TEST |
| 88 |
|
| 89 |
START_TEST (feat_get_next_test) { |
| 90 |
int ok; |
| 91 |
const char *res; |
| 92 |
|
| 93 |
res = pr_feat_get_next(); |
| 94 |
ck_assert_msg(res == NULL, "Failed to handle empty feat"); |
| 95 |
ck_assert_msg(errno == EPERM, "Failed to set errno to EPERM"); |
| 96 |
|
| 97 |
ok = pr_feat_add("foo"); |
| 98 |
ck_assert_msg(ok == 0, "Failed to add feat: %s", strerror(errno)); |
| 99 |
|
| 100 |
res = pr_feat_get_next(); |
| 101 |
ck_assert_msg(res != NULL, "Failed to get feat: %s", strerror(errno)); |
| 102 |
ck_assert_msg(strcmp(res, "foo") == 0, "Expected '%s', got '%s'", "foo", res); |
| 103 |
|
| 104 |
res = pr_feat_get_next(); |
| 105 |
ck_assert_msg(res == NULL, "Expected null, got '%s'", res); |
| 106 |
} |
| 107 |
END_TEST |
| 108 |
|
| 109 |
START_TEST (feat_remove_test) { |
| 110 |
int res; |
| 111 |
const char *feat; |
| 112 |
|
| 113 |
res = pr_feat_remove(NULL); |
| 114 |
ck_assert_msg(res == -1, "Failed to handle empty feat"); |
| 115 |
ck_assert_msg(errno == EPERM, "Failed to set errno to EPERM"); |
| 116 |
|
| 117 |
feat = "foo"; |
| 118 |
res = pr_feat_add(feat); |
| 119 |
ck_assert_msg(res == 0, "Failed to add feat: %s", strerror(errno)); |
| 120 |
|
| 121 |
res = pr_feat_remove(NULL); |
| 122 |
ck_assert_msg(res == -1, "Failed to handle null feat"); |
| 123 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL"); |
| 124 |
|
| 125 |
res = pr_feat_remove(feat); |
| 126 |
ck_assert_msg(res == 0, "Failed to remove feat: %s", strerror(errno)); |
| 127 |
|
| 128 |
res = pr_feat_remove(feat); |
| 129 |
ck_assert_msg(res == -1, "Failed to detected removed feat"); |
| 130 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT"); |
| 131 |
} |
| 132 |
END_TEST |
| 133 |
|
| 134 |
Suite *tests_get_feat_suite(void) { |
| 135 |
Suite *suite; |
| 136 |
TCase *testcase; |
| 137 |
|
| 138 |
suite = suite_create("feat"); |
| 139 |
|
| 140 |
testcase = tcase_create("base"); |
| 141 |
|
| 142 |
tcase_add_checked_fixture(testcase, set_up, tear_down); |
| 143 |
|
| 144 |
tcase_add_test(testcase, feat_add_test); |
| 145 |
tcase_add_test(testcase, feat_get_test); |
| 146 |
tcase_add_test(testcase, feat_get_next_test); |
| 147 |
tcase_add_test(testcase, feat_remove_test); |
| 148 |
|
| 149 |
suite_add_tcase(suite, testcase); |
| 150 |
|
| 151 |
return suite; |
| 152 |
} |