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

Side by Side Diff: base/build_time_unittest.cc

Issue 1846713002: Improve the error message in BuildTime.InThePast to help figure out the problem. (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: Rewrite Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/build_time.h" 5 #include "base/build_time.h"
6 #include "base/generated_build_date.h" 6 #include "base/generated_build_date.h"
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 TEST(BuildTime, DateLooksValid) { 11 TEST(BuildTime, DateLooksValid) {
12 char build_date[] = BUILD_DATE; 12 char build_date[] = BUILD_DATE;
13 13
14 EXPECT_EQ(11u, strlen(build_date)); 14 EXPECT_EQ(20u, strlen(build_date));
15 EXPECT_EQ(' ', build_date[3]); 15 EXPECT_EQ(' ', build_date[3]);
16 EXPECT_EQ(' ', build_date[6]); 16 EXPECT_EQ(' ', build_date[6]);
17 } 17 EXPECT_EQ(' ', build_date[11]);
18 18 EXPECT_EQ('0', build_date[12]);
19 TEST(BuildTime, TimeLooksValid) { 19 EXPECT_EQ('5', build_date[13]);
20 char build_time[] = "00:00:00"; 20 EXPECT_EQ(':', build_date[14]);
21 21 EXPECT_EQ('0', build_date[15]);
22 EXPECT_EQ(8u, strlen(build_time)); 22 EXPECT_EQ('0', build_date[16]);
23 EXPECT_EQ(':', build_time[2]); 23 EXPECT_EQ(':', build_date[17]);
24 EXPECT_EQ(':', build_time[5]); 24 EXPECT_EQ('0', build_date[18]);
25 EXPECT_EQ('0', build_date[19]);
25 } 26 }
26 27
27 TEST(BuildTime, InThePast) { 28 TEST(BuildTime, InThePast) {
28 EXPECT_TRUE(base::GetBuildTime() < base::Time::Now()); 29 EXPECT_LT(base::GetBuildTime(), base::Time::Now());
29 EXPECT_TRUE(base::GetBuildTime() < base::Time::NowFromSystemTime()); 30 EXPECT_LT(base::GetBuildTime(), base::Time::NowFromSystemTime());
30 } 31 }
32
33 TEST(BuildTime, NotTooFar) {
34 // BuildTime must be less than 45 days old.
35 base::Time cutoff(base::Time::Now() - base::TimeDelta::FromDays(45));
36 EXPECT_GT(base::GetBuildTime(), cutoff);
37 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698