diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2022-03-03 14:59:59 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-03-04 06:20:08 +0100 |
commit | eccbe009fd28f5b468267af853931b121b5601fd (patch) | |
tree | d343a1dcf5f45cf1954f98d6f3efdaf0f6b3bcba /sal | |
parent | c1b2ed31cbde0a81853ba4fe59841cded6c52105 (diff) |
Enable tests in rtl_str.cxx
And disable the tests that try to use nullptr where it's not accepted.
Change-Id: I1cd031e371485fdd57e7691565376253a01049c3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130938
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/CppunitTest_sal_rtl.mk | 1 | ||||
-rw-r--r-- | sal/qa/rtl/ostring/rtl_str.cxx | 382 |
2 files changed, 160 insertions, 223 deletions
diff --git a/sal/CppunitTest_sal_rtl.mk b/sal/CppunitTest_sal_rtl.mk index 02b6c94e3d1b..f35586b180c2 100644 --- a/sal/CppunitTest_sal_rtl.mk +++ b/sal/CppunitTest_sal_rtl.mk @@ -20,6 +20,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sal_rtl,\ sal/qa/rtl/doublelock/rtl_doublelocking \ sal/qa/rtl/locale/rtl_locale \ sal/qa/rtl/math/test-rtl-math \ + sal/qa/rtl/ostring/rtl_str \ sal/qa/rtl/oustringbuffer/test_oustringbuffer_appendchar \ sal/qa/rtl/oustringbuffer/test_oustringbuffer_appenduninitialized \ sal/qa/rtl/oustringbuffer/test_oustringbuffer_assign \ diff --git a/sal/qa/rtl/ostring/rtl_str.cxx b/sal/qa/rtl/ostring/rtl_str.cxx index 7cfabcab79be..b214b0ee41b4 100644 --- a/sal/qa/rtl/ostring/rtl_str.cxx +++ b/sal/qa/rtl/ostring/rtl_str.cxx @@ -30,25 +30,23 @@ namespace rtl_str class compare : public CppUnit::TestFixture { - public: - - void compare_000() - { - rtl_str_compare( NULL, NULL); - } - - void compare_000_1() - { - OString aStr1 = "Line must be equal."; - rtl_str_compare( aStr1.getStr(), NULL); - } +// void compare_000() +// { +// rtl_str_compare( nullptr, nullptr); +// } + +// void compare_000_1() +// { +// OString aStr1 = "Line must be equal."; +// rtl_str_compare( aStr1.getStr(), nullptr); +// } void compare_001() { OString aStr1 = ""; OString aStr2 = ""; sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr()); - CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal.", sal_Int32(0), nValue); } void compare_002() @@ -57,7 +55,7 @@ namespace rtl_str OString aStr2 = "Line must be equal."; sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr()); - CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal.", sal_Int32(0), nValue); } void compare_003() @@ -74,35 +72,33 @@ namespace rtl_str // because these macros are need by auto register mechanism. CPPUNIT_TEST_SUITE(compare); - CPPUNIT_TEST(compare_000); - CPPUNIT_TEST(compare_000_1); +// CPPUNIT_TEST(compare_000); // Commented out: null-terminated arguments cannot be null +// CPPUNIT_TEST(compare_000_1); // Commented out: null-terminated arguments cannot be null CPPUNIT_TEST(compare_001); CPPUNIT_TEST(compare_002); CPPUNIT_TEST(compare_003); CPPUNIT_TEST_SUITE_END(); -}; // class compare + }; // class compare class compareIgnoreAsciiCase : public CppUnit::TestFixture { - public: - - void compare_000() - { - rtl_str_compareIgnoreAsciiCase( NULL, NULL); - } - - void compare_000_1() - { - OString aStr1 = "Line must be equal."; - rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), NULL); - } +// void compare_000() +// { +// rtl_str_compareIgnoreAsciiCase( nullptr, nullptr); +// } + +// void compare_000_1() +// { +// OString aStr1 = "Line must be equal."; +// rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), nullptr); +// } void compare_001() { OString aStr1 = ""; OString aStr2 = ""; sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); - CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal.", sal_Int32(0), nValue); } void compare_002() @@ -111,7 +107,7 @@ namespace rtl_str OString aStr2 = "Line must be equal."; sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); - CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal.", sal_Int32(0), nValue); } void compare_002_1() @@ -120,7 +116,7 @@ namespace rtl_str OString aStr2 = "LINE MUST BE EQUAL."; sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); - CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitive).", nValue == 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal (if case insensitive).", sal_Int32(0), nValue); } void compare_003() @@ -137,8 +133,8 @@ namespace rtl_str // because these macros are need by auto register mechanism. CPPUNIT_TEST_SUITE(compareIgnoreAsciiCase); - CPPUNIT_TEST(compare_000); - CPPUNIT_TEST(compare_000_1); +// CPPUNIT_TEST(compare_000); // Commented out: null-terminated arguments cannot be null +// CPPUNIT_TEST(compare_000_1); // Commented out: null-terminated arguments cannot be null CPPUNIT_TEST(compare_001); CPPUNIT_TEST(compare_002); CPPUNIT_TEST(compare_002_1); @@ -148,17 +144,15 @@ namespace rtl_str class shortenedCompareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture { - public: - void compare_000() { - rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0, 0); + rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( nullptr, 0, nullptr, 0, 0); } void compare_000_1() { OString aStr1 = "Line must be equal."; - rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0, 1); + rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), nullptr, 0, 1); } void compare_001() { @@ -166,7 +160,7 @@ namespace rtl_str OString aStr2 = ""; sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), aStr2.getStr(), aStr2.getLength(), aStr1.getLength()); - CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal.", sal_Int32(0), nValue); } void compare_002() @@ -177,7 +171,7 @@ namespace rtl_str sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), aStr2.getStr(), aStr2.getLength(), aStr1.getLength()); - CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal.", sal_Int32(0), nValue); } void compare_002_1() @@ -188,7 +182,7 @@ namespace rtl_str sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), aStr2.getStr(), aStr2.getLength(), aStr1.getLength()); - CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitive).", nValue == 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal (if case insensitive).", sal_Int32(0), nValue); } void compare_003() @@ -199,7 +193,7 @@ namespace rtl_str sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), aStr2.getStr(), aStr2.getLength(), 5); - CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal first 5 characters.", nValue == 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal first 5 characters.", sal_Int32(0), nValue); } void compare_004() @@ -226,16 +220,14 @@ namespace rtl_str CPPUNIT_TEST(compare_003); CPPUNIT_TEST(compare_004); CPPUNIT_TEST_SUITE_END(); -}; // class compare + }; // class compare class hashCode : public CppUnit::TestFixture { - public: - - void hashCode_000() - { - rtl_str_hashCode( NULL ); - } +// void hashCode_000() +// { +// rtl_str_hashCode( nullptr ); +// } void hashCode_001() { @@ -253,7 +245,7 @@ namespace rtl_str OString aStr2 = "Line for a hashCode."; sal_Int32 nHashCode2 = rtl_str_hashCode( aStr2.getStr() ); - CPPUNIT_ASSERT_MESSAGE("hashcodes must be equal.", nHashCode1 == nHashCode2 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("hashcodes must be equal.", nHashCode1, nHashCode2 ); } void hashCode_003() @@ -272,7 +264,7 @@ namespace rtl_str // because these macros are need by auto register mechanism. CPPUNIT_TEST_SUITE(hashCode); - CPPUNIT_TEST(hashCode_000); +// CPPUNIT_TEST(hashCode_000); // Commented out: null-terminated arguments cannot be null CPPUNIT_TEST(hashCode_001); CPPUNIT_TEST(hashCode_002); CPPUNIT_TEST(hashCode_003); @@ -281,28 +273,26 @@ namespace rtl_str class indexOfChar : public CppUnit::TestFixture { - public: - - void indexOfChar_000() - { - rtl_str_indexOfChar( NULL, 0 ); - } +// void indexOfChar_000() +// { +// rtl_str_indexOfChar( nullptr, 0 ); +// } void indexOfChar_001() { OString aStr1 = "Line for an indexOfChar."; sal_Int32 nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'L' ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(0), nIndex); /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'i' ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(1), nIndex); /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'n' ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 2); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(2), nIndex); /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'e' ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 3); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(3), nIndex); } void indexOfChar_002() @@ -310,7 +300,7 @@ namespace rtl_str OString aStr1 = "Line for an indexOfChar."; sal_Int32 nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'y' ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(-1), nIndex); } // Change the following lines only, if you add, remove or rename @@ -318,7 +308,7 @@ namespace rtl_str // because these macros are need by auto register mechanism. CPPUNIT_TEST_SUITE(indexOfChar); - CPPUNIT_TEST(indexOfChar_000); +// CPPUNIT_TEST(indexOfChar_000); // Commented out: null-terminated arguments cannot be null CPPUNIT_TEST(indexOfChar_001); CPPUNIT_TEST(indexOfChar_002); CPPUNIT_TEST_SUITE_END(); @@ -326,28 +316,26 @@ namespace rtl_str class lastIndexOfChar : public CppUnit::TestFixture { - public: - - void lastIndexOfChar_000() - { - rtl_str_lastIndexOfChar( NULL, 0 ); - } +// void lastIndexOfChar_000() +// { +// rtl_str_lastIndexOfChar( nullptr, 0 ); +// } void lastIndexOfChar_001() { OString aStr1 = "Line for a lastIndexOfChar."; sal_Int32 nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'C' ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 22); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(22), nIndex); /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'h' ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 23); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(23), nIndex); /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'a' ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 24); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(24), nIndex); /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'r' ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 25); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(25), nIndex); } void lastIndexOfChar_002() @@ -355,7 +343,7 @@ namespace rtl_str OString aStr1 = "Line for a lastIndexOfChar."; sal_Int32 nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'y' ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(-1), nIndex); } // Change the following lines only, if you add, remove or rename @@ -363,7 +351,7 @@ namespace rtl_str // because these macros are need by auto register mechanism. CPPUNIT_TEST_SUITE(lastIndexOfChar); - CPPUNIT_TEST(lastIndexOfChar_000); +// CPPUNIT_TEST(lastIndexOfChar_000); // Commented out: null-terminated arguments cannot be null CPPUNIT_TEST(lastIndexOfChar_001); CPPUNIT_TEST(lastIndexOfChar_002); CPPUNIT_TEST_SUITE_END(); @@ -371,34 +359,32 @@ namespace rtl_str class indexOfStr : public CppUnit::TestFixture { - public: - - void indexOfStr_000() - { - rtl_str_indexOfStr( NULL, 0 ); - } +// void indexOfStr_000() +// { +// rtl_str_indexOfStr( nullptr, 0 ); +// } - void indexOfStr_000_1() - { - OString aStr1 = "Line for an indexOfStr."; - rtl_str_indexOfStr( aStr1.getStr(), 0 ); - } +// void indexOfStr_000_1() +// { +// OString aStr1 = "Line for an indexOfStr."; +// rtl_str_indexOfStr( aStr1.getStr(), 0 ); +// } void indexOfStr_001() { OString aStr1 = "Line for an indexOfStr."; sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "Line" ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(0), nIndex); /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "for" ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 5); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(5), nIndex); /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "a" ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 9); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(9), nIndex); /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "an index" ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex ==9); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(9), nIndex); } void indexOfStr_002() @@ -406,7 +392,7 @@ namespace rtl_str OString aStr1 = "Line for an indexOfStr."; sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "not exist" ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(-1), nIndex); } // Change the following lines only, if you add, remove or rename @@ -414,7 +400,7 @@ namespace rtl_str // because these macros are need by auto register mechanism. CPPUNIT_TEST_SUITE(indexOfStr); - CPPUNIT_TEST(indexOfStr_000); +// CPPUNIT_TEST(indexOfStr_000); // Commented out: null-terminated arguments cannot be null CPPUNIT_TEST(indexOfStr_001); CPPUNIT_TEST(indexOfStr_002); CPPUNIT_TEST_SUITE_END(); @@ -422,18 +408,16 @@ namespace rtl_str class lastIndexOfStr : public CppUnit::TestFixture { - public: - - void lastIndexOfStr_000() - { - rtl_str_lastIndexOfStr( NULL, NULL ); - } +// void lastIndexOfStr_000() +// { +// rtl_str_lastIndexOfStr( nullptr, nullptr ); +// } - void lastIndexOfStr_000_1() - { - OString aStr1 = "Line for a lastIndexOfStr."; - rtl_str_lastIndexOfStr( aStr1.getStr(), NULL ); - } +// void lastIndexOfStr_000_1() +// { +// OString aStr1 = "Line for a lastIndexOfStr."; +// rtl_str_lastIndexOfStr( aStr1.getStr(), nullptr ); +// } void lastIndexOfStr_001() { @@ -441,15 +425,15 @@ namespace rtl_str OString aSearchStr = "Index"; sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 15); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(15), nIndex); /* OString */ aSearchStr = "Line"; /* sal_Int32 */ nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(0), nIndex); /* OString */ aSearchStr = ""; /* sal_Int32 */ nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(-1), nIndex); } void lastIndexOfStr_002() @@ -458,7 +442,7 @@ namespace rtl_str OString aSearchStr = "foo"; sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(-1), nIndex); } void lastIndexOfStr_003() @@ -467,7 +451,7 @@ namespace rtl_str OString aSearchStr = "O"; sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); - CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 20 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(20), nIndex); } // Change the following lines only, if you add, remove or rename @@ -475,7 +459,7 @@ namespace rtl_str // because these macros are need by auto register mechanism. CPPUNIT_TEST_SUITE(lastIndexOfStr); - CPPUNIT_TEST(lastIndexOfStr_000); +// CPPUNIT_TEST(lastIndexOfStr_000); // Commented out: null-terminated arguments cannot be null CPPUNIT_TEST(lastIndexOfStr_001); CPPUNIT_TEST(lastIndexOfStr_002); CPPUNIT_TEST(lastIndexOfStr_003); @@ -484,25 +468,23 @@ namespace rtl_str class replaceChar : public CppUnit::TestFixture { - public: - - void replaceChar_000() - { - rtl_str_replaceChar( NULL, 0, 0 ); - } +// void replaceChar_000() +// { +// rtl_str_replaceChar( nullptr, 0, 0 ); +// } void replaceChar_001() { OString aStr1 = "replace char."; OString aShouldStr1 = "ruplacu char."; - char* pStr = (char*) malloc(aStr1.getLength() + 1); - CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + char* pStr = static_cast<char*>(malloc(aStr1.getLength() + 1)); + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != nullptr); strcpy(pStr, aStr1.getStr()); rtl_str_replaceChar( pStr, 'e', 'u' ); - CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(OString(pStr)) == sal_True); + CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(OString(pStr))); free(pStr); } @@ -511,36 +493,34 @@ namespace rtl_str // because these macros are need by auto register mechanism. CPPUNIT_TEST_SUITE(replaceChar); - CPPUNIT_TEST(replaceChar_000); +// CPPUNIT_TEST(replaceChar_000); // Commented out: null-terminated arguments cannot be null CPPUNIT_TEST(replaceChar_001); CPPUNIT_TEST_SUITE_END(); }; // class replaceChar class replaceChar_WithLength : public CppUnit::TestFixture { - public: - void replaceChar_WithLength_000() { - rtl_str_replaceChar_WithLength( NULL, 0, 0, 0 ); + rtl_str_replaceChar_WithLength( nullptr, 0, 0, 0 ); } - void replaceChar_WithLength_000_1() - { - rtl_str_replaceChar_WithLength( NULL, 1, 0, 0 ); - } +// void replaceChar_WithLength_000_1() +// { +// rtl_str_replaceChar_WithLength( nullptr, 1, 0, 0 ); +// } void replaceChar_WithLength_001() { OString aStr1 = "replace char."; OString aShouldStr1 = "ruplace char."; - char* pStr = (char*) malloc(aStr1.getLength() + 1); - CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + char* pStr = static_cast<char*>(malloc(aStr1.getLength() + 1)); + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != nullptr); strcpy(pStr, aStr1.getStr()); rtl_str_replaceChar_WithLength( pStr, 6, 'e', 'u' ); - CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(OString(pStr)) == sal_True); + CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(OString(pStr))); free(pStr); } @@ -550,32 +530,30 @@ namespace rtl_str CPPUNIT_TEST_SUITE(replaceChar_WithLength); CPPUNIT_TEST(replaceChar_WithLength_000); - CPPUNIT_TEST(replaceChar_WithLength_000_1); +// CPPUNIT_TEST(replaceChar_WithLength_000_1); // Commented out: when length is not 0, string can't be null CPPUNIT_TEST(replaceChar_WithLength_001); CPPUNIT_TEST_SUITE_END(); }; // class replaceChar class toAsciiLowerCase : public CppUnit::TestFixture { - public: - - void toAsciiLowerCase_000() - { - rtl_str_toAsciiLowerCase( NULL ); - } +// void toAsciiLowerCase_000() +// { +// rtl_str_toAsciiLowerCase( nullptr ); +// } void toAsciiLowerCase_001() { OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE."; OString aShouldStr1 = "change this to ascii lower case."; - char* pStr = (char*) malloc(aStr1.getLength() + 1); - CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + char* pStr = static_cast<char*>(malloc(aStr1.getLength() + 1)); + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != nullptr); strcpy(pStr, aStr1.getStr()); rtl_str_toAsciiLowerCase( pStr ); - CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(OString(pStr)) == sal_True); + CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(OString(pStr))); free(pStr); } @@ -584,18 +562,16 @@ namespace rtl_str // because these macros are need by auto register mechanism. CPPUNIT_TEST_SUITE(toAsciiLowerCase); - CPPUNIT_TEST(toAsciiLowerCase_000); +// CPPUNIT_TEST(toAsciiLowerCase_000); // Commented out: null-terminated arguments cannot be null CPPUNIT_TEST(toAsciiLowerCase_001); CPPUNIT_TEST_SUITE_END(); }; // class replaceChar class toAsciiLowerCase_WithLength : public CppUnit::TestFixture { - public: - void toAsciiLowerCase_WithLength_000() { - rtl_str_toAsciiLowerCase_WithLength( NULL, 0 ); + rtl_str_toAsciiLowerCase_WithLength( nullptr, 0 ); } void toAsciiLowerCase_WithLength_001() @@ -603,14 +579,14 @@ namespace rtl_str OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE."; OString aShouldStr1 = "change thiS TO ASCII LOWER CASE."; - char* pStr = (char*) malloc(aStr1.getLength() + 1); - CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + char* pStr = static_cast<char*>(malloc(aStr1.getLength() + 1)); + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != nullptr); strcpy(pStr, aStr1.getStr()); rtl_str_toAsciiLowerCase_WithLength( pStr, 10 ); printf("Lowercase with length: '%s'\n", pStr); - CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(OString(pStr)) == sal_True); + CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(OString(pStr))); free(pStr); } @@ -626,25 +602,23 @@ namespace rtl_str class toAsciiUpperCase : public CppUnit::TestFixture { - public: - - void toAsciiUpperCase_000() - { - rtl_str_toAsciiUpperCase( NULL ); - } +// void toAsciiUpperCase_000() +// { +// rtl_str_toAsciiUpperCase( nullptr ); +// } void toAsciiUpperCase_001() { OString aStr1 = "change this to ascii upper case."; OString aShouldStr1 = "CHANGE THIS TO ASCII UPPER CASE."; - char* pStr = (char*) malloc(aStr1.getLength() + 1); - CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + char* pStr = static_cast<char*>(malloc(aStr1.getLength() + 1)); + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != nullptr); strcpy(pStr, aStr1.getStr()); rtl_str_toAsciiUpperCase( pStr ); - CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(OString(pStr)) == sal_True); + CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(OString(pStr))); free(pStr); } @@ -653,18 +627,16 @@ namespace rtl_str // because these macros are need by auto register mechanism. CPPUNIT_TEST_SUITE(toAsciiUpperCase); - CPPUNIT_TEST(toAsciiUpperCase_000); +// CPPUNIT_TEST(toAsciiUpperCase_000); // Commented out: null-terminated arguments cannot be null CPPUNIT_TEST(toAsciiUpperCase_001); CPPUNIT_TEST_SUITE_END(); }; // class replaceChar class toAsciiUpperCase_WithLength : public CppUnit::TestFixture { - public: - void toAsciiUpperCase_WithLength_000() { - rtl_str_toAsciiUpperCase_WithLength( NULL, 0 ); + rtl_str_toAsciiUpperCase_WithLength( nullptr, 0 ); } void toAsciiUpperCase_WithLength_001() @@ -672,14 +644,14 @@ namespace rtl_str OString aStr1 = "change this to ascii lower case."; OString aShouldStr1 = "CHANGE THIs to ascii lower case."; - char* pStr = (char*) malloc(aStr1.getLength() + 1); - CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + char* pStr = static_cast<char*>(malloc(aStr1.getLength() + 1)); + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != nullptr); strcpy(pStr, aStr1.getStr()); rtl_str_toAsciiUpperCase_WithLength( pStr, 10 ); printf("Uppercase with length: '%s'\n", aStr1.getStr()); - CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(OString(pStr)) == sal_True); + CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(OString(pStr))); free(pStr); } @@ -695,10 +667,9 @@ namespace rtl_str class trim_WithLength : public CppUnit::TestFixture { - public: void trim_WithLength_000() { - rtl_str_trim_WithLength(NULL, 0); + rtl_str_trim_WithLength(nullptr, 0); // should not GPF } @@ -710,68 +681,42 @@ namespace rtl_str void trim_WithLength_001() { - char const *pStr = " trim this"; - char *pStr2 = strdup(pStr); - if (pStr2) - { - rtl_str_trim_WithLength( pStr2, 2 ); + char pStr[] = { " trim this" }; + rtl_str_trim_WithLength( pStr, 2 ); - CPPUNIT_ASSERT_MESSAGE("string should be empty", strlen(pStr2) == 0); - free(pStr2); - } + CPPUNIT_ASSERT_EQUAL_MESSAGE("string should be empty", size_t(0), strlen(pStr)); } void trim_WithLength_002() { - char const *pStr = "trim this"; - char *pStr2 = strdup(pStr); - if (pStr2) - { - rtl_str_trim_WithLength( pStr2, 5 ); + char pStr[] = { "trim this" }; + rtl_str_trim_WithLength( pStr, 5 ); - CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4); - free(pStr2); - } + CPPUNIT_ASSERT_EQUAL_MESSAGE("string should contain 'trim'", size_t(4), strlen(pStr)); } void trim_WithLength_003() { - char const *pStr = " trim this"; - char *pStr2 = strdup(pStr); - if (pStr2) - { - strcpy(pStr2, pStr); - rtl_str_trim_WithLength( pStr2, 11 ); + char pStr[] = {" trim this"}; + rtl_str_trim_WithLength( pStr, 11 ); - CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4); - free(pStr2); - } + CPPUNIT_ASSERT_EQUAL_MESSAGE("string should contain 'trim'", size_t(4), strlen(pStr)); } void trim_WithLength_004() { - char const *pStr = "\r\n\t \n\r trim \n this"; - char *pStr2 = strdup(pStr); - if (pStr2) - { - rtl_str_trim_WithLength( pStr2, 17 ); + char pStr[] = { "\r\n\t \n\r trim \n this" }; + rtl_str_trim_WithLength( pStr, 17 ); - CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4); - free(pStr2); - } + CPPUNIT_ASSERT_EQUAL_MESSAGE("string should contain 'trim'", size_t(4), strlen(pStr)); } void trim_WithLength_005() { - char const *pStr = "\r\n\t \n\r trim \t this \n\r\t\t "; - char *pStr2 = strdup(pStr); - if (pStr2) - { - rtl_str_trim_WithLength( pStr2, strlen(pStr2) ); + char pStr[] = { "\r\n\t \n\r trim \t this \n\r\t\t " }; + rtl_str_trim_WithLength( pStr, strlen(pStr) ); - CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 11); - free(pStr2); - } + CPPUNIT_ASSERT_EQUAL_MESSAGE("string should contain 'trim \t this'", size_t(11), strlen(pStr)); } // Change the following lines only, if you add, remove or rename @@ -791,22 +736,17 @@ namespace rtl_str class valueOfChar : public CppUnit::TestFixture { - public: - void valueOfChar_000() - { - rtl_str_valueOfChar(NULL, 0); - // should not GPF - } +// void valueOfChar_000() +// { +// rtl_str_valueOfChar(nullptr, 0); +// // should not GPF +// } void valueOfChar_001() { - char *pStr = (char*)malloc(RTL_STR_MAX_VALUEOFCHAR); - if (pStr) - { - rtl_str_valueOfChar(pStr, 'A'); + char pStr[RTL_STR_MAX_VALUEOFCHAR]; + rtl_str_valueOfChar(pStr, 'A'); - CPPUNIT_ASSERT_MESSAGE("string should contain 'A'", pStr[0] == 'A'); - free(pStr); - } + CPPUNIT_ASSERT_EQUAL_MESSAGE("string should contain 'A'", 'A', pStr[0]); } // Change the following lines only, if you add, remove or rename @@ -814,7 +754,7 @@ namespace rtl_str // because these macros are need by auto register mechanism. CPPUNIT_TEST_SUITE(valueOfChar); - CPPUNIT_TEST(valueOfChar_000); +// CPPUNIT_TEST(valueOfChar_000); // Commented out: null-terminated arguments cannot be null CPPUNIT_TEST(valueOfChar_001); CPPUNIT_TEST_SUITE_END(); }; @@ -842,8 +782,4 @@ CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::valueOfChar); } // namespace rtl_str -// this macro creates an empty function, which will called by the RegisterAllFunctions() -// to let the user the possibility to also register some functions by hand. -CPPUNIT_PLUGIN_IMPLEMENT(); - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |