tdf#154546 skip dispatch when presenter controller is not set
[LibreOffice.git] / sal / qa / rtl / strings / test_strings_defaultstringview.cxx
blob591688b31c3c87e80103ca8ba40fd6e69de2aa73
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.
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 */
10 #include <sal/config.h>
12 #include <string_view>
14 #include <cppunit/TestAssert.h>
15 #include <cppunit/TestFixture.h>
16 #include <cppunit/extensions/HelperMacros.h>
18 #include <rtl/string.hxx>
19 #include <rtl/ustrbuf.hxx>
20 #include <rtl/ustring.hxx>
22 namespace
24 class Test : public CppUnit::TestFixture
26 void string() { CPPUNIT_ASSERT_EQUAL(OString(), OString(std::string_view())); }
28 void stringbuffer()
30 // No functions related to OStringBuffer that take a std::string_view or std::u16string_view
31 // argument.
34 void ustring()
36 CPPUNIT_ASSERT_EQUAL(OUString(), OUString(std::u16string_view()));
37 OUString s1("foo");
38 s1 = std::u16string_view();
39 CPPUNIT_ASSERT_EQUAL(OUString(), s1);
40 OUString s2("foo");
41 s2 += std::u16string_view();
42 CPPUNIT_ASSERT_EQUAL(OUString("foo"), s2);
43 CPPUNIT_ASSERT_GREATER(sal_Int32(0),
44 OUString("foo").reverseCompareTo(std::u16string_view()));
45 CPPUNIT_ASSERT_EQUAL(false, OUString("foo").equalsIgnoreAsciiCase(std::u16string_view()));
46 CPPUNIT_ASSERT_GREATER(sal_Int32(0),
47 OUString("foo").compareToIgnoreAsciiCase(std::u16string_view()));
48 CPPUNIT_ASSERT_EQUAL(true, OUString("foo").match(std::u16string_view()));
49 CPPUNIT_ASSERT_EQUAL(true, OUString("foo").matchIgnoreAsciiCase(std::u16string_view()));
50 CPPUNIT_ASSERT_EQUAL(true, OUString("foo").startsWith(std::u16string_view()));
51 CPPUNIT_ASSERT_EQUAL(true,
52 OUString("foo").startsWithIgnoreAsciiCase(std::u16string_view()));
53 CPPUNIT_ASSERT_EQUAL(true, OUString("foo").endsWith(std::u16string_view()));
54 CPPUNIT_ASSERT_EQUAL(true, OUString("foo").endsWithIgnoreAsciiCase(std::u16string_view()));
55 OUString const foo("foo"); // avoid loplugin:stringconstant, loplugin:stringview
56 CPPUNIT_ASSERT_EQUAL(false, foo == std::u16string_view());
57 CPPUNIT_ASSERT_EQUAL(true, foo != std::u16string_view());
58 CPPUNIT_ASSERT_EQUAL(false, foo < std::u16string_view());
59 CPPUNIT_ASSERT_EQUAL(false, foo <= std::u16string_view());
60 CPPUNIT_ASSERT_EQUAL(true, foo > std::u16string_view());
61 CPPUNIT_ASSERT_EQUAL(true, foo >= std::u16string_view());
62 CPPUNIT_ASSERT_EQUAL(false, 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(true, std::u16string_view() <= foo);
66 CPPUNIT_ASSERT_EQUAL(false, std::u16string_view() > foo);
67 CPPUNIT_ASSERT_EQUAL(false, std::u16string_view() >= foo);
68 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), OUString("foo").indexOf(std::u16string_view()));
69 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), OUString("foo").lastIndexOf(std::u16string_view()));
70 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), OUString("foo").lastIndexOf(std::u16string_view(), 3));
71 CPPUNIT_ASSERT_EQUAL(
72 OUString("foobarfoo"),
73 OUString("foobarfoo").replaceFirst(std::u16string_view(), std::u16string_view()));
74 CPPUNIT_ASSERT_EQUAL(
75 OUString("barfoo"),
76 OUString("foobarfoo").replaceFirst(std::u16string_view(u"foo"), std::u16string_view()));
77 CPPUNIT_ASSERT_EQUAL(
78 OUString("foobarfoo"),
79 OUString("foobarfoo").replaceFirst(std::u16string_view(), std::u16string_view(u"baz")));
80 CPPUNIT_ASSERT_EQUAL(OUString("barfoo"),
81 OUString("foobarfoo").replaceFirst("foo", std::u16string_view()));
82 CPPUNIT_ASSERT_EQUAL(OUString("foobarfoo"),
83 OUString("foobarfoo").replaceFirst(std::u16string_view(), "baz"));
84 CPPUNIT_ASSERT_EQUAL(
85 OUString("foobarfoo"),
86 OUString("foobarfoo").replaceAll(std::u16string_view(), std::u16string_view()));
87 CPPUNIT_ASSERT_EQUAL(
88 OUString("bar"),
89 OUString("foobarfoo").replaceAll(std::u16string_view(u"foo"), std::u16string_view()));
90 CPPUNIT_ASSERT_EQUAL(
91 OUString("foobarfoo"),
92 OUString("foobarfoo").replaceAll(std::u16string_view(), std::u16string_view(u"baz")));
93 CPPUNIT_ASSERT_EQUAL(OUString("bar"),
94 OUString("foobarfoo").replaceAll("foo", std::u16string_view()));
95 CPPUNIT_ASSERT_EQUAL(OUString("foobarfoo"),
96 OUString("foobarfoo").replaceAll(std::u16string_view(), "baz"));
97 CPPUNIT_ASSERT_EQUAL(OUString(), OUString::createFromAscii(std::string_view()));
100 void ustringbuffer()
102 OUStringBuffer b("foo");
103 b.append(std::u16string_view());
104 CPPUNIT_ASSERT_EQUAL(OUString("foo"), b.toString());
107 CPPUNIT_TEST_SUITE(Test);
108 CPPUNIT_TEST(string);
109 CPPUNIT_TEST(stringbuffer);
110 CPPUNIT_TEST(ustring);
111 CPPUNIT_TEST(ustringbuffer);
112 CPPUNIT_TEST_SUITE_END();
116 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */