| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <sal/config.h> |
| 11 |
|
| 12 |
#include <string_view> |
| 13 |
|
| 14 |
#include <cppunit/TestAssert.h> |
| 15 |
#include <cppunit/TestFixture.h> |
| 16 |
#include <cppunit/extensions/HelperMacros.h> |
| 17 |
|
| 18 |
#include <rtl/string.hxx> |
| 19 |
#include <rtl/ustrbuf.hxx> |
| 20 |
#include <rtl/ustring.hxx> |
| 21 |
|
| 22 |
namespace |
| 23 |
{ |
| 24 |
class Test : public CppUnit::TestFixture |
| 25 |
{ |
| 26 |
void string() { CPPUNIT_ASSERT_EQUAL(OString(), OString(std::string_view())); } |
| 27 |
|
| 28 |
void stringbuffer() |
| 29 |
{ |
| 30 |
// No functions related to OStringBuffer that take a std::string_view or std::u16string_view |
| 31 |
// argument. |
| 32 |
} |
| 33 |
|
| 34 |
void ustring() |
| 35 |
{ |
| 36 |
CPPUNIT_ASSERT_EQUAL(OUString(), OUString(std::u16string_view())); |
| 37 |
OUString s1(u"foo"_ustr); |
| 38 |
s1 = std::u16string_view(); |
| 39 |
CPPUNIT_ASSERT_EQUAL(OUString(), s1); |
| 40 |
OUString s2(u"foo"_ustr); |
| 41 |
s2 += std::u16string_view(); |
| 42 |
CPPUNIT_ASSERT_EQUAL(u"foo"_ustr, s2); |
| 43 |
CPPUNIT_ASSERT_GREATER(sal_Int32(0), u"foo"_ustr.reverseCompareTo(std::u16string_view())); |
| 44 |
CPPUNIT_ASSERT_EQUAL(false, u"foo"_ustr.equalsIgnoreAsciiCase(std::u16string_view())); |
| 45 |
CPPUNIT_ASSERT_GREATER(sal_Int32(0), |
| 46 |
u"foo"_ustr.compareToIgnoreAsciiCase(std::u16string_view())); |
| 47 |
CPPUNIT_ASSERT_EQUAL(true, u"foo"_ustr.match(std::u16string_view())); |
| 48 |
CPPUNIT_ASSERT_EQUAL(true, u"foo"_ustr.matchIgnoreAsciiCase(std::u16string_view())); |
| 49 |
CPPUNIT_ASSERT_EQUAL(true, u"foo"_ustr.startsWith(std::u16string_view())); |
| 50 |
CPPUNIT_ASSERT_EQUAL(true, u"foo"_ustr.startsWithIgnoreAsciiCase(std::u16string_view())); |
| 51 |
CPPUNIT_ASSERT_EQUAL(true, u"foo"_ustr.endsWith(std::u16string_view())); |
| 52 |
CPPUNIT_ASSERT_EQUAL(true, u"foo"_ustr.endsWithIgnoreAsciiCase(std::u16string_view())); |
| 53 |
static constexpr OUString foo( |
| 54 |
u"foo"_ustr); // avoid loplugin:stringconstant, loplugin:stringview |
| 55 |
CPPUNIT_ASSERT_EQUAL(false, foo == std::u16string_view()); |
| 56 |
CPPUNIT_ASSERT_EQUAL(true, foo != std::u16string_view()); |
| 57 |
CPPUNIT_ASSERT_EQUAL(false, foo < std::u16string_view()); |
| 58 |
CPPUNIT_ASSERT_EQUAL(false, foo <= std::u16string_view()); |
| 59 |
CPPUNIT_ASSERT_EQUAL(true, foo > std::u16string_view()); |
| 60 |
CPPUNIT_ASSERT_EQUAL(true, foo >= std::u16string_view()); |
| 61 |
CPPUNIT_ASSERT_EQUAL(false, std::u16string_view() == foo); |
| 62 |
CPPUNIT_ASSERT_EQUAL(true, std::u16string_view() != foo); |
| 63 |
CPPUNIT_ASSERT_EQUAL(true, std::u16string_view() < foo); |
| 64 |
CPPUNIT_ASSERT_EQUAL(true, std::u16string_view() <= foo); |
| 65 |
CPPUNIT_ASSERT_EQUAL(false, std::u16string_view() > foo); |
| 66 |
CPPUNIT_ASSERT_EQUAL(false, std::u16string_view() >= foo); |
| 67 |
CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), u"foo"_ustr.indexOf(std::u16string_view())); |
| 68 |
CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), u"foo"_ustr.lastIndexOf(std::u16string_view())); |
| 69 |
CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), u"foo"_ustr.lastIndexOf(std::u16string_view(), 3)); |
| 70 |
CPPUNIT_ASSERT_EQUAL(u"foobarfoo"_ustr, u"foobarfoo"_ustr.replaceFirst( |
| 71 |
std::u16string_view(), std::u16string_view())); |
| 72 |
CPPUNIT_ASSERT_EQUAL( |
| 73 |
u"barfoo"_ustr, |
| 74 |
u"foobarfoo"_ustr.replaceFirst(std::u16string_view(u"foo"), std::u16string_view())); |
| 75 |
CPPUNIT_ASSERT_EQUAL( |
| 76 |
u"foobarfoo"_ustr, |
| 77 |
u"foobarfoo"_ustr.replaceFirst(std::u16string_view(), std::u16string_view(u"baz"))); |
| 78 |
CPPUNIT_ASSERT_EQUAL(u"barfoo"_ustr, |
| 79 |
u"foobarfoo"_ustr.replaceFirst("foo", std::u16string_view())); |
| 80 |
CPPUNIT_ASSERT_EQUAL(u"foobarfoo"_ustr, |
| 81 |
u"foobarfoo"_ustr.replaceFirst(std::u16string_view(), "baz")); |
| 82 |
CPPUNIT_ASSERT_EQUAL(u"foobarfoo"_ustr, u"foobarfoo"_ustr.replaceAll( |
| 83 |
std::u16string_view(), std::u16string_view())); |
| 84 |
CPPUNIT_ASSERT_EQUAL(u"bar"_ustr, u"foobarfoo"_ustr.replaceAll(std::u16string_view(u"foo"), |
| 85 |
std::u16string_view())); |
| 86 |
CPPUNIT_ASSERT_EQUAL( |
| 87 |
u"foobarfoo"_ustr, |
| 88 |
u"foobarfoo"_ustr.replaceAll(std::u16string_view(), std::u16string_view(u"baz"))); |
| 89 |
CPPUNIT_ASSERT_EQUAL(u"bar"_ustr, |
| 90 |
u"foobarfoo"_ustr.replaceAll("foo", std::u16string_view())); |
| 91 |
CPPUNIT_ASSERT_EQUAL(u"foobarfoo"_ustr, |
| 92 |
u"foobarfoo"_ustr.replaceAll(std::u16string_view(), "baz")); |
| 93 |
CPPUNIT_ASSERT_EQUAL(OUString(), OUString::createFromAscii(std::string_view())); |
| 94 |
} |
| 95 |
|
| 96 |
void ustringbuffer() |
| 97 |
{ |
| 98 |
OUStringBuffer b("foo"); |
| 99 |
b.append(std::u16string_view()); |
| 100 |
CPPUNIT_ASSERT_EQUAL(u"foo"_ustr, b.toString()); |
| 101 |
} |
| 102 |
|
| 103 |
CPPUNIT_TEST_SUITE(Test); |
| 104 |
CPPUNIT_TEST(string); |
| 105 |
CPPUNIT_TEST(stringbuffer); |
| 106 |
CPPUNIT_TEST(ustring); |
| 107 |
CPPUNIT_TEST(ustringbuffer); |
| 108 |
CPPUNIT_TEST_SUITE_END(); |
| 109 |
}; |
| 110 |
} |
| 111 |
|
| 112 |
CPPUNIT_TEST_SUITE_REGISTRATION(Test); |
| 113 |
|
| 114 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |