ctime.pass.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. // test <ctime>
  9. #include <ctime>
  10. #include <type_traits>
  11. #include "test_macros.h"
  12. #ifndef NULL
  13. #error NULL not defined
  14. #endif
  15. #ifndef CLOCKS_PER_SEC
  16. #error CLOCKS_PER_SEC not defined
  17. #endif
  18. #if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES)
  19. #ifndef TIME_UTC
  20. #error TIME_UTC not defined
  21. #endif
  22. #endif
  23. int main(int, char**)
  24. {
  25. std::clock_t c = 0;
  26. std::size_t s = 0;
  27. std::time_t t = 0;
  28. std::tm tm = {};
  29. #if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES)
  30. std::timespec tmspec = {};
  31. ((void)tmspec); // Prevent unused warning
  32. #endif
  33. ((void)c); // Prevent unused warning
  34. ((void)s); // Prevent unused warning
  35. ((void)t); // Prevent unused warning
  36. ((void)tm); // Prevent unused warning
  37. static_assert((std::is_same<decltype(std::clock()), std::clock_t>::value), "");
  38. static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), "");
  39. static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), "");
  40. static_assert((std::is_same<decltype(std::time(&t)), std::time_t>::value), "");
  41. #if TEST_STD_VER > 14 && defined(TEST_HAS_TIMESPEC_GET)
  42. static_assert((std::is_same<decltype(std::timespec_get(nullptr, 0)), int>::value), "");
  43. #endif
  44. #ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
  45. static_assert((std::is_same<decltype(std::asctime(&tm)), char*>::value), "");
  46. static_assert((std::is_same<decltype(std::ctime(&t)), char*>::value), "");
  47. static_assert((std::is_same<decltype(std::gmtime(&t)), std::tm*>::value), "");
  48. static_assert((std::is_same<decltype(std::localtime(&t)), std::tm*>::value), "");
  49. #endif
  50. char* c1 = 0;
  51. const char* c2 = 0;
  52. ((void)c1); // Prevent unused warning
  53. ((void)c2); // Prevent unused warning
  54. static_assert((std::is_same<decltype(std::strftime(c1,s,c2,&tm)), std::size_t>::value), "");
  55. return 0;
  56. }