Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: base/time_unittest.cc

Issue 4471001: Reland http://codereview.chromium.org/4139008, with a different (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: this crap still does not work Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/time_mac.cc ('k') | chrome/browser/extensions/convert_user_script.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <time.h> 5 #include <time.h>
6 6
7 #include "base/platform_thread.h" 7 #include "base/platform_thread.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 EXPECT_EQ(now_t_1, now_t_2); 45 EXPECT_EQ(now_t_1, now_t_2);
46 46
47 EXPECT_EQ(10, Time().FromTimeT(10).ToTimeT()); 47 EXPECT_EQ(10, Time().FromTimeT(10).ToTimeT());
48 EXPECT_EQ(10.0, Time().FromTimeT(10).ToDoubleT()); 48 EXPECT_EQ(10.0, Time().FromTimeT(10).ToDoubleT());
49 49
50 // Conversions of 0 should stay 0. 50 // Conversions of 0 should stay 0.
51 EXPECT_EQ(0, Time().ToTimeT()); 51 EXPECT_EQ(0, Time().ToTimeT());
52 EXPECT_EQ(0, Time::FromTimeT(0).ToInternalValue()); 52 EXPECT_EQ(0, Time::FromTimeT(0).ToInternalValue());
53 } 53 }
54 54
55 TEST(Time, FromExplodedWithMilliseconds) {
56 // Some platform implementations of FromExploded are liable to drop
57 // milliseconds if we aren't careful.
58 Time now = Time::NowFromSystemTime();
59 Time::Exploded exploded1 = {0};
60 now.UTCExplode(&exploded1);
61 exploded1.millisecond = 500;
62 Time time = Time::FromUTCExploded(exploded1);
63 Time::Exploded exploded2 = {0};
64 time.UTCExplode(&exploded2);
65 EXPECT_EQ(exploded1.millisecond, exploded2.millisecond);
66 }
67
55 TEST(Time, ZeroIsSymmetric) { 68 TEST(Time, ZeroIsSymmetric) {
56 Time zero_time(Time::FromTimeT(0)); 69 Time zero_time(Time::FromTimeT(0));
57 EXPECT_EQ(0, zero_time.ToTimeT()); 70 EXPECT_EQ(0, zero_time.ToTimeT());
58 71
59 EXPECT_EQ(0.0, zero_time.ToDoubleT()); 72 EXPECT_EQ(0.0, zero_time.ToDoubleT());
60 } 73 }
61 74
62 TEST(Time, LocalExplode) { 75 TEST(Time, LocalExplode) {
63 Time a = Time::Now(); 76 Time a = Time::Now();
64 Time::Exploded exploded; 77 Time::Exploded exploded;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 exploded.minute = 0; 220 exploded.minute = 0;
208 exploded.second = 0; 221 exploded.second = 0;
209 exploded.millisecond = 0; 222 exploded.millisecond = 0;
210 Time t = Time::FromUTCExploded(exploded); 223 Time t = Time::FromUTCExploded(exploded);
211 // Unix 1970 epoch. 224 // Unix 1970 epoch.
212 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue()); 225 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue());
213 226
214 // We can't test 1601 epoch, since the system time functions on Linux 227 // We can't test 1601 epoch, since the system time functions on Linux
215 // only compute years starting from 1900. 228 // only compute years starting from 1900.
216 } 229 }
OLDNEW
« no previous file with comments | « base/time_mac.cc ('k') | chrome/browser/extensions/convert_user_script.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698