mirror of https://github.com/OpenMW/openmw.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.2 KiB
C++
64 lines
2.2 KiB
C++
3 years ago
|
#include "format.hpp"
|
||
|
|
||
3 years ago
|
#include <components/serialization/binarywriter.hpp>
|
||
3 years ago
|
|
||
|
#include <gmock/gmock.h>
|
||
2 years ago
|
#include <gtest/gtest.h>
|
||
3 years ago
|
|
||
|
#include <array>
|
||
|
#include <cstdint>
|
||
|
#include <vector>
|
||
|
|
||
|
namespace
|
||
|
{
|
||
|
using namespace testing;
|
||
3 years ago
|
using namespace Serialization;
|
||
|
using namespace SerializationTesting;
|
||
3 years ago
|
|
||
|
TEST(DetourNavigatorSerializationBinaryWriterTest, shouldWriteArithmeticTypeValue)
|
||
|
{
|
||
|
std::vector<std::byte> result(4);
|
||
|
BinaryWriter binaryWriter(result.data(), result.data() + result.size());
|
||
|
const TestFormat<Mode::Write> 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<std::byte> result(8);
|
||
|
BinaryWriter binaryWriter(result.data(), result.data() + result.size());
|
||
2 years ago
|
std::vector<std::uint32_t> values({ 42, 13 });
|
||
3 years ago
|
const TestFormat<Mode::Write> format;
|
||
|
binaryWriter(format, values.data(), values.size());
|
||
2 years ago
|
constexpr std::array<std::byte, 8> 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),
|
||
3 years ago
|
};
|
||
|
EXPECT_THAT(result, ElementsAreArray(expected));
|
||
|
}
|
||
|
|
||
|
TEST(DetourNavigatorSerializationBinaryWriterTest, forNotEnoughSpaceForArithmeticTypeShouldThrowException)
|
||
|
{
|
||
|
std::vector<std::byte> result(3);
|
||
|
BinaryWriter binaryWriter(result.data(), result.data() + result.size());
|
||
|
const TestFormat<Mode::Write> format;
|
||
|
EXPECT_THROW(binaryWriter(format, std::uint32_t(42)), std::runtime_error);
|
||
|
}
|
||
|
|
||
|
TEST(DetourNavigatorSerializationBinaryWriterTest, forNotEnoughSpaceForArithmeticTypeRangeShouldThrowException)
|
||
|
{
|
||
|
std::vector<std::byte> result(7);
|
||
|
BinaryWriter binaryWriter(result.data(), result.data() + result.size());
|
||
2 years ago
|
std::vector<std::uint32_t> values({ 42, 13 });
|
||
3 years ago
|
const TestFormat<Mode::Write> format;
|
||
|
EXPECT_THROW(binaryWriter(format, values.data(), values.size()), std::runtime_error);
|
||
|
}
|
||
|
}
|