From: Tsuda Kageyu Date: Mon, 5 Dec 2016 01:15:26 +0000 (+0900) Subject: Add a test to check if ByteVector is detached correctly when being replaced. X-Git-Tag: v1.12-beta-1~100 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b00a5c1aab4603819cce2a2d4946c978c60d8fd0;p=taglib Add a test to check if ByteVector is detached correctly when being replaced. --- diff --git a/tests/test_bytevector.cpp b/tests/test_bytevector.cpp index 1e063b71..428e795c 100644 --- a/tests/test_bytevector.cpp +++ b/tests/test_bytevector.cpp @@ -46,6 +46,7 @@ class TestByteVector : public CppUnit::TestFixture CPPUNIT_TEST(testIntegerConversion); CPPUNIT_TEST(testFloatingPointConversion); CPPUNIT_TEST(testReplace); + CPPUNIT_TEST(testReplaceAndDetach); CPPUNIT_TEST(testIterator); CPPUNIT_TEST(testResize); CPPUNIT_TEST(testAppend1); @@ -312,6 +313,44 @@ public: CPPUNIT_ASSERT_EQUAL(ByteVector("abcdaba"), a); } } + void testReplaceAndDetach() + { + { + ByteVector a("abcdabf"); + ByteVector b = a; + a.replace(ByteVector("a"), ByteVector("x")); + CPPUNIT_ASSERT_EQUAL(ByteVector("xbcdxbf"), a); + CPPUNIT_ASSERT_EQUAL(ByteVector("abcdabf"), b); + } + { + ByteVector a("abcdabf"); + ByteVector b = a; + a.replace('a', 'x'); + CPPUNIT_ASSERT_EQUAL(ByteVector("xbcdxbf"), a); + CPPUNIT_ASSERT_EQUAL(ByteVector("abcdabf"), b); + } + { + ByteVector a("abcdabf"); + ByteVector b = a; + a.replace(ByteVector("ab"), ByteVector("xy")); + CPPUNIT_ASSERT_EQUAL(ByteVector("xycdxyf"), a); + CPPUNIT_ASSERT_EQUAL(ByteVector("abcdabf"), b); + } + { + ByteVector a("abcdabf"); + ByteVector b = a; + a.replace(ByteVector("a"), ByteVector("")); + CPPUNIT_ASSERT_EQUAL(ByteVector("bcdbf"), a); + CPPUNIT_ASSERT_EQUAL(ByteVector("abcdabf"), b); + } + { + ByteVector a("abdab"); + ByteVector b = a; + a.replace(ByteVector(""), ByteVector("c")); + CPPUNIT_ASSERT_EQUAL(ByteVector("abcdabc"), a); + CPPUNIT_ASSERT_EQUAL(ByteVector("abdab"), b); + } + } void testIterator() {