aboutsummaryrefslogtreecommitdiff
path: root/test/common
diff options
context:
space:
mode:
authorMax Horn2008-07-29 17:42:19 +0000
committerMax Horn2008-07-29 17:42:19 +0000
commitaaa4d104f7eb4094ec6bd69ef2d44f80edd61aa4 (patch)
treef515c39e140b5ddd37f46060578d3b41759a15e3 /test/common
parent0a95a4814cbc9453f3af7abb46d6998409d96f53 (diff)
downloadscummvm-rg350-aaa4d104f7eb4094ec6bd69ef2d44f80edd61aa4.tar.gz
scummvm-rg350-aaa4d104f7eb4094ec6bd69ef2d44f80edd61aa4.tar.bz2
scummvm-rg350-aaa4d104f7eb4094ec6bd69ef2d44f80edd61aa4.zip
Added two new classes, BufferedReadStream & BufferedSeekableReadStream, as proposed on scummvm-devel
svn-id: r33419
Diffstat (limited to 'test/common')
-rw-r--r--test/common/bufferedreadstream.h27
-rw-r--r--test/common/bufferedseekablereadstream.h65
-rw-r--r--test/common/seekablesubreadstream.h20
-rw-r--r--test/common/subreadstream.h15
4 files changed, 106 insertions, 21 deletions
diff --git a/test/common/bufferedreadstream.h b/test/common/bufferedreadstream.h
new file mode 100644
index 0000000000..7733949d9a
--- /dev/null
+++ b/test/common/bufferedreadstream.h
@@ -0,0 +1,27 @@
+#include <cxxtest/TestSuite.h>
+
+#include "common/stream.h"
+
+class BufferedReadStreamTestSuite : public CxxTest::TestSuite {
+ public:
+ void test_traverse(void) {
+ byte contents[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ Common::MemoryReadStream ms(contents, 10);
+
+ // Use a buffer size of 4 -- note that 10 % 4 != 0,
+ // so we test what happens if the cache can't be completly
+ // refilled.
+ Common::BufferedReadStream srs(&ms, 4);
+
+ int i;
+ byte b;
+ for (i = 0; i < 10; ++i) {
+ TS_ASSERT( !srs.eos() );
+
+ b = srs.readByte();
+ TS_ASSERT_EQUALS( i, b );
+ }
+
+ TS_ASSERT( srs.eos() );
+ }
+};
diff --git a/test/common/bufferedseekablereadstream.h b/test/common/bufferedseekablereadstream.h
new file mode 100644
index 0000000000..63941904cd
--- /dev/null
+++ b/test/common/bufferedseekablereadstream.h
@@ -0,0 +1,65 @@
+#include <cxxtest/TestSuite.h>
+
+#include "common/stream.h"
+
+class BufferedSeekableReadStreamTestSuite : public CxxTest::TestSuite {
+ public:
+ void test_traverse(void) {
+ byte contents[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ Common::MemoryReadStream ms(contents, 10);
+
+ Common::BufferedSeekableReadStream ssrs(&ms, 4);
+
+ int i;
+ byte b;
+ for (i = 0; i < 10; ++i) {
+ TS_ASSERT( !ssrs.eos() );
+
+ TS_ASSERT_EQUALS( i, 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(contents, 10);
+
+ Common::BufferedSeekableReadStream ssrs(&ms, 4);
+ byte b;
+
+ TS_ASSERT_EQUALS( ssrs.pos(), (uint32)0 );
+
+ ssrs.seek(1, SEEK_SET);
+ TS_ASSERT_EQUALS( ssrs.pos(), (uint32)1 );
+ b = ssrs.readByte();
+ TS_ASSERT_EQUALS( b, 1 );
+
+ ssrs.seek(5, SEEK_CUR);
+ TS_ASSERT_EQUALS( ssrs.pos(), (uint32)7 );
+ b = ssrs.readByte();
+ TS_ASSERT_EQUALS( b, 7 );
+
+ ssrs.seek(-3, SEEK_CUR);
+ TS_ASSERT_EQUALS( ssrs.pos(), (uint32)5 );
+ b = ssrs.readByte();
+ TS_ASSERT_EQUALS( b, 5 );
+
+ ssrs.seek(0, SEEK_END);
+ TS_ASSERT_EQUALS( ssrs.pos(), (uint32)10 );
+ TS_ASSERT( ssrs.eos() );
+
+ ssrs.seek(3, SEEK_END);
+ TS_ASSERT_EQUALS( ssrs.pos(), (uint32)7 );
+ b = ssrs.readByte();
+ TS_ASSERT_EQUALS( b, 7 );
+
+ ssrs.seek(8, SEEK_END);
+ TS_ASSERT_EQUALS( ssrs.pos(), (uint32)2 );
+ b = ssrs.readByte();
+ TS_ASSERT_EQUALS( b, 2 );
+ }
+};
diff --git a/test/common/seekablesubreadstream.h b/test/common/seekablesubreadstream.h
index c4b21667c7..4e517093a5 100644
--- a/test/common/seekablesubreadstream.h
+++ b/test/common/seekablesubreadstream.h
@@ -2,22 +2,19 @@
#include "common/stream.h"
-class SeekableSubReadStreamTestSuite : public CxxTest::TestSuite
-{
+class SeekableSubReadStreamTestSuite : public CxxTest::TestSuite {
public:
- void test_traverse( void )
- {
+ void test_traverse(void) {
byte contents[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- Common::MemoryReadStream ms = Common::MemoryReadStream(contents, 10);
+ Common::MemoryReadStream ms(contents, 10);
int start = 2, end = 8;
- Common::SeekableSubReadStream ssrs = Common::SeekableSubReadStream(&ms, start, end);
+ Common::SeekableSubReadStream ssrs(&ms, start, end);
int i;
byte b;
- for (i = start; i < end; ++i)
- {
+ for (i = start; i < end; ++i) {
TS_ASSERT( !ssrs.eos() );
TS_ASSERT_EQUALS( uint32(i - start), ssrs.pos() );
@@ -29,12 +26,11 @@ class SeekableSubReadStreamTestSuite : public CxxTest::TestSuite
TS_ASSERT( ssrs.eos() );
}
- void test_seek( void )
- {
+ 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::MemoryReadStream ms(contents, 10);
- Common::SeekableSubReadStream ssrs = Common::SeekableSubReadStream(&ms, 1, 9);
+ Common::SeekableSubReadStream ssrs(&ms, 1, 9);
byte b;
TS_ASSERT_EQUALS( ssrs.pos(), (uint32)0 );
diff --git a/test/common/subreadstream.h b/test/common/subreadstream.h
index c48f57c3a8..4e14448c06 100644
--- a/test/common/subreadstream.h
+++ b/test/common/subreadstream.h
@@ -2,25 +2,22 @@
#include "common/stream.h"
-class SubReadStreamTestSuite : public CxxTest::TestSuite
-{
+class SubReadStreamTestSuite : public CxxTest::TestSuite {
public:
- void test_traverse( void )
- {
+ void test_traverse(void) {
byte contents[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- Common::MemoryReadStream ms = Common::MemoryReadStream(contents, 10);
+ Common::MemoryReadStream ms(contents, 10);
int end = 5;
- Common::SubReadStream srs = Common::SubReadStream(&ms, end);
+ Common::SubReadStream srs(&ms, end);
int i;
byte b;
- for (i = 0; i < end; ++i)
- {
+ for (i = 0; i < end; ++i) {
TS_ASSERT( !srs.eos() );
- srs.read(&b, 1);
+ b = srs.readByte();
TS_ASSERT_EQUALS( i, b );
}