summaryrefslogtreecommitdiffstats
path: root/sal/qa
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2012-12-02 22:29:21 +0100
committerLuboš Luňák <l.lunak@suse.cz>2012-12-03 18:04:23 +0100
commitd87f5d30879aca73fff271c254589fc41a91fdd0 (patch)
treed3d736178035c1d590f0642cd031e1f6d4b3fd17 /sal/qa
parentUpdated core (diff)
downloadcore-d87f5d30879aca73fff271c254589fc41a91fdd0.tar.gz
core-d87f5d30879aca73fff271c254589fc41a91fdd0.zip
support for fast O(U)String concatenation using operator+
Operator+ now, instead of requiring O(U)String operands and returning another O(U)String object, keeps a track of the whole concatenation operation using temporary O(U)StringConcat objects and performs the whole operation only at the very end. Change-Id: I94b3348300a137498514d26e96459c1698328520
Diffstat (limited to 'sal/qa')
-rw-r--r--sal/qa/rtl/strings/test_ostring_concat.cxx79
-rw-r--r--sal/qa/rtl/strings/test_oustring_concat.cxx68
2 files changed, 147 insertions, 0 deletions
diff --git a/sal/qa/rtl/strings/test_ostring_concat.cxx b/sal/qa/rtl/strings/test_ostring_concat.cxx
new file mode 100644
index 000000000000..a79b2dad32fb
--- /dev/null
+++ b/sal/qa/rtl/strings/test_ostring_concat.cxx
@@ -0,0 +1,79 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/types.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <rtl/string.hxx>
+
+#include <typeinfo>
+
+using namespace rtl;
+
+namespace std
+{
+template< typename charT, typename traits > std::basic_ostream<charT, traits> &
+operator <<(
+ std::basic_ostream<charT, traits> & stream, const std::type_info& info )
+{
+ return stream << info.name();
+}
+} // namespace
+
+namespace test { namespace ostring {
+
+class StringConcat : public CppUnit::TestFixture
+{
+private:
+ void check();
+
+CPPUNIT_TEST_SUITE(StringConcat);
+CPPUNIT_TEST(check);
+CPPUNIT_TEST_SUITE_END();
+};
+
+#ifdef RTL_FAST_STRING
+#define TYPES_ASSERT_EQUAL( a, b ) CPPUNIT_ASSERT_EQUAL( a, b )
+#else
+#define TYPES_ASSERT_EQUAL( a, b )
+#endif
+void test::ostring::StringConcat::check()
+{
+// All the extra () are to protect commas againsts being treated as separators of macro arguments.
+ CPPUNIT_ASSERT_EQUAL( OString( "foobar" ), OString( OString( "foo" ) + OString( "bar" )));
+ TYPES_ASSERT_EQUAL(( typeid( OStringConcat< OString, OString > )), typeid( OString( "foo" ) + OString( "bar" )));
+ CPPUNIT_ASSERT_EQUAL( OString( "foobar" ), OString( OString( "foo" ) + "bar" ));
+ TYPES_ASSERT_EQUAL(( typeid( OStringConcat< OString, const char[ 4 ] > )), typeid( OString( "foo" ) + "bar" ));
+ CPPUNIT_ASSERT_EQUAL( OString( "foobarbaz" ), OString( OString( "foo" ) + "bar" + "baz" ));
+ TYPES_ASSERT_EQUAL(( typeid( OStringConcat< OStringConcat< OString, const char[ 4 ] >, const char[ 4 ] > )), typeid( OString( "foo" ) + "bar" + "baz" ));
+ CPPUNIT_ASSERT_EQUAL( OString( "foobar" ), OString( OStringLiteral( "foo" ) + "bar" ));
+ TYPES_ASSERT_EQUAL(( typeid( OStringConcat< OStringLiteral, const char[ 4 ] > )), typeid( OStringLiteral( "foo" ) + "bar" ));
+ CPPUNIT_ASSERT_EQUAL( OString( "foobar" ), OString( OStringLiteral( "foo" ) + (const char*)"bar" ));
+ TYPES_ASSERT_EQUAL(( typeid( OStringConcat< OStringLiteral, const char* > )), typeid( OStringLiteral( "foo" ) + (const char*)"bar" ));
+ const char d1[] = "xyz";
+ char d2[] = "abc";
+ const char* d3 = d1;
+ char* d4 = d2;
+ CPPUNIT_ASSERT_EQUAL( OString( "fooxyz" ), OString( OString( "foo" ) + d1 ));
+ TYPES_ASSERT_EQUAL(( typeid( OStringConcat< OString, const char[ 4 ] > )), typeid( OString( "foo" ) + d1 ));
+ CPPUNIT_ASSERT_EQUAL( OString( "fooabc" ), OString( OString( "foo" ) + d2 ));
+ TYPES_ASSERT_EQUAL(( typeid( OStringConcat< OString, char[ 4 ] > )), typeid( OString( "foo" ) + d2 ));
+ CPPUNIT_ASSERT_EQUAL( OString( "fooxyz" ), OString( OString( "foo" ) + d3 ));
+ TYPES_ASSERT_EQUAL(( typeid( OStringConcat< OString, const char* > )), typeid( OString( "foo" ) + d3 ));
+ CPPUNIT_ASSERT_EQUAL( OString( "fooabc" ), OString( OString( "foo" ) + d4 ));
+ TYPES_ASSERT_EQUAL(( typeid( OStringConcat< OString, char* > )), typeid( OString( "foo" ) + d4 ));
+}
+#undef typeid
+
+}} // namespace
+
+CPPUNIT_TEST_SUITE_REGISTRATION(test::ostring::StringConcat);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/qa/rtl/strings/test_oustring_concat.cxx b/sal/qa/rtl/strings/test_oustring_concat.cxx
new file mode 100644
index 000000000000..0cc25128a075
--- /dev/null
+++ b/sal/qa/rtl/strings/test_oustring_concat.cxx
@@ -0,0 +1,68 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/types.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <rtl/ustring.hxx>
+
+#include <typeinfo>
+
+using namespace rtl;
+
+namespace std
+{
+template< typename charT, typename traits > std::basic_ostream<charT, traits> &
+operator <<(
+ std::basic_ostream<charT, traits> & stream, const std::type_info& info )
+{
+ return stream << info.name();
+}
+} // namespace
+
+namespace test { namespace oustring {
+
+class StringConcat : public CppUnit::TestFixture
+{
+private:
+ void check();
+
+CPPUNIT_TEST_SUITE(StringConcat);
+CPPUNIT_TEST(check);
+CPPUNIT_TEST_SUITE_END();
+};
+
+#ifdef RTL_FAST_STRING
+#define TYPES_ASSERT_EQUAL( a, b ) CPPUNIT_ASSERT_EQUAL( a, b )
+#else
+#define TYPES_ASSERT_EQUAL( a, b )
+#endif
+void test::oustring::StringConcat::check()
+{
+// All the extra () are to protect commas againsts being treated as separators of macro arguments.
+ CPPUNIT_ASSERT_EQUAL( OUString( "foobar" ), OUString( OUString( "foo" ) + OUString( "bar" )));
+ TYPES_ASSERT_EQUAL(( typeid( OUStringConcat< OUString, OUString > )), typeid( OUString( "foo" ) + OUString( "bar" )));
+ CPPUNIT_ASSERT_EQUAL( OUString( "foobar" ), OUString( OUString( "foo" ) + "bar" ));
+ TYPES_ASSERT_EQUAL(( typeid( OUStringConcat< OUString, const char[ 4 ] > )), typeid( OUString( "foo" ) + "bar" ));
+ CPPUNIT_ASSERT_EQUAL( OUString( "foobarbaz" ), OUString( OUString( "foo" ) + "bar" + "baz" ));
+ TYPES_ASSERT_EQUAL(( typeid( OUStringConcat< OUStringConcat< OUString, const char[ 4 ] >, const char[ 4 ] > )), typeid( OUString( "foo" ) + "bar" + "baz" ));
+ CPPUNIT_ASSERT_EQUAL( OUString( "foobar" ), OUString( OUStringLiteral( "foo" ) + "bar" ));
+ TYPES_ASSERT_EQUAL(( typeid( OUStringConcat< OUStringLiteral, const char[ 4 ] > )), typeid( OUStringLiteral( "foo" ) + "bar" ));
+ const char d1[] = "xyz";
+ CPPUNIT_ASSERT_EQUAL( OUString( "fooxyz" ), OUString( OUString( "foo" ) + d1 ));
+ TYPES_ASSERT_EQUAL(( typeid( OUStringConcat< OUString, const char[ 4 ] > )), typeid( OUString( "foo" ) + d1 ));
+}
+#undef typeid
+
+}} // namespace
+
+CPPUNIT_TEST_SUITE_REGISTRATION(test::oustring::StringConcat);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */