Chromium Code Reviews| Index: net/cert/x509_cert_types_unittest.cc |
| diff --git a/net/cert/x509_cert_types_unittest.cc b/net/cert/x509_cert_types_unittest.cc |
| index 50275f0eb010f7cb253fab4ca4c78ec7500c93e5..2fe7a2337078fc32857aa023466ebfc430e6b699 100644 |
| --- a/net/cert/x509_cert_types_unittest.cc |
| +++ b/net/cert/x509_cert_types_unittest.cc |
| @@ -182,18 +182,21 @@ const struct CertDateTestData { |
| "20120101123000Z", |
| true, |
| {2012, 1, 0, 1, 12, 30, 0}}, |
| + // test 31st of April |
| + {CERT_DATE_FORMAT_GENERALIZED_TIME, "20160431121000Z", false, {0}}, |
| + // test 31st of February |
| + {CERT_DATE_FORMAT_GENERALIZED_TIME, "20160231121000Z", false, {0}}, |
| }; |
| // GTest pretty printer. |
| void PrintTo(const CertDateTestData& data, std::ostream* os) { |
| + base::Time out_time; |
| + bool result = base::Time::FromUTCExploded(data.expected_result, &out_time); |
| *os << " format: " << data.format |
| << "; date string: " << base::StringPiece(data.date_string) |
| - << "; valid: " << data.is_valid |
| - << "; expected date: " |
| - << (data.is_valid ? |
| - base::Time::FromUTCExploded(data.expected_result) |
| - .ToInternalValue() : |
| - 0U); |
| + << "; valid: " << data.is_valid << "; expected date: " |
| + << (data.is_valid ? out_time.ToInternalValue() : 0U) |
| + << "; FromUTCExploded conversion result: " << result; |
| } |
| class X509CertTypesDateTest : public testing::TestWithParam<CertDateTestData> { |
| @@ -202,24 +205,52 @@ class X509CertTypesDateTest : public testing::TestWithParam<CertDateTestData> { |
| void SetUp() override { test_data_ = GetParam(); } |
| protected: |
| - CertDateTestData test_data_; |
| + bool ExplodedExceedsBitsLimit(const base::Time::Exploded& exploded) { |
| + base::Time max_time; |
| + max_time = base::Time::Max(); |
| + base::Time out_time; |
| + bool converted = base::Time::FromUTCExploded(exploded, &out_time); |
| + if (converted && out_time.ToInternalValue() <= max_time.ToInternalValue()) |
|
eroman
2016/12/17 02:39:30
Won't "out_time.ToInternalValue() <= max_time.ToIn
maksims_
2016/12/19 15:45:13
Nope, on 32-bit build int64_t resolves to 2^32. An
eroman
2016/12/19 19:22:31
These are both int64_t values, this isn't going to
maksims (do not use this acc)
2016/12/19 20:37:31
Ok, thx. Done.
|
| + return false; |
| + return true; |
| + } |
| + |
| + CertDateTestData test_data_; |
| }; |
| TEST_P(X509CertTypesDateTest, Parse) { |
| base::Time parsed_date; |
| bool parsed = ParseCertificateDate( |
| test_data_.date_string, test_data_.format, &parsed_date); |
| - EXPECT_EQ(test_data_.is_valid, parsed); |
| + |
| + // On systems that support only 32-bit numeric representation, time values |
| + // which year is more that 2038 are expected to fail. First, figure out |
| + // if test data is expected to fail and modify test expectations accordingly. |
| + bool exceeds_limit = false; |
| + if (sizeof(time_t) <= 4 && |
|
eroman
2016/12/17 02:39:30
Rather than the ExplodedExceedsBitsLimit() functio
maksims_
2016/12/19 15:45:13
See my comment above
|
| + ExplodedExceedsBitsLimit(test_data_.expected_result)) { |
| + EXPECT_FALSE(parsed); |
| + exceeds_limit = true; |
| + } else { |
| + EXPECT_EQ(test_data_.is_valid, parsed); |
| + } |
| + |
| if (!test_data_.is_valid) |
| return; |
| - // Convert the expected value to a base::Time(). This ensures that systems |
| + // Convert the expected value to a base::Time(). This ensures that |
| // systems that only support 32-bit times will pass the tests, by ensuring at |
| - // least that the times have the same truncating behaviour. |
| + // least that the times have the same truncating behavior. |
| // Note: Compared as internal values so that mismatches can be cleanly |
| - // printed by GTest (eg: without PrintTo overrides). |
| - EXPECT_EQ(base::Time::FromUTCExploded(test_data_.expected_result) |
| - .ToInternalValue(), |
| - parsed_date.ToInternalValue()); |
| + // printed by GTest (e.g.: without PrintTo overrides). |
| + base::Time out_time; |
| + if (exceeds_limit) { |
| + EXPECT_FALSE( |
| + base::Time::FromUTCExploded(test_data_.expected_result, &out_time)); |
| + } else { |
| + EXPECT_TRUE( |
| + base::Time::FromUTCExploded(test_data_.expected_result, &out_time)); |
| + } |
| + EXPECT_EQ(out_time.ToInternalValue(), parsed_date.ToInternalValue()); |
| } |
| INSTANTIATE_TEST_CASE_P(, |
| X509CertTypesDateTest, |