diff --git a/test/debug.cpp b/test/debug.cpp index 027e86b..c6eb29f 100644 --- a/test/debug.cpp +++ b/test/debug.cpp @@ -29,26 +29,36 @@ int main() // Positive { - std::stringstream buffer; - buffer << (char)0x4F; // LSB - buffer << (char)0x1A; - buffer << (char)0xAD; - buffer << (char)0x05; // MSB + std::stringstream ibuffer; + ibuffer << (char)0x4F; // LSB + ibuffer << (char)0x1A; + ibuffer << (char)0xAD; + ibuffer << (char)0x05; // MSB - auto value = IntIO::read(buffer); + auto value = i32_IO::read(ibuffer); assert(value == 95230543); + + std::stringstream obuffer; + i32_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(ibuffer.str() == obuffer.str()); } // Negative { - std::stringstream buffer; - buffer << (char)0xB1; // LSB - buffer << (char)0xE5; - buffer << (char)0x52; - buffer << (char)0xFA; // MSB + std::stringstream ibuffer; + ibuffer << (char)0xB1; // LSB + ibuffer << (char)0xE5; + ibuffer << (char)0x52; + ibuffer << (char)0xFA; // MSB - auto value = IntIO::read(buffer); + auto value = i32_IO::read(ibuffer); assert(value == -95230543); + + std::stringstream obuffer; + i32_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(ibuffer.str() == obuffer.str()); } #undef TEST_ENDIANNESS @@ -69,26 +79,36 @@ int main() // Positive { - std::stringstream buffer; - buffer << (char)0x05; // MSB - buffer << (char)0xAD; - buffer << (char)0x1A; - buffer << (char)0x4F; // LSB + std::stringstream ibuffer; + ibuffer << (char)0x05; // MSB + ibuffer << (char)0xAD; + ibuffer << (char)0x1A; + ibuffer << (char)0x4F; // LSB - auto value = i32_IO::read(buffer); + auto value = i32_IO::read(ibuffer); assert(value == 95230543); + + std::stringstream obuffer; + i32_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(ibuffer.str() == obuffer.str()); } // Negative { - std::stringstream buffer; - buffer << (char)0xFA; // MSB - buffer << (char)0x52; - buffer << (char)0xE5; - buffer << (char)0xB1; // LSB + std::stringstream ibuffer; + ibuffer << (char)0xFA; // MSB + ibuffer << (char)0x52; + ibuffer << (char)0xE5; + ibuffer << (char)0xB1; // LSB - auto value = i32_IO::read(buffer); + auto value = i32_IO::read(ibuffer); assert(value == -95230543); + + std::stringstream obuffer; + i32_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(ibuffer.str() == obuffer.str()); } #undef TEST_ENDIANNESS @@ -109,38 +129,57 @@ int main() // Positive integer { - std::stringstream buffer; - buffer << (char)0b11111111; // LSB - buffer << (char)0b11111111; - buffer << (char)0b01111111; // MSB (value) - buffer << (char)0b00000000; // MSB (container) + std::stringstream ibuffer; + ibuffer << (char)0b11111111; // LSB + ibuffer << (char)0b11111111; + ibuffer << (char)0b01111111; // MSB (value) + ibuffer << (char)0b00000000; // MSB (container) - auto value = i24a_IO::read(buffer); + auto value = i24a_IO::read(ibuffer); assert(value == 8388607); + + std::stringstream obuffer; + i24a_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(ibuffer.str() == obuffer.str()); } // Negative integer { - std::stringstream buffer; - buffer << (char)0b11111111; // LSB - buffer << (char)0b11111111; - buffer << (char)0b11111111; // MSB (value) - buffer << (char)0b00000000; // MSB (container) + std::stringstream ibuffer; + ibuffer << (char)0b11111111; // LSB + ibuffer << (char)0b11111111; + ibuffer << (char)0b11111111; // MSB (value) + ibuffer << (char)0b00000000; // MSB (container) - auto value = i24a_IO::read(buffer); + auto value = i24a_IO::read(ibuffer); assert(value == -1); + + std::stringstream obuffer; + i24a_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(ibuffer.str() == obuffer.str()); } // Garbage data in MSB { - std::stringstream buffer; - buffer << (char)0x2B; // LSB - buffer << (char)0xF0; - buffer << (char)0x7F; // MSB (value) - buffer << (char)0x42; // MSB (container) + std::stringstream ibuffer; + ibuffer << (char)0x2B; // LSB + ibuffer << (char)0xF0; + ibuffer << (char)0x7F; // MSB (value) + ibuffer << (char)0x42; // MSB (container) - auto value = i24a_IO::read(buffer); + auto value = i24a_IO::read(ibuffer); assert(value == 8384555); + + std::stringstream tmp_buffer; + i24a_IO::write(value, tmp_buffer); + value = i24a_IO::read(tmp_buffer); + + std::stringstream obuffer; + i24a_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(tmp_buffer.str() == obuffer.str()); } #undef TEST_ENDIANNESS @@ -158,38 +197,57 @@ int main() // Positive integer { - std::stringstream buffer; - buffer << (char)0b00000000; // MSB (container) - buffer << (char)0b01111111; // MSB (value) - buffer << (char)0b11111111; - buffer << (char)0b11111111; // LSB + std::stringstream ibuffer; + ibuffer << (char)0b00000000; // MSB (container) + ibuffer << (char)0b01111111; // MSB (value) + ibuffer << (char)0b11111111; + ibuffer << (char)0b11111111; // LSB - auto value = i24a_IO::read(buffer); + auto value = i24a_IO::read(ibuffer); assert(value == 8388607); + + std::stringstream obuffer; + i24a_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(ibuffer.str() == obuffer.str()); } // Negative integer { - std::stringstream buffer; - buffer << (char)0b00000000; // MSB (container) - buffer << (char)0b11111111; // MSB (value) - buffer << (char)0b11111111; - buffer << (char)0b11111111; // LSB + std::stringstream ibuffer; + ibuffer << (char)0b00000000; // MSB (container) + ibuffer << (char)0b11111111; // MSB (value) + ibuffer << (char)0b11111111; + ibuffer << (char)0b11111111; // LSB - auto value = i24a_IO::read(buffer); + auto value = i24a_IO::read(ibuffer); assert(value == -1); + + std::stringstream obuffer; + i24a_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(ibuffer.str() == obuffer.str()); } // Garbage data in MSB (container) { - std::stringstream buffer; - buffer << (char)0x42; // MSB (container) - buffer << (char)0x7F; // MSB (value) - buffer << (char)0xF0; - buffer << (char)0x2B; // LSB + std::stringstream ibuffer; + ibuffer << (char)0x42; // MSB (container) + ibuffer << (char)0x7F; // MSB (value) + ibuffer << (char)0xF0; + ibuffer << (char)0x2B; // LSB - auto value = i24a_IO::read(buffer); + auto value = i24a_IO::read(ibuffer); assert(value == 8384555); + + std::stringstream tmp_buffer; + i24a_IO::write(value, tmp_buffer); + value = i24a_IO::read(tmp_buffer); + + std::stringstream obuffer; + i24a_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(tmp_buffer.str() == obuffer.str()); } #undef TEST_ENDIANNESS @@ -203,42 +261,69 @@ int main() #define TEST_INT_BITS 24 #define TEST_ALIGN false - using i24a_IO = IntIO; + using i24_IO = IntIO; // Positive integer { - std::stringstream buffer; - buffer << (char)0b11111111; // LSB - buffer << (char)0b11111111; - buffer << (char)0b01111111; // MSB - buffer << (char)0b00000000; // Padding + std::stringstream ibuffer; + ibuffer << (char)0b11111111; // LSB + ibuffer << (char)0b11111111; + ibuffer << (char)0b01111111; // MSB + ibuffer << (char)0b00000000; // Padding - auto value = i24a_IO::read(buffer); + auto value = i24_IO::read(ibuffer); assert(value == 8388607); + + std::stringstream tmp_buffer; + i24_IO::write(value, tmp_buffer); + value = i24_IO::read(tmp_buffer); + + std::stringstream obuffer; + i24_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(tmp_buffer.str() == obuffer.str()); } // Negative integer { - std::stringstream buffer; - buffer << (char)0b11111111; // LSB - buffer << (char)0b11111111; - buffer << (char)0b11111111; // MSB - buffer << (char)0b00000000; // Padding + std::stringstream ibuffer; + ibuffer << (char)0b11111111; // LSB + ibuffer << (char)0b11111111; + ibuffer << (char)0b11111111; // MSB + ibuffer << (char)0b00000000; // Padding - auto value = i24a_IO::read(buffer); + auto value = i24_IO::read(ibuffer); assert(value == -1); + + std::stringstream tmp_buffer; + i24_IO::write(value, tmp_buffer); + value = i24_IO::read(tmp_buffer); + + std::stringstream obuffer; + i24_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(tmp_buffer.str() == obuffer.str()); } // Garbage data in padding { - std::stringstream buffer; - buffer << (char)0x2B; // LSB - buffer << (char)0xF0; - buffer << (char)0x7F; // MSB - buffer << (char)0x42; // Padding + std::stringstream ibuffer; + ibuffer << (char)0x2B; // LSB + ibuffer << (char)0xF0; + ibuffer << (char)0x7F; // MSB + ibuffer << (char)0x42; // Padding - auto value = i24a_IO::read(buffer); + auto value = i24_IO::read(ibuffer); assert(value == 8384555); + + std::stringstream tmp_buffer; + i24_IO::write(value, tmp_buffer); + value = i24_IO::read(tmp_buffer); + + std::stringstream obuffer; + i24_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(tmp_buffer.str() == obuffer.str()); } #undef TEST_ENDIANNESS @@ -252,42 +337,69 @@ int main() #define TEST_INT_BITS 24 #define TEST_ALIGN false - using i24a_IO = IntIO; + using i24_IO = IntIO; // Positive integer { - std::stringstream buffer; - buffer << (char)0b01111111; // MSB - buffer << (char)0b11111111; - buffer << (char)0b11111111; // LSB - buffer << (char)0b00000000; // Padding + std::stringstream ibuffer; + ibuffer << (char)0b01111111; // MSB + ibuffer << (char)0b11111111; + ibuffer << (char)0b11111111; // LSB + ibuffer << (char)0b00000000; // Padding - auto value = i24a_IO::read(buffer); + auto value = i24_IO::read(ibuffer); assert(value == 8388607); + + std::stringstream tmp_buffer; + i24_IO::write(value, tmp_buffer); + value = i24_IO::read(tmp_buffer); + + std::stringstream obuffer; + i24_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(tmp_buffer.str() == obuffer.str()); } // Negative integer { - std::stringstream buffer; - buffer << (char)0b11111111; // MSB - buffer << (char)0b11111111; - buffer << (char)0b11111111; // LSB - buffer << (char)0b00000000; // Padding + std::stringstream ibuffer; + ibuffer << (char)0b11111111; // MSB + ibuffer << (char)0b11111111; + ibuffer << (char)0b11111111; // LSB + ibuffer << (char)0b00000000; // Padding - auto value = i24a_IO::read(buffer); + auto value = i24_IO::read(ibuffer); assert(value == -1); + + std::stringstream tmp_buffer; + i24_IO::write(value, tmp_buffer); + value = i24_IO::read(tmp_buffer); + + std::stringstream obuffer; + i24_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(tmp_buffer.str() == obuffer.str()); } // Garbage data in padding { - std::stringstream buffer; - buffer << (char)0x7F; // MSB - buffer << (char)0xF0; - buffer << (char)0x2B; // LSB - buffer << (char)0x42; // Padding + std::stringstream ibuffer; + ibuffer << (char)0x7F; // MSB + ibuffer << (char)0xF0; + ibuffer << (char)0x2B; // LSB + ibuffer << (char)0x42; // Padding - auto value = i24a_IO::read(buffer); + auto value = i24_IO::read(ibuffer); assert(value == 8384555); + + std::stringstream tmp_buffer; + i24_IO::write(value, tmp_buffer); + value = i24_IO::read(tmp_buffer); + + std::stringstream obuffer; + i24_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(tmp_buffer.str() == obuffer.str()); } #undef TEST_ENDIANNESS @@ -308,38 +420,57 @@ int main() // Positive integer { - std::stringstream buffer; - buffer << (char)0b11111111; // LSB - buffer << (char)0b00001111; // MSB - buffer << (char)0b00000000; // Padding - buffer << (char)0b00000000; // Padding + std::stringstream ibuffer; + ibuffer << (char)0b11111111; // LSB + ibuffer << (char)0b00001111; // MSB + ibuffer << (char)0b00000000; // Padding + ibuffer << (char)0b00000000; // Padding - auto value = i13a_IO::read(buffer); + auto value = i13a_IO::read(ibuffer); assert(value == 4095); + + std::stringstream obuffer; + i13a_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(ibuffer.str() == obuffer.str()); } // Negative integer { - std::stringstream buffer; - buffer << (char)0b11111111; // LSB - buffer << (char)0b00011111; // MSB - buffer << (char)0b00000000; // Padding - buffer << (char)0b00000000; // Padding + std::stringstream ibuffer; + ibuffer << (char)0b11111111; // LSB + ibuffer << (char)0b00011111; // MSB + ibuffer << (char)0b00000000; // Padding + ibuffer << (char)0b00000000; // Padding - auto value = i13a_IO::read(buffer); + auto value = i13a_IO::read(ibuffer); assert(value == -1); + + std::stringstream obuffer; + i13a_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(ibuffer.str() == obuffer.str()); } // Garbage data in MSB { - std::stringstream buffer; - buffer << (char)0b11111111; // LSB - buffer << (char)0b01011111; // MSB - buffer << (char)0b00000000; // Padding - buffer << (char)0b00000000; // Padding + std::stringstream ibuffer; + ibuffer << (char)0b11111111; // LSB + ibuffer << (char)0b01011111; // MSB + ibuffer << (char)0b00000000; // Padding + ibuffer << (char)0b00000000; // Padding - auto value = i13a_IO::read(buffer); + auto value = i13a_IO::read(ibuffer); assert(value == -1); + + std::stringstream tmp_buffer; + i13a_IO::write(value, tmp_buffer); + value = i13a_IO::read(tmp_buffer); + + std::stringstream obuffer; + i13a_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(tmp_buffer.str() == obuffer.str()); } #undef TEST_ENDIANNESS @@ -357,38 +488,57 @@ int main() // Positive integer { - std::stringstream buffer; - buffer << (char)0b00000000; // Padding - buffer << (char)0b00000000; // Padding - buffer << (char)0b00001111; // MSB - buffer << (char)0b11111111; // LSB + std::stringstream ibuffer; + ibuffer << (char)0b00000000; // Padding + ibuffer << (char)0b00000000; // Padding + ibuffer << (char)0b00001111; // MSB + ibuffer << (char)0b11111111; // LSB - auto value = i13a_IO::read(buffer); + auto value = i13a_IO::read(ibuffer); assert(value == 4095); + + std::stringstream obuffer; + i13a_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(ibuffer.str() == obuffer.str()); } // Negative integer { - std::stringstream buffer; - buffer << (char)0b00000000; // Padding - buffer << (char)0b00000000; // Padding - buffer << (char)0b00011111; // MSB - buffer << (char)0b11111111; // LSB + std::stringstream ibuffer; + ibuffer << (char)0b00000000; // Padding + ibuffer << (char)0b00000000; // Padding + ibuffer << (char)0b00011111; // MSB + ibuffer << (char)0b11111111; // LSB - auto value = i13a_IO::read(buffer); + auto value = i13a_IO::read(ibuffer); assert(value == -1); + + std::stringstream obuffer; + i13a_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(ibuffer.str() == obuffer.str()); } // Garbage data in MSB { - std::stringstream buffer; - buffer << (char)0b00000000; // Padding - buffer << (char)0b00000000; // Padding - buffer << (char)0b01011111; // MSB - buffer << (char)0b11111111; // LSB + std::stringstream ibuffer; + ibuffer << (char)0b00000000; // Padding + ibuffer << (char)0b00000000; // Padding + ibuffer << (char)0b01011111; // MSB + ibuffer << (char)0b11111111; // LSB - auto value = i13a_IO::read(buffer); + auto value = i13a_IO::read(ibuffer); assert(value == -1); + + std::stringstream tmp_buffer; + i13a_IO::write(value, tmp_buffer); + value = i13a_IO::read(tmp_buffer); + + std::stringstream obuffer; + i13a_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(tmp_buffer.str() == obuffer.str()); } #undef TEST_ENDIANNESS @@ -401,22 +551,28 @@ int main() { // Float { - using f32_IO = FloatIO; + using f32_IO = FloatIO; + using i32_IO = IntIO; // Little endian { #define TEST_ENDIANNESS Endian::LITTLE - std::stringstream buffer; - buffer << (char)0x52; // LSB - buffer << (char)0x06; - buffer << (char)0x9E; - buffer << (char)0x3F; // MSB + std::stringstream ibuffer; + ibuffer << (char)0x52; // LSB + ibuffer << (char)0x06; + ibuffer << (char)0x9E; + ibuffer << (char)0x3F; // MSB - auto value = f32_IO::read(buffer); + auto value = f32_IO::read(ibuffer); float comparison = 1.23456789; assert(value == comparison); + std::stringstream obuffer; + f32_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(ibuffer.str() == obuffer.str()); + #undef TEST_ENDIANNESS } @@ -424,63 +580,78 @@ int main() { #define TEST_ENDIANNESS Endian::BIG - std::stringstream buffer; - buffer << (char)0x3F; // MSB - buffer << (char)0x9E; - buffer << (char)0x06; - buffer << (char)0x52; // LSB + std::stringstream ibuffer; + ibuffer << (char)0x3F; // MSB + ibuffer << (char)0x9E; + ibuffer << (char)0x06; + ibuffer << (char)0x52; // LSB - auto value = f32_IO::read(buffer); + auto value = f32_IO::read(ibuffer); float comparison = 1.23456789; assert(value == comparison); + std::stringstream obuffer; + f32_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(ibuffer.str() == obuffer.str()); + #undef TEST_ENDIANNESS } } // Double { - using f64_IO = FloatIO; + using f64_IO = FloatIO; - // Little endian + // Little endian Denormalized { #define TEST_ENDIANNESS Endian::LITTLE - std::stringstream buffer; - buffer << (char)0x1B; // LSB - buffer << (char)0xDE; - buffer << (char)0x83; - buffer << (char)0x42; - buffer << (char)0xCA; - buffer << (char)0xC0; - buffer << (char)0xF3; - buffer << (char)0x3F; // MSB - - auto value = f64_IO::read(buffer); - double comparison = 1.23456789; + std::stringstream ibuffer; + ibuffer << (char)0x5A; // LSB + ibuffer << (char)0x28; + ibuffer << (char)0xFD; + ibuffer << (char)0x3A; + ibuffer << (char)0xDD; + ibuffer << (char)0x9A; + ibuffer << (char)0xBF; + ibuffer << (char)0xBF; // MSB + + auto value = f64_IO::read(ibuffer); + double comparison = -0.12345678987654321; assert(value == comparison); + std::stringstream obuffer; + f64_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(ibuffer.str() == obuffer.str()); + #undef TEST_ENDIANNESS } - // Big endian + // Little endian Denormalized { - #define TEST_ENDIANNESS Endian::BIG + #define TEST_ENDIANNESS Endian::LITTLE - std::stringstream buffer; - buffer << (char)0x3F; // MSB - buffer << (char)0xF3; - buffer << (char)0xC0; - buffer << (char)0xCA; - buffer << (char)0x42; - buffer << (char)0x83; - buffer << (char)0xDE; - buffer << (char)0x1B; // LSB - - auto value = f64_IO::read(buffer); - double comparison = 1.23456789; + std::stringstream ibuffer; + ibuffer << (char)0x38; // LSB + ibuffer << (char)0x39; + ibuffer << (char)0xDE; + ibuffer << (char)0x44; + ibuffer << (char)0xCA; + ibuffer << (char)0xC0; + ibuffer << (char)0xF3; + ibuffer << (char)0x3F; // MSB + + auto value = f64_IO::read(ibuffer); + double comparison = 1.234567898765432; assert(value == comparison); + std::stringstream obuffer; + f64_IO::write(value, obuffer); + ibuffer.seekg(0); + assert(ibuffer.str() == obuffer.str()); + #undef TEST_ENDIANNESS } }