|
26 | 26 | "\0\0\0\0\0\0\0\0" /* 56 - 63 */ \
|
27 | 27 | ""
|
28 | 28 |
|
29 |
| -// FIXME: test for unterminated string here too!!!! |
| 29 | +// FIXME: test for unterminated string here too! |
30 | 30 |
|
31 | 31 | struct newline_test {
|
32 | 32 | const char *input;
|
@@ -395,3 +395,79 @@ void names(void **state)
|
395 | 395 | assert_int_equal(code, tests[i].code);
|
396 | 396 | }
|
397 | 397 | }
|
| 398 | + |
| 399 | +struct ttls_test { |
| 400 | + const char *text; |
| 401 | + bool non_strict; |
| 402 | + bool pretty_ttls; |
| 403 | + int32_t code; |
| 404 | + uint32_t ttl; |
| 405 | +}; |
| 406 | + |
| 407 | +static int32_t tests_callback( |
| 408 | + zone_parser_t *parser, |
| 409 | + const zone_name_t *owner, |
| 410 | + uint16_t type, |
| 411 | + uint16_t class, |
| 412 | + uint32_t ttl, |
| 413 | + uint16_t rdlength, |
| 414 | + const uint8_t *rdata, |
| 415 | + void *user_data) |
| 416 | +{ |
| 417 | + const struct ttls_test *test = (const struct ttls_test *)user_data; |
| 418 | + |
| 419 | + (void)parser; |
| 420 | + (void)owner; |
| 421 | + (void)type; |
| 422 | + (void)class; |
| 423 | + (void)ttl; |
| 424 | + (void)rdlength; |
| 425 | + (void)rdata; |
| 426 | + |
| 427 | + if (ttl != test->ttl) |
| 428 | + return ZONE_SYNTAX_ERROR; |
| 429 | + return 0; |
| 430 | +} |
| 431 | + |
| 432 | +/*!cmocka */ |
| 433 | +void ttls(void **state) |
| 434 | +{ |
| 435 | + (void)state; |
| 436 | + |
| 437 | + static const struct ttls_test tests[] = { |
| 438 | + { "foo. 0 A 192.168.0.1", false, false, ZONE_SUCCESS, 0 }, |
| 439 | + { "foo. 1 A 192.168.0.1", false, false, ZONE_SUCCESS, 1 }, |
| 440 | + { "foo. 2147483647 A 192.168.0.1", false, false, ZONE_SUCCESS, 2147483647 }, |
| 441 | + { "foo. 2147483648 A 192.168.0.1", false, false, ZONE_SEMANTIC_ERROR, 0 }, |
| 442 | + { "foo. 2147483648 A 192.168.0.1", true, false, ZONE_SUCCESS, 2147483648 }, |
| 443 | + { "foo. 4294967295 A 192.168.0.1", true, false, ZONE_SUCCESS, 4294967295 }, |
| 444 | + { "foo. 4294967296 A 192.168.0.1", true, false, ZONE_SYNTAX_ERROR, 0 }, |
| 445 | + { "foo. 1d A 192.168.0.1", false, false, ZONE_SYNTAX_ERROR, 0 }, |
| 446 | + { "foo. 1d A 192.168.0.1", false, true, ZONE_SUCCESS, 86400 } |
| 447 | + }; |
| 448 | + |
| 449 | + static const uint8_t origin[] = { 3, 'f', 'o', 'o', 0 }; |
| 450 | + |
| 451 | + for (size_t i=0, n=sizeof(tests)/sizeof(tests[0]); i < n; i++) { |
| 452 | + zone_parser_t parser = { 0 }; |
| 453 | + zone_name_buffer_t name; |
| 454 | + zone_rdata_buffer_t rdata; |
| 455 | + zone_buffers_t buffers = { 1, &name, &rdata }; |
| 456 | + zone_options_t options = { 0 }; |
| 457 | + const char *str = tests[i].text; |
| 458 | + size_t len = strlen(str); |
| 459 | + int32_t code; |
| 460 | + |
| 461 | + options.accept.callback = tests_callback; |
| 462 | + options.origin.octets = origin; |
| 463 | + options.origin.length = sizeof(origin); |
| 464 | + options.default_ttl = 3600; |
| 465 | + options.default_class = ZONE_IN; |
| 466 | + options.non_strict = tests[i].non_strict; |
| 467 | + options.pretty_ttls = tests[i].pretty_ttls; |
| 468 | + |
| 469 | + fprintf(stderr, "INPUT: '%s'\n", str); |
| 470 | + code = zone_parse_string(&parser, &options, &buffers, str, len, (void*)&tests[i]); |
| 471 | + assert_int_equal(code, tests[i].code); |
| 472 | + } |
| 473 | +} |
0 commit comments