[Scummvm-cvs-logs] SF.net SVN: scummvm:[54440] scummvm/trunk/test/common
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Tue Nov 23 23:27:01 CET 2010
Revision: 54440
http://scummvm.svn.sourceforge.net/scummvm/?rev=54440&view=rev
Author: fingolfin
Date: 2010-11-23 22:27:00 +0000 (Tue, 23 Nov 2010)
Log Message:
-----------
TEST: Add/extend MemoryReadStream(Endian) test cases
Modified Paths:
--------------
scummvm/trunk/test/common/memoryreadstream.h
Added Paths:
-----------
scummvm/trunk/test/common/memoryreadstreamendian.h
Modified: scummvm/trunk/test/common/memoryreadstream.h
===================================================================
--- scummvm/trunk/test/common/memoryreadstream.h 2010-11-23 22:26:43 UTC (rev 54439)
+++ scummvm/trunk/test/common/memoryreadstream.h 2010-11-23 22:27:00 UTC (rev 54440)
@@ -58,4 +58,30 @@
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());
+ }
};
Added: scummvm/trunk/test/common/memoryreadstreamendian.h
===================================================================
--- scummvm/trunk/test/common/memoryreadstreamendian.h (rev 0)
+++ scummvm/trunk/test/common/memoryreadstreamendian.h 2010-11-23 22:27:00 UTC (rev 54440)
@@ -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());
+ }
+};
Property changes on: scummvm/trunk/test/common/memoryreadstreamendian.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list