| 32 | }; |
| 33 | |
| 34 | TEST_F(TestIntervalHolder, TestMatchAllPeriods) { |
| 35 | EXPECT_OK_AND_ASSIGN(auto interval_days_holder, IntervalDaysHolder::Make(0)); |
| 36 | EXPECT_OK_AND_ASSIGN(auto interval_years_holder, IntervalYearsHolder::Make(0)); |
| 37 | |
| 38 | auto& cast_interval_day = *interval_days_holder; |
| 39 | auto& cast_interval_year = *interval_years_holder; |
| 40 | |
| 41 | // Pass only numbers to cast |
| 42 | bool out_valid; |
| 43 | std::string data("73834992"); |
| 44 | int64_t response = |
| 45 | cast_interval_day(&execution_context_, data.data(), 8, true, &out_valid); |
| 46 | int64_t qty_days_in_response = 0; |
| 47 | int64_t qty_millis_in_response = 73834992; |
| 48 | EXPECT_TRUE(out_valid); |
| 49 | EXPECT_FALSE(execution_context_.has_error()); |
| 50 | EXPECT_EQ(response, (qty_millis_in_response << 32) | qty_days_in_response); |
| 51 | |
| 52 | int32_t response_interval_yrs = |
| 53 | cast_interval_year(&execution_context_, data.data(), 8, true, &out_valid); |
| 54 | EXPECT_EQ(response_interval_yrs, 73834992); |
| 55 | EXPECT_TRUE(out_valid); |
| 56 | EXPECT_FALSE(execution_context_.has_error()); |
| 57 | |
| 58 | data = "1"; |
| 59 | response = cast_interval_day(&execution_context_, data.data(), 1, true, &out_valid); |
| 60 | qty_days_in_response = 0; |
| 61 | qty_millis_in_response = 1; |
| 62 | EXPECT_TRUE(out_valid); |
| 63 | EXPECT_FALSE(execution_context_.has_error()); |
| 64 | EXPECT_EQ(response, (qty_millis_in_response << 32) | qty_days_in_response); |
| 65 | |
| 66 | data = "PT0.001S"; |
| 67 | response = cast_interval_day(&execution_context_, data.data(), 8, true, &out_valid); |
| 68 | qty_days_in_response = 0; |
| 69 | qty_millis_in_response = 1; |
| 70 | EXPECT_TRUE(out_valid); |
| 71 | EXPECT_FALSE(execution_context_.has_error()); |
| 72 | EXPECT_EQ(response, (qty_millis_in_response << 32) | qty_days_in_response); |
| 73 | |
| 74 | // Pass only years and days to cast |
| 75 | data = "P12Y15D"; |
| 76 | response = cast_interval_day(&execution_context_, data.data(), 7, true, &out_valid); |
| 77 | qty_days_in_response = 15; |
| 78 | qty_millis_in_response = 0; |
| 79 | EXPECT_TRUE(out_valid); |
| 80 | EXPECT_FALSE(execution_context_.has_error()); |
| 81 | EXPECT_EQ(response, (qty_millis_in_response << 32) | qty_days_in_response); |
| 82 | |
| 83 | response_interval_yrs = |
| 84 | cast_interval_year(&execution_context_, data.data(), 7, true, &out_valid); |
| 85 | EXPECT_TRUE(out_valid); |
| 86 | EXPECT_FALSE(execution_context_.has_error()); |
| 87 | EXPECT_EQ(response_interval_yrs, 144); |
| 88 | |
| 89 | // Pass years and days and months to cast |
| 90 | data = "P12Y2M15D"; |
| 91 | response = cast_interval_day(&execution_context_, data.data(), 9, true, &out_valid); |