From 8ce397e8c0a83e49e390de9deb73d588e4931ecf Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Tue, 29 Oct 2024 21:02:25 -0500 Subject: Reworking of Result. --- test/CMakeLists.txt | 2 +- test/test_file.cpp | 2 +- test/test_fud.cpp | 2 +- test/test_result.cpp | 7 ++++++- test/test_utf8.cpp | 5 +++-- test/test_vector.cpp | 3 ++- 6 files changed, 14 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index aef8052..1ceca71 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -7,7 +7,7 @@ else() endif() if(FUD_SAN) -set(CVG_FLAGS ${CVG_FLAGS} -fsanitize=address -fsanitize=undefined) +set(CVG_FLAGS ${CVG_FLAGS} -fsanitize=address -fsanitize=undefined -fno-sanitize=vptr) endif() set(gtest_URL https://github.com/google/googletest.git) diff --git a/test/test_file.cpp b/test/test_file.cpp index 06e6bcc..27844d8 100644 --- a/test/test_file.cpp +++ b/test/test_file.cpp @@ -75,7 +75,7 @@ TEST(FudFile, Basic) }; ASSERT_GE(createFile(testName1), 0); - fileResult = RegularFile::open(testName1.asView(), FileAccessMode::Read, OpenFlags{}, NullOpt); + fileResult = std::move(RegularFile::open(testName1.asView(), FileAccessMode::Read, OpenFlags{}, NullOpt)); ASSERT_TRUE(fileResult.isOkay()); auto file{fileResult.takeOkay()}; ASSERT_EQ(file.close(), FudStatus::Success); diff --git a/test/test_fud.cpp b/test/test_fud.cpp index 72d569a..f84ad20 100644 --- a/test/test_fud.cpp +++ b/test/test_fud.cpp @@ -51,7 +51,7 @@ TEST(FudTest, GetEnv) ASSERT_TRUE(fudVarResult.isError()); ASSERT_EQ(fudVarResult.getError(), FudStatus::NullPointer); - fudVarResult = getEnv(testVarName); + fudVarResult = std::move(getEnv(testVarName)); ASSERT_TRUE(fudVarResult.isError()); ASSERT_EQ(fudVarResult.getError(), FudStatus::NotFound); diff --git a/test/test_result.cpp b/test/test_result.cpp index 5eadd8c..414941a 100644 --- a/test/test_result.cpp +++ b/test/test_result.cpp @@ -15,8 +15,8 @@ * limitations under the License. */ -#include "fud_status.hpp" #include "fud_result.hpp" +#include "fud_status.hpp" #include "gtest/gtest.h" @@ -49,4 +49,9 @@ TEST(ResultTest, ErrResult) ASSERT_EQ(err2.getError(), FudStatus::ArgumentInvalid); } +TEST(ResultTest, ImplicitConversion) +{ + // Result foo = Result::okay(-1); +} + } // namespace fud diff --git a/test/test_utf8.cpp b/test/test_utf8.cpp index 5447954..8c3cad2 100644 --- a/test/test_utf8.cpp +++ b/test/test_utf8.cpp @@ -137,13 +137,14 @@ TEST(Utf8Test, Utf8MultiByte) virtual Result allocate(size_t bytes, size_t alignment) override final { + using RetType = Result; static_cast(alignment); if (bytes > m_memory.size() - m_allocated) { - return FudStatus::AllocFailure; + return RetType::error(FudStatus::AllocFailure); } auto* data = m_memory.data() + m_allocated; m_allocated += bytes; - return data; + return RetType::okay(data); } virtual FudStatus deallocate(void* pointer, size_t bytes) override final diff --git a/test/test_vector.cpp b/test/test_vector.cpp index b4fd83c..cadeaa6 100644 --- a/test/test_vector.cpp +++ b/test/test_vector.cpp @@ -98,7 +98,8 @@ TEST(VectorTest, NonTrivialVector) ASSERT_GE(nonTrivialVector.capacity(), 11); ASSERT_EQ(counter, 11); auto capacity = nonTrivialVector.capacity(); - ASSERT_EQ(nonTrivialVector.reserve(SIZE_MAX / sizeof(NonTrivial)), FudStatus::AllocFailure); + constexpr auto FAIL_RESERVE_SIZE = 0x10000000000 / sizeof(NonTrivial); + ASSERT_EQ(nonTrivialVector.reserve(FAIL_RESERVE_SIZE), FudStatus::AllocFailure); ASSERT_EQ(nonTrivialVector.capacity(), capacity); { -- cgit v1.2.3