tdf#154546 skip dispatch when presenter controller is not set
[LibreOffice.git] / sal / qa / rtl / strings / test_ostring.cxx
blobb4fb201cafa3a360d73f3a61712d08b1c079b757
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <cppunit/TestAssert.h>
13 #include <cppunit/TestFixture.h>
14 #include <cppunit/extensions/HelperMacros.h>
15 #include <rtl/string.hxx>
17 namespace {
19 class Test: public CppUnit::TestFixture {
20 private:
21 void testStartsWithIgnoreAsciiCase();
22 void testCompareTo();
23 void testUtf8StringLiterals();
25 CPPUNIT_TEST_SUITE(Test);
26 CPPUNIT_TEST(testStartsWithIgnoreAsciiCase);
27 CPPUNIT_TEST(testCompareTo);
28 CPPUNIT_TEST(testUtf8StringLiterals);
29 CPPUNIT_TEST_SUITE_END();
32 void Test::testStartsWithIgnoreAsciiCase() {
34 OString r;
35 CPPUNIT_ASSERT(OString().startsWithIgnoreAsciiCase(std::string_view(), &r));
36 CPPUNIT_ASSERT(r.isEmpty());
39 OString r;
40 CPPUNIT_ASSERT(OString("foo").startsWithIgnoreAsciiCase(std::string_view(), &r));
41 CPPUNIT_ASSERT_EQUAL(OString("foo"), r);
44 OString r;
45 CPPUNIT_ASSERT(
46 OString("foo").startsWithIgnoreAsciiCase("F", &r));
47 CPPUNIT_ASSERT_EQUAL(OString("oo"), r);
50 OString r("other");
51 CPPUNIT_ASSERT(
52 !OString("foo").startsWithIgnoreAsciiCase("bar", &r));
53 CPPUNIT_ASSERT_EQUAL(OString("other"), r);
56 OString r("other");
57 CPPUNIT_ASSERT(
58 !OString("foo").startsWithIgnoreAsciiCase("foobar", &r));
59 CPPUNIT_ASSERT_EQUAL(OString("other"), r);
63 OString r;
64 CPPUNIT_ASSERT(OString().startsWithIgnoreAsciiCase("", &r));
65 CPPUNIT_ASSERT(r.isEmpty());
68 OString r;
69 CPPUNIT_ASSERT(OString("foo").startsWithIgnoreAsciiCase("", &r));
70 CPPUNIT_ASSERT_EQUAL(OString("foo"), r);
73 OString r;
74 CPPUNIT_ASSERT(
75 OString("foo").startsWithIgnoreAsciiCase("F", &r));
76 CPPUNIT_ASSERT_EQUAL(OString("oo"), r);
79 OString r("other");
80 CPPUNIT_ASSERT(
81 !OString("foo").startsWithIgnoreAsciiCase("bar", &r));
82 CPPUNIT_ASSERT_EQUAL(OString("other"), r);
85 OString r("other");
86 CPPUNIT_ASSERT(
87 !OString("foo").startsWithIgnoreAsciiCase("foobar", &r));
88 CPPUNIT_ASSERT_EQUAL(OString("other"), r);
92 void Test::testCompareTo()
94 // test that embedded NUL does not stop the compare
95 char str1[2] = { '\0', 'x' };
96 char str2[2] = { '\0', 'y' };
98 OString s1(str1, 2);
99 OString s2(str2, 2);
100 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), s1.compareTo(s1));
101 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), s2.compareTo(s2));
102 CPPUNIT_ASSERT(s1.compareTo(s2) < 0);
103 CPPUNIT_ASSERT(s2.compareTo(s1) > 0);
104 CPPUNIT_ASSERT(s1.compareTo(OString(s2 + "y")) < 0);
105 CPPUNIT_ASSERT(s2.compareTo(OString(s1 + "x")) > 0);
106 CPPUNIT_ASSERT(OString(s1 + "x").compareTo(s2) < 0);
107 CPPUNIT_ASSERT(OString(s2 + "y").compareTo(s1) > 0);
110 void Test::testUtf8StringLiterals()
112 const OString sIn(u8"ßa");
113 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), sIn.getLength());
114 CPPUNIT_ASSERT_EQUAL(195, int(static_cast<unsigned char>(sIn[0])));
115 CPPUNIT_ASSERT_EQUAL(159, int(static_cast<unsigned char>(sIn[1])));
116 CPPUNIT_ASSERT_EQUAL(97, int(static_cast<unsigned char>(sIn[2])));
119 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */