//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11 // // typedef TrivialClock file_time_type; // RUN: %build -I%libcxx_src_root/src/experimental/filesystem // RUN: %run #include #include #include #include #include #include #include "filesystem_time_helper.h" using namespace std::chrono; namespace fs = std::experimental::filesystem; using fs::file_time_type; using fs::fs_time_util; enum TestKind { TK_64Bit, TK_32Bit, TK_FloatingPoint }; template constexpr TestKind getTestKind() { if (sizeof(TimeT) == 8 && !std::is_floating_point::value) return TK_64Bit; else if (sizeof(TimeT) == 4 && !std::is_floating_point::value) return TK_32Bit; else if (std::is_floating_point::value) return TK_FloatingPoint; else assert(false && "test kind not supported"); } template , TestKind = getTestKind()> struct check_is_representable; template struct check_is_representable : public Base { using Base::convert_timespec; using Base::is_representable; using Base::max_nsec; using Base::max_seconds; using Base::min_nsec_timespec; using Base::min_seconds; static constexpr auto max_time_t = std::numeric_limits::max(); static constexpr auto min_time_t = std::numeric_limits::min(); static constexpr bool test_timespec() { static_assert(is_representable(TimeSpecT{max_seconds, max_nsec}), ""); static_assert(!is_representable(TimeSpecT{max_seconds + 1, 0}), ""); static_assert(!is_representable(TimeSpecT{max_seconds, max_nsec + 1}), ""); static_assert(!is_representable(TimeSpecT{max_time_t, 0}), ""); static_assert(is_representable(TimeSpecT{min_seconds, 0}), ""); static_assert( is_representable(TimeSpecT{min_seconds - 1, min_nsec_timespec}), ""); static_assert( is_representable(TimeSpecT{min_seconds - 1, min_nsec_timespec + 1}), ""); static_assert( !is_representable(TimeSpecT{min_seconds - 1, min_nsec_timespec - 1}), ""); static_assert(!is_representable(TimeSpecT{min_time_t, 999999999}), ""); return true; } static constexpr bool test_file_time_type() { static_assert(Base::is_representable(FileTimeT::max()), ""); static_assert(Base::is_representable(FileTimeT::min()), ""); return true; } static constexpr bool test_convert_timespec() { static_assert(convert_timespec(TimeSpecT{max_seconds, max_nsec}) == FileTimeT::max(), ""); static_assert(convert_timespec(TimeSpecT{max_seconds, max_nsec - 1}) < FileTimeT::max(), ""); static_assert(convert_timespec(TimeSpecT{max_seconds - 1, 999999999}) < FileTimeT::max(), ""); static_assert(convert_timespec(TimeSpecT{ min_seconds - 1, min_nsec_timespec}) == FileTimeT::min(), ""); static_assert( convert_timespec(TimeSpecT{min_seconds - 1, min_nsec_timespec + 1}) > FileTimeT::min(), ""); static_assert( convert_timespec(TimeSpecT{min_seconds, 0}) > FileTimeT::min(), ""); return true; } static bool test() { static_assert(test_timespec(), ""); static_assert(test_file_time_type(), ""); static_assert(test_convert_timespec(), ""); return true; } }; template struct check_is_representable : public Base { static constexpr auto max_time_t = std::numeric_limits::max(); static constexpr auto min_time_t = std::numeric_limits::min(); using Base::convert_timespec; using Base::is_representable; using Base::max_nsec; using Base::max_seconds; using Base::min_nsec_timespec; using Base::min_seconds; static constexpr bool test_timespec() { static_assert(is_representable(TimeSpecT{max_time_t, 999999999}), ""); static_assert(is_representable(TimeSpecT{max_time_t, 1000000000}), ""); static_assert(is_representable(TimeSpecT{min_time_t, 0}), ""); return true; } static constexpr bool test_file_time_type() { static_assert(!is_representable(FileTimeT::max()), ""); static_assert(!is_representable(FileTimeT::min()), ""); static_assert(is_representable(FileTimeT(seconds(max_time_t))), ""); static_assert(is_representable(FileTimeT(seconds(min_time_t))), ""); return true; } static constexpr bool test_convert_timespec() { // FIXME add tests for 32 bit builds return true; } static bool test() { static_assert(test_timespec(), ""); static_assert(test_file_time_type(), ""); static_assert(test_convert_timespec(), ""); return true; } }; template struct check_is_representable : public Base { static bool test() { return true; } }; template struct TestTimeSpec { TimeT tv_sec; NSecT tv_nsec; }; template struct TestClock { typedef Dur duration; typedef typename duration::rep rep; typedef typename duration::period period; typedef std::chrono::time_point time_point; static constexpr const bool is_steady = false; static time_point now() noexcept { return {}; } }; template > using TestFileTimeT = time_point >; int main() { assert(( check_is_representable::test())); assert((check_is_representable, int64_t, TestTimeSpec >::test())); assert((check_is_representable, int32_t, TestTimeSpec >::test())); // Test that insane platforms like ppc64 linux, which use long double as time_t, // at least compile. assert((check_is_representable, double, TestTimeSpec >::test())); }