From 6c7fd1db481ff10a16ecab958c6542784fa60b9c Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Wed, 30 Oct 2024 09:51:54 -0500 Subject: Use std::byte* instead of void* for allocators. --- test/test_allocator.cpp | 2 +- test/test_common.cpp | 14 +++++++------- test/test_common.hpp | 9 ++++----- test/test_directory.cpp | 4 ++-- test/test_string.cpp | 2 +- test/test_utf8.cpp | 12 ++++++------ 6 files changed, 21 insertions(+), 22 deletions(-) (limited to 'test') diff --git a/test/test_allocator.cpp b/test/test_allocator.cpp index d93df1e..6382463 100644 --- a/test/test_allocator.cpp +++ b/test/test_allocator.cpp @@ -23,7 +23,7 @@ namespace fud { struct FailAllocator : public MockFudAlloc { - virtual void* operator()(size_t size) override { + virtual std::byte* operator()(size_t size) override { static_cast(size); return nullptr; } diff --git a/test/test_common.cpp b/test/test_common.cpp index 784cb0d..778b4b5 100644 --- a/test/test_common.cpp +++ b/test/test_common.cpp @@ -25,12 +25,12 @@ namespace fud { -void* MockFudAlloc::operator()(size_t size) +std::byte* MockFudAlloc::operator()(size_t size) { - return malloc(size); + return static_cast(malloc(size)); } -void MockFudDealloc::operator()(void* pointer) +void MockFudDealloc::operator()(std::byte* pointer) { return free(pointer); } @@ -39,24 +39,24 @@ MockFudAlloc globalDefaultMockAlloc{}; MockFudDealloc globalDefaultMockDealloc{}; -void* MockFudAllocator::allocate(size_t size) +std::byte* MockFudAllocator::allocate(size_t size) { return (*m_allocator)(size); } -void MockFudAllocator::deallocate(void* pointer) +void MockFudAllocator::deallocate(std::byte* pointer) { return (*m_deallocator)(pointer); } MockFudAllocator globalMockFudAlloc{}; -void* fudAlloc(size_t size) +std::byte* fudAlloc(size_t size) { return globalMockFudAlloc.allocate(size); } -void fudFree(void* ptr) +void fudFree(std::byte* ptr) { return globalMockFudAlloc.deallocate(ptr); } diff --git a/test/test_common.hpp b/test/test_common.hpp index fd16364..8912e42 100644 --- a/test/test_common.hpp +++ b/test/test_common.hpp @@ -57,23 +57,22 @@ static_assert(sizeof(FOUR_BYTE) == 4 + 1); #define CHARACTER_SET LOWERCASE_CHARS u8" " UPPERCASE_CHARS // NOLINTEND(cppcoreguidelines-macro-usage) -constexpr size_t charSetSize = sizeof(CHARACTER_SET) - 1; struct MockFudAlloc { - virtual void* operator()(size_t size); + virtual std::byte* operator()(size_t size); }; extern MockFudAlloc globalDefaultMockAlloc; struct MockFudDealloc { - virtual void operator()(void* pointer); + virtual void operator()(std::byte* pointer); }; extern MockFudDealloc globalDefaultMockDealloc; struct MockFudAllocator { - void* allocate(size_t size); - void deallocate(void* pointer); + std::byte* allocate(size_t size); + void deallocate(std::byte* pointer); MockFudAlloc* m_allocator{&globalDefaultMockAlloc}; MockFudDealloc* m_deallocator{&globalDefaultMockDealloc}; diff --git a/test/test_directory.cpp b/test/test_directory.cpp index ba1c0e1..96b9c2d 100644 --- a/test/test_directory.cpp +++ b/test/test_directory.cpp @@ -60,9 +60,9 @@ TEST(FudDirectory, Basic) CBinaryFile file{std::move(fileResult).takeOkay()}; ASSERT_EQ(file.open(), FudStatus::Success); Array data{u8"test"}; - WriteResult expected{data.size(), FudStatus::Success}; + DrainResult expected{data.size(), FudStatus::Success}; auto writeResult = file.write(data); - ASSERT_EQ(writeResult.bytesWritten, expected.bytesWritten); + ASSERT_EQ(writeResult.bytesDrained, expected.bytesDrained); ASSERT_EQ(writeResult.status, expected.status); } diff --git a/test/test_string.cpp b/test/test_string.cpp index 9f5b24e..6bcbd37 100644 --- a/test/test_string.cpp +++ b/test/test_string.cpp @@ -25,7 +25,7 @@ namespace fud { TEST(FudString, CStringLength) { - const char* nullPointer = nullPointer; + const char* nullPointer{nullptr}; ASSERT_EQ(cStringLength(nullPointer), -1); ASSERT_EQ(cStringLength(""), 0); ASSERT_EQ(cStringLength("a"), 1); diff --git a/test/test_utf8.cpp b/test/test_utf8.cpp index 591d1a3..69a1643 100644 --- a/test/test_utf8.cpp +++ b/test/test_utf8.cpp @@ -127,17 +127,17 @@ TEST(Utf8Test, Utf8MultiByte) constexpr size_t bufSize = data.size(); EXPECT_EQ(data[bufSize - 1], '\0'); - class FixedAllocator final : public Allocator { + class FixedAllocator : public Allocator { private: - Array m_memory{}; + Array m_memory{}; size_t m_allocated{0}; public: - virtual ~FixedAllocator() override final = default; + virtual ~FixedAllocator() override = default; - virtual Result allocate(size_t bytes, size_t alignment) override final + virtual Result allocate(size_t bytes, size_t alignment) override final { - using RetType = Result; + using RetType = Result; static_cast(alignment); if (bytes > m_memory.size() - m_allocated) { return RetType::error(FudStatus::AllocFailure); @@ -147,7 +147,7 @@ TEST(Utf8Test, Utf8MultiByte) return RetType::okay(data); } - virtual FudStatus deallocate(void* pointer, size_t bytes) override final + virtual FudStatus deallocate(std::byte* pointer, size_t bytes) override final { static_cast(pointer); static_cast(bytes); -- cgit v1.2.3