Used to test custom date output test cases i.e. date value -> string.
| 477 | |
| 478 | // Used to test custom date output test cases i.e. date value -> string. |
| 479 | struct DateFormatTC { |
| 480 | const int32_t days_since_epoch; |
| 481 | const char* fmt; |
| 482 | const char* str; |
| 483 | bool should_fail; |
| 484 | |
| 485 | DateFormatTC(int32_t days_since_epoch, const char* fmt, const char* str, |
| 486 | bool should_fail = false) |
| 487 | : days_since_epoch(days_since_epoch), |
| 488 | fmt(fmt), |
| 489 | str(str), |
| 490 | should_fail(should_fail) { |
| 491 | } |
| 492 | |
| 493 | void Run(int id, const TimestampValue& now) const { |
| 494 | DateTimeFormatContext dt_ctx(fmt); |
| 495 | dt_ctx.SetCenturyBreakAndCurrentTime(now); |
| 496 | |
| 497 | stringstream desc; |
| 498 | desc << "DateFormatTC [" << id << "]: " << "days_since_epoch:" << days_since_epoch |
| 499 | << " fmt:" << fmt << " str:" << str; |
| 500 | |
| 501 | ASSERT_TRUE(SimpleDateFormatTokenizer::Tokenize(&dt_ctx, PARSE, false)) << desc.str(); |
| 502 | |
| 503 | const DateValue cust_dv(days_since_epoch); |
| 504 | EXPECT_TRUE(cust_dv.IsValid()) << desc.str(); |
| 505 | EXPECT_GE(dt_ctx.fmt_out_len, dt_ctx.fmt_len) << desc.str(); |
| 506 | |
| 507 | string buff = cust_dv.Format(dt_ctx); |
| 508 | EXPECT_TRUE(!buff.empty()) << desc.str(); |
| 509 | EXPECT_LE(buff.length(), dt_ctx.fmt_out_len) << desc.str(); |
| 510 | EXPECT_EQ(buff, string(str, strlen(str))) << desc.str(); |
| 511 | } |
| 512 | |
| 513 | }; |
| 514 | |
| 515 | TEST(DateTest, FormatComplexFormats) { |
| 516 | const TimestampValue now(date(1980, 2, 28), time_duration(16, 14, 24)); |