TestLibCTime.cpp 886 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/StringView.h>
  7. #include <AK/TestSuite.h>
  8. #include <time.h>
  9. const auto expected_epoch = "Thu Jan 1 00:00:00 1970\n"sv;
  10. TEST_CASE(asctime)
  11. {
  12. time_t epoch = 0;
  13. auto result = asctime(localtime(&epoch));
  14. EXPECT_EQ(expected_epoch, StringView(result));
  15. }
  16. TEST_CASE(asctime_r)
  17. {
  18. char buffer[26] {};
  19. time_t epoch = 0;
  20. auto result = asctime_r(localtime(&epoch), buffer);
  21. EXPECT_EQ(expected_epoch, StringView(result));
  22. }
  23. TEST_CASE(ctime)
  24. {
  25. time_t epoch = 0;
  26. auto result = ctime(&epoch);
  27. EXPECT_EQ(expected_epoch, StringView(result));
  28. }
  29. TEST_CASE(ctime_r)
  30. {
  31. char buffer[26] {};
  32. time_t epoch = 0;
  33. auto result = ctime_r(&epoch, buffer);
  34. EXPECT_EQ(expected_epoch, StringView(result));
  35. }
  36. TEST_MAIN(LibCTime)