1 //===-- Unittests for gmtime_r --------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "src/time/gmtime_r.h"
10 #include "src/time/time_constants.h"
11 #include "test/UnitTest/Test.h"
12 #include "test/src/time/TmMatcher.h"
14 // gmtime and gmtime_r share the same code and thus didn't repeat all the tests
15 // from gmtime. Added couple of validation tests.
16 TEST(LlvmLibcGmTimeR
, EndOf32BitEpochYear
) {
17 // Test for maximum value of a signed 32-bit integer.
18 // Test implementation can encode time for Tue 19 January 2038 03:14:07 UTC.
19 time_t seconds
= 0x7FFFFFFF;
21 struct tm
*tm_data_ptr
;
22 tm_data_ptr
= LIBC_NAMESPACE::gmtime_r(&seconds
, &tm_data
);
28 0, // tm_mon starts with 0 for Jan
29 2038 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE
, // year
34 EXPECT_TM_EQ(*tm_data_ptr
, tm_data
);
37 TEST(LlvmLibcGmTimeR
, Max64BitYear
) {
38 if (sizeof(time_t) == 4)
40 // Test for Tue Jan 1 12:50:50 in 2,147,483,647th year.
41 time_t seconds
= 67767976202043050;
43 struct tm
*tm_data_ptr
;
44 tm_data_ptr
= LIBC_NAMESPACE::gmtime_r(&seconds
, &tm_data
);
50 0, // tm_mon starts with 0 for Jan
51 2147483647 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE
, // year
56 EXPECT_TM_EQ(*tm_data_ptr
, tm_data
);