summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-10-30 09:51:54 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-10-30 09:51:54 -0500
commit6c7fd1db481ff10a16ecab958c6542784fa60b9c (patch)
treee0162f930ec44a7c53b07061311d52910c36e481 /test
parent8dcb1de91e15ff7fc66279cd9cd9ad8a70f624e0 (diff)
Use std::byte* instead of void* for allocators.
Diffstat (limited to 'test')
-rw-r--r--test/test_allocator.cpp2
-rw-r--r--test/test_common.cpp14
-rw-r--r--test/test_common.hpp9
-rw-r--r--test/test_directory.cpp4
-rw-r--r--test/test_string.cpp2
-rw-r--r--test/test_utf8.cpp12
6 files changed, 21 insertions, 22 deletions
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<void>(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<std::byte*>(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<utf8, 5> 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<utf8, bufSize> m_memory{};
+ Array<std::byte, bufSize> m_memory{};
size_t m_allocated{0};
public:
- virtual ~FixedAllocator() override final = default;
+ virtual ~FixedAllocator() override = default;
- virtual Result<void*, FudStatus> allocate(size_t bytes, size_t alignment) override final
+ virtual Result<std::byte*, FudStatus> allocate(size_t bytes, size_t alignment) override final
{
- using RetType = Result<void*, FudStatus>;
+ using RetType = Result<std::byte*, FudStatus>;
static_cast<void>(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<void>(pointer);
static_cast<void>(bytes);