2013-07-16 10:03:32 +08:00
|
|
|
//===- llvm/unittest/Support/TimeValueTest.cpp - Time Value tests ---------===//
|
2010-11-25 03:20:05 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
2010-11-30 02:16:10 +08:00
|
|
|
#include "llvm/Support/TimeValue.h"
|
2010-11-25 03:20:05 +08:00
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
namespace {
|
|
|
|
|
2013-07-16 10:03:32 +08:00
|
|
|
TEST(TimeValue, time_t) {
|
2010-11-25 03:20:05 +08:00
|
|
|
sys::TimeValue now = sys::TimeValue::now();
|
2014-06-09 06:29:17 +08:00
|
|
|
time_t now_t = time(nullptr);
|
2014-02-27 03:12:28 +08:00
|
|
|
EXPECT_TRUE(std::abs(static_cast<long>(now_t - now.toEpochTime())) < 2);
|
2010-11-25 03:20:05 +08:00
|
|
|
}
|
|
|
|
|
2013-07-16 10:44:23 +08:00
|
|
|
TEST(TimeValue, Win32FILETIME) {
|
|
|
|
uint64_t epoch_as_filetime = 0x19DB1DED53E8000ULL;
|
|
|
|
uint32_t ns = 765432100;
|
|
|
|
sys::TimeValue epoch;
|
|
|
|
|
|
|
|
// FILETIME has 100ns of intervals.
|
|
|
|
uint64_t ft1970 = epoch_as_filetime + ns / 100;
|
|
|
|
epoch.fromWin32Time(ft1970);
|
|
|
|
|
|
|
|
// The "seconds" part in Posix time may be expected as zero.
|
2014-02-11 17:11:18 +08:00
|
|
|
EXPECT_EQ(0u, epoch.toEpochTime());
|
|
|
|
EXPECT_EQ(ns, static_cast<uint32_t>(epoch.nanoseconds()));
|
2013-07-16 10:44:23 +08:00
|
|
|
|
|
|
|
// Confirm it reversible.
|
|
|
|
EXPECT_EQ(ft1970, epoch.toWin32Time());
|
|
|
|
}
|
|
|
|
|
2010-11-25 03:20:05 +08:00
|
|
|
}
|