aboutsummaryrefslogtreecommitdiff
path: root/test/common
diff options
context:
space:
mode:
authorMax Horn2006-11-13 22:06:27 +0000
committerMax Horn2006-11-13 22:06:27 +0000
commita750e6f4f5b45cb63d0ddf04477b53ab6035d878 (patch)
tree5d5b82d53e2da28eba3945fda4ba5a6b15c33b12 /test/common
parentaba00bd320418b42668bdb5371c4e86bd0ef0bbc (diff)
downloadscummvm-rg350-a750e6f4f5b45cb63d0ddf04477b53ab6035d878.tar.gz
scummvm-rg350-a750e6f4f5b45cb63d0ddf04477b53ab6035d878.tar.bz2
scummvm-rg350-a750e6f4f5b45cb63d0ddf04477b53ab6035d878.zip
Patch #1583931: (Seekable)SubReadStream (the unit tests were missing, as I accidentally commited from the wrong directory)
svn-id: r24715
Diffstat (limited to 'test/common')
-rw-r--r--test/common/seekablesubreadstream.h72
-rw-r--r--test/common/subreadstream.h30
2 files changed, 102 insertions, 0 deletions
diff --git a/test/common/seekablesubreadstream.h b/test/common/seekablesubreadstream.h
new file mode 100644
index 0000000000..96de086949
--- /dev/null
+++ b/test/common/seekablesubreadstream.h
@@ -0,0 +1,72 @@
+#include <cxxtest/TestSuite.h>
+
+#include "common/stdafx.h"
+#include "common/stream.h"
+
+class SeekableSubReadStreamTestSuite : public CxxTest::TestSuite
+{
+ public:
+ void test_traverse( void )
+ {
+ byte contents[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ Common::MemoryReadStream ms = Common::MemoryReadStream(contents, 10);
+
+ int start = 2, end = 8;
+
+ Common::SeekableSubReadStream ssrs = Common::SeekableSubReadStream(&ms, start, end);
+
+ int i;
+ byte b;
+ for (i = start; i < end; ++i)
+ {
+ TS_ASSERT( !ssrs.eos() );
+
+ TS_ASSERT_EQUALS( i - start, ssrs.pos() );
+
+ ssrs.read(&b, 1);
+ TS_ASSERT_EQUALS( i, b );
+ }
+
+ TS_ASSERT( ssrs.eos() );
+ }
+
+ void test_seek( void )
+ {
+ byte contents[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ Common::MemoryReadStream ms = Common::MemoryReadStream(contents, 10);
+
+ Common::SeekableSubReadStream ssrs = Common::SeekableSubReadStream(&ms, 1, 9);
+ byte b;
+
+ TS_ASSERT_EQUALS( ssrs.pos(), 0 );
+
+ ssrs.seek(1, SEEK_SET);
+ TS_ASSERT_EQUALS( ssrs.pos(), 1 );
+ b = ssrs.readByte();
+ TS_ASSERT_EQUALS( b, 2 );
+
+ ssrs.seek(5, SEEK_CUR);
+ TS_ASSERT_EQUALS( ssrs.pos(), 7 );
+ b = ssrs.readByte();
+ TS_ASSERT_EQUALS( b, 8 );
+
+ ssrs.seek(-3, SEEK_CUR);
+ TS_ASSERT_EQUALS( ssrs.pos(), 5 );
+ b = ssrs.readByte();
+ TS_ASSERT_EQUALS( b, 6 );
+
+ ssrs.seek(0, SEEK_END);
+ TS_ASSERT_EQUALS( ssrs.pos(), 8 );
+ TS_ASSERT( ssrs.eos() );
+
+ ssrs.seek(3, SEEK_END);
+ TS_ASSERT_EQUALS( ssrs.pos(), 5 );
+ b = ssrs.readByte();
+ TS_ASSERT_EQUALS( b, 6 );
+
+ ssrs.seek(8, SEEK_END);
+ TS_ASSERT_EQUALS( ssrs.pos(), 0 );
+ b = ssrs.readByte();
+ TS_ASSERT_EQUALS( b, 1 );
+ }
+};
diff --git a/test/common/subreadstream.h b/test/common/subreadstream.h
new file mode 100644
index 0000000000..eb50436665
--- /dev/null
+++ b/test/common/subreadstream.h
@@ -0,0 +1,30 @@
+#include <cxxtest/TestSuite.h>
+
+#include "common/stdafx.h"
+#include "common/stream.h"
+
+class SubReadStreamTestSuite : public CxxTest::TestSuite
+{
+ public:
+ void test_traverse( void )
+ {
+ byte contents[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ Common::MemoryReadStream ms = Common::MemoryReadStream(contents, 10);
+
+ int end = 5;
+
+ Common::SubReadStream srs = Common::SubReadStream(&ms, end);
+
+ int i;
+ byte b;
+ for (i = 0; i < end; ++i)
+ {
+ TS_ASSERT( !srs.eos() );
+
+ srs.read(&b, 1);
+ TS_ASSERT_EQUALS( i, b );
+ }
+
+ TS_ASSERT( srs.eos() );
+ }
+};