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 25cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 26cdf0e10cSrcweir #include "precompiled_sal.hxx" 27*1a7dd8bbSDamjan Jovanovic #include "gtest/gtest.h" 28*1a7dd8bbSDamjan Jovanovic #include <rtl/ustring.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir /** print a UNI_CODE file name. 31cdf0e10cSrcweir */ 32cdf0e10cSrcweir inline void printOUString( ::rtl::OUString const & _suStr ) 33cdf0e10cSrcweir { 34cdf0e10cSrcweir rtl::OString aString; 35cdf0e10cSrcweir 36*1a7dd8bbSDamjan Jovanovic printf( "OUString: " ); 37cdf0e10cSrcweir aString = ::rtl::OUStringToOString( _suStr, RTL_TEXTENCODING_ASCII_US ); 38*1a7dd8bbSDamjan Jovanovic printf( "%s\n", aString.getStr( ) ); 39cdf0e10cSrcweir } 40cdf0e10cSrcweir 41cdf0e10cSrcweir 42cdf0e10cSrcweir namespace rtl_ustr 43cdf0e10cSrcweir { 44cdf0e10cSrcweir 45*1a7dd8bbSDamjan Jovanovic class compare : public ::testing::Test 46cdf0e10cSrcweir { 47cdf0e10cSrcweir public: 48*1a7dd8bbSDamjan Jovanovic }; // class compare 49cdf0e10cSrcweir 50*1a7dd8bbSDamjan Jovanovic TEST_F(compare, compare_000) 51cdf0e10cSrcweir { 52cdf0e10cSrcweir rtl_ustr_compare( NULL, NULL); 53cdf0e10cSrcweir // should not GPF 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56*1a7dd8bbSDamjan Jovanovic TEST_F(compare, compare_000_1) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 59cdf0e10cSrcweir rtl_ustr_compare( aStr1.getStr(), NULL); 60cdf0e10cSrcweir // should not GPF 61cdf0e10cSrcweir } 62*1a7dd8bbSDamjan Jovanovic TEST_F(compare, compare_001) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir rtl::OUString aStr1; 65cdf0e10cSrcweir rtl::OUString aStr2; 66cdf0e10cSrcweir 67cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_compare( aStr1.getStr(), aStr2.getStr()); 68*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal."; 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71*1a7dd8bbSDamjan Jovanovic TEST_F(compare, compare_002) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 74cdf0e10cSrcweir rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line must be equal."); 75cdf0e10cSrcweir 76cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_compare( aStr1.getStr(), aStr2.getStr()); 77*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal."; 78cdf0e10cSrcweir } 79cdf0e10cSrcweir 80*1a7dd8bbSDamjan Jovanovic TEST_F(compare, compare_003) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ."); 83cdf0e10cSrcweir rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ."); 84cdf0e10cSrcweir 85cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_compare( aStr1.getStr(), aStr2.getStr()); 86*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue != 0) << "compare failed, strings differ."; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89*1a7dd8bbSDamjan Jovanovic class compareIgnoreAsciiCase : public ::testing::Test 90cdf0e10cSrcweir { 91cdf0e10cSrcweir public: 92*1a7dd8bbSDamjan Jovanovic }; // class compareIgnoreAsciiCase 93cdf0e10cSrcweir 94*1a7dd8bbSDamjan Jovanovic TEST_F(compareIgnoreAsciiCase, compare_000) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir rtl_ustr_compareIgnoreAsciiCase( NULL, NULL); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99*1a7dd8bbSDamjan Jovanovic TEST_F(compareIgnoreAsciiCase, compare_000_1) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 102cdf0e10cSrcweir rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), NULL); 103cdf0e10cSrcweir } 104*1a7dd8bbSDamjan Jovanovic TEST_F(compareIgnoreAsciiCase, compare_001) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir rtl::OUString aStr1; 107cdf0e10cSrcweir rtl::OUString aStr2; 108cdf0e10cSrcweir 109cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); 110*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal."; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113*1a7dd8bbSDamjan Jovanovic TEST_F(compareIgnoreAsciiCase, compare_002) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 116cdf0e10cSrcweir rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line must be equal."); 117cdf0e10cSrcweir 118cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); 119*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal."; 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122*1a7dd8bbSDamjan Jovanovic TEST_F(compareIgnoreAsciiCase, compare_002_1) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 125cdf0e10cSrcweir rtl::OUString aStr2 = rtl::OUString::createFromAscii("LINE MUST BE EQUAL."); 126cdf0e10cSrcweir 127cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); 128*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal (if case insensitve)."; 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131*1a7dd8bbSDamjan Jovanovic TEST_F(compareIgnoreAsciiCase, compare_003) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ."); 134cdf0e10cSrcweir rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ."); 135cdf0e10cSrcweir 136cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); 137*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue != 0) << "compare failed, strings differ."; 138cdf0e10cSrcweir } 139cdf0e10cSrcweir // ----------------------------------------------------------------------------- 140cdf0e10cSrcweir 141*1a7dd8bbSDamjan Jovanovic class shortenedCompareIgnoreAsciiCase_WithLength : public ::testing::Test 142cdf0e10cSrcweir { 143cdf0e10cSrcweir public: 144*1a7dd8bbSDamjan Jovanovic }; // class compare 145cdf0e10cSrcweir 146*1a7dd8bbSDamjan Jovanovic TEST_F(shortenedCompareIgnoreAsciiCase_WithLength, compare_000) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0, 0); 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151*1a7dd8bbSDamjan Jovanovic TEST_F(shortenedCompareIgnoreAsciiCase_WithLength, compare_000_1) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 154cdf0e10cSrcweir rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0, 1); 155cdf0e10cSrcweir } 156*1a7dd8bbSDamjan Jovanovic TEST_F(shortenedCompareIgnoreAsciiCase_WithLength, compare_001) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir rtl::OUString aStr1; 159cdf0e10cSrcweir rtl::OUString aStr2; 160cdf0e10cSrcweir 161cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), aStr2.getStr(), aStr2.getLength(), aStr1.getLength()); 162*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal."; 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165*1a7dd8bbSDamjan Jovanovic TEST_F(shortenedCompareIgnoreAsciiCase_WithLength, compare_002) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 168cdf0e10cSrcweir rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line must be equal."); 169cdf0e10cSrcweir 170cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), 171cdf0e10cSrcweir aStr2.getStr(), aStr2.getLength(), 172cdf0e10cSrcweir aStr1.getLength()); 173*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal."; 174cdf0e10cSrcweir } 175cdf0e10cSrcweir 176*1a7dd8bbSDamjan Jovanovic TEST_F(shortenedCompareIgnoreAsciiCase_WithLength, compare_002_1) 177cdf0e10cSrcweir { 178cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 179cdf0e10cSrcweir rtl::OUString aStr2 = rtl::OUString::createFromAscii("LINE MUST BE EQUAL."); 180cdf0e10cSrcweir 181cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), 182cdf0e10cSrcweir aStr2.getStr(), aStr2.getLength(), 183cdf0e10cSrcweir aStr1.getLength()); 184*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal (if case insensitve)."; 185cdf0e10cSrcweir } 186cdf0e10cSrcweir 187*1a7dd8bbSDamjan Jovanovic TEST_F(shortenedCompareIgnoreAsciiCase_WithLength, compare_003) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ."); 190cdf0e10cSrcweir rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ."); 191cdf0e10cSrcweir 192cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), 193cdf0e10cSrcweir aStr2.getStr(), aStr2.getLength(), 194cdf0e10cSrcweir 5); 195*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal first 5 characters."; 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198*1a7dd8bbSDamjan Jovanovic TEST_F(shortenedCompareIgnoreAsciiCase_WithLength, compare_004) 199cdf0e10cSrcweir { 200cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ."); 201cdf0e10cSrcweir rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ."); 202cdf0e10cSrcweir 203cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), 204cdf0e10cSrcweir aStr2.getStr(), aStr2.getLength(), 205cdf0e10cSrcweir aStr1.getLength()); 206*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue != 0) << "compare failed, strings differ."; 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir // // ----------------------------------------------------------------------------- 210cdf0e10cSrcweir // 211*1a7dd8bbSDamjan Jovanovic // class hashCode : public ::testing::Test 212cdf0e10cSrcweir // { 213cdf0e10cSrcweir // public: 214*1a7dd8bbSDamjan Jovanovic // }; 215cdf0e10cSrcweir // 216*1a7dd8bbSDamjan Jovanovic // TEST_F(hashCode, hashCode_000) 217cdf0e10cSrcweir // { 218cdf0e10cSrcweir // sal_Int32 nHashCode = rtl_ustr_hashCode( NULL ); 219cdf0e10cSrcweir // volatile int dummy = 0; 220cdf0e10cSrcweir // } 221cdf0e10cSrcweir // 222*1a7dd8bbSDamjan Jovanovic // TEST_F(hashCode, hashCode_001) 223cdf0e10cSrcweir // { 224cdf0e10cSrcweir // rtl::OString aStr1 = "Line for a hashCode."; 225cdf0e10cSrcweir // sal_Int32 nHashCode = rtl_ustr_hashCode( aStr1.getStr() ); 226*1a7dd8bbSDamjan Jovanovic // printf("hashcode: %d\n", nHashCode); 227*1a7dd8bbSDamjan Jovanovic // // ASSERT_TRUE(nValue == 0) << "failed."; 228cdf0e10cSrcweir // } 229cdf0e10cSrcweir // 230*1a7dd8bbSDamjan Jovanovic // TEST_F(hashCode, hashCode_002) 231cdf0e10cSrcweir // { 232cdf0e10cSrcweir // rtl::OString aStr1 = "Line for a hashCode."; 233cdf0e10cSrcweir // sal_Int32 nHashCode1 = rtl_ustr_hashCode( aStr1.getStr() ); 234cdf0e10cSrcweir // 235cdf0e10cSrcweir // rtl::OString aStr2 = "Line for a hashCode."; 236cdf0e10cSrcweir // sal_Int32 nHashCode2 = rtl_ustr_hashCode( aStr2.getStr() ); 237cdf0e10cSrcweir // 238*1a7dd8bbSDamjan Jovanovic // ASSERT_TRUE(nHashCode1 == nHashCode2) << "hashcodes must be equal."; 239cdf0e10cSrcweir // } 240cdf0e10cSrcweir // 241*1a7dd8bbSDamjan Jovanovic // TEST_F(hashCode, hashCode_003) 242cdf0e10cSrcweir // { 243cdf0e10cSrcweir // rtl::OString aStr1 = "Line for a hashCode."; 244cdf0e10cSrcweir // sal_Int32 nHashCode1 = rtl_ustr_hashCode( aStr1.getStr() ); 245cdf0e10cSrcweir // 246cdf0e10cSrcweir // rtl::OString aStr2 = "Line for an other hashcode."; 247cdf0e10cSrcweir // sal_Int32 nHashCode2 = rtl_ustr_hashCode( aStr2.getStr() ); 248cdf0e10cSrcweir // 249*1a7dd8bbSDamjan Jovanovic // ASSERT_TRUE(nHashCode1 != nHashCode2) << "hashcodes must differ."; 250cdf0e10cSrcweir // } 251cdf0e10cSrcweir // 252cdf0e10cSrcweir // 253cdf0e10cSrcweir // // ----------------------------------------------------------------------------- 254cdf0e10cSrcweir // 255*1a7dd8bbSDamjan Jovanovic class indexOfChar : public ::testing::Test 256cdf0e10cSrcweir { 257cdf0e10cSrcweir public: 258*1a7dd8bbSDamjan Jovanovic }; // class indexOfChar 259cdf0e10cSrcweir 260*1a7dd8bbSDamjan Jovanovic TEST_F(indexOfChar, indexOfChar_000) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir rtl_ustr_indexOfChar( NULL, 0 ); 263cdf0e10cSrcweir } 264cdf0e10cSrcweir 265*1a7dd8bbSDamjan Jovanovic TEST_F(indexOfChar, indexOfChar_001) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfChar."); 268cdf0e10cSrcweir 269cdf0e10cSrcweir sal_Int32 nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'L' ); 270*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == 0) << "index is wrong."; 271cdf0e10cSrcweir 272cdf0e10cSrcweir /* sal_Int32 */ nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'i' ); 273*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == 1) << "index is wrong."; 274cdf0e10cSrcweir 275cdf0e10cSrcweir /* sal_Int32 */ nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'n' ); 276*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == 2) << "index is wrong."; 277cdf0e10cSrcweir 278cdf0e10cSrcweir /* sal_Int32 */ nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'e' ); 279*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == 3) << "index is wrong."; 280cdf0e10cSrcweir } 281cdf0e10cSrcweir 282*1a7dd8bbSDamjan Jovanovic TEST_F(indexOfChar, indexOfChar_002) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfChar."); 285cdf0e10cSrcweir sal_Int32 nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'y' ); 286cdf0e10cSrcweir 287*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == -1) << "index is wrong."; 288cdf0e10cSrcweir } 289cdf0e10cSrcweir 290cdf0e10cSrcweir // // ----------------------------------------------------------------------------- 291*1a7dd8bbSDamjan Jovanovic class lastIndexOfChar : public ::testing::Test 292cdf0e10cSrcweir { 293cdf0e10cSrcweir public: 294*1a7dd8bbSDamjan Jovanovic }; // class lastIndexOfChar 295cdf0e10cSrcweir 296*1a7dd8bbSDamjan Jovanovic TEST_F(lastIndexOfChar, lastIndexOfChar_000) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir rtl_ustr_lastIndexOfChar( NULL, 0 ); 299cdf0e10cSrcweir } 300cdf0e10cSrcweir 301*1a7dd8bbSDamjan Jovanovic TEST_F(lastIndexOfChar, lastIndexOfChar_001) 302cdf0e10cSrcweir { 303cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfChar."); 304cdf0e10cSrcweir 305cdf0e10cSrcweir sal_Int32 nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'C' ); 306*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == 22) << "index is wrong."; 307cdf0e10cSrcweir 308cdf0e10cSrcweir /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'h' ); 309*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == 23) << "index is wrong."; 310cdf0e10cSrcweir 311cdf0e10cSrcweir /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'a' ); 312*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == 24) << "index is wrong."; 313cdf0e10cSrcweir 314cdf0e10cSrcweir /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'r' ); 315*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == 25) << "index is wrong."; 316cdf0e10cSrcweir } 317cdf0e10cSrcweir 318*1a7dd8bbSDamjan Jovanovic TEST_F(lastIndexOfChar, lastIndexOfChar_002) 319cdf0e10cSrcweir { 320cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfChar."); 321cdf0e10cSrcweir sal_Int32 nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'y' ); 322cdf0e10cSrcweir 323*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == -1) << "index is wrong."; 324cdf0e10cSrcweir } 325cdf0e10cSrcweir 326cdf0e10cSrcweir // ----------------------------------------------------------------------------- 327cdf0e10cSrcweir 328*1a7dd8bbSDamjan Jovanovic class indexOfStr : public ::testing::Test 329cdf0e10cSrcweir { 330cdf0e10cSrcweir public: 331*1a7dd8bbSDamjan Jovanovic }; // class compare 332cdf0e10cSrcweir 333*1a7dd8bbSDamjan Jovanovic TEST_F(indexOfStr, indexOfStr_000) 334cdf0e10cSrcweir { 335cdf0e10cSrcweir rtl_ustr_indexOfStr( NULL, 0 ); 336cdf0e10cSrcweir } 337cdf0e10cSrcweir 338*1a7dd8bbSDamjan Jovanovic TEST_F(indexOfStr, indexOfStr_000_1) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfStr."); 341cdf0e10cSrcweir rtl_ustr_indexOfStr( aStr1.getStr(), 0 ); 342cdf0e10cSrcweir } 343cdf0e10cSrcweir 344*1a7dd8bbSDamjan Jovanovic TEST_F(indexOfStr, indexOfStr_001) 345cdf0e10cSrcweir { 346cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfStr."); 347cdf0e10cSrcweir 348cdf0e10cSrcweir rtl::OUString suSearch = rtl::OUString::createFromAscii("Line"); 349*1a7dd8bbSDamjan Jovanovic sal_Int32 nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch.getStr() ); 350*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == 0) << "index is wrong."; 351cdf0e10cSrcweir 352cdf0e10cSrcweir /* rtl::OUString */ suSearch = rtl::OUString::createFromAscii("for"); 353*1a7dd8bbSDamjan Jovanovic /* sal_Int32 */ nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch.getStr() ); 354*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == 5) << "index is wrong."; 355cdf0e10cSrcweir 356cdf0e10cSrcweir /* rtl::OUString */ suSearch = rtl::OUString::createFromAscii("a"); 357*1a7dd8bbSDamjan Jovanovic /* sal_Int32 */ nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch.getStr() ); 358*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == 9) << "index is wrong."; 359cdf0e10cSrcweir 360cdf0e10cSrcweir /* rtl::OUString */ suSearch = rtl::OUString::createFromAscii("a index"); 361*1a7dd8bbSDamjan Jovanovic /* sal_Int32 */ nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch.getStr() ); 362*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex ==9) << "index is wrong."; 363cdf0e10cSrcweir } 364cdf0e10cSrcweir 365*1a7dd8bbSDamjan Jovanovic TEST_F(indexOfStr, indexOfStr_002) 366cdf0e10cSrcweir { 367cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfStr."); 368cdf0e10cSrcweir rtl::OUString suSearch = rtl::OUString::createFromAscii("not exist"); 369*1a7dd8bbSDamjan Jovanovic sal_Int32 nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch.getStr() ); 370cdf0e10cSrcweir 371*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == -1) << "index is wrong."; 372cdf0e10cSrcweir } 373cdf0e10cSrcweir 374cdf0e10cSrcweir // ----------------------------------------------------------------------------- 375cdf0e10cSrcweir 376cdf0e10cSrcweir 377*1a7dd8bbSDamjan Jovanovic class lastIndexOfStr : public ::testing::Test 378cdf0e10cSrcweir { 379cdf0e10cSrcweir public: 380*1a7dd8bbSDamjan Jovanovic }; // class lastIndexOfStr 381cdf0e10cSrcweir 382*1a7dd8bbSDamjan Jovanovic TEST_F(lastIndexOfStr, lastIndexOfStr_000) 383cdf0e10cSrcweir { 384cdf0e10cSrcweir rtl_ustr_lastIndexOfStr( NULL, NULL ); 385cdf0e10cSrcweir } 386cdf0e10cSrcweir 387*1a7dd8bbSDamjan Jovanovic TEST_F(lastIndexOfStr, lastIndexOfStr_000_1) 388cdf0e10cSrcweir { 389cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr."); 390cdf0e10cSrcweir rtl_ustr_lastIndexOfStr( aStr1.getStr(), NULL ); 391cdf0e10cSrcweir } 392cdf0e10cSrcweir 393*1a7dd8bbSDamjan Jovanovic TEST_F(lastIndexOfStr, lastIndexOfStr_001) 394cdf0e10cSrcweir { 395cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr."); 396cdf0e10cSrcweir rtl::OUString aSearchStr = rtl::OUString::createFromAscii("Index"); 397cdf0e10cSrcweir 398cdf0e10cSrcweir sal_Int32 nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); 399*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == 15) << "index is wrong."; 400cdf0e10cSrcweir 401cdf0e10cSrcweir /* rtl::OString */ aSearchStr = rtl::OUString::createFromAscii("Line"); 402cdf0e10cSrcweir /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); 403*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == 0) << "index is wrong."; 404cdf0e10cSrcweir 405cdf0e10cSrcweir /* rtl::OString */ aSearchStr = rtl::OUString::createFromAscii(""); 406cdf0e10cSrcweir /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); 407*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == -1) << "index is wrong."; 408cdf0e10cSrcweir } 409cdf0e10cSrcweir 410*1a7dd8bbSDamjan Jovanovic TEST_F(lastIndexOfStr, lastIndexOfStr_002) 411cdf0e10cSrcweir { 412cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr."); 413cdf0e10cSrcweir rtl::OUString aSearchStr = rtl::OUString::createFromAscii("foo"); 414cdf0e10cSrcweir sal_Int32 nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); 415cdf0e10cSrcweir 416*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == -1) << "index is wrong."; 417cdf0e10cSrcweir } 418cdf0e10cSrcweir 419*1a7dd8bbSDamjan Jovanovic TEST_F(lastIndexOfStr, lastIndexOfStr_003) 420cdf0e10cSrcweir { 421cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr."); 422cdf0e10cSrcweir rtl::OUString aSearchStr = rtl::OUString::createFromAscii("O"); 423cdf0e10cSrcweir sal_Int32 nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); 424cdf0e10cSrcweir 425*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nIndex == 20) << "index is wrong."; 426cdf0e10cSrcweir } 427cdf0e10cSrcweir 428cdf0e10cSrcweir // ----------------------------------------------------------------------------- 429cdf0e10cSrcweir 430*1a7dd8bbSDamjan Jovanovic class replaceChar : public ::testing::Test 431cdf0e10cSrcweir { 432cdf0e10cSrcweir public: 433*1a7dd8bbSDamjan Jovanovic }; // class replaceChar 434cdf0e10cSrcweir 435*1a7dd8bbSDamjan Jovanovic TEST_F(replaceChar, replaceChar_000) 436cdf0e10cSrcweir { 437cdf0e10cSrcweir rtl_ustr_replaceChar( NULL, 0, 0 ); 438cdf0e10cSrcweir } 439cdf0e10cSrcweir 440*1a7dd8bbSDamjan Jovanovic TEST_F(replaceChar, replaceChar_001) 441cdf0e10cSrcweir { 442cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("replace char."); 443cdf0e10cSrcweir rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("ruplacu char."); 444cdf0e10cSrcweir 445cdf0e10cSrcweir sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode); 446cdf0e10cSrcweir sal_Unicode* pStr = (sal_Unicode*) malloc( nLength + sizeof(sal_Unicode)); // length + 1 (null terminator) 447*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(pStr != NULL) << "can't get memory for test"; 448cdf0e10cSrcweir memset(pStr, 0, nLength + sizeof(sal_Unicode)); 449cdf0e10cSrcweir memcpy(pStr, aStr1.getStr(), nLength); 450cdf0e10cSrcweir 451cdf0e10cSrcweir rtl_ustr_replaceChar( pStr, 'e', 'u' ); 452cdf0e10cSrcweir rtl::OUString suStr(pStr, aStr1.getLength()); 453cdf0e10cSrcweir 454*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(aShouldStr1.equals(suStr) == sal_True) << "replace failed"; 455cdf0e10cSrcweir free(pStr); 456cdf0e10cSrcweir } 457cdf0e10cSrcweir 458cdf0e10cSrcweir // ----------------------------------------------------------------------------- 459cdf0e10cSrcweir 460*1a7dd8bbSDamjan Jovanovic class replaceChar_WithLength : public ::testing::Test 461cdf0e10cSrcweir { 462cdf0e10cSrcweir public: 463*1a7dd8bbSDamjan Jovanovic }; // class replaceChar 464cdf0e10cSrcweir 465*1a7dd8bbSDamjan Jovanovic TEST_F(replaceChar_WithLength, replaceChar_WithLength_000) 466cdf0e10cSrcweir { 467cdf0e10cSrcweir rtl_ustr_replaceChar_WithLength( NULL, 0, 0, 0 ); 468cdf0e10cSrcweir } 469cdf0e10cSrcweir 470*1a7dd8bbSDamjan Jovanovic TEST_F(replaceChar_WithLength, replaceChar_WithLength_000_1) 471cdf0e10cSrcweir { 472cdf0e10cSrcweir rtl_ustr_replaceChar_WithLength( NULL, 1, 0, 0 ); 473cdf0e10cSrcweir } 474*1a7dd8bbSDamjan Jovanovic TEST_F(replaceChar_WithLength, replaceChar_WithLength_001) 475cdf0e10cSrcweir { 476cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("replace char."); 477cdf0e10cSrcweir rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("ruplace char."); 478cdf0e10cSrcweir 479cdf0e10cSrcweir sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode); 480cdf0e10cSrcweir sal_Unicode* pStr = (sal_Unicode*) malloc(nLength); 481*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(pStr != NULL) << "can't get memory for test"; 482cdf0e10cSrcweir memcpy(pStr, aStr1.getStr(), nLength); 483cdf0e10cSrcweir 484cdf0e10cSrcweir rtl_ustr_replaceChar_WithLength( pStr, 6, 'e', 'u' ); 485cdf0e10cSrcweir rtl::OUString suStr(pStr, aStr1.getLength()); 486cdf0e10cSrcweir 487*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(aShouldStr1.equals(suStr) == sal_True) << "replace failed"; 488cdf0e10cSrcweir free(pStr); 489cdf0e10cSrcweir } 490cdf0e10cSrcweir 491*1a7dd8bbSDamjan Jovanovic TEST_F(replaceChar_WithLength, replaceChar_WithLength_002) 492cdf0e10cSrcweir { 493cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("eeeeeeeeeeeee"); 494cdf0e10cSrcweir rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("uuuuuueeeeeee"); 495cdf0e10cSrcweir 496cdf0e10cSrcweir sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode); 497cdf0e10cSrcweir sal_Unicode* pStr = (sal_Unicode*) malloc(nLength); // no null terminator is need 498*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(pStr != NULL) << "can't get memory for test"; 499cdf0e10cSrcweir memcpy(pStr, aStr1.getStr(), nLength); 500cdf0e10cSrcweir 501cdf0e10cSrcweir rtl_ustr_replaceChar_WithLength( pStr, 6, 'e', 'u' ); 502cdf0e10cSrcweir rtl::OUString suStr(pStr, aStr1.getLength()); 503cdf0e10cSrcweir 504*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(aShouldStr1.equals(suStr) == sal_True) << "replace failed"; 505cdf0e10cSrcweir free(pStr); 506cdf0e10cSrcweir } 507cdf0e10cSrcweir 508cdf0e10cSrcweir // ----------------------------------------------------------------------------- 509cdf0e10cSrcweir 510*1a7dd8bbSDamjan Jovanovic class toAsciiLowerCase : public ::testing::Test 511cdf0e10cSrcweir { 512cdf0e10cSrcweir public: 513*1a7dd8bbSDamjan Jovanovic }; // class replaceChar 514cdf0e10cSrcweir 515*1a7dd8bbSDamjan Jovanovic TEST_F(toAsciiLowerCase, toAsciiLowerCase_000) 516cdf0e10cSrcweir { 517cdf0e10cSrcweir rtl_ustr_toAsciiLowerCase( NULL ); 518cdf0e10cSrcweir } 519cdf0e10cSrcweir 520*1a7dd8bbSDamjan Jovanovic TEST_F(toAsciiLowerCase, toAsciiLowerCase_001) 521cdf0e10cSrcweir { 522cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII LOWER CASE."); 523cdf0e10cSrcweir rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("change this to ascii lower case."); 524cdf0e10cSrcweir 525cdf0e10cSrcweir sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode); 526cdf0e10cSrcweir sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode) ); // we need to add '\0' so one more 527*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(pStr != NULL) << "can't get memory for test"; 528cdf0e10cSrcweir memset(pStr, 0, nLength + sizeof(sal_Unicode)); // empty the sal_Unicode array 529cdf0e10cSrcweir memcpy(pStr, aStr1.getStr(), nLength); 530cdf0e10cSrcweir 531cdf0e10cSrcweir rtl_ustr_toAsciiLowerCase( pStr ); 532cdf0e10cSrcweir rtl::OUString suStr(pStr, aStr1.getLength()); 533cdf0e10cSrcweir 534*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(aShouldStr1.equals(suStr) == sal_True) << "failed"; 535cdf0e10cSrcweir free(pStr); 536cdf0e10cSrcweir } 537cdf0e10cSrcweir 538*1a7dd8bbSDamjan Jovanovic class toAsciiLowerCase_WithLength : public ::testing::Test 539*1a7dd8bbSDamjan Jovanovic { 540cdf0e10cSrcweir }; // class replaceChar 541cdf0e10cSrcweir 542*1a7dd8bbSDamjan Jovanovic TEST_F(toAsciiLowerCase, toAsciiLowerCase_WithLength_000) 543cdf0e10cSrcweir { 544cdf0e10cSrcweir rtl_ustr_toAsciiLowerCase_WithLength( NULL, 0 ); 545cdf0e10cSrcweir } 546cdf0e10cSrcweir 547*1a7dd8bbSDamjan Jovanovic TEST_F(toAsciiLowerCase, toAsciiLowerCase_WithLength_001) 548cdf0e10cSrcweir { 549cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII LOWER CASE."); 550cdf0e10cSrcweir rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("change thiS TO ASCII LOWER CASE."); 551cdf0e10cSrcweir 552cdf0e10cSrcweir sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode); 553cdf0e10cSrcweir sal_Unicode* pStr = (sal_Unicode*) malloc(nLength); 554*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(pStr != NULL) << "can't get memory for test"; 555cdf0e10cSrcweir memcpy(pStr, aStr1.getStr(), nLength); 556cdf0e10cSrcweir 557cdf0e10cSrcweir rtl_ustr_toAsciiLowerCase_WithLength( pStr, 10 ); 558cdf0e10cSrcweir 559cdf0e10cSrcweir rtl::OUString suStr(pStr, aStr1.getLength()); 560cdf0e10cSrcweir sal_Bool bResult = aShouldStr1.equals(suStr); 561cdf0e10cSrcweir 562cdf0e10cSrcweir printOUString(suStr); 563*1a7dd8bbSDamjan Jovanovic printf("Result length: %d\n", suStr.getLength() ); 564*1a7dd8bbSDamjan Jovanovic printf("Result: %d\n", bResult); 565cdf0e10cSrcweir 566*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(bResult == sal_True) << "failed"; 567cdf0e10cSrcweir free(pStr); 568cdf0e10cSrcweir } 569cdf0e10cSrcweir 570cdf0e10cSrcweir // ----------------------------------------------------------------------------- 571cdf0e10cSrcweir 572*1a7dd8bbSDamjan Jovanovic class toAsciiUpperCase : public ::testing::Test 573cdf0e10cSrcweir { 574cdf0e10cSrcweir public: 575*1a7dd8bbSDamjan Jovanovic }; // class replaceChar 576cdf0e10cSrcweir 577*1a7dd8bbSDamjan Jovanovic TEST_F(toAsciiUpperCase, toAsciiUpperCase_000) 578cdf0e10cSrcweir { 579cdf0e10cSrcweir rtl_ustr_toAsciiUpperCase( NULL ); 580cdf0e10cSrcweir } 581cdf0e10cSrcweir 582*1a7dd8bbSDamjan Jovanovic TEST_F(toAsciiUpperCase, toAsciiUpperCase_001) 583cdf0e10cSrcweir { 584cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("change this to ascii upper case."); 585cdf0e10cSrcweir rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII UPPER CASE."); 586cdf0e10cSrcweir 587cdf0e10cSrcweir sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode); 588cdf0e10cSrcweir sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode)); // length + null terminator 589*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(pStr != NULL) << "can't get memory for test"; 590cdf0e10cSrcweir memset(pStr, 0, nLength + sizeof(sal_Unicode)); 591cdf0e10cSrcweir memcpy(pStr, aStr1.getStr(), nLength); 592cdf0e10cSrcweir 593cdf0e10cSrcweir rtl_ustr_toAsciiUpperCase( pStr ); 594cdf0e10cSrcweir rtl::OUString suStr(pStr, aStr1.getLength()); 595cdf0e10cSrcweir 596*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(aShouldStr1.equals(suStr) == sal_True) << "failed"; 597cdf0e10cSrcweir free(pStr); 598cdf0e10cSrcweir } 599cdf0e10cSrcweir 600*1a7dd8bbSDamjan Jovanovic class toAsciiUpperCase_WithLength : public ::testing::Test 601cdf0e10cSrcweir { 602cdf0e10cSrcweir public: 603*1a7dd8bbSDamjan Jovanovic }; // class replaceChar 604cdf0e10cSrcweir 605*1a7dd8bbSDamjan Jovanovic TEST_F(toAsciiUpperCase_WithLength, toAsciiUpperCase_WithLength_000) 606cdf0e10cSrcweir { 607cdf0e10cSrcweir rtl_ustr_toAsciiUpperCase_WithLength( NULL, 0 ); 608cdf0e10cSrcweir } 609cdf0e10cSrcweir 610*1a7dd8bbSDamjan Jovanovic TEST_F(toAsciiUpperCase_WithLength, toAsciiUpperCase_WithLength_001) 611cdf0e10cSrcweir { 612cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("change this to ascii lower case."); 613cdf0e10cSrcweir rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("CHANGE THIs to ascii lower case."); 614cdf0e10cSrcweir 615cdf0e10cSrcweir sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode); 616cdf0e10cSrcweir sal_Unicode* pStr = (sal_Unicode*) malloc(nLength); 617*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(pStr != NULL) << "can't get memory for test"; 618cdf0e10cSrcweir 619cdf0e10cSrcweir memcpy(pStr, aStr1.getStr(), nLength); 620cdf0e10cSrcweir rtl_ustr_toAsciiUpperCase_WithLength( pStr, 10 ); 621cdf0e10cSrcweir rtl::OUString suStr(pStr, aStr1.getLength()); 622cdf0e10cSrcweir 623*1a7dd8bbSDamjan Jovanovic // printf("Uppercase with length: '%s'\n", aStr1.getStr()); 624*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(aShouldStr1.equals(suStr) == sal_True) << "failed"; 625cdf0e10cSrcweir free(pStr); 626cdf0e10cSrcweir } 627cdf0e10cSrcweir 628cdf0e10cSrcweir // ----------------------------------------------------------------------------- 629cdf0e10cSrcweir 630*1a7dd8bbSDamjan Jovanovic class trim_WithLength : public ::testing::Test 631cdf0e10cSrcweir { 632cdf0e10cSrcweir public: 633*1a7dd8bbSDamjan Jovanovic }; 634*1a7dd8bbSDamjan Jovanovic 635*1a7dd8bbSDamjan Jovanovic TEST_F(trim_WithLength, trim_WithLength_000) 636cdf0e10cSrcweir { 637cdf0e10cSrcweir rtl_ustr_trim_WithLength(NULL, 0); 638cdf0e10cSrcweir // should not GPF 639cdf0e10cSrcweir } 640cdf0e10cSrcweir 641*1a7dd8bbSDamjan Jovanovic TEST_F(trim_WithLength, trim_WithLength_000_1) 642cdf0e10cSrcweir { 643cdf0e10cSrcweir rtl::OUString suStr = rtl::OUString::createFromAscii(" trim this"); 644cdf0e10cSrcweir 645cdf0e10cSrcweir sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode); 646cdf0e10cSrcweir sal_Unicode *pStr = (sal_Unicode*)malloc(nLength); 647cdf0e10cSrcweir memcpy(pStr, suStr.getStr(), nLength); 648cdf0e10cSrcweir 649cdf0e10cSrcweir rtl_ustr_trim_WithLength( pStr, 0 ); 650cdf0e10cSrcweir free(pStr); 651cdf0e10cSrcweir } 652cdf0e10cSrcweir 653*1a7dd8bbSDamjan Jovanovic TEST_F(trim_WithLength, trim_WithLength_001) 654cdf0e10cSrcweir { 655cdf0e10cSrcweir rtl::OUString suStr = rtl::OUString::createFromAscii(" trim this"); 656cdf0e10cSrcweir sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode); 657cdf0e10cSrcweir sal_Unicode *pStr = (sal_Unicode*)malloc(nLength); 658cdf0e10cSrcweir memcpy(pStr, suStr.getStr(), nLength); 659cdf0e10cSrcweir 660cdf0e10cSrcweir rtl_ustr_trim_WithLength( pStr, 2 ); 661cdf0e10cSrcweir 662*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(rtl::OUString(pStr).getLength() == 0) << "string should be empty"; 663cdf0e10cSrcweir free(pStr); 664cdf0e10cSrcweir } 665cdf0e10cSrcweir 666cdf0e10cSrcweir 667*1a7dd8bbSDamjan Jovanovic TEST_F(trim_WithLength, trim_WithLength_002) 668cdf0e10cSrcweir { 669cdf0e10cSrcweir rtl::OUString suStr = rtl::OUString::createFromAscii("trim this"); 670cdf0e10cSrcweir 671cdf0e10cSrcweir sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode); 672cdf0e10cSrcweir sal_Unicode *pStr = (sal_Unicode*)malloc(nLength); 673cdf0e10cSrcweir memcpy(pStr, suStr.getStr(), nLength); 674cdf0e10cSrcweir 675cdf0e10cSrcweir rtl_ustr_trim_WithLength( pStr, 5 ); 676cdf0e10cSrcweir 677*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(rtl::OUString(pStr).getLength() == 4) << "string should contain 'trim'"; 678cdf0e10cSrcweir free(pStr); 679cdf0e10cSrcweir } 680cdf0e10cSrcweir 681cdf0e10cSrcweir 682*1a7dd8bbSDamjan Jovanovic TEST_F(trim_WithLength, trim_WithLength_003) 683cdf0e10cSrcweir { 684cdf0e10cSrcweir rtl::OUString suStr = rtl::OUString::createFromAscii(" trim this"); 685cdf0e10cSrcweir 686cdf0e10cSrcweir sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode); 687cdf0e10cSrcweir sal_Unicode *pStr = (sal_Unicode*)malloc(nLength); 688cdf0e10cSrcweir memcpy(pStr, suStr.getStr(), nLength); 689cdf0e10cSrcweir 690cdf0e10cSrcweir rtl_ustr_trim_WithLength( pStr, 11 ); 691cdf0e10cSrcweir 692*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(rtl::OUString(pStr).getLength() == 4) << "string should contain 'trim'"; 693cdf0e10cSrcweir free(pStr); 694cdf0e10cSrcweir } 695cdf0e10cSrcweir 696*1a7dd8bbSDamjan Jovanovic TEST_F(trim_WithLength, trim_WithLength_004) 697cdf0e10cSrcweir { 698cdf0e10cSrcweir rtl::OUString suStr = rtl::OUString::createFromAscii("\r\n\t \n\r trim \n this"); 699cdf0e10cSrcweir 700cdf0e10cSrcweir sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode); 701cdf0e10cSrcweir sal_Unicode *pStr = (sal_Unicode*)malloc(nLength); 702cdf0e10cSrcweir memcpy(pStr, suStr.getStr(), nLength); 703cdf0e10cSrcweir 704cdf0e10cSrcweir rtl_ustr_trim_WithLength( pStr, 17 ); 705cdf0e10cSrcweir 706*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(rtl::OUString(pStr).getLength() == 4) << "string should contain 'trim'"; 707cdf0e10cSrcweir free(pStr); 708cdf0e10cSrcweir } 709cdf0e10cSrcweir 710*1a7dd8bbSDamjan Jovanovic TEST_F(trim_WithLength, trim_WithLength_005) 711cdf0e10cSrcweir { 712cdf0e10cSrcweir rtl::OUString suStr = rtl::OUString::createFromAscii("\r\n\t \n\r trim \t this \n\r\t\t "); 713cdf0e10cSrcweir 714cdf0e10cSrcweir sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode); 715cdf0e10cSrcweir sal_Unicode *pStr = (sal_Unicode*)malloc(nLength); 716cdf0e10cSrcweir memcpy(pStr, suStr.getStr(), nLength); 717cdf0e10cSrcweir 718cdf0e10cSrcweir rtl_ustr_trim_WithLength( pStr, suStr.getLength() ); 719cdf0e10cSrcweir 720*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(rtl::OUString(pStr).getLength() == 11) << "string should contain 'trim \\t this'"; 721cdf0e10cSrcweir free(pStr); 722cdf0e10cSrcweir } 723cdf0e10cSrcweir 724cdf0e10cSrcweir // ----------------------------------------------------------------------------- 725cdf0e10cSrcweir 726*1a7dd8bbSDamjan Jovanovic class valueOfChar : public ::testing::Test 727cdf0e10cSrcweir { 728cdf0e10cSrcweir public: 729*1a7dd8bbSDamjan Jovanovic }; 730*1a7dd8bbSDamjan Jovanovic 731*1a7dd8bbSDamjan Jovanovic TEST_F(valueOfChar, valueOfChar_000) 732cdf0e10cSrcweir { 733cdf0e10cSrcweir rtl_ustr_valueOfChar(NULL, 0); 734cdf0e10cSrcweir // should not GPF 735cdf0e10cSrcweir } 736*1a7dd8bbSDamjan Jovanovic TEST_F(valueOfChar, valueOfChar_001) 737cdf0e10cSrcweir { 738cdf0e10cSrcweir sal_Unicode *pStr = (sal_Unicode*)malloc(RTL_USTR_MAX_VALUEOFCHAR); 739cdf0e10cSrcweir if (pStr) 740cdf0e10cSrcweir { 741cdf0e10cSrcweir rtl_ustr_valueOfChar(pStr, 'A'); 742cdf0e10cSrcweir 743*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(pStr[0] == L'A') << "string should contain 'A'"; 744cdf0e10cSrcweir free(pStr); 745cdf0e10cSrcweir } 746cdf0e10cSrcweir } 747cdf0e10cSrcweir 748cdf0e10cSrcweir 749*1a7dd8bbSDamjan Jovanovic class ascii_compare_WithLength : public ::testing::Test 750cdf0e10cSrcweir { 751cdf0e10cSrcweir public: 752*1a7dd8bbSDamjan Jovanovic }; 753*1a7dd8bbSDamjan Jovanovic 754*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compare_WithLength, zero_length) 755cdf0e10cSrcweir { 756cdf0e10cSrcweir sal_Unicode pUnicode[] = {0xffff, 0xffff}; 757cdf0e10cSrcweir char const * pAscii = "reference"; 758cdf0e10cSrcweir 759cdf0e10cSrcweir sal_Int32 value = rtl_ustr_ascii_compare_WithLength(pUnicode, 0, pAscii); 760*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(value < 0) << "ref string is empty, compare failed, needs to be <0."; 761cdf0e10cSrcweir } 762cdf0e10cSrcweir 763*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compare_WithLength, equal_ascii_shorter) 764cdf0e10cSrcweir { 765cdf0e10cSrcweir rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("referenceString")); 766cdf0e10cSrcweir char const * pAscii = "reference"; 767cdf0e10cSrcweir 768cdf0e10cSrcweir sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii); 769*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(value > 0) << "ref string is bigger, compare failed, needs to be >0."; 770cdf0e10cSrcweir } 771cdf0e10cSrcweir 772*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compare_WithLength, equal_ascii_shorter_asciiLength) 773cdf0e10cSrcweir { 774cdf0e10cSrcweir rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("referenceString")); 775cdf0e10cSrcweir char const * pAscii = "reference"; 776cdf0e10cSrcweir 777cdf0e10cSrcweir sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, rtl_str_getLength(pAscii), pAscii); 778*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(value == 0) << "ref string is bigger despite ascii length, compare failed, needs to be == 0."; 779cdf0e10cSrcweir } 780cdf0e10cSrcweir 781*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compare_WithLength, equal_ref_shorter) 782cdf0e10cSrcweir { 783cdf0e10cSrcweir rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("reference")); 784cdf0e10cSrcweir char const * pAscii = "referenceString"; 785cdf0e10cSrcweir 786cdf0e10cSrcweir sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii); 787*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(value < 0) << "ascii string is bigger, but only compared to ref length, needs to be 0."; 788cdf0e10cSrcweir } 789cdf0e10cSrcweir 790*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compare_WithLength, equal) 791cdf0e10cSrcweir { 792cdf0e10cSrcweir rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("reference")); 793cdf0e10cSrcweir char const * pAscii = "reference"; 794cdf0e10cSrcweir 795cdf0e10cSrcweir sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii); 796*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(value == 0) << "strings are equal, compare failed, needs to be 0."; 797cdf0e10cSrcweir } 798cdf0e10cSrcweir 799*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compare_WithLength, unequal_reference_bigger) 800cdf0e10cSrcweir { 801cdf0e10cSrcweir rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("defghi")); 802cdf0e10cSrcweir char const * pAscii = "abc"; 803cdf0e10cSrcweir 804cdf0e10cSrcweir sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii); 805*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(value > 0) << "strings are unequal and ref is bigger, needs to be >0."; 806cdf0e10cSrcweir } 807cdf0e10cSrcweir 808*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compare_WithLength, unequal_ascii_bigger) 809cdf0e10cSrcweir { 810cdf0e10cSrcweir rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("abc")); 811cdf0e10cSrcweir char const * pAscii = "defghi"; 812cdf0e10cSrcweir 813cdf0e10cSrcweir sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii); 814cdf0e10cSrcweir 815*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(value < 0) << "strings are unequal and ascii is bigger, needs to be <0."; 816cdf0e10cSrcweir } 817cdf0e10cSrcweir 818cdf0e10cSrcweir 819*1a7dd8bbSDamjan Jovanovic class ascii_shortenedCompareIgnoreAsciiCase_WithLength : public ::testing::Test 820cdf0e10cSrcweir { 821cdf0e10cSrcweir public: 822*1a7dd8bbSDamjan Jovanovic }; // class ascii_shortenedCompareIgnoreAsciiCase_WithLength 823cdf0e10cSrcweir 824*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_shortenedCompareIgnoreAsciiCase_WithLength, ascii_shortenedCompareIgnoreAsciiCase_WithLength_000) 825cdf0e10cSrcweir { 826cdf0e10cSrcweir rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0); 827cdf0e10cSrcweir // should not GPF 828cdf0e10cSrcweir } 829cdf0e10cSrcweir 830*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_shortenedCompareIgnoreAsciiCase_WithLength, ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_1) 831cdf0e10cSrcweir { 832cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 833cdf0e10cSrcweir rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0); 834cdf0e10cSrcweir // should not GPF 835cdf0e10cSrcweir } 836*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_shortenedCompareIgnoreAsciiCase_WithLength, ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_2) 837cdf0e10cSrcweir { 838cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 839cdf0e10cSrcweir rtl::OString sStr2 = "Line is shorter."; 840cdf0e10cSrcweir rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), sStr2.getLength(), sStr2.getStr(), 0); 841cdf0e10cSrcweir // should not GPF 842cdf0e10cSrcweir } 843*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_shortenedCompareIgnoreAsciiCase_WithLength, ascii_shortenedCompareIgnoreAsciiCase_WithLength_001) 844cdf0e10cSrcweir { 845cdf0e10cSrcweir rtl::OUString suStr1; 846cdf0e10cSrcweir rtl::OString sStr2; 847cdf0e10cSrcweir 848*1a7dd8bbSDamjan Jovanovic sal_Int32 nValue = rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( suStr1.getStr(), 0, sStr2.getStr(), 0); 849*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal."; 850cdf0e10cSrcweir } 851cdf0e10cSrcweir 852*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_shortenedCompareIgnoreAsciiCase_WithLength, ascii_shortenedCompareIgnoreAsciiCase_WithLength_002) 853cdf0e10cSrcweir { 854cdf0e10cSrcweir rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal."); 855cdf0e10cSrcweir rtl::OString sStr2 = "Line must be equal."; 856cdf0e10cSrcweir 857cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr(), sStr2.getLength()); 858*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal."; 859cdf0e10cSrcweir } 860cdf0e10cSrcweir 861*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_shortenedCompareIgnoreAsciiCase_WithLength, ascii_shortenedCompareIgnoreAsciiCase_WithLength_003) 862cdf0e10cSrcweir { 863cdf0e10cSrcweir rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ."); 864cdf0e10cSrcweir rtl::OString sStr2 = "Line must be differ and longer."; 865cdf0e10cSrcweir 866cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr(), sStr2.getLength()); 867*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue != 0) << "compare failed, strings differ."; 868cdf0e10cSrcweir } 869cdf0e10cSrcweir 870cdf0e10cSrcweir // ----------------------------------------------------------------------------- 871cdf0e10cSrcweir 872*1a7dd8bbSDamjan Jovanovic class ascii_compareIgnoreAsciiCase_WithLength : public ::testing::Test 873cdf0e10cSrcweir { 874cdf0e10cSrcweir public: 875*1a7dd8bbSDamjan Jovanovic }; // class ascii_compareIgnoreAsciiCase_WithLength 876cdf0e10cSrcweir 877*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compareIgnoreAsciiCase_WithLength, ascii_compareIgnoreAsciiCase_WithLength_000) 878cdf0e10cSrcweir { 879cdf0e10cSrcweir rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( NULL, 0, NULL); 880cdf0e10cSrcweir // should not GPF 881cdf0e10cSrcweir } 882cdf0e10cSrcweir 883*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compareIgnoreAsciiCase_WithLength, ascii_compareIgnoreAsciiCase_WithLength_000_1) 884cdf0e10cSrcweir { 885cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 886cdf0e10cSrcweir rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( aStr1.getStr(), 0, NULL); 887cdf0e10cSrcweir // should not GPF 888cdf0e10cSrcweir } 889*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compareIgnoreAsciiCase_WithLength, ascii_compareIgnoreAsciiCase_WithLength_000_2) 890cdf0e10cSrcweir { 891cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 892cdf0e10cSrcweir rtl::OString sStr2 = "Line is shorter."; 893cdf0e10cSrcweir rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( aStr1.getStr(), sStr2.getLength(), sStr2.getStr()); 894cdf0e10cSrcweir // should not GPF 895cdf0e10cSrcweir } 896*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compareIgnoreAsciiCase_WithLength, ascii_compareIgnoreAsciiCase_WithLength_001) 897cdf0e10cSrcweir { 898cdf0e10cSrcweir rtl::OUString suStr1; 899cdf0e10cSrcweir rtl::OString sStr2; 900cdf0e10cSrcweir 901*1a7dd8bbSDamjan Jovanovic sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( suStr1.getStr(), 0, sStr2.getStr()); 902*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compareIgnoreAsciiCase_WithLength failed, strings are equal."; 903cdf0e10cSrcweir } 904cdf0e10cSrcweir 905*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compareIgnoreAsciiCase_WithLength, ascii_compareIgnoreAsciiCase_WithLength_002) 906cdf0e10cSrcweir { 907cdf0e10cSrcweir rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal."); 908cdf0e10cSrcweir rtl::OString sStr2 = "Line must be equal."; 909cdf0e10cSrcweir 910cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr()); 911*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal."; 912cdf0e10cSrcweir } 913cdf0e10cSrcweir 914*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compareIgnoreAsciiCase_WithLength, ascii_compareIgnoreAsciiCase_WithLength_003) 915cdf0e10cSrcweir { 916cdf0e10cSrcweir rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ."); 917cdf0e10cSrcweir rtl::OString sStr2 = "Line must be differ and longer."; 918cdf0e10cSrcweir 919cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr()); 920*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue != 0) << "compare failed, strings differ."; 921cdf0e10cSrcweir } 922cdf0e10cSrcweir // ----------------------------------------------------------------------------- 923cdf0e10cSrcweir 924*1a7dd8bbSDamjan Jovanovic class ascii_compare : public ::testing::Test 925cdf0e10cSrcweir { 926cdf0e10cSrcweir public: 927*1a7dd8bbSDamjan Jovanovic }; // class ascii_compare 928cdf0e10cSrcweir 929*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compare, ascii_compare_000) 930cdf0e10cSrcweir { 931cdf0e10cSrcweir rtl_ustr_ascii_compare( NULL, NULL); 932cdf0e10cSrcweir // should not GPF 933cdf0e10cSrcweir } 934cdf0e10cSrcweir 935*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compare, ascii_compare_000_1) 936cdf0e10cSrcweir { 937cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 938cdf0e10cSrcweir rtl_ustr_ascii_compare( aStr1.getStr(), NULL); 939cdf0e10cSrcweir // should not GPF 940cdf0e10cSrcweir } 941*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compare, ascii_compare_001) 942cdf0e10cSrcweir { 943cdf0e10cSrcweir rtl::OUString suStr1; 944cdf0e10cSrcweir rtl::OString sStr2; 945cdf0e10cSrcweir 946*1a7dd8bbSDamjan Jovanovic sal_Int32 nValue = rtl_ustr_ascii_compare( suStr1.getStr(), sStr2.getStr()); 947*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal."; 948cdf0e10cSrcweir } 949cdf0e10cSrcweir 950*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compare, ascii_compare_002) 951cdf0e10cSrcweir { 952cdf0e10cSrcweir rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal."); 953cdf0e10cSrcweir rtl::OString sStr2 = "Line must be equal."; 954cdf0e10cSrcweir 955cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_ascii_compare( suStr1.getStr(), sStr2.getStr()); 956*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal."; 957cdf0e10cSrcweir } 958cdf0e10cSrcweir 959*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compare, ascii_compare_003) 960cdf0e10cSrcweir { 961cdf0e10cSrcweir rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ."); 962cdf0e10cSrcweir rtl::OString sStr2 = "Line foo bar, ok, differ."; 963cdf0e10cSrcweir 964cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_ascii_compare( suStr1.getStr(), sStr2.getStr()); 965*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue != 0) << "compare failed, strings differ."; 966cdf0e10cSrcweir } 967cdf0e10cSrcweir 968cdf0e10cSrcweir // ----------------------------------------------------------------------------- 969cdf0e10cSrcweir 970*1a7dd8bbSDamjan Jovanovic class ascii_compareIgnoreAsciiCase : public ::testing::Test 971cdf0e10cSrcweir { 972cdf0e10cSrcweir public: 973*1a7dd8bbSDamjan Jovanovic }; // class ascii_compareIgnoreAsciiCase 974cdf0e10cSrcweir 975*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compareIgnoreAsciiCase, ascii_compareIgnoreAsciiCase_000) 976cdf0e10cSrcweir { 977cdf0e10cSrcweir rtl_ustr_ascii_compareIgnoreAsciiCase( NULL, NULL); 978cdf0e10cSrcweir // should not GPF 979cdf0e10cSrcweir } 980cdf0e10cSrcweir 981*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compareIgnoreAsciiCase, ascii_compareIgnoreAsciiCase_000_1) 982cdf0e10cSrcweir { 983cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 984cdf0e10cSrcweir rtl_ustr_ascii_compareIgnoreAsciiCase( aStr1.getStr(), NULL); 985cdf0e10cSrcweir // should not GPF 986cdf0e10cSrcweir } 987*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compareIgnoreAsciiCase, ascii_compareIgnoreAsciiCase_001) 988cdf0e10cSrcweir { 989cdf0e10cSrcweir rtl::OUString suStr1; 990cdf0e10cSrcweir rtl::OString sStr2; 991cdf0e10cSrcweir 992*1a7dd8bbSDamjan Jovanovic sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr()); 993*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal."; 994cdf0e10cSrcweir } 995cdf0e10cSrcweir 996*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compareIgnoreAsciiCase, ascii_compareIgnoreAsciiCase_002) 997cdf0e10cSrcweir { 998cdf0e10cSrcweir rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal."); 999cdf0e10cSrcweir rtl::OString sStr2 = "Line must be equal."; 1000cdf0e10cSrcweir 1001cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr()); 1002*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal."; 1003cdf0e10cSrcweir } 1004cdf0e10cSrcweir 1005*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compareIgnoreAsciiCase, ascii_compareIgnoreAsciiCase_002_1) 1006cdf0e10cSrcweir { 1007cdf0e10cSrcweir rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal, when ignore case."); 1008cdf0e10cSrcweir rtl::OString sStr2 = "LINE MUST BE EQUAL, WHEN IGNORE CASE."; 1009cdf0e10cSrcweir 1010cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr()); 1011*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal (if case insensitve)."; 1012cdf0e10cSrcweir } 1013cdf0e10cSrcweir 1014*1a7dd8bbSDamjan Jovanovic TEST_F(ascii_compareIgnoreAsciiCase, ascii_compareIgnoreAsciiCase_003) 1015cdf0e10cSrcweir { 1016cdf0e10cSrcweir rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ."); 1017cdf0e10cSrcweir rtl::OString sStr2 = "Line foo bar, ok, differ."; 1018cdf0e10cSrcweir 1019cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr()); 1020*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue != 0) << "compare failed, strings differ."; 1021cdf0e10cSrcweir } 1022cdf0e10cSrcweir 1023cdf0e10cSrcweir //! LLA: some more tests with some high level strings 1024cdf0e10cSrcweir 1025*1a7dd8bbSDamjan Jovanovic // TEST_F(ascii_compareIgnoreAsciiCase, ascii_compareIgnoreAsciiCase_001() 1026cdf0e10cSrcweir // { 1027cdf0e10cSrcweir // rtl::OUString suStr1 = rtl::OUString::createFromAscii("change this to ascii upper case."); 1028cdf0e10cSrcweir // rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII UPPER CASE."); 1029cdf0e10cSrcweir // 1030cdf0e10cSrcweir // sal_uInt32 nLength = suStr1.getLength() * sizeof(sal_Unicode); 1031cdf0e10cSrcweir // sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode)); // length + null terminator 1032*1a7dd8bbSDamjan Jovanovic // ASSERT_TRUE(pStr != NULL) << "can't get memory for test"; 1033cdf0e10cSrcweir // memset(pStr, 0, nLength + sizeof(sal_Unicode)); 1034cdf0e10cSrcweir // memcpy(pStr, suStr1.getStr(), nLength); 1035cdf0e10cSrcweir // 1036cdf0e10cSrcweir // rtl_ustr_ascii_compareIgnoreAsciiCase( pStr ); 1037cdf0e10cSrcweir // rtl::OUString suStr(pStr, suStr1.getLength()); 1038cdf0e10cSrcweir // 1039*1a7dd8bbSDamjan Jovanovic // ASSERT_TRUE(aShouldStr1.equals(suStr) == sal_True) << "failed"; 1040cdf0e10cSrcweir // free(pStr); 1041cdf0e10cSrcweir // } 1042cdf0e10cSrcweir 1043cdf0e10cSrcweir // sample out of inc/rtl/ustring.hxx 1044cdf0e10cSrcweir // rtl_uString * pToken = NULL; 1045cdf0e10cSrcweir // sal_Int32 nIndex = 0; 1046cdf0e10cSrcweir // do 1047cdf0e10cSrcweir // { 1048cdf0e10cSrcweir // ... 1049cdf0e10cSrcweir // nIndex = rtl_uString_getToken(&pToken, pStr, 0, ';', nIndex); 1050cdf0e10cSrcweir // ... 1051cdf0e10cSrcweir // } 1052cdf0e10cSrcweir // while (nIndex >= 0); 1053cdf0e10cSrcweir 1054*1a7dd8bbSDamjan Jovanovic class getToken : public ::testing::Test 1055cdf0e10cSrcweir { 1056cdf0e10cSrcweir public: 1057*1a7dd8bbSDamjan Jovanovic }; // class ascii_compareIgnoreAsciiCase 1058cdf0e10cSrcweir 1059*1a7dd8bbSDamjan Jovanovic TEST_F(getToken, getToken_000) 1060cdf0e10cSrcweir { 1061cdf0e10cSrcweir rtl_ustr_ascii_compareIgnoreAsciiCase( NULL, NULL); 1062cdf0e10cSrcweir // should not GPF 1063cdf0e10cSrcweir } 1064cdf0e10cSrcweir 1065*1a7dd8bbSDamjan Jovanovic TEST_F(getToken, ascii_compareIgnoreAsciiCase_000_1) 1066cdf0e10cSrcweir { 1067cdf0e10cSrcweir rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 1068cdf0e10cSrcweir rtl_ustr_ascii_compareIgnoreAsciiCase( aStr1.getStr(), NULL); 1069cdf0e10cSrcweir // should not GPF 1070cdf0e10cSrcweir } 1071*1a7dd8bbSDamjan Jovanovic TEST_F(getToken, ascii_compareIgnoreAsciiCase_001) 1072cdf0e10cSrcweir { 1073cdf0e10cSrcweir rtl::OUString suStr1; 1074cdf0e10cSrcweir rtl::OString sStr2; 1075cdf0e10cSrcweir 1076*1a7dd8bbSDamjan Jovanovic sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr()); 1077*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal."; 1078cdf0e10cSrcweir } 1079cdf0e10cSrcweir 1080*1a7dd8bbSDamjan Jovanovic TEST_F(getToken, ascii_compareIgnoreAsciiCase_002) 1081cdf0e10cSrcweir { 1082cdf0e10cSrcweir rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal."); 1083cdf0e10cSrcweir rtl::OString sStr2 = "Line must be equal."; 1084cdf0e10cSrcweir 1085cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr()); 1086*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal."; 1087cdf0e10cSrcweir } 1088cdf0e10cSrcweir 1089*1a7dd8bbSDamjan Jovanovic TEST_F(getToken, ascii_compareIgnoreAsciiCase_002_1) 1090cdf0e10cSrcweir { 1091cdf0e10cSrcweir rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal, when ignore case."); 1092cdf0e10cSrcweir rtl::OString sStr2 = "LINE MUST BE EQUAL, WHEN IGNORE CASE."; 1093cdf0e10cSrcweir 1094cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr()); 1095*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal (if case insensitve)."; 1096cdf0e10cSrcweir } 1097cdf0e10cSrcweir 1098*1a7dd8bbSDamjan Jovanovic TEST_F(getToken, ascii_compareIgnoreAsciiCase_003) 1099cdf0e10cSrcweir { 1100cdf0e10cSrcweir rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ."); 1101cdf0e10cSrcweir rtl::OString sStr2 = "Line foo bar, ok, differ."; 1102cdf0e10cSrcweir 1103cdf0e10cSrcweir sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr()); 1104*1a7dd8bbSDamjan Jovanovic ASSERT_TRUE(nValue != 0) << "compare failed, strings differ."; 1105cdf0e10cSrcweir } 1106cdf0e10cSrcweir 1107cdf0e10cSrcweir //! LLA: some more tests with some high level strings 1108cdf0e10cSrcweir 1109*1a7dd8bbSDamjan Jovanovic // TEST_F(getToken, ascii_compareIgnoreAsciiCase_001) 1110cdf0e10cSrcweir // { 1111cdf0e10cSrcweir // rtl::OUString suStr1 = rtl::OUString::createFromAscii("change this to ascii upper case."); 1112cdf0e10cSrcweir // rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII UPPER CASE."); 1113cdf0e10cSrcweir // 1114cdf0e10cSrcweir // sal_uInt32 nLength = suStr1.getLength() * sizeof(sal_Unicode); 1115cdf0e10cSrcweir // sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode)); // length + null terminator 1116*1a7dd8bbSDamjan Jovanovic // ASSERT_TRUE(pStr != NULL) << "can't get memory for test"; 1117cdf0e10cSrcweir // memset(pStr, 0, nLength + sizeof(sal_Unicode)); 1118cdf0e10cSrcweir // memcpy(pStr, suStr1.getStr(), nLength); 1119cdf0e10cSrcweir // 1120cdf0e10cSrcweir // rtl_ustr_ascii_compareIgnoreAsciiCase( pStr ); 1121cdf0e10cSrcweir // rtl::OUString suStr(pStr, suStr1.getLength()); 1122cdf0e10cSrcweir // 1123*1a7dd8bbSDamjan Jovanovic // ASSERT_TRUE(aShouldStr1.equals(suStr) == sal_True) << "failed"; 1124cdf0e10cSrcweir // free(pStr); 1125cdf0e10cSrcweir // } 1126cdf0e10cSrcweir 1127cdf0e10cSrcweir } // namespace rtl_ustr 1128cdf0e10cSrcweir 1129cdf0e10cSrcweir 1130*1a7dd8bbSDamjan Jovanovic int main(int argc, char **argv) 1131*1a7dd8bbSDamjan Jovanovic { 1132*1a7dd8bbSDamjan Jovanovic ::testing::InitGoogleTest(&argc, argv); 1133*1a7dd8bbSDamjan Jovanovic return RUN_ALL_TESTS(); 1134*1a7dd8bbSDamjan Jovanovic } 1135