diff options
Diffstat (limited to 'libcxx/test/std/utilities/time')
101 files changed, 3593 insertions, 0 deletions
diff --git a/libcxx/test/std/utilities/time/clock.h b/libcxx/test/std/utilities/time/clock.h new file mode 100644 index 00000000000..c72470c9cc8 --- /dev/null +++ b/libcxx/test/std/utilities/time/clock.h @@ -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. +// +//===----------------------------------------------------------------------===// + +#ifndef CLOCK_H +#define CLOCK_H + +#include <chrono> + +class Clock +{ + typedef std::chrono::nanoseconds duration; + typedef duration::rep rep; + typedef duration::period period; + typedef std::chrono::time_point<Clock, duration> time_point; + static const bool is_steady = false; + + static time_point now(); +}; + +#endif // CLOCK_H diff --git a/libcxx/test/std/utilities/time/hours.pass.cpp b/libcxx/test/std/utilities/time/hours.pass.cpp new file mode 100644 index 00000000000..e4c39f7859e --- /dev/null +++ b/libcxx/test/std/utilities/time/hours.pass.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// typedef duration<signed integral type of at least 23 bits, ratio<3600>> hours; + +#include <chrono> +#include <type_traits> +#include <limits> + +int main() +{ + typedef std::chrono::hours D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed<Rep>::value, ""); + static_assert(std::is_integral<Rep>::value, ""); + static_assert(std::numeric_limits<Rep>::digits >= 22, ""); + static_assert((std::is_same<Period, std::ratio<3600> >::value), ""); +} diff --git a/libcxx/test/std/utilities/time/microseconds.pass.cpp b/libcxx/test/std/utilities/time/microseconds.pass.cpp new file mode 100644 index 00000000000..1fe6b10da5a --- /dev/null +++ b/libcxx/test/std/utilities/time/microseconds.pass.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// typedef duration<signed integral type of at least 55 bits, micro> microseconds; + +#include <chrono> +#include <type_traits> +#include <limits> + +int main() +{ + typedef std::chrono::microseconds D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed<Rep>::value, ""); + static_assert(std::is_integral<Rep>::value, ""); + static_assert(std::numeric_limits<Rep>::digits >= 54, ""); + static_assert((std::is_same<Period, std::micro>::value), ""); +} diff --git a/libcxx/test/std/utilities/time/milliseconds.pass.cpp b/libcxx/test/std/utilities/time/milliseconds.pass.cpp new file mode 100644 index 00000000000..75df301f7a6 --- /dev/null +++ b/libcxx/test/std/utilities/time/milliseconds.pass.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// typedef duration<signed integral type of at least 45 bits, milli> milliseconds; + +#include <chrono> +#include <type_traits> +#include <limits> + +int main() +{ + typedef std::chrono::milliseconds D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed<Rep>::value, ""); + static_assert(std::is_integral<Rep>::value, ""); + static_assert(std::numeric_limits<Rep>::digits >= 44, ""); + static_assert((std::is_same<Period, std::milli>::value), ""); +} diff --git a/libcxx/test/std/utilities/time/minutes.pass.cpp b/libcxx/test/std/utilities/time/minutes.pass.cpp new file mode 100644 index 00000000000..14214861c07 --- /dev/null +++ b/libcxx/test/std/utilities/time/minutes.pass.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// typedef duration<signed integral type of at least 29 bits, ratio< 60>> minutes; + +#include <chrono> +#include <type_traits> +#include <limits> + +int main() +{ + typedef std::chrono::minutes D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed<Rep>::value, ""); + static_assert(std::is_integral<Rep>::value, ""); + static_assert(std::numeric_limits<Rep>::digits >= 28, ""); + static_assert((std::is_same<Period, std::ratio<60> >::value), ""); +} diff --git a/libcxx/test/std/utilities/time/nanoseconds.pass.cpp b/libcxx/test/std/utilities/time/nanoseconds.pass.cpp new file mode 100644 index 00000000000..d422803f452 --- /dev/null +++ b/libcxx/test/std/utilities/time/nanoseconds.pass.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// typedef duration<signed integral type of at least 64 bits, nano> nanoseconds; + +#include <chrono> +#include <type_traits> +#include <limits> + +int main() +{ + typedef std::chrono::nanoseconds D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed<Rep>::value, ""); + static_assert(std::is_integral<Rep>::value, ""); + static_assert(std::numeric_limits<Rep>::digits >= 63, ""); + static_assert((std::is_same<Period, std::nano>::value), ""); +} diff --git a/libcxx/test/std/utilities/time/rep.h b/libcxx/test/std/utilities/time/rep.h new file mode 100644 index 00000000000..2ec3514ab56 --- /dev/null +++ b/libcxx/test/std/utilities/time/rep.h @@ -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. +// +//===----------------------------------------------------------------------===// + +#ifndef REP_H +#define REP_H + +class Rep +{ + int data_; +public: + _LIBCPP_CONSTEXPR Rep() : data_(-1) {} + explicit _LIBCPP_CONSTEXPR Rep(int i) : data_(i) {} + + bool _LIBCPP_CONSTEXPR operator==(int i) const {return data_ == i;} + bool _LIBCPP_CONSTEXPR operator==(const Rep& r) const {return data_ == r.data_;} + + Rep& operator*=(Rep x) {data_ *= x.data_; return *this;} + Rep& operator/=(Rep x) {data_ /= x.data_; return *this;} +}; + +#endif // REP_H diff --git a/libcxx/test/std/utilities/time/seconds.pass.cpp b/libcxx/test/std/utilities/time/seconds.pass.cpp new file mode 100644 index 00000000000..231d59695a0 --- /dev/null +++ b/libcxx/test/std/utilities/time/seconds.pass.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// typedef duration<signed integral type of at least 35 bits > seconds; + +#include <chrono> +#include <type_traits> +#include <limits> + +int main() +{ + typedef std::chrono::seconds D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed<Rep>::value, ""); + static_assert(std::is_integral<Rep>::value, ""); + static_assert(std::numeric_limits<Rep>::digits >= 34, ""); + static_assert((std::is_same<Period, std::ratio<1> >::value), ""); +} diff --git a/libcxx/test/std/utilities/time/time.clock.req/nothing_to_do.pass.cpp b/libcxx/test/std/utilities/time/time.clock.req/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.clock.req/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/utilities/time/time.clock/nothing_to_do.pass.cpp b/libcxx/test/std/utilities/time/time.clock/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.clock/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/utilities/time/time.clock/time.clock.hires/consistency.pass.cpp b/libcxx/test/std/utilities/time/time.clock/time.clock.hires/consistency.pass.cpp new file mode 100644 index 00000000000..848534d6179 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.clock/time.clock.hires/consistency.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// This test uses new symbols that were not defined in the libc++ shipped on +// darwin11 and darwin12: +// XFAIL: with_system_lib=x86_64-apple-darwin11 +// XFAIL: with_system_lib=x86_64-apple-darwin12 + +// <chrono> + +// high_resolution_clock + +// check clock invariants + +#include <chrono> + +template <class _Tp> +void test(const _Tp &) {} + +int main() +{ + typedef std::chrono::high_resolution_clock C; + static_assert((std::is_same<C::rep, C::duration::rep>::value), ""); + static_assert((std::is_same<C::period, C::duration::period>::value), ""); + static_assert((std::is_same<C::duration, C::time_point::duration>::value), ""); + static_assert(C::is_steady || !C::is_steady, ""); + test(std::chrono::high_resolution_clock::is_steady); +} diff --git a/libcxx/test/std/utilities/time/time.clock/time.clock.hires/now.pass.cpp b/libcxx/test/std/utilities/time/time.clock/time.clock.hires/now.pass.cpp new file mode 100644 index 00000000000..0bcd99d76ad --- /dev/null +++ b/libcxx/test/std/utilities/time/time.clock/time.clock.hires/now.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// high_resolution_clock + +// static time_point now(); + +#include <chrono> + +int main() +{ + typedef std::chrono::high_resolution_clock C; + C::time_point t1 = C::now(); +} diff --git a/libcxx/test/std/utilities/time/time.clock/time.clock.steady/consistency.pass.cpp b/libcxx/test/std/utilities/time/time.clock/time.clock.steady/consistency.pass.cpp new file mode 100644 index 00000000000..60c646147ce --- /dev/null +++ b/libcxx/test/std/utilities/time/time.clock/time.clock.steady/consistency.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// This test uses new symbols that were not defined in the libc++ shipped on +// darwin11 and darwin12: +// XFAIL: with_system_lib=x86_64-apple-darwin11 +// XFAIL: with_system_lib=x86_64-apple-darwin12 +// UNSUPPORTED: libcpp-has-no-monotonic-clock + +// <chrono> + +// steady_clock + +// check clock invariants + +#include <chrono> + +template <class _Tp> +void test(const _Tp &) {} + +int main() +{ + typedef std::chrono::steady_clock C; + static_assert((std::is_same<C::rep, C::duration::rep>::value), ""); + static_assert((std::is_same<C::period, C::duration::period>::value), ""); + static_assert((std::is_same<C::duration, C::time_point::duration>::value), ""); + static_assert(C::is_steady, ""); + test(std::chrono::steady_clock::is_steady); +} diff --git a/libcxx/test/std/utilities/time/time.clock/time.clock.steady/now.pass.cpp b/libcxx/test/std/utilities/time/time.clock/time.clock.steady/now.pass.cpp new file mode 100644 index 00000000000..4b86d9e8cbc --- /dev/null +++ b/libcxx/test/std/utilities/time/time.clock/time.clock.steady/now.pass.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: libcpp-has-no-monotonic-clock + +// <chrono> + +// steady_clock + +// static time_point now(); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::steady_clock C; + C::time_point t1 = C::now(); + C::time_point t2 = C::now(); + assert(t2 >= t1); +} diff --git a/libcxx/test/std/utilities/time/time.clock/time.clock.system/consistency.pass.cpp b/libcxx/test/std/utilities/time/time.clock/time.clock.system/consistency.pass.cpp new file mode 100644 index 00000000000..d9d6b04d631 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.clock/time.clock.system/consistency.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// This test uses new symbols that were not defined in the libc++ shipped on +// darwin11 and darwin12: +// XFAIL: with_system_lib=x86_64-apple-darwin11 +// XFAIL: with_system_lib=x86_64-apple-darwin12 + +// <chrono> + +// system_clock + +// check clock invariants + +#include <chrono> + +template <class _Tp> +void test(const _Tp &) {} + +int main() +{ + typedef std::chrono::system_clock C; + static_assert((std::is_same<C::rep, C::duration::rep>::value), ""); + static_assert((std::is_same<C::period, C::duration::period>::value), ""); + static_assert((std::is_same<C::duration, C::time_point::duration>::value), ""); + static_assert((std::is_same<C::time_point::clock, C>::value), ""); + static_assert((C::is_steady || !C::is_steady), ""); + test(std::chrono::system_clock::is_steady); +} diff --git a/libcxx/test/std/utilities/time/time.clock/time.clock.system/from_time_t.pass.cpp b/libcxx/test/std/utilities/time/time.clock/time.clock.system/from_time_t.pass.cpp new file mode 100644 index 00000000000..9b12a667ffd --- /dev/null +++ b/libcxx/test/std/utilities/time/time.clock/time.clock.system/from_time_t.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// system_clock + +// static time_point from_time_t(time_t t); + +#include <chrono> +#include <ctime> + +int main() +{ + typedef std::chrono::system_clock C; + C::time_point t1 = C::from_time_t(C::to_time_t(C::now())); +} diff --git a/libcxx/test/std/utilities/time/time.clock/time.clock.system/now.pass.cpp b/libcxx/test/std/utilities/time/time.clock/time.clock.system/now.pass.cpp new file mode 100644 index 00000000000..60530fdf3a9 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.clock/time.clock.system/now.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// system_clock + +// static time_point now(); + +#include <chrono> + +int main() +{ + typedef std::chrono::system_clock C; + C::time_point t1 = C::now(); +} diff --git a/libcxx/test/std/utilities/time/time.clock/time.clock.system/rep_signed.pass.cpp b/libcxx/test/std/utilities/time/time.clock/time.clock.system/rep_signed.pass.cpp new file mode 100644 index 00000000000..b6a440e16dd --- /dev/null +++ b/libcxx/test/std/utilities/time/time.clock/time.clock.system/rep_signed.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// system_clock + +// rep should be signed + +#include <chrono> +#include <cassert> + +int main() +{ + assert(std::chrono::system_clock::duration::min() < + std::chrono::system_clock::duration::zero()); +} diff --git a/libcxx/test/std/utilities/time/time.clock/time.clock.system/to_time_t.pass.cpp b/libcxx/test/std/utilities/time/time.clock/time.clock.system/to_time_t.pass.cpp new file mode 100644 index 00000000000..2a82d5375e1 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.clock/time.clock.system/to_time_t.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// system_clock + +// time_t to_time_t(const time_point& t); + +#include <chrono> +#include <ctime> + +int main() +{ + typedef std::chrono::system_clock C; + std::time_t t1 = C::to_time_t(C::now()); +} diff --git a/libcxx/test/std/utilities/time/time.duration/default_ratio.pass.cpp b/libcxx/test/std/utilities/time/time.duration/default_ratio.pass.cpp new file mode 100644 index 00000000000..a34e27832bd --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/default_ratio.pass.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// Test default template arg: + +// template <class Rep, class Period = ratio<1>> +// class duration; + +#include <chrono> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::chrono::duration<int, std::ratio<1> >, + std::chrono::duration<int> >::value), ""); +} diff --git a/libcxx/test/std/utilities/time/time.duration/duration.fail.cpp b/libcxx/test/std/utilities/time/time.duration/duration.fail.cpp new file mode 100644 index 00000000000..053616b79b4 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/duration.fail.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// If a program instantiates duration with a duration type for the template +// argument Rep a diagnostic is required. + +#include <chrono> + +int main() +{ + typedef std::chrono::duration<std::chrono::milliseconds> D; + D d; +} diff --git a/libcxx/test/std/utilities/time/time.duration/positive_num.fail.cpp b/libcxx/test/std/utilities/time/time.duration/positive_num.fail.cpp new file mode 100644 index 00000000000..e9096fd3fcb --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/positive_num.fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// Period::num shall be positive, diagnostic required. + +#include <chrono> + +int main() +{ + typedef std::chrono::duration<int, std::ratio<5, -1> > D; + D d; +} diff --git a/libcxx/test/std/utilities/time/time.duration/ratio.fail.cpp b/libcxx/test/std/utilities/time/time.duration/ratio.fail.cpp new file mode 100644 index 00000000000..4ce0aaad003 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/ratio.fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// Period shall be a specialization of ratio, diagnostic required. + +#include <chrono> + +template <int N, int D = 1> +class Ratio +{ +public: + static const int num = N; + static const int den = D; +}; + +int main() +{ + typedef std::chrono::duration<int, Ratio<1> > D; + D d; +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_++.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_++.pass.cpp new file mode 100644 index 00000000000..8a8f4b1c0d9 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_++.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator++(); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::hours h(3); + std::chrono::hours& href = ++h; + assert(&href == &h); + assert(h.count() == 4); +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_++int.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_++int.pass.cpp new file mode 100644 index 00000000000..cf502828100 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_++int.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration operator++(int); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::hours h(3); + std::chrono::hours h2 = h++; + assert(h.count() == 4); + assert(h2.count() == 3); +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp new file mode 100644 index 00000000000..c0f10147ee8 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration operator+() const; + +#include <chrono> +#include <cassert> + +int main() +{ + { + const std::chrono::minutes m(3); + std::chrono::minutes m2 = +m; + assert(m.count() == m2.count()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::minutes m(3); + constexpr std::chrono::minutes m2 = +m; + static_assert(m.count() == m2.count(), ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+=.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+=.pass.cpp new file mode 100644 index 00000000000..8d8cf4539c1 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+=.pass.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator+=(const duration& d); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::seconds s(3); + s += std::chrono::seconds(2); + assert(s.count() == 5); + s += std::chrono::minutes(2); + assert(s.count() == 125); +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_--.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_--.pass.cpp new file mode 100644 index 00000000000..0aadfbcd599 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_--.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator--(); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::hours h(3); + std::chrono::hours& href = --h; + assert(&href == &h); + assert(h.count() == 2); +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_--int.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_--int.pass.cpp new file mode 100644 index 00000000000..7fc6a1df603 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_--int.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration operator--(int); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::hours h(3); + std::chrono::hours h2 = h--; + assert(h.count() == 2); + assert(h2.count() == 3); +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp new file mode 100644 index 00000000000..00da6f69ca5 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration operator-() const; + +#include <chrono> +#include <cassert> + +int main() +{ + { + const std::chrono::minutes m(3); + std::chrono::minutes m2 = -m; + assert(m2.count() == -m.count()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::minutes m(3); + constexpr std::chrono::minutes m2 = -m; + static_assert(m2.count() == -m.count(), ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-=.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-=.pass.cpp new file mode 100644 index 00000000000..a0a7aed202b --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-=.pass.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator-=(const duration& d); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::seconds s(3); + s -= std::chrono::seconds(2); + assert(s.count() == 1); + s -= std::chrono::minutes(2); + assert(s.count() == -119); +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_divide=.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_divide=.pass.cpp new file mode 100644 index 00000000000..09786bcd8cf --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_divide=.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator/=(const rep& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::nanoseconds ns(15); + ns /= 5; + assert(ns.count() == 3); +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_mod=duration.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_mod=duration.pass.cpp new file mode 100644 index 00000000000..8a4a2b47232 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_mod=duration.pass.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator%=(const duration& rhs) + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::microseconds us(11); + std::chrono::microseconds us2(3); + us %= us2; + assert(us.count() == 2); + us %= std::chrono::milliseconds(3); + assert(us.count() == 2); +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_mod=rep.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_mod=rep.pass.cpp new file mode 100644 index 00000000000..8758e17ba6a --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_mod=rep.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator%=(const rep& rhs) + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::microseconds us(11); + us %= 3; + assert(us.count() == 2); +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_times=.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_times=.pass.cpp new file mode 100644 index 00000000000..b97534a3615 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.arithmetic/op_times=.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator*=(const rep& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::nanoseconds ns(3); + ns *= 5; + assert(ns.count() == 15); +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.cast/duration_cast.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.cast/duration_cast.pass.cpp new file mode 100644 index 00000000000..1c87fcd909e --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.cast/duration_cast.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class ToDuration, class Rep, class Period> +// constexpr +// ToDuration +// duration_cast(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::duration_cast<ToDuration>(f)) R; + static_assert((std::is_same<R, ToDuration>::value), ""); + assert(std::chrono::duration_cast<ToDuration>(f) == d); + } +} + +int main() +{ + test(std::chrono::milliseconds(7265000), std::chrono::hours(2)); + test(std::chrono::milliseconds(7265000), std::chrono::minutes(121)); + test(std::chrono::milliseconds(7265000), std::chrono::seconds(7265)); + test(std::chrono::milliseconds(7265000), std::chrono::milliseconds(7265000)); + test(std::chrono::milliseconds(7265000), std::chrono::microseconds(7265000000LL)); + test(std::chrono::milliseconds(7265000), std::chrono::nanoseconds(7265000000000LL)); + test(std::chrono::milliseconds(7265000), + std::chrono::duration<double, std::ratio<3600> >(7265./3600)); + test(std::chrono::duration<int, std::ratio<2, 3> >(9), + std::chrono::duration<int, std::ratio<3, 5> >(10)); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::hours h = std::chrono::duration_cast<std::chrono::hours>(std::chrono::milliseconds(7265000)); + static_assert(h.count() == 2, ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.cast/toduration.fail.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.cast/toduration.fail.cpp new file mode 100644 index 00000000000..13dd8f44c36 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.cast/toduration.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class ToDuration, class Rep, class Period> +// ToDuration +// duration_cast(const duration<Rep, Period>& d); + +// ToDuration shall be an instantiation of duration. + +#include <chrono> + +int main() +{ + std::chrono::duration_cast<int>(std::chrono::milliseconds(3)); +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.comparisons/op_equal.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.comparisons/op_equal.pass.cpp new file mode 100644 index 00000000000..2d0dd94d4cf --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.comparisons/op_equal.pass.cpp @@ -0,0 +1,115 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period1, class Rep2, class Period2> +// constexpr +// bool +// operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +// template <class Rep1, class Period1, class Rep2, class Period2> +// constexpr +// bool +// operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::seconds s1(3); + std::chrono::seconds s2(3); + assert(s1 == s2); + assert(!(s1 != s2)); + } + { + std::chrono::seconds s1(3); + std::chrono::seconds s2(4); + assert(!(s1 == s2)); + assert(s1 != s2); + } + { + std::chrono::milliseconds s1(3); + std::chrono::microseconds s2(3000); + assert(s1 == s2); + assert(!(s1 != s2)); + } + { + std::chrono::milliseconds s1(3); + std::chrono::microseconds s2(4000); + assert(!(s1 == s2)); + assert(s1 != s2); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(9); + std::chrono::duration<int, std::ratio<3, 5> > s2(10); + assert(s1 == s2); + assert(!(s1 != s2)); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(10); + std::chrono::duration<int, std::ratio<3, 5> > s2(9); + assert(!(s1 == s2)); + assert(s1 != s2); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(9); + std::chrono::duration<double, std::ratio<3, 5> > s2(10); + assert(s1 == s2); + assert(!(s1 != s2)); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::seconds s2(3); + static_assert(s1 == s2, ""); + static_assert(!(s1 != s2), ""); + } + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::seconds s2(4); + static_assert(!(s1 == s2), ""); + static_assert(s1 != s2, ""); + } + { + constexpr std::chrono::milliseconds s1(3); + constexpr std::chrono::microseconds s2(3000); + static_assert(s1 == s2, ""); + static_assert(!(s1 != s2), ""); + } + { + constexpr std::chrono::milliseconds s1(3); + constexpr std::chrono::microseconds s2(4000); + static_assert(!(s1 == s2), ""); + static_assert(s1 != s2, ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(9); + constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(10); + static_assert(s1 == s2, ""); + static_assert(!(s1 != s2), ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(10); + constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(9); + static_assert(!(s1 == s2), ""); + static_assert(s1 != s2, ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(9); + constexpr std::chrono::duration<double, std::ratio<3, 5> > s2(10); + static_assert(s1 == s2, ""); + static_assert(!(s1 != s2), ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.comparisons/op_less.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.comparisons/op_less.pass.cpp new file mode 100644 index 00000000000..9d875579f32 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.comparisons/op_less.pass.cpp @@ -0,0 +1,153 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period1, class Rep2, class Period2> +// constexpr +// bool +// operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +// template <class Rep1, class Period1, class Rep2, class Period2> +// constexpr +// bool +// operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +// template <class Rep1, class Period1, class Rep2, class Period2> +// constexpr +// bool +// operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +// template <class Rep1, class Period1, class Rep2, class Period2> +// constexpr +// bool +// operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::seconds s1(3); + std::chrono::seconds s2(3); + assert(!(s1 < s2)); + assert(!(s1 > s2)); + assert( (s1 <= s2)); + assert( (s1 >= s2)); + } + { + std::chrono::seconds s1(3); + std::chrono::seconds s2(4); + assert( (s1 < s2)); + assert(!(s1 > s2)); + assert( (s1 <= s2)); + assert(!(s1 >= s2)); + } + { + std::chrono::milliseconds s1(3); + std::chrono::microseconds s2(3000); + assert(!(s1 < s2)); + assert(!(s1 > s2)); + assert( (s1 <= s2)); + assert( (s1 >= s2)); + } + { + std::chrono::milliseconds s1(3); + std::chrono::microseconds s2(4000); + assert( (s1 < s2)); + assert(!(s1 > s2)); + assert( (s1 <= s2)); + assert(!(s1 >= s2)); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(9); + std::chrono::duration<int, std::ratio<3, 5> > s2(10); + assert(!(s1 < s2)); + assert(!(s1 > s2)); + assert( (s1 <= s2)); + assert( (s1 >= s2)); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(10); + std::chrono::duration<int, std::ratio<3, 5> > s2(9); + assert(!(s1 < s2)); + assert( (s1 > s2)); + assert(!(s1 <= s2)); + assert( (s1 >= s2)); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(9); + std::chrono::duration<double, std::ratio<3, 5> > s2(10); + assert(!(s1 < s2)); + assert(!(s1 > s2)); + assert( (s1 <= s2)); + assert( (s1 >= s2)); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::seconds s2(3); + static_assert(!(s1 < s2), ""); + static_assert(!(s1 > s2), ""); + static_assert( (s1 <= s2), ""); + static_assert( (s1 >= s2), ""); + } + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::seconds s2(4); + static_assert( (s1 < s2), ""); + static_assert(!(s1 > s2), ""); + static_assert( (s1 <= s2), ""); + static_assert(!(s1 >= s2), ""); + } + { + constexpr std::chrono::milliseconds s1(3); + constexpr std::chrono::microseconds s2(3000); + static_assert(!(s1 < s2), ""); + static_assert(!(s1 > s2), ""); + static_assert( (s1 <= s2), ""); + static_assert( (s1 >= s2), ""); + } + { + constexpr std::chrono::milliseconds s1(3); + constexpr std::chrono::microseconds s2(4000); + static_assert( (s1 < s2), ""); + static_assert(!(s1 > s2), ""); + static_assert( (s1 <= s2), ""); + static_assert(!(s1 >= s2), ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(9); + constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(10); + static_assert(!(s1 < s2), ""); + static_assert(!(s1 > s2), ""); + static_assert( (s1 <= s2), ""); + static_assert( (s1 >= s2), ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(10); + constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(9); + static_assert(!(s1 < s2), ""); + static_assert( (s1 > s2), ""); + static_assert(!(s1 <= s2), ""); + static_assert( (s1 >= s2), ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(9); + constexpr std::chrono::duration<double, std::ratio<3, 5> > s2(10); + static_assert(!(s1 < s2), ""); + static_assert(!(s1 > s2), ""); + static_assert( (s1 <= s2), ""); + static_assert( (s1 >= s2), ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.cons/convert_exact.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/convert_exact.pass.cpp new file mode 100644 index 00000000000..152227d82a8 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/convert_exact.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2, class Period2> +// duration(const duration<Rep2, Period2>& d); + +// exact conversions allowed for integral reps + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::milliseconds ms(1); + std::chrono::microseconds us = ms; + assert(us.count() == 1000); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::milliseconds ms(1); + constexpr std::chrono::microseconds us = ms; + static_assert(us.count() == 1000, ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.cons/convert_float_to_int.fail.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/convert_float_to_int.fail.cpp new file mode 100644 index 00000000000..04c08257828 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/convert_float_to_int.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2, class Period2> +// duration(const duration<Rep2, Period2>& d); + +// conversions from floating point to integral durations disallowed + +#include <chrono> + +int main() +{ + std::chrono::duration<double> d; + std::chrono::duration<int> i = d; +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.cons/convert_inexact.fail.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/convert_inexact.fail.cpp new file mode 100644 index 00000000000..e82e25e8f69 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/convert_inexact.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2, class Period2> +// duration(const duration<Rep2, Period2>& d); + +// inexact conversions disallowed for integral reps + +#include <chrono> + +int main() +{ + std::chrono::microseconds us(1); + std::chrono::milliseconds ms = us; +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.cons/convert_inexact.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/convert_inexact.pass.cpp new file mode 100644 index 00000000000..519b2b141c2 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/convert_inexact.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2, class Period2> +// duration(const duration<Rep2, Period2>& d); + +// inexact conversions allowed for floating point reps + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::duration<double, std::micro> us(1); + std::chrono::duration<double, std::milli> ms = us; + assert(ms.count() == 1./1000); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::duration<double, std::micro> us(1); + constexpr std::chrono::duration<double, std::milli> ms = us; + static_assert(ms.count() == 1./1000, ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.cons/convert_int_to_float.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/convert_int_to_float.pass.cpp new file mode 100644 index 00000000000..59fefe2e002 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/convert_int_to_float.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2, class Period2> +// duration(const duration<Rep2, Period2>& d); + +// conversions from integral to floating point durations allowed + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::duration<int> i(3); + std::chrono::duration<double, std::milli> d = i; + assert(d.count() == 3000); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::duration<int> i(3); + constexpr std::chrono::duration<double, std::milli> d = i; + static_assert(d.count() == 3000, ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.cons/convert_overflow.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/convert_overflow.pass.cpp new file mode 100644 index 00000000000..74b65d6b9cc --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/convert_overflow.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2, class Period2> +// duration(const duration<Rep2, Period2>& d); + +// overflow should SFINAE instead of error out, LWG 2094 + +#include <chrono> +#include <cassert> + +bool called = false; + +void f(std::chrono::milliseconds); +void f(std::chrono::seconds) +{ + called = true; +} + +int main() +{ + { + std::chrono::duration<int, std::exa> r(1); + f(r); + assert(called); + } +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.cons/default.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/default.pass.cpp new file mode 100644 index 00000000000..c52990961c2 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/default.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration() = default; + +// Rep must be default initialized, not initialized with 0 + +#include <chrono> +#include <cassert> + +#include "../../rep.h" + +template <class D> +void +test() +{ + D d; + assert(d.count() == typename D::rep()); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + constexpr D d2 = D(); + static_assert(d2.count() == typename D::rep(), ""); +#endif +} + +int main() +{ + test<std::chrono::duration<Rep> >(); +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep.pass.cpp new file mode 100644 index 00000000000..20f81619bd1 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2> +// explicit duration(const Rep2& r); + +#include <chrono> +#include <cassert> + +#include "../../rep.h" + +template <class D, class R> +void +test(R r) +{ + D d(r); + assert(d.count() == r); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + constexpr D d2(R(2)); + static_assert(d2.count() == 2, ""); +#endif +} + +int main() +{ + test<std::chrono::duration<int> >(5); + test<std::chrono::duration<int, std::ratio<3, 2> > >(5); + test<std::chrono::duration<Rep, std::ratio<3, 2> > >(Rep(3)); + test<std::chrono::duration<double, std::ratio<2, 3> > >(5.5); +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep01.fail.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep01.fail.cpp new file mode 100644 index 00000000000..9f071ca1afc --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep01.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2> +// explicit duration(const Rep2& r); + +// test for explicit + +#include <chrono> + +#include "../../rep.h" + +int main() +{ + std::chrono::duration<int> d = 1; +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep02.fail.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep02.fail.cpp new file mode 100644 index 00000000000..37f32e77686 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep02.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2> +// explicit duration(const Rep2& r); + +// Rep2 shall be implicitly convertible to rep + +#include <chrono> + +#include "../../rep.h" + +int main() +{ + std::chrono::duration<Rep> d(1); +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep02.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep02.pass.cpp new file mode 100644 index 00000000000..b3ba9f7081e --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep02.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2> +// explicit duration(const Rep2& r); + +// construct double with int + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::duration<double> d(5); + assert(d.count() == 5); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + constexpr std::chrono::duration<double> d2(5); + static_assert(d2.count() == 5, ""); +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep03.fail.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep03.fail.cpp new file mode 100644 index 00000000000..4ace54b231f --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.cons/rep03.fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2> +// explicit duration(const Rep2& r); + +// treat_as_floating_point<Rep2>::value shall be false + +#include <chrono> + +int main() +{ + std::chrono::duration<int> d(1.); +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals.pass.cpp new file mode 100644 index 00000000000..48324ae8365 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +#include <chrono> +#include <type_traits> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using namespace std::literals::chrono_literals; + +// Make sure the types are right + static_assert ( std::is_same<decltype( 3h ), std::chrono::hours>::value, "" ); + static_assert ( std::is_same<decltype( 3min ), std::chrono::minutes>::value, "" ); + static_assert ( std::is_same<decltype( 3s ), std::chrono::seconds>::value, "" ); + static_assert ( std::is_same<decltype( 3ms ), std::chrono::milliseconds>::value, "" ); + static_assert ( std::is_same<decltype( 3us ), std::chrono::microseconds>::value, "" ); + static_assert ( std::is_same<decltype( 3ns ), std::chrono::nanoseconds>::value, "" ); + + std::chrono::hours h = 4h; + assert ( h == std::chrono::hours(4)); + auto h2 = 4.0h; + assert ( h == h2 ); + + std::chrono::minutes min = 36min; + assert ( min == std::chrono::minutes(36)); + auto min2 = 36.0min; + assert ( min == min2 ); + + std::chrono::seconds s = 24s; + assert ( s == std::chrono::seconds(24)); + auto s2 = 24.0s; + assert ( s == s2 ); + + std::chrono::milliseconds ms = 247ms; + assert ( ms == std::chrono::milliseconds(247)); + auto ms2 = 247.0ms; + assert ( ms == ms2 ); + + std::chrono::microseconds us = 867us; + assert ( us == std::chrono::microseconds(867)); + auto us2 = 867.0us; + assert ( us == us2 ); + + std::chrono::nanoseconds ns = 645ns; + assert ( ns == std::chrono::nanoseconds(645)); + auto ns2 = 645.ns; + assert ( ns == ns2 ); +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals1.fail.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals1.fail.cpp new file mode 100644 index 00000000000..46aaa30e51e --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals1.fail.cpp @@ -0,0 +1,21 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 <chrono> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + std::chrono::hours h = 4h; // should fail w/conversion operator not found +#else +#error +#endif +} + diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals1.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals1.pass.cpp new file mode 100644 index 00000000000..574f9bcce87 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals1.pass.cpp @@ -0,0 +1,48 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 <chrono> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using namespace std::chrono; + + hours h = 4h; + assert ( h == hours(4)); + auto h2 = 4.0h; + assert ( h == h2 ); + + minutes min = 36min; + assert ( min == minutes(36)); + auto min2 = 36.0min; + assert ( min == min2 ); + + seconds s = 24s; + assert ( s == seconds(24)); + auto s2 = 24.0s; + assert ( s == s2 ); + + milliseconds ms = 247ms; + assert ( ms == milliseconds(247)); + auto ms2 = 247.0ms; + assert ( ms == ms2 ); + + microseconds us = 867us; + assert ( us == microseconds(867)); + auto us2 = 867.0us; + assert ( us == us2 ); + + nanoseconds ns = 645ns; + assert ( ns == nanoseconds(645)); + auto ns2 = 645.ns; + assert ( ns == ns2 ); +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals2.fail.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals2.fail.cpp new file mode 100644 index 00000000000..17358e589f4 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals2.fail.cpp @@ -0,0 +1,22 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 <chrono> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using std::chrono::hours; + + hours foo = 4h; // should fail w/conversion operator not found +#else +#error +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals2.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals2.pass.cpp new file mode 100644 index 00000000000..e37bc6e6796 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals2.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +#include <chrono> +#include <type_traits> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using namespace std::literals; + + std::chrono::hours h = 4h; + assert ( h == std::chrono::hours(4)); + auto h2 = 4.0h; + assert ( h == h2 ); + + std::chrono::minutes min = 36min; + assert ( min == std::chrono::minutes(36)); + auto min2 = 36.0min; + assert ( min == min2 ); + + std::chrono::seconds s = 24s; + assert ( s == std::chrono::seconds(24)); + auto s2 = 24.0s; + assert ( s == s2 ); + + std::chrono::milliseconds ms = 247ms; + assert ( ms == std::chrono::milliseconds(247)); + auto ms2 = 247.0ms; + assert ( ms == ms2 ); + + std::chrono::microseconds us = 867us; + assert ( us == std::chrono::microseconds(867)); + auto us2 = 867.0us; + assert ( us == us2 ); + + std::chrono::nanoseconds ns = 645ns; + assert ( ns == std::chrono::nanoseconds(645)); + auto ns2 = 645.ns; + assert ( ns == ns2 ); +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_+.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_+.pass.cpp new file mode 100644 index 00000000000..6585351cb4c --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_+.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period1, class Rep2, class Period2> +// typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type +// operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::seconds s1(3); + std::chrono::seconds s2(5); + std::chrono::seconds r = s1 + s2; + assert(r.count() == 8); + } + { + std::chrono::seconds s1(3); + std::chrono::microseconds s2(5); + std::chrono::microseconds r = s1 + s2; + assert(r.count() == 3000005); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(3); + std::chrono::duration<int, std::ratio<3, 5> > s2(5); + std::chrono::duration<int, std::ratio<1, 15> > r = s1 + s2; + assert(r.count() == 75); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(3); + std::chrono::duration<double, std::ratio<3, 5> > s2(5); + std::chrono::duration<double, std::ratio<1, 15> > r = s1 + s2; + assert(r.count() == 75); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::seconds s2(5); + constexpr std::chrono::seconds r = s1 + s2; + static_assert(r.count() == 8, ""); + } + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::microseconds s2(5); + constexpr std::chrono::microseconds r = s1 + s2; + static_assert(r.count() == 3000005, ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(3); + constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(5); + constexpr std::chrono::duration<int, std::ratio<1, 15> > r = s1 + s2; + static_assert(r.count() == 75, ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(3); + constexpr std::chrono::duration<double, std::ratio<3, 5> > s2(5); + constexpr std::chrono::duration<double, std::ratio<1, 15> > r = s1 + s2; + static_assert(r.count() == 75, ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_-.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_-.pass.cpp new file mode 100644 index 00000000000..fac58b9716d --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_-.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period1, class Rep2, class Period2> +// constexpr +// typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type +// operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::seconds s1(3); + std::chrono::seconds s2(5); + std::chrono::seconds r = s1 - s2; + assert(r.count() == -2); + } + { + std::chrono::seconds s1(3); + std::chrono::microseconds s2(5); + std::chrono::microseconds r = s1 - s2; + assert(r.count() == 2999995); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(3); + std::chrono::duration<int, std::ratio<3, 5> > s2(5); + std::chrono::duration<int, std::ratio<1, 15> > r = s1 - s2; + assert(r.count() == -15); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(3); + std::chrono::duration<double, std::ratio<3, 5> > s2(5); + std::chrono::duration<double, std::ratio<1, 15> > r = s1 - s2; + assert(r.count() == -15); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::seconds s2(5); + constexpr std::chrono::seconds r = s1 - s2; + static_assert(r.count() == -2, ""); + } + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::microseconds s2(5); + constexpr std::chrono::microseconds r = s1 - s2; + static_assert(r.count() == 2999995, ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(3); + constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(5); + constexpr std::chrono::duration<int, std::ratio<1, 15> > r = s1 - s2; + static_assert(r.count() == -15, ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(3); + constexpr std::chrono::duration<double, std::ratio<3, 5> > s2(5); + constexpr std::chrono::duration<double, std::ratio<1, 15> > r = s1 - s2; + static_assert(r.count() == -15, ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp new file mode 100644 index 00000000000..6b24676f100 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period1, class Rep2, class Period2> +// constexpr +// typename common_type<Rep1, Rep2>::type +// operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::nanoseconds ns1(15); + std::chrono::nanoseconds ns2(5); + assert(ns1 / ns2 == 3); + } + { + std::chrono::microseconds us1(15); + std::chrono::nanoseconds ns2(5); + assert(us1 / ns2 == 3000); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(30); + std::chrono::duration<int, std::ratio<3, 5> > s2(5); + assert(s1 / s2 == 6); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(30); + std::chrono::duration<double, std::ratio<3, 5> > s2(5); + assert(s1 / s2 == 20./3); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::nanoseconds ns1(15); + constexpr std::chrono::nanoseconds ns2(5); + static_assert(ns1 / ns2 == 3, ""); + } + { + constexpr std::chrono::microseconds us1(15); + constexpr std::chrono::nanoseconds ns2(5); + static_assert(us1 / ns2 == 3000, ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(30); + constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(5); + static_assert(s1 / s2 == 6, ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(30); + constexpr std::chrono::duration<double, std::ratio<3, 5> > s2(5); + static_assert(s1 / s2 == 20./3, ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.fail.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.fail.cpp new file mode 100644 index 00000000000..db725773fd4 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator/(const duration<Rep1, Period>& d, const Rep2& s); + +#include <chrono> + +#include "../../rep.h" + +int main() +{ + std::chrono::duration<Rep> d(Rep(15)); + d = d / 5; +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.pass.cpp new file mode 100644 index 00000000000..3036cde5bf6 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period, class Rep2> +// constexpr +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator/(const duration<Rep1, Period>& d, const Rep2& s); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::nanoseconds ns(15); + ns = ns / 5; + assert(ns.count() == 3); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::nanoseconds ns(15); + constexpr std::chrono::nanoseconds ns2 = ns / 5; + static_assert(ns2.count() == 3, ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_mod_duration.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_mod_duration.pass.cpp new file mode 100644 index 00000000000..e69f3205d14 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_mod_duration.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period1, class Rep2, class Period2> +// constexpr +// typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type +// operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::nanoseconds ns1(15); + std::chrono::nanoseconds ns2(6); + std::chrono::nanoseconds r = ns1 % ns2; + assert(r.count() == 3); + } + { + std::chrono::microseconds us1(15); + std::chrono::nanoseconds ns2(28); + std::chrono::nanoseconds r = us1 % ns2; + assert(r.count() == 20); + } + { + std::chrono::duration<int, std::ratio<3, 5> > s1(6); + std::chrono::duration<int, std::ratio<2, 3> > s2(3); + std::chrono::duration<int, std::ratio<1, 15> > r = s1 % s2; + assert(r.count() == 24); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::nanoseconds ns1(15); + constexpr std::chrono::nanoseconds ns2(6); + constexpr std::chrono::nanoseconds r = ns1 % ns2; + static_assert(r.count() == 3, ""); + } + { + constexpr std::chrono::microseconds us1(15); + constexpr std::chrono::nanoseconds ns2(28); + constexpr std::chrono::nanoseconds r = us1 % ns2; + static_assert(r.count() == 20, ""); + } + { + constexpr std::chrono::duration<int, std::ratio<3, 5> > s1(6); + constexpr std::chrono::duration<int, std::ratio<2, 3> > s2(3); + constexpr std::chrono::duration<int, std::ratio<1, 15> > r = s1 % s2; + static_assert(r.count() == 24, ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.fail.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.fail.cpp new file mode 100644 index 00000000000..16e511d44f6 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator%(const duration<Rep1, Period>& d, const Rep2& s) + +#include <chrono> + +#include "../../rep.h" + +int main() +{ + std::chrono::duration<Rep> d(Rep(15)); + d = d % 5; +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.pass.cpp new file mode 100644 index 00000000000..1acbe34ea5e --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period, class Rep2> +// constexpr +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator%(const duration<Rep1, Period>& d, const Rep2& s) + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::nanoseconds ns(15); + ns = ns % 6; + assert(ns.count() == 3); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::nanoseconds ns(15); + constexpr std::chrono::nanoseconds ns2 = ns % 6; + static_assert(ns2.count() == 3, ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_times_rep.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_times_rep.pass.cpp new file mode 100644 index 00000000000..190e74b1dc3 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_times_rep.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period, class Rep2> +// constexpr +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator*(const duration<Rep1, Period>& d, const Rep2& s); + +// template <class Rep1, class Period, class Rep2> +// constexpr +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator*(const Rep1& s, const duration<Rep2, Period>& d); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::nanoseconds ns(3); + ns = ns * 5; + assert(ns.count() == 15); + ns = 6 * ns; + assert(ns.count() == 90); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::nanoseconds ns(3); + constexpr std::chrono::nanoseconds ns2 = ns * 5; + static_assert(ns2.count() == 15, ""); + constexpr std::chrono::nanoseconds ns3 = 6 * ns; + static_assert(ns3.count() == 18, ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_times_rep1.fail.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_times_rep1.fail.cpp new file mode 100644 index 00000000000..d8160500f91 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_times_rep1.fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator*(const duration<Rep1, Period>& d, const Rep2& s); + +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator*(const Rep1& s, const duration<Rep2, Period>& d); + +#include <chrono> + +#include "../../rep.h" + +int main() +{ + std::chrono::duration<Rep> d; + d = d * 5; +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_times_rep2.fail.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_times_rep2.fail.cpp new file mode 100644 index 00000000000..e224ba94210 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.nonmember/op_times_rep2.fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator*(const duration<Rep1, Period>& d, const Rep2& s); + +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator*(const Rep1& s, const duration<Rep2, Period>& d); + +#include <chrono> + +#include "../../rep.h" + +int main() +{ + std::chrono::duration<Rep> d; + d = 5 * d; +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.observer/tested_elsewhere.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.observer/tested_elsewhere.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.observer/tested_elsewhere.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.special/max.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.special/max.pass.cpp new file mode 100644 index 00000000000..405461e88ae --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.special/max.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// static constexpr duration max(); + +#include <chrono> +#include <limits> +#include <cassert> + +#include "../../rep.h" + +template <class D> +void test() +{ + { + typedef typename D::rep Rep; + Rep max_rep = std::chrono::duration_values<Rep>::max(); + assert(D::max().count() == max_rep); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + typedef typename D::rep Rep; + constexpr Rep max_rep = std::chrono::duration_values<Rep>::max(); + static_assert(D::max().count() == max_rep, ""); + } +#endif +} + +int main() +{ + test<std::chrono::duration<int> >(); + test<std::chrono::duration<Rep> >(); +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.special/min.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.special/min.pass.cpp new file mode 100644 index 00000000000..44cd64eff3d --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.special/min.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// static constexpr duration min(); + +#include <chrono> +#include <limits> +#include <cassert> + +#include "../../rep.h" + +template <class D> +void test() +{ + { + typedef typename D::rep Rep; + Rep min_rep = std::chrono::duration_values<Rep>::min(); + assert(D::min().count() == min_rep); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + typedef typename D::rep Rep; + constexpr Rep min_rep = std::chrono::duration_values<Rep>::min(); + static_assert(D::min().count() == min_rep, ""); + } +#endif +} + +int main() +{ + test<std::chrono::duration<int> >(); + test<std::chrono::duration<Rep> >(); +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.special/zero.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.special/zero.pass.cpp new file mode 100644 index 00000000000..18350fe2ff4 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.special/zero.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// static constexpr duration zero(); + +#include <chrono> +#include <cassert> + +#include "../../rep.h" + +template <class D> +void test() +{ + { + typedef typename D::rep Rep; + Rep zero_rep = std::chrono::duration_values<Rep>::zero(); + assert(D::zero().count() == zero_rep); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + typedef typename D::rep Rep; + constexpr Rep zero_rep = std::chrono::duration_values<Rep>::zero(); + static_assert(D::zero().count() == zero_rep, ""); + } +#endif +} + +int main() +{ + test<std::chrono::duration<int> >(); + test<std::chrono::duration<Rep> >(); +} diff --git a/libcxx/test/std/utilities/time/time.duration/types.pass.cpp b/libcxx/test/std/utilities/time/time.duration/types.pass.cpp new file mode 100644 index 00000000000..8eaffe77651 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.duration/types.pass.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// Test nested types + +// typedef Rep rep; +// typedef Period period; + +#include <chrono> +#include <type_traits> + +int main() +{ + typedef std::chrono::duration<long, std::ratio<3, 2> > D; + static_assert((std::is_same<D::rep, long>::value), ""); + static_assert((std::is_same<D::period, std::ratio<3, 2> >::value), ""); +} diff --git a/libcxx/test/std/utilities/time/time.point/default_duration.pass.cpp b/libcxx/test/std/utilities/time/time.point/default_duration.pass.cpp new file mode 100644 index 00000000000..dfdf225ed47 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/default_duration.pass.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// Test default template arg: + +// template <class Clock, class Duration = typename Clock::duration> +// class time_point; + +#include <chrono> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::chrono::system_clock::duration, + std::chrono::time_point<std::chrono::system_clock>::duration>::value), ""); +} diff --git a/libcxx/test/std/utilities/time/time.point/duration.fail.cpp b/libcxx/test/std/utilities/time/time.point/duration.fail.cpp new file mode 100644 index 00000000000..ee48bcb392e --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/duration.fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// Duration shall be an instance of duration. + +#include <chrono> + +int main() +{ + typedef std::chrono::time_point<std::chrono::system_clock, int> T; + T t; +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.arithmetic/op_+=.pass.cpp b/libcxx/test/std/utilities/time/time.point/time.point.arithmetic/op_+=.pass.cpp new file mode 100644 index 00000000000..ffe855ce903 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.arithmetic/op_+=.pass.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// time_point& operator+=(const duration& d); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration; + std::chrono::time_point<Clock, Duration> t(Duration(3)); + t += Duration(2); + assert(t.time_since_epoch() == Duration(5)); +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.arithmetic/op_-=.pass.cpp b/libcxx/test/std/utilities/time/time.point/time.point.arithmetic/op_-=.pass.cpp new file mode 100644 index 00000000000..acad1cfecb4 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.arithmetic/op_-=.pass.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// time_point& operator-=(const duration& d); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration; + std::chrono::time_point<Clock, Duration> t(Duration(3)); + t -= Duration(2); + assert(t.time_since_epoch() == Duration(1)); +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.cast/time_point_cast.pass.cpp b/libcxx/test/std/utilities/time/time.point/time.point.cast/time_point_cast.pass.cpp new file mode 100644 index 00000000000..7d7e82ac5e2 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.cast/time_point_cast.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class ToDuration, class Clock, class Duration> +// time_point<Clock, ToDuration> +// time_point_cast(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::time_point_cast<ToDuration>(f)) R; + static_assert((std::is_same<R, ToTimePoint>::value), ""); + assert(std::chrono::time_point_cast<ToDuration>(f) == t); + } +} + +#if _LIBCPP_STD_VER > 11 + +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::time_point_cast<ToDuration>(f) == t, ""); + } + +} + +#endif + +int main() +{ + test(std::chrono::milliseconds(7265000), std::chrono::hours(2)); + test(std::chrono::milliseconds(7265000), std::chrono::minutes(121)); + test(std::chrono::milliseconds(7265000), std::chrono::seconds(7265)); + test(std::chrono::milliseconds(7265000), std::chrono::milliseconds(7265000)); + test(std::chrono::milliseconds(7265000), std::chrono::microseconds(7265000000LL)); + test(std::chrono::milliseconds(7265000), std::chrono::nanoseconds(7265000000000LL)); + test(std::chrono::milliseconds(7265000), + std::chrono::duration<double, std::ratio<3600> >(7265./3600)); + test(std::chrono::duration<int, std::ratio<2, 3> >(9), + std::chrono::duration<int, std::ratio<3, 5> >(10)); +#if _LIBCPP_STD_VER > 11 + { + test_constexpr<std::chrono::milliseconds, 7265000, std::chrono::hours, 2> (); + test_constexpr<std::chrono::milliseconds, 7265000, std::chrono::minutes,121> (); + test_constexpr<std::chrono::milliseconds, 7265000, std::chrono::seconds,7265> (); + test_constexpr<std::chrono::milliseconds, 7265000, std::chrono::milliseconds,7265000> (); + test_constexpr<std::chrono::milliseconds, 7265000, std::chrono::microseconds,7265000000LL> (); + test_constexpr<std::chrono::milliseconds, 7265000, std::chrono::nanoseconds,7265000000000LL> (); + typedef std::chrono::duration<int, std::ratio<3, 5>> T1; + test_constexpr<std::chrono::duration<int, std::ratio<2, 3>>, 9, T1, 10> (); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.cast/toduration.fail.cpp b/libcxx/test/std/utilities/time/time.point/time.point.cast/toduration.fail.cpp new file mode 100644 index 00000000000..de1e5bb3e27 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.cast/toduration.fail.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class ToDuration, class Clock, class Duration> +// time_point<Clock, ToDuration> +// time_point_cast(const time_point<Clock, Duration>& t); + +// ToDuration shall be an instantiation of duration. + +#include <chrono> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::time_point<Clock, std::chrono::milliseconds> FromTimePoint; + typedef std::chrono::time_point<Clock, std::chrono::minutes> ToTimePoint; + std::chrono::time_point_cast<ToTimePoint>(FromTimePoint(std::chrono::milliseconds(3))); +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.comparisons/op_equal.fail.cpp b/libcxx/test/std/utilities/time/time.point/time.point.comparisons/op_equal.fail.cpp new file mode 100644 index 00000000000..f5ff11958ba --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.comparisons/op_equal.fail.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// time_points with different clocks should not compare + +#include <chrono> + +#include "../../clock.h" + +int main() +{ + typedef std::chrono::system_clock Clock1; + typedef Clock Clock2; + typedef std::chrono::milliseconds Duration1; + typedef std::chrono::microseconds Duration2; + typedef std::chrono::time_point<Clock1, Duration1> T1; + typedef std::chrono::time_point<Clock2, Duration2> T2; + + T1 t1(Duration1(3)); + T2 t2(Duration2(3000)); + t1 == t2; +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.comparisons/op_equal.pass.cpp b/libcxx/test/std/utilities/time/time.point/time.point.comparisons/op_equal.pass.cpp new file mode 100644 index 00000000000..fbd3a1386d3 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.comparisons/op_equal.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration1; + typedef std::chrono::microseconds Duration2; + typedef std::chrono::time_point<Clock, Duration1> T1; + typedef std::chrono::time_point<Clock, Duration2> T2; + + { + T1 t1(Duration1(3)); + T1 t2(Duration1(3)); + assert( (t1 == t2)); + assert(!(t1 != t2)); + } + { + T1 t1(Duration1(3)); + T1 t2(Duration1(4)); + assert(!(t1 == t2)); + assert( (t1 != t2)); + } + { + T1 t1(Duration1(3)); + T2 t2(Duration2(3000)); + assert( (t1 == t2)); + assert(!(t1 != t2)); + } + { + T1 t1(Duration1(3)); + T2 t2(Duration2(3001)); + assert(!(t1 == t2)); + assert( (t1 != t2)); + } + +#if _LIBCPP_STD_VER > 11 + { + constexpr T1 t1(Duration1(3)); + constexpr T1 t2(Duration1(3)); + static_assert( (t1 == t2), ""); + static_assert(!(t1 != t2), ""); + } + { + constexpr T1 t1(Duration1(3)); + constexpr T1 t2(Duration1(4)); + static_assert(!(t1 == t2), ""); + static_assert( (t1 != t2), ""); + } + { + constexpr T1 t1(Duration1(3)); + constexpr T2 t2(Duration2(3000)); + static_assert( (t1 == t2), ""); + static_assert(!(t1 != t2), ""); + } + { + constexpr T1 t1(Duration1(3)); + constexpr T2 t2(Duration2(3001)); + static_assert(!(t1 == t2), ""); + static_assert( (t1 != t2), ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.comparisons/op_less.fail.cpp b/libcxx/test/std/utilities/time/time.point/time.point.comparisons/op_less.fail.cpp new file mode 100644 index 00000000000..f9745cbf9de --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.comparisons/op_less.fail.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// time_points with different clocks should not compare + +#include <chrono> + +#include "../../clock.h" + +int main() +{ + typedef std::chrono::system_clock Clock1; + typedef Clock Clock2; + typedef std::chrono::milliseconds Duration1; + typedef std::chrono::microseconds Duration2; + typedef std::chrono::time_point<Clock1, Duration1> T1; + typedef std::chrono::time_point<Clock2, Duration2> T2; + + T1 t1(Duration1(3)); + T2 t2(Duration2(3000)); + t1 < t2; +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.comparisons/op_less.pass.cpp b/libcxx/test/std/utilities/time/time.point/time.point.comparisons/op_less.pass.cpp new file mode 100644 index 00000000000..9d94400ed3d --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.comparisons/op_less.pass.cpp @@ -0,0 +1,108 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration1; + typedef std::chrono::microseconds Duration2; + typedef std::chrono::time_point<Clock, Duration1> T1; + typedef std::chrono::time_point<Clock, Duration2> T2; + + { + T1 t1(Duration1(3)); + T1 t2(Duration1(3)); + assert(!(t1 < t2)); + assert(!(t1 > t2)); + assert( (t1 <= t2)); + assert( (t1 >= t2)); + } + { + T1 t1(Duration1(3)); + T1 t2(Duration1(4)); + assert( (t1 < t2)); + assert(!(t1 > t2)); + assert( (t1 <= t2)); + assert(!(t1 >= t2)); + } + { + T1 t1(Duration1(3)); + T2 t2(Duration2(3000)); + assert(!(t1 < t2)); + assert(!(t1 > t2)); + assert( (t1 <= t2)); + assert( (t1 >= t2)); + } + { + T1 t1(Duration1(3)); + T2 t2(Duration2(3001)); + assert( (t1 < t2)); + assert(!(t1 > t2)); + assert( (t1 <= t2)); + assert(!(t1 >= t2)); + } + +#if _LIBCPP_STD_VER > 11 + { + constexpr T1 t1(Duration1(3)); + constexpr T1 t2(Duration1(3)); + static_assert(!(t1 < t2), ""); + static_assert(!(t1 > t2), ""); + static_assert( (t1 <= t2), ""); + static_assert( (t1 >= t2), ""); + } + { + constexpr T1 t1(Duration1(3)); + constexpr T1 t2(Duration1(4)); + static_assert( (t1 < t2), ""); + static_assert(!(t1 > t2), ""); + static_assert( (t1 <= t2), ""); + static_assert(!(t1 >= t2), ""); + } + { + constexpr T1 t1(Duration1(3)); + constexpr T2 t2(Duration2(3000)); + static_assert(!(t1 < t2), ""); + static_assert(!(t1 > t2), ""); + static_assert( (t1 <= t2), ""); + static_assert( (t1 >= t2), ""); + } + { + constexpr T1 t1(Duration1(3)); + constexpr T2 t2(Duration2(3001)); + static_assert( (t1 < t2), ""); + static_assert(!(t1 > t2), ""); + static_assert( (t1 <= t2), ""); + static_assert(!(t1 >= t2), ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.cons/convert.fail.cpp b/libcxx/test/std/utilities/time/time.point/time.point.cons/convert.fail.cpp new file mode 100644 index 00000000000..565aa6c4f52 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.cons/convert.fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class Duration2> +// time_point(const time_point<clock, Duration2>& t); + +// Duration2 shall be implicitly convertible to duration. + +#include <chrono> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration1; + typedef std::chrono::microseconds Duration2; + { + std::chrono::time_point<Clock, Duration2> t2(Duration2(3)); + std::chrono::time_point<Clock, Duration1> t1 = t2; + } +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.cons/convert.pass.cpp b/libcxx/test/std/utilities/time/time.point/time.point.cons/convert.pass.cpp new file mode 100644 index 00000000000..6cd7dcb7d2f --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.cons/convert.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class Duration2> +// time_point(const time_point<clock, Duration2>& t); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::microseconds Duration1; + typedef std::chrono::milliseconds Duration2; + { + std::chrono::time_point<Clock, Duration2> t2(Duration2(3)); + std::chrono::time_point<Clock, Duration1> t1 = t2; + assert(t1.time_since_epoch() == Duration1(3000)); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::chrono::time_point<Clock, Duration2> t2(Duration2(3)); + constexpr std::chrono::time_point<Clock, Duration1> t1 = t2; + static_assert(t1.time_since_epoch() == Duration1(3000), ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.cons/default.pass.cpp b/libcxx/test/std/utilities/time/time.point/time.point.cons/default.pass.cpp new file mode 100644 index 00000000000..01f0bc16993 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.cons/default.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// time_point(); + +#include <chrono> +#include <cassert> + +#include "../../rep.h" + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::duration<Rep, std::milli> Duration; + { + std::chrono::time_point<Clock, Duration> t; + assert(t.time_since_epoch() == Duration::zero()); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::chrono::time_point<Clock, Duration> t; + static_assert(t.time_since_epoch() == Duration::zero(), ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.cons/duration.fail.cpp b/libcxx/test/std/utilities/time/time.point/time.point.cons/duration.fail.cpp new file mode 100644 index 00000000000..810007ed942 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.cons/duration.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// explicit time_point(const duration& d); + +// test for explicit + +#include <chrono> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration; + std::chrono::time_point<Clock, Duration> t = Duration(3); +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.cons/duration.pass.cpp b/libcxx/test/std/utilities/time/time.point/time.point.cons/duration.pass.cpp new file mode 100644 index 00000000000..9d53d86dea3 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.cons/duration.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// explicit time_point(const duration& d); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration; + { + std::chrono::time_point<Clock, Duration> t(Duration(3)); + assert(t.time_since_epoch() == Duration(3)); + } + { + std::chrono::time_point<Clock, Duration> t(std::chrono::seconds(3)); + assert(t.time_since_epoch() == Duration(3000)); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::chrono::time_point<Clock, Duration> t(Duration(3)); + static_assert(t.time_since_epoch() == Duration(3), ""); + } + { + constexpr std::chrono::time_point<Clock, Duration> t(std::chrono::seconds(3)); + static_assert(t.time_since_epoch() == Duration(3000), ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.nonmember/op_+.pass.cpp b/libcxx/test/std/utilities/time/time.point/time.point.nonmember/op_+.pass.cpp new file mode 100644 index 00000000000..7a8fa6dcf14 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.nonmember/op_+.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class Clock, class Duration1, class Rep2, class Period2> +// time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> +// operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); + +// template <class Rep1, class Period1, class Clock, class Duration2> +// time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type> +// operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration1; + typedef std::chrono::microseconds Duration2; + { + std::chrono::time_point<Clock, Duration1> t1(Duration1(3)); + std::chrono::time_point<Clock, Duration2> t2 = t1 + Duration2(5); + assert(t2.time_since_epoch() == Duration2(3005)); + t2 = Duration2(6) + t1; + assert(t2.time_since_epoch() == Duration2(3006)); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::chrono::time_point<Clock, Duration1> t1(Duration1(3)); + constexpr std::chrono::time_point<Clock, Duration2> t2 = t1 + Duration2(5); + static_assert(t2.time_since_epoch() == Duration2(3005), ""); + constexpr std::chrono::time_point<Clock, Duration2> t3 = Duration2(6) + t1; + static_assert(t3.time_since_epoch() == Duration2(3006), ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.nonmember/op_-duration.pass.cpp b/libcxx/test/std/utilities/time/time.point/time.point.nonmember/op_-duration.pass.cpp new file mode 100644 index 00000000000..342d27b5aeb --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.nonmember/op_-duration.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class Clock, class Duration1, class Rep2, class Period2> +// time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> +// operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration1; + typedef std::chrono::microseconds Duration2; + { + std::chrono::time_point<Clock, Duration1> t1(Duration1(3)); + std::chrono::time_point<Clock, Duration2> t2 = t1 - Duration2(5); + assert(t2.time_since_epoch() == Duration2(2995)); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::chrono::time_point<Clock, Duration1> t1(Duration1(3)); + constexpr std::chrono::time_point<Clock, Duration2> t2 = t1 - Duration2(5); + static_assert(t2.time_since_epoch() == Duration2(2995), ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.nonmember/op_-time_point.pass.cpp b/libcxx/test/std/utilities/time/time.point/time.point.nonmember/op_-time_point.pass.cpp new file mode 100644 index 00000000000..5267f07e1b8 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.nonmember/op_-time_point.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class Clock, class Duration1, class Duration2> +// typename common_type<Duration1, Duration2>::type +// operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration1; + typedef std::chrono::microseconds Duration2; + { + std::chrono::time_point<Clock, Duration1> t1(Duration1(3)); + std::chrono::time_point<Clock, Duration2> t2(Duration2(5)); + assert((t1 - t2) == Duration2(2995)); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::chrono::time_point<Clock, Duration1> t1(Duration1(3)); + constexpr std::chrono::time_point<Clock, Duration2> t2(Duration2(5)); + static_assert((t1 - t2) == Duration2(2995), ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.observer/tested_elsewhere.pass.cpp b/libcxx/test/std/utilities/time/time.point/time.point.observer/tested_elsewhere.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.observer/tested_elsewhere.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.special/max.pass.cpp b/libcxx/test/std/utilities/time/time.point/time.point.special/max.pass.cpp new file mode 100644 index 00000000000..6bba6fc8278 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.special/max.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// static constexpr time_point max(); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration; + typedef std::chrono::time_point<Clock, Duration> TP; + assert(TP::max() == TP(Duration::max())); +} diff --git a/libcxx/test/std/utilities/time/time.point/time.point.special/min.pass.cpp b/libcxx/test/std/utilities/time/time.point/time.point.special/min.pass.cpp new file mode 100644 index 00000000000..b1d955c252a --- /dev/null +++ b/libcxx/test/std/utilities/time/time.point/time.point.special/min.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// static constexpr time_point min(); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration; + typedef std::chrono::time_point<Clock, Duration> TP; + assert(TP::min() == TP(Duration::min())); +} diff --git a/libcxx/test/std/utilities/time/time.traits/nothing_to_do.pass.cpp b/libcxx/test/std/utilities/time/time.traits/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.traits/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/utilities/time/time.traits/time.traits.duration_values/max.pass.cpp b/libcxx/test/std/utilities/time/time.traits/time.traits.duration_values/max.pass.cpp new file mode 100644 index 00000000000..89dc1dcc1a5 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.traits/time.traits.duration_values/max.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration_values::max + +#include <chrono> +#include <limits> +#include <cassert> + +#include "../../rep.h" + +int main() +{ + assert(std::chrono::duration_values<int>::max() == + std::numeric_limits<int>::max()); + assert(std::chrono::duration_values<double>::max() == + std::numeric_limits<double>::max()); + assert(std::chrono::duration_values<Rep>::max() == + std::numeric_limits<Rep>::max()); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + static_assert(std::chrono::duration_values<int>::max() == + std::numeric_limits<int>::max(), ""); + static_assert(std::chrono::duration_values<double>::max() == + std::numeric_limits<double>::max(), ""); + static_assert(std::chrono::duration_values<Rep>::max() == + std::numeric_limits<Rep>::max(), ""); +#endif +} diff --git a/libcxx/test/std/utilities/time/time.traits/time.traits.duration_values/min.pass.cpp b/libcxx/test/std/utilities/time/time.traits/time.traits.duration_values/min.pass.cpp new file mode 100644 index 00000000000..69812bba006 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.traits/time.traits.duration_values/min.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration_values::min + +#include <chrono> +#include <limits> +#include <cassert> + +#include "../../rep.h" + +int main() +{ + assert(std::chrono::duration_values<int>::min() == + std::numeric_limits<int>::lowest()); + assert(std::chrono::duration_values<double>::min() == + std::numeric_limits<double>::lowest()); + assert(std::chrono::duration_values<Rep>::min() == + std::numeric_limits<Rep>::lowest()); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + static_assert(std::chrono::duration_values<int>::min() == + std::numeric_limits<int>::lowest(), ""); + static_assert(std::chrono::duration_values<double>::min() == + std::numeric_limits<double>::lowest(), ""); + static_assert(std::chrono::duration_values<Rep>::min() == + std::numeric_limits<Rep>::lowest(), ""); +#endif +} diff --git a/libcxx/test/std/utilities/time/time.traits/time.traits.duration_values/zero.pass.cpp b/libcxx/test/std/utilities/time/time.traits/time.traits.duration_values/zero.pass.cpp new file mode 100644 index 00000000000..234b4bc31c9 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.traits/time.traits.duration_values/zero.pass.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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration_values::zero + +#include <chrono> +#include <cassert> + +#include "../../rep.h" + +int main() +{ + assert(std::chrono::duration_values<int>::zero() == 0); + assert(std::chrono::duration_values<Rep>::zero() == 0); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + static_assert(std::chrono::duration_values<int>::zero() == 0, ""); + static_assert(std::chrono::duration_values<Rep>::zero() == 0, ""); +#endif +} diff --git a/libcxx/test/std/utilities/time/time.traits/time.traits.is_fp/treat_as_floating_point.pass.cpp b/libcxx/test/std/utilities/time/time.traits/time.traits.is_fp/treat_as_floating_point.pass.cpp new file mode 100644 index 00000000000..c32350faa83 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.traits/time.traits.is_fp/treat_as_floating_point.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// treat_as_floating_point + +#include <chrono> +#include <type_traits> + +template <class T> +void +test() +{ + static_assert((std::is_base_of<std::is_floating_point<T>, + std::chrono::treat_as_floating_point<T> >::value), ""); +} + +struct A {}; + +int main() +{ + test<int>(); + test<unsigned>(); + test<char>(); + test<bool>(); + test<float>(); + test<double>(); + test<long double>(); + test<A>(); +} diff --git a/libcxx/test/std/utilities/time/time.traits/time.traits.specializations/duration.pass.cpp b/libcxx/test/std/utilities/time/time.traits/time.traits.specializations/duration.pass.cpp new file mode 100644 index 00000000000..f942844b60a --- /dev/null +++ b/libcxx/test/std/utilities/time/time.traits/time.traits.specializations/duration.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// template <class Rep1, class Period1, class Rep2, class Period2> +// struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>> +// { +// typedef chrono::duration<typename common_type<Rep1, Rep2>::type, see below }> type; +// }; + +#include <chrono> + +template <class D1, class D2, class De> +void +test() +{ + typedef typename std::common_type<D1, D2>::type Dc; + static_assert((std::is_same<Dc, De>::value), ""); +} + +int main() +{ + test<std::chrono::duration<int, std::ratio<1, 100> >, + std::chrono::duration<long, std::ratio<1, 1000> >, + std::chrono::duration<long, std::ratio<1, 1000> > >(); + test<std::chrono::duration<long, std::ratio<1, 100> >, + std::chrono::duration<int, std::ratio<1, 1000> >, + std::chrono::duration<long, std::ratio<1, 1000> > >(); + test<std::chrono::duration<char, std::ratio<1, 30> >, + std::chrono::duration<short, std::ratio<1, 1000> >, + std::chrono::duration<int, std::ratio<1, 3000> > >(); + test<std::chrono::duration<double, std::ratio<21, 1> >, + std::chrono::duration<short, std::ratio<15, 1> >, + std::chrono::duration<double, std::ratio<3, 1> > >(); +} diff --git a/libcxx/test/std/utilities/time/time.traits/time.traits.specializations/time_point.pass.cpp b/libcxx/test/std/utilities/time/time.traits/time.traits.specializations/time_point.pass.cpp new file mode 100644 index 00000000000..a0786b49924 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.traits/time.traits.specializations/time_point.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// template <class Clock, class Duration1, class Duration2> +// struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>> +// { +// typedef chrono::time_point<Clock, typename common_type<Duration1, Duration2>::type> type; +// }; + +#include <chrono> + +template <class D1, class D2, class De> +void +test() +{ + typedef std::chrono::system_clock C; + typedef std::chrono::time_point<C, D1> T1; + typedef std::chrono::time_point<C, D2> T2; + typedef std::chrono::time_point<C, De> Te; + typedef typename std::common_type<T1, T2>::type Tc; + static_assert((std::is_same<Tc, Te>::value), ""); +} + +int main() +{ + test<std::chrono::duration<int, std::ratio<1, 100> >, + std::chrono::duration<long, std::ratio<1, 1000> >, + std::chrono::duration<long, std::ratio<1, 1000> > >(); + test<std::chrono::duration<long, std::ratio<1, 100> >, + std::chrono::duration<int, std::ratio<1, 1000> >, + std::chrono::duration<long, std::ratio<1, 1000> > >(); + test<std::chrono::duration<char, std::ratio<1, 30> >, + std::chrono::duration<short, std::ratio<1, 1000> >, + std::chrono::duration<int, std::ratio<1, 3000> > >(); + test<std::chrono::duration<double, std::ratio<21, 1> >, + std::chrono::duration<short, std::ratio<15, 1> >, + std::chrono::duration<double, std::ratio<3, 1> > >(); +} diff --git a/libcxx/test/std/utilities/time/version.pass.cpp b/libcxx/test/std/utilities/time/version.pass.cpp new file mode 100644 index 00000000000..bfa3f6d6797 --- /dev/null +++ b/libcxx/test/std/utilities/time/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +#include <chrono> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} |