Skip to content

Commit

Permalink
Put some references to __DATE__ and __TIME__ behind a preprocessor flag.
Browse files Browse the repository at this point in the history
BUG=330260

Review URL: https://codereview.chromium.org/660753003

Cr-Commit-Position: refs/heads/master@{#300105}
  • Loading branch information
sebmarchand authored and Commit bot committed Oct 17, 2014
1 parent a80c255 commit 35b9a92
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions base/build_time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ Time GetBuildTime() {
//
// __DATE__ is exactly "Mmm DD YYYY".
// __TIME__ is exactly "hh:mm:ss".
#if defined(DONT_EMBED_BUILD_METADATA)
const char kDateTime[] = "Sep 02 2008 08:00:00 PST";
#else
const char kDateTime[] = __DATE__ " " __TIME__ " PST";
#endif
bool result = Time::FromString(kDateTime, &integral_build_time);
DCHECK(result);
return integral_build_time;
Expand Down
8 changes: 8 additions & 0 deletions base/build_time_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@
#include "testing/gtest/include/gtest/gtest.h"

TEST(BuildTime, DateLooksValid) {
#if !defined(DONT_EMBED_BUILD_METADATA)
char build_date[] = __DATE__;
#else
char build_date[] = "Sep 02 2008";
#endif

EXPECT_EQ(11u, strlen(build_date));
EXPECT_EQ(' ', build_date[3]);
EXPECT_EQ(' ', build_date[6]);
}

TEST(BuildTime, TimeLooksValid) {
#if defined(DONT_EMBED_BUILD_METADATA)
char build_time[] = "08:00:00";
#else
char build_time[] = __TIME__;
#endif

EXPECT_EQ(8u, strlen(build_time));
EXPECT_EQ(':', build_time[2]);
Expand Down

0 comments on commit 35b9a92

Please sign in to comment.