diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-08-15 00:22:23 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-08-15 09:21:49 +0100 |
commit | 061ebc34468c37d27524352de56faaf9df742556 (patch) | |
tree | 96d924d1f23690029ba13598290858881bdb2495 /comphelper/qa/string | |
parent | 90fe8dadaaad07aee2ec513eab1ad75bbf306cb3 (diff) |
add a getToken wrapper for extracting a single token painlessly
Diffstat (limited to 'comphelper/qa/string')
-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 8dbd056589c4..4d3d50d8697b 100644 --- a/comphelper/qa/string/test_string.cxx +++ b/comphelper/qa/string/test_string.cxx @@ -44,12 +44,14 @@ public: void test(); void testNatural(); void testReplace(); + void testToken(); void testDecimalStringToNumber(); CPPUNIT_TEST_SUITE(TestString); CPPUNIT_TEST(test); CPPUNIT_TEST(testNatural); CPPUNIT_TEST(testReplace); + CPPUNIT_TEST(testToken); CPPUNIT_TEST(testDecimalStringToNumber); CPPUNIT_TEST_SUITE_END(); }; @@ -311,11 +313,39 @@ void TestString::testReplace() 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"))); + + aOut = ::comphelper::string::replace(aIn, + rtl::OString(' '), + rtl::OString()); + CPPUNIT_ASSERT(aOut.equalsL( + RTL_CONSTASCII_STRINGPARAM("aaafooaaafoobbb"))); +} + +void TestString::testToken() +{ + ::rtl::OString aIn(RTL_CONSTASCII_STRINGPARAM("10.11.12")); + ::rtl::OString aOut; + + aOut = ::comphelper::string::getToken(aIn, -1, '.'); + CPPUNIT_ASSERT(aOut.isEmpty()); + + aOut = ::comphelper::string::getToken(aIn, 0, '.'); + CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("10"))); + + aOut = ::comphelper::string::getToken(aIn, 1, '.'); + CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("11"))); + + aOut = ::comphelper::string::getToken(aIn, 2, '.'); + CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("12"))); + + aOut = ::comphelper::string::getToken(aIn, 3, '.'); + CPPUNIT_ASSERT(aOut.isEmpty()); } CPPUNIT_TEST_SUITE_REGISTRATION(TestString); |