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

Side by Side Diff: base/time/time_unittest.cc

Issue 2241603002: Add explicit TimeDelta constexpr copy constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months 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
« base/time/time.h ('K') | « base/time/time.h ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/threading/platform_thread.h" 16 #include "base/threading/platform_thread.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 namespace base { 20 namespace base {
21 21
22 namespace { 22 namespace {
23 23
24 // For TimeDelta::ConstexprInitialization
25 enum { kExpectedDeltaInMilliseconds = 10 };
miu 2016/08/11 21:48:56 Is it necessary for this to be an enum to trigger
liberato (no reviews please) 2016/08/11 22:10:35 it's not necessary. originally, i had it as const
26 constexpr TimeDelta kConstexprTimeDelta =
27 TimeDelta::FromMilliseconds(kExpectedDeltaInMilliseconds);
28
24 TEST(TimeTestOutOfBounds, FromExplodedOutOfBoundsTime) { 29 TEST(TimeTestOutOfBounds, FromExplodedOutOfBoundsTime) {
25 // FromUTCExploded must set time to Time(0) and failure, if the day is set to 30 // FromUTCExploded must set time to Time(0) and failure, if the day is set to
26 // 31 on a 28-30 day month. Test |exploded| returns Time(0) on 31st of 31 // 31 on a 28-30 day month. Test |exploded| returns Time(0) on 31st of
27 // February and 31st of April. New implementation handles this. 32 // February and 31st of April. New implementation handles this.
28 33
29 const struct DateTestData { 34 const struct DateTestData {
30 Time::Exploded explode; 35 Time::Exploded explode;
31 bool is_valid; 36 bool is_valid;
32 } kDateTestData[] = { 37 } kDateTestData[] = {
33 // 31st of February 38 // 31st of February
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 1091
1087 Time time_now = Time::Now(); 1092 Time time_now = Time::Now();
1088 EXPECT_EQ(one_second, (time_now + one_second) - time_now); 1093 EXPECT_EQ(one_second, (time_now + one_second) - time_now);
1089 EXPECT_EQ(-one_second, (time_now - one_second) - time_now); 1094 EXPECT_EQ(-one_second, (time_now - one_second) - time_now);
1090 1095
1091 TimeTicks ticks_now = TimeTicks::Now(); 1096 TimeTicks ticks_now = TimeTicks::Now();
1092 EXPECT_EQ(-one_second, (ticks_now - one_second) - ticks_now); 1097 EXPECT_EQ(-one_second, (ticks_now - one_second) - ticks_now);
1093 EXPECT_EQ(one_second, (ticks_now + one_second) - ticks_now); 1098 EXPECT_EQ(one_second, (ticks_now + one_second) - ticks_now);
1094 } 1099 }
1095 1100
1101 TEST(TimeDelta, ConstexprInitialization) {
miu 2016/08/11 21:48:56 Please put these changes in time_win_unittest.cc i
liberato (no reviews please) 2016/08/11 22:10:35 Done.
1102 // Make sure that TimeDelta works around crbug.com/635974
1103 EXPECT_EQ(kExpectedDeltaInMilliseconds, kConstexprTimeDelta.InMilliseconds());
1104 }
1105
1096 TEST(TimeDeltaLogging, DCheckEqCompiles) { 1106 TEST(TimeDeltaLogging, DCheckEqCompiles) {
1097 DCHECK_EQ(TimeDelta(), TimeDelta()); 1107 DCHECK_EQ(TimeDelta(), TimeDelta());
1098 } 1108 }
1099 1109
1100 TEST(TimeDeltaLogging, EmptyIsZero) { 1110 TEST(TimeDeltaLogging, EmptyIsZero) {
1101 TimeDelta zero; 1111 TimeDelta zero;
1102 EXPECT_EQ("0s", AnyToString(zero)); 1112 EXPECT_EQ("0s", AnyToString(zero));
1103 } 1113 }
1104 1114
1105 TEST(TimeDeltaLogging, FiveHundredMs) { 1115 TEST(TimeDeltaLogging, FiveHundredMs) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 1183
1174 TEST(TimeTicksLogging, DoesNotMakeStreamBad) { 1184 TEST(TimeTicksLogging, DoesNotMakeStreamBad) {
1175 std::ostringstream oss; 1185 std::ostringstream oss;
1176 oss << TimeTicks(); 1186 oss << TimeTicks();
1177 EXPECT_TRUE(oss.good()); 1187 EXPECT_TRUE(oss.good());
1178 } 1188 }
1179 1189
1180 } // namespace 1190 } // namespace
1181 1191
1182 } // namespace base 1192 } // namespace base
OLDNEW
« base/time/time.h ('K') | « base/time/time.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698