From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- sal/qa/rtl/strings/test_ostring.cxx | 123 ++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 sal/qa/rtl/strings/test_ostring.cxx (limited to 'sal/qa/rtl/strings/test_ostring.cxx') diff --git a/sal/qa/rtl/strings/test_ostring.cxx b/sal/qa/rtl/strings/test_ostring.cxx new file mode 100644 index 000000000..b4fb201ca --- /dev/null +++ b/sal/qa/rtl/strings/test_ostring.cxx @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include +#include +#include +#include + +namespace { + +class Test: public CppUnit::TestFixture { +private: + void testStartsWithIgnoreAsciiCase(); + void testCompareTo(); + void testUtf8StringLiterals(); + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(testStartsWithIgnoreAsciiCase); + CPPUNIT_TEST(testCompareTo); + CPPUNIT_TEST(testUtf8StringLiterals); + CPPUNIT_TEST_SUITE_END(); +}; + +void Test::testStartsWithIgnoreAsciiCase() { + { + OString r; + CPPUNIT_ASSERT(OString().startsWithIgnoreAsciiCase(std::string_view(), &r)); + CPPUNIT_ASSERT(r.isEmpty()); + } + { + OString r; + CPPUNIT_ASSERT(OString("foo").startsWithIgnoreAsciiCase(std::string_view(), &r)); + CPPUNIT_ASSERT_EQUAL(OString("foo"), r); + } + { + OString r; + CPPUNIT_ASSERT( + OString("foo").startsWithIgnoreAsciiCase("F", &r)); + CPPUNIT_ASSERT_EQUAL(OString("oo"), r); + } + { + OString r("other"); + CPPUNIT_ASSERT( + !OString("foo").startsWithIgnoreAsciiCase("bar", &r)); + CPPUNIT_ASSERT_EQUAL(OString("other"), r); + } + { + OString r("other"); + CPPUNIT_ASSERT( + !OString("foo").startsWithIgnoreAsciiCase("foobar", &r)); + CPPUNIT_ASSERT_EQUAL(OString("other"), r); + } + + { + OString r; + CPPUNIT_ASSERT(OString().startsWithIgnoreAsciiCase("", &r)); + CPPUNIT_ASSERT(r.isEmpty()); + } + { + OString r; + CPPUNIT_ASSERT(OString("foo").startsWithIgnoreAsciiCase("", &r)); + CPPUNIT_ASSERT_EQUAL(OString("foo"), r); + } + { + OString r; + CPPUNIT_ASSERT( + OString("foo").startsWithIgnoreAsciiCase("F", &r)); + CPPUNIT_ASSERT_EQUAL(OString("oo"), r); + } + { + OString r("other"); + CPPUNIT_ASSERT( + !OString("foo").startsWithIgnoreAsciiCase("bar", &r)); + CPPUNIT_ASSERT_EQUAL(OString("other"), r); + } + { + OString r("other"); + CPPUNIT_ASSERT( + !OString("foo").startsWithIgnoreAsciiCase("foobar", &r)); + CPPUNIT_ASSERT_EQUAL(OString("other"), r); + } +} + +void Test::testCompareTo() +{ + // test that embedded NUL does not stop the compare + char str1[2] = { '\0', 'x' }; + char str2[2] = { '\0', 'y' }; + + OString s1(str1, 2); + OString s2(str2, 2); + CPPUNIT_ASSERT_EQUAL(static_cast(0), s1.compareTo(s1)); + CPPUNIT_ASSERT_EQUAL(static_cast(0), s2.compareTo(s2)); + CPPUNIT_ASSERT(s1.compareTo(s2) < 0); + CPPUNIT_ASSERT(s2.compareTo(s1) > 0); + CPPUNIT_ASSERT(s1.compareTo(OString(s2 + "y")) < 0); + CPPUNIT_ASSERT(s2.compareTo(OString(s1 + "x")) > 0); + CPPUNIT_ASSERT(OString(s1 + "x").compareTo(s2) < 0); + CPPUNIT_ASSERT(OString(s2 + "y").compareTo(s1) > 0); +} + +void Test::testUtf8StringLiterals() +{ + const OString sIn(u8"ßa"); + CPPUNIT_ASSERT_EQUAL(static_cast(3), sIn.getLength()); + CPPUNIT_ASSERT_EQUAL(195, int(static_cast(sIn[0]))); + CPPUNIT_ASSERT_EQUAL(159, int(static_cast(sIn[1]))); + CPPUNIT_ASSERT_EQUAL(97, int(static_cast(sIn[2]))); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3