update dev300-m57
[ooovba.git] / sal / qa / rtl / strings / test_oustring_endswith.cxx
blob6d744f2cf7abaa7e9a6d2cb63c557d7554471e01
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: test_oustring_endswith.cxx,v $
10 * $Revision: 1.5 $
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
46 private:
47 void endsWith();
49 CPPUNIT_TEST_SUITE(EndsWith);
50 CPPUNIT_TEST(endsWith);
51 CPPUNIT_TEST_SUITE_END();
54 } }
56 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test::oustring::EndsWith, "alltest");
58 namespace {
60 void appendString(rtl::OStringBuffer & buffer, rtl::OString const & string)
62 buffer.append('"');
63 for (int i = 0; i < string.getLength(); ++i) {
64 char c = string[i];
65 if (c < ' ' || c == '"' || c == '\\' || c > '~') {
66 buffer.append('\\');
67 sal_Int32 n = static_cast< sal_Int32 >(
68 static_cast< unsigned char >(c));
69 if (n < 16) {
70 buffer.append('0');
72 buffer.append(n, 16);
73 } else {
74 buffer.append(c);
77 buffer.append('"');
82 void test::oustring::EndsWith::endsWith()
84 struct Data {
85 char const * str1;
86 sal_Int32 str1Len;
87 char const * str2;
88 sal_Int32 str2Len;
89 bool endsWith;
91 Data const data[] = {
92 { RTL_CONSTASCII_STRINGPARAM(""), RTL_CONSTASCII_STRINGPARAM(""),
93 true },
94 { RTL_CONSTASCII_STRINGPARAM("abc"), RTL_CONSTASCII_STRINGPARAM(""),
95 true },
96 { RTL_CONSTASCII_STRINGPARAM(""), RTL_CONSTASCII_STRINGPARAM("abc"),
97 false },
98 { RTL_CONSTASCII_STRINGPARAM("ABC"), RTL_CONSTASCII_STRINGPARAM("abc"),
99 true },
100 { RTL_CONSTASCII_STRINGPARAM("abcd"), RTL_CONSTASCII_STRINGPARAM("bcd"),
101 true },
102 { RTL_CONSTASCII_STRINGPARAM("bcd"), RTL_CONSTASCII_STRINGPARAM("abcd"),
103 false },
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));
111 msg.append(
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(
117 msg.getStr(),
118 rtl::OUString(
119 data[i].str1, data[i].str1Len,
120 RTL_TEXTENCODING_ASCII_US).endsWithIgnoreAsciiCaseAsciiL(
121 data[i].str2, data[i].str2Len)
122 == data[i].endsWith);