Detach before appending a character

git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@944552 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
Lukáš Lalinský 2009-03-25 17:52:23 +00:00
parent 98d2808c17
commit 1eace99153
2 changed files with 22 additions and 0 deletions

View File

@ -560,6 +560,8 @@ String &String::operator+=(wchar_t c)
String &String::operator+=(char c)
{
detach();
d->data += uchar(c);
return *this;
}

View File

@ -37,6 +37,8 @@ class TestString : public CppUnit::TestFixture
CPPUNIT_TEST(testUTF16Decode);
CPPUNIT_TEST(testUTF16DecodeInvalidBOM);
CPPUNIT_TEST(testUTF16DecodeEmptyWithBOM);
CPPUNIT_TEST(testAppendCharDetach);
CPPUNIT_TEST(testAppendStringDetach);
CPPUNIT_TEST_SUITE_END();
public:
@ -131,6 +133,24 @@ public:
CPPUNIT_ASSERT_EQUAL(String(), String(b, String::UTF16));
}
void testAppendStringDetach()
{
String a("a");
String b = a;
a += "b";
CPPUNIT_ASSERT_EQUAL(String("ab"), a);
CPPUNIT_ASSERT_EQUAL(String("a"), b);
}
void testAppendCharDetach()
{
String a("a");
String b = a;
a += 'b';
CPPUNIT_ASSERT_EQUAL(String("ab"), a);
CPPUNIT_ASSERT_EQUAL(String("a"), b);
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestString);