summaryrefslogtreecommitdiff
path: root/libc/test/src/time/ctime_test.cpp
blob: 5ff69f6619b4f620a4e97d0578f17e659dde92d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//===-- Unittests for ctime -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/__support/libc_errno.h"
#include "src/time/ctime.h"
#include "test/UnitTest/Test.h"
#include "test/src/time/TmHelper.h"

TEST(LlvmLibcCtime, nullptr) {
  char *result;
  result = LIBC_NAMESPACE::ctime(nullptr);
  ASSERT_STREQ(nullptr, result);
}

TEST(LlvmLibcCtime, ValidUnixTimestamp0) {
  time_t t;
  char *result;
  t = 0;
  result = LIBC_NAMESPACE::ctime(&t);
  ASSERT_STREQ("Thu Jan  1 00:00:00 1970\n", result);
}

TEST(LlvmLibcCtime, ValidUnixTimestamp32Int) {
  time_t t;
  char *result;
  t = 2147483647;
  result = LIBC_NAMESPACE::ctime(&t);
  ASSERT_STREQ("Tue Jan 19 03:14:07 2038\n", result);
}

TEST(LlvmLibcCtime, InvalidArgument) {
  time_t t;
  char *result;
  t = 2147483648;
  result = LIBC_NAMESPACE::ctime(&t);
  ASSERT_STREQ(nullptr, result);
}