aboutsummaryrefslogtreecommitdiff
path: root/test/common/array.h
diff options
context:
space:
mode:
authorMax Horn2011-05-16 15:23:09 +0200
committerMax Horn2011-05-16 15:23:17 +0200
commit88319a727a5adc4888ec17e5ee091e14ce176afd (patch)
tree1d59d4368371e23f42377083ce5ee75292d30867 /test/common/array.h
parenta564a10e7f0afd99d7f0936c5b3e1acce31875b7 (diff)
downloadscummvm-rg350-88319a727a5adc4888ec17e5ee091e14ce176afd.tar.gz
scummvm-rg350-88319a727a5adc4888ec17e5ee091e14ce176afd.tar.bz2
scummvm-rg350-88319a727a5adc4888ec17e5ee091e14ce176afd.zip
COMMON: Fix inserting an array into itself under certain conditions
Diffstat (limited to 'test/common/array.h')
-rw-r--r--test/common/array.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/common/array.h b/test/common/array.h
index f17edd3984..c10270436f 100644
--- a/test/common/array.h
+++ b/test/common/array.h
@@ -107,6 +107,34 @@ class ArrayTestSuite : public CxxTest::TestSuite
}
+ void test_self_insert() {
+ Common::Array<int> array;
+ int i;
+
+ // Insert some data -- and make sure we have enough space for
+ // *twice* as much data. This way, there is no need to allocate
+ // new storage, so if the insert() operation is "clever", it
+ // will try to reuse the existing storage.
+ // This in turn may uncover bugs if the insertion code does not
+ // expect self-insertions.
+ array.reserve(128);
+ for (i = 0; i < 64; ++i)
+ array.push_back(i);
+
+ // Now insert the array into the middle of itself
+ array.insert_at(12, array);
+
+ // Verify integrity
+ TS_ASSERT_EQUALS(array.size(), 128UL);
+
+ for (i = 0; i < 12; ++i)
+ TS_ASSERT_EQUALS(array[i], i);
+ for (i = 0; i < 64; ++i)
+ TS_ASSERT_EQUALS(array[i+12], i);
+ for (i = 12; i < 64; ++i)
+ TS_ASSERT_EQUALS(array[i+64], i);
+ }
+
void test_remove_at() {
Common::Array<int> array;