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