diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2014-12-17 15:47:01 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2014-12-17 16:39:33 +0100 |
commit | 0f5e9170248df98ef7c7c6d475ff7d2bb9fa2214 (patch) | |
tree | 484d55e20e414c16202163b766fdd87777ebb46d /sal/qa | |
parent | 0ba6360363fb73b5b200bbc486ed8eeac5f3d337 (diff) |
Introduce rtl::OUStringLiteral1
...to use single ASCII character literals "more directly" in the OUString API
(instead of having to go via an intermediary OUString ctor call). Especially
useful for character literals that are defined as const variables or via macros
("direct" uses of character literals in the OUString API can often simply be
replaced with single-character string literals, for improved readability).
(The functions overloaded for OUStringLiteral1 are those that are actually used
by the existing LO code; more could potentially be added. The asymmetry in the
operator ==/!= parameter types is by design, though---writing code like
'x' == s
is an abomination that shall not be abetted.)
Change-Id: Ic5264714be7439eed56b5dfca6ccaee277306f1f
Diffstat (limited to 'sal/qa')
-rw-r--r-- | sal/qa/rtl/strings/test_oustring_stringliterals.cxx | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx index 192eeb5ae63b..0693fc2a3e08 100644 --- a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx +++ b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx @@ -31,6 +31,7 @@ private: void checkExtraIntArgument(); void checkNonconstChar(); void checkBuffer(); + void checkOUStringLiteral1(); void testcall( const char str[] ); @@ -40,6 +41,7 @@ CPPUNIT_TEST(checkUsage); CPPUNIT_TEST(checkExtraIntArgument); CPPUNIT_TEST(checkNonconstChar); CPPUNIT_TEST(checkBuffer); +CPPUNIT_TEST(checkOUStringLiteral1); CPPUNIT_TEST_SUITE_END(); }; @@ -170,6 +172,28 @@ void test::oustring::StringLiterals::checkBuffer() CPPUNIT_ASSERT( !VALID_CONVERSION( buf.append( rtl::OUStringBuffer( d )))); } +void test::oustring::StringLiterals::checkOUStringLiteral1() +{ + rtl::OUString s1; + s1 = rtlunittest::OUStringLiteral1<'A'>(); + CPPUNIT_ASSERT_EQUAL(1, s1.getLength()); + CPPUNIT_ASSERT_EQUAL(sal_Unicode('A'), s1[0]); + + CPPUNIT_ASSERT_EQUAL( + true, rtl::OUString("A") == rtlunittest::OUStringLiteral1<'A'>()); + CPPUNIT_ASSERT_EQUAL( + false, rtl::OUString("AB") == rtlunittest::OUStringLiteral1<'A'>()); + CPPUNIT_ASSERT_EQUAL( + false, rtl::OUString("A") != rtlunittest::OUStringLiteral1<'A'>()); + CPPUNIT_ASSERT_EQUAL( + true, rtl::OUString("AB") != rtlunittest::OUStringLiteral1<'A'>()); + + rtl::OUString s2("A" + rtlunittest::OUStringLiteral1<'b'>()); + CPPUNIT_ASSERT_EQUAL(2, s2.getLength()); + CPPUNIT_ASSERT_EQUAL(sal_Unicode('A'), s2[0]); + CPPUNIT_ASSERT_EQUAL(sal_Unicode('b'), s2[1]); +} + }} // namespace CPPUNIT_TEST_SUITE_REGISTRATION(test::oustring::StringLiterals); |