Release Readt
Some checks failed
CI / build-linux-and-wasm (x64-linux) (push) Has been cancelled

This commit is contained in:
2026-01-25 22:08:16 +05:30
parent 601b573983
commit ebde7c7e66
19 changed files with 51 additions and 567 deletions

View File

@ -20,20 +20,15 @@ using namespace IACore;
IAT_BEGIN_BLOCK(Core, StreamReader)
// -------------------------------------------------------------------------
// 1. Basic Primitive Reading (u8)
// -------------------------------------------------------------------------
auto test_read_uint8() -> bool {
u8 data[] = {0xAA, 0xBB, 0xCC};
StreamReader reader(data);
// Read First Byte
auto val1 = reader.read<u8>();
IAT_CHECK(val1.has_value());
IAT_CHECK_EQ(*val1, 0xAA);
IAT_CHECK_EQ(reader.cursor(), static_cast<usize>(1));
// Read Second Byte
auto val2 = reader.read<u8>();
IAT_CHECK(val2.has_value());
IAT_CHECK_EQ(*val2, 0xBB);
@ -41,12 +36,8 @@ auto test_read_uint8() -> bool {
return true;
}
// -------------------------------------------------------------------------
// 2. Multi-byte Reading (Endianness check)
// -------------------------------------------------------------------------
auto test_read_multi_byte() -> bool {
// 0x04030201 in Little Endian memory layout
// IACore always assumes a Little Endian machine
u8 data[] = {0x01, 0x02, 0x03, 0x04};
StreamReader reader(data);
@ -61,12 +52,9 @@ auto test_read_multi_byte() -> bool {
return true;
}
// -------------------------------------------------------------------------
// 3. Floating Point (Approx check)
// -------------------------------------------------------------------------
auto test_read_float() -> bool {
const f32 pi = 3.14159f;
// Bit-cast float to bytes for setup
u8 data[4];
std::memcpy(data, &pi, 4);
@ -79,49 +67,37 @@ auto test_read_float() -> bool {
return true;
}
// -------------------------------------------------------------------------
// 4. Batch Buffer Reading
// -------------------------------------------------------------------------
auto test_read_buffer() -> bool {
u8 src[] = {1, 2, 3, 4, 5};
u8 dst[3] = {0};
StreamReader reader(src);
// Read 3 bytes into dst
const auto res = reader.read(dst, 3);
IAT_CHECK(res.has_value());
// Verify dst content
IAT_CHECK_EQ(dst[0], 1);
IAT_CHECK_EQ(dst[1], 2);
IAT_CHECK_EQ(dst[2], 3);
// Verify cursor
IAT_CHECK_EQ(reader.cursor(), static_cast<usize>(3));
return true;
}
// -------------------------------------------------------------------------
// 5. Navigation (Seek, Skip, Remaining)
// -------------------------------------------------------------------------
auto test_navigation() -> bool {
u8 data[10] = {0}; // Zero init
u8 data[10] = {0};
StreamReader reader(data);
IAT_CHECK_EQ(reader.remaining(), static_cast<usize>(10));
// Skip
reader.skip(5);
IAT_CHECK_EQ(reader.cursor(), static_cast<usize>(5));
IAT_CHECK_EQ(reader.remaining(), static_cast<usize>(5));
// Skip clamping
reader.skip(100); // Should clamp to 10
reader.skip(100);
IAT_CHECK_EQ(reader.cursor(), static_cast<usize>(10));
IAT_CHECK(reader.is_eof());
// Seek
reader.seek(2);
IAT_CHECK_EQ(reader.cursor(), static_cast<usize>(2));
IAT_CHECK_EQ(reader.remaining(), static_cast<usize>(8));
@ -130,22 +106,16 @@ auto test_navigation() -> bool {
return true;
}
// -------------------------------------------------------------------------
// 6. Error Handling (EOF Protection)
// -------------------------------------------------------------------------
auto test_boundary_checks() -> bool {
u8 data[] = {0x00, 0x00};
StreamReader reader(data);
// Valid read
(void)reader.read<u16>();
IAT_CHECK(reader.is_eof());
// Invalid Read Primitive
auto val = reader.read<u8>();
IAT_CHECK_NOT(val.has_value()); // Should be unexpected
IAT_CHECK_NOT(val.has_value());
// Invalid Batch Read
u8 buf[1];
auto batch = reader.read(buf, 1);
IAT_CHECK_NOT(batch.has_value());
@ -153,9 +123,6 @@ auto test_boundary_checks() -> bool {
return true;
}
// -------------------------------------------------------------------------
// Registration
// -------------------------------------------------------------------------
IAT_BEGIN_TEST_LIST()
IAT_ADD_TEST(test_read_uint8);
IAT_ADD_TEST(test_read_multi_byte);