#include "format.hpp" #include #include #include #include #include #include namespace { using namespace testing; using namespace Serialization; using namespace SerializationTesting; TEST(DetourNavigatorSerializationBinaryWriterTest, shouldWriteArithmeticTypeValue) { std::vector result(4); BinaryWriter binaryWriter(result.data(), result.data() + result.size()); const TestFormat format; binaryWriter(format, std::uint32_t(42)); EXPECT_THAT(result, ElementsAre(std::byte(42), std::byte(0), std::byte(0), std::byte(0))); } TEST(DetourNavigatorSerializationBinaryWriterTest, shouldWriteArithmeticTypeRangeValue) { std::vector result(8); BinaryWriter binaryWriter(result.data(), result.data() + result.size()); std::vector values({ 42, 13 }); const TestFormat format; binaryWriter(format, values.data(), values.size()); constexpr std::array expected{ std::byte(42), std::byte(0), std::byte(0), std::byte(0), std::byte(13), std::byte(0), std::byte(0), std::byte(0), }; EXPECT_THAT(result, ElementsAreArray(expected)); } TEST(DetourNavigatorSerializationBinaryWriterTest, forNotEnoughSpaceForArithmeticTypeShouldThrowException) { std::vector result(3); BinaryWriter binaryWriter(result.data(), result.data() + result.size()); const TestFormat format; EXPECT_THROW(binaryWriter(format, std::uint32_t(42)), std::runtime_error); } TEST(DetourNavigatorSerializationBinaryWriterTest, forNotEnoughSpaceForArithmeticTypeRangeShouldThrowException) { std::vector result(7); BinaryWriter binaryWriter(result.data(), result.data() + result.size()); std::vector values({ 42, 13 }); const TestFormat format; EXPECT_THROW(binaryWriter(format, values.data(), values.size()), std::runtime_error); } }