1//===-- Unittests for ctime -----------------------------------------------===//
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
9#include "src/__support/libc_errno.h"
10#include "src/time/ctime.h"
11#include "test/UnitTest/Test.h"
12#include "test/src/time/TmHelper.h"
13
14TEST(LlvmLibcCtime, nullptr) {
15 char *result;
16 result = LIBC_NAMESPACE::ctime(nullptr);
17 ASSERT_STREQ(nullptr, result);
18}
19
20TEST(LlvmLibcCtime, ValidUnixTimestamp0) {
21 time_t t;
22 char *result;
23 t = 0;
24 result = LIBC_NAMESPACE::ctime(&t);
25 ASSERT_STREQ("Thu Jan 1 00:00:00 1970\n", result);
26}
27
28TEST(LlvmLibcCtime, ValidUnixTimestamp32Int) {
29 time_t t;
30 char *result;
31 t = 2147483647;
32 result = LIBC_NAMESPACE::ctime(&t);
33 ASSERT_STREQ("Tue Jan 19 03:14:07 2038\n", result);
34}
35
36TEST(LlvmLibcCtime, InvalidArgument) {
37 time_t t;
38 char *result;
39 t = 2147483648;
40 result = LIBC_NAMESPACE::ctime(&t);
41 ASSERT_STREQ(nullptr, result);
42}
43

source code of libc/test/src/time/ctime_test.cpp