xref: /aosp_15_r20/external/llvm-libc/test/src/time/ctime_test.cpp (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
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/errno/libc_errno.h"
10 #include "src/time/ctime.h"
11 #include "test/UnitTest/Test.h"
12 #include "test/src/time/TmHelper.h"
13 
TEST(LlvmLibcCtime,NULL)14 TEST(LlvmLibcCtime, NULL) {
15   char *result;
16   result = LIBC_NAMESPACE::ctime(NULL);
17   ASSERT_STREQ(NULL, result);
18 }
19 
TEST(LlvmLibcCtime,ValidUnixTimestamp0)20 TEST(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 
TEST(LlvmLibcCtime,ValidUnixTimestamp32Int)28 TEST(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 
TEST(LlvmLibcCtime,InvalidArgument)36 TEST(LlvmLibcCtime, InvalidArgument) {
37   time_t t;
38   char *result;
39   t = 2147483648;
40   result = LIBC_NAMESPACE::ctime(&t);
41   ASSERT_STREQ(NULL, result);
42 }
43