1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: test_oustring_endswith.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sal.hxx"
34 #include "cppunit/simpleheader.hxx"
35 #include "rtl/strbuf.hxx"
36 #include "rtl/string.h"
37 #include "rtl/string.hxx"
38 #include "rtl/textenc.h"
39 #include "rtl/ustring.hxx"
40 #include "sal/types.h"
42 namespace test
{ namespace oustring
{
44 class EndsWith
: public CppUnit::TestFixture
49 CPPUNIT_TEST_SUITE(EndsWith
);
50 CPPUNIT_TEST(endsWith
);
51 CPPUNIT_TEST_SUITE_END();
56 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test::oustring::EndsWith
, "alltest");
60 void appendString(rtl::OStringBuffer
& buffer
, rtl::OString
const & string
)
63 for (int i
= 0; i
< string
.getLength(); ++i
) {
65 if (c
< ' ' || c
== '"' || c
== '\\' || c
> '~') {
67 sal_Int32 n
= static_cast< sal_Int32
>(
68 static_cast< unsigned char >(c
));
82 void test::oustring::EndsWith::endsWith()
92 { RTL_CONSTASCII_STRINGPARAM(""), RTL_CONSTASCII_STRINGPARAM(""),
94 { RTL_CONSTASCII_STRINGPARAM("abc"), RTL_CONSTASCII_STRINGPARAM(""),
96 { RTL_CONSTASCII_STRINGPARAM(""), RTL_CONSTASCII_STRINGPARAM("abc"),
98 { RTL_CONSTASCII_STRINGPARAM("ABC"), RTL_CONSTASCII_STRINGPARAM("abc"),
100 { RTL_CONSTASCII_STRINGPARAM("abcd"), RTL_CONSTASCII_STRINGPARAM("bcd"),
102 { RTL_CONSTASCII_STRINGPARAM("bcd"), RTL_CONSTASCII_STRINGPARAM("abcd"),
104 { RTL_CONSTASCII_STRINGPARAM("a\0b\0c"),
105 RTL_CONSTASCII_STRINGPARAM("b\0c"), true },
106 { RTL_CONSTASCII_STRINGPARAM("a\0b\0c"),
107 RTL_CONSTASCII_STRINGPARAM("b"), false } };
108 for (int i
= 0; i
< sizeof data
/ sizeof data
[0]; ++i
) {
109 rtl::OStringBuffer msg
;
110 appendString(msg
, rtl::OString(data
[i
].str1
, data
[i
].str1Len
));
112 RTL_CONSTASCII_STRINGPARAM(".endsWithIgnoreAsciiCaseAsciiL("));
113 appendString(msg
, rtl::OString(data
[i
].str2
, data
[i
].str2Len
));
114 msg
.append(RTL_CONSTASCII_STRINGPARAM(") == "));
115 msg
.append(static_cast< sal_Bool
>(data
[i
].endsWith
));
116 CPPUNIT_ASSERT_MESSAGE(
119 data
[i
].str1
, data
[i
].str1Len
,
120 RTL_TEXTENCODING_ASCII_US
).endsWithIgnoreAsciiCaseAsciiL(
121 data
[i
].str2
, data
[i
].str2Len
)
122 == data
[i
].endsWith
);