Fixed a bug in appending strings and added some relevant tests

This commit is contained in:
Tsuda Kageyu 2013-09-08 14:41:35 +09:00
parent 70e58dcb21
commit 60590c0a1a
2 changed files with 19 additions and 9 deletions

View File

@ -635,7 +635,7 @@ String &String::operator+=(const wchar_t *s)
{
detach();
*d->data += *s;
*d->data += s;
return *this;
}

View File

@ -149,20 +149,30 @@ public:
void testAppendStringDetach()
{
String a("a");
String a("abc");
String b = a;
a += "b";
CPPUNIT_ASSERT_EQUAL(String("ab"), a);
CPPUNIT_ASSERT_EQUAL(String("a"), b);
String c = a;
b += "def";
c += L"def";
CPPUNIT_ASSERT_EQUAL(String("abc"), a);
CPPUNIT_ASSERT_EQUAL(String("abcdef"), b);
CPPUNIT_ASSERT_EQUAL(String("abcdef"), c);
}
void testAppendCharDetach()
{
String a("a");
String a("abc");
String b = a;
a += 'b';
CPPUNIT_ASSERT_EQUAL(String("ab"), a);
CPPUNIT_ASSERT_EQUAL(String("a"), b);
String c = a;
b += 'd';
c += L'd';
CPPUNIT_ASSERT_EQUAL(String("abc"), a);
CPPUNIT_ASSERT_EQUAL(String("abcd"), b);
CPPUNIT_ASSERT_EQUAL(String("abcd"), c);
}
void testRfind()