diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-08-15 00:10:42 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-08-15 09:21:49 +0100 |
commit | 90fe8dadaaad07aee2ec513eab1ad75bbf306cb3 (patch) | |
tree | a84008d4e036d9b4476c96fdfa100a2d132cb336 /comphelper/qa | |
parent | 3324eca4eddb906c0a0d8efbc86b097f96a2c3a7 (diff) |
add a jdk 1.5-alike string replace to comphelper::string
Diffstat (limited to 'comphelper/qa')
-rw-r--r-- | comphelper/qa/string/test_string.cxx | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/comphelper/qa/string/test_string.cxx b/comphelper/qa/string/test_string.cxx index eefe7a96f2c4..8dbd056589c4 100644 --- a/comphelper/qa/string/test_string.cxx +++ b/comphelper/qa/string/test_string.cxx @@ -43,11 +43,13 @@ class TestString: public CppUnit::TestFixture public: void test(); void testNatural(); + void testReplace(); void testDecimalStringToNumber(); CPPUNIT_TEST_SUITE(TestString); CPPUNIT_TEST(test); CPPUNIT_TEST(testNatural); + CPPUNIT_TEST(testReplace); CPPUNIT_TEST(testDecimalStringToNumber); CPPUNIT_TEST_SUITE_END(); }; @@ -288,6 +290,34 @@ void TestString::testNatural() ); } +void TestString::testReplace() +{ + ::rtl::OString aIn(RTL_CONSTASCII_STRINGPARAM("aaa")); + ::rtl::OString aOut; + + aOut = ::comphelper::string::replace(aIn, + rtl::OString(RTL_CONSTASCII_STRINGPARAM("aa")), + rtl::OString(RTL_CONSTASCII_STRINGPARAM("b"))); + CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("ba"))); + + aOut = ::comphelper::string::replace(aIn, + rtl::OString(), + rtl::OString(RTL_CONSTASCII_STRINGPARAM("whatever"))); + CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("aaa"))); + + aOut = ::comphelper::string::replace(aIn, + rtl::OString(RTL_CONSTASCII_STRINGPARAM("aaa")), + rtl::OString()); + CPPUNIT_ASSERT(aOut.isEmpty()); + + aIn = rtl::OString(RTL_CONSTASCII_STRINGPARAM("aaa foo aaa foo bbb")); + aOut = ::comphelper::string::replace(aIn, + rtl::OString(RTL_CONSTASCII_STRINGPARAM("foo")), + rtl::OString(RTL_CONSTASCII_STRINGPARAM("bar"))); + CPPUNIT_ASSERT(aOut.equalsL( + RTL_CONSTASCII_STRINGPARAM("aaa bar aaa bar bbb"))); +} + CPPUNIT_TEST_SUITE_REGISTRATION(TestString); } |