aboutsummaryrefslogtreecommitdiff
path: root/test/common
diff options
context:
space:
mode:
authorMax Horn2010-11-23 22:27:00 +0000
committerMax Horn2010-11-23 22:27:00 +0000
commit5d791cb090a6ead8594b956316f3735382703e8d (patch)
tree359416760b9894901eaf10fe20376b23a020d3da /test/common
parentb485d0ee49f305bcb241447988309eac9c38c4c7 (diff)
downloadscummvm-rg350-5d791cb090a6ead8594b956316f3735382703e8d.tar.gz
scummvm-rg350-5d791cb090a6ead8594b956316f3735382703e8d.tar.bz2
scummvm-rg350-5d791cb090a6ead8594b956316f3735382703e8d.zip
TEST: Add/extend MemoryReadStream(Endian) test cases
svn-id: r54440
Diffstat (limited to 'test/common')
-rw-r--r--test/common/memoryreadstream.h26
-rw-r--r--test/common/memoryreadstreamendian.h113
2 files changed, 139 insertions, 0 deletions
diff --git a/test/common/memoryreadstream.h b/test/common/memoryreadstream.h
index f7a144d730..a476f12a2f 100644
--- a/test/common/memoryreadstream.h
+++ b/test/common/memoryreadstream.h
@@ -58,4 +58,30 @@ class MemoryReadStreamTestSuite : public CxxTest::TestSuite {
TS_ASSERT_EQUALS(ms.pos(), 0);
TS_ASSERT(!ms.eos());
}
+
+ void test_seek_read_le() {
+ byte contents[] = { 1, 2, 3, 4, 5, 6, 7 };
+ 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(!ms.eos());
+ }
+
+ void test_seek_read_be() {
+ byte contents[] = { 1, 2, 3, 4, 5, 6, 7 };
+ 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(!ms.eos());
+ }
};
diff --git a/test/common/memoryreadstreamendian.h b/test/common/memoryreadstreamendian.h
new file mode 100644
index 0000000000..35e804c70b
--- /dev/null
+++ b/test/common/memoryreadstreamendian.h
@@ -0,0 +1,113 @@
+#include <cxxtest/TestSuite.h>
+
+#include "common/memstream.h"
+
+class MemoryReadStreamEndianTestSuite : public CxxTest::TestSuite {
+ public:
+ void test_seek_set() {
+ byte contents[] = { 'a', 'b', '\n', '\n', 'c', '\n' };
+ Common::MemoryReadStreamEndian ms(contents, sizeof(contents), false);
+
+ ms.seek(0, SEEK_SET);
+ TS_ASSERT_EQUALS(ms.pos(), 0);
+ TS_ASSERT(!ms.eos());
+
+ ms.seek(1, SEEK_SET);
+ TS_ASSERT_EQUALS(ms.pos(), 1);
+ TS_ASSERT(!ms.eos());
+
+ ms.seek(5, SEEK_SET);
+ TS_ASSERT_EQUALS(ms.pos(), 5);
+ TS_ASSERT(!ms.eos());
+ }
+
+ void test_seek_cur() {
+ byte contents[] = { 'a', 'b', '\n', '\n', 'c' };
+ Common::MemoryReadStreamEndian ms(contents, sizeof(contents), false);
+
+ ms.seek(3, SEEK_CUR);
+ TS_ASSERT_EQUALS(ms.pos(), 3);
+ TS_ASSERT(!ms.eos());
+
+ ms.seek(-1, SEEK_CUR);
+ TS_ASSERT_EQUALS(ms.pos(), 2);
+ TS_ASSERT(!ms.eos());
+
+ ms.seek(3, SEEK_CUR);
+ TS_ASSERT_EQUALS(ms.pos(), 5);
+ TS_ASSERT(!ms.eos());
+
+ ms.seek(-1, SEEK_CUR);
+ TS_ASSERT_EQUALS(ms.pos(), 4);
+ TS_ASSERT(!ms.eos());
+ }
+
+ void test_seek_end() {
+ byte contents[] = { 'a', 'b', '\n', '\n', 'c' };
+ Common::MemoryReadStreamEndian ms(contents, sizeof(contents), false);
+
+ ms.seek(0, SEEK_END);
+ TS_ASSERT_EQUALS(ms.pos(), 5);
+ TS_ASSERT(!ms.eos());
+
+ ms.seek(-1, SEEK_END);
+ TS_ASSERT_EQUALS(ms.pos(), 4);
+ TS_ASSERT(!ms.eos());
+
+ ms.seek(-5, SEEK_END);
+ TS_ASSERT_EQUALS(ms.pos(), 0);
+ TS_ASSERT(!ms.eos());
+ }
+
+ void test_seek_read_le() {
+ byte contents[] = { 1, 2, 3, 4, 5, 6, 7 };
+ 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(!ms.eos());
+ }
+
+ void test_seek_read_be() {
+ byte contents[] = { 1, 2, 3, 4, 5, 6, 7 };
+ 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(!ms.eos());
+ }
+
+ void test_seek_read_le2() {
+ byte contents[] = { 1, 2, 3, 4, 5, 6, 7 };
+ 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(!ms.eos());
+ }
+
+ void test_seek_read_be2() {
+ byte contents[] = { 1, 2, 3, 4, 5, 6, 7 };
+ 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(!ms.eos());
+ }
+};