aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2003-12-24 16:16:00 +0000
committerMax Horn2003-12-24 16:16:00 +0000
commit1af37210a6d402680c7ede3cd96126e6ed7a2634 (patch)
treeaa31f7a7e32a61cc98f73c3ca42169c2095d68bc
parent3472e930513cce9268d99bee7a69aa29ee9720af (diff)
downloadscummvm-rg350-1af37210a6d402680c7ede3cd96126e6ed7a2634.tar.gz
scummvm-rg350-1af37210a6d402680c7ede3cd96126e6ed7a2634.tar.bz2
scummvm-rg350-1af37210a6d402680c7ede3cd96126e6ed7a2634.zip
simple unit tests for List/Map/String classes
svn-id: r11886
-rw-r--r--test/common/list.h19
-rw-r--r--test/common/map.h64
-rw-r--r--test/common/str.h63
3 files changed, 146 insertions, 0 deletions
diff --git a/test/common/list.h b/test/common/list.h
new file mode 100644
index 0000000000..b52a9c0f21
--- /dev/null
+++ b/test/common/list.h
@@ -0,0 +1,19 @@
+#include <cxxtest/TestSuite.h>
+
+#include "stdafx.h"
+#include "common/list.h"
+
+class ListTestSuite : public CxxTest::TestSuite
+{
+ public:
+ void test_isEmpty_clear( void )
+ {
+ Common::List<int> list;
+ TS_ASSERT( list.isEmpty() );
+ list.push_back(17);
+ list.push_back(33);
+ TS_ASSERT( !list.isEmpty() );
+ list.clear();
+ TS_ASSERT( list.isEmpty() );
+ }
+};
diff --git a/test/common/map.h b/test/common/map.h
new file mode 100644
index 0000000000..f4ab71b960
--- /dev/null
+++ b/test/common/map.h
@@ -0,0 +1,64 @@
+#include <cxxtest/TestSuite.h>
+
+#include "stdafx.h"
+#include "common/map.h"
+
+class MapTestSuite : public CxxTest::TestSuite
+{
+ public:
+ void test_isEmpty_clear( void )
+ {
+ Common::Map<int, int> map;
+ TS_ASSERT( map.isEmpty() );
+ map[0] = 17;
+ map[1] = 33;
+ TS_ASSERT( !map.isEmpty() );
+ map.clear();
+ TS_ASSERT( map.isEmpty() );
+ }
+ void test_contains( void )
+ {
+ Common::Map<int, int> map;
+ map[0] = 17;
+ map[1] = 33;
+ TS_ASSERT( map.contains(0) );
+ TS_ASSERT( map.contains(1) );
+ TS_ASSERT( !map.contains(17) );
+ TS_ASSERT( !map.contains(-1) );
+ }
+
+ void test_add_remove( void )
+ {
+ Common::Map<int, int> map;
+ map[0] = 17;
+ map[1] = 33;
+ TS_ASSERT( map.contains(1) );
+ map.remove(1);
+ TS_ASSERT( !map.contains(1) );
+ map.addKey(1);
+ TS_ASSERT( map.contains(1) );
+ }
+
+ void test_merge( void )
+ {
+ Common::Map<int, int> mapA, mapB;
+ mapA[0] = 17;
+ mapA[1] = 33;
+ mapA[2] = 45;
+ mapA[3] = 12;
+
+ mapB[1] = -1;
+ mapB[4] = 96;
+
+ mapA.merge(mapB);
+
+ TS_ASSERT( mapA.contains(1) );
+ TS_ASSERT( mapA.contains(4) );
+
+ TS_ASSERT_EQUALS( mapA[0], 17 );
+ TS_ASSERT_EQUALS( mapA[1], -1 );
+ TS_ASSERT_EQUALS( mapA[2], 45 );
+ TS_ASSERT_EQUALS( mapA[3], 12 );
+ TS_ASSERT_EQUALS( mapA[4], 96 );
+ }
+};
diff --git a/test/common/str.h b/test/common/str.h
new file mode 100644
index 0000000000..7b71bd3ecd
--- /dev/null
+++ b/test/common/str.h
@@ -0,0 +1,63 @@
+#include <cxxtest/TestSuite.h>
+
+#include "stdafx.h"
+#include "common/str.h"
+
+class StringTestSuite : public CxxTest::TestSuite
+{
+ public:
+ void test_isEmpty_clear( void )
+ {
+ Common::String str("test");
+ TS_ASSERT( !str.isEmpty() );
+ str.clear();
+ TS_ASSERT( str.isEmpty() );
+ }
+
+ void test_lastChar( void )
+ {
+ Common::String str;
+ TS_ASSERT_EQUALS( str.lastChar(), '\0' );
+ str = "test";
+ TS_ASSERT_EQUALS( str.lastChar(), 't' );
+ Common::String str2("bar");
+ TS_ASSERT_EQUALS( str2.lastChar(), 'r' );
+ }
+
+ void test_concat1( void )
+ {
+ Common::String str("foo");
+ Common::String str2("bar");
+ str += str2;
+ TS_ASSERT_EQUALS( str, "foobar" );
+ TS_ASSERT_EQUALS( str2, "bar" );
+ }
+
+ void test_concat2( void )
+ {
+ Common::String str("foo");
+ str += "bar";
+ TS_ASSERT_EQUALS( str, "foobar" );
+ }
+
+ void test_concat3( void )
+ {
+ Common::String str("foo");
+ str += 'X';
+ TS_ASSERT_EQUALS( str, "fooX" );
+ }
+
+ void test_toLowercase( void )
+ {
+ Common::String str("Test it, NOW! 42");
+ str.toLowercase();
+ TS_ASSERT_EQUALS( str, "test it, now! 42" );
+ }
+
+ void test_toUppercase( void )
+ {
+ Common::String str("Test it, NOW! 42");
+ str.toUppercase();
+ TS_ASSERT_EQUALS( str, "TEST IT, NOW! 42" );
+ }
+};