NAKAMURA Takumi | e7f0393 | 2013-07-16 02:03:32 +0000 | [diff] [blame] | 1 | //===- llvm/unittest/Support/TimeValueTest.cpp - Time Value tests ---------===// |
Michael J. Spencer | f2ca4cb | 2010-11-24 19:20:05 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "gtest/gtest.h" |
Michael J. Spencer | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 11 | #include "llvm/Support/TimeValue.h" |
Michael J. Spencer | f2ca4cb | 2010-11-24 19:20:05 +0000 | [diff] [blame] | 12 | #include <time.h> |
| 13 | |
| 14 | using namespace llvm; |
| 15 | namespace { |
| 16 | |
NAKAMURA Takumi | e7f0393 | 2013-07-16 02:03:32 +0000 | [diff] [blame] | 17 | TEST(TimeValue, time_t) { |
Michael J. Spencer | f2ca4cb | 2010-11-24 19:20:05 +0000 | [diff] [blame] | 18 | sys::TimeValue now = sys::TimeValue::now(); |
| 19 | time_t now_t = time(NULL); |
| 20 | EXPECT_TRUE(abs(static_cast<long>(now_t - now.toEpochTime())) < 2); |
| 21 | } |
| 22 | |
NAKAMURA Takumi | 334f8b9 | 2013-07-16 02:44:23 +0000 | [diff] [blame] | 23 | TEST(TimeValue, Win32FILETIME) { |
| 24 | uint64_t epoch_as_filetime = 0x19DB1DED53E8000ULL; |
| 25 | uint32_t ns = 765432100; |
| 26 | sys::TimeValue epoch; |
| 27 | |
| 28 | // FILETIME has 100ns of intervals. |
| 29 | uint64_t ft1970 = epoch_as_filetime + ns / 100; |
| 30 | epoch.fromWin32Time(ft1970); |
| 31 | |
| 32 | // The "seconds" part in Posix time may be expected as zero. |
| 33 | EXPECT_EQ(ns / 100, epoch.toPosixTime()); |
| 34 | |
| 35 | // Confirm it reversible. |
| 36 | EXPECT_EQ(ft1970, epoch.toWin32Time()); |
| 37 | } |
| 38 | |
Michael J. Spencer | f2ca4cb | 2010-11-24 19:20:05 +0000 | [diff] [blame] | 39 | } |