summaryrefslogtreecommitdiff
path: root/sal/qa/rtl
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2012-03-08 01:14:39 +0100
committerLuboš Luňák <l.lunak@suse.cz>2012-03-12 13:35:58 +0100
commit91752ecd4ededaaf44f5ac870b3c01dd17b5d3c9 (patch)
tree9e1f276d34f402ab6724daf9bdb98f5f112bca82 /sal/qa/rtl
parent61327c99481b4fb9c36973a8b65b3f8004112951 (diff)
also check that string literals do not actually trigger OUString ctors
Diffstat (limited to 'sal/qa/rtl')
-rw-r--r--sal/qa/rtl/strings/test_oustring_stringliterals.cxx52
1 files changed, 33 insertions, 19 deletions
diff --git a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx
index 520cf59fcea1..d35596c34111 100644
--- a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx
+++ b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx
@@ -28,7 +28,7 @@
// activate the extra needed ctor
#define RTL_STRING_UNITTEST
-extern bool rtl_string_unittest_const_literal; // actually unused here
+extern bool rtl_string_unittest_const_literal;
#include "sal/config.h"
#include "sal/precppunit.hxx"
@@ -100,24 +100,38 @@ void test::oustring::StringLiterals::testcall( const char str[] )
}
void test::oustring::StringLiterals::checkUsage()
-{ // simply check that all string literal based calls work as expected
- CPPUNIT_ASSERT_EQUAL( rtl::OUString( "foo" ), rtl::OUString() = "foo" );
- CPPUNIT_ASSERT( rtl::OUString( "FoO" ).equalsIgnoreAsciiCase( "fOo" ));
- CPPUNIT_ASSERT( rtl::OUString( "foobarfoo" ).match( "bar", 3 ));
- CPPUNIT_ASSERT( rtl::OUString( "foobar" ).match( "foo" ));
- CPPUNIT_ASSERT( rtl::OUString( "FooBaRfoo" ).matchIgnoreAsciiCase( "bAr", 3 ));
- CPPUNIT_ASSERT( rtl::OUString( "FooBaR" ).matchIgnoreAsciiCase( "fOo" ));
- CPPUNIT_ASSERT( rtl::OUString( "foobar" ).endsWith( "bar" ));
- CPPUNIT_ASSERT( rtl::OUString( "foo" ) == "foo" );
- CPPUNIT_ASSERT( "foo" == rtl::OUString( "foo" ));
- CPPUNIT_ASSERT( rtl::OUString( "foo" ) != "bar" );
- CPPUNIT_ASSERT( "foo" != rtl::OUString( "bar" ));
- CPPUNIT_ASSERT( rtl::OUString( "foobarfoo" ).indexOf( "foo", 1 ) == 6 );
- CPPUNIT_ASSERT( rtl::OUString( "foobarfoo" ).lastIndexOf( "foo" ) == 6 );
- CPPUNIT_ASSERT( rtl::OUString( "foobarfoo" ).replaceFirst( "foo", rtl::OUString( "test" )) == "testbarfoo" );
- CPPUNIT_ASSERT( rtl::OUString( "foobarfoo" ).replaceFirst( "foo", "test" ) == "testbarfoo" );
- CPPUNIT_ASSERT( rtl::OUString( "foobarfoo" ).replaceAll( "foo", rtl::OUString( "test" )) == "testbartest" );
- CPPUNIT_ASSERT( rtl::OUString( "foobarfoo" ).replaceAll( "foo", "test" ) == "testbartest" );
+{
+// simply check that all string literal based calls work as expected
+// also check that they really use string literal overload and do not convert to OUString
+ rtl::OUString foo( "foo" );
+ rtl::OUString FoO( "FoO" );
+ rtl::OUString foobarfoo( "foobarfoo" );
+ rtl::OUString foobar( "foobar" );
+ rtl::OUString FooBaRfoo( "FooBaRfoo" );
+ rtl::OUString FooBaR( "FooBaR" );
+ rtl::OUString bar( "bar" );
+ rtl::OUString test( "test" );
+
+ rtl_string_unittest_const_literal = false; // start checking for OUString conversions
+ CPPUNIT_ASSERT_EQUAL( foo, rtl::OUString() = "foo" );
+ CPPUNIT_ASSERT( FoO.equalsIgnoreAsciiCase( "fOo" ));
+ CPPUNIT_ASSERT( foobarfoo.match( "bar", 3 ));
+ CPPUNIT_ASSERT( foobar.match( "foo" ));
+ CPPUNIT_ASSERT( FooBaRfoo.matchIgnoreAsciiCase( "bAr", 3 ));
+ CPPUNIT_ASSERT( FooBaR.matchIgnoreAsciiCase( "fOo" ));
+ CPPUNIT_ASSERT( foobar.endsWith( "bar" ));
+ CPPUNIT_ASSERT( foo == "foo" );
+ CPPUNIT_ASSERT( "foo" == foo );
+ CPPUNIT_ASSERT( foo != "bar" );
+ CPPUNIT_ASSERT( "foo" != bar );
+ CPPUNIT_ASSERT( foobarfoo.indexOf( "foo", 1 ) == 6 );
+ CPPUNIT_ASSERT( foobarfoo.lastIndexOf( "foo" ) == 6 );
+ CPPUNIT_ASSERT( foobarfoo.replaceFirst( "foo", test ) == "testbarfoo" );
+ CPPUNIT_ASSERT( foobarfoo.replaceFirst( "foo", "test" ) == "testbarfoo" );
+ CPPUNIT_ASSERT( foobarfoo.replaceAll( "foo", test ) == "testbartest" );
+ CPPUNIT_ASSERT( foobarfoo.replaceAll( "foo", "test" ) == "testbartest" );
+ // if this is not true, some of the calls above converted to OUString
+ CPPUNIT_ASSERT( rtl_string_unittest_const_literal == false );
}
void test::oustring::StringLiterals::checkExtraIntArgument()