aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEugene Sandulenko2015-01-04 19:50:33 +0100
committerEugene Sandulenko2015-01-04 19:50:33 +0100
commit9abd92a711bc8615c389ab00a2a30627c813c00f (patch)
tree30ceeca7210a1871d5a2519ac996c08b161f8b01 /test
parent6c97eb4e366a292e91d143861f36c24b3169e06b (diff)
parent93167fabb55741a9606efa0088cf348c8ff2019e (diff)
downloadscummvm-rg350-9abd92a711bc8615c389ab00a2a30627c813c00f.tar.gz
scummvm-rg350-9abd92a711bc8615c389ab00a2a30627c813c00f.tar.bz2
scummvm-rg350-9abd92a711bc8615c389ab00a2a30627c813c00f.zip
Merge pull request #508 from RichieSams/add_endian_and_stream_support_for_int64
COMMON: Add support for endian-safe reading/writing of int64
Diffstat (limited to 'test')
-rw-r--r--test/common/endian.h12
-rw-r--r--test/common/memoryreadstream.h16
-rw-r--r--test/common/memoryreadstreamendian.h32
3 files changed, 42 insertions, 18 deletions
diff --git a/test/common/endian.h b/test/common/endian.h
index cba7618c43..f083d1248c 100644
--- a/test/common/endian.h
+++ b/test/common/endian.h
@@ -10,6 +10,18 @@ class EndianTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS(MKTAG('A','B','C','D'), tag);
}
+ void test_READ_BE_UINT64() {
+ const char data[8] = {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF};
+ uint64 value = READ_BE_UINT64(data);
+ TS_ASSERT_EQUALS(value, 0x123456789ABCDEFFULL);
+ }
+
+ void test_READ_LE_UINT64() {
+ const char data[8] = {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF};
+ uint64 value = READ_LE_UINT64(data);
+ TS_ASSERT_EQUALS(value, 0xFFEDCBA978563412ULL);
+ }
+
void test_READ_BE_UINT32() {
const char data[4] = { 0x12, 0x34, 0x56, 0x78 };
uint32 value = READ_BE_UINT32(data);
diff --git a/test/common/memoryreadstream.h b/test/common/memoryreadstream.h
index adef861a5e..79c4079e9b 100644
--- a/test/common/memoryreadstream.h
+++ b/test/common/memoryreadstream.h
@@ -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());
}
diff --git a/test/common/memoryreadstreamendian.h b/test/common/memoryreadstreamendian.h
index 35e804c70b..515128ea2a 100644
--- a/test/common/memoryreadstreamendian.h
+++ b/test/common/memoryreadstreamendian.h
@@ -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());
}
};