1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // test <ctime>
11
12 #include <ctime>
13 #include <type_traits>
14 #include "test_macros.h"
15
16 #ifndef NULL
17 #error NULL not defined
18 #endif
19
20 #ifndef CLOCKS_PER_SEC
21 #error CLOCKS_PER_SEC not defined
22 #endif
23
24 #if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES)
25 #ifndef TIME_UTC
26 #error TIME_UTC not defined
27 #endif
28 #endif
29
main()30 int main()
31 {
32 std::clock_t c = 0;
33 std::size_t s = 0;
34 std::time_t t = 0;
35 std::tm tm = {};
36 #if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES)
37 std::timespec tmspec = {};
38 ((void)tmspec); // Prevent unused warning
39 #endif
40 ((void)c); // Prevent unused warning
41 ((void)s); // Prevent unused warning
42 ((void)t); // Prevent unused warning
43 ((void)tm); // Prevent unused warning
44 static_assert((std::is_same<decltype(std::clock()), std::clock_t>::value), "");
45 static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), "");
46 static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), "");
47 static_assert((std::is_same<decltype(std::time(&t)), std::time_t>::value), "");
48 #if TEST_STD_VER > 14 && defined(TEST_HAS_TIMESPEC_GET)
49 static_assert((std::is_same<decltype(std::timespec_get(nullptr, 0)), int>::value), "");
50 #endif
51 #ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
52 static_assert((std::is_same<decltype(std::asctime(&tm)), char*>::value), "");
53 static_assert((std::is_same<decltype(std::ctime(&t)), char*>::value), "");
54 static_assert((std::is_same<decltype(std::gmtime(&t)), std::tm*>::value), "");
55 static_assert((std::is_same<decltype(std::localtime(&t)), std::tm*>::value), "");
56 #endif
57 char* c1 = 0;
58 const char* c2 = 0;
59 ((void)c1); // Prevent unused warning
60 ((void)c2); // Prevent unused warning
61 static_assert((std::is_same<decltype(std::strftime(c1,s,c2,&tm)), std::size_t>::value), "");
62 }
63