aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorStrangerke2013-06-26 23:11:34 +0200
committerStrangerke2013-06-26 23:11:34 +0200
commit6e2d567bca53b6ffee771b4105e2e73dbd73f5b4 (patch)
tree9880f0c496263ffb6928248d495ce4172dabed18 /test
parentac387835e4527c1814919093b4e4bc9798d5742d (diff)
parent6716fa39a6fb2a3925576288c256688c5aadd7e9 (diff)
downloadscummvm-rg350-6e2d567bca53b6ffee771b4105e2e73dbd73f5b4.tar.gz
scummvm-rg350-6e2d567bca53b6ffee771b4105e2e73dbd73f5b4.tar.bz2
scummvm-rg350-6e2d567bca53b6ffee771b4105e2e73dbd73f5b4.zip
Merge branch 'master' of https://github.com/scummvm/scummvm into mortevielle
Conflicts: engines/engines.mk
Diffstat (limited to 'test')
-rw-r--r--test/common/bitstream.h152
-rw-r--r--test/common/bufferedseekablereadstream.h7
2 files changed, 159 insertions, 0 deletions
diff --git a/test/common/bitstream.h b/test/common/bitstream.h
new file mode 100644
index 0000000000..3f6a15fcd8
--- /dev/null
+++ b/test/common/bitstream.h
@@ -0,0 +1,152 @@
+#include <cxxtest/TestSuite.h>
+
+#include "common/bitstream.h"
+#include "common/memstream.h"
+
+class BitStreamTestSuite : public CxxTest::TestSuite
+{
+ public:
+ void test_get_bit() {
+ byte contents[] = { 'a' };
+
+ Common::MemoryReadStream ms(contents, sizeof(contents));
+
+ Common::BitStream8MSB bs(ms);
+ TS_ASSERT_EQUALS(bs.pos(), 0u);
+ TS_ASSERT_EQUALS(bs.getBit(), 0u);
+ TS_ASSERT_EQUALS(bs.getBit(), 1u);
+ TS_ASSERT_EQUALS(bs.getBit(), 1u);
+ TS_ASSERT_EQUALS(bs.pos(), 3u);
+ TS_ASSERT(!bs.eos());
+ }
+
+ void test_get_bits() {
+ byte contents[] = { 'a', 'b' };
+
+ Common::MemoryReadStream ms(contents, sizeof(contents));
+
+ Common::BitStream8MSB bs(ms);
+ TS_ASSERT_EQUALS(bs.pos(), 0u);
+ TS_ASSERT_EQUALS(bs.getBits(3), 3u);
+ TS_ASSERT_EQUALS(bs.pos(), 3u);
+ TS_ASSERT_EQUALS(bs.getBits(8), 11u);
+ TS_ASSERT_EQUALS(bs.pos(), 11u);
+ TS_ASSERT(!bs.eos());
+ }
+
+ void test_skip() {
+ byte contents[] = { 'a', 'b' };
+
+ Common::MemoryReadStream ms(contents, sizeof(contents));
+
+ Common::BitStream8MSB bs(ms);
+ TS_ASSERT_EQUALS(bs.pos(), 0u);
+ bs.skip(5);
+ TS_ASSERT_EQUALS(bs.pos(), 5u);
+ bs.skip(4);
+ TS_ASSERT_EQUALS(bs.pos(), 9u);
+ TS_ASSERT_EQUALS(bs.getBits(3), 6u);
+ TS_ASSERT(!bs.eos());
+ }
+
+ void test_rewind() {
+ byte contents[] = { 'a' };
+
+ Common::MemoryReadStream ms(contents, sizeof(contents));
+
+ Common::BitStream8MSB bs(ms);
+ TS_ASSERT_EQUALS(bs.pos(), 0u);
+ bs.skip(5);
+ TS_ASSERT_EQUALS(bs.pos(), 5u);
+ bs.rewind();
+ TS_ASSERT_EQUALS(bs.pos(), 0u);
+ TS_ASSERT_EQUALS(bs.getBits(3), 3u);
+ TS_ASSERT(!bs.eos());
+
+ TS_ASSERT_EQUALS(bs.size(), 8u);
+ }
+
+ void test_peek_bit() {
+ byte contents[] = { 'a' };
+
+ Common::MemoryReadStream ms(contents, sizeof(contents));
+
+ Common::BitStream8MSB bs(ms);
+ TS_ASSERT_EQUALS(bs.pos(), 0u);
+ TS_ASSERT_EQUALS(bs.peekBit(), 0u);
+ TS_ASSERT_EQUALS(bs.pos(), 0u);
+ TS_ASSERT_EQUALS(bs.getBit(), 0u);
+ TS_ASSERT_EQUALS(bs.pos(), 1u);
+ TS_ASSERT_EQUALS(bs.peekBit(), 1u);
+ TS_ASSERT_EQUALS(bs.pos(), 1u);
+ TS_ASSERT(!bs.eos());
+ }
+
+ void test_peek_bits() {
+ byte contents[] = { 'a', 'b' };
+
+ Common::MemoryReadStream ms(contents, sizeof(contents));
+
+ Common::BitStream8MSB bs(ms);
+ TS_ASSERT_EQUALS(bs.pos(), 0u);
+ TS_ASSERT_EQUALS(bs.peekBits(3), 3u);
+ TS_ASSERT_EQUALS(bs.pos(), 0u);
+ bs.skip(3);
+ TS_ASSERT_EQUALS(bs.pos(), 3u);
+ TS_ASSERT_EQUALS(bs.peekBits(8), 11u);
+ TS_ASSERT_EQUALS(bs.pos(), 3u);
+ bs.skip(8);
+ TS_ASSERT_EQUALS(bs.pos(), 11u);
+ TS_ASSERT_EQUALS(bs.peekBits(5), 2u);
+ TS_ASSERT(!bs.eos());
+ }
+
+ void test_eos() {
+ byte contents[] = { 'a', 'b' };
+
+ Common::MemoryReadStream ms(contents, sizeof(contents));
+
+ Common::BitStream8MSB bs(ms);
+ bs.skip(11);
+ TS_ASSERT_EQUALS(bs.pos(), 11u);
+ TS_ASSERT_EQUALS(bs.getBits(5), 2u);
+ TS_ASSERT(bs.eos());
+
+ bs.rewind();
+ TS_ASSERT_EQUALS(bs.pos(), 0u);
+ TS_ASSERT(!bs.eos());
+ }
+
+ void test_get_bits_lsb() {
+ byte contents[] = { 'a', 'b' };
+
+ Common::MemoryReadStream ms(contents, sizeof(contents));
+
+ Common::BitStream8LSB bs(ms);
+ TS_ASSERT_EQUALS(bs.pos(), 0u);
+ TS_ASSERT_EQUALS(bs.getBits(3), 1u);
+ TS_ASSERT_EQUALS(bs.pos(), 3u);
+ TS_ASSERT_EQUALS(bs.getBits(8), 76u);
+ TS_ASSERT_EQUALS(bs.pos(), 11u);
+ TS_ASSERT(!bs.eos());
+ }
+
+ void test_peek_bits_lsb() {
+ byte contents[] = { 'a', 'b' };
+
+ Common::MemoryReadStream ms(contents, sizeof(contents));
+
+ Common::BitStream8LSB bs(ms);
+ TS_ASSERT_EQUALS(bs.pos(), 0u);
+ TS_ASSERT_EQUALS(bs.peekBits(3), 1u);
+ TS_ASSERT_EQUALS(bs.pos(), 0u);
+ bs.skip(3);
+ TS_ASSERT_EQUALS(bs.pos(), 3u);
+ TS_ASSERT_EQUALS(bs.peekBits(8), 76u);
+ TS_ASSERT_EQUALS(bs.pos(), 3u);
+ bs.skip(8);
+ TS_ASSERT_EQUALS(bs.pos(), 11u);
+ TS_ASSERT_EQUALS(bs.peekBits(5), 12u);
+ TS_ASSERT(!bs.eos());
+ }
+};
diff --git a/test/common/bufferedseekablereadstream.h b/test/common/bufferedseekablereadstream.h
index 11eb58f3d0..bf21f22f77 100644
--- a/test/common/bufferedseekablereadstream.h
+++ b/test/common/bufferedseekablereadstream.h
@@ -72,6 +72,13 @@ class BufferedSeekableReadStreamTestSuite : public CxxTest::TestSuite {
b = ssrs.readByte();
TS_ASSERT_EQUALS(b, 2);
+ ssrs.seek(5, SEEK_CUR);
+ TS_ASSERT_EQUALS(ssrs.pos(), 8);
+ ssrs.seek(-1, SEEK_CUR);
+ TS_ASSERT_EQUALS(ssrs.pos(), 7);
+ b = ssrs.readByte();
+ TS_ASSERT_EQUALS(b, 7);
+
delete &ssrs;
}
};