1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/types.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
23 #include <rtl/strbuf.hxx>
24 #include <rtl/string.h>
25 #include <rtl/string.hxx>
26 #include <rtl/textenc.h>
27 #include <rtl/ustring.hxx>
28 #include <sal/macros.h>
30 namespace test::oustring
{
32 class EndsWith
: public CppUnit::TestFixture
37 CPPUNIT_TEST_SUITE(EndsWith
);
38 CPPUNIT_TEST(endsWith
);
39 CPPUNIT_TEST_SUITE_END();
44 CPPUNIT_TEST_SUITE_REGISTRATION(test::oustring::EndsWith
);
48 void appendString(OStringBuffer
& buffer
, OString
const & string
)
51 for (int i
= 0; i
< string
.getLength(); ++i
) {
53 if (c
< ' ' || c
== '"' || c
== '\\' || c
> '~') {
55 sal_Int32 n
= static_cast< sal_Int32
>(
56 static_cast< unsigned char >(c
));
70 void test::oustring::EndsWith::endsWith()
80 { RTL_CONSTASCII_STRINGPARAM(""), RTL_CONSTASCII_STRINGPARAM(""),
82 { RTL_CONSTASCII_STRINGPARAM("abc"), RTL_CONSTASCII_STRINGPARAM(""),
84 { RTL_CONSTASCII_STRINGPARAM(""), RTL_CONSTASCII_STRINGPARAM("abc"),
86 { RTL_CONSTASCII_STRINGPARAM("ABC"), RTL_CONSTASCII_STRINGPARAM("abc"),
88 { RTL_CONSTASCII_STRINGPARAM("abcd"), RTL_CONSTASCII_STRINGPARAM("bcd"),
90 { RTL_CONSTASCII_STRINGPARAM("bcd"), RTL_CONSTASCII_STRINGPARAM("abcd"),
92 { RTL_CONSTASCII_STRINGPARAM("a\0b\0c"),
93 RTL_CONSTASCII_STRINGPARAM("b\0c"), true },
94 { RTL_CONSTASCII_STRINGPARAM("a\0b\0c"),
95 RTL_CONSTASCII_STRINGPARAM("b"), false } };
96 for (auto const[pStr1
, nStr1Len
, pStr2
, nStr2Len
, bEndsWith
] : data
)
99 appendString(msg
, OString(pStr1
, nStr1Len
));
100 msg
.append(".endsWithIgnoreAsciiCaseAsciiL(");
101 appendString(msg
, OString(pStr2
, nStr2Len
));
103 msg
.append(bEndsWith
);
104 CPPUNIT_ASSERT_EQUAL_MESSAGE(msg
.getStr(), bEndsWith
,
105 OUString(pStr1
, nStr1Len
, RTL_TEXTENCODING_ASCII_US
)
106 .endsWithIgnoreAsciiCaseAsciiL(pStr2
, nStr2Len
));
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */