|
9 | 9 |
|
10 | 10 | #include <time.h> |
11 | 11 | #include <string.h> |
| 12 | +#include <math.h> |
| 13 | +#include <float.h> |
| 14 | +#include <limits.h> |
12 | 15 | #include "flb_tests_internal.h" |
13 | 16 |
|
14 | 17 | /* Parsers configuration */ |
@@ -588,13 +591,73 @@ void test_parser_time_system_timezone_midnight() |
588 | 591 | flb_config_exit(config); |
589 | 592 | } |
590 | 593 |
|
| 594 | +void test_parser_time_lookup_long_fraction() |
| 595 | +{ |
| 596 | + int ret; |
| 597 | + double ns; |
| 598 | + time_t epoch; |
| 599 | + struct flb_tm tm; |
| 600 | + struct flb_parser *parser; |
| 601 | + struct flb_config *config; |
| 602 | + const char *time_string = "10/03/2016 12:21:08.123456789123456789123456789123456789123456789123456789"; |
| 603 | + |
| 604 | + config = flb_config_init(); |
| 605 | + load_json_parsers(config); |
| 606 | + |
| 607 | + parser = flb_parser_get("generic_N", config); |
| 608 | + TEST_CHECK(parser != NULL); |
| 609 | + if (parser == NULL) { |
| 610 | + flb_parser_exit(config); |
| 611 | + flb_config_exit(config); |
| 612 | + return; |
| 613 | + } |
| 614 | + |
| 615 | + ret = flb_parser_time_lookup(time_string, strlen(time_string), 0, parser, &tm, &ns); |
| 616 | + TEST_CHECK(ret == 0); |
| 617 | + |
| 618 | + epoch = flb_parser_tm2time(&tm, FLB_FALSE); |
| 619 | + TEST_CHECK(epoch == 1475497268); |
| 620 | + TEST_CHECK(fabs(ns - 0.123456789) <= DBL_EPSILON); |
| 621 | + |
| 622 | + flb_parser_exit(config); |
| 623 | + flb_config_exit(config); |
| 624 | +} |
| 625 | + |
| 626 | +void test_parser_time_lookup_reject_oversized_length() |
| 627 | +{ |
| 628 | + int ret; |
| 629 | + double ns; |
| 630 | + struct flb_tm tm; |
| 631 | + struct flb_parser *parser; |
| 632 | + struct flb_config *config; |
| 633 | + |
| 634 | + config = flb_config_init(); |
| 635 | + load_json_parsers(config); |
| 636 | + |
| 637 | + parser = flb_parser_get("generic_N", config); |
| 638 | + TEST_CHECK(parser != NULL); |
| 639 | + if (parser == NULL) { |
| 640 | + flb_parser_exit(config); |
| 641 | + flb_config_exit(config); |
| 642 | + return; |
| 643 | + } |
| 644 | + |
| 645 | + ret = flb_parser_time_lookup("x", (size_t) INT_MAX + 1, 0, parser, &tm, &ns); |
| 646 | + TEST_CHECK(ret == -1); |
| 647 | + |
| 648 | + flb_parser_exit(config); |
| 649 | + flb_config_exit(config); |
| 650 | +} |
| 651 | + |
591 | 652 |
|
592 | 653 | TEST_LIST = { |
593 | 654 | { "tzone_offset", test_parser_tzone_offset}, |
594 | 655 | { "time_lookup", test_parser_time_lookup}, |
595 | 656 | { "json_time_lookup", test_json_parser_time_lookup}, |
596 | 657 | { "regex_time_lookup", test_regex_parser_time_lookup}, |
597 | 658 | { "time_system_timezone_midnight", test_parser_time_system_timezone_midnight}, |
| 659 | + { "time_lookup_long_fraction", test_parser_time_lookup_long_fraction}, |
| 660 | + { "time_lookup_reject_oversized_length", test_parser_time_lookup_reject_oversized_length}, |
598 | 661 | { "mysql_unquoted" , test_mysql_unquoted }, |
599 | 662 | { 0 } |
600 | 663 | }; |
0 commit comments