xref: /trunk/main/sal/qa/rtl/ostring/rtl_str.cxx (revision b3f397bd)
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/string.hxx>
29 
30 namespace rtl_str
31 {
32 
33     class compare : public ::testing::Test
34     {
35     public:
36     }; // class compare
37 
TEST_F(compare,compare_000)38     TEST_F(compare, compare_000)
39     {
40         rtl_str_compare( NULL, NULL);
41     }
42 
TEST_F(compare,compare_000_1)43     TEST_F(compare, compare_000_1)
44     {
45         rtl::OString aStr1 = "Line must be equal.";
46         rtl_str_compare( aStr1.getStr(), NULL);
47     }
TEST_F(compare,compare_001)48     TEST_F(compare, compare_001)
49     {
50         rtl::OString aStr1 = "";
51         rtl::OString aStr2 = "";
52 
53         sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr());
54         ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal.";
55     }
56 
TEST_F(compare,compare_002)57     TEST_F(compare, compare_002)
58     {
59         rtl::OString aStr1 = "Line must be equal.";
60         rtl::OString aStr2 = "Line must be equal.";
61 
62         sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr());
63         ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal.";
64     }
65 
TEST_F(compare,compare_003)66     TEST_F(compare, compare_003)
67     {
68         rtl::OString aStr1 = "Line must differ.";
69         rtl::OString aStr2 = "Line foo bar, ok, differ.";
70 
71         sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr());
72         ASSERT_TRUE(nValue != 0) << "compare failed, strings differ.";
73     }
74 
75     class compareIgnoreAsciiCase : public ::testing::Test
76     {
77     public:
78     }; // class compareIgnoreAsciiCase
79 
TEST_F(compareIgnoreAsciiCase,compare_000)80     TEST_F(compareIgnoreAsciiCase, compare_000)
81     {
82         rtl_str_compareIgnoreAsciiCase( NULL, NULL);
83     }
84 
TEST_F(compareIgnoreAsciiCase,compare_000_1)85     TEST_F(compareIgnoreAsciiCase, compare_000_1)
86     {
87         rtl::OString aStr1 = "Line must be equal.";
88         rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), NULL);
89     }
TEST_F(compareIgnoreAsciiCase,compare_001)90     TEST_F(compareIgnoreAsciiCase, compare_001)
91     {
92         rtl::OString aStr1 = "";
93         rtl::OString aStr2 = "";
94 
95         sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
96         ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal.";
97     }
98 
TEST_F(compareIgnoreAsciiCase,compare_002)99     TEST_F(compareIgnoreAsciiCase, compare_002)
100     {
101         rtl::OString aStr1 = "Line must be equal.";
102         rtl::OString aStr2 = "Line must be equal.";
103 
104         sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
105         ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal.";
106     }
107 
TEST_F(compareIgnoreAsciiCase,compare_002_1)108     TEST_F(compareIgnoreAsciiCase, compare_002_1)
109     {
110         rtl::OString aStr1 = "Line must be equal.";
111         rtl::OString aStr2 = "LINE MUST BE EQUAL.";
112 
113         sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
114         ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal (if case insensitve).";
115     }
116 
TEST_F(compareIgnoreAsciiCase,compare_003)117     TEST_F(compareIgnoreAsciiCase, compare_003)
118     {
119         rtl::OString aStr1 = "Line must differ.";
120         rtl::OString aStr2 = "Line foo bar, ok, differ.";
121 
122         sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
123         ASSERT_TRUE(nValue != 0) << "compare failed, strings differ.";
124     }
125 // -----------------------------------------------------------------------------
126 
127     class shortenedCompareIgnoreAsciiCase_WithLength : public ::testing::Test
128     {
129     public:
130     }; // class compare
131 
TEST_F(shortenedCompareIgnoreAsciiCase_WithLength,compare_000)132     TEST_F(shortenedCompareIgnoreAsciiCase_WithLength, compare_000)
133     {
134         rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0, 0);
135     }
136 
TEST_F(shortenedCompareIgnoreAsciiCase_WithLength,compare_000_1)137     TEST_F(shortenedCompareIgnoreAsciiCase_WithLength, compare_000_1)
138     {
139         rtl::OString aStr1 = "Line must be equal.";
140         rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0, 1);
141     }
TEST_F(shortenedCompareIgnoreAsciiCase_WithLength,compare_001)142     TEST_F(shortenedCompareIgnoreAsciiCase_WithLength, compare_001)
143     {
144         rtl::OString aStr1 = "";
145         rtl::OString aStr2 = "";
146 
147         sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), aStr2.getStr(), aStr2.getLength(), aStr1.getLength());
148         ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal.";
149     }
150 
TEST_F(shortenedCompareIgnoreAsciiCase_WithLength,compare_002)151     TEST_F(shortenedCompareIgnoreAsciiCase_WithLength, compare_002)
152     {
153         rtl::OString aStr1 = "Line must be equal.";
154         rtl::OString aStr2 = "Line must be equal.";
155 
156         sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
157                                                                                aStr2.getStr(), aStr2.getLength(),
158                                                                                aStr1.getLength());
159         ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal.";
160     }
161 
TEST_F(shortenedCompareIgnoreAsciiCase_WithLength,compare_002_1)162     TEST_F(shortenedCompareIgnoreAsciiCase_WithLength, compare_002_1)
163     {
164         rtl::OString aStr1 = "Line must be equal.";
165         rtl::OString aStr2 = "LINE MUST BE EQUAL.";
166 
167         sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
168                                                                                aStr2.getStr(), aStr2.getLength(),
169                                                                                aStr1.getLength());
170         ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal (if case insensitve).";
171     }
172 
TEST_F(shortenedCompareIgnoreAsciiCase_WithLength,compare_003)173     TEST_F(shortenedCompareIgnoreAsciiCase_WithLength, compare_003)
174     {
175         rtl::OString aStr1 = "Line must differ.";
176         rtl::OString aStr2 = "Line foo bar, ok, differ.";
177 
178         sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
179                                                                                aStr2.getStr(), aStr2.getLength(),
180                                                                                5);
181         ASSERT_TRUE(nValue == 0) << "compare failed, strings are equal first 5 characters.";
182     }
183 
TEST_F(shortenedCompareIgnoreAsciiCase_WithLength,compare_004)184     TEST_F(shortenedCompareIgnoreAsciiCase_WithLength, compare_004)
185     {
186         rtl::OString aStr1 = "Line must differ.";
187         rtl::OString aStr2 = "Line foo bar, ok, differ.";
188 
189         sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
190                                                                                aStr2.getStr(), aStr2.getLength(),
191                                                                                aStr1.getLength());
192         ASSERT_TRUE(nValue != 0) << "compare failed, strings differ.";
193     }
194 
195 // -----------------------------------------------------------------------------
196 
197     class hashCode : public ::testing::Test
198     {
199     public:
200     }; // class compare
201 
TEST_F(hashCode,hashCode_000)202     TEST_F(hashCode, hashCode_000)
203     {
204         rtl_str_hashCode( NULL );
205     }
206 
TEST_F(hashCode,hashCode_001)207     TEST_F(hashCode, hashCode_001)
208     {
209         rtl::OString aStr1 = "Line for a hashCode.";
210         sal_Int32 nHashCode = rtl_str_hashCode( aStr1.getStr() );
211         printf("hashcode: %d\n", nHashCode);
212         // ASSERT_TRUE(nValue == 0) << "failed.";
213     }
214 
TEST_F(hashCode,hashCode_002)215     TEST_F(hashCode, hashCode_002)
216     {
217         rtl::OString aStr1 = "Line for a hashCode.";
218         sal_Int32 nHashCode1 = rtl_str_hashCode( aStr1.getStr() );
219 
220         rtl::OString aStr2 = "Line for a hashCode.";
221         sal_Int32 nHashCode2 = rtl_str_hashCode( aStr2.getStr() );
222 
223         ASSERT_TRUE(nHashCode1 == nHashCode2) << "hashcodes must be equal.";
224     }
225 
TEST_F(hashCode,hashCode_003)226     TEST_F(hashCode, hashCode_003)
227     {
228         rtl::OString aStr1 = "Line for a hashCode.";
229         sal_Int32 nHashCode1 = rtl_str_hashCode( aStr1.getStr() );
230 
231         rtl::OString aStr2 = "Line for an other hashcode.";
232         sal_Int32 nHashCode2 = rtl_str_hashCode( aStr2.getStr() );
233 
234         ASSERT_TRUE(nHashCode1 != nHashCode2) << "hashcodes must differ.";
235     }
236 
237 // -----------------------------------------------------------------------------
238 
239     class indexOfChar : public ::testing::Test
240     {
241     public:
242     }; // class compare
243 
TEST_F(indexOfChar,indexOfChar_000)244     TEST_F(indexOfChar, indexOfChar_000)
245     {
246         rtl_str_indexOfChar( NULL, 0 );
247     }
248 
TEST_F(indexOfChar,indexOfChar_001)249     TEST_F(indexOfChar, indexOfChar_001)
250     {
251         rtl::OString aStr1 = "Line for a indexOfChar.";
252 
253         sal_Int32 nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'L' );
254         ASSERT_TRUE(nIndex == 0) << "index is wrong.";
255 
256         /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'i' );
257         ASSERT_TRUE(nIndex == 1) << "index is wrong.";
258 
259         /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'n' );
260         ASSERT_TRUE(nIndex == 2) << "index is wrong.";
261 
262         /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'e' );
263         ASSERT_TRUE(nIndex == 3) << "index is wrong.";
264     }
265 
TEST_F(indexOfChar,indexOfChar_002)266     TEST_F(indexOfChar, indexOfChar_002)
267     {
268         rtl::OString aStr1 = "Line for a indexOfChar.";
269         sal_Int32 nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'y' );
270 
271         ASSERT_TRUE(nIndex == -1) << "index is wrong.";
272     }
273 
274 // -----------------------------------------------------------------------------
275     class lastIndexOfChar : public ::testing::Test
276     {
277     public:
278     }; // class lastIndexOfChar
279 
TEST_F(lastIndexOfChar,lastIndexOfChar_000)280     TEST_F(lastIndexOfChar, lastIndexOfChar_000)
281     {
282         rtl_str_lastIndexOfChar( NULL, 0 );
283     }
284 
TEST_F(lastIndexOfChar,lastIndexOfChar_001)285     TEST_F(lastIndexOfChar, lastIndexOfChar_001)
286     {
287         rtl::OString aStr1 = "Line for a lastIndexOfChar.";
288 
289         sal_Int32 nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'C' );
290         ASSERT_TRUE(nIndex == 22) << "index is wrong.";
291 
292         /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'h' );
293         ASSERT_TRUE(nIndex == 23) << "index is wrong.";
294 
295         /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'a' );
296         ASSERT_TRUE(nIndex == 24) << "index is wrong.";
297 
298         /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'r' );
299         ASSERT_TRUE(nIndex == 25) << "index is wrong.";
300     }
301 
TEST_F(lastIndexOfChar,lastIndexOfChar_002)302     TEST_F(lastIndexOfChar, lastIndexOfChar_002)
303     {
304         rtl::OString aStr1 = "Line for a lastIndexOfChar.";
305         sal_Int32 nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'y' );
306 
307         ASSERT_TRUE(nIndex == -1) << "index is wrong.";
308     }
309 
310 // -----------------------------------------------------------------------------
311 
312     class indexOfStr : public ::testing::Test
313     {
314     public:
315     }; // class compare
316 
TEST_F(indexOfStr,indexOfStr_000)317     TEST_F(indexOfStr, indexOfStr_000)
318     {
319         rtl_str_indexOfStr( NULL, 0 );
320     }
321 
TEST_F(indexOfStr,indexOfStr_000_1)322     TEST_F(indexOfStr, indexOfStr_000_1)
323     {
324         rtl::OString aStr1 = "Line for a indexOfStr.";
325         rtl_str_indexOfStr( aStr1.getStr(), 0 );
326     }
327 
TEST_F(indexOfStr,indexOfStr_001)328     TEST_F(indexOfStr, indexOfStr_001)
329     {
330         rtl::OString aStr1 = "Line for a indexOfStr.";
331 
332         sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "Line" );
333         ASSERT_TRUE(nIndex == 0) << "index is wrong.";
334 
335         /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "for" );
336         ASSERT_TRUE(nIndex == 5) << "index is wrong.";
337 
338         /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "a" );
339         ASSERT_TRUE(nIndex == 9) << "index is wrong.";
340 
341         /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "a index" );
342         ASSERT_TRUE(nIndex ==9) << "index is wrong.";
343     }
344 
TEST_F(indexOfStr,indexOfStr_002)345     TEST_F(indexOfStr, indexOfStr_002)
346     {
347         rtl::OString aStr1 = "Line for a indexOfStr.";
348         sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "not exist" );
349 
350         ASSERT_TRUE(nIndex == -1) << "index is wrong.";
351     }
352 
353 // -----------------------------------------------------------------------------
354 
355 
356     class lastIndexOfStr : public ::testing::Test
357     {
358     public:
359     }; // class lastIndexOfStr
360 
TEST_F(lastIndexOfStr,lastIndexOfStr_000)361     TEST_F(lastIndexOfStr, lastIndexOfStr_000)
362     {
363         rtl_str_lastIndexOfStr( NULL, NULL );
364     }
365 
TEST_F(lastIndexOfStr,lastIndexOfStr_000_1)366     TEST_F(lastIndexOfStr, lastIndexOfStr_000_1)
367     {
368         rtl::OString aStr1 = "Line for a lastIndexOfStr.";
369         rtl_str_lastIndexOfStr( aStr1.getStr(), NULL );
370     }
371 
TEST_F(lastIndexOfStr,lastIndexOfStr_001)372     TEST_F(lastIndexOfStr, lastIndexOfStr_001)
373     {
374         rtl::OString aStr1 = "Line for a lastIndexOfStr.";
375         rtl::OString aSearchStr = "Index";
376 
377         sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
378         ASSERT_TRUE(nIndex == 15) << "index is wrong.";
379 
380         /* rtl::OString */ aSearchStr = "Line";
381         /* sal_Int32 */ nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
382         ASSERT_TRUE(nIndex == 0) << "index is wrong.";
383 
384         /* rtl::OString */ aSearchStr = "";
385         /* sal_Int32 */ nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
386         ASSERT_TRUE(nIndex == -1) << "index is wrong.";
387     }
388 
TEST_F(lastIndexOfStr,lastIndexOfStr_002)389     TEST_F(lastIndexOfStr, lastIndexOfStr_002)
390     {
391         rtl::OString aStr1 = "Line for a lastIndexOfStr.";
392         rtl::OString aSearchStr = "foo";
393         sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
394 
395         ASSERT_TRUE(nIndex == -1) << "index is wrong.";
396     }
397 
TEST_F(lastIndexOfStr,lastIndexOfStr_003)398     TEST_F(lastIndexOfStr, lastIndexOfStr_003)
399     {
400         rtl::OString aStr1 = "Line for a lastIndexOfStr.";
401         rtl::OString aSearchStr = "O";
402         sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
403 
404         ASSERT_TRUE(nIndex == 20) << "index is wrong.";
405     }
406 
407 // -----------------------------------------------------------------------------
408 
409     class replaceChar : public ::testing::Test
410     {
411     public:
412     }; // class replaceChar
413 
TEST_F(replaceChar,replaceChar_000)414     TEST_F(replaceChar, replaceChar_000)
415     {
416         rtl_str_replaceChar( NULL, 0, 0 );
417     }
418 
TEST_F(replaceChar,replaceChar_001)419     TEST_F(replaceChar, replaceChar_001)
420     {
421         rtl::OString aStr1 = "replace char.";
422         rtl::OString aShouldStr1 = "ruplacu char.";
423 
424         sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
425         ASSERT_TRUE(pStr != NULL) << "can't get memory for test";
426         strcpy(pStr, aStr1.getStr());
427 
428         rtl_str_replaceChar( pStr, 'e', 'u' );
429 
430         ASSERT_TRUE(aShouldStr1.equals(rtl::OString(pStr)) == sal_True) << "replace failed";
431         free(pStr);
432     }
433 
434 // -----------------------------------------------------------------------------
435 
436     class replaceChar_WithLength : public ::testing::Test
437     {
438     public:
439     }; // class replaceChar
440 
TEST_F(replaceChar_WithLength,replaceChar_WithLength_000)441     TEST_F(replaceChar_WithLength, replaceChar_WithLength_000)
442     {
443         rtl_str_replaceChar_WithLength( NULL, 0, 0, 0 );
444     }
445 
TEST_F(replaceChar_WithLength,replaceChar_WithLength_000_1)446     TEST_F(replaceChar_WithLength, replaceChar_WithLength_000_1)
447     {
448         rtl_str_replaceChar_WithLength( NULL, 1, 0, 0 );
449     }
TEST_F(replaceChar_WithLength,replaceChar_WithLength_001)450     TEST_F(replaceChar_WithLength, replaceChar_WithLength_001)
451     {
452         rtl::OString aStr1 = "replace char.";
453         rtl::OString aShouldStr1 = "ruplace char.";
454 
455         sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
456         ASSERT_TRUE(pStr != NULL) << "can't get memory for test";
457         strcpy(pStr, aStr1.getStr());
458 
459         rtl_str_replaceChar_WithLength( pStr, 6, 'e', 'u' );
460 
461         ASSERT_TRUE(aShouldStr1.equals(rtl::OString(pStr)) == sal_True) << "replace failed";
462         free(pStr);
463     }
464 
465 // -----------------------------------------------------------------------------
466 
467     class toAsciiLowerCase : public ::testing::Test
468     {
469     public:
470     }; // class replaceChar
471 
TEST_F(toAsciiLowerCase,toAsciiLowerCase_000)472     TEST_F(toAsciiLowerCase, toAsciiLowerCase_000)
473     {
474         rtl_str_toAsciiLowerCase( NULL );
475     }
476 
TEST_F(toAsciiLowerCase,toAsciiLowerCase_001)477     TEST_F(toAsciiLowerCase, toAsciiLowerCase_001)
478     {
479         rtl::OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE.";
480         rtl::OString aShouldStr1 = "change this to ascii lower case.";
481 
482         sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
483         ASSERT_TRUE(pStr != NULL) << "can't get memory for test";
484         strcpy(pStr, aStr1.getStr());
485 
486         rtl_str_toAsciiLowerCase( pStr );
487 
488         ASSERT_TRUE(aShouldStr1.equals(rtl::OString(pStr)) == sal_True) << "failed";
489         free(pStr);
490     }
491 
492     class toAsciiLowerCase_WithLength : public ::testing::Test
493     {
494     public:
495     }; // class replaceChar
496 
TEST_F(toAsciiLowerCase_WithLength,toAsciiLowerCase_WithLength_000)497     TEST_F(toAsciiLowerCase_WithLength, toAsciiLowerCase_WithLength_000)
498     {
499         rtl_str_toAsciiLowerCase_WithLength( NULL, 0 );
500     }
501 
TEST_F(toAsciiLowerCase_WithLength,toAsciiLowerCase_WithLength_001)502     TEST_F(toAsciiLowerCase_WithLength, toAsciiLowerCase_WithLength_001)
503     {
504         rtl::OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE.";
505         rtl::OString aShouldStr1 = "change thiS TO ASCII LOWER CASE.";
506 
507         sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
508         ASSERT_TRUE(pStr != NULL) << "can't get memory for test";
509         strcpy(pStr, aStr1.getStr());
510 
511         rtl_str_toAsciiLowerCase_WithLength( pStr, 10 );
512 
513         printf("Lowercase with length: '%s'\n", pStr);
514         ASSERT_TRUE(aShouldStr1.equals(rtl::OString(pStr)) == sal_True) << "failed";
515         free(pStr);
516     }
517 
518 // -----------------------------------------------------------------------------
519 
520     class toAsciiUpperCase : public ::testing::Test
521     {
522     public:
523     }; // class replaceChar
524 
TEST_F(toAsciiUpperCase,toAsciiUpperCase_000)525     TEST_F(toAsciiUpperCase, toAsciiUpperCase_000)
526     {
527         rtl_str_toAsciiUpperCase( NULL );
528     }
529 
TEST_F(toAsciiUpperCase,toAsciiUpperCase_001)530     TEST_F(toAsciiUpperCase, toAsciiUpperCase_001)
531     {
532         rtl::OString aStr1 = "change this to ascii upper case.";
533         rtl::OString aShouldStr1 = "CHANGE THIS TO ASCII UPPER CASE.";
534 
535         sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
536         ASSERT_TRUE(pStr != NULL) << "can't get memory for test";
537         strcpy(pStr, aStr1.getStr());
538 
539         rtl_str_toAsciiUpperCase( pStr );
540 
541         ASSERT_TRUE(aShouldStr1.equals(rtl::OString(pStr)) == sal_True) << "failed";
542         free(pStr);
543     }
544 
545     class toAsciiUpperCase_WithLength : public ::testing::Test
546     {
547     public:
548     }; // class replaceChar
549 
TEST_F(toAsciiUpperCase_WithLength,toAsciiUpperCase_WithLength_000)550     TEST_F(toAsciiUpperCase_WithLength, toAsciiUpperCase_WithLength_000)
551     {
552         rtl_str_toAsciiUpperCase_WithLength( NULL, 0 );
553     }
554 
TEST_F(toAsciiUpperCase_WithLength,toAsciiUpperCase_WithLength_001)555     TEST_F(toAsciiUpperCase_WithLength, toAsciiUpperCase_WithLength_001)
556     {
557         rtl::OString aStr1 = "change this to ascii lower case.";
558         rtl::OString aShouldStr1 = "CHANGE THIs to ascii lower case.";
559 
560         sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
561         ASSERT_TRUE(pStr != NULL) << "can't get memory for test";
562 
563         strcpy(pStr, aStr1.getStr());
564         rtl_str_toAsciiUpperCase_WithLength( pStr, 10 );
565 
566         printf("Uppercase with length: '%s'\n", aStr1.getStr());
567         ASSERT_TRUE(aShouldStr1.equals(rtl::OString(pStr)) == sal_True) << "failed";
568         free(pStr);
569     }
570 
571     // -----------------------------------------------------------------------------
572 
573     class trim_WithLength : public ::testing::Test
574     {
575       public:
576     };
577 
TEST_F(trim_WithLength,trim_WithLength_000)578     TEST_F(trim_WithLength, trim_WithLength_000)
579     {
580         rtl_str_trim_WithLength(NULL, 0);
581         // should not GPF
582     }
583 
TEST_F(trim_WithLength,trim_WithLength_000_1)584     TEST_F(trim_WithLength, trim_WithLength_000_1)
585     {
586         char pStr[] = { "  trim this" };
587         rtl_str_trim_WithLength( pStr, 0 );
588     }
589 
TEST_F(trim_WithLength,trim_WithLength_001)590     TEST_F(trim_WithLength, trim_WithLength_001)
591     {
592         char const *pStr = "  trim this";
593         sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
594         if (pStr2)
595         {
596             strcpy(pStr2, pStr);
597             rtl_str_trim_WithLength( pStr2, 2 );
598 
599             ASSERT_TRUE(strlen(pStr2) == 0) << "string should be empty";
600             free(pStr2);
601         }
602     }
603 
TEST_F(trim_WithLength,trim_WithLength_002)604     TEST_F(trim_WithLength, trim_WithLength_002)
605     {
606         char const *pStr = "trim this";
607         sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
608         if (pStr2)
609         {
610             strcpy(pStr2, pStr);
611             rtl_str_trim_WithLength( pStr2, 5 );
612 
613             ASSERT_TRUE(strlen(pStr2) == 4) << "string should contain 'trim'";
614             free(pStr2);
615         }
616     }
617 
TEST_F(trim_WithLength,trim_WithLength_003)618     TEST_F(trim_WithLength, trim_WithLength_003)
619     {
620         char const *pStr = "     trim   this";
621         sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
622         if (pStr2)
623         {
624             strcpy(pStr2, pStr);
625             rtl_str_trim_WithLength( pStr2, 11 );
626 
627             ASSERT_TRUE(strlen(pStr2) == 4) << "string should contain 'trim'";
628             free(pStr2);
629         }
630     }
631 
TEST_F(trim_WithLength,trim_WithLength_004)632     TEST_F(trim_WithLength, trim_WithLength_004)
633     {
634         char const *pStr = "\r\n\t \n\r    trim  \n this";
635         sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
636         if (pStr2)
637         {
638             strcpy(pStr2, pStr);
639             rtl_str_trim_WithLength( pStr2, 17 );
640 
641             ASSERT_TRUE(strlen(pStr2) == 4) << "string should contain 'trim'";
642             free(pStr2);
643         }
644     }
645 
TEST_F(trim_WithLength,trim_WithLength_005)646     TEST_F(trim_WithLength, trim_WithLength_005)
647     {
648         char const *pStr = "\r\n\t \n\r    trim \t this \n\r\t\t     ";
649         sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
650         if (pStr2)
651         {
652             strcpy(pStr2, pStr);
653             rtl_str_trim_WithLength( pStr2, strlen(pStr2) );
654             ASSERT_TRUE(strlen(pStr2) == 11) << "string should contain 'trim'";
655             free(pStr2);
656         }
657     }
658 
659     // -----------------------------------------------------------------------------
660 
661     class valueOfChar : public ::testing::Test
662     {
663       public:
664     };
665 
TEST_F(valueOfChar,valueOfChar_000)666     TEST_F(valueOfChar, valueOfChar_000)
667     {
668         rtl_str_valueOfChar(NULL, 0);
669         // should not GPF
670     }
TEST_F(valueOfChar,valueOfChar_001)671     TEST_F(valueOfChar, valueOfChar_001)
672     {
673         sal_Char *pStr = (sal_Char*)malloc(RTL_STR_MAX_VALUEOFCHAR);
674         if (pStr)
675         {
676             rtl_str_valueOfChar(pStr, 'A');
677 
678             ASSERT_TRUE(pStr[0] == 'A') << "string should contain 'A'";
679             free(pStr);
680         }
681     }
682 
683 } // namespace rtl_str
684 
main(int argc,char ** argv)685 int main(int argc, char **argv)
686 {
687     ::testing::InitGoogleTest(&argc, argv);
688     return RUN_ALL_TESTS();
689 }
690