brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.1 KiB · 8f7a79e Raw
94 lines · cpp
1//===-- Unittests for localtime_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/localtime_r.h"10#include "test/UnitTest/Test.h"11 12TEST(LlvmLibcLocaltimeR, ValidUnixTimestamp0) {13  struct tm input = {.tm_sec = 0,14                     .tm_min = 0,15                     .tm_hour = 0,16                     .tm_mday = 0,17                     .tm_mon = 0,18                     .tm_year = 0,19                     .tm_wday = 0,20                     .tm_yday = 0,21                     .tm_isdst = 0};22  const time_t timer = 0;23 24  struct tm *result = LIBC_NAMESPACE::localtime_r(&timer, &input);25 26  ASSERT_EQ(70, result->tm_year);27  ASSERT_EQ(0, result->tm_mon);28  ASSERT_EQ(1, result->tm_mday);29  ASSERT_EQ(0, result->tm_hour);30  ASSERT_EQ(0, result->tm_min);31  ASSERT_EQ(0, result->tm_sec);32  ASSERT_EQ(4, result->tm_wday);33  ASSERT_EQ(0, result->tm_yday);34  ASSERT_EQ(0, result->tm_isdst);35}36 37TEST(LlvmLibcLocaltime, NullPtr) {38  EXPECT_DEATH([] { LIBC_NAMESPACE::localtime_r(nullptr, nullptr); },39               WITH_SIGNAL(4));40}41 42// TODO(zimirza): These tests does not expect the correct output of localtime as43// per specification. This is due to timezone functions removed from44// https://github.com/llvm/llvm-project/pull/110363.45// This will be resolved a new pull request.46 47TEST(LlvmLibcLocaltimeR, ValidUnixTimestamp) {48  struct tm input = {.tm_sec = 0,49                     .tm_min = 0,50                     .tm_hour = 0,51                     .tm_mday = 0,52                     .tm_mon = 0,53                     .tm_year = 0,54                     .tm_wday = 0,55                     .tm_yday = 0,56                     .tm_isdst = 0};57  const time_t timer = 1756595338;58  struct tm *result = LIBC_NAMESPACE::localtime_r(&timer, &input);59 60  ASSERT_EQ(125, result->tm_year);61  ASSERT_EQ(7, result->tm_mon);62  ASSERT_EQ(30, result->tm_mday);63  ASSERT_EQ(23, result->tm_hour);64  ASSERT_EQ(8, result->tm_min);65  ASSERT_EQ(58, result->tm_sec);66  ASSERT_EQ(6, result->tm_wday);67  ASSERT_EQ(241, result->tm_yday);68  ASSERT_EQ(0, result->tm_isdst);69}70 71TEST(LlvmLibcLocaltimeR, ValidUnixTimestampNegative) {72  struct tm input = {.tm_sec = 0,73                     .tm_min = 0,74                     .tm_hour = 0,75                     .tm_mday = 0,76                     .tm_mon = 0,77                     .tm_year = 0,78                     .tm_wday = 0,79                     .tm_yday = 0,80                     .tm_isdst = 0};81  const time_t timer = -1756595338;82  struct tm *result = LIBC_NAMESPACE::localtime_r(&timer, &input);83 84  ASSERT_EQ(14, result->tm_year);85  ASSERT_EQ(4, result->tm_mon);86  ASSERT_EQ(4, result->tm_mday);87  ASSERT_EQ(0, result->tm_hour);88  ASSERT_EQ(51, result->tm_min);89  ASSERT_EQ(2, result->tm_sec);90  ASSERT_EQ(1, result->tm_wday);91  ASSERT_EQ(123, result->tm_yday);92  ASSERT_EQ(0, result->tm_isdst);93}94