diff options
Diffstat (limited to 'test/common')
-rw-r--r-- | test/common/bufferedreadstream.h | 3 | ||||
-rw-r--r-- | test/common/bufferedseekablereadstream.h | 3 | ||||
-rw-r--r-- | test/common/hashmap.h | 51 | ||||
-rw-r--r-- | test/common/queue.h | 80 |
4 files changed, 118 insertions, 19 deletions
diff --git a/test/common/bufferedreadstream.h b/test/common/bufferedreadstream.h index 7733949d9a..2644745af2 100644 --- a/test/common/bufferedreadstream.h +++ b/test/common/bufferedreadstream.h @@ -13,8 +13,7 @@ class BufferedReadStreamTestSuite : public CxxTest::TestSuite { // refilled. Common::BufferedReadStream srs(&ms, 4); - int i; - byte b; + byte i, b; for (i = 0; i < 10; ++i) { TS_ASSERT( !srs.eos() ); diff --git a/test/common/bufferedseekablereadstream.h b/test/common/bufferedseekablereadstream.h index 63941904cd..c3e85c1b66 100644 --- a/test/common/bufferedseekablereadstream.h +++ b/test/common/bufferedseekablereadstream.h @@ -10,8 +10,7 @@ class BufferedSeekableReadStreamTestSuite : public CxxTest::TestSuite { Common::BufferedSeekableReadStream ssrs(&ms, 4); - int i; - byte b; + byte i, b; for (i = 0; i < 10; ++i) { TS_ASSERT( !ssrs.eos() ); diff --git a/test/common/hashmap.h b/test/common/hashmap.h index 5aa609bc00..acde1da028 100644 --- a/test/common/hashmap.h +++ b/test/common/hashmap.h @@ -1,12 +1,12 @@ #include <cxxtest/TestSuite.h> #include "common/hashmap.h" +#include "common/hash-str.h" class HashMapTestSuite : public CxxTest::TestSuite { public: - void test_empty_clear( void ) - { + void test_empty_clear(void) { Common::HashMap<int, int> container; TS_ASSERT( container.empty() ); container[0] = 17; @@ -14,10 +14,17 @@ class HashMapTestSuite : public CxxTest::TestSuite TS_ASSERT( !container.empty() ); container.clear(); TS_ASSERT( container.empty() ); + + Common::StringMap container2; + TS_ASSERT( container2.empty() ); + container2["foo"] = "bar"; + container2["quux"] = "blub"; + TS_ASSERT( !container2.empty() ); + container2.clear(); + TS_ASSERT( container2.empty() ); } - void test_contains( void ) - { + void test_contains(void) { Common::HashMap<int, int> container; container[0] = 17; container[1] = 33; @@ -25,25 +32,41 @@ class HashMapTestSuite : public CxxTest::TestSuite TS_ASSERT( container.contains(1) ); TS_ASSERT( !container.contains(17) ); TS_ASSERT( !container.contains(-1) ); + + Common::StringMap container2; + container2["foo"] = "bar"; + container2["quux"] = "blub"; + TS_ASSERT( container2.contains("foo") ); + TS_ASSERT( container2.contains("quux") ); + TS_ASSERT( !container2.contains("bar") ); + TS_ASSERT( !container2.contains("asdf") ); } - void test_add_remove( void ) - { + void test_add_remove(void) { Common::HashMap<int, int> container; container[0] = 17; container[1] = 33; + container[2] = 45; + container[3] = 12; + container[4] = 96; TS_ASSERT( container.contains(1) ); container.erase(1); TS_ASSERT( !container.contains(1) ); container[1] = 42; TS_ASSERT( container.contains(1) ); container.erase(0); + TS_ASSERT( !container.empty() ); container.erase(1); + TS_ASSERT( !container.empty() ); + container.erase(2); + TS_ASSERT( !container.empty() ); + container.erase(3); + TS_ASSERT( !container.empty() ); + container.erase(4); TS_ASSERT( container.empty() ); } - void test_lookup( void ) - { + void test_lookup(void) { Common::HashMap<int, int> container; container[0] = 17; container[1] = -1; @@ -58,8 +81,7 @@ class HashMapTestSuite : public CxxTest::TestSuite TS_ASSERT_EQUALS( container[4], 96 ); } - void test_iterator_begin_end( void ) - { + void test_iterator_begin_end(void) { Common::HashMap<int, int> container; // The container is initially empty ... @@ -74,12 +96,11 @@ class HashMapTestSuite : public CxxTest::TestSuite TS_ASSERT( container.begin() == container.end() ); } - void test_hash_map_copy( void ) - { - Common::HashMap<int, int> map1, map2; + void test_hash_map_copy(void) { + Common::HashMap<int, int> map1, container2; map1[323] = 32; - map2 = map1; - TS_ASSERT_EQUALS(map2[323], 32); + container2 = map1; + TS_ASSERT_EQUALS(container2[323], 32); } // TODO: Add test cases for iterators, find, ... diff --git a/test/common/queue.h b/test/common/queue.h new file mode 100644 index 0000000000..7eedec9a5d --- /dev/null +++ b/test/common/queue.h @@ -0,0 +1,80 @@ +#include <cxxtest/TestSuite.h> + +#include "common/queue.h" + +class QueueTestSuite : public CxxTest::TestSuite { +public: + void test_empty_clear() { + Common::Queue<int> queue; + TS_ASSERT(queue.empty()); + + queue.push(1); + queue.push(2); + TS_ASSERT(!queue.empty()); + + queue.clear(); + + TS_ASSERT(queue.empty()); + } + + void test_size() { + Common::Queue<int> queue; + TS_ASSERT_EQUALS(queue.size(), 0); + + queue.push(5); + TS_ASSERT_EQUALS(queue.size(), 1); + + queue.push(9); + queue.push(0); + TS_ASSERT_EQUALS(queue.size(), 3); + + queue.pop(); + TS_ASSERT_EQUALS(queue.size(), 2); + } + + void test_front_back_pop() { + Common::Queue<int> queue; + + queue.push( 42); + queue.push(-23); + + TS_ASSERT_EQUALS(queue.front(), 42); + TS_ASSERT_EQUALS(queue.back(), -23); + + queue.front() = -23; + queue.back() = 42; + TS_ASSERT_EQUALS(queue.front(), -23); + TS_ASSERT_EQUALS(queue.back(), 42); + + queue.pop(); + TS_ASSERT_EQUALS(queue.front(), 42); + } + + void test_assign() { + Common::Queue<int> q1, q2; + + for (int i = 0; i < 5; ++i) { + q1.push(i); + q2.push(4-i); + } + + Common::Queue<int> q3(q1); + + for (int i = 0; i < 5; ++i) { + TS_ASSERT_EQUALS(q3.front(), i); + q3.pop(); + } + + TS_ASSERT(q3.empty()); + + q3 = q2; + + for (int i = 4; i >= 0; --i) { + TS_ASSERT_EQUALS(q3.front(), i); + q3.pop(); + } + + TS_ASSERT(q3.empty()); + } +}; + |