OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <time.h> | 8 #include <time.h> |
9 #include <limits> | 9 #include <limits> |
10 #include <string> | 10 #include <string> |
11 | 11 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 Time now = Time::NowFromSystemTime(); | 118 Time now = Time::NowFromSystemTime(); |
119 Time::Exploded exploded1 = {0}; | 119 Time::Exploded exploded1 = {0}; |
120 now.UTCExplode(&exploded1); | 120 now.UTCExplode(&exploded1); |
121 exploded1.millisecond = 500; | 121 exploded1.millisecond = 500; |
122 Time time = Time::FromUTCExploded(exploded1); | 122 Time time = Time::FromUTCExploded(exploded1); |
123 Time::Exploded exploded2 = {0}; | 123 Time::Exploded exploded2 = {0}; |
124 time.UTCExplode(&exploded2); | 124 time.UTCExplode(&exploded2); |
125 EXPECT_EQ(exploded1.millisecond, exploded2.millisecond); | 125 EXPECT_EQ(exploded1.millisecond, exploded2.millisecond); |
126 } | 126 } |
127 | 127 |
128 TEST_F(TimeTest, FromExplodedError) { | |
mmenke
2016/05/18 17:32:01
Maybe call this test "FromExplodedOutOfBoundsTime"
maksims (do not use this acc)
2016/05/19 09:57:20
Done.
| |
129 // FromUTCExploded might return Time(0), if the day is set to 31 on a | |
mmenke
2016/05/18 17:32:01
nit: might -> must
maksims (do not use this acc)
2016/05/19 09:57:20
Done.
| |
130 // 28-30 day month. Test |exploded| returns Time(0) on 31st of February and | |
131 // 31st of April; | |
132 base::Time::Exploded exploded = {0}; | |
133 exploded.year = 2016; | |
134 exploded.month = 2; | |
135 exploded.day_of_month = 31; | |
136 exploded.hour = 12; | |
137 exploded.minute = 30; | |
138 exploded.second = 0; | |
139 | |
140 EXPECT_TRUE(exploded.HasValidValues()); | |
141 | |
142 base::Time t_time = base::Time::FromUTCExploded(exploded); | |
143 EXPECT_TRUE(t_time.is_null()); | |
144 t_time = base::Time::FromLocalExploded(exploded); | |
145 EXPECT_TRUE(t_time.is_null()); | |
146 | |
147 // 31st of April | |
148 exploded.year = 2016; | |
149 exploded.month = 4; | |
150 exploded.day_of_month = 31; | |
151 exploded.hour = 12; | |
152 exploded.minute = 30; | |
eroman
2016/05/18 19:35:17
Good start, but will also want tests for:
* nega
maksims (do not use this acc)
2016/05/19 09:57:20
Done.
| |
153 exploded.second = 0; | |
154 | |
155 EXPECT_TRUE(exploded.HasValidValues()); | |
156 | |
157 t_time = base::Time::FromUTCExploded(exploded); | |
158 EXPECT_TRUE(t_time.is_null()); | |
159 t_time = base::Time::FromLocalExploded(exploded); | |
160 EXPECT_TRUE(t_time.is_null()); | |
161 } | |
162 | |
128 TEST_F(TimeTest, ZeroIsSymmetric) { | 163 TEST_F(TimeTest, ZeroIsSymmetric) { |
129 Time zero_time(Time::FromTimeT(0)); | 164 Time zero_time(Time::FromTimeT(0)); |
130 EXPECT_EQ(0, zero_time.ToTimeT()); | 165 EXPECT_EQ(0, zero_time.ToTimeT()); |
131 | 166 |
132 EXPECT_EQ(0.0, zero_time.ToDoubleT()); | 167 EXPECT_EQ(0.0, zero_time.ToDoubleT()); |
133 } | 168 } |
134 | 169 |
135 TEST_F(TimeTest, LocalExplode) { | 170 TEST_F(TimeTest, LocalExplode) { |
136 Time a = Time::Now(); | 171 Time a = Time::Now(); |
137 Time::Exploded exploded; | 172 Time::Exploded exploded; |
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1116 | 1151 |
1117 TEST(TimeTicksLogging, DoesNotMakeStreamBad) { | 1152 TEST(TimeTicksLogging, DoesNotMakeStreamBad) { |
1118 std::ostringstream oss; | 1153 std::ostringstream oss; |
1119 oss << TimeTicks(); | 1154 oss << TimeTicks(); |
1120 EXPECT_TRUE(oss.good()); | 1155 EXPECT_TRUE(oss.good()); |
1121 } | 1156 } |
1122 | 1157 |
1123 } // namespace | 1158 } // namespace |
1124 | 1159 |
1125 } // namespace base | 1160 } // namespace base |
OLD | NEW |