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