aboutsummaryrefslogtreecommitdiff
path: root/test/common
diff options
context:
space:
mode:
authorColin Snover2016-02-03 13:51:16 -0600
committerColin Snover2016-02-18 13:18:01 -0600
commit7d54f0aaaf1854e421ee0e8eac3292c7bc0db284 (patch)
treeb0735335839815ffc3088fc95bc4fc8c4e4723e2 /test/common
parent1a542ae82c941353fb135aac8c0c2a0b4b6df3e7 (diff)
downloadscummvm-rg350-7d54f0aaaf1854e421ee0e8eac3292c7bc0db284.tar.gz
scummvm-rg350-7d54f0aaaf1854e421ee0e8eac3292c7bc0db284.tar.bz2
scummvm-rg350-7d54f0aaaf1854e421ee0e8eac3292c7bc0db284.zip
COMMON: Add methods for inserting and erasing with iterators
This provides improved feature parity to Common::List and is used in SCI32 engine.
Diffstat (limited to 'test/common')
-rw-r--r--test/common/array.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/common/array.h b/test/common/array.h
index f0027ec201..64354abc00 100644
--- a/test/common/array.h
+++ b/test/common/array.h
@@ -44,6 +44,48 @@ class ArrayTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS(iter, array.end());
}
+ void test_erase_iterator() {
+ Common::Array<int> array;
+ Common::Array<int>::iterator iter;
+
+ // Fill the array with some random data
+ array.push_back(17);
+ array.push_back(33);
+ array.push_back(-11);
+
+ iter = array.begin();
+ ++iter;
+
+ iter = array.erase(iter);
+ TS_ASSERT_DIFFERS(iter, array.end());
+ TS_ASSERT_EQUALS(*iter, -11);
+ TS_ASSERT_EQUALS(array.size(), (unsigned int)2);
+ TS_ASSERT_EQUALS(array[0], 17);
+ TS_ASSERT_EQUALS(array[1], -11);
+ }
+
+ void test_insert_iterator() {
+ Common::Array<int> array;
+ Common::Array<int>::iterator iter;
+
+ // Fill the array with some random data
+ array.push_back(17);
+ array.push_back(33);
+ array.push_back(-11);
+
+ iter = array.begin();
+ ++iter;
+
+ array.insert(iter, 99);
+
+ TS_ASSERT_EQUALS(*iter, 99);
+ TS_ASSERT_EQUALS(array.size(), (unsigned int)4);
+ TS_ASSERT_EQUALS(array[0], 17);
+ TS_ASSERT_EQUALS(array[1], 99);
+ TS_ASSERT_EQUALS(array[2], 33);
+ TS_ASSERT_EQUALS(array[3], -11);
+ }
+
void test_direct_access() {
Common::Array<int> array;