summaryrefslogtreecommitdiff
path: root/Tests/LibC/TestLibCTime.cpp
blob: fcf232763925e42c0f32d56b75868651a323519c (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
43
/*
 * Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <AK/StringView.h>
#include <LibTest/TestCase.h>
#include <time.h>

const auto expected_epoch = "Thu Jan  1 00:00:00 1970\n"sv;

TEST_CASE(asctime)
{
    time_t epoch = 0;
    auto result = asctime(localtime(&epoch));
    EXPECT_EQ(expected_epoch, StringView(result));
}

TEST_CASE(asctime_r)
{
    char buffer[26] {};
    time_t epoch = 0;
    auto result = asctime_r(localtime(&epoch), buffer);
    EXPECT_EQ(expected_epoch, StringView(result));
}

TEST_CASE(ctime)
{
    time_t epoch = 0;
    auto result = ctime(&epoch);

    EXPECT_EQ(expected_epoch, StringView(result));
}

TEST_CASE(ctime_r)
{
    char buffer[26] {};
    time_t epoch = 0;
    auto result = ctime_r(&epoch, buffer);

    EXPECT_EQ(expected_epoch, StringView(result));
}