summaryrefslogtreecommitdiff
path: root/Tests/LibC/TestLibCTime.cpp
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2021-05-06 01:14:50 -0700
committerAndreas Kling <kling@serenityos.org>2021-05-06 17:54:28 +0200
commitfd0dbd1ebfbcbc29d46393061daa49dc7390caa7 (patch)
tree278ea94a46900e47ff7dae46b1017cd31095971a /Tests/LibC/TestLibCTime.cpp
parent6e641fadfa61d4b890db52fb60cc3709352336b6 (diff)
downloadserenity-fd0dbd1ebfbcbc29d46393061daa49dc7390caa7.zip
Tests: Establish root Tests directory, move Userland/Tests there
With the goal of centralizing all tests in the system, this is a first step to establish a Tests sub-tree. It will contain all of the unit tests and test harnesses for the various components in the system.
Diffstat (limited to 'Tests/LibC/TestLibCTime.cpp')
-rw-r--r--Tests/LibC/TestLibCTime.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/Tests/LibC/TestLibCTime.cpp b/Tests/LibC/TestLibCTime.cpp
new file mode 100644
index 0000000000..fcf2327639
--- /dev/null
+++ b/Tests/LibC/TestLibCTime.cpp
@@ -0,0 +1,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));
+}