1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
9 // <chrono>
10
11 // template <class Duration>
12 // class hh_mm_ss
13 //
14 // constexpr chrono::seconds seconds() const noexcept;
15 //
16 // See the table in hours.pass.cpp for correspondence between the magic values used below
17
18 #include <chrono>
19 #include <cassert>
20
21 #include "test_macros.h"
22
23 template <typename Duration>
check_seconds(Duration d)24 constexpr long check_seconds(Duration d)
25 {
26 using HMS = std::chrono::hh_mm_ss<Duration>;
27 ASSERT_SAME_TYPE(std::chrono::seconds, decltype(std::declval<HMS>().seconds()));
28 ASSERT_NOEXCEPT( std::declval<HMS>().seconds());
29 return HMS(d).seconds().count();
30 }
31
main(int,char **)32 int main(int, char**)
33 {
34 using microfortnights = std::chrono::duration<int, std::ratio<756, 625>>;
35
36 static_assert( check_seconds(std::chrono::seconds( 1)) == 1, "");
37 static_assert( check_seconds(std::chrono::seconds(-1)) == 1, "");
38
39 assert( check_seconds(std::chrono::seconds( 5000)) == 20);
40 assert( check_seconds(std::chrono::seconds(-5000)) == 20);
41 assert( check_seconds(std::chrono::minutes( 5000)) == 0);
42 assert( check_seconds(std::chrono::minutes(-5000)) == 0);
43 assert( check_seconds(std::chrono::hours( 11)) == 0);
44 assert( check_seconds(std::chrono::hours(-11)) == 0);
45
46 assert( check_seconds(std::chrono::milliseconds( 123456789LL)) == 36);
47 assert( check_seconds(std::chrono::milliseconds(-123456789LL)) == 36);
48 assert( check_seconds(std::chrono::microseconds( 123456789LL)) == 3);
49 assert( check_seconds(std::chrono::microseconds(-123456789LL)) == 3);
50 assert( check_seconds(std::chrono::nanoseconds( 123456789LL)) == 0);
51 assert( check_seconds(std::chrono::nanoseconds(-123456789LL)) == 0);
52
53 assert( check_seconds(microfortnights( 1000)) == 9);
54 assert( check_seconds(microfortnights( -1000)) == 9);
55 assert( check_seconds(microfortnights( 10000)) == 36);
56 assert( check_seconds(microfortnights(-10000)) == 36);
57
58 return 0;
59 }
60