diff options
Diffstat (limited to 'libcxx/test/std/utilities')
15 files changed, 782 insertions, 0 deletions
diff --git a/libcxx/test/std/utilities/time/time.hms/hhmmss.fail.cpp b/libcxx/test/std/utilities/time/time.hms/hhmmss.fail.cpp new file mode 100644 index 00000000000..8849831d915 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.hms/hhmmss.fail.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// <chrono> + +// template <class Duration> class hh_mm_ss; +// If Duration is not an instance of duration, the program is ill-formed. + +#include <chrono> +#include <string> +#include <cassert> +#include "test_macros.h" + +struct A {}; + +int main(int, char**) +{ + std::chrono::hh_mm_ss<void> h0; // expected-error-re@chrono:* {{static_assert failed {{.*}} "template parameter of hh_mm_ss must be a std::chrono::duration"}} + std::chrono::hh_mm_ss<int> h1; // expected-error-re@chrono:* {{static_assert failed {{.*}} "template parameter of hh_mm_ss must be a std::chrono::duration"}} + std::chrono::hh_mm_ss<std::string> h2; // expected-error-re@chrono:* {{static_assert failed {{.*}} "template parameter of hh_mm_ss must be a std::chrono::duration"}} + std::chrono::hh_mm_ss<A> h3; // expected-error-re@chrono:* {{static_assert failed {{.*}} "template parameter of hh_mm_ss must be a std::chrono::duration"}} + + return 0; +} diff --git a/libcxx/test/std/utilities/time/time.hms/time.12/is_am.pass.cpp b/libcxx/test/std/utilities/time/time.hms/time.12/is_am.pass.cpp new file mode 100644 index 00000000000..f10707b2c5c --- /dev/null +++ b/libcxx/test/std/utilities/time/time.hms/time.12/is_am.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// <chrono> + +// constexpr bool is_am(const hours& h) noexcept; +// Returns: 0h <= h && h <= 11h. + +#include <chrono> +#include <cassert> + +#include "test_macros.h" + +int main(int, char**) +{ + using hours = std::chrono::hours; + ASSERT_SAME_TYPE(bool, decltype(std::chrono::is_am(std::declval<hours>()))); + ASSERT_NOEXCEPT( std::chrono::is_am(std::declval<hours>())); + + static_assert( std::chrono::is_am(hours( 0)), ""); + static_assert( std::chrono::is_am(hours(11)), ""); + static_assert(!std::chrono::is_am(hours(12)), ""); + static_assert(!std::chrono::is_am(hours(23)), ""); + + for (int i = 0; i < 12; ++i) + assert( std::chrono::is_am(hours(i))); + for (int i = 12; i < 24; ++i) + assert(!std::chrono::is_am(hours(i))); + + return 0; +} diff --git a/libcxx/test/std/utilities/time/time.hms/time.12/is_pm.pass.cpp b/libcxx/test/std/utilities/time/time.hms/time.12/is_pm.pass.cpp new file mode 100644 index 00000000000..7dcc768f8d0 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.hms/time.12/is_pm.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// <chrono> + +// constexpr bool is_pm(const hours& h) noexcept; +// Returns: 12h <= h && h <= 23 + +#include <chrono> +#include <cassert> + +#include "test_macros.h" + +int main(int, char**) +{ + using hours = std::chrono::hours; + ASSERT_SAME_TYPE(bool, decltype(std::chrono::is_pm(std::declval<hours>()))); + ASSERT_NOEXCEPT( std::chrono::is_pm(std::declval<hours>())); + + static_assert(!std::chrono::is_pm(hours( 0)), ""); + static_assert(!std::chrono::is_pm(hours(11)), ""); + static_assert( std::chrono::is_pm(hours(12)), ""); + static_assert( std::chrono::is_pm(hours(23)), ""); + + for (int i = 0; i < 12; ++i) + assert(!std::chrono::is_pm(hours(i))); + for (int i = 12; i < 24; ++i) + assert( std::chrono::is_pm(hours(i))); + + return 0; +} diff --git a/libcxx/test/std/utilities/time/time.hms/time.12/make12.pass.cpp b/libcxx/test/std/utilities/time/time.hms/time.12/make12.pass.cpp new file mode 100644 index 00000000000..bca956802f9 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.hms/time.12/make12.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// <chrono> + +// constexpr hours make12(const hours& h) noexcept; +// Returns: The 12-hour equivalent of h in the range [1h, 12h]. +// If h is not in the range [0h, 23h], the value returned is unspecified. + +#include <chrono> +#include <cassert> + +#include "test_macros.h" + +int main(int, char**) +{ + using hours = std::chrono::hours; + ASSERT_SAME_TYPE(hours, decltype(std::chrono::make12(std::declval<hours>()))); + ASSERT_NOEXCEPT( std::chrono::make12(std::declval<hours>())); + + static_assert( std::chrono::make12(hours( 0)) == hours(12), ""); + static_assert( std::chrono::make12(hours(11)) == hours(11), ""); + static_assert( std::chrono::make12(hours(12)) == hours(12), ""); + static_assert( std::chrono::make12(hours(23)) == hours(11), ""); + + assert( std::chrono::make12(hours(0)) == hours(12)); + for (int i = 1; i < 13; ++i) + assert( std::chrono::make12(hours(i)) == hours(i)); + for (int i = 13; i < 24; ++i) + assert( std::chrono::make12(hours(i)) == hours(i-12)); + + return 0; +} diff --git a/libcxx/test/std/utilities/time/time.hms/time.12/make24.pass.cpp b/libcxx/test/std/utilities/time/time.hms/time.12/make24.pass.cpp new file mode 100644 index 00000000000..46a5419076f --- /dev/null +++ b/libcxx/test/std/utilities/time/time.hms/time.12/make24.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// <chrono> + +// constexpr hours make24(const hours& h, bool is_pm) noexcept; +// Returns: If is_pm is false, returns the 24-hour equivalent of h in the range [0h, 11h], +// assuming h represents an ante meridiem hour. +// Else returns the 24-hour equivalent of h in the range [12h, 23h], +// assuming h represents a post meridiem hour. +// If h is not in the range [1h, 12h], the value returned is unspecified. + +#include <chrono> +#include <cassert> + +#include "test_macros.h" + +int main(int, char**) +{ + using hours = std::chrono::hours; + ASSERT_SAME_TYPE(hours, decltype(std::chrono::make24(std::declval<hours>(), false))); + ASSERT_NOEXCEPT( std::chrono::make24(std::declval<hours>(), false)); + + static_assert( std::chrono::make24(hours( 1), false) == hours( 1), ""); + static_assert( std::chrono::make24(hours(11), false) == hours(11), ""); + static_assert( std::chrono::make24(hours(12), false) == hours( 0), ""); + static_assert( std::chrono::make24(hours( 1), true) == hours(13), ""); + static_assert( std::chrono::make24(hours(11), true) == hours(23), ""); + static_assert( std::chrono::make24(hours(12), true) == hours(12), ""); + + for (int i = 1; i < 11; ++i) + { + assert((std::chrono::make24(hours(i), false)) == hours(i)); + assert((std::chrono::make24(hours(i), true)) == hours(12+i)); + } + assert((std::chrono::make24(hours(12), false)) == hours( 0)); + assert((std::chrono::make24(hours(12), true)) == hours(12)); + + return 0; +} diff --git a/libcxx/test/std/utilities/time/time.hms/time.hms.members/hours.pass.cpp b/libcxx/test/std/utilities/time/time.hms/time.hms.members/hours.pass.cpp new file mode 100644 index 00000000000..45eb67755a3 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.hms/time.hms.members/hours.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// <chrono> + +// template <class Duration> +// class hh_mm_ss +// +// constexpr chrono::hours hours() const noexcept; + +// Test values +// duration hours minutes seconds fractional +// 5000s 1 23 20 0 +// 5000 minutes 83 20 0 0 +// 123456789ms 34 17 36 789ms +// 123456789us 0 2 3 456789us +// 123456789ns 0 0 0 123456789ns +// 1000mfn 0 20 9 0.6 (6000/10000) +// 10000mfn 3 21 36 0 + + +#include <chrono> +#include <cassert> + +#include "test_macros.h" + +template <typename Duration> +constexpr long check_hours(Duration d) +{ + using HMS = std::chrono::hh_mm_ss<Duration>; + ASSERT_SAME_TYPE(std::chrono::hours, decltype(std::declval<HMS>().hours())); + ASSERT_NOEXCEPT( std::declval<HMS>().hours()); + return HMS(d).hours().count(); +} + +int main(int, char**) +{ + using microfortnights = std::chrono::duration<int, std::ratio<756, 625>>; + + static_assert( check_hours(std::chrono::minutes( 1)) == 0, ""); + static_assert( check_hours(std::chrono::minutes(-1)) == 0, ""); + + assert( check_hours(std::chrono::seconds( 5000)) == 1); + assert( check_hours(std::chrono::seconds(-5000)) == 1); + assert( check_hours(std::chrono::minutes( 5000)) == 83); + assert( check_hours(std::chrono::minutes(-5000)) == 83); + assert( check_hours(std::chrono::hours( 11)) == 11); + assert( check_hours(std::chrono::hours(-11)) == 11); + + assert( check_hours(std::chrono::milliseconds( 123456789LL)) == 34); + assert( check_hours(std::chrono::milliseconds(-123456789LL)) == 34); + assert( check_hours(std::chrono::microseconds( 123456789LL)) == 0); + assert( check_hours(std::chrono::microseconds(-123456789LL)) == 0); + assert( check_hours(std::chrono::nanoseconds( 123456789LL)) == 0); + assert( check_hours(std::chrono::nanoseconds(-123456789LL)) == 0); + + assert( check_hours(microfortnights( 1000)) == 0); + assert( check_hours(microfortnights( -1000)) == 0); + assert( check_hours(microfortnights( 10000)) == 3); + assert( check_hours(microfortnights(-10000)) == 3); + + return 0; +} diff --git a/libcxx/test/std/utilities/time/time.hms/time.hms.members/is_negative.pass.cpp b/libcxx/test/std/utilities/time/time.hms/time.hms.members/is_negative.pass.cpp new file mode 100644 index 00000000000..6f82fbe6624 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.hms/time.hms.members/is_negative.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// <chrono> + +// template <class Duration> +// class hh_mm_ss +// +// constexpr bool is_negative() const noexcept; + +#include <chrono> +#include <cassert> + +#include "test_macros.h" + +template <typename Duration> +constexpr bool check_neg(Duration d) +{ + ASSERT_SAME_TYPE(bool, decltype(std::declval<std::chrono::hh_mm_ss<Duration>>().is_negative())); + ASSERT_NOEXCEPT( std::declval<std::chrono::hh_mm_ss<Duration>>().is_negative()); + return std::chrono::hh_mm_ss<Duration>(d).is_negative(); +} + +int main(int, char**) +{ + using microfortnights = std::chrono::duration<int, std::ratio<756, 625>>; + + static_assert(!check_neg(std::chrono::minutes( 1)), ""); + static_assert( check_neg(std::chrono::minutes(-1)), ""); + + assert(!check_neg(std::chrono::seconds( 5000))); + assert( check_neg(std::chrono::seconds(-5000))); + assert(!check_neg(std::chrono::minutes( 5000))); + assert( check_neg(std::chrono::minutes(-5000))); + assert(!check_neg(std::chrono::hours( 11))); + assert( check_neg(std::chrono::hours(-11))); + + assert(!check_neg(std::chrono::milliseconds( 123456789LL))); + assert( check_neg(std::chrono::milliseconds(-123456789LL))); + assert(!check_neg(std::chrono::microseconds( 123456789LL))); + assert( check_neg(std::chrono::microseconds(-123456789LL))); + assert(!check_neg(std::chrono::nanoseconds( 123456789LL))); + assert( check_neg(std::chrono::nanoseconds(-123456789LL))); + + assert(!check_neg(microfortnights( 10000))); + assert( check_neg(microfortnights(-10000))); + + return 0; +} diff --git a/libcxx/test/std/utilities/time/time.hms/time.hms.members/minutes.pass.cpp b/libcxx/test/std/utilities/time/time.hms/time.hms.members/minutes.pass.cpp new file mode 100644 index 00000000000..a3ecc814e35 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.hms/time.hms.members/minutes.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// <chrono> + +// template <class Duration> +// class hh_mm_ss +// +// constexpr chrono::minutes minutes() const noexcept; +// +// See the table in hours.pass.cpp for correspondence between the magic values used below + +#include <chrono> +#include <cassert> + +#include "test_macros.h" + +template <typename Duration> +constexpr long check_minutes(Duration d) +{ + using HMS = std::chrono::hh_mm_ss<Duration>; + ASSERT_SAME_TYPE(std::chrono::minutes, decltype(std::declval<HMS>().minutes())); + ASSERT_NOEXCEPT( std::declval<HMS>().minutes()); + return HMS(d).minutes().count(); +} + +int main(int, char**) +{ + using microfortnights = std::chrono::duration<int, std::ratio<756, 625>>; + + static_assert( check_minutes(std::chrono::minutes( 1)) == 1, ""); + static_assert( check_minutes(std::chrono::minutes(-1)) == 1, ""); + + assert( check_minutes(std::chrono::seconds( 5000)) == 23); + assert( check_minutes(std::chrono::seconds(-5000)) == 23); + assert( check_minutes(std::chrono::minutes( 5000)) == 20); + assert( check_minutes(std::chrono::minutes(-5000)) == 20); + assert( check_minutes(std::chrono::hours( 11)) == 0); + assert( check_minutes(std::chrono::hours(-11)) == 0); + + assert( check_minutes(std::chrono::milliseconds( 123456789LL)) == 17); + assert( check_minutes(std::chrono::milliseconds(-123456789LL)) == 17); + assert( check_minutes(std::chrono::microseconds( 123456789LL)) == 2); + assert( check_minutes(std::chrono::microseconds(-123456789LL)) == 2); + assert( check_minutes(std::chrono::nanoseconds( 123456789LL)) == 0); + assert( check_minutes(std::chrono::nanoseconds(-123456789LL)) == 0); + + assert( check_minutes(microfortnights( 1000)) == 20); + assert( check_minutes(microfortnights( -1000)) == 20); + assert( check_minutes(microfortnights( 10000)) == 21); + assert( check_minutes(microfortnights(-10000)) == 21); + + return 0; +} diff --git a/libcxx/test/std/utilities/time/time.hms/time.hms.members/precision.pass.cpp b/libcxx/test/std/utilities/time/time.hms/time.hms.members/precision.pass.cpp new file mode 100644 index 00000000000..58e0484c908 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.hms/time.hms.members/precision.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// <chrono> + +// template <class Duration> +// class hh_mm_ss +// { +// public: +// static unsigned constexpr fractional_width = see below; +// using precision = see below; +// +// precision is duration<common_type_t<Duration::rep, seconds::rep>, +// ratio<1, 10^^fractional_width>> + +#include <chrono> +#include <cassert> + +#include "test_macros.h" + +constexpr unsigned long long powers[] = { + 1ULL, + 10ULL, + 100ULL, + 1000ULL, + 10000ULL, + 100000ULL, + 1000000ULL, + 10000000ULL, + 100000000ULL, + 1000000000ULL, + 10000000000ULL, + 100000000000ULL, + 1000000000000ULL, + 10000000000000ULL, + 100000000000000ULL, + 1000000000000000ULL, + 10000000000000000ULL, + 100000000000000000ULL, + 1000000000000000000ULL, + 10000000000000000000ULL + }; + +template <typename Duration, unsigned width> +constexpr bool check_precision() +{ + using HMS = std::chrono::hh_mm_ss<Duration>; + using CT = std::common_type_t<typename Duration::rep, std::chrono::seconds::rep>; + using Pre = std::chrono::duration<CT, std::ratio<1, powers[width]>>; + return std::is_same_v<typename HMS::precision, Pre>; +} + +int main(int, char**) +{ + using microfortnights = std::chrono::duration<int, std::ratio<756, 625>>; + + static_assert( check_precision<std::chrono::hours, 0>(), ""); + static_assert( check_precision<std::chrono::minutes, 0>(), ""); + static_assert( check_precision<std::chrono::seconds, 0>(), ""); + static_assert( check_precision<std::chrono::milliseconds, 3>(), ""); + static_assert( check_precision<std::chrono::microseconds, 6>(), ""); + static_assert( check_precision<std::chrono::nanoseconds, 9>(), ""); + static_assert( check_precision<std::chrono::duration<int, std::ratio< 1, 2>>, 1>(), ""); + static_assert( check_precision<std::chrono::duration<int, std::ratio< 1, 3>>, 6>(), ""); + static_assert( check_precision<std::chrono::duration<int, std::ratio< 1, 4>>, 2>(), ""); + static_assert( check_precision<std::chrono::duration<int, std::ratio< 1, 5>>, 1>(), ""); + static_assert( check_precision<std::chrono::duration<int, std::ratio< 1, 6>>, 6>(), ""); + static_assert( check_precision<std::chrono::duration<int, std::ratio< 1, 7>>, 6>(), ""); + static_assert( check_precision<std::chrono::duration<int, std::ratio< 1, 8>>, 3>(), ""); + static_assert( check_precision<std::chrono::duration<int, std::ratio< 1, 9>>, 6>(), ""); + static_assert( check_precision<std::chrono::duration<int, std::ratio< 1, 10>>, 1>(), ""); + static_assert( check_precision<microfortnights, 4>(), ""); + + return 0; +} diff --git a/libcxx/test/std/utilities/time/time.hms/time.hms.members/precision_type.pass.cpp b/libcxx/test/std/utilities/time/time.hms/time.hms.members/precision_type.pass.cpp new file mode 100644 index 00000000000..58e0484c908 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.hms/time.hms.members/precision_type.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// <chrono> + +// template <class Duration> +// class hh_mm_ss +// { +// public: +// static unsigned constexpr fractional_width = see below; +// using precision = see below; +// +// precision is duration<common_type_t<Duration::rep, seconds::rep>, +// ratio<1, 10^^fractional_width>> + +#include <chrono> +#include <cassert> + +#include "test_macros.h" + +constexpr unsigned long long powers[] = { + 1ULL, + 10ULL, + 100ULL, + 1000ULL, + 10000ULL, + 100000ULL, + 1000000ULL, + 10000000ULL, + 100000000ULL, + 1000000000ULL, + 10000000000ULL, + 100000000000ULL, + 1000000000000ULL, + 10000000000000ULL, + 100000000000000ULL, + 1000000000000000ULL, + 10000000000000000ULL, + 100000000000000000ULL, + 1000000000000000000ULL, + 10000000000000000000ULL + }; + +template <typename Duration, unsigned width> +constexpr bool check_precision() +{ + using HMS = std::chrono::hh_mm_ss<Duration>; + using CT = std::common_type_t<typename Duration::rep, std::chrono::seconds::rep>; + using Pre = std::chrono::duration<CT, std::ratio<1, powers[width]>>; + return std::is_same_v<typename HMS::precision, Pre>; +} + +int main(int, char**) +{ + using microfortnights = std::chrono::duration<int, std::ratio<756, 625>>; + + static_assert( check_precision<std::chrono::hours, 0>(), ""); + static_assert( check_precision<std::chrono::minutes, 0>(), ""); + static_assert( check_precision<std::chrono::seconds, 0>(), ""); + static_assert( check_precision<std::chrono::milliseconds, 3>(), ""); + static_assert( check_precision<std::chrono::microseconds, 6>(), ""); + static_assert( check_precision<std::chrono::nanoseconds, 9>(), ""); + static_assert( check_precision<std::chrono::duration<int, std::ratio< 1, 2>>, 1>(), ""); + static_assert( check_precision<std::chrono::duration<int, std::ratio< 1, 3>>, 6>(), ""); + static_assert( check_precision<std::chrono::duration<int, std::ratio< 1, 4>>, 2>(), ""); + static_assert( check_precision<std::chrono::duration<int, std::ratio< 1, 5>>, 1>(), ""); + static_assert( check_precision<std::chrono::duration<int, std::ratio< 1, 6>>, 6>(), ""); + static_assert( check_precision<std::chrono::duration<int, std::ratio< 1, 7>>, 6>(), ""); + static_assert( check_precision<std::chrono::duration<int, std::ratio< 1, 8>>, 3>(), ""); + static_assert( check_precision<std::chrono::duration<int, std::ratio< 1, 9>>, 6>(), ""); + static_assert( check_precision<std::chrono::duration<int, std::ratio< 1, 10>>, 1>(), ""); + static_assert( check_precision<microfortnights, 4>(), ""); + + return 0; +} diff --git a/libcxx/test/std/utilities/time/time.hms/time.hms.members/seconds.pass.cpp b/libcxx/test/std/utilities/time/time.hms/time.hms.members/seconds.pass.cpp new file mode 100644 index 00000000000..079f2b1cdca --- /dev/null +++ b/libcxx/test/std/utilities/time/time.hms/time.hms.members/seconds.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// <chrono> + +// template <class Duration> +// class hh_mm_ss +// +// constexpr chrono::seconds seconds() const noexcept; +// +// See the table in hours.pass.cpp for correspondence between the magic values used below + +#include <chrono> +#include <cassert> + +#include "test_macros.h" + +template <typename Duration> +constexpr long check_seconds(Duration d) +{ + using HMS = std::chrono::hh_mm_ss<Duration>; + ASSERT_SAME_TYPE(std::chrono::seconds, decltype(std::declval<HMS>().seconds())); + ASSERT_NOEXCEPT( std::declval<HMS>().seconds()); + return HMS(d).seconds().count(); +} + +int main(int, char**) +{ + using microfortnights = std::chrono::duration<int, std::ratio<756, 625>>; + + static_assert( check_seconds(std::chrono::seconds( 1)) == 1, ""); + static_assert( check_seconds(std::chrono::seconds(-1)) == 1, ""); + + assert( check_seconds(std::chrono::seconds( 5000)) == 20); + assert( check_seconds(std::chrono::seconds(-5000)) == 20); + assert( check_seconds(std::chrono::minutes( 5000)) == 0); + assert( check_seconds(std::chrono::minutes(-5000)) == 0); + assert( check_seconds(std::chrono::hours( 11)) == 0); + assert( check_seconds(std::chrono::hours(-11)) == 0); + + assert( check_seconds(std::chrono::milliseconds( 123456789LL)) == 36); + assert( check_seconds(std::chrono::milliseconds(-123456789LL)) == 36); + assert( check_seconds(std::chrono::microseconds( 123456789LL)) == 3); + assert( check_seconds(std::chrono::microseconds(-123456789LL)) == 3); + assert( check_seconds(std::chrono::nanoseconds( 123456789LL)) == 0); + assert( check_seconds(std::chrono::nanoseconds(-123456789LL)) == 0); + + assert( check_seconds(microfortnights( 1000)) == 9); + assert( check_seconds(microfortnights( -1000)) == 9); + assert( check_seconds(microfortnights( 10000)) == 36); + assert( check_seconds(microfortnights(-10000)) == 36); + + return 0; +} diff --git a/libcxx/test/std/utilities/time/time.hms/time.hms.members/subseconds.pass.cpp b/libcxx/test/std/utilities/time/time.hms/time.hms.members/subseconds.pass.cpp new file mode 100644 index 00000000000..0245d8630fd --- /dev/null +++ b/libcxx/test/std/utilities/time/time.hms/time.hms.members/subseconds.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// <chrono> + +// template <class Duration> +// class hh_mm_ss +// +// constexpr precision subseconds() const noexcept; +// +// See the table in hours.pass.cpp for correspondence between the magic values used below + +#include <chrono> +#include <cassert> + +#include "test_macros.h" + +template <typename Duration> +constexpr long check_subseconds(Duration d) +{ + using HMS = std::chrono::hh_mm_ss<Duration>; + ASSERT_SAME_TYPE(typename HMS::precision, decltype(std::declval<HMS>().subseconds())); + ASSERT_NOEXCEPT( std::declval<HMS>().subseconds()); + return HMS(d).subseconds().count(); +} + +int main(int, char**) +{ + using microfortnights = std::chrono::duration<int, std::ratio<756, 625>>; + + static_assert( check_subseconds(std::chrono::seconds( 1)) == 0, ""); + static_assert( check_subseconds(std::chrono::seconds(-1)) == 0, ""); + + assert( check_subseconds(std::chrono::seconds( 5000)) == 0); + assert( check_subseconds(std::chrono::seconds(-5000)) == 0); + assert( check_subseconds(std::chrono::minutes( 5000)) == 0); + assert( check_subseconds(std::chrono::minutes(-5000)) == 0); + assert( check_subseconds(std::chrono::hours( 11)) == 0); + assert( check_subseconds(std::chrono::hours(-11)) == 0); + + assert( check_subseconds(std::chrono::milliseconds( 123456789LL)) == 789); + assert( check_subseconds(std::chrono::milliseconds(-123456789LL)) == 789); + assert( check_subseconds(std::chrono::microseconds( 123456789LL)) == 456789LL); + assert( check_subseconds(std::chrono::microseconds(-123456789LL)) == 456789LL); + assert( check_subseconds(std::chrono::nanoseconds( 123456789LL)) == 123456789LL); + assert( check_subseconds(std::chrono::nanoseconds(-123456789LL)) == 123456789LL); + + assert( check_subseconds(microfortnights( 1000)) == 6000); + assert( check_subseconds(microfortnights( -1000)) == 6000); + assert( check_subseconds(microfortnights( 10000)) == 0); + assert( check_subseconds(microfortnights(-10000)) == 0); + + return 0; +} diff --git a/libcxx/test/std/utilities/time/time.hms/time.hms.members/to_duration.pass.cpp b/libcxx/test/std/utilities/time/time.hms/time.hms.members/to_duration.pass.cpp new file mode 100644 index 00000000000..6bc62af6a29 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.hms/time.hms.members/to_duration.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// <chrono> + +// template <class Duration> +// class hh_mm_ss +// +// constexpr precision to_duration() const noexcept; +// +// See the table in hours.pass.cpp for correspondence between the magic values used below + +#include <chrono> +#include <cassert> + +#include "test_macros.h" + +template <typename Duration> +constexpr long long check_duration(Duration d) +{ + using HMS = std::chrono::hh_mm_ss<Duration>; + ASSERT_SAME_TYPE(typename HMS::precision, decltype(std::declval<HMS>().to_duration())); + ASSERT_NOEXCEPT( std::declval<HMS>().to_duration()); + + return HMS(d).to_duration().count(); +} + +int main(int, char**) +{ + using microfortnights = std::chrono::duration<int, std::ratio<756, 625>>; + + static_assert( check_duration(std::chrono::minutes( 1)) == 60, ""); + static_assert( check_duration(std::chrono::minutes(-1)) == -60, ""); + + assert( check_duration(std::chrono::seconds( 5000)) == 5000LL); + assert( check_duration(std::chrono::seconds(-5000)) == -5000LL); + assert( check_duration(std::chrono::minutes( 5000)) == 300000LL); + assert( check_duration(std::chrono::minutes(-5000)) == -300000LL); + assert( check_duration(std::chrono::hours( 11)) == 39600LL); + assert( check_duration(std::chrono::hours(-11)) == -39600LL); + + assert( check_duration(std::chrono::milliseconds( 123456789LL)) == 123456789LL); + assert( check_duration(std::chrono::milliseconds(-123456789LL)) == -123456789LL); + assert( check_duration(std::chrono::microseconds( 123456789LL)) == 123456789LL); + assert( check_duration(std::chrono::microseconds(-123456789LL)) == -123456789LL); + assert( check_duration(std::chrono::nanoseconds( 123456789LL)) == 123456789LL); + assert( check_duration(std::chrono::nanoseconds(-123456789LL)) == -123456789LL); + + assert( check_duration(microfortnights( 1000)) == 12096000); + assert( check_duration(microfortnights( -1000)) == -12096000); + assert( check_duration(microfortnights( 10000)) == 120960000); + assert( check_duration(microfortnights(-10000)) == -120960000); + + return 0; +} diff --git a/libcxx/test/std/utilities/time/time.hms/time.hms.members/width.pass.cpp b/libcxx/test/std/utilities/time/time.hms/time.hms.members/width.pass.cpp new file mode 100644 index 00000000000..b18d6465c8c --- /dev/null +++ b/libcxx/test/std/utilities/time/time.hms/time.hms.members/width.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// <chrono> + +// template <class Duration> +// class hh_mm_ss +// { +// public: +// static unsigned constexpr fractional_width = see below; +// using precision = see below; +// +// fractional_width is the number of fractional decimal digits represented by precision. +// fractional_width has the value of the smallest possible integer in the range [0, 18] +// such that precision will exactly represent all values of Duration. +// If no such value of fractional_width exists, then fractional_width is 6. + + +#include <chrono> +#include <cassert> + +#include "test_macros.h" + +template <typename Duration, unsigned width> +constexpr bool check_width() +{ + using HMS = std::chrono::hh_mm_ss<Duration>; + return HMS::fractional_width == width; +} + +int main(int, char**) +{ + using microfortnights = std::chrono::duration<int, std::ratio<756, 625>>; + + static_assert( check_width<std::chrono::hours, 0>(), ""); + static_assert( check_width<std::chrono::minutes, 0>(), ""); + static_assert( check_width<std::chrono::seconds, 0>(), ""); + static_assert( check_width<std::chrono::milliseconds, 3>(), ""); + static_assert( check_width<std::chrono::microseconds, 6>(), ""); + static_assert( check_width<std::chrono::nanoseconds, 9>(), ""); + static_assert( check_width<std::chrono::duration<int, std::ratio< 1, 2>>, 1>(), ""); + static_assert( check_width<std::chrono::duration<int, std::ratio< 1, 3>>, 6>(), ""); + static_assert( check_width<std::chrono::duration<int, std::ratio< 1, 4>>, 2>(), ""); + static_assert( check_width<std::chrono::duration<int, std::ratio< 1, 5>>, 1>(), ""); + static_assert( check_width<std::chrono::duration<int, std::ratio< 1, 6>>, 6>(), ""); + static_assert( check_width<std::chrono::duration<int, std::ratio< 1, 7>>, 6>(), ""); + static_assert( check_width<std::chrono::duration<int, std::ratio< 1, 8>>, 3>(), ""); + static_assert( check_width<std::chrono::duration<int, std::ratio< 1, 9>>, 6>(), ""); + static_assert( check_width<std::chrono::duration<int, std::ratio< 1, 10>>, 1>(), ""); + static_assert( check_width<microfortnights, 4>(), ""); + + return 0; +} diff --git a/libcxx/test/std/utilities/time/time.hms/time.hms.nonmembers/nothing.to.do.pass.cpp b/libcxx/test/std/utilities/time/time.hms/time.hms.nonmembers/nothing.to.do.pass.cpp new file mode 100644 index 00000000000..dba6619fa88 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.hms/time.hms.nonmembers/nothing.to.do.pass.cpp @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// template <class Duration> class hh_mm_ss; + +#include <chrono> +#include <cassert> + +#include "test_macros.h" + +int main(int, char**) +{ + return 0; +} |