187d2adbcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 387d2adbcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 487d2adbcSAndrew Rist * or more contributor license agreements. See the NOTICE file 587d2adbcSAndrew Rist * distributed with this work for additional information 687d2adbcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 787d2adbcSAndrew Rist * to you under the Apache License, Version 2.0 (the 887d2adbcSAndrew Rist * "License"); you may not use this file except in compliance 987d2adbcSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 1187d2adbcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 1387d2adbcSAndrew Rist * Unless required by applicable law or agreed to in writing, 1487d2adbcSAndrew Rist * software distributed under the License is distributed on an 1587d2adbcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1687d2adbcSAndrew Rist * KIND, either express or implied. See the License for the 1787d2adbcSAndrew Rist * specific language governing permissions and limitations 1887d2adbcSAndrew Rist * under the License. 19cdf0e10cSrcweir * 2087d2adbcSAndrew Rist *************************************************************/ 2187d2adbcSAndrew Rist 2287d2adbcSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sal.hxx" 26cdf0e10cSrcweir 27*fd5f88ecSDamjan Jovanovic #include "gtest/gtest.h" 28cdf0e10cSrcweir #include "rtl/strbuf.hxx" 29cdf0e10cSrcweir #include "rtl/string.h" 30cdf0e10cSrcweir #include "rtl/string.hxx" 31cdf0e10cSrcweir #include "rtl/textenc.h" 32cdf0e10cSrcweir #include "rtl/ustring.hxx" 33cdf0e10cSrcweir #include "sal/types.h" 34cdf0e10cSrcweir 35cdf0e10cSrcweir 36cdf0e10cSrcweir 37cdf0e10cSrcweir namespace { 38cdf0e10cSrcweir 39cdf0e10cSrcweir void appendString(rtl::OStringBuffer & buffer, rtl::OString const & string) 40cdf0e10cSrcweir { 41cdf0e10cSrcweir buffer.append('"'); 42cdf0e10cSrcweir for (int i = 0; i < string.getLength(); ++i) { 43cdf0e10cSrcweir char c = string[i]; 44cdf0e10cSrcweir if (c < ' ' || c == '"' || c == '\\' || c > '~') { 45cdf0e10cSrcweir buffer.append('\\'); 46cdf0e10cSrcweir sal_Int32 n = static_cast< sal_Int32 >( 47cdf0e10cSrcweir static_cast< unsigned char >(c)); 48cdf0e10cSrcweir if (n < 16) { 49cdf0e10cSrcweir buffer.append('0'); 50cdf0e10cSrcweir } 51cdf0e10cSrcweir buffer.append(n, 16); 52cdf0e10cSrcweir } else { 53cdf0e10cSrcweir buffer.append(c); 54cdf0e10cSrcweir } 55cdf0e10cSrcweir } 56cdf0e10cSrcweir buffer.append('"'); 57cdf0e10cSrcweir } 58cdf0e10cSrcweir 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61*fd5f88ecSDamjan Jovanovic 62*fd5f88ecSDamjan Jovanovic 63*fd5f88ecSDamjan Jovanovic namespace test { namespace oustring { 64*fd5f88ecSDamjan Jovanovic 65*fd5f88ecSDamjan Jovanovic class EndsWith: public ::testing::Test 66*fd5f88ecSDamjan Jovanovic { 67*fd5f88ecSDamjan Jovanovic }; 68*fd5f88ecSDamjan Jovanovic 69*fd5f88ecSDamjan Jovanovic TEST_F(EndsWith, endsWith) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir struct Data { 72cdf0e10cSrcweir char const * str1; 73cdf0e10cSrcweir sal_Int32 str1Len; 74cdf0e10cSrcweir char const * str2; 75cdf0e10cSrcweir sal_Int32 str2Len; 76cdf0e10cSrcweir bool endsWith; 77cdf0e10cSrcweir }; 78cdf0e10cSrcweir Data const data[] = { 79cdf0e10cSrcweir { RTL_CONSTASCII_STRINGPARAM(""), RTL_CONSTASCII_STRINGPARAM(""), 80cdf0e10cSrcweir true }, 81cdf0e10cSrcweir { RTL_CONSTASCII_STRINGPARAM("abc"), RTL_CONSTASCII_STRINGPARAM(""), 82cdf0e10cSrcweir true }, 83cdf0e10cSrcweir { RTL_CONSTASCII_STRINGPARAM(""), RTL_CONSTASCII_STRINGPARAM("abc"), 84cdf0e10cSrcweir false }, 85cdf0e10cSrcweir { RTL_CONSTASCII_STRINGPARAM("ABC"), RTL_CONSTASCII_STRINGPARAM("abc"), 86cdf0e10cSrcweir true }, 87cdf0e10cSrcweir { RTL_CONSTASCII_STRINGPARAM("abcd"), RTL_CONSTASCII_STRINGPARAM("bcd"), 88cdf0e10cSrcweir true }, 89cdf0e10cSrcweir { RTL_CONSTASCII_STRINGPARAM("bcd"), RTL_CONSTASCII_STRINGPARAM("abcd"), 90cdf0e10cSrcweir false }, 91cdf0e10cSrcweir { RTL_CONSTASCII_STRINGPARAM("a\0b\0c"), 92cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("b\0c"), true }, 93cdf0e10cSrcweir { RTL_CONSTASCII_STRINGPARAM("a\0b\0c"), 94cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("b"), false } }; 95cdf0e10cSrcweir for (int i = 0; i < sizeof data / sizeof data[0]; ++i) { 96cdf0e10cSrcweir rtl::OStringBuffer msg; 97cdf0e10cSrcweir appendString(msg, rtl::OString(data[i].str1, data[i].str1Len)); 98cdf0e10cSrcweir msg.append( 99cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM(".endsWithIgnoreAsciiCaseAsciiL(")); 100cdf0e10cSrcweir appendString(msg, rtl::OString(data[i].str2, data[i].str2Len)); 101cdf0e10cSrcweir msg.append(RTL_CONSTASCII_STRINGPARAM(") == ")); 102cdf0e10cSrcweir msg.append(static_cast< sal_Bool >(data[i].endsWith)); 103*fd5f88ecSDamjan Jovanovic ASSERT_TRUE( 104cdf0e10cSrcweir rtl::OUString( 105cdf0e10cSrcweir data[i].str1, data[i].str1Len, 106cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US).endsWithIgnoreAsciiCaseAsciiL( 107cdf0e10cSrcweir data[i].str2, data[i].str2Len) 108*fd5f88ecSDamjan Jovanovic == data[i].endsWith) << msg.getStr(); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir } 111*fd5f88ecSDamjan Jovanovic 112*fd5f88ecSDamjan Jovanovic } } 113