This commit is contained in:
@ -21,24 +21,16 @@ using namespace IACore;
|
||||
|
||||
IAT_BEGIN_BLOCK(Core, StreamWriter)
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 1. Memory Writer (Dynamic Vector)
|
||||
// -------------------------------------------------------------------------
|
||||
auto test_memory_writer() -> bool {
|
||||
StreamWriter writer;
|
||||
|
||||
// Write single byte repeated
|
||||
IAT_CHECK(writer.write(static_cast<u8>(0xAA), 1).has_value());
|
||||
|
||||
// Write primitive (u32) - 0x12345678
|
||||
// Little Endian: 78 56 34 12
|
||||
const u32 val = 0x12345678;
|
||||
IAT_CHECK(writer.write(val).has_value());
|
||||
|
||||
// Check cursor
|
||||
IAT_CHECK_EQ(writer.cursor(), static_cast<usize>(1 + 4));
|
||||
|
||||
// Check data content
|
||||
const u8 *ptr = writer.data();
|
||||
IAT_CHECK_EQ(ptr[0], 0xAA);
|
||||
IAT_CHECK_EQ(ptr[1], 0x78);
|
||||
@ -47,26 +39,19 @@ auto test_memory_writer() -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 2. Fixed Buffer Writer (Non-Owning)
|
||||
// -------------------------------------------------------------------------
|
||||
auto test_fixed_buffer() -> bool {
|
||||
u8 buffer[4] = {0};
|
||||
StreamWriter writer(Span<u8>(buffer, 4));
|
||||
|
||||
// Write 2 bytes
|
||||
IAT_CHECK(writer.write(static_cast<u8>(0xFF), 2).has_value());
|
||||
IAT_CHECK_EQ(writer.cursor(), static_cast<usize>(2));
|
||||
|
||||
// Write 2 more bytes
|
||||
IAT_CHECK(writer.write(static_cast<u8>(0xEE), 2).has_value());
|
||||
IAT_CHECK_EQ(writer.cursor(), static_cast<usize>(4));
|
||||
|
||||
// Write 1 more byte -> Should fail (Out of bounds)
|
||||
const auto res = writer.write(static_cast<u8>(0x00), 1);
|
||||
IAT_CHECK_NOT(res.has_value());
|
||||
|
||||
// Verify content
|
||||
IAT_CHECK_EQ(buffer[0], 0xFF);
|
||||
IAT_CHECK_EQ(buffer[1], 0xFF);
|
||||
IAT_CHECK_EQ(buffer[2], 0xEE);
|
||||
@ -75,13 +60,9 @@ auto test_fixed_buffer() -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 3. File Writer
|
||||
// -------------------------------------------------------------------------
|
||||
auto test_file_writer() -> bool {
|
||||
const Path path = "test_stream_writer.bin";
|
||||
|
||||
// Ensure clean state
|
||||
if (std::filesystem::exists(path)) {
|
||||
std::filesystem::remove(path);
|
||||
}
|
||||
@ -94,11 +75,9 @@ auto test_file_writer() -> bool {
|
||||
const String hello = "Hello World";
|
||||
IAT_CHECK(writer.write(hello.data(), hello.size()).has_value());
|
||||
|
||||
// Explicit flush
|
||||
IAT_CHECK(writer.flush().has_value());
|
||||
}
|
||||
|
||||
// Verify file content via FileOps
|
||||
auto read_res = FileOps::read_binary_file(path);
|
||||
IAT_CHECK(read_res.has_value());
|
||||
|
||||
@ -106,15 +85,11 @@ auto test_file_writer() -> bool {
|
||||
read_res->size());
|
||||
IAT_CHECK_EQ(read_str, String("Hello World"));
|
||||
|
||||
// Cleanup
|
||||
std::filesystem::remove(path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 4. Primitive Types
|
||||
// -------------------------------------------------------------------------
|
||||
auto test_primitives() -> bool {
|
||||
StreamWriter writer;
|
||||
|
||||
@ -129,9 +104,6 @@ auto test_primitives() -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Registration
|
||||
// -------------------------------------------------------------------------
|
||||
IAT_BEGIN_TEST_LIST()
|
||||
IAT_ADD_TEST(test_memory_writer);
|
||||
IAT_ADD_TEST(test_fixed_buffer);
|
||||
|
||||
Reference in New Issue
Block a user