| 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_config(); |
| 37 |
pr_parser_prepare(p, NULL); |
| 38 |
|
| 39 |
if (getenv("TEST_VERBOSE") != NULL) { |
| 40 |
pr_trace_set_levels("config", 1, 20); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
static void tear_down(void) { |
| 45 |
if (getenv("TEST_VERBOSE") != NULL) { |
| 46 |
pr_trace_set_levels("config", 0, 0); |
| 47 |
} |
| 48 |
|
| 49 |
pr_parser_cleanup(); |
| 50 |
|
| 51 |
if (p) { |
| 52 |
destroy_pool(p); |
| 53 |
p = permanent_pool = NULL; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
START_TEST (config_init_config_test) { |
| 58 |
mark_point(); |
| 59 |
init_config(); |
| 60 |
|
| 61 |
mark_point(); |
| 62 |
init_config(); |
| 63 |
|
| 64 |
mark_point(); |
| 65 |
init_config(); |
| 66 |
} |
| 67 |
END_TEST |
| 68 |
|
| 69 |
START_TEST (config_alloc_test) { |
| 70 |
config_rec *c; |
| 71 |
int config_type = CONF_PARAM; |
| 72 |
|
| 73 |
mark_point(); |
| 74 |
c = pr_config_alloc(NULL, NULL, 0); |
| 75 |
ck_assert_msg(c == NULL, "Failed to handle null pool"); |
| 76 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 77 |
strerror(errno), errno); |
| 78 |
|
| 79 |
mark_point(); |
| 80 |
c = pr_config_alloc(p, NULL, config_type); |
| 81 |
ck_assert_msg(c != NULL, "Failed to handle null argument: %s", strerror(errno)); |
| 82 |
ck_assert_msg(c->name == NULL, "Failed to handle null name"); |
| 83 |
ck_assert_msg(c->config_type == config_type, "Failed to set config type"); |
| 84 |
|
| 85 |
mark_point(); |
| 86 |
c = pr_config_alloc(p, "foobar", config_type); |
| 87 |
ck_assert_msg(c != NULL, "Failed to allocate config_rec: %s", strerror(errno)); |
| 88 |
ck_assert_msg(c->name != NULL, "Failed to handle name"); |
| 89 |
ck_assert_msg(c->config_type == config_type, "Failed to set config type"); |
| 90 |
} |
| 91 |
END_TEST |
| 92 |
|
| 93 |
START_TEST (config_add_config_to_set_test) { |
| 94 |
xaset_t *set; |
| 95 |
config_rec *c; |
| 96 |
|
| 97 |
mark_point(); |
| 98 |
c = pr_config_add_config_to_set(NULL, NULL, 0); |
| 99 |
ck_assert_msg(c == NULL, "Failed to handle null set"); |
| 100 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 101 |
strerror(errno), errno); |
| 102 |
|
| 103 |
mark_point(); |
| 104 |
set = xaset_create(p, NULL); |
| 105 |
c = pr_config_add_config_to_set(set, NULL, 0); |
| 106 |
ck_assert_msg(c == NULL, "Failed to handle null set"); |
| 107 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 108 |
strerror(errno), errno); |
| 109 |
|
| 110 |
mark_point(); |
| 111 |
c = pr_config_alloc(p, "foobar", 0); |
| 112 |
c = pr_config_add_config_to_set(set, c, 0); |
| 113 |
ck_assert_msg(c != NULL, "Failed to add config to set: %s", strerror(errno)); |
| 114 |
} |
| 115 |
END_TEST |
| 116 |
|
| 117 |
START_TEST (config_add_config_test) { |
| 118 |
int res; |
| 119 |
const char *name = NULL; |
| 120 |
config_rec *c = NULL; |
| 121 |
server_rec *s = NULL; |
| 122 |
|
| 123 |
s = pr_parser_server_ctxt_open("127.0.0.1"); |
| 124 |
ck_assert_msg(s != NULL, "Failed to open server context: %s", strerror(errno)); |
| 125 |
|
| 126 |
name = "foo"; |
| 127 |
|
| 128 |
mark_point(); |
| 129 |
c = add_config(NULL, name); |
| 130 |
ck_assert_msg(c != NULL, "Failed to add config '%s': %s", name, |
| 131 |
strerror(errno)); |
| 132 |
ck_assert_msg(c->config_type == 0, "Expected config_type 0, got %d", |
| 133 |
c->config_type); |
| 134 |
|
| 135 |
mark_point(); |
| 136 |
pr_config_dump(NULL, s->conf, NULL); |
| 137 |
|
| 138 |
c = add_config_param_set(&(c->subset), "bar", 1, "baz"); |
| 139 |
|
| 140 |
mark_point(); |
| 141 |
pr_config_dump(NULL, s->conf, NULL); |
| 142 |
|
| 143 |
mark_point(); |
| 144 |
res = remove_config(s->conf, name, FALSE); |
| 145 |
ck_assert_msg(res > 0, "Failed to remove config '%s': %s", name, |
| 146 |
strerror(errno)); |
| 147 |
} |
| 148 |
END_TEST |
| 149 |
|
| 150 |
START_TEST (config_add_config_param_test) { |
| 151 |
int res; |
| 152 |
const char *name = NULL; |
| 153 |
config_rec *c = NULL; |
| 154 |
server_rec *s = NULL; |
| 155 |
|
| 156 |
s = pr_parser_server_ctxt_open("127.0.0.1"); |
| 157 |
ck_assert_msg(s != NULL, "Failed to open server context: %s", |
| 158 |
strerror(errno)); |
| 159 |
|
| 160 |
c = add_config_param(NULL, 0, NULL); |
| 161 |
ck_assert_msg(c == NULL, "Failed to handle null arguments"); |
| 162 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 163 |
strerror(errno), errno); |
| 164 |
|
| 165 |
name = "foo"; |
| 166 |
|
| 167 |
mark_point(); |
| 168 |
c = add_config_param(name, 1, "bar"); |
| 169 |
ck_assert_msg(c != NULL, "Failed to add config '%s': %s", name, |
| 170 |
strerror(errno)); |
| 171 |
ck_assert_msg(c->config_type == CONF_PARAM, "Expected config_type %d, got %d", |
| 172 |
CONF_PARAM, c->config_type); |
| 173 |
|
| 174 |
mark_point(); |
| 175 |
pr_config_dump(NULL, s->conf, NULL); |
| 176 |
|
| 177 |
mark_point(); |
| 178 |
res = pr_config_remove(s->conf, name, PR_CONFIG_FL_PRESERVE_ENTRY, FALSE); |
| 179 |
ck_assert_msg(res > 0, "Failed to remove config '%s': %s", name, |
| 180 |
strerror(errno)); |
| 181 |
} |
| 182 |
END_TEST |
| 183 |
|
| 184 |
START_TEST (config_add_config_param_set_test) { |
| 185 |
xaset_t *set = NULL; |
| 186 |
const char *name = NULL; |
| 187 |
config_rec *c = NULL; |
| 188 |
|
| 189 |
name = "foo"; |
| 190 |
|
| 191 |
c = add_config_param_set(NULL, name, 0); |
| 192 |
ck_assert_msg(c == NULL, "Failed to handle null set argument"); |
| 193 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 194 |
errno, strerror(errno)); |
| 195 |
|
| 196 |
c = add_config_param_set(&set, name, 0); |
| 197 |
ck_assert_msg(c != NULL, "Failed to add config '%s' to set: %s", name, |
| 198 |
strerror(errno)); |
| 199 |
ck_assert_msg(c->config_type == CONF_PARAM, "Expected config_type %d, got %d", |
| 200 |
CONF_PARAM, c->config_type); |
| 201 |
ck_assert_msg(c->argc == 0, "Expected argc 0, got %d", c->argc); |
| 202 |
|
| 203 |
c = add_config_param_set(&set, name, 2, "bar", "baz"); |
| 204 |
ck_assert_msg(c != NULL, "Failed to add config '%s' to set: %s", name, |
| 205 |
strerror(errno)); |
| 206 |
ck_assert_msg(c->config_type == CONF_PARAM, "Expected config_type %d, got %d", |
| 207 |
CONF_PARAM, c->config_type); |
| 208 |
ck_assert_msg(c->argc == 2, "Expected argc 2, got %d", c->argc); |
| 209 |
ck_assert_msg(strcmp("bar", (char *) c->argv[0]) == 0, |
| 210 |
"Expected argv[0] to be 'bar', got '%s'", (char *) c->argv[0]); |
| 211 |
ck_assert_msg(strcmp("baz", (char *) c->argv[1]) == 0, |
| 212 |
"Expected argv[1] to be 'baz', got '%s'", (char *) c->argv[1]); |
| 213 |
ck_assert_msg(c->argv[2] == NULL, "Expected argv[2] to be null"); |
| 214 |
} |
| 215 |
END_TEST |
| 216 |
|
| 217 |
START_TEST (config_add_config_param_str_test) { |
| 218 |
int res; |
| 219 |
const char *name = NULL; |
| 220 |
config_rec *c = NULL, *c2; |
| 221 |
server_rec *s = NULL; |
| 222 |
|
| 223 |
s = pr_parser_server_ctxt_open("127.0.0.1"); |
| 224 |
ck_assert_msg(s != NULL, "Failed to open server context: %s", strerror(errno)); |
| 225 |
|
| 226 |
name = "foo"; |
| 227 |
|
| 228 |
mark_point(); |
| 229 |
c = add_config_param_str(name, 1, "bar"); |
| 230 |
ck_assert_msg(c != NULL, "Failed to add config '%s': %s", name, |
| 231 |
strerror(errno)); |
| 232 |
ck_assert_msg(c->config_type == CONF_PARAM, "Expected config_type %d, got %d", |
| 233 |
CONF_PARAM, c->config_type); |
| 234 |
|
| 235 |
c2 = add_config_param_str("foo2", 1, NULL); |
| 236 |
ck_assert_msg(c2 != NULL, "Failed to add config 'foo2': %s", strerror(errno)); |
| 237 |
|
| 238 |
mark_point(); |
| 239 |
pr_config_dump(NULL, s->conf, NULL); |
| 240 |
|
| 241 |
mark_point(); |
| 242 |
res = remove_config(s->conf, name, FALSE); |
| 243 |
ck_assert_msg(res > 0, "Failed to remove config '%s': %s", name, |
| 244 |
strerror(errno)); |
| 245 |
} |
| 246 |
END_TEST |
| 247 |
|
| 248 |
START_TEST (config_add_server_config_param_str_test) { |
| 249 |
const char *name; |
| 250 |
config_rec *c; |
| 251 |
server_rec *s; |
| 252 |
|
| 253 |
mark_point(); |
| 254 |
c = pr_conf_add_server_config_param_str(NULL, NULL, 0); |
| 255 |
ck_assert_msg(c == NULL, "Failed to handle null arguments"); |
| 256 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 257 |
strerror(errno), errno); |
| 258 |
|
| 259 |
mark_point(); |
| 260 |
s = pr_parser_server_ctxt_open("127.0.0.2"); |
| 261 |
ck_assert_msg(s != NULL, "Failed to open server context: %s", strerror(errno)); |
| 262 |
|
| 263 |
mark_point(); |
| 264 |
name = "foo"; |
| 265 |
|
| 266 |
c = pr_conf_add_server_config_param_str(s, name, 1, "bar"); |
| 267 |
ck_assert_msg(c != NULL, "Failed to add config '%s': %s", name, |
| 268 |
strerror(errno)); |
| 269 |
|
| 270 |
(void) remove_config(s->conf, name, FALSE); |
| 271 |
} |
| 272 |
END_TEST |
| 273 |
|
| 274 |
START_TEST (config_add_config_set_test) { |
| 275 |
int flags = PR_CONFIG_FL_INSERT_HEAD, res; |
| 276 |
xaset_t *set = NULL; |
| 277 |
const char *name = NULL; |
| 278 |
config_rec *c = NULL; |
| 279 |
|
| 280 |
res = remove_config(NULL, NULL, FALSE); |
| 281 |
ck_assert_msg(res == 0, "Failed to handle null arguments: %s", strerror(errno)); |
| 282 |
|
| 283 |
name = "foo"; |
| 284 |
|
| 285 |
c = add_config_set(NULL, name); |
| 286 |
ck_assert_msg(c == NULL, "Failed to handle null set argument"); |
| 287 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 288 |
errno, strerror(errno)); |
| 289 |
|
| 290 |
c = add_config_set(&set, name); |
| 291 |
ck_assert_msg(c != NULL, "Failed to add config '%s' to set: %s", name, |
| 292 |
strerror(errno)); |
| 293 |
ck_assert_msg(c->config_type == 0, "Expected config_type 0, got %d", |
| 294 |
c->config_type); |
| 295 |
|
| 296 |
res = remove_config(set, name, FALSE); |
| 297 |
ck_assert_msg(res > 0, "Failed to remove config '%s': %s", name, |
| 298 |
strerror(errno)); |
| 299 |
|
| 300 |
name = "bar"; |
| 301 |
res = remove_config(set, name, FALSE); |
| 302 |
ck_assert_msg(res == 0, "Removed config '%s' unexpectedly: %s", name, |
| 303 |
strerror(errno)); |
| 304 |
|
| 305 |
c = pr_config_add_set(&set, name, flags); |
| 306 |
ck_assert_msg(c != NULL, "Failed to add config '%s' to set: %s", name, |
| 307 |
strerror(errno)); |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
res = remove_config(set, name, FALSE); |
| 320 |
ck_assert_msg(res > 0, "Failed to remove config '%s': %s", name, |
| 321 |
strerror(errno)); |
| 322 |
} |
| 323 |
END_TEST |
| 324 |
|
| 325 |
START_TEST (config_dump_test) { |
| 326 |
mark_point(); |
| 327 |
pr_config_dump(NULL, NULL, NULL); |
| 328 |
} |
| 329 |
END_TEST |
| 330 |
|
| 331 |
START_TEST (config_find_config_test) { |
| 332 |
int res; |
| 333 |
config_rec *c; |
| 334 |
xaset_t *set = NULL; |
| 335 |
const char *name; |
| 336 |
|
| 337 |
c = find_config(NULL, -1, NULL, FALSE); |
| 338 |
ck_assert_msg(c == NULL, "Failed to handle null arguments"); |
| 339 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 340 |
strerror(errno), errno); |
| 341 |
|
| 342 |
c = find_config_next(NULL, NULL, CONF_PARAM, NULL, FALSE); |
| 343 |
ck_assert_msg(c == NULL, "Failed to handle null arguments"); |
| 344 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 345 |
strerror(errno), errno); |
| 346 |
|
| 347 |
mark_point(); |
| 348 |
|
| 349 |
name = "foo"; |
| 350 |
c = add_config_param_set(&set, name, 0); |
| 351 |
ck_assert_msg(c != NULL, "Failed to add config '%s': %s", name, |
| 352 |
strerror(errno)); |
| 353 |
|
| 354 |
name = "bar"; |
| 355 |
c = find_config(set, -1, name, FALSE); |
| 356 |
ck_assert_msg(c == NULL, "Failed to handle null arguments"); |
| 357 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 358 |
errno, strerror(errno)); |
| 359 |
|
| 360 |
mark_point(); |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
name = "foo"; |
| 365 |
c = find_config(set, -1, name, FALSE); |
| 366 |
ck_assert_msg(c != NULL, "Failed to find config '%s': %s", name, |
| 367 |
strerror(errno)); |
| 368 |
|
| 369 |
mark_point(); |
| 370 |
|
| 371 |
c = find_config_next(c, c->next, -1, name, FALSE); |
| 372 |
ck_assert_msg(c == NULL, "Found next config unexpectedly"); |
| 373 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 374 |
errno, strerror(errno)); |
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
name = "foo2"; |
| 381 |
c = add_config_param_set(&set, name, 0); |
| 382 |
ck_assert_msg(c != NULL, "Failed to add config '%s': %s", name, |
| 383 |
strerror(errno)); |
| 384 |
|
| 385 |
name = NULL; |
| 386 |
c = find_config(set, -1, name, FALSE); |
| 387 |
ck_assert_msg(c != NULL, "Failed to find any config: %s", strerror(errno)); |
| 388 |
|
| 389 |
mark_point(); |
| 390 |
|
| 391 |
c = find_config_next(c, c->next, -1, name, FALSE); |
| 392 |
ck_assert_msg(c != NULL, "Expected to find another config"); |
| 393 |
|
| 394 |
mark_point(); |
| 395 |
|
| 396 |
name = "foo"; |
| 397 |
res = remove_config(set, name, FALSE); |
| 398 |
ck_assert_msg(res > 0, "Failed to remove config '%s': %s", name, |
| 399 |
strerror(errno)); |
| 400 |
|
| 401 |
mark_point(); |
| 402 |
|
| 403 |
c = find_config(set, -1, name, FALSE); |
| 404 |
ck_assert_msg(c == NULL, "Found config '%s' unexpectedly", name); |
| 405 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 406 |
errno, strerror(errno)); |
| 407 |
|
| 408 |
name = "other"; |
| 409 |
c = find_config(set, -1, name, TRUE); |
| 410 |
ck_assert_msg(c == NULL, "Found config '%s' unexpectedly (recurse = true)", |
| 411 |
name); |
| 412 |
ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT, |
| 413 |
strerror(errno), errno); |
| 414 |
} |
| 415 |
END_TEST |
| 416 |
|
| 417 |
START_TEST (config_find_config2_test) { |
| 418 |
int res; |
| 419 |
config_rec *c; |
| 420 |
xaset_t *set = NULL; |
| 421 |
const char *name; |
| 422 |
unsigned long flags = 0; |
| 423 |
|
| 424 |
c = find_config2(NULL, -1, NULL, FALSE, flags); |
| 425 |
ck_assert_msg(c == NULL, "Failed to handle null arguments"); |
| 426 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 427 |
errno, strerror(errno)); |
| 428 |
|
| 429 |
mark_point(); |
| 430 |
|
| 431 |
name = "foo"; |
| 432 |
c = add_config_param_set(&set, name, 0); |
| 433 |
ck_assert_msg(c != NULL, "Failed to add config '%s': %s", name, |
| 434 |
strerror(errno)); |
| 435 |
|
| 436 |
name = "bar"; |
| 437 |
c = find_config2(set, -1, name, FALSE, flags); |
| 438 |
ck_assert_msg(c == NULL, "Failed to handle null arguments"); |
| 439 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 440 |
errno, strerror(errno)); |
| 441 |
|
| 442 |
mark_point(); |
| 443 |
|
| 444 |
|
| 445 |
name = "foo"; |
| 446 |
c = find_config2(set, -1, name, FALSE, flags); |
| 447 |
ck_assert_msg(c != NULL, "Failed to find config '%s': %s", name, |
| 448 |
strerror(errno)); |
| 449 |
|
| 450 |
mark_point(); |
| 451 |
|
| 452 |
c = find_config_next2(c, c->next, -1, name, FALSE, flags); |
| 453 |
ck_assert_msg(c == NULL, "Found next config unexpectedly"); |
| 454 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 455 |
errno, strerror(errno)); |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
name = "foo2"; |
| 462 |
c = add_config_param_set(&set, name, 0); |
| 463 |
ck_assert_msg(c != NULL, "Failed to add config '%s': %s", name, |
| 464 |
strerror(errno)); |
| 465 |
|
| 466 |
name = NULL; |
| 467 |
c = find_config2(set, -1, name, FALSE, flags); |
| 468 |
ck_assert_msg(c != NULL, "Failed to find any config: %s", strerror(errno)); |
| 469 |
|
| 470 |
mark_point(); |
| 471 |
|
| 472 |
c = find_config_next2(c, c->next, -1, name, FALSE, flags); |
| 473 |
ck_assert_msg(c != NULL, "Expected to find another config"); |
| 474 |
|
| 475 |
mark_point(); |
| 476 |
|
| 477 |
name = "foo"; |
| 478 |
res = remove_config(set, name, FALSE); |
| 479 |
ck_assert_msg(res > 0, "Failed to remove config '%s': %s", name, |
| 480 |
strerror(errno)); |
| 481 |
|
| 482 |
mark_point(); |
| 483 |
|
| 484 |
c = find_config2(set, -1, name, FALSE, flags); |
| 485 |
ck_assert_msg(c == NULL, "Found config '%s' unexpectedly", name); |
| 486 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 487 |
errno, strerror(errno)); |
| 488 |
} |
| 489 |
END_TEST |
| 490 |
|
| 491 |
START_TEST (config_find_config2_recurse_test) { |
| 492 |
int res; |
| 493 |
config_rec *c; |
| 494 |
xaset_t *set = NULL; |
| 495 |
const char *name; |
| 496 |
unsigned long flags = 0; |
| 497 |
|
| 498 |
c = find_config2(NULL, -1, NULL, TRUE, flags); |
| 499 |
ck_assert_msg(c == NULL, "Failed to handle null arguments"); |
| 500 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 501 |
errno, strerror(errno)); |
| 502 |
|
| 503 |
mark_point(); |
| 504 |
|
| 505 |
name = "foo"; |
| 506 |
c = add_config_param_set(&set, name, 0); |
| 507 |
ck_assert_msg(c != NULL, "Failed to add config '%s': %s", name, |
| 508 |
strerror(errno)); |
| 509 |
|
| 510 |
name = "bar"; |
| 511 |
c = find_config2(set, -1, name, TRUE, flags); |
| 512 |
ck_assert_msg(c == NULL, "Failed to handle null arguments"); |
| 513 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 514 |
errno, strerror(errno)); |
| 515 |
|
| 516 |
mark_point(); |
| 517 |
|
| 518 |
|
| 519 |
name = "foo"; |
| 520 |
c = find_config2(set, -1, name, TRUE, flags); |
| 521 |
ck_assert_msg(c != NULL, "Failed to find config '%s': %s", name, |
| 522 |
strerror(errno)); |
| 523 |
|
| 524 |
mark_point(); |
| 525 |
|
| 526 |
c = find_config_next2(c, c->next, -1, name, TRUE, flags); |
| 527 |
ck_assert_msg(c == NULL, "Found next config unexpectedly"); |
| 528 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 529 |
errno, strerror(errno)); |
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
name = "foo2"; |
| 536 |
c = add_config_param_set(&set, name, 0); |
| 537 |
ck_assert_msg(c != NULL, "Failed to add config '%s': %s", name, |
| 538 |
strerror(errno)); |
| 539 |
|
| 540 |
name = NULL; |
| 541 |
c = find_config2(set, -1, name, TRUE, flags); |
| 542 |
ck_assert_msg(c != NULL, "Failed to find any config: %s", strerror(errno)); |
| 543 |
|
| 544 |
mark_point(); |
| 545 |
|
| 546 |
c = find_config_next2(c, c->next, -1, name, TRUE, flags); |
| 547 |
ck_assert_msg(c != NULL, "Expected to find another config"); |
| 548 |
|
| 549 |
mark_point(); |
| 550 |
|
| 551 |
name = "foo"; |
| 552 |
res = remove_config(set, name, FALSE); |
| 553 |
ck_assert_msg(res > 0, "Failed to remove config '%s': %s", name, |
| 554 |
strerror(errno)); |
| 555 |
|
| 556 |
mark_point(); |
| 557 |
|
| 558 |
c = find_config2(set, -1, name, TRUE, flags); |
| 559 |
ck_assert_msg(c == NULL, "Found config '%s' unexpectedly", name); |
| 560 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 561 |
errno, strerror(errno)); |
| 562 |
} |
| 563 |
END_TEST |
| 564 |
|
| 565 |
START_TEST (config_find_config_set_top_test) { |
| 566 |
config_rec *c; |
| 567 |
|
| 568 |
mark_point(); |
| 569 |
c = pcalloc(p, sizeof(config_rec)); |
| 570 |
c->parent = pcalloc(p, sizeof(config_rec)); |
| 571 |
find_config_set_top(c); |
| 572 |
|
| 573 |
mark_point(); |
| 574 |
find_config_set_top(NULL); |
| 575 |
} |
| 576 |
END_TEST |
| 577 |
|
| 578 |
START_TEST (config_get_param_ptr_test) { |
| 579 |
void *res; |
| 580 |
int count; |
| 581 |
xaset_t *set = NULL; |
| 582 |
config_rec *c; |
| 583 |
const char *name = NULL; |
| 584 |
|
| 585 |
res = get_param_ptr(NULL, NULL, FALSE); |
| 586 |
ck_assert_msg(res == NULL, "Failed to handle null arguments"); |
| 587 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 588 |
errno, strerror(errno)); |
| 589 |
|
| 590 |
mark_point(); |
| 591 |
|
| 592 |
name = "foo"; |
| 593 |
c = add_config_param_set(&set, name, 1, "bar"); |
| 594 |
ck_assert_msg(c != NULL, "Failed to add config '%s': %s", name, |
| 595 |
strerror(errno)); |
| 596 |
|
| 597 |
name = "bar"; |
| 598 |
res = get_param_ptr(set, name, FALSE); |
| 599 |
ck_assert_msg(res == NULL, "Failed to handle null arguments"); |
| 600 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 601 |
errno, strerror(errno)); |
| 602 |
|
| 603 |
mark_point(); |
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
get_param_ptr(NULL, NULL, FALSE); |
| 609 |
|
| 610 |
name = "foo"; |
| 611 |
res = get_param_ptr(set, name, FALSE); |
| 612 |
ck_assert_msg(res != NULL, "Failed to find config '%s': %s", name, |
| 613 |
strerror(errno)); |
| 614 |
|
| 615 |
mark_point(); |
| 616 |
|
| 617 |
res = get_param_ptr_next(name, FALSE); |
| 618 |
ck_assert_msg(res == NULL, "Found next config unexpectedly"); |
| 619 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 620 |
errno, strerror(errno)); |
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
name = "foo2"; |
| 627 |
c = add_config_param_set(&set, name, 1, "baz"); |
| 628 |
ck_assert_msg(c != NULL, "Failed to add config '%s': %s", name, |
| 629 |
strerror(errno)); |
| 630 |
|
| 631 |
get_param_ptr(NULL, NULL, FALSE); |
| 632 |
|
| 633 |
name = NULL; |
| 634 |
res = get_param_ptr(set, name, FALSE); |
| 635 |
ck_assert_msg(res != NULL, "Failed to find any config: %s", strerror(errno)); |
| 636 |
|
| 637 |
mark_point(); |
| 638 |
res = get_param_ptr_next(name, FALSE); |
| 639 |
ck_assert_msg(res != NULL, "Expected to find another config"); |
| 640 |
|
| 641 |
mark_point(); |
| 642 |
res = get_param_ptr_next("foobar", TRUE); |
| 643 |
ck_assert_msg(res == NULL, "Found another config unexpectedly"); |
| 644 |
ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT, |
| 645 |
strerror(errno), errno); |
| 646 |
|
| 647 |
res = get_param_ptr_next(name, FALSE); |
| 648 |
ck_assert_msg(res == NULL, "Found another config unexpectedly"); |
| 649 |
ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT, |
| 650 |
strerror(errno), errno); |
| 651 |
|
| 652 |
mark_point(); |
| 653 |
|
| 654 |
name = "foo"; |
| 655 |
count = remove_config(set, name, FALSE); |
| 656 |
ck_assert_msg(count > 0, "Failed to remove config '%s': %s", name, |
| 657 |
strerror(errno)); |
| 658 |
|
| 659 |
mark_point(); |
| 660 |
res = get_param_ptr(set, name, FALSE); |
| 661 |
ck_assert_msg(res == NULL, "Found config '%s' unexpectedly", name); |
| 662 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 663 |
errno, strerror(errno)); |
| 664 |
} |
| 665 |
END_TEST |
| 666 |
|
| 667 |
START_TEST (config_set_get_id_test) { |
| 668 |
unsigned int id, res; |
| 669 |
const char *name; |
| 670 |
|
| 671 |
res = pr_config_get_id(NULL); |
| 672 |
ck_assert_msg(res == 0, "Failed to handle null argument"); |
| 673 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 674 |
errno, strerror(errno)); |
| 675 |
|
| 676 |
res = pr_config_set_id(NULL); |
| 677 |
ck_assert_msg(res == 0, "Failed to handle null argument"); |
| 678 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 679 |
errno, strerror(errno)); |
| 680 |
|
| 681 |
name = "foo"; |
| 682 |
|
| 683 |
id = pr_config_set_id(name); |
| 684 |
ck_assert_msg(id > 0, "Failed to set ID for config '%s': %s", name, |
| 685 |
strerror(errno)); |
| 686 |
|
| 687 |
res = pr_config_get_id(name); |
| 688 |
ck_assert_msg(res == id, "Expected ID %u for config '%s', found %u", id, |
| 689 |
name, res); |
| 690 |
} |
| 691 |
END_TEST |
| 692 |
|
| 693 |
START_TEST (config_merge_down_test) { |
| 694 |
xaset_t *set; |
| 695 |
config_rec *c, *src, *dst; |
| 696 |
const char *name; |
| 697 |
|
| 698 |
mark_point(); |
| 699 |
pr_config_merge_down(NULL, FALSE); |
| 700 |
|
| 701 |
mark_point(); |
| 702 |
set = xaset_create(p, NULL); |
| 703 |
pr_config_merge_down(set, FALSE); |
| 704 |
|
| 705 |
name = "foo"; |
| 706 |
c = add_config_param_set(&set, name, 0); |
| 707 |
|
| 708 |
mark_point(); |
| 709 |
pr_config_merge_down(set, FALSE); |
| 710 |
|
| 711 |
name = "bar"; |
| 712 |
c = add_config_param_set(&set, name, 1, "baz"); |
| 713 |
c->flags |= CF_MERGEDOWN; |
| 714 |
|
| 715 |
mark_point(); |
| 716 |
pr_config_merge_down(set, FALSE); |
| 717 |
|
| 718 |
name = "BAZ"; |
| 719 |
c = add_config_param_set(&set, name, 2, "quxx", "Quzz"); |
| 720 |
c->flags |= CF_MERGEDOWN_MULTI; |
| 721 |
|
| 722 |
mark_point(); |
| 723 |
pr_config_merge_down(set, FALSE); |
| 724 |
|
| 725 |
|
| 726 |
name = "<Anonymous>"; |
| 727 |
src = add_config_param_set(&set, name, 0); |
| 728 |
src->config_type = CONF_ANON; |
| 729 |
|
| 730 |
mark_point(); |
| 731 |
pr_config_merge_down(set, FALSE); |
| 732 |
|
| 733 |
name = "<Directory>"; |
| 734 |
dst = add_config_param_set(&set, name, 1, "/baz"); |
| 735 |
dst->config_type = CONF_DIR; |
| 736 |
|
| 737 |
name = "foo"; |
| 738 |
c = add_config_param_set(&(src->subset), name, 1, "alef"); |
| 739 |
c->flags |= CF_MERGEDOWN; |
| 740 |
|
| 741 |
c = add_config_param_set(&(dst->subset), name, 1, "alef"); |
| 742 |
c->flags |= CF_MERGEDOWN; |
| 743 |
|
| 744 |
mark_point(); |
| 745 |
pr_config_merge_down(set, FALSE); |
| 746 |
|
| 747 |
|
| 748 |
name = "alef"; |
| 749 |
c = add_config_param_set(&(src->subset), name, 1, "alef"); |
| 750 |
c->flags |= CF_MERGEDOWN; |
| 751 |
|
| 752 |
c = add_config_param_set(&(dst->subset), name, 2, "bet", "vet"); |
| 753 |
c->flags |= CF_MERGEDOWN; |
| 754 |
|
| 755 |
c = add_config_param_set(&(src->subset), "Bet", 3, "1", "2", "3"); |
| 756 |
c->config_type = CONF_LIMIT; |
| 757 |
c->flags |= CF_MERGEDOWN; |
| 758 |
|
| 759 |
mark_point(); |
| 760 |
pr_config_merge_down(set, FALSE); |
| 761 |
} |
| 762 |
END_TEST |
| 763 |
|
| 764 |
Suite *tests_get_config_suite(void) { |
| 765 |
Suite *suite; |
| 766 |
TCase *testcase; |
| 767 |
|
| 768 |
suite = suite_create("config"); |
| 769 |
|
| 770 |
testcase = tcase_create("base"); |
| 771 |
tcase_add_checked_fixture(testcase, set_up, tear_down); |
| 772 |
|
| 773 |
tcase_add_test(testcase, config_init_config_test); |
| 774 |
tcase_add_test(testcase, config_alloc_test); |
| 775 |
tcase_add_test(testcase, config_add_config_to_set_test); |
| 776 |
tcase_add_test(testcase, config_add_config_test); |
| 777 |
tcase_add_test(testcase, config_add_config_param_test); |
| 778 |
tcase_add_test(testcase, config_add_config_param_set_test); |
| 779 |
tcase_add_test(testcase, config_add_config_param_str_test); |
| 780 |
tcase_add_test(testcase, config_add_server_config_param_str_test); |
| 781 |
tcase_add_test(testcase, config_add_config_set_test); |
| 782 |
tcase_add_test(testcase, config_dump_test); |
| 783 |
tcase_add_test(testcase, config_find_config_test); |
| 784 |
tcase_add_test(testcase, config_find_config2_test); |
| 785 |
tcase_add_test(testcase, config_find_config2_recurse_test); |
| 786 |
tcase_add_test(testcase, config_find_config_set_top_test); |
| 787 |
tcase_add_test(testcase, config_get_param_ptr_test); |
| 788 |
tcase_add_test(testcase, config_set_get_id_test); |
| 789 |
tcase_add_test(testcase, config_merge_down_test); |
| 790 |
|
| 791 |
suite_add_tcase(suite, testcase); |
| 792 |
return suite; |
| 793 |
} |