diff options
author | Johannes Schickel | 2009-05-31 22:11:06 +0000 |
---|---|---|
committer | Johannes Schickel | 2009-05-31 22:11:06 +0000 |
commit | b0f49a6211b1f945c208b19a19840c7d32485334 (patch) | |
tree | 76eb58ca5a0677d2bd679d7a19d2e27c2085baff /test/common/str.h | |
parent | ede3dec88a291d7435708deec88f4108e383224b (diff) | |
download | scummvm-rg350-b0f49a6211b1f945c208b19a19840c7d32485334.tar.gz scummvm-rg350-b0f49a6211b1f945c208b19a19840c7d32485334.tar.bz2 scummvm-rg350-b0f49a6211b1f945c208b19a19840c7d32485334.zip |
Add unit tests for Common::String operators. These test cases will for example cover tests on String instances, which will be added to itself (foo += foo). NOTE: Those fail currently.
svn-id: r41082
Diffstat (limited to 'test/common/str.h')
-rw-r--r-- | test/common/str.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/common/str.h b/test/common/str.h index 887e11360f..c37d94d72a 100644 --- a/test/common/str.h +++ b/test/common/str.h @@ -118,6 +118,35 @@ class StringTestSuite : public CxxTest::TestSuite TS_ASSERT_EQUALS(foo3, "fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd""fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd"); } + void test_self_asignment() { + Common::String foo1("12345678901234567890123456789012"); + foo1 = foo1.c_str() + 2; + TS_ASSERT_EQUALS(foo1, "345678901234567890123456789012"); + + Common::String foo2("123456789012"); + foo2 = foo2.c_str() + 2; + TS_ASSERT_EQUALS(foo2, "3456789012"); + + // "foo3" and "foo4" will be using allocated storage from construction on. + Common::String foo3("12345678901234567890123456789012"); + foo3 += foo3.c_str(); + TS_ASSERT_EQUALS(foo3, "12345678901234567890123456789012""12345678901234567890123456789012"); + + Common::String foo4("12345678901234567890123456789012"); + foo4 += foo4; + TS_ASSERT_EQUALS(foo4, "12345678901234567890123456789012""12345678901234567890123456789012"); + + // Based on our current Common::String implementation "foo5" and "foo6" will first use the internal storage, + // and on "operator +=" they will change to allocated memory. + Common::String foo5("123456789012"); + foo5 += foo5.c_str(); + TS_ASSERT_EQUALS(foo5, "123456789012""123456789012"); + + Common::String foo6("123456789012"); + foo6 += foo6; + TS_ASSERT_EQUALS(foo6, "123456789012""123456789012"); + } + void test_hasPrefix() { Common::String str("this/is/a/test, haha"); TS_ASSERT_EQUALS(str.hasPrefix(""), true); |