blob: 3d2b9780c069d3a7dbbe1373881d70a16306917c [file] [log] [blame]
NAKAMURA Takumiad187dd2013-07-16 02:03:32 +00001//===- llvm/unittest/Support/TimeValueTest.cpp - Time Value tests ---------===//
Michael J. Spencer98847782010-11-24 19:20:05 +00002//
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. Spencer447762d2010-11-29 18:16:10 +000011#include "llvm/Support/TimeValue.h"
Michael J. Spencer98847782010-11-24 19:20:05 +000012#include <time.h>
13
14using namespace llvm;
15namespace {
16
NAKAMURA Takumiad187dd2013-07-16 02:03:32 +000017TEST(TimeValue, time_t) {
Michael J. Spencer98847782010-11-24 19:20:05 +000018 sys::TimeValue now = sys::TimeValue::now();
Craig Topper66f09ad2014-06-08 22:29:17 +000019 time_t now_t = time(nullptr);
David Blaikie51a18402014-02-26 19:12:28 +000020 EXPECT_TRUE(std::abs(static_cast<long>(now_t - now.toEpochTime())) < 2);
Michael J. Spencer98847782010-11-24 19:20:05 +000021}
22
NAKAMURA Takumibe2978b2013-07-16 02:44:23 +000023TEST(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.
Dmitri Gribenko70e65852014-02-11 09:11:18 +000033 EXPECT_EQ(0u, epoch.toEpochTime());
34 EXPECT_EQ(ns, static_cast<uint32_t>(epoch.nanoseconds()));
NAKAMURA Takumibe2978b2013-07-16 02:44:23 +000035
36 // Confirm it reversible.
37 EXPECT_EQ(ft1970, epoch.toWin32Time());
38}
39
Michael J. Spencer98847782010-11-24 19:20:05 +000040}