brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · b8da357 Raw
61 lines · cpp
1//===-- Unittests for gmtime_r --------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/time/gmtime_r.h"10#include "src/time/time_constants.h"11#include "test/UnitTest/ErrnoCheckingTest.h"12#include "test/UnitTest/Test.h"13#include "test/src/time/TmMatcher.h"14 15using LlvmLibcGmTimeR = LIBC_NAMESPACE::testing::ErrnoCheckingTest;16 17// gmtime and gmtime_r share the same code and thus didn't repeat all the tests18// from gmtime. Added couple of validation tests.19TEST_F(LlvmLibcGmTimeR, EndOf32BitEpochYear) {20  // Test for maximum value of a signed 32-bit integer.21  // Test implementation can encode time for Tue 19 January 2038 03:14:07 UTC.22  time_t seconds = 0x7FFFFFFF;23  struct tm tm_data;24  struct tm *tm_data_ptr;25  tm_data_ptr = LIBC_NAMESPACE::gmtime_r(&seconds, &tm_data);26  EXPECT_TM_EQ(27      (tm{7,  // sec28          14, // min29          3,  // hr30          19, // day31          0,  // tm_mon starts with 0 for Jan32          2038 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year33          2,                                                     // wday34          7,                                                     // yday35          0}),36      *tm_data_ptr);37  EXPECT_TM_EQ(*tm_data_ptr, tm_data);38}39 40TEST_F(LlvmLibcGmTimeR, Max64BitYear) {41  if (sizeof(time_t) == 4)42    return;43  // Test for Tue Jan 1 12:50:50 in 2,147,483,647th year.44  time_t seconds = 67767976202043050;45  struct tm tm_data;46  struct tm *tm_data_ptr;47  tm_data_ptr = LIBC_NAMESPACE::gmtime_r(&seconds, &tm_data);48  EXPECT_TM_EQ(49      (tm{50, // sec50          50, // min51          12, // hr52          1,  // day53          0,  // tm_mon starts with 0 for Jan54          2147483647 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year55          2,                                                           // wday56          50,                                                          // yday57          0}),58      *tm_data_ptr);59  EXPECT_TM_EQ(*tm_data_ptr, tm_data);60}61