Test the specified url.parse function. * * URL::parse and URL::parse_regex should behave the same. This function * performs the same behavior for each. * * @param[in] test_case The test case specification to run. * * @param[in] parse_function Whether to run parse() or * parse_regex(). */
| 521 | * parse_regex(). |
| 522 | */ |
| 523 | void |
| 524 | test_parse(url_parse_test_case const &test_case, bool parse_function) |
| 525 | { |
| 526 | URL url; |
| 527 | HdrHeap *heap = new_HdrHeap(); |
| 528 | url.create(heap); |
| 529 | ParseResult result = PARSE_RESULT_OK; |
| 530 | if (parse_function == URL_PARSE) { |
| 531 | if (test_case.verify_host_characters) { |
| 532 | result = url.parse(test_case.input_uri); |
| 533 | } else { |
| 534 | result = url.parse_no_host_check(test_case.input_uri); |
| 535 | } |
| 536 | } else if (parse_function == URL_PARSE_REGEX) { |
| 537 | result = url.parse_regex(test_case.input_uri); |
| 538 | } |
| 539 | bool expected_is_valid = test_case.is_valid; |
| 540 | if (parse_function == URL_PARSE_REGEX) { |
| 541 | expected_is_valid = test_case.is_valid_regex; |
| 542 | } |
| 543 | if (expected_is_valid && result != PARSE_RESULT_DONE) { |
| 544 | std::printf("Parse URI: \"%s\", expected it to be valid but it was parsed invalid (%d)\n", test_case.input_uri.c_str(), result); |
| 545 | CHECK(false); |
| 546 | } else if (!expected_is_valid && result != PARSE_RESULT_ERROR) { |
| 547 | std::printf("Parse URI: \"%s\", expected it to be invalid but it was parsed valid (%d)\n", test_case.input_uri.c_str(), result); |
| 548 | CHECK(false); |
| 549 | } |
| 550 | if (result == PARSE_RESULT_DONE) { |
| 551 | char buf[1024]; |
| 552 | int index = 0; |
| 553 | int offset = 0; |
| 554 | url.print(buf, sizeof(buf), &index, &offset); |
| 555 | std::string printed_url{buf, static_cast<size_t>(index)}; |
| 556 | if (parse_function == URL_PARSE) { |
| 557 | CHECK(test_case.expected_printed_url == printed_url); |
| 558 | CHECK(test_case.expected_printed_url.size() == printed_url.size()); |
| 559 | } else if (parse_function == URL_PARSE_REGEX) { |
| 560 | CHECK(test_case.expected_printed_url_regex == printed_url); |
| 561 | CHECK(test_case.expected_printed_url_regex.size() == printed_url.size()); |
| 562 | } |
| 563 | } |
| 564 | heap->destroy(); |
| 565 | } |
| 566 | |
| 567 | TEST_CASE("UrlParse", "[proxy][parseurl]") |
| 568 | { |
no test coverage detected