1 parent
8583a479dd
commit
3851aeb703
42 files changed
+6948
-759
No files matched your search
@@ -0,0 +1,31 @@
|
||||
#include <Void/Binary/Reader.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <array>
|
||||
|
||||
Void::Testing::Test binary_reader_checks_bounds_and_endian()
|
||||
{
|
||||
const std::array bytes{std::byte{0x12}, std::byte{0x34}, std::byte{0x56}};
|
||||
Void::Binary::Reader reader{bytes};
|
||||
auto value = reader.read<std::uint16_t>(std::endian::big);
|
||||
Void::Testing::require(value.has_value());
|
||||
Void::Testing::expect_eq(*value, static_cast<std::uint16_t>(0x1234));
|
||||
Void::Testing::expect_eq(reader.position(), static_cast<std::size_t>(2));
|
||||
auto overflow = reader.read<std::uint16_t>(std::endian::big);
|
||||
Void::Testing::expect(!overflow.has_value());
|
||||
Void::Testing::expect_eq(reader.position(), static_cast<std::size_t>(2));
|
||||
}
|
||||
|
||||
Void::Testing::Test binary_reader_subreader_is_bounded()
|
||||
{
|
||||
const std::array bytes{std::byte{'a'}, std::byte{'b'}, std::byte{'c'}};
|
||||
Void::Binary::Reader reader{bytes};
|
||||
auto child = reader.subreader(2);
|
||||
Void::Testing::require(child.has_value());
|
||||
auto value = child->readString(2);
|
||||
Void::Testing::require(value.has_value());
|
||||
Void::Testing::expect_eq(*value, std::string{"ab"});
|
||||
Void::Testing::expect(!child->readBytes(1).has_value());
|
||||
Void::Testing::expect_eq(reader.remaining(), static_cast<std::size_t>(1));
|
||||
}
|
||||
Reference in new issue
Block a user