mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 13:17:34 +00:00
Tests: Unify LibC tests to single location.
In a1720eed2a
I added this new test,
but missed that there were already some "unit tests" for LibC over
in Userland/Tests/LibC. So lets unify these two locations.
This commit is contained in:
parent
7a0d7525f1
commit
8ae3191ab5
5 changed files with 10 additions and 13 deletions
|
@ -1,6 +1,11 @@
|
|||
set(TEST_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/snprintf-correctness.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/strlcpy-correctness.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TestLibCTime.cpp
|
||||
)
|
||||
|
||||
file(GLOB CMD_SOURCES CONFIGURE_DEPENDS "*.cpp")
|
||||
list(REMOVE_ITEM CMD_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/snprintf-correctness.cpp)
|
||||
list(REMOVE_ITEM CMD_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/strlcpy-correctness.cpp)
|
||||
list(REMOVE_ITEM CMD_SOURCES ${TEST_SOURCES})
|
||||
|
||||
# FIXME: These tests do not use LibTest
|
||||
foreach(CMD_SRC ${CMD_SOURCES})
|
||||
|
@ -10,5 +15,6 @@ foreach(CMD_SRC ${CMD_SOURCES})
|
|||
install(TARGETS ${CMD_NAME} RUNTIME DESTINATION usr/Tests/LibC)
|
||||
endforeach()
|
||||
|
||||
serenity_test(snprintf-correctness.cpp LibC)
|
||||
serenity_test(strlcpy-correctness.cpp LibC)
|
||||
foreach(source ${TEST_SOURCES})
|
||||
serenity_test(${source} LibC)
|
||||
endforeach()
|
||||
|
|
43
Userland/Tests/LibC/TestLibCTime.cpp
Normal file
43
Userland/Tests/LibC/TestLibCTime.cpp
Normal file
|
@ -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));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue