diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:54:09 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:54:09 +0000 |
| commit | b4c64ad90b81d2a779786b7edb4c5c6dd28cc57d (patch) | |
| tree | 13f237c02db4d1894ab06884d1b739344766bede /test/std/utilities/time | |
| parent | 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (diff) | |
Notes
Diffstat (limited to 'test/std/utilities/time')
16 files changed, 633 insertions, 0 deletions
diff --git a/test/std/utilities/time/date.time/ctime.pass.cpp b/test/std/utilities/time/date.time/ctime.pass.cpp new file mode 100644 index 000000000000..d0a838e0c271 --- /dev/null +++ b/test/std/utilities/time/date.time/ctime.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#include <ctime> +#include <type_traits> + +#ifndef NULL +#error NULL not defined +#endif + +#ifndef CLOCKS_PER_SEC +#error CLOCKS_PER_SEC not defined +#endif + +int main() +{ + std::clock_t c = 0; + ((void)c); // avoid unused warning + std::size_t s = 0; + std::time_t t = 0; + std::tm tm = {0}; + char str[3]; + static_assert((std::is_same<decltype(std::clock()), std::clock_t>::value), ""); + static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), ""); + static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), ""); + static_assert((std::is_same<decltype(std::time(&t)), std::time_t>::value), ""); +#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS + static_assert((std::is_same<decltype(std::asctime(&tm)), char*>::value), ""); + static_assert((std::is_same<decltype(std::ctime(&t)), char*>::value), ""); + static_assert((std::is_same<decltype(std::gmtime(&t)), std::tm*>::value), ""); + static_assert((std::is_same<decltype(std::localtime(&t)), std::tm*>::value), ""); +#endif + static_assert((std::is_same<decltype(std::strftime(str,s,"",&tm)), std::size_t>::value), ""); +} diff --git a/test/std/utilities/time/time.duration/time.duration.alg/abs.fail.cpp b/test/std/utilities/time/time.duration/time.duration.alg/abs.fail.cpp new file mode 100644 index 000000000000..221004c568ce --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.alg/abs.fail.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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++03, c++11, c++14 +// <chrono> + +// ceil + +// template <class Rep, class Period> +// constexpr duration<Rep, Period> abs(duration<Rep, Period> d) + +// This function shall not participate in overload resolution unless numeric_limits<Rep>::is_signed is true. + +#include <chrono> + +typedef std::chrono::duration<unsigned> unsigned_secs; + +int main() +{ + std::chrono::abs(unsigned_secs(0)); +} diff --git a/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp b/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp new file mode 100644 index 000000000000..ec32c37a9423 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// 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++03, c++11, c++14 + +// <chrono> + +// abs + +// template <class Rep, class Period> +// constexpr duration<Rep, Period> abs(duration<Rep, Period> d) + +#include <chrono> +#include <type_traits> +#include <cassert> + +template <class Duration> +void +test(const Duration& f, const Duration& d) +{ + { + typedef decltype(std::chrono::abs(f)) R; + static_assert((std::is_same<R, Duration>::value), ""); + assert(std::chrono::abs(f) == d); + } +} + +int main() +{ +// 7290000ms is 2 hours, 1 minute, and 30 seconds + test(std::chrono::milliseconds( 7290000), std::chrono::milliseconds( 7290000)); + test(std::chrono::milliseconds(-7290000), std::chrono::milliseconds( 7290000)); + test(std::chrono::minutes( 122), std::chrono::minutes( 122)); + test(std::chrono::minutes(-122), std::chrono::minutes( 122)); + test(std::chrono::hours(0), std::chrono::hours(0)); + + { +// 9000000ms is 2 hours and 30 minutes + constexpr std::chrono::hours h1 = std::chrono::abs(std::chrono::hours(-3)); + static_assert(h1.count() == 3, ""); + constexpr std::chrono::hours h2 = std::chrono::abs(std::chrono::hours(3)); + static_assert(h2.count() == 3, ""); + } +} diff --git a/test/std/utilities/time/time.duration/time.duration.cast/ceil.fail.cpp b/test/std/utilities/time/time.duration/time.duration.cast/ceil.fail.cpp new file mode 100644 index 000000000000..909e8573247c --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cast/ceil.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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++03, c++11, c++14 +// <chrono> + +// ceil + +// template <class ToDuration, class Rep, class Period> +// ToDuration +// ceil(const duration<Rep, Period>& d); + +// ToDuration shall be an instantiation of duration. + +#include <chrono> + +int main() +{ + std::chrono::ceil<int>(std::chrono::milliseconds(3)); +} diff --git a/test/std/utilities/time/time.duration/time.duration.cast/ceil.pass.cpp b/test/std/utilities/time/time.duration/time.duration.cast/ceil.pass.cpp new file mode 100644 index 000000000000..6fb73b97db17 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cast/ceil.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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++03, c++11, c++14 + +// <chrono> + +// ceil + +// template <class ToDuration, class Rep, class Period> +// constexpr +// ToDuration +// ceil(const duration<Rep, Period>& d); + +#include <chrono> +#include <type_traits> +#include <cassert> + +template <class ToDuration, class FromDuration> +void +test(const FromDuration& f, const ToDuration& d) +{ + { + typedef decltype(std::chrono::ceil<ToDuration>(f)) R; + static_assert((std::is_same<R, ToDuration>::value), ""); + assert(std::chrono::ceil<ToDuration>(f) == d); + } +} + +int main() +{ +// 7290000ms is 2 hours, 1 minute, and 30 seconds + test(std::chrono::milliseconds( 7290000), std::chrono::hours( 3)); + test(std::chrono::milliseconds(-7290000), std::chrono::hours(-2)); + test(std::chrono::milliseconds( 7290000), std::chrono::minutes( 122)); + test(std::chrono::milliseconds(-7290000), std::chrono::minutes(-121)); + + { +// 9000000ms is 2 hours and 30 minutes + constexpr std::chrono::hours h1 = std::chrono::ceil<std::chrono::hours>(std::chrono::milliseconds(9000000)); + static_assert(h1.count() == 3, ""); + constexpr std::chrono::hours h2 = std::chrono::ceil<std::chrono::hours>(std::chrono::milliseconds(-9000000)); + static_assert(h2.count() == -2, ""); + } +} diff --git a/test/std/utilities/time/time.duration/time.duration.cast/floor.fail.cpp b/test/std/utilities/time/time.duration/time.duration.cast/floor.fail.cpp new file mode 100644 index 000000000000..14d9ca878df8 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cast/floor.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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++03, c++11, c++14 +// <chrono> + +// floor + +// template <class ToDuration, class Rep, class Period> +// ToDuration +// floor(const duration<Rep, Period>& d); + +// ToDuration shall be an instantiation of duration. + +#include <chrono> + +int main() +{ + std::chrono::floor<int>(std::chrono::milliseconds(3)); +} diff --git a/test/std/utilities/time/time.duration/time.duration.cast/floor.pass.cpp b/test/std/utilities/time/time.duration/time.duration.cast/floor.pass.cpp new file mode 100644 index 000000000000..57929dd91228 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cast/floor.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// 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++03, c++11, c++14 +// <chrono> + +// floor + +// template <class ToDuration, class Rep, class Period> +// constexpr +// ToDuration +// floor(const duration<Rep, Period>& d); + +#include <chrono> +#include <type_traits> +#include <cassert> + +template <class ToDuration, class FromDuration> +void +test(const FromDuration& f, const ToDuration& d) +{ + { + typedef decltype(std::chrono::floor<ToDuration>(f)) R; + static_assert((std::is_same<R, ToDuration>::value), ""); + assert(std::chrono::floor<ToDuration>(f) == d); + } +} + +int main() +{ +// 7290000ms is 2 hours, 1 minute, and 30 seconds + test(std::chrono::milliseconds( 7290000), std::chrono::hours( 2)); + test(std::chrono::milliseconds(-7290000), std::chrono::hours(-3)); + test(std::chrono::milliseconds( 7290000), std::chrono::minutes( 121)); + test(std::chrono::milliseconds(-7290000), std::chrono::minutes(-122)); + + { +// 9000000ms is 2 hours and 30 minutes + constexpr std::chrono::hours h1 = std::chrono::floor<std::chrono::hours>(std::chrono::milliseconds(9000000)); + static_assert(h1.count() == 2, ""); + constexpr std::chrono::hours h2 = std::chrono::floor<std::chrono::hours>(std::chrono::milliseconds(-9000000)); + static_assert(h2.count() == -3, ""); + } +} diff --git a/test/std/utilities/time/time.duration/time.duration.cast/round.fail.cpp b/test/std/utilities/time/time.duration/time.duration.cast/round.fail.cpp new file mode 100644 index 000000000000..6f9f5bd29b63 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cast/round.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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++03, c++11, c++14 +// <chrono> + +// round + +// template <class ToDuration, class Rep, class Period> +// ToDuration +// round(const duration<Rep, Period>& d); + +// ToDuration shall be an instantiation of duration. + +#include <chrono> + +int main() +{ + std::chrono::round<int>(std::chrono::milliseconds(3)); +} diff --git a/test/std/utilities/time/time.duration/time.duration.cast/round.pass.cpp b/test/std/utilities/time/time.duration/time.duration.cast/round.pass.cpp new file mode 100644 index 000000000000..e50b85c991a2 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cast/round.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// 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++03, c++11, c++14 +// <chrono> + +// round + +// template <class ToDuration, class Rep, class Period> +// constexpr +// ToDuration +// ceil(const duration<Rep, Period>& d); + +#include <chrono> +#include <type_traits> +#include <cassert> + +template <class ToDuration, class FromDuration> +void +test(const FromDuration& f, const ToDuration& d) +{ + { + typedef decltype(std::chrono::round<ToDuration>(f)) R; + static_assert((std::is_same<R, ToDuration>::value), ""); + assert(std::chrono::round<ToDuration>(f) == d); + } +} + +int main() +{ +// 7290000ms is 2 hours, 1 minute, and 30 seconds + test(std::chrono::milliseconds( 7290000), std::chrono::hours( 2)); + test(std::chrono::milliseconds(-7290000), std::chrono::hours(-2)); + test(std::chrono::milliseconds( 7290000), std::chrono::minutes( 122)); + test(std::chrono::milliseconds(-7290000), std::chrono::minutes(-122)); + + { +// 9000000ms is 2 hours and 30 minutes + constexpr std::chrono::hours h1 = std::chrono::round<std::chrono::hours>(std::chrono::milliseconds(9000000)); + static_assert(h1.count() == 2, ""); + constexpr std::chrono::hours h2 = std::chrono::round<std::chrono::hours>(std::chrono::milliseconds(-9000000)); + static_assert(h2.count() == -2, ""); + } +} diff --git a/test/std/utilities/time/time.point/time.point.cast/ceil.fail.cpp b/test/std/utilities/time/time.point/time.point.cast/ceil.fail.cpp new file mode 100644 index 000000000000..1c92d75b97ca --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cast/ceil.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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++03, c++11, c++14 +// <chrono> + +// ceil + +// template <class ToDuration, class Clock, class Duration> +// time_point<Clock, ToDuration> +// ceil(const time_point<Clock, Duration>& t); + +// ToDuration shall be an instantiation of duration. + +#include <chrono> + +int main() +{ + std::chrono::ceil<int>(std::chrono::system_clock::now()); +} diff --git a/test/std/utilities/time/time.point/time.point.cast/ceil.pass.cpp b/test/std/utilities/time/time.point/time.point.cast/ceil.pass.cpp new file mode 100644 index 000000000000..379929c7f2d8 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cast/ceil.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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++03, c++11, c++14 +// <chrono> + +// ceil + +// template <class ToDuration, class Clock, class Duration> +// time_point<Clock, ToDuration> +// ceil(const time_point<Clock, Duration>& t); + +#include <chrono> +#include <type_traits> +#include <cassert> + +template <class FromDuration, class ToDuration> +void +test(const FromDuration& df, const ToDuration& d) +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::time_point<Clock, FromDuration> FromTimePoint; + typedef std::chrono::time_point<Clock, ToDuration> ToTimePoint; + { + FromTimePoint f(df); + ToTimePoint t(d); + typedef decltype(std::chrono::ceil<ToDuration>(f)) R; + static_assert((std::is_same<R, ToTimePoint>::value), ""); + assert(std::chrono::ceil<ToDuration>(f) == t); + } +} + +template<class FromDuration, long long From, class ToDuration, long long To> +void test_constexpr () +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::time_point<Clock, FromDuration> FromTimePoint; + typedef std::chrono::time_point<Clock, ToDuration> ToTimePoint; + { + constexpr FromTimePoint f{FromDuration{From}}; + constexpr ToTimePoint t{ToDuration{To}}; + static_assert(std::chrono::ceil<ToDuration>(f) == t, ""); + } +} + + +int main() +{ +// 7290000ms is 2 hours, 1 minute, and 30 seconds + test(std::chrono::milliseconds( 7290000), std::chrono::hours( 3)); + test(std::chrono::milliseconds(-7290000), std::chrono::hours(-2)); + test(std::chrono::milliseconds( 7290000), std::chrono::minutes( 122)); + test(std::chrono::milliseconds(-7290000), std::chrono::minutes(-121)); + +// 9000000ms is 2 hours and 30 minutes + test_constexpr<std::chrono::milliseconds, 9000000, std::chrono::hours, 3> (); + test_constexpr<std::chrono::milliseconds,-9000000, std::chrono::hours, -2> (); + test_constexpr<std::chrono::milliseconds, 9000001, std::chrono::minutes, 151> (); + test_constexpr<std::chrono::milliseconds,-9000001, std::chrono::minutes,-150> (); + + test_constexpr<std::chrono::milliseconds, 9000000, std::chrono::seconds, 9000> (); + test_constexpr<std::chrono::milliseconds,-9000000, std::chrono::seconds,-9000> (); +} diff --git a/test/std/utilities/time/time.point/time.point.cast/floor.fail.cpp b/test/std/utilities/time/time.point/time.point.cast/floor.fail.cpp new file mode 100644 index 000000000000..ea48e1219e34 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cast/floor.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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++03, c++11, c++14 +// <chrono> + +// floor + +// template <class ToDuration, class Clock, class Duration> +// time_point<Clock, ToDuration> +// floor(const time_point<Clock, Duration>& t); + +// ToDuration shall be an instantiation of duration. + +#include <chrono> + +int main() +{ + std::chrono::floor<int>(std::chrono::system_clock::now()); +} diff --git a/test/std/utilities/time/time.point/time.point.cast/floor.pass.cpp b/test/std/utilities/time/time.point/time.point.cast/floor.pass.cpp new file mode 100644 index 000000000000..d0a908fa932a --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cast/floor.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// 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++03, c++11, c++14 +// <chrono> + +// floor + +// template <class ToDuration, class Clock, class Duration> +// time_point<Clock, ToDuration> +// floor(const time_point<Clock, Duration>& t); + +#include <chrono> +#include <type_traits> +#include <cassert> + +template <class FromDuration, class ToDuration> +void +test(const FromDuration& df, const ToDuration& d) +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::time_point<Clock, FromDuration> FromTimePoint; + typedef std::chrono::time_point<Clock, ToDuration> ToTimePoint; + { + FromTimePoint f(df); + ToTimePoint t(d); + typedef decltype(std::chrono::floor<ToDuration>(f)) R; + static_assert((std::is_same<R, ToTimePoint>::value), ""); + assert(std::chrono::floor<ToDuration>(f) == t); + } +} + +template<class FromDuration, long long From, class ToDuration, long long To> +void test_constexpr () +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::time_point<Clock, FromDuration> FromTimePoint; + typedef std::chrono::time_point<Clock, ToDuration> ToTimePoint; + { + constexpr FromTimePoint f{FromDuration{From}}; + constexpr ToTimePoint t{ToDuration{To}}; + static_assert(std::chrono::floor<ToDuration>(f) == t, ""); + } +} + +int main() +{ +// 7290000ms is 2 hours, 1 minute, and 30 seconds + test(std::chrono::milliseconds( 7290000), std::chrono::hours( 2)); + test(std::chrono::milliseconds(-7290000), std::chrono::hours(-3)); + test(std::chrono::milliseconds( 7290000), std::chrono::minutes( 121)); + test(std::chrono::milliseconds(-7290000), std::chrono::minutes(-122)); + +// 9000000ms is 2 hours and 30 minutes + test_constexpr<std::chrono::milliseconds, 9000000, std::chrono::hours, 2> (); + test_constexpr<std::chrono::milliseconds,-9000000, std::chrono::hours, -3> (); + test_constexpr<std::chrono::milliseconds, 9000001, std::chrono::minutes, 150> (); + test_constexpr<std::chrono::milliseconds,-9000001, std::chrono::minutes,-151> (); + + test_constexpr<std::chrono::milliseconds, 9000000, std::chrono::seconds, 9000> (); + test_constexpr<std::chrono::milliseconds,-9000000, std::chrono::seconds,-9000> (); +} diff --git a/test/std/utilities/time/time.point/time.point.cast/round.fail.cpp b/test/std/utilities/time/time.point/time.point.cast/round.fail.cpp new file mode 100644 index 000000000000..53c14f47de69 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cast/round.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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++03, c++11, c++14 +// <chrono> + +// round + +// template <class ToDuration, class Clock, class Duration> +// time_point<Clock, ToDuration> +// round(const time_point<Clock, Duration>& t); + +// ToDuration shall be an instantiation of duration. + +#include <chrono> + +int main() +{ + std::chrono::round<int>(std::chrono::system_clock::now()); +} diff --git a/test/std/utilities/time/time.point/time.point.cast/round.pass.cpp b/test/std/utilities/time/time.point/time.point.cast/round.pass.cpp new file mode 100644 index 000000000000..ab8bf3a75e79 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cast/round.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// 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++03, c++11, c++14 +// <chrono> + +// round + +// template <class ToDuration, class Clock, class Duration> +// time_point<Clock, ToDuration> +// round(const time_point<Clock, Duration>& t); + +#include <chrono> +#include <type_traits> +#include <cassert> + +template <class FromDuration, class ToDuration> +void +test(const FromDuration& df, const ToDuration& d) +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::time_point<Clock, FromDuration> FromTimePoint; + typedef std::chrono::time_point<Clock, ToDuration> ToTimePoint; + { + FromTimePoint f(df); + ToTimePoint t(d); + typedef decltype(std::chrono::round<ToDuration>(f)) R; + static_assert((std::is_same<R, ToTimePoint>::value), ""); + assert(std::chrono::round<ToDuration>(f) == t); + } +} + +template<class FromDuration, long long From, class ToDuration, long long To> +void test_constexpr () +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::time_point<Clock, FromDuration> FromTimePoint; + typedef std::chrono::time_point<Clock, ToDuration> ToTimePoint; + { + constexpr FromTimePoint f{FromDuration{From}}; + constexpr ToTimePoint t{ToDuration{To}}; + static_assert(std::chrono::round<ToDuration>(f) == t, ""); + } +} + +int main() +{ +// 7290000ms is 2 hours, 1 minute, and 30 seconds + test(std::chrono::milliseconds( 7290000), std::chrono::hours( 2)); + test(std::chrono::milliseconds(-7290000), std::chrono::hours(-2)); + test(std::chrono::milliseconds( 7290000), std::chrono::minutes( 122)); + test(std::chrono::milliseconds(-7290000), std::chrono::minutes(-122)); + +// 9000000ms is 2 hours and 30 minutes + test_constexpr<std::chrono::milliseconds, 9000000, std::chrono::hours, 2> (); + test_constexpr<std::chrono::milliseconds,-9000000, std::chrono::hours, -2> (); + test_constexpr<std::chrono::milliseconds, 9000001, std::chrono::minutes, 150> (); + test_constexpr<std::chrono::milliseconds,-9000001, std::chrono::minutes,-150> (); + + test_constexpr<std::chrono::milliseconds, 9000000, std::chrono::seconds, 9000> (); + test_constexpr<std::chrono::milliseconds,-9000000, std::chrono::seconds,-9000> (); +} diff --git a/test/std/utilities/time/time.traits/time.traits.is_fp/treat_as_floating_point.pass.cpp b/test/std/utilities/time/time.traits/time.traits.is_fp/treat_as_floating_point.pass.cpp index c32350faa83b..f9ddc87a7a14 100644 --- a/test/std/utilities/time/time.traits/time.traits.is_fp/treat_as_floating_point.pass.cpp +++ b/test/std/utilities/time/time.traits/time.traits.is_fp/treat_as_floating_point.pass.cpp @@ -20,6 +20,10 @@ test() { static_assert((std::is_base_of<std::is_floating_point<T>, std::chrono::treat_as_floating_point<T> >::value), ""); +#if TEST_STD_VER > 14 + static_assert((std::is_base_of<std::is_floating_point<T>, + std::chrono::treat_as_floating_point_v<T> >), ""); +#endif } struct A {}; |
