diff options
-rw-r--r-- | common/array.h | 3 | ||||
-rw-r--r-- | common/str.h | 11 | ||||
-rw-r--r-- | test/common/array.h | 13 |
3 files changed, 16 insertions, 11 deletions
diff --git a/common/array.h b/common/array.h index 2db0ed2a8b..491ed138a2 100644 --- a/common/array.h +++ b/common/array.h @@ -54,7 +54,8 @@ public: /** * Construct an array by copying data from a regular array. */ - Array(const T *data, int n) { + template<class T2> + Array(const T2 *data, int n) { _capacity = _size = n; _storage = new T[_capacity]; copy(data, data + _size, _storage); diff --git a/common/str.h b/common/str.h index 5792692030..9c5e267f1c 100644 --- a/common/str.h +++ b/common/str.h @@ -314,16 +314,7 @@ Common::String normalizePath(const Common::String &path, const char sep); bool matchString(const char *str, const char *pat, bool pathMode = false); -class StringList : public Array<String> { -public: - void push_back(const char *str) { - Array<String>::push_back(str); - } - - void push_back(const String &str) { - Array<String>::push_back(str); - } -}; +typedef Array<String> StringList; } // End of namespace Common diff --git a/test/common/array.h b/test/common/array.h index 5ee117e524..52c6529bbc 100644 --- a/test/common/array.h +++ b/test/common/array.h @@ -1,6 +1,7 @@ #include <cxxtest/TestSuite.h> #include "common/array.h" +#include "common/str.h" class ArrayTestSuite : public CxxTest::TestSuite { @@ -151,4 +152,16 @@ class ArrayTestSuite : public CxxTest::TestSuite TS_ASSERT_EQUALS( array2.size(), (unsigned int)3 ); } + + void test_array_constructor_str() { + const char *array1[] = { "a", "b", "c" }; + + Common::StringList array2(array1, 3); + + TS_ASSERT_EQUALS( array2[0], "a" ); + TS_ASSERT_EQUALS( array2[1], "b" ); + TS_ASSERT_EQUALS( array2[2], "c" ); + + TS_ASSERT_EQUALS( array2.size(), (unsigned int)3 ); + } }; |