| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/time/time.h" | 5 #include "base/time/time.h" |
| 6 #include "net/der/encode_values.h" | 6 #include "net/der/encode_values.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 namespace net { | 9 namespace net { |
| 10 namespace der { | 10 namespace der { |
| 11 namespace test { | 11 namespace test { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 37 // the conversion is successful, and the encoded GeneralizedTime can should | 37 // the conversion is successful, and the encoded GeneralizedTime can should |
| 38 // match the test time. | 38 // match the test time. |
| 39 // | 39 // |
| 40 // Thu, 1 Jan 1570 00:00:00 GMT. This time is unrepresentable by the Windows | 40 // Thu, 1 Jan 1570 00:00:00 GMT. This time is unrepresentable by the Windows |
| 41 // native time libraries. | 41 // native time libraries. |
| 42 TEST(EncodeValuesTest, EncodeTimeFromBeforeWindowsEpoch) { | 42 TEST(EncodeValuesTest, EncodeTimeFromBeforeWindowsEpoch) { |
| 43 base::Time::Exploded exploded; | 43 base::Time::Exploded exploded; |
| 44 exploded.year = 1570; | 44 exploded.year = 1570; |
| 45 exploded.month = 1; | 45 exploded.month = 1; |
| 46 exploded.day_of_week = 5; | 46 exploded.day_of_week = 5; |
| 47 exploded.day_of_month = 1; |
| 47 exploded.hour = 0; | 48 exploded.hour = 0; |
| 48 exploded.minute = 0; | 49 exploded.minute = 0; |
| 49 exploded.second = 0; | 50 exploded.second = 0; |
| 50 exploded.millisecond = 0; | 51 exploded.millisecond = 0; |
| 51 | 52 |
| 52 base::Time time; | 53 base::Time time; |
| 53 if (!base::Time::FromUTCExploded(exploded, &time)) | 54 if (!base::Time::FromUTCExploded(exploded, &time)) |
| 54 return; | 55 return; |
| 55 | 56 |
| 56 GeneralizedTime generalized_time; | 57 GeneralizedTime generalized_time; |
| 57 ASSERT_TRUE(EncodeTimeAsGeneralizedTime(time, &generalized_time)); | 58 ASSERT_TRUE(EncodeTimeAsGeneralizedTime(time, &generalized_time)); |
| 58 EXPECT_EQ(1570, generalized_time.year); | 59 EXPECT_EQ(1570, generalized_time.year); |
| 59 EXPECT_EQ(1, generalized_time.month); | 60 EXPECT_EQ(1, generalized_time.month); |
| 60 EXPECT_EQ(1, generalized_time.day); | 61 EXPECT_EQ(1, generalized_time.day); |
| 61 EXPECT_EQ(0, generalized_time.hours); | 62 EXPECT_EQ(0, generalized_time.hours); |
| 62 EXPECT_EQ(0, generalized_time.minutes); | 63 EXPECT_EQ(0, generalized_time.minutes); |
| 63 EXPECT_EQ(0, generalized_time.seconds); | 64 EXPECT_EQ(0, generalized_time.seconds); |
| 64 } | 65 } |
| 65 | 66 |
| 66 // Sat, 1 Jan 2039 00:00:00 GMT. See above comment. This time may be | 67 // Sat, 1 Jan 2039 00:00:00 GMT. See above comment. This time may be |
| 67 // unrepresentable on 32-bit systems. | 68 // unrepresentable on 32-bit systems. |
| 68 TEST(EncodeValuesTest, EncodeTimeAfterTimeTMax) { | 69 TEST(EncodeValuesTest, EncodeTimeAfterTimeTMax) { |
| 69 base::Time::Exploded exploded; | 70 base::Time::Exploded exploded; |
| 70 exploded.year = 2039; | 71 exploded.year = 2039; |
| 71 exploded.month = 1; | 72 exploded.month = 1; |
| 72 exploded.day_of_week = 7; | 73 exploded.day_of_week = 7; |
| 74 exploded.day_of_month = 1; |
| 73 exploded.hour = 0; | 75 exploded.hour = 0; |
| 74 exploded.minute = 0; | 76 exploded.minute = 0; |
| 75 exploded.second = 0; | 77 exploded.second = 0; |
| 76 exploded.millisecond = 0; | 78 exploded.millisecond = 0; |
| 77 | 79 |
| 78 base::Time time; | 80 base::Time time; |
| 79 if (!base::Time::FromUTCExploded(exploded, &time)) | 81 if (!base::Time::FromUTCExploded(exploded, &time)) |
| 80 return; | 82 return; |
| 81 | 83 |
| 82 GeneralizedTime generalized_time; | 84 GeneralizedTime generalized_time; |
| 83 ASSERT_TRUE(EncodeTimeAsGeneralizedTime(time, &generalized_time)); | 85 ASSERT_TRUE(EncodeTimeAsGeneralizedTime(time, &generalized_time)); |
| 84 EXPECT_EQ(2039, generalized_time.year); | 86 EXPECT_EQ(2039, generalized_time.year); |
| 85 EXPECT_EQ(1, generalized_time.month); | 87 EXPECT_EQ(1, generalized_time.month); |
| 86 EXPECT_EQ(1, generalized_time.day); | 88 EXPECT_EQ(1, generalized_time.day); |
| 87 EXPECT_EQ(0, generalized_time.hours); | 89 EXPECT_EQ(0, generalized_time.hours); |
| 88 EXPECT_EQ(0, generalized_time.minutes); | 90 EXPECT_EQ(0, generalized_time.minutes); |
| 89 EXPECT_EQ(0, generalized_time.seconds); | 91 EXPECT_EQ(0, generalized_time.seconds); |
| 90 } | 92 } |
| 91 | 93 |
| 92 } // namespace test | 94 } // namespace test |
| 93 | 95 |
| 94 } // namespace der | 96 } // namespace der |
| 95 | 97 |
| 96 } // namespace net | 98 } // namespace net |
| OLD | NEW |