diff options
author | Max Horn | 2009-03-05 20:37:53 +0000 |
---|---|---|
committer | Max Horn | 2009-03-05 20:37:53 +0000 |
commit | 05b4370c21b3abf7a1ff6aa83194cf95ab73579c (patch) | |
tree | a4d2cecedc5735d3205489e50610f85ca57be348 /test | |
parent | 2017d1c9ea12968e80a7aaeed1d9289f39c3a96e (diff) | |
download | scummvm-rg350-05b4370c21b3abf7a1ff6aa83194cf95ab73579c.tar.gz scummvm-rg350-05b4370c21b3abf7a1ff6aa83194cf95ab73579c.tar.bz2 scummvm-rg350-05b4370c21b3abf7a1ff6aa83194cf95ab73579c.zip |
Fix for bug #2664460: Various SeekableReadStream::seek() implementations (as well as our unit tests, ouch) handled SEEK_END incorrectly (using -offset instead of offset), contrary to what the docs said and what fseek does. Hopefully I found and fixed all affected parts, but still watch out for regressions
svn-id: r39135
Diffstat (limited to 'test')
-rw-r--r-- | test/common/bufferedseekablereadstream.h | 4 | ||||
-rw-r--r-- | test/common/memoryreadstream.h | 61 | ||||
-rw-r--r-- | test/common/seekablesubreadstream.h | 4 |
3 files changed, 65 insertions, 4 deletions
diff --git a/test/common/bufferedseekablereadstream.h b/test/common/bufferedseekablereadstream.h index f039acd2a8..b91a27d221 100644 --- a/test/common/bufferedseekablereadstream.h +++ b/test/common/bufferedseekablereadstream.h @@ -56,13 +56,13 @@ class BufferedSeekableReadStreamTestSuite : public CxxTest::TestSuite { b = ssrs.readByte(); TS_ASSERT( ssrs.eos() ); - ssrs.seek(3, SEEK_END); + ssrs.seek(-3, SEEK_END); TS_ASSERT( !ssrs.eos() ); TS_ASSERT_EQUALS( ssrs.pos(), 7 ); b = ssrs.readByte(); TS_ASSERT_EQUALS( b, 7 ); - ssrs.seek(8, SEEK_END); + ssrs.seek(-8, SEEK_END); TS_ASSERT_EQUALS( ssrs.pos(), 2 ); b = ssrs.readByte(); TS_ASSERT_EQUALS( b, 2 ); diff --git a/test/common/memoryreadstream.h b/test/common/memoryreadstream.h new file mode 100644 index 0000000000..2cec073ad5 --- /dev/null +++ b/test/common/memoryreadstream.h @@ -0,0 +1,61 @@ +#include <cxxtest/TestSuite.h> + +#include "common/stream.h" + +class MemoryReadStreamTestSuite : public CxxTest::TestSuite { + public: + void test_seek_set(void) { + byte contents[] = { 'a', 'b', '\n', '\n', 'c', '\n' }; + Common::MemoryReadStream ms(contents, sizeof(contents)); + + 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(void) { + byte contents[] = { 'a', 'b', '\n', '\n', 'c' }; + Common::MemoryReadStream ms(contents, sizeof(contents)); + + 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(void) { + byte contents[] = { 'a', 'b', '\n', '\n', 'c' }; + Common::MemoryReadStream ms(contents, sizeof(contents)); + + 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()); + } +}; diff --git a/test/common/seekablesubreadstream.h b/test/common/seekablesubreadstream.h index 68febc7fd6..354e2dd5c1 100644 --- a/test/common/seekablesubreadstream.h +++ b/test/common/seekablesubreadstream.h @@ -58,13 +58,13 @@ class SeekableSubReadStreamTestSuite : public CxxTest::TestSuite { b = ssrs.readByte(); TS_ASSERT( ssrs.eos() ); - ssrs.seek(3, SEEK_END); + ssrs.seek(-3, SEEK_END); TS_ASSERT( !ssrs.eos() ); TS_ASSERT_EQUALS( ssrs.pos(), 5 ); b = ssrs.readByte(); TS_ASSERT_EQUALS( b, 6 ); - ssrs.seek(8, SEEK_END); + ssrs.seek(-8, SEEK_END); TS_ASSERT_EQUALS( ssrs.pos(), 0 ); b = ssrs.readByte(); TS_ASSERT_EQUALS( b, 1 ); |