• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "base/build_time.h"
6 #if !defined(DONT_EMBED_BUILD_METADATA)
7 #include "base/generated_build_date.h"
8 #endif
9 #include "base/time/time.h"
10 
11 #include "testing/gtest/include/gtest/gtest.h"
12 
TEST(BuildTime,DateLooksValid)13 TEST(BuildTime, DateLooksValid) {
14 #if !defined(DONT_EMBED_BUILD_METADATA)
15   char build_date[] = BUILD_DATE;
16 #else
17   char build_date[] = "Sep 02 2008 05:00:00";
18 #endif
19 
20   EXPECT_EQ(20u, strlen(build_date));
21   EXPECT_EQ(' ', build_date[3]);
22   EXPECT_EQ(' ', build_date[6]);
23   EXPECT_EQ(' ', build_date[11]);
24   EXPECT_EQ('0', build_date[12]);
25   EXPECT_EQ('5', build_date[13]);
26   EXPECT_EQ(':', build_date[14]);
27   EXPECT_EQ('0', build_date[15]);
28   EXPECT_EQ('0', build_date[16]);
29   EXPECT_EQ(':', build_date[17]);
30   EXPECT_EQ('0', build_date[18]);
31   EXPECT_EQ('0', build_date[19]);
32 }
33 
TEST(BuildTime,InThePast)34 TEST(BuildTime, InThePast) {
35   EXPECT_LT(base::GetBuildTime(), base::Time::Now());
36   EXPECT_LT(base::GetBuildTime(), base::Time::NowFromSystemTime());
37 }
38 
39 #if !defined(DONT_EMBED_BUILD_METADATA)
TEST(BuildTime,NotTooFar)40 TEST(BuildTime, NotTooFar) {
41   // BuildTime must be less than 45 days old.
42   base::Time cutoff(base::Time::Now() - base::TimeDelta::FromDays(45));
43   EXPECT_GT(base::GetBuildTime(), cutoff);
44 }
45 #endif
46