From 88c00598b2a0bae1bdfe88d4300afec2512183d8 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Tue, 4 Dec 2012 19:58:11 +0100 Subject: support for fast string operator+ in operator+=/append Not much point in building a string instance that will be copied elsewhere immediatelly. Change-Id: I38b7d3696f2c619e6424eb3959b00cd2c7738c47 --- sal/qa/rtl/strings/test_ostring_concat.cxx | 19 ++++++++++++++++--- sal/qa/rtl/strings/test_oustring_concat.cxx | 18 +++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) (limited to 'sal/qa') diff --git a/sal/qa/rtl/strings/test_ostring_concat.cxx b/sal/qa/rtl/strings/test_ostring_concat.cxx index c3a422a51f5f..4c0630c56351 100644 --- a/sal/qa/rtl/strings/test_ostring_concat.cxx +++ b/sal/qa/rtl/strings/test_ostring_concat.cxx @@ -12,6 +12,7 @@ #include #include +#include #include @@ -32,12 +33,14 @@ namespace test { namespace ostring { class StringConcat : public CppUnit::TestFixture { private: - void check(); + void checkConcat(); void checkEnsureCapacity(); + void checkAppend(); CPPUNIT_TEST_SUITE(StringConcat); -CPPUNIT_TEST(check); +CPPUNIT_TEST(checkConcat); CPPUNIT_TEST(checkEnsureCapacity); +CPPUNIT_TEST(checkAppend); CPPUNIT_TEST_SUITE_END(); }; @@ -46,7 +49,7 @@ CPPUNIT_TEST_SUITE_END(); #else #define TYPES_ASSERT_EQUAL( a, b ) #endif -void test::ostring::StringConcat::check() +void test::ostring::StringConcat::checkConcat() { // All the extra () are to protect commas againsts being treated as separators of macro arguments. CPPUNIT_ASSERT_EQUAL( OString(), OString(OString() + OString()) ); @@ -113,6 +116,16 @@ void test::ostring::StringConcat::checkEnsureCapacity() rtl_string_release( oldStr ); } +void test::ostring::StringConcat::checkAppend() +{ + OString str( "foo" ); + str += OStringLiteral( "bar" ) + "baz"; + CPPUNIT_ASSERT_EQUAL( OString( "foobarbaz" ), str ); + OStringBuffer buf( "foo" ); + buf.append( OStringLiteral( "bar" ) + "baz" ); + CPPUNIT_ASSERT_EQUAL( OString( "foobarbaz" ), buf.makeStringAndClear()); +} + }} // namespace CPPUNIT_TEST_SUITE_REGISTRATION(test::ostring::StringConcat); diff --git a/sal/qa/rtl/strings/test_oustring_concat.cxx b/sal/qa/rtl/strings/test_oustring_concat.cxx index 108b166c6de2..8d98232a71a2 100644 --- a/sal/qa/rtl/strings/test_oustring_concat.cxx +++ b/sal/qa/rtl/strings/test_oustring_concat.cxx @@ -12,6 +12,7 @@ #include #include +#include #include @@ -32,12 +33,14 @@ namespace test { namespace oustring { class StringConcat : public CppUnit::TestFixture { private: - void check(); + void checkConcat(); void checkEnsureCapacity(); + void checkAppend(); CPPUNIT_TEST_SUITE(StringConcat); -CPPUNIT_TEST(check); +CPPUNIT_TEST(checkConcat); CPPUNIT_TEST(checkEnsureCapacity); +CPPUNIT_TEST(checkAppend); CPPUNIT_TEST_SUITE_END(); }; @@ -46,7 +49,7 @@ CPPUNIT_TEST_SUITE_END(); #else #define TYPES_ASSERT_EQUAL( a, b ) #endif -void test::oustring::StringConcat::check() +void test::oustring::StringConcat::checkConcat() { // All the extra () are to protect commas againsts being treated as separators of macro arguments. CPPUNIT_ASSERT_EQUAL( OUString(), OUString(OUString() + OUString()) ); @@ -105,6 +108,15 @@ void test::oustring::StringConcat::checkEnsureCapacity() rtl_uString_release( oldStr ); } +void test::oustring::StringConcat::checkAppend() +{ + OUString str( "foo" ); + str += OUStringLiteral( "bar" ) + "baz"; + CPPUNIT_ASSERT_EQUAL( OUString( "foobarbaz" ), str ); + OUStringBuffer buf( "foo" ); + buf.append( OUStringLiteral( "bar" ) + "baz" ); + CPPUNIT_ASSERT_EQUAL( OUString( "foobarbaz" ), buf.makeStringAndClear()); +} }} // namespace -- cgit