1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 21:58:10 +00:00

AK: Use an enum to specify the open mode instead of a bool

Let's replace this bool with an `enum class` in order to enhance
readability. This is done by repurposing `MappedFile`'s `OpenMode` into
a shared `enum` simply called `Mode`.
This commit is contained in:
Lucas CHOLLET 2023-11-05 15:31:17 -05:00 committed by Tim Schumacher
parent 00ad8419cf
commit b00476abac
7 changed files with 24 additions and 25 deletions

View file

@ -27,7 +27,7 @@ TEST_CASE(mapped_file_open)
TRY_OR_FAIL(maybe_file.value()->write_until_depleted(text.bytes()));
}
auto maybe_file = Core::MappedFile::map("/tmp/file-open-test.txt"sv, Core::MappedFile::OpenMode::ReadWrite);
auto maybe_file = Core::MappedFile::map("/tmp/file-open-test.txt"sv, Core::MappedFile::Mode::ReadWrite);
if (maybe_file.is_error()) {
warnln("Failed to open the file: {}", strerror(maybe_file.error().code()));
VERIFY_NOT_REACHED();
@ -46,7 +46,7 @@ constexpr auto expected_buffer_contents = "<small>(Please consider transla
TEST_CASE(mapped_file_read_bytes)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map("/usr/Tests/LibCore/long_lines.txt"sv, Core::MappedFile::OpenMode::ReadOnly));
auto file = TRY_OR_FAIL(Core::MappedFile::map("/usr/Tests/LibCore/long_lines.txt"sv, Core::MappedFile::Mode::ReadOnly));
auto buffer = TRY_OR_FAIL(ByteBuffer::create_uninitialized(131));
@ -63,7 +63,7 @@ constexpr auto expected_seek_contents3 = "levels of advanc"sv;
TEST_CASE(mapped_file_seeking_around)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map("/usr/Tests/LibCore/long_lines.txt"sv, Core::MappedFile::OpenMode::ReadOnly));
auto file = TRY_OR_FAIL(Core::MappedFile::map("/usr/Tests/LibCore/long_lines.txt"sv, Core::MappedFile::Mode::ReadOnly));
EXPECT_EQ(file->size().release_value(), 8702ul);
@ -89,7 +89,7 @@ TEST_CASE(mapped_file_seeking_around)
BENCHMARK_CASE(file_tell)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map("/usr/Tests/LibCore/10kb.txt"sv, Core::MappedFile::OpenMode::ReadOnly));
auto file = TRY_OR_FAIL(Core::MappedFile::map("/usr/Tests/LibCore/10kb.txt"sv, Core::MappedFile::Mode::ReadOnly));
auto expected_file_offset = 0u;
auto ten_byte_buffer = TRY_OR_FAIL(ByteBuffer::create_uninitialized(1));
for (auto i = 0u; i < 4000; ++i) {