| 261 | } |
| 262 | |
| 263 | void Run(int id, const TimestampValue& now) const { |
| 264 | DateTimeFormatContext dt_ctx(fmt); |
| 265 | dt_ctx.SetCenturyBreakAndCurrentTime(now); |
| 266 | |
| 267 | stringstream desc; |
| 268 | desc << "DateTC [" << id << "]: " << " fmt:" << fmt << " str:" << str |
| 269 | << " expected date:" << expected_year << "/" << expected_month << "/" |
| 270 | << expected_day; |
| 271 | |
| 272 | bool parse_result = SimpleDateFormatTokenizer::Tokenize(&dt_ctx, PARSE, false); |
| 273 | if (fmt_should_fail) { |
| 274 | EXPECT_FALSE(parse_result) << desc.str(); |
| 275 | return; |
| 276 | } else { |
| 277 | ASSERT_TRUE(parse_result) << desc.str(); |
| 278 | } |
| 279 | |
| 280 | DateValue cust_dv = DateValue::ParseSimpleDateFormat(str, strlen(str), dt_ctx); |
| 281 | if (str_should_fail) { |
| 282 | EXPECT_FALSE(cust_dv.IsValid()) << desc.str(); |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | // Check the date (based on any date format tokens being present) |
| 287 | ValidateDate(cust_dv, expected_year, expected_month, expected_day, desc.str()); |
| 288 | |
| 289 | // Check formatted date |
| 290 | if (!should_format) return; |
| 291 | |
| 292 | string buff = cust_dv.Format(dt_ctx); |
| 293 | EXPECT_TRUE(!buff.empty()) << desc.str(); |
| 294 | EXPECT_LE(buff.length(), dt_ctx.fmt_len) << desc.str(); |
| 295 | EXPECT_EQ(string(str, strlen(str)), buff) << desc.str(); |
| 296 | } |
| 297 | }; |
| 298 | |
| 299 | TEST(DateTest, ParseFormatEdgeCases) { |
no test coverage detected