| 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 |
|
| 36 |
init_stash(); |
| 37 |
} |
| 38 |
|
| 39 |
static void tear_down(void) { |
| 40 |
if (p) { |
| 41 |
destroy_pool(p); |
| 42 |
p = permanent_pool = NULL; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
START_TEST (stash_add_symbol_test) { |
| 47 |
int res; |
| 48 |
conftable conftab; |
| 49 |
cmdtable cmdtab, hooktab; |
| 50 |
authtable authtab; |
| 51 |
|
| 52 |
res = pr_stash_add_symbol(0, NULL); |
| 53 |
ck_assert_msg(res == -1, "Failed to handle null arguments"); |
| 54 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 55 |
errno, strerror(errno)); |
| 56 |
|
| 57 |
res = pr_stash_add_symbol(0, "Foo"); |
| 58 |
ck_assert_msg(res == -1, "Failed to handle bad type"); |
| 59 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 60 |
errno, strerror(errno)); |
| 61 |
|
| 62 |
memset(&conftab, 0, sizeof(conftab)); |
| 63 |
res = pr_stash_add_symbol(PR_SYM_CONF, &conftab); |
| 64 |
ck_assert_msg(res == -1, "Failed to handle null conf name"); |
| 65 |
ck_assert_msg(errno == EPERM, "Failed to set errno to EPERM, got %d (%s)", |
| 66 |
errno, strerror(errno)); |
| 67 |
|
| 68 |
memset(&cmdtab, 0, sizeof(cmdtab)); |
| 69 |
res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab); |
| 70 |
ck_assert_msg(res == -1, "Failed to handle null cmd name"); |
| 71 |
ck_assert_msg(errno == EPERM, "Failed to set errno to EPERM, got %d (%s)", |
| 72 |
errno, strerror(errno)); |
| 73 |
|
| 74 |
memset(&authtab, 0, sizeof(authtab)); |
| 75 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 76 |
ck_assert_msg(res == -1, "Failed to handle null auth name"); |
| 77 |
ck_assert_msg(errno == EPERM, "Failed to set errno to EPERM, got %d (%s)", |
| 78 |
errno, strerror(errno)); |
| 79 |
|
| 80 |
memset(&hooktab, 0, sizeof(hooktab)); |
| 81 |
res = pr_stash_add_symbol(PR_SYM_HOOK, &hooktab); |
| 82 |
ck_assert_msg(res == -1, "Failed to handle null hook name"); |
| 83 |
ck_assert_msg(errno == EPERM, "Failed to set errno to EPERM, got %d (%s)", |
| 84 |
errno, strerror(errno)); |
| 85 |
|
| 86 |
memset(&conftab, 0, sizeof(conftab)); |
| 87 |
conftab.directive = pstrdup(p, ""); |
| 88 |
res = pr_stash_add_symbol(PR_SYM_CONF, &conftab); |
| 89 |
ck_assert_msg(res == -1, "Failed to handle empty conf name"); |
| 90 |
ck_assert_msg(errno == EPERM, "Failed to set errno to EPERM, got %d (%s)", |
| 91 |
errno, strerror(errno)); |
| 92 |
|
| 93 |
memset(&conftab, 0, sizeof(conftab)); |
| 94 |
conftab.directive = pstrdup(p, "Foo"); |
| 95 |
res = pr_stash_add_symbol(PR_SYM_CONF, &conftab); |
| 96 |
ck_assert_msg(res == 0, "Failed to add CONF symbol: %s", strerror(errno)); |
| 97 |
|
| 98 |
memset(&cmdtab, 0, sizeof(cmdtab)); |
| 99 |
cmdtab.command = pstrdup(p, "Foo"); |
| 100 |
res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab); |
| 101 |
ck_assert_msg(res == 0, "Failed to add CMD symbol: %s", strerror(errno)); |
| 102 |
|
| 103 |
memset(&authtab, 0, sizeof(authtab)); |
| 104 |
authtab.name = pstrdup(p, "Foo"); |
| 105 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 106 |
ck_assert_msg(res == 0, "Failed to add AUTH symbol: %s", strerror(errno)); |
| 107 |
|
| 108 |
memset(&hooktab, 0, sizeof(hooktab)); |
| 109 |
hooktab.command = pstrdup(p, "Foo"); |
| 110 |
res = pr_stash_add_symbol(PR_SYM_HOOK, &hooktab); |
| 111 |
ck_assert_msg(res == 0, "Failed to add HOOK symbol: %s", strerror(errno)); |
| 112 |
} |
| 113 |
END_TEST |
| 114 |
|
| 115 |
START_TEST (stash_get_symbol_test) { |
| 116 |
int res; |
| 117 |
void *sym; |
| 118 |
conftable conftab; |
| 119 |
cmdtable cmdtab, hooktab; |
| 120 |
authtable authtab; |
| 121 |
|
| 122 |
sym = pr_stash_get_symbol(0, NULL, NULL, NULL); |
| 123 |
ck_assert_msg(sym == NULL, "Failed to handle null arguments"); |
| 124 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 125 |
errno, strerror(errno)); |
| 126 |
|
| 127 |
sym = pr_stash_get_symbol(0, "foo", NULL, NULL); |
| 128 |
ck_assert_msg(sym == NULL, "Failed to handle bad type argument"); |
| 129 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 130 |
errno, strerror(errno)); |
| 131 |
|
| 132 |
sym = pr_stash_get_symbol(PR_SYM_CONF, "foo", NULL, NULL); |
| 133 |
ck_assert_msg(sym == NULL, "Failed to handle nonexistent CONF symbol"); |
| 134 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 135 |
errno, strerror(errno)); |
| 136 |
|
| 137 |
sym = pr_stash_get_symbol(PR_SYM_CMD, "foo", NULL, NULL); |
| 138 |
ck_assert_msg(sym == NULL, "Failed to handle nonexistent CMD symbol"); |
| 139 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 140 |
errno, strerror(errno)); |
| 141 |
|
| 142 |
sym = pr_stash_get_symbol(PR_SYM_AUTH, "foo", NULL, NULL); |
| 143 |
ck_assert_msg(sym == NULL, "Failed to handle nonexistent AUTH symbol"); |
| 144 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 145 |
errno, strerror(errno)); |
| 146 |
|
| 147 |
sym = pr_stash_get_symbol(PR_SYM_HOOK, "foo", NULL, NULL); |
| 148 |
ck_assert_msg(sym == NULL, "Failed to handle nonexistent HOOK symbol"); |
| 149 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 150 |
errno, strerror(errno)); |
| 151 |
|
| 152 |
memset(&conftab, 0, sizeof(conftab)); |
| 153 |
conftab.directive = pstrdup(p, "foo"); |
| 154 |
res = pr_stash_add_symbol(PR_SYM_CONF, &conftab); |
| 155 |
ck_assert_msg(res == 0, "Failed to add CONF symbol: %s", strerror(errno)); |
| 156 |
|
| 157 |
sym = pr_stash_get_symbol(PR_SYM_CONF, "foo", NULL, NULL); |
| 158 |
ck_assert_msg(sym != NULL, "Failed to get CONF symbol: %s", strerror(errno)); |
| 159 |
ck_assert_msg(sym == &conftab, "Expected %p, got %p", &conftab, sym); |
| 160 |
|
| 161 |
sym = pr_stash_get_symbol(PR_SYM_CONF, "foo", sym, NULL); |
| 162 |
ck_assert_msg(sym == NULL, "Unexpectedly found CONF symbol"); |
| 163 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 164 |
errno, strerror(errno)); |
| 165 |
|
| 166 |
memset(&cmdtab, 0, sizeof(cmdtab)); |
| 167 |
cmdtab.command = pstrdup(p, "foo"); |
| 168 |
res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab); |
| 169 |
ck_assert_msg(res == 0, "Failed to add CMD symbol: %s", strerror(errno)); |
| 170 |
|
| 171 |
sym = pr_stash_get_symbol(PR_SYM_CMD, "foo", NULL, NULL); |
| 172 |
ck_assert_msg(sym != NULL, "Failed to get CMD symbol: %s", strerror(errno)); |
| 173 |
ck_assert_msg(sym == &cmdtab, "Expected %p, got %p", &cmdtab, sym); |
| 174 |
|
| 175 |
sym = pr_stash_get_symbol(PR_SYM_CMD, "foo", sym, NULL); |
| 176 |
ck_assert_msg(sym == NULL, "Unexpectedly found CMD symbol"); |
| 177 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 178 |
errno, strerror(errno)); |
| 179 |
|
| 180 |
memset(&authtab, 0, sizeof(authtab)); |
| 181 |
authtab.name = pstrdup(p, "foo"); |
| 182 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 183 |
ck_assert_msg(res == 0, "Failed to add AUTH symbol: %s", strerror(errno)); |
| 184 |
|
| 185 |
sym = pr_stash_get_symbol(PR_SYM_AUTH, "foo", NULL, NULL); |
| 186 |
ck_assert_msg(sym != NULL, "Failed to get AUTH symbol: %s", strerror(errno)); |
| 187 |
ck_assert_msg(sym == &authtab, "Expected %p, got %p", &authtab, sym); |
| 188 |
|
| 189 |
sym = pr_stash_get_symbol(PR_SYM_AUTH, "foo", sym, NULL); |
| 190 |
ck_assert_msg(sym == NULL, "Unexpectedly found AUTH symbol"); |
| 191 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 192 |
errno, strerror(errno)); |
| 193 |
|
| 194 |
memset(&hooktab, 0, sizeof(hooktab)); |
| 195 |
hooktab.command = pstrdup(p, "foo"); |
| 196 |
res = pr_stash_add_symbol(PR_SYM_HOOK, &hooktab); |
| 197 |
ck_assert_msg(res == 0, "Failed to add HOOK symbol: %s", strerror(errno)); |
| 198 |
|
| 199 |
sym = pr_stash_get_symbol(PR_SYM_HOOK, "foo", NULL, NULL); |
| 200 |
ck_assert_msg(sym != NULL, "Failed to get HOOK symbol: %s", strerror(errno)); |
| 201 |
ck_assert_msg(sym == &hooktab, "Expected %p, got %p", &hooktab, sym); |
| 202 |
|
| 203 |
sym = pr_stash_get_symbol(PR_SYM_HOOK, "foo", sym, NULL); |
| 204 |
ck_assert_msg(sym == NULL, "Unexpectedly found HOOK symbol"); |
| 205 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 206 |
errno, strerror(errno)); |
| 207 |
} |
| 208 |
END_TEST |
| 209 |
|
| 210 |
START_TEST (stash_get_symbol2_test) { |
| 211 |
int res; |
| 212 |
void *sym; |
| 213 |
conftable conftab; |
| 214 |
cmdtable cmdtab, hooktab; |
| 215 |
authtable authtab; |
| 216 |
|
| 217 |
sym = pr_stash_get_symbol2(0, NULL, NULL, NULL, NULL); |
| 218 |
ck_assert_msg(sym == NULL, "Failed to handle null arguments"); |
| 219 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 220 |
errno, strerror(errno)); |
| 221 |
|
| 222 |
sym = pr_stash_get_symbol2(0, "foo", NULL, NULL, NULL); |
| 223 |
ck_assert_msg(sym == NULL, "Failed to handle bad type argument"); |
| 224 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 225 |
errno, strerror(errno)); |
| 226 |
|
| 227 |
sym = pr_stash_get_symbol2(PR_SYM_CONF, "foo", NULL, NULL, NULL); |
| 228 |
ck_assert_msg(sym == NULL, "Failed to handle nonexistent CONF symbol"); |
| 229 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 230 |
errno, strerror(errno)); |
| 231 |
|
| 232 |
sym = pr_stash_get_symbol2(PR_SYM_CMD, "foo", NULL, NULL, NULL); |
| 233 |
ck_assert_msg(sym == NULL, "Failed to handle nonexistent CMD symbol"); |
| 234 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 235 |
errno, strerror(errno)); |
| 236 |
|
| 237 |
sym = pr_stash_get_symbol2(PR_SYM_AUTH, "foo", NULL, NULL, NULL); |
| 238 |
ck_assert_msg(sym == NULL, "Failed to handle nonexistent AUTH symbol"); |
| 239 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 240 |
errno, strerror(errno)); |
| 241 |
|
| 242 |
sym = pr_stash_get_symbol2(PR_SYM_HOOK, "foo", NULL, NULL, NULL); |
| 243 |
ck_assert_msg(sym == NULL, "Failed to handle nonexistent HOOK symbol"); |
| 244 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 245 |
errno, strerror(errno)); |
| 246 |
|
| 247 |
memset(&conftab, 0, sizeof(conftab)); |
| 248 |
conftab.directive = pstrdup(p, "foo"); |
| 249 |
res = pr_stash_add_symbol(PR_SYM_CONF, &conftab); |
| 250 |
ck_assert_msg(res == 0, "Failed to add CONF symbol: %s", strerror(errno)); |
| 251 |
|
| 252 |
sym = pr_stash_get_symbol2(PR_SYM_CONF, "foo", NULL, NULL, NULL); |
| 253 |
ck_assert_msg(sym != NULL, "Failed to get CONF symbol: %s", strerror(errno)); |
| 254 |
ck_assert_msg(sym == &conftab, "Expected %p, got %p", &conftab, sym); |
| 255 |
|
| 256 |
sym = pr_stash_get_symbol2(PR_SYM_CONF, "foo", sym, NULL, NULL); |
| 257 |
ck_assert_msg(sym == NULL, "Unexpectedly found CONF symbol"); |
| 258 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 259 |
errno, strerror(errno)); |
| 260 |
|
| 261 |
memset(&cmdtab, 0, sizeof(cmdtab)); |
| 262 |
cmdtab.command = pstrdup(p, "foo"); |
| 263 |
res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab); |
| 264 |
ck_assert_msg(res == 0, "Failed to add CMD symbol: %s", strerror(errno)); |
| 265 |
|
| 266 |
sym = pr_stash_get_symbol2(PR_SYM_CMD, "foo", NULL, NULL, NULL); |
| 267 |
ck_assert_msg(sym != NULL, "Failed to get CMD symbol: %s", strerror(errno)); |
| 268 |
ck_assert_msg(sym == &cmdtab, "Expected %p, got %p", &cmdtab, sym); |
| 269 |
|
| 270 |
sym = pr_stash_get_symbol2(PR_SYM_CMD, "foo", sym, NULL, NULL); |
| 271 |
ck_assert_msg(sym == NULL, "Unexpectedly found CMD symbol"); |
| 272 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 273 |
errno, strerror(errno)); |
| 274 |
|
| 275 |
memset(&authtab, 0, sizeof(authtab)); |
| 276 |
authtab.name = pstrdup(p, "foo"); |
| 277 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 278 |
ck_assert_msg(res == 0, "Failed to add AUTH symbol: %s", strerror(errno)); |
| 279 |
|
| 280 |
sym = pr_stash_get_symbol2(PR_SYM_AUTH, "foo", NULL, NULL, NULL); |
| 281 |
ck_assert_msg(sym != NULL, "Failed to get AUTH symbol: %s", strerror(errno)); |
| 282 |
ck_assert_msg(sym == &authtab, "Expected %p, got %p", &authtab, sym); |
| 283 |
|
| 284 |
sym = pr_stash_get_symbol2(PR_SYM_AUTH, "foo", sym, NULL, NULL); |
| 285 |
ck_assert_msg(sym == NULL, "Unexpectedly found AUTH symbol"); |
| 286 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 287 |
errno, strerror(errno)); |
| 288 |
|
| 289 |
memset(&hooktab, 0, sizeof(hooktab)); |
| 290 |
hooktab.command = pstrdup(p, "foo"); |
| 291 |
res = pr_stash_add_symbol(PR_SYM_HOOK, &hooktab); |
| 292 |
ck_assert_msg(res == 0, "Failed to add HOOK symbol: %s", strerror(errno)); |
| 293 |
|
| 294 |
sym = pr_stash_get_symbol2(PR_SYM_HOOK, "foo", NULL, NULL, NULL); |
| 295 |
ck_assert_msg(sym != NULL, "Failed to get HOOK symbol: %s", strerror(errno)); |
| 296 |
ck_assert_msg(sym == &hooktab, "Expected %p, got %p", &hooktab, sym); |
| 297 |
|
| 298 |
sym = pr_stash_get_symbol2(PR_SYM_HOOK, "foo", sym, NULL, NULL); |
| 299 |
ck_assert_msg(sym == NULL, "Unexpectedly found HOOK symbol"); |
| 300 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 301 |
errno, strerror(errno)); |
| 302 |
} |
| 303 |
END_TEST |
| 304 |
|
| 305 |
#ifdef PR_USE_DEVEL |
| 306 |
static void stash_dump(const char *fmt, ...) { |
| 307 |
} |
| 308 |
|
| 309 |
START_TEST (stash_dump_test) { |
| 310 |
int res; |
| 311 |
conftable conftab; |
| 312 |
cmdtable cmdtab, hooktab; |
| 313 |
authtable authtab; |
| 314 |
module m; |
| 315 |
|
| 316 |
mark_point(); |
| 317 |
pr_stash_dump(stash_dump); |
| 318 |
|
| 319 |
memset(&conftab, 0, sizeof(conftab)); |
| 320 |
conftab.directive = pstrdup(p, "Conf"); |
| 321 |
res = pr_stash_add_symbol(PR_SYM_CONF, &conftab); |
| 322 |
ck_assert_msg(res == 0, "Failed to add CONF symbol: %s", strerror(errno)); |
| 323 |
|
| 324 |
memset(&cmdtab, 0, sizeof(cmdtab)); |
| 325 |
cmdtab.command = pstrdup(p, "Cmd"); |
| 326 |
res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab); |
| 327 |
ck_assert_msg(res == 0, "Failed to add CMD symbol: %s", strerror(errno)); |
| 328 |
|
| 329 |
memset(&authtab, 0, sizeof(authtab)); |
| 330 |
authtab.name = pstrdup(p, "Auth"); |
| 331 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 332 |
ck_assert_msg(res == 0, "Failed to add AUTH symbol: %s", strerror(errno)); |
| 333 |
|
| 334 |
memset(&m, 0, sizeof(m)); |
| 335 |
m.name = "testsuite"; |
| 336 |
memset(&hooktab, 0, sizeof(hooktab)); |
| 337 |
hooktab.command = pstrdup(p, "Hook"); |
| 338 |
hooktab.m = &m; |
| 339 |
res = pr_stash_add_symbol(PR_SYM_HOOK, &hooktab); |
| 340 |
ck_assert_msg(res == 0, "Failed to add HOOK symbol: %s", strerror(errno)); |
| 341 |
|
| 342 |
mark_point(); |
| 343 |
pr_stash_dump(stash_dump); |
| 344 |
|
| 345 |
res = pr_stash_remove_symbol(PR_SYM_CONF, "Conf", NULL); |
| 346 |
ck_assert_msg(res > 0, "Failed to remove CONF symbol: %s", strerror(errno)); |
| 347 |
|
| 348 |
res = pr_stash_remove_symbol(PR_SYM_CMD, "Cmd", NULL); |
| 349 |
ck_assert_msg(res > 0, "Failed to remove CMD symbol: %s", strerror(errno)); |
| 350 |
|
| 351 |
res = pr_stash_remove_symbol(PR_SYM_AUTH, "Auth", NULL); |
| 352 |
ck_assert_msg(res > 0, "Failed to remove AUTH symbol: %s", strerror(errno)); |
| 353 |
|
| 354 |
res = pr_stash_remove_symbol(PR_SYM_HOOK, "Hook", NULL); |
| 355 |
ck_assert_msg(res > 0, "Failed to remove HOOK symbol: %s", strerror(errno)); |
| 356 |
|
| 357 |
mark_point(); |
| 358 |
pr_stash_dump(stash_dump); |
| 359 |
} |
| 360 |
END_TEST |
| 361 |
#endif |
| 362 |
|
| 363 |
START_TEST (stash_remove_symbol_test) { |
| 364 |
int res; |
| 365 |
conftable conftab; |
| 366 |
cmdtable cmdtab, hooktab; |
| 367 |
authtable authtab; |
| 368 |
|
| 369 |
res = pr_stash_remove_symbol(0, NULL, NULL); |
| 370 |
ck_assert_msg(res == -1, "Failed to handle null arguments"); |
| 371 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 372 |
errno, strerror(errno)); |
| 373 |
|
| 374 |
res = pr_stash_remove_symbol(0, "foo", NULL); |
| 375 |
ck_assert_msg(res == -1, "Failed to handle bad symbol type"); |
| 376 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 377 |
errno, strerror(errno)); |
| 378 |
|
| 379 |
res = pr_stash_remove_symbol(PR_SYM_CONF, "foo", NULL); |
| 380 |
ck_assert_msg(res == 0, "Expected %d, got %d", 0, res); |
| 381 |
|
| 382 |
memset(&conftab, 0, sizeof(conftab)); |
| 383 |
conftab.directive = pstrdup(p, "foo"); |
| 384 |
res = pr_stash_add_symbol(PR_SYM_CONF, &conftab); |
| 385 |
ck_assert_msg(res == 0, "Failed to add CONF symbol: %s", strerror(errno)); |
| 386 |
|
| 387 |
res = pr_stash_add_symbol(PR_SYM_CONF, &conftab); |
| 388 |
ck_assert_msg(res == 0, "Failed to add CONF symbol: %s", strerror(errno)); |
| 389 |
|
| 390 |
res = pr_stash_remove_symbol(PR_SYM_CONF, "foo", NULL); |
| 391 |
ck_assert_msg(res == 2, "Expected %d, got %d", 2, res); |
| 392 |
|
| 393 |
memset(&cmdtab, 0, sizeof(cmdtab)); |
| 394 |
cmdtab.command = pstrdup(p, "foo"); |
| 395 |
res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab); |
| 396 |
ck_assert_msg(res == 0, "Failed to add CMD symbol: %s", strerror(errno)); |
| 397 |
|
| 398 |
res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab); |
| 399 |
ck_assert_msg(res == 0, "Failed to add CMD symbol: %s", strerror(errno)); |
| 400 |
|
| 401 |
res = pr_stash_remove_symbol(PR_SYM_CMD, "foo", NULL); |
| 402 |
ck_assert_msg(res == 2, "Expected %d, got %d", 2, res); |
| 403 |
|
| 404 |
memset(&authtab, 0, sizeof(authtab)); |
| 405 |
authtab.name = pstrdup(p, "foo"); |
| 406 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 407 |
ck_assert_msg(res == 0, "Failed to add AUTH symbol: %s", strerror(errno)); |
| 408 |
|
| 409 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 410 |
ck_assert_msg(res == 0, "Failed to add AUTH symbol: %s", strerror(errno)); |
| 411 |
|
| 412 |
res = pr_stash_remove_symbol(PR_SYM_AUTH, "foo", NULL); |
| 413 |
ck_assert_msg(res == 2, "Expected %d, got %d", 2, res); |
| 414 |
|
| 415 |
memset(&hooktab, 0, sizeof(hooktab)); |
| 416 |
hooktab.command = pstrdup(p, "foo"); |
| 417 |
res = pr_stash_add_symbol(PR_SYM_HOOK, &hooktab); |
| 418 |
ck_assert_msg(res == 0, "Failed to add HOOK symbol: %s", strerror(errno)); |
| 419 |
|
| 420 |
res = pr_stash_add_symbol(PR_SYM_HOOK, &hooktab); |
| 421 |
ck_assert_msg(res == 0, "Failed to add HOOK symbol: %s", strerror(errno)); |
| 422 |
|
| 423 |
res = pr_stash_remove_symbol(PR_SYM_HOOK, "foo", NULL); |
| 424 |
ck_assert_msg(res == 2, "Expected %d, got %d", 2, res); |
| 425 |
} |
| 426 |
END_TEST |
| 427 |
|
| 428 |
START_TEST (stash_remove_conf_test) { |
| 429 |
int res; |
| 430 |
conftable conftab; |
| 431 |
|
| 432 |
res = pr_stash_remove_conf(NULL, NULL); |
| 433 |
ck_assert_msg(res == -1, "Failed to handle null arguments"); |
| 434 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 435 |
errno, strerror(errno)); |
| 436 |
|
| 437 |
res = pr_stash_remove_conf("foo", NULL); |
| 438 |
ck_assert_msg(res == 0, "Expected %d, got %d", 0, res); |
| 439 |
|
| 440 |
memset(&conftab, 0, sizeof(conftab)); |
| 441 |
conftab.directive = pstrdup(p, "foo"); |
| 442 |
res = pr_stash_add_symbol(PR_SYM_CONF, &conftab); |
| 443 |
ck_assert_msg(res == 0, "Failed to add CONF symbol: %s", strerror(errno)); |
| 444 |
|
| 445 |
res = pr_stash_add_symbol(PR_SYM_CONF, &conftab); |
| 446 |
ck_assert_msg(res == 0, "Failed to add CONF symbol: %s", strerror(errno)); |
| 447 |
|
| 448 |
res = pr_stash_remove_conf("foo", NULL); |
| 449 |
ck_assert_msg(res == 2, "Expected %d, got %d", 2, res); |
| 450 |
} |
| 451 |
END_TEST |
| 452 |
|
| 453 |
START_TEST (stash_remove_cmd_test) { |
| 454 |
int res; |
| 455 |
cmdtable cmdtab, cmdtab2; |
| 456 |
|
| 457 |
res = pr_stash_remove_cmd(NULL, NULL, 0, NULL, -1); |
| 458 |
ck_assert_msg(res == -1, "Failed to handle null arguments"); |
| 459 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 460 |
errno, strerror(errno)); |
| 461 |
|
| 462 |
res = pr_stash_remove_cmd("foo", NULL, 0, NULL, -1); |
| 463 |
ck_assert_msg(res == 0, "Expected %d, got %d", 0, res); |
| 464 |
|
| 465 |
memset(&cmdtab, 0, sizeof(cmdtab)); |
| 466 |
cmdtab.command = pstrdup(p, "foo"); |
| 467 |
res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab); |
| 468 |
ck_assert_msg(res == 0, "Failed to add CMD symbol: %s", strerror(errno)); |
| 469 |
|
| 470 |
memset(&cmdtab2, 0, sizeof(cmdtab2)); |
| 471 |
cmdtab2.command = pstrdup(p, "foo"); |
| 472 |
res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab2); |
| 473 |
ck_assert_msg(res == 0, "Failed to add CMD symbol: %s", strerror(errno)); |
| 474 |
|
| 475 |
res = pr_stash_remove_cmd("foo", NULL, 0, NULL, -1); |
| 476 |
ck_assert_msg(res == 2, "Expected %d, got %d", 2, res); |
| 477 |
|
| 478 |
|
| 479 |
mark_point(); |
| 480 |
memset(&cmdtab, 0, sizeof(cmdtab)); |
| 481 |
cmdtab.command = pstrdup(p, "foo"); |
| 482 |
cmdtab.cmd_type = PRE_CMD; |
| 483 |
res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab); |
| 484 |
ck_assert_msg(res == 0, "Failed to add CMD symbol: %s", strerror(errno)); |
| 485 |
|
| 486 |
memset(&cmdtab2, 0, sizeof(cmdtab2)); |
| 487 |
cmdtab2.command = pstrdup(p, "foo"); |
| 488 |
cmdtab2.cmd_type = CMD; |
| 489 |
res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab2); |
| 490 |
ck_assert_msg(res == 0, "Failed to add CMD symbol: %s", strerror(errno)); |
| 491 |
|
| 492 |
mark_point(); |
| 493 |
res = pr_stash_remove_cmd("foo", NULL, PRE_CMD, NULL, -1); |
| 494 |
ck_assert_msg(res == 1, "Expected %d, got %d", 1, res); |
| 495 |
(void) pr_stash_remove_symbol(PR_SYM_CMD, "foo", NULL); |
| 496 |
|
| 497 |
|
| 498 |
mark_point(); |
| 499 |
memset(&cmdtab, 0, sizeof(cmdtab)); |
| 500 |
cmdtab.command = pstrdup(p, "foo"); |
| 501 |
cmdtab.group = G_WRITE; |
| 502 |
res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab); |
| 503 |
ck_assert_msg(res == 0, "Failed to add CMD symbol: %s", strerror(errno)); |
| 504 |
|
| 505 |
memset(&cmdtab2, 0, sizeof(cmdtab2)); |
| 506 |
cmdtab2.command = pstrdup(p, "foo"); |
| 507 |
res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab2); |
| 508 |
ck_assert_msg(res == 0, "Failed to add CMD symbol: %s", strerror(errno)); |
| 509 |
|
| 510 |
mark_point(); |
| 511 |
res = pr_stash_remove_cmd("foo", NULL, 0, G_WRITE, -1); |
| 512 |
ck_assert_msg(res == 1, "Expected %d, got %d", 1, res); |
| 513 |
(void) pr_stash_remove_symbol(PR_SYM_CMD, "foo", NULL); |
| 514 |
|
| 515 |
|
| 516 |
mark_point(); |
| 517 |
memset(&cmdtab, 0, sizeof(cmdtab)); |
| 518 |
cmdtab.command = pstrdup(p, "foo"); |
| 519 |
cmdtab.cmd_class = CL_SFTP; |
| 520 |
res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab); |
| 521 |
ck_assert_msg(res == 0, "Failed to add CMD symbol: %s", strerror(errno)); |
| 522 |
|
| 523 |
memset(&cmdtab2, 0, sizeof(cmdtab2)); |
| 524 |
cmdtab2.command = pstrdup(p, "foo"); |
| 525 |
cmdtab2.cmd_class = CL_MISC; |
| 526 |
res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab2); |
| 527 |
ck_assert_msg(res == 0, "Failed to add CMD symbol: %s", strerror(errno)); |
| 528 |
|
| 529 |
mark_point(); |
| 530 |
res = pr_stash_remove_cmd("foo", NULL, 0, NULL, CL_SFTP); |
| 531 |
ck_assert_msg(res == 1, "Expected %d, got %d", 1, res); |
| 532 |
(void) pr_stash_remove_symbol(PR_SYM_CMD, "foo", NULL); |
| 533 |
} |
| 534 |
END_TEST |
| 535 |
|
| 536 |
START_TEST (stash_remove_auth_test) { |
| 537 |
int res; |
| 538 |
authtable authtab; |
| 539 |
|
| 540 |
res = pr_stash_remove_auth(NULL, NULL); |
| 541 |
ck_assert_msg(res == -1, "Failed to handle null arguments"); |
| 542 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 543 |
errno, strerror(errno)); |
| 544 |
|
| 545 |
res = pr_stash_remove_auth("foo", NULL); |
| 546 |
ck_assert_msg(res == 0, "Expected %d, got %d", 0, res); |
| 547 |
|
| 548 |
memset(&authtab, 0, sizeof(authtab)); |
| 549 |
authtab.name = pstrdup(p, "foo"); |
| 550 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 551 |
ck_assert_msg(res == 0, "Failed to add AUTH symbol: %s", strerror(errno)); |
| 552 |
|
| 553 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 554 |
ck_assert_msg(res == 0, "Failed to add AUTH symbol: %s", strerror(errno)); |
| 555 |
|
| 556 |
res = pr_stash_remove_auth("foo", NULL); |
| 557 |
ck_assert_msg(res == 2, "Expected %d, got %d", 2, res); |
| 558 |
} |
| 559 |
END_TEST |
| 560 |
|
| 561 |
START_TEST (stash_remove_hook_test) { |
| 562 |
int res; |
| 563 |
cmdtable hooktab; |
| 564 |
|
| 565 |
res = pr_stash_remove_hook(NULL, NULL); |
| 566 |
ck_assert_msg(res == -1, "Failed to handle null arguments"); |
| 567 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 568 |
errno, strerror(errno)); |
| 569 |
|
| 570 |
res = pr_stash_remove_hook("foo", NULL); |
| 571 |
ck_assert_msg(res == 0, "Expected %d, got %d", 0, res); |
| 572 |
|
| 573 |
memset(&hooktab, 0, sizeof(hooktab)); |
| 574 |
hooktab.command = pstrdup(p, "foo"); |
| 575 |
res = pr_stash_add_symbol(PR_SYM_HOOK, &hooktab); |
| 576 |
ck_assert_msg(res == 0, "Failed to add HOOK symbol: %s", strerror(errno)); |
| 577 |
|
| 578 |
res = pr_stash_add_symbol(PR_SYM_HOOK, &hooktab); |
| 579 |
ck_assert_msg(res == 0, "Failed to add HOOK symbol: %s", strerror(errno)); |
| 580 |
|
| 581 |
res = pr_stash_remove_hook("foo", NULL); |
| 582 |
ck_assert_msg(res == 2, "Expected %d, got %d", 2, res); |
| 583 |
} |
| 584 |
END_TEST |
| 585 |
|
| 586 |
Suite *tests_get_stash_suite(void) { |
| 587 |
Suite *suite; |
| 588 |
TCase *testcase; |
| 589 |
|
| 590 |
suite = suite_create("stash"); |
| 591 |
testcase = tcase_create("stash"); |
| 592 |
|
| 593 |
tcase_add_checked_fixture(testcase, set_up, tear_down); |
| 594 |
|
| 595 |
tcase_add_test(testcase, stash_add_symbol_test); |
| 596 |
tcase_add_test(testcase, stash_get_symbol_test); |
| 597 |
tcase_add_test(testcase, stash_get_symbol2_test); |
| 598 |
tcase_add_test(testcase, stash_remove_symbol_test); |
| 599 |
#ifdef PR_USE_DEVEL |
| 600 |
tcase_add_test(testcase, stash_dump_test); |
| 601 |
#endif |
| 602 |
|
| 603 |
tcase_add_test(testcase, stash_remove_conf_test); |
| 604 |
tcase_add_test(testcase, stash_remove_cmd_test); |
| 605 |
tcase_add_test(testcase, stash_remove_auth_test); |
| 606 |
tcase_add_test(testcase, stash_remove_hook_test); |
| 607 |
|
| 608 |
suite_add_tcase(suite, testcase); |
| 609 |
return suite; |
| 610 |
} |