aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/common/bufferedreadstream.h11
-rw-r--r--test/common/bufferedseekablereadstream.h13
-rw-r--r--test/common/md5.h4
-rw-r--r--test/common/memoryreadstream.h28
-rw-r--r--test/common/memoryreadstreamendian.h113
-rw-r--r--test/common/seekablesubreadstream.h3
-rw-r--r--test/common/str.h10
-rw-r--r--test/common/stream.h2
-rw-r--r--test/common/subreadstream.h3
-rwxr-xr-xtest/cxxtest/cxxtestgen.py12
-rw-r--r--test/module.mk3
11 files changed, 178 insertions, 24 deletions
diff --git a/test/common/bufferedreadstream.h b/test/common/bufferedreadstream.h
index 0b2cda696c..c10fbf4b1d 100644
--- a/test/common/bufferedreadstream.h
+++ b/test/common/bufferedreadstream.h
@@ -1,6 +1,7 @@
#include <cxxtest/TestSuite.h>
-#include "common/stream.h"
+#include "common/memstream.h"
+#include "common/bufferedstream.h"
class BufferedReadStreamTestSuite : public CxxTest::TestSuite {
public:
@@ -11,7 +12,7 @@ class BufferedReadStreamTestSuite : public CxxTest::TestSuite {
// Use a buffer size of 4 -- note that 10 % 4 != 0,
// so we test what happens if the cache can't be completely
// refilled.
- Common::BufferedReadStream srs(&ms, 4);
+ Common::ReadStream &srs = *Common::wrapBufferedReadStream(&ms, 4, DisposeAfterUse::NO);
byte i, b;
for (i = 0; i < 10; ++i) {
@@ -26,13 +27,15 @@ class BufferedReadStreamTestSuite : public CxxTest::TestSuite {
b = srs.readByte();
TS_ASSERT(srs.eos());
+
+ delete &srs;
}
void test_traverse2() {
byte contents[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
Common::MemoryReadStream ms(contents, 9);
- Common::BufferedReadStream brs(&ms, 4);
+ Common::ReadStream &brs = *Common::wrapBufferedReadStream(&ms, 4, DisposeAfterUse::NO);
// Traverse the stream with reads of 2 bytes. The size is not
// a multiple of 2, so we can test the final partial read.
@@ -51,5 +54,7 @@ class BufferedReadStreamTestSuite : public CxxTest::TestSuite {
TS_ASSERT_EQUALS(n, 1);
TS_ASSERT(brs.eos());
+
+ delete &brs;
}
};
diff --git a/test/common/bufferedseekablereadstream.h b/test/common/bufferedseekablereadstream.h
index 74401ad202..11eb58f3d0 100644
--- a/test/common/bufferedseekablereadstream.h
+++ b/test/common/bufferedseekablereadstream.h
@@ -1,6 +1,7 @@
#include <cxxtest/TestSuite.h>
-#include "common/stream.h"
+#include "common/memstream.h"
+#include "common/bufferedstream.h"
class BufferedSeekableReadStreamTestSuite : public CxxTest::TestSuite {
public:
@@ -8,7 +9,8 @@ class BufferedSeekableReadStreamTestSuite : public CxxTest::TestSuite {
byte contents[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Common::MemoryReadStream ms(contents, 10);
- Common::BufferedSeekableReadStream ssrs(&ms, 4);
+ Common::SeekableReadStream &ssrs
+ = *Common::wrapBufferedSeekableReadStream(&ms, 4, DisposeAfterUse::NO);
byte i, b;
for (i = 0; i < 10; ++i) {
@@ -24,13 +26,16 @@ class BufferedSeekableReadStreamTestSuite : public CxxTest::TestSuite {
TS_ASSERT_EQUALS((uint)0, ssrs.read(&b, 1));
TS_ASSERT(ssrs.eos());
+
+ delete &ssrs;
}
void test_seek() {
byte contents[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Common::MemoryReadStream ms(contents, 10);
- Common::BufferedSeekableReadStream ssrs(&ms, 4);
+ Common::SeekableReadStream &ssrs
+ = *Common::wrapBufferedSeekableReadStream(&ms, 4, DisposeAfterUse::NO);
byte b;
TS_ASSERT_EQUALS(ssrs.pos(), 0);
@@ -66,5 +71,7 @@ class BufferedSeekableReadStreamTestSuite : public CxxTest::TestSuite {
TS_ASSERT_EQUALS(ssrs.pos(), 2);
b = ssrs.readByte();
TS_ASSERT_EQUALS(b, 2);
+
+ delete &ssrs;
}
};
diff --git a/test/common/md5.h b/test/common/md5.h
index c59b6dc853..f310845bb9 100644
--- a/test/common/md5.h
+++ b/test/common/md5.h
@@ -29,14 +29,14 @@ static const char *md5_test_digest[] = {
class MD5TestSuite : public CxxTest::TestSuite {
public:
- void test_md5_file() {
+ void test_computeStreamMD5() {
int i, j;
char output[33];
unsigned char md5sum[16];
for (i = 0; i < 7; i++) {
Common::MemoryReadStream stream((const byte *)md5_test_string[i], strlen(md5_test_string[i]));
- Common::md5_file(stream, md5sum);
+ Common::computeStreamMD5(stream, md5sum);
for (j = 0; j < 16; j++) {
sprintf(output + j * 2, "%02x", md5sum[j]);
diff --git a/test/common/memoryreadstream.h b/test/common/memoryreadstream.h
index dab9b34e0c..a476f12a2f 100644
--- a/test/common/memoryreadstream.h
+++ b/test/common/memoryreadstream.h
@@ -1,6 +1,6 @@
#include <cxxtest/TestSuite.h>
-#include "common/stream.h"
+#include "common/memstream.h"
class MemoryReadStreamTestSuite : public CxxTest::TestSuite {
public:
@@ -58,4 +58,30 @@ class MemoryReadStreamTestSuite : public CxxTest::TestSuite {
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());
+ }
};
diff --git a/test/common/memoryreadstreamendian.h b/test/common/memoryreadstreamendian.h
new file mode 100644
index 0000000000..35e804c70b
--- /dev/null
+++ b/test/common/memoryreadstreamendian.h
@@ -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());
+ }
+};
diff --git a/test/common/seekablesubreadstream.h b/test/common/seekablesubreadstream.h
index b6e584e510..0a7f93ca5e 100644
--- a/test/common/seekablesubreadstream.h
+++ b/test/common/seekablesubreadstream.h
@@ -1,6 +1,7 @@
#include <cxxtest/TestSuite.h>
-#include "common/stream.h"
+#include "common/memstream.h"
+#include "common/substream.h"
class SeekableSubReadStreamTestSuite : public CxxTest::TestSuite {
public:
diff --git a/test/common/str.h b/test/common/str.h
index 0908b21c1e..5d9fe29af9 100644
--- a/test/common/str.h
+++ b/test/common/str.h
@@ -316,12 +316,12 @@ class StringTestSuite : public CxxTest::TestSuite
}
void test_string_printf() {
- TS_ASSERT_EQUALS( Common::String::printf(""), "" );
- TS_ASSERT_EQUALS( Common::String::printf("%s", "test"), "test" );
- TS_ASSERT_EQUALS( Common::String::printf("%s.s%.02d", "monkey", 1), "monkey.s01" );
- TS_ASSERT_EQUALS( Common::String::printf("Some %s to make this string longer than the default built-in %s %d", "text", "capacity", 123456), "Some text to make this string longer than the default built-in capacity 123456" );
+ TS_ASSERT_EQUALS( Common::String::format(""), "" );
+ TS_ASSERT_EQUALS( Common::String::format("%s", "test"), "test" );
+ TS_ASSERT_EQUALS( Common::String::format("%s.s%.02d", "monkey", 1), "monkey.s01" );
+ TS_ASSERT_EQUALS( Common::String::format("Some %s to make this string longer than the default built-in %s %d", "text", "capacity", 123456), "Some text to make this string longer than the default built-in capacity 123456" );
- Common::String s = Common::String::printf("%s%X", "test", 1234);
+ Common::String s = Common::String::format("%s%X", "test", 1234);
TS_ASSERT_EQUALS(s, "test4D2");
TS_ASSERT_EQUALS(s.size(), 7U);
}
diff --git a/test/common/stream.h b/test/common/stream.h
index 8f989009cd..2bd0599acc 100644
--- a/test/common/stream.h
+++ b/test/common/stream.h
@@ -1,6 +1,6 @@
#include <cxxtest/TestSuite.h>
-#include "common/stream.h"
+#include "common/memstream.h"
class ReadLineStreamTestSuite : public CxxTest::TestSuite {
public:
diff --git a/test/common/subreadstream.h b/test/common/subreadstream.h
index 15d959892f..463f49e929 100644
--- a/test/common/subreadstream.h
+++ b/test/common/subreadstream.h
@@ -1,6 +1,7 @@
#include <cxxtest/TestSuite.h>
-#include "common/stream.h"
+#include "common/memstream.h"
+#include "common/substream.h"
class SubReadStreamTestSuite : public CxxTest::TestSuite {
public:
diff --git a/test/cxxtest/cxxtestgen.py b/test/cxxtest/cxxtestgen.py
index 831d23ab41..4145c3ca3e 100755
--- a/test/cxxtest/cxxtestgen.py
+++ b/test/cxxtest/cxxtestgen.py
@@ -57,7 +57,7 @@ def main():
def usage( problem = None ):
'''Print usage info and exit'''
if problem is None:
- print usageString()
+ print( usageString() )
sys.exit(0)
else:
sys.stderr.write( usageString() )
@@ -82,7 +82,7 @@ def parseCommandline():
'error-printer', 'abort-on-fail', 'have-std', 'no-std',
'have-eh', 'no-eh', 'template=', 'include=',
'root', 'part', 'no-static-init', 'factor', 'longlong='] )
- except getopt.error, problem:
+ except getopt.error as problem:
usage( problem )
setOptions( options )
return setFiles( patterns )
@@ -315,7 +315,7 @@ def scanLineForDestroy( suite, lineNo, line ):
def cstr( str ):
'''Convert a string to its C representation'''
- return '"' + string.replace( str, '\\', '\\\\' ) + '"'
+ return '"' + str.replace( '\\', '\\\\' ) + '"'
def addSuiteCreateDestroy( suite, which, line ):
@@ -335,10 +335,10 @@ def closeSuite():
def verifySuite(suite):
'''Verify current suite is legal'''
- if suite.has_key('create') and not suite.has_key('destroy'):
+ if 'create' in suite and not 'destroy' in suite:
abort( '%s:%s: Suite %s has createSuite() but no destroySuite()' %
(suite['file'], suite['create'], suite['name']) )
- if suite.has_key('destroy') and not suite.has_key('create'):
+ if 'destroy' in suite and not 'create' in suite:
abort( '%s:%s: Suite %s has destroySuite() but no createSuite()' %
(suite['file'], suite['destroy'], suite['name']) )
@@ -474,7 +474,7 @@ def isGenerated(suite):
def isDynamic(suite):
'''Checks whether a suite is dynamic'''
- return suite.has_key('create')
+ return 'create' in suite
lastIncluded = ''
def writeInclude(output, file):
diff --git a/test/module.mk b/test/module.mk
index a092bfd7a7..8b74950217 100644
--- a/test/module.mk
+++ b/test/module.mk
@@ -12,6 +12,7 @@ TEST_LIBS := sound/libsound.a common/libcommon.a
TEST_FLAGS := --runner=StdioPrinter
TEST_CFLAGS := -I$(srcdir)/test/cxxtest
TEST_LDFLAGS := $(LIBS)
+TEST_CXXFLAGS := $(filter-out -Wglobal-constructors,$(CXXFLAGS))
ifdef HAVE_GCC3
# In test/common/str.h, we test a zero length format string. This causes GCC
@@ -28,7 +29,7 @@ endif
test: test/runner
./test/runner
test/runner: test/runner.cpp $(TEST_LIBS)
- $(QUIET_LINK)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TEST_LDFLAGS) $(TEST_CFLAGS) -o $@ $+
+ $(QUIET_LINK)$(CXX) $(TEST_CXXFLAGS) $(CPPFLAGS) $(TEST_LDFLAGS) $(TEST_CFLAGS) -o $@ $+
test/runner.cpp: $(TESTS)
@mkdir -p test
$(srcdir)/test/cxxtest/cxxtestgen.py $(TEST_FLAGS) -o $@ $+