mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
LibCore: Drop TestLibCoreIODevice
It does not make sense to test known-working code that is deprecated and in the process of being removed. Also, this test becomes too cumbersome to write without using read_all or line iteration in some form, and migrating the test is just silly.
This commit is contained in:
parent
8ba7bd1b67
commit
64a2a63df6
Notes:
sideshowbarker
2024-07-17 07:08:37 +09:00
Author: https://github.com/BenWiederhake Commit: https://github.com/SerenityOS/serenity/commit/64a2a63df6 Pull-request: https://github.com/SerenityOS/serenity/pull/18930 Reviewed-by: https://github.com/gmta ✅
3 changed files with 0 additions and 96 deletions
|
@ -627,8 +627,6 @@ if (BUILD_LAGOM)
|
|||
lagom_test(../../Tests/LibAudio/TestFLACSpec.cpp LIBS LibAudio WORKING_DIRECTORY "${FLAC_TEST_PATH}/..")
|
||||
|
||||
# LibCore
|
||||
lagom_test(../../Tests/LibCore/TestLibCoreIODevice.cpp WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/LibCore)
|
||||
|
||||
if ((LINUX OR APPLE) AND NOT EMSCRIPTEN)
|
||||
lagom_test(../../Tests/LibCore/TestLibCoreFileWatcher.cpp)
|
||||
endif()
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
set(TEST_SOURCES
|
||||
TestLibCoreArgsParser.cpp
|
||||
TestLibCoreFileWatcher.cpp
|
||||
TestLibCoreIODevice.cpp
|
||||
TestLibCoreDeferredInvoke.cpp
|
||||
TestLibCoreStream.cpp
|
||||
TestLibCoreFilePermissionsMask.cpp
|
||||
|
|
|
@ -1,93 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2021, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibCore/DeprecatedFile.h>
|
||||
#include <LibTest/TestCase.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static bool files_have_same_contents(DeprecatedString filename1, DeprecatedString filename2)
|
||||
{
|
||||
auto file1 = Core::DeprecatedFile::open(filename1, Core::OpenMode::ReadOnly).value();
|
||||
auto file2 = Core::DeprecatedFile::open(filename2, Core::OpenMode::ReadOnly).value();
|
||||
auto contents1 = file1->read_all(), contents2 = file2->read_all();
|
||||
return contents1 == contents2;
|
||||
}
|
||||
|
||||
TEST_CASE(file_readline)
|
||||
{
|
||||
auto path = "long_lines.txt";
|
||||
auto file_or_error = Core::DeprecatedFile::open(path, Core::OpenMode::ReadOnly);
|
||||
if (file_or_error.is_error()) {
|
||||
warnln("Failed to open {}: {}", path, file_or_error.error());
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
auto file = file_or_error.release_value();
|
||||
auto output_path = "/tmp/output.txt";
|
||||
auto outfile_or_error = Core::DeprecatedFile::open(output_path, Core::OpenMode::WriteOnly);
|
||||
auto outputfile = outfile_or_error.release_value();
|
||||
while (file->can_read_line()) {
|
||||
outputfile->write(file->read_line());
|
||||
outputfile->write("\n"sv);
|
||||
}
|
||||
file->close();
|
||||
outputfile->close();
|
||||
VERIFY(files_have_same_contents(path, output_path));
|
||||
unlink(output_path);
|
||||
}
|
||||
|
||||
TEST_CASE(file_get_read_position)
|
||||
{
|
||||
const DeprecatedString path = "10kb.txt";
|
||||
auto file = Core::DeprecatedFile::open(path, Core::OpenMode::ReadOnly).release_value();
|
||||
|
||||
const size_t step_size = 98;
|
||||
for (size_t i = 0; i < 10240 - step_size; i += step_size) {
|
||||
auto read_buffer = file->read(step_size);
|
||||
EXPECT_EQ(read_buffer.size(), step_size);
|
||||
|
||||
for (size_t j = 0; j < read_buffer.size(); j++) {
|
||||
EXPECT_EQ(static_cast<u32>(read_buffer[j] - '0'), (i + j) % 10);
|
||||
}
|
||||
|
||||
off_t offset = 0;
|
||||
VERIFY(file->seek(0, SeekMode::FromCurrentPosition, &offset));
|
||||
EXPECT_EQ(offset, static_cast<off_t>(i + step_size));
|
||||
}
|
||||
|
||||
{
|
||||
off_t offset = 0;
|
||||
VERIFY(file->seek(0, SeekMode::FromEndPosition, &offset));
|
||||
EXPECT_EQ(offset, 10240);
|
||||
}
|
||||
|
||||
{
|
||||
off_t offset = 0;
|
||||
VERIFY(file->seek(0, SeekMode::SetPosition, &offset));
|
||||
EXPECT_EQ(offset, 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(file_lines_range)
|
||||
{
|
||||
auto path = "long_lines.txt";
|
||||
auto file_or_error = Core::DeprecatedFile::open(path, Core::OpenMode::ReadOnly);
|
||||
if (file_or_error.is_error()) {
|
||||
warnln("Failed to open {}: {}", path, file_or_error.error());
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
auto file = file_or_error.release_value();
|
||||
auto output_path = "/tmp/output.txt";
|
||||
auto outfile_or_error = Core::DeprecatedFile::open(output_path, Core::OpenMode::WriteOnly);
|
||||
auto outputfile = outfile_or_error.release_value();
|
||||
for (auto line : file->lines()) {
|
||||
outputfile->write(line);
|
||||
outputfile->write("\n"sv);
|
||||
}
|
||||
file->close();
|
||||
outputfile->close();
|
||||
VERIFY(files_have_same_contents(path, output_path));
|
||||
unlink(output_path);
|
||||
}
|
Loading…
Add table
Reference in a new issue