tdf#154546 skip dispatch when presenter controller is not set
[LibreOffice.git] / sal / qa / rtl / ostring / rtl_str.cxx
blobf7af2200833f4af7c27ba81e2ed2afa16e06c97f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/types.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
23 #include <cppunit/plugin/TestPlugIn.h>
25 #include <rtl/string.hxx>
26 #include <cstring>
28 namespace rtl_str
31 class compare : public CppUnit::TestFixture
33 void compare_001()
35 OString aStr1 = "";
36 OString aStr2 = "";
38 sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr());
39 CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal.", sal_Int32(0), nValue);
42 void compare_002()
44 OString aStr1 = "Line must be equal.";
45 OString aStr2 = "Line must be equal.";
47 sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr());
48 CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal.", sal_Int32(0), nValue);
51 void compare_003()
53 OString aStr1 = "Line must differ.";
54 OString aStr2 = "Line foo bar, ok, differ.";
56 sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr());
57 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
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.
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
71 class compareIgnoreAsciiCase : public CppUnit::TestFixture
73 void compare_001()
75 OString aStr1 = "";
76 OString aStr2 = "";
78 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
79 CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal.", sal_Int32(0), nValue);
82 void compare_002()
84 OString aStr1 = "Line must be equal.";
85 OString aStr2 = "Line must be equal.";
87 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
88 CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal.", sal_Int32(0), nValue);
91 void compare_002_1()
93 OString aStr1 = "Line must be equal.";
94 OString aStr2 = "LINE MUST BE EQUAL.";
96 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
97 CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal (if case insensitive).", sal_Int32(0), nValue);
100 void compare_003()
102 OString aStr1 = "Line must differ.";
103 OString aStr2 = "Line foo bar, ok, differ.";
105 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
106 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
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.
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
121 class shortenedCompareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture
123 void compare_000()
125 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( nullptr, 0, nullptr, 0, 0);
128 void compare_000_1()
130 OString aStr1 = "Line must be equal.";
131 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), nullptr, 0, 1);
133 void compare_001()
135 OString aStr1 = "";
136 OString aStr2 = "";
138 sal_Int32 nValue = rtl_str_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);
142 void compare_002()
144 OString aStr1 = "Line must be equal.";
145 OString aStr2 = "Line must be equal.";
147 sal_Int32 nValue = rtl_str_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);
153 void compare_002_1()
155 OString aStr1 = "Line must be equal.";
156 OString aStr2 = "LINE MUST BE EQUAL.";
158 sal_Int32 nValue = rtl_str_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);
164 void compare_003()
166 OString aStr1 = "Line must differ.";
167 OString aStr2 = "Line foo bar, ok, differ.";
169 sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
170 aStr2.getStr(), aStr2.getLength(),
172 CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal first 5 characters.", sal_Int32(0), nValue);
175 void compare_004()
177 OString aStr1 = "Line must differ.";
178 OString aStr2 = "Line foo bar, ok, differ.";
180 sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
181 aStr2.getStr(), aStr2.getLength(),
182 aStr1.getLength());
183 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
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.
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
201 class hashCode : public CppUnit::TestFixture
203 void hashCode_001()
205 OString aStr1 = "Line for a hashCode.";
206 sal_Int32 nHashCode = rtl_str_hashCode( aStr1.getStr() );
207 printf("hashcode: %" SAL_PRIdINT32 "\n", nHashCode);
208 // CPPUNIT_ASSERT_MESSAGE("failed.", nValue == 0);
211 void hashCode_002()
213 OString aStr1 = "Line for a hashCode.";
214 sal_Int32 nHashCode1 = rtl_str_hashCode( aStr1.getStr() );
216 OString aStr2 = "Line for a hashCode.";
217 sal_Int32 nHashCode2 = rtl_str_hashCode( aStr2.getStr() );
219 CPPUNIT_ASSERT_EQUAL_MESSAGE("hashcodes must be equal.", nHashCode1, nHashCode2 );
222 void hashCode_003()
224 OString aStr1 = "Line for a hashCode.";
225 sal_Int32 nHashCode1 = rtl_str_hashCode( aStr1.getStr() );
227 OString aStr2 = "Line for another hashcode.";
228 sal_Int32 nHashCode2 = rtl_str_hashCode( aStr2.getStr() );
230 CPPUNIT_ASSERT_MESSAGE("hashcodes must differ.", nHashCode1 != nHashCode2 );
233 // Change the following lines only, if you add, remove or rename
234 // member functions of the current class,
235 // because these macros are need by auto register mechanism.
237 CPPUNIT_TEST_SUITE(hashCode);
238 CPPUNIT_TEST(hashCode_001);
239 CPPUNIT_TEST(hashCode_002);
240 CPPUNIT_TEST(hashCode_003);
241 CPPUNIT_TEST_SUITE_END();
242 }; // class compare
244 class indexOfChar : public CppUnit::TestFixture
246 void indexOfChar_000()
248 sal_Int32 nIndex = rtl_str_indexOfChar("", 0);
249 CPPUNIT_ASSERT_EQUAL_MESSAGE("Trailing zero character is not part of the string",
250 sal_Int32(-1), nIndex);
253 void indexOfChar_001()
255 OString aStr1 = "Line for an indexOfChar.";
257 sal_Int32 nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'L' );
258 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(0), nIndex);
260 /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'i' );
261 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(1), nIndex);
263 /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'n' );
264 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(2), nIndex);
266 /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'e' );
267 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(3), nIndex);
270 void indexOfChar_002()
272 OString aStr1 = "Line for an indexOfChar.";
273 sal_Int32 nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'y' );
275 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(-1), nIndex);
278 // Change the following lines only, if you add, remove or rename
279 // member functions of the current class,
280 // because these macros are need by auto register mechanism.
282 CPPUNIT_TEST_SUITE(indexOfChar);
283 CPPUNIT_TEST(indexOfChar_000);
284 CPPUNIT_TEST(indexOfChar_001);
285 CPPUNIT_TEST(indexOfChar_002);
286 CPPUNIT_TEST_SUITE_END();
287 }; // class compare
289 class lastIndexOfChar : public CppUnit::TestFixture
291 void lastIndexOfChar_000()
293 sal_Int32 nIndex = rtl_str_lastIndexOfChar("", 0);
294 CPPUNIT_ASSERT_EQUAL_MESSAGE("Trailing zero character is not part of the string",
295 sal_Int32(-1), nIndex);
298 void lastIndexOfChar_001()
300 OString aStr1 = "Line for a lastIndexOfChar.";
302 sal_Int32 nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'C' );
303 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(22), nIndex);
305 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'h' );
306 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(23), nIndex);
308 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'a' );
309 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(24), nIndex);
311 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'r' );
312 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(25), nIndex);
315 void lastIndexOfChar_002()
317 OString aStr1 = "Line for a lastIndexOfChar.";
318 sal_Int32 nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'y' );
320 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(-1), nIndex);
323 // Change the following lines only, if you add, remove or rename
324 // member functions of the current class,
325 // because these macros are need by auto register mechanism.
327 CPPUNIT_TEST_SUITE(lastIndexOfChar);
328 CPPUNIT_TEST(lastIndexOfChar_000);
329 CPPUNIT_TEST(lastIndexOfChar_001);
330 CPPUNIT_TEST(lastIndexOfChar_002);
331 CPPUNIT_TEST_SUITE_END();
332 }; // class lastIndexOfChar
334 class indexOfStr : public CppUnit::TestFixture
336 void indexOfStr_000()
338 OString aStr1("Line for an indexOfStr.");
339 sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "" );
340 CPPUNIT_ASSERT_EQUAL_MESSAGE("an empty substring is always not findable",
341 sal_Int32(-1), nIndex);
344 void indexOfStr_001()
346 OString aStr1 = "Line for an indexOfStr.";
348 sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "Line" );
349 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(0), nIndex);
351 /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "for" );
352 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(5), nIndex);
354 /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "a" );
355 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(9), nIndex);
357 /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "an index" );
358 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(9), nIndex);
361 void indexOfStr_002()
363 OString aStr1 = "Line for an indexOfStr.";
364 sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "not exist" );
366 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(-1), nIndex);
369 // Change the following lines only, if you add, remove or rename
370 // member functions of the current class,
371 // because these macros are need by auto register mechanism.
373 CPPUNIT_TEST_SUITE(indexOfStr);
374 CPPUNIT_TEST(indexOfStr_000);
375 CPPUNIT_TEST(indexOfStr_001);
376 CPPUNIT_TEST(indexOfStr_002);
377 CPPUNIT_TEST_SUITE_END();
378 }; // class compare
380 class lastIndexOfStr : public CppUnit::TestFixture
382 void lastIndexOfStr_000()
384 OString aStr1("Line for a lastIndexOfStr.");
385 sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), "" );
386 CPPUNIT_ASSERT_EQUAL_MESSAGE("an empty substring is always not findable",
387 sal_Int32(-1), nIndex);
390 void lastIndexOfStr_001()
392 OString aStr1 = "Line for a lastIndexOfStr.";
393 OString aSearchStr = "Index";
395 sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
396 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(15), nIndex);
398 /* OString */ aSearchStr = "Line";
399 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
400 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(0), nIndex);
402 /* OString */ aSearchStr = "";
403 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
404 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(-1), nIndex);
407 void lastIndexOfStr_002()
409 OString aStr1 = "Line for a lastIndexOfStr.";
410 OString aSearchStr = "foo";
411 sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
413 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(-1), nIndex);
416 void lastIndexOfStr_003()
418 OString aStr1 = "Line for a lastIndexOfStr.";
419 OString aSearchStr = "O";
420 sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
422 CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(20), nIndex);
425 // Change the following lines only, if you add, remove or rename
426 // member functions of the current class,
427 // because these macros are need by auto register mechanism.
429 CPPUNIT_TEST_SUITE(lastIndexOfStr);
430 CPPUNIT_TEST(lastIndexOfStr_000);
431 CPPUNIT_TEST(lastIndexOfStr_001);
432 CPPUNIT_TEST(lastIndexOfStr_002);
433 CPPUNIT_TEST(lastIndexOfStr_003);
434 CPPUNIT_TEST_SUITE_END();
435 }; // class lastIndexOfStr
437 class replaceChar : public CppUnit::TestFixture
439 void replaceChar_001()
441 OString aStr1 = "replace char.";
442 OString aShouldStr1 = "ruplacu char.";
444 char* pStr = static_cast<char*>(malloc(aStr1.getLength() + 1));
445 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != nullptr);
446 strcpy(pStr, aStr1.getStr());
448 rtl_str_replaceChar( pStr, 'e', 'u' );
450 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(OString(pStr)));
451 free(pStr);
454 // Change the following lines only, if you add, remove or rename
455 // member functions of the current class,
456 // because these macros are need by auto register mechanism.
458 CPPUNIT_TEST_SUITE(replaceChar);
459 CPPUNIT_TEST(replaceChar_001);
460 CPPUNIT_TEST_SUITE_END();
461 }; // class replaceChar
463 class replaceChar_WithLength : public CppUnit::TestFixture
465 void replaceChar_WithLength_000()
467 rtl_str_replaceChar_WithLength( nullptr, 0, 0, 0 );
470 void replaceChar_WithLength_001()
472 OString aStr1 = "replace char.";
473 OString aShouldStr1 = "ruplace char.";
475 char* pStr = static_cast<char*>(malloc(aStr1.getLength() + 1));
476 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != nullptr);
477 strcpy(pStr, aStr1.getStr());
479 rtl_str_replaceChar_WithLength( pStr, 6, 'e', 'u' );
481 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(OString(pStr)));
482 free(pStr);
485 // Change the following lines only, if you add, remove or rename
486 // member functions of the current class,
487 // because these macros are need by auto register mechanism.
489 CPPUNIT_TEST_SUITE(replaceChar_WithLength);
490 CPPUNIT_TEST(replaceChar_WithLength_000);
491 CPPUNIT_TEST(replaceChar_WithLength_001);
492 CPPUNIT_TEST_SUITE_END();
493 }; // class replaceChar
495 class toAsciiLowerCase : public CppUnit::TestFixture
497 void toAsciiLowerCase_001()
499 OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE.";
500 OString aShouldStr1 = "change this to ascii lower case.";
502 char* pStr = static_cast<char*>(malloc(aStr1.getLength() + 1));
503 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != nullptr);
504 strcpy(pStr, aStr1.getStr());
506 rtl_str_toAsciiLowerCase( pStr );
508 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(OString(pStr)));
509 free(pStr);
512 // Change the following lines only, if you add, remove or rename
513 // member functions of the current class,
514 // because these macros are need by auto register mechanism.
516 CPPUNIT_TEST_SUITE(toAsciiLowerCase);
517 CPPUNIT_TEST(toAsciiLowerCase_001);
518 CPPUNIT_TEST_SUITE_END();
519 }; // class replaceChar
521 class toAsciiLowerCase_WithLength : public CppUnit::TestFixture
523 void toAsciiLowerCase_WithLength_000()
525 rtl_str_toAsciiLowerCase_WithLength( nullptr, 0 );
528 void toAsciiLowerCase_WithLength_001()
530 OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE.";
531 OString aShouldStr1 = "change thiS TO ASCII LOWER CASE.";
533 char* pStr = static_cast<char*>(malloc(aStr1.getLength() + 1));
534 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != nullptr);
535 strcpy(pStr, aStr1.getStr());
537 rtl_str_toAsciiLowerCase_WithLength( pStr, 10 );
539 printf("Lowercase with length: '%s'\n", pStr);
540 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(OString(pStr)));
541 free(pStr);
544 // Change the following lines only, if you add, remove or rename
545 // member functions of the current class,
546 // because these macros are need by auto register mechanism.
548 CPPUNIT_TEST_SUITE(toAsciiLowerCase_WithLength);
549 CPPUNIT_TEST(toAsciiLowerCase_WithLength_000);
550 CPPUNIT_TEST(toAsciiLowerCase_WithLength_001);
551 CPPUNIT_TEST_SUITE_END();
552 }; // class replaceChar
554 class toAsciiUpperCase : public CppUnit::TestFixture
556 void toAsciiUpperCase_001()
558 OString aStr1 = "change this to ascii upper case.";
559 OString aShouldStr1 = "CHANGE THIS TO ASCII UPPER CASE.";
561 char* pStr = static_cast<char*>(malloc(aStr1.getLength() + 1));
562 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != nullptr);
563 strcpy(pStr, aStr1.getStr());
565 rtl_str_toAsciiUpperCase( pStr );
567 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(OString(pStr)));
568 free(pStr);
571 // Change the following lines only, if you add, remove or rename
572 // member functions of the current class,
573 // because these macros are need by auto register mechanism.
575 CPPUNIT_TEST_SUITE(toAsciiUpperCase);
576 CPPUNIT_TEST(toAsciiUpperCase_001);
577 CPPUNIT_TEST_SUITE_END();
578 }; // class replaceChar
580 class toAsciiUpperCase_WithLength : public CppUnit::TestFixture
582 void toAsciiUpperCase_WithLength_000()
584 rtl_str_toAsciiUpperCase_WithLength( nullptr, 0 );
587 void toAsciiUpperCase_WithLength_001()
589 OString aStr1 = "change this to ascii lower case.";
590 OString aShouldStr1 = "CHANGE THIs to ascii lower case.";
592 char* pStr = static_cast<char*>(malloc(aStr1.getLength() + 1));
593 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != nullptr);
595 strcpy(pStr, aStr1.getStr());
596 rtl_str_toAsciiUpperCase_WithLength( pStr, 10 );
598 printf("Uppercase with length: '%s'\n", aStr1.getStr());
599 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(OString(pStr)));
600 free(pStr);
603 // Change the following lines only, if you add, remove or rename
604 // member functions of the current class,
605 // because these macros are need by auto register mechanism.
607 CPPUNIT_TEST_SUITE(toAsciiUpperCase_WithLength);
608 CPPUNIT_TEST(toAsciiUpperCase_WithLength_000);
609 CPPUNIT_TEST(toAsciiUpperCase_WithLength_001);
610 CPPUNIT_TEST_SUITE_END();
611 }; // class replaceChar
613 class trim_WithLength : public CppUnit::TestFixture
615 void trim_WithLength_000()
617 rtl_str_trim_WithLength(nullptr, 0);
618 // should not GPF
621 void trim_WithLength_000_1()
623 char pStr[] = { " trim this" };
624 rtl_str_trim_WithLength( pStr, 0 );
627 void trim_WithLength_001()
629 char pStr[] = { " trim this" };
630 rtl_str_trim_WithLength( pStr, 2 );
632 CPPUNIT_ASSERT_EQUAL_MESSAGE("string should be empty", size_t(0), strlen(pStr));
635 void trim_WithLength_002()
637 char pStr[] = { "trim this" };
638 rtl_str_trim_WithLength( pStr, 5 );
640 CPPUNIT_ASSERT_EQUAL_MESSAGE("string should contain 'trim'", size_t(4), strlen(pStr));
643 void trim_WithLength_003()
645 char pStr[] = {" trim this"};
646 rtl_str_trim_WithLength( pStr, 11 );
648 CPPUNIT_ASSERT_EQUAL_MESSAGE("string should contain 'trim'", size_t(4), strlen(pStr));
651 void trim_WithLength_004()
653 char pStr[] = { "\r\n\t \n\r trim \n this" };
654 rtl_str_trim_WithLength( pStr, 17 );
656 CPPUNIT_ASSERT_EQUAL_MESSAGE("string should contain 'trim'", size_t(4), strlen(pStr));
659 void trim_WithLength_005()
661 char pStr[] = { "\r\n\t \n\r trim \t this \n\r\t\t " };
662 rtl_str_trim_WithLength( pStr, strlen(pStr) );
664 CPPUNIT_ASSERT_EQUAL_MESSAGE("string should contain 'trim \t this'", size_t(11), strlen(pStr));
667 // Change the following lines only, if you add, remove or rename
668 // member functions of the current class,
669 // because these macros are need by auto register mechanism.
671 CPPUNIT_TEST_SUITE(trim_WithLength);
672 CPPUNIT_TEST(trim_WithLength_000);
673 CPPUNIT_TEST(trim_WithLength_000_1);
674 CPPUNIT_TEST(trim_WithLength_001);
675 CPPUNIT_TEST(trim_WithLength_002);
676 CPPUNIT_TEST(trim_WithLength_003);
677 CPPUNIT_TEST(trim_WithLength_004);
678 CPPUNIT_TEST(trim_WithLength_005);
679 CPPUNIT_TEST_SUITE_END();
682 class valueOfChar : public CppUnit::TestFixture
684 void valueOfChar_001()
686 char pStr[RTL_STR_MAX_VALUEOFCHAR];
687 rtl_str_valueOfChar(pStr, 'A');
689 CPPUNIT_ASSERT_EQUAL_MESSAGE("string should contain 'A'", 'A', pStr[0]);
692 // Change the following lines only, if you add, remove or rename
693 // member functions of the current class,
694 // because these macros are need by auto register mechanism.
696 CPPUNIT_TEST_SUITE(valueOfChar);
697 CPPUNIT_TEST(valueOfChar_001);
698 CPPUNIT_TEST_SUITE_END();
701 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::compare);
702 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::compareIgnoreAsciiCase);
703 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::shortenedCompareIgnoreAsciiCase_WithLength);
704 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::hashCode);
706 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::indexOfChar);
707 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::lastIndexOfChar);
708 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::indexOfStr);
709 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::lastIndexOfStr);
711 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::replaceChar);
712 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::replaceChar_WithLength);
714 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::toAsciiLowerCase);
715 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::toAsciiLowerCase_WithLength);
716 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::toAsciiUpperCase);
717 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::toAsciiUpperCase_WithLength);
719 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::trim_WithLength);
720 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::valueOfChar);
722 } // namespace rtl_str
724 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */