TEST: Create test cases for reading uint64 from a stream

This commit is contained in:
Adrian Astley 2014-12-21 04:12:43 -06:00
parent d497b45b1c
commit 93167fabb5
2 changed files with 30 additions and 18 deletions

View File

@ -60,28 +60,32 @@ class MemoryReadStreamTestSuite : public CxxTest::TestSuite {
}
void test_seek_read_le() {
byte contents[] = { 1, 2, 3, 4, 5, 6, 7 };
byte contents[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
Common::MemoryReadStream ms(contents, sizeof(contents));
TS_ASSERT_EQUALS(ms.readUint16LE(), 0x0201UL);
TS_ASSERT_EQUALS(ms.pos(), 2);
TS_ASSERT_EQUALS(ms.readUint32LE(), 0x06050403UL);
TS_ASSERT_EQUALS(ms.pos(), 6);
TS_ASSERT_EQUALS(ms.readByte(), 0x07);
TS_ASSERT_EQUALS(ms.pos(), 7);
TS_ASSERT_EQUALS(ms.readUint64LE(), 0x0E0D0C0B0A090807ULL);
TS_ASSERT_EQUALS(ms.pos(), 14);
TS_ASSERT_EQUALS(ms.readByte(), 0x0F);
TS_ASSERT_EQUALS(ms.pos(), 15);
TS_ASSERT(!ms.eos());
}
void test_seek_read_be() {
byte contents[] = { 1, 2, 3, 4, 5, 6, 7 };
byte contents[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
Common::MemoryReadStream ms(contents, sizeof(contents));
TS_ASSERT_EQUALS(ms.readUint16BE(), 0x0102UL);
TS_ASSERT_EQUALS(ms.pos(), 2);
TS_ASSERT_EQUALS(ms.readUint32BE(), 0x03040506UL);
TS_ASSERT_EQUALS(ms.pos(), 6);
TS_ASSERT_EQUALS(ms.readByte(), 0x07);
TS_ASSERT_EQUALS(ms.pos(), 7);
TS_ASSERT_EQUALS(ms.readUint64LE(), 0x0708090A0B0C0D0EULL);
TS_ASSERT_EQUALS(ms.pos(), 14);
TS_ASSERT_EQUALS(ms.readByte(), 0x0F);
TS_ASSERT_EQUALS(ms.pos(), 15);
TS_ASSERT(!ms.eos());
}

View File

@ -60,54 +60,62 @@ class MemoryReadStreamEndianTestSuite : public CxxTest::TestSuite {
}
void test_seek_read_le() {
byte contents[] = { 1, 2, 3, 4, 5, 6, 7 };
byte contents[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
Common::MemoryReadStreamEndian ms(contents, sizeof(contents), false);
TS_ASSERT_EQUALS(ms.readUint16LE(), 0x0201UL);
TS_ASSERT_EQUALS(ms.pos(), 2);
TS_ASSERT_EQUALS(ms.readUint32LE(), 0x06050403UL);
TS_ASSERT_EQUALS(ms.pos(), 6);
TS_ASSERT_EQUALS(ms.readByte(), 0x07);
TS_ASSERT_EQUALS(ms.pos(), 7);
TS_ASSERT_EQUALS(ms.readUint64LE(), 0x0E0D0C0B0A090807ULL);
TS_ASSERT_EQUALS(ms.pos(), 14);
TS_ASSERT_EQUALS(ms.readByte(), 0x0F);
TS_ASSERT_EQUALS(ms.pos(), 15);
TS_ASSERT(!ms.eos());
}
void test_seek_read_be() {
byte contents[] = { 1, 2, 3, 4, 5, 6, 7 };
byte contents[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
Common::MemoryReadStreamEndian ms(contents, sizeof(contents), false);
TS_ASSERT_EQUALS(ms.readUint16BE(), 0x0102UL);
TS_ASSERT_EQUALS(ms.pos(), 2);
TS_ASSERT_EQUALS(ms.readUint32BE(), 0x03040506UL);
TS_ASSERT_EQUALS(ms.pos(), 6);
TS_ASSERT_EQUALS(ms.readByte(), 0x07);
TS_ASSERT_EQUALS(ms.pos(), 7);
TS_ASSERT_EQUALS(ms.readUint64LE(), 0x0708090A0B0C0D0EULL);
TS_ASSERT_EQUALS(ms.pos(), 14);
TS_ASSERT_EQUALS(ms.readByte(), 0x0F);
TS_ASSERT_EQUALS(ms.pos(), 15);
TS_ASSERT(!ms.eos());
}
void test_seek_read_le2() {
byte contents[] = { 1, 2, 3, 4, 5, 6, 7 };
byte contents[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
Common::MemoryReadStreamEndian ms(contents, sizeof(contents), false);
TS_ASSERT_EQUALS(ms.readUint16(), 0x0201UL);
TS_ASSERT_EQUALS(ms.pos(), 2);
TS_ASSERT_EQUALS(ms.readUint32(), 0x06050403UL);
TS_ASSERT_EQUALS(ms.pos(), 6);
TS_ASSERT_EQUALS(ms.readByte(), 0x07);
TS_ASSERT_EQUALS(ms.pos(), 7);
TS_ASSERT_EQUALS(ms.readUint64LE(), 0x0E0D0C0B0A090807ULL);
TS_ASSERT_EQUALS(ms.pos(), 14);
TS_ASSERT_EQUALS(ms.readByte(), 0x0F);
TS_ASSERT_EQUALS(ms.pos(), 15);
TS_ASSERT(!ms.eos());
}
void test_seek_read_be2() {
byte contents[] = { 1, 2, 3, 4, 5, 6, 7 };
byte contents[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
Common::MemoryReadStreamEndian ms(contents, sizeof(contents), true);
TS_ASSERT_EQUALS(ms.readUint16(), 0x0102UL);
TS_ASSERT_EQUALS(ms.pos(), 2);
TS_ASSERT_EQUALS(ms.readUint32(), 0x03040506UL);
TS_ASSERT_EQUALS(ms.pos(), 6);
TS_ASSERT_EQUALS(ms.readByte(), 0x07);
TS_ASSERT_EQUALS(ms.pos(), 7);
TS_ASSERT_EQUALS(ms.readUint64LE(), 0x0708090A0B0C0D0EULL);
TS_ASSERT_EQUALS(ms.pos(), 14);
TS_ASSERT_EQUALS(ms.readByte(), 0x0F);
TS_ASSERT_EQUALS(ms.pos(), 15);
TS_ASSERT(!ms.eos());
}
};