TimeValueTest.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //===- llvm/unittest/Support/TimeValueTest.cpp - Time Value tests ---------===//
  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. #include "gtest/gtest.h"
  10. #include "llvm/Support/TimeValue.h"
  11. #include <time.h>
  12. using namespace llvm;
  13. namespace {
  14. TEST(TimeValue, time_t) {
  15. sys::TimeValue now = sys::TimeValue::now();
  16. time_t now_t = time(nullptr);
  17. EXPECT_TRUE(std::abs(static_cast<long>(now_t - now.toEpochTime())) < 2);
  18. }
  19. TEST(TimeValue, Win32FILETIME) {
  20. uint64_t epoch_as_filetime = 0x19DB1DED53E8000ULL;
  21. uint32_t ns = 765432100;
  22. sys::TimeValue epoch;
  23. // FILETIME has 100ns of intervals.
  24. uint64_t ft1970 = epoch_as_filetime + ns / 100;
  25. epoch.fromWin32Time(ft1970);
  26. // The "seconds" part in Posix time may be expected as zero.
  27. EXPECT_EQ(0u, epoch.toEpochTime());
  28. EXPECT_EQ(ns, static_cast<uint32_t>(epoch.nanoseconds()));
  29. // Confirm it reversible.
  30. EXPECT_EQ(ft1970, epoch.toWin32Time());
  31. }
  32. }