| 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 |
static void set_up(void) { |
| 32 |
if (p == NULL) { |
| 33 |
p = permanent_pool = make_sub_pool(NULL); |
| 34 |
} |
| 35 |
pr_response_set_pool(p); |
| 36 |
|
| 37 |
if (getenv("TEST_VERBOSE") != NULL) { |
| 38 |
pr_trace_use_stderr(TRUE); |
| 39 |
pr_trace_set_levels("response", 0, 20); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
static void tear_down(void) { |
| 44 |
if (getenv("TEST_VERBOSE") != NULL) { |
| 45 |
pr_trace_use_stderr(FALSE); |
| 46 |
} |
| 47 |
|
| 48 |
pr_response_set_pool(NULL); |
| 49 |
|
| 50 |
if (p) { |
| 51 |
destroy_pool(p); |
| 52 |
p = permanent_pool = NULL; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
START_TEST (help_add_test) { |
| 57 |
const char *cmd, *syntax; |
| 58 |
|
| 59 |
mark_point(); |
| 60 |
pr_help_add(NULL, NULL, 0); |
| 61 |
|
| 62 |
cmd = "FOO"; |
| 63 |
|
| 64 |
mark_point(); |
| 65 |
pr_help_add(cmd, NULL, 0); |
| 66 |
|
| 67 |
syntax = "<path>"; |
| 68 |
|
| 69 |
mark_point(); |
| 70 |
pr_help_add(cmd, syntax, FALSE); |
| 71 |
|
| 72 |
mark_point(); |
| 73 |
pr_help_add(cmd, syntax, TRUE); |
| 74 |
|
| 75 |
cmd = "BAR"; |
| 76 |
|
| 77 |
mark_point(); |
| 78 |
pr_help_add(cmd, syntax, FALSE); |
| 79 |
} |
| 80 |
END_TEST |
| 81 |
|
| 82 |
START_TEST (help_add_response_test) { |
| 83 |
int res; |
| 84 |
const char *resp_code = NULL, *resp_msg = NULL; |
| 85 |
cmd_rec *cmd; |
| 86 |
|
| 87 |
res = pr_help_add_response(NULL, NULL); |
| 88 |
ck_assert_msg(res == -1, "Failed to handle null arguments"); |
| 89 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %s (%d)", |
| 90 |
strerror(errno), errno); |
| 91 |
|
| 92 |
mark_point(); |
| 93 |
|
| 94 |
cmd = pr_cmd_alloc(p, 2, C_HELP, "FOO"); |
| 95 |
res = pr_help_add_response(cmd, NULL); |
| 96 |
ck_assert_msg(res == -1, "Failed to handle empty help list"); |
| 97 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %s (%d)", |
| 98 |
strerror(errno), errno); |
| 99 |
|
| 100 |
mark_point(); |
| 101 |
|
| 102 |
|
| 103 |
pr_help_add("FOO", "", TRUE); |
| 104 |
|
| 105 |
mark_point(); |
| 106 |
|
| 107 |
res = pr_help_add_response(cmd, NULL); |
| 108 |
ck_assert_msg(res == 0, "Failed to add help response: %s", strerror(errno)); |
| 109 |
|
| 110 |
mark_point(); |
| 111 |
|
| 112 |
resp_code = resp_msg = NULL; |
| 113 |
res = pr_response_get_last(p, &resp_code, &resp_msg); |
| 114 |
ck_assert_msg(res == 0, "Failed to get last response: %s", strerror(errno)); |
| 115 |
ck_assert_msg(resp_code != NULL, "Expected non-null response code"); |
| 116 |
ck_assert_msg(strcmp(resp_code, R_214) == 0, |
| 117 |
"Expected response code %s, got %s", R_214, resp_code); |
| 118 |
ck_assert_msg(resp_msg != NULL, "Expected non-null response message"); |
| 119 |
ck_assert_msg(strcmp(resp_msg, "Direct comments to ftp-admin") == 0, |
| 120 |
"Expected response message '%s', got '%s'", "Direct comments to ftp-admin", |
| 121 |
resp_msg); |
| 122 |
|
| 123 |
mark_point(); |
| 124 |
|
| 125 |
res = pr_help_add_response(cmd, "FOO"); |
| 126 |
ck_assert_msg(res == 0, "Failed to add help response: %s", strerror(errno)); |
| 127 |
|
| 128 |
mark_point(); |
| 129 |
|
| 130 |
resp_code = resp_msg = NULL; |
| 131 |
res = pr_response_get_last(p, &resp_code, &resp_msg); |
| 132 |
ck_assert_msg(res == 0, "Failed to get last response: %s", strerror(errno)); |
| 133 |
ck_assert_msg(resp_code != NULL, "Expected non-null response code"); |
| 134 |
ck_assert_msg(strcmp(resp_code, R_214) == 0, |
| 135 |
"Expected response code %s, got %s", R_214, resp_code); |
| 136 |
ck_assert_msg(resp_msg != NULL, "Expected non-null response message"); |
| 137 |
ck_assert_msg(strcmp(resp_msg, "Syntax: FOO ") == 0, |
| 138 |
"Expected response message '%s', got '%s'", "Syntax: FOO ", resp_msg); |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
mark_point(); |
| 143 |
|
| 144 |
pr_help_add("BAR", "<path>", FALSE); |
| 145 |
|
| 146 |
res = pr_help_add_response(cmd, "BAR"); |
| 147 |
ck_assert_msg(res == 0, "Failed to add help response: %s", strerror(errno)); |
| 148 |
|
| 149 |
mark_point(); |
| 150 |
|
| 151 |
resp_code = resp_msg = NULL; |
| 152 |
res = pr_response_get_last(p, &resp_code, &resp_msg); |
| 153 |
ck_assert_msg(res == 0, "Failed to get last response: %s", strerror(errno)); |
| 154 |
ck_assert_msg(resp_code != NULL, "Expected non-null response code"); |
| 155 |
ck_assert_msg(strcmp(resp_code, R_214) == 0, |
| 156 |
"Expected response code %s, got %s", R_214, resp_code); |
| 157 |
ck_assert_msg(resp_msg != NULL, "Expected non-null response message"); |
| 158 |
ck_assert_msg(strcmp(resp_msg, "Syntax: BAR <path>") == 0, |
| 159 |
"Expected response message '%s', got '%s'", "Syntax: BAR <path>", resp_msg); |
| 160 |
} |
| 161 |
END_TEST |
| 162 |
|
| 163 |
Suite *tests_get_help_suite(void) { |
| 164 |
Suite *suite; |
| 165 |
TCase *testcase; |
| 166 |
|
| 167 |
suite = suite_create("help"); |
| 168 |
|
| 169 |
testcase = tcase_create("base"); |
| 170 |
|
| 171 |
tcase_add_checked_fixture(testcase, set_up, tear_down); |
| 172 |
|
| 173 |
tcase_add_test(testcase, help_add_test); |
| 174 |
tcase_add_test(testcase, help_add_response_test); |
| 175 |
|
| 176 |
suite_add_tcase(suite, testcase); |
| 177 |
return suite; |
| 178 |
} |