diff options
Diffstat (limited to '')
-rw-r--r-- | sal/qa/rtl/ostring/rtl_OString2.cxx | 508 | ||||
-rw-r--r-- | sal/qa/rtl/ostring/rtl_str.cxx | 724 | ||||
-rw-r--r-- | sal/qa/rtl/ostring/rtl_str.xsce | 43 | ||||
-rw-r--r-- | sal/qa/rtl/ostring/rtl_string.cxx | 169 | ||||
-rw-r--r-- | sal/qa/rtl/ostring/rtl_string.xsce | 18 |
5 files changed, 1462 insertions, 0 deletions
diff --git a/sal/qa/rtl/ostring/rtl_OString2.cxx b/sal/qa/rtl/ostring/rtl_OString2.cxx new file mode 100644 index 000000000..204475084 --- /dev/null +++ b/sal/qa/rtl/ostring/rtl_OString2.cxx @@ -0,0 +1,508 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <rtl/string.hxx> + +#include "valueequal.hxx" + +namespace rtl_OString +{ + +class valueOf : public CppUnit::TestFixture +{ + void valueOf_float_test_impl(float _nValue) + { + OString sValue; + sValue = OString::valueOf( _nValue ); + printf("nFloat := %.9f sValue := %s\n", _nValue, sValue.getStr()); + + float nValueATOF = static_cast<float>(atof( sValue.getStr() )); + + bool bEqualResult = is_float_equal(_nValue, nValueATOF); + CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true); + } + + void valueOf_float_test(float _nValue) + { + valueOf_float_test_impl(_nValue); + + // test also the negative part. + float nNegativeValue = -_nValue; + valueOf_float_test_impl(nNegativeValue); + } + +public: + // insert your test code here. + void valueOf_float_test_001() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + float nValue = 3.0f; + valueOf_float_test(nValue); + } + + void valueOf_float_test_002() + { + float nValue = 3.5f; + valueOf_float_test(nValue); + } + + void valueOf_float_test_003() + { + float nValue = 3.0625f; + valueOf_float_test(nValue); + } + + void valueOf_float_test_004() + { + float nValue = 3.502525f; + valueOf_float_test(nValue); + } + + void valueOf_float_test_005() + { + float nValue = 3.141592f; + valueOf_float_test(nValue); + } + + void valueOf_float_test_006() + { + float nValue = 3.5025255f; + valueOf_float_test(nValue); + } + + void valueOf_float_test_007() + { + float nValue = 3.0039062f; + valueOf_float_test(nValue); + } + +private: + + void valueOf_double_test_impl(double _nValue) + { + OString sValue; + sValue = OString::valueOf( _nValue ); + printf("nDouble := %.20f sValue := %s\n", _nValue, sValue.getStr()); + + double nValueATOF = atof( sValue.getStr() ); + + bool bEqualResult = is_double_equal(_nValue, nValueATOF); + CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true); + } + + void valueOf_double_test(double _nValue) + { + valueOf_double_test_impl(_nValue); + + // test also the negative part. + double nNegativeValue = -_nValue; + valueOf_double_test_impl(nNegativeValue); + } +public: + + // valueOf double + void valueOf_double_test_001() + { + double nValue = 3.0; + valueOf_double_test(nValue); + } + void valueOf_double_test_002() + { + double nValue = 3.5; + valueOf_double_test(nValue); + } + void valueOf_double_test_003() + { + double nValue = 3.0625; + valueOf_double_test(nValue); + } + void valueOf_double_test_004() + { + double nValue = 3.1415926535; + valueOf_double_test(nValue); + } + void valueOf_double_test_005() + { + double nValue = 3.141592653589793; + valueOf_double_test(nValue); + } + void valueOf_double_test_006() + { + double nValue = 3.1415926535897932; + valueOf_double_test(nValue); + } + void valueOf_double_test_007() + { + double nValue = 3.14159265358979323; + valueOf_double_test(nValue); + } + void valueOf_double_test_008() + { + double nValue = 3.141592653589793238462643; + valueOf_double_test(nValue); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(valueOf); + CPPUNIT_TEST(valueOf_float_test_001); + CPPUNIT_TEST(valueOf_float_test_002); + CPPUNIT_TEST(valueOf_float_test_003); + CPPUNIT_TEST(valueOf_float_test_004); + CPPUNIT_TEST(valueOf_float_test_005); + CPPUNIT_TEST(valueOf_float_test_006); + CPPUNIT_TEST(valueOf_float_test_007); + + CPPUNIT_TEST(valueOf_double_test_001); + CPPUNIT_TEST(valueOf_double_test_002); + CPPUNIT_TEST(valueOf_double_test_003); + CPPUNIT_TEST(valueOf_double_test_004); + CPPUNIT_TEST(valueOf_double_test_005); + CPPUNIT_TEST(valueOf_double_test_006); + CPPUNIT_TEST(valueOf_double_test_007); + CPPUNIT_TEST(valueOf_double_test_008); + CPPUNIT_TEST_SUITE_END(); +}; // class valueOf + +// - toDouble (tests) + +class toDouble : public CppUnit::TestFixture +{ + +public: + + toDouble() + { + // testPrecision a; + } + + void toDouble_test_impl(OString const& _sValue) + { + double nValueATOF = atof( _sValue.getStr() ); + + // OUString suValue = OUString::createFromAscii( _sValue.getStr() ); + double nValueToDouble = _sValue.toDouble(); + + bool bEqualResult = is_double_equal(nValueToDouble, nValueATOF); + CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true); + } + + void toDouble_test(OString const& _sValue) + { + toDouble_test_impl(_sValue); + + // test also the negative part. + OString sNegativValue("-"); + sNegativValue += _sValue; + toDouble_test_impl(sNegativValue); + } + + // insert your test code here. + void toDouble_selftest() + { + printf("Start selftest:\n"); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.01) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.0001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.00001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.000001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000000001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000000001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000000001) == false); + // we check til 14 values after comma + CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000000000001) == true); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000000000001) == true); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000000000001) == true); + printf("Selftest done.\n"); + } + + void toDouble_test_3() + { + OString sValue("3"); + toDouble_test(sValue); + } + void toDouble_test_3_5() + { + OString sValue("3.5"); + toDouble_test(sValue); + } + void toDouble_test_3_0625() + { + OString sValue("3.0625"); + toDouble_test(sValue); + } + void toDouble_test_pi() + { + // value from http://www.angio.net/pi/digits/50.txt + OString sValue("3.141592653589793238462643383279502884197169399375"); + toDouble_test(sValue); + } + + void toDouble_test_1() + { + OString sValue("1"); + toDouble_test(sValue); + } + void toDouble_test_10() + { + OString sValue("10"); + toDouble_test(sValue); + } + void toDouble_test_100() + { + OString sValue("100"); + toDouble_test(sValue); + } + void toDouble_test_1000() + { + OString sValue("1000"); + toDouble_test(sValue); + } + void toDouble_test_10000() + { + OString sValue("10000"); + toDouble_test(sValue); + } + void toDouble_test_1e99() + { + OString sValue("1e99"); + toDouble_test(sValue); + } + void toDouble_test_1e_n99() + { + OString sValue("1e-99"); + toDouble_test(sValue); + } + void toDouble_test_1e308() + { + OString sValue("1e308"); + toDouble_test(sValue); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(toDouble); + CPPUNIT_TEST(toDouble_selftest); + + CPPUNIT_TEST(toDouble_test_3); + CPPUNIT_TEST(toDouble_test_3_5); + CPPUNIT_TEST(toDouble_test_3_0625); + CPPUNIT_TEST(toDouble_test_pi); + CPPUNIT_TEST(toDouble_test_1); + CPPUNIT_TEST(toDouble_test_10); + CPPUNIT_TEST(toDouble_test_100); + CPPUNIT_TEST(toDouble_test_1000); + CPPUNIT_TEST(toDouble_test_10000); + CPPUNIT_TEST(toDouble_test_1e99); + CPPUNIT_TEST(toDouble_test_1e_n99); + CPPUNIT_TEST(toDouble_test_1e308); + CPPUNIT_TEST_SUITE_END(); +}; // class toDouble + +// - getToken (tests) + +class getToken : public CppUnit::TestFixture +{ + +public: + void getToken_000() + { + OString sTokenStr; + + sal_Int32 nIndex = 0; + do + { + OString sToken = sTokenStr.getToken( 0, ';', nIndex ); + } + while ( nIndex >= 0 ); + // printf("Index %d\n", nIndex); + // should not GPF + } + + void getToken_001() + { + OString sTokenStr = "a;b"; + + sal_Int32 nIndex = 0; + + OString sToken = sTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'a'", sToken.equals("a") == sal_True); + + /* OString */ sToken = sTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'b'", sToken.equals("b") == sal_True); + CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1); + } + + void getToken_002() + { + OString sTokenStr = "a;b.c"; + + sal_Int32 nIndex = 0; + + OString sToken = sTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'a'", sToken.equals("a") == sal_True); + + /* OString */ sToken = sTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'b'", sToken.equals("b") == sal_True); + + /* OString */ sToken = sTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'c'", sToken.equals("c") == sal_True); + CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1); + } + + void getToken_003() + { + OString sTokenStr = "a;;b"; + + sal_Int32 nIndex = 0; + + OString sToken = sTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'a'", sToken.equals("a") == sal_True); + + /* OString */ sToken = sTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be empty", sToken.isEmpty()); + + /* OString */ sToken = sTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'b'", sToken.equals("b") == sal_True); + CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1); + } + + void getToken_004() + { + OString sTokenStr = "longer.then.ever."; + + sal_Int32 nIndex = 0; + + OString sToken = sTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be 'longer'", sToken.equals("longer") == sal_True); + + /* OString */ sToken = sTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be 'then'", sToken.equals("then") == sal_True); + + /* OString */ sToken = sTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be 'ever'", sToken.equals("ever") == sal_True); + + /* OString */ sToken = sTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be empty", sToken.isEmpty()); + + CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1); + } + + CPPUNIT_TEST_SUITE(getToken); + CPPUNIT_TEST(getToken_000); + CPPUNIT_TEST(getToken_001); + CPPUNIT_TEST(getToken_002); + CPPUNIT_TEST(getToken_003); + CPPUNIT_TEST(getToken_004); + CPPUNIT_TEST_SUITE_END(); +}; // class getToken + +// testing the method replaceAt( sal_Int32 index, sal_Int32 count, +// const OString& newStr ) + +// Developer note: Mindy Liu, 2004-04-23 +// stolen from sal/qa/rtl_strings/rtl_OString.cxx + +class replaceAt : public CppUnit::TestFixture +{ + +public: + sal_Bool check_replaceAt( const OString* expVal, const OString* input, + const OString* newStr, sal_Int32 index, sal_Int32 count) + { + OString aStr1; + aStr1= input->replaceAt( index, count, *newStr ); + + printf("the result OString is %s#\n", aStr1.getStr() ); + + sal_Bool bRes = ( expVal->compareTo(aStr1) == 0 ); + return bRes; + } + + void replaceAt_001() + { + sal_Bool bRes = check_replaceAt(new OString("Java@Sun"), + new OString("Sun java"), new OString("Java@Sun"), 0, 8 ); + CPPUNIT_ASSERT_MESSAGE("string differs, replace whole string", bRes == sal_True); + } + + void replaceAt_002() + { + sal_Bool bRes = check_replaceAt(new OString("Sun Java desktop system"), + new OString("Sun "), new OString("Java desktop system"), 10, 8 ); + CPPUNIT_ASSERT_MESSAGE("index > length of input string", bRes == sal_True); + } + + void replaceAt_003() + { + sal_Bool bRes = check_replaceAt(new OString("SuJava desktop system"), + new OString("Sun "), new OString("Java desktop system"), 2, 64 ); + CPPUNIT_ASSERT_MESSAGE("larger count", bRes == sal_True); + } + + void replaceAt_004() + { + + sal_Bool bRes = check_replaceAt(new OString("Java desktop system"), + new OString("Sun "), new OString("Java desktop system"), -4, 8 ); + CPPUNIT_ASSERT_MESSAGE("navigate index", bRes == sal_True); + } + void replaceAt_005() + { + + sal_Bool bRes = check_replaceAt(new OString("Sun Jesktop System"), + new OString("Sun Java Desktop System"), new OString(""), 5, 5 ); + CPPUNIT_ASSERT_MESSAGE("replace with null string", bRes == sal_True); + } + + CPPUNIT_TEST_SUITE(replaceAt); + CPPUNIT_TEST(replaceAt_001); + CPPUNIT_TEST(replaceAt_002); + CPPUNIT_TEST(replaceAt_003); + CPPUNIT_TEST(replaceAt_004); + CPPUNIT_TEST(replaceAt_005); + CPPUNIT_TEST_SUITE_END(); +}; // class replaceAt + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OString::valueOf); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OString::toDouble); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OString::getToken); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OString::replaceAt); + +} // namespace rtl_OString + +// 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: */ diff --git a/sal/qa/rtl/ostring/rtl_str.cxx b/sal/qa/rtl/ostring/rtl_str.cxx new file mode 100644 index 000000000..f7af22008 --- /dev/null +++ b/sal/qa/rtl/ostring/rtl_str.cxx @@ -0,0 +1,724 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <rtl/string.hxx> +#include <cstring> + +namespace rtl_str +{ + + class compare : public CppUnit::TestFixture + { + void compare_001() + { + OString aStr1 = ""; + OString aStr2 = ""; + + sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal.", sal_Int32(0), nValue); + } + + void compare_002() + { + OString aStr1 = "Line must be equal."; + OString aStr2 = "Line must be equal."; + + sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal.", sal_Int32(0), nValue); + } + + void compare_003() + { + OString aStr1 = "Line must differ."; + OString aStr2 = "Line foo bar, ok, differ."; + + sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(compare); + CPPUNIT_TEST(compare_001); + CPPUNIT_TEST(compare_002); + CPPUNIT_TEST(compare_003); + CPPUNIT_TEST_SUITE_END(); + }; // class compare + + class compareIgnoreAsciiCase : public CppUnit::TestFixture + { + void compare_001() + { + OString aStr1 = ""; + OString aStr2 = ""; + + sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal.", sal_Int32(0), nValue); + } + + void compare_002() + { + OString aStr1 = "Line must be equal."; + OString aStr2 = "Line must be equal."; + + sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal.", sal_Int32(0), nValue); + } + + void compare_002_1() + { + OString aStr1 = "Line must be equal."; + OString aStr2 = "LINE MUST BE EQUAL."; + + sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal (if case insensitive).", sal_Int32(0), nValue); + } + + void compare_003() + { + OString aStr1 = "Line must differ."; + OString aStr2 = "Line foo bar, ok, differ."; + + sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(compareIgnoreAsciiCase); + CPPUNIT_TEST(compare_001); + CPPUNIT_TEST(compare_002); + CPPUNIT_TEST(compare_002_1); + CPPUNIT_TEST(compare_003); + CPPUNIT_TEST_SUITE_END(); + }; // class compareIgnoreAsciiCase + + class shortenedCompareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture + { + void compare_000() + { + 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(), nullptr, 0, 1); + } + void compare_001() + { + OString aStr1 = ""; + OString aStr2 = ""; + + sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), aStr2.getStr(), aStr2.getLength(), aStr1.getLength()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal.", sal_Int32(0), nValue); + } + + void compare_002() + { + OString aStr1 = "Line must be equal."; + OString aStr2 = "Line must be equal."; + + sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), + aStr2.getStr(), aStr2.getLength(), + aStr1.getLength()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal.", sal_Int32(0), nValue); + } + + void compare_002_1() + { + OString aStr1 = "Line must be equal."; + OString aStr2 = "LINE MUST BE EQUAL."; + + sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), + aStr2.getStr(), aStr2.getLength(), + aStr1.getLength()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal (if case insensitive).", sal_Int32(0), nValue); + } + + void compare_003() + { + OString aStr1 = "Line must differ."; + OString aStr2 = "Line foo bar, ok, differ."; + + sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), + aStr2.getStr(), aStr2.getLength(), + 5); + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare failed, strings are equal first 5 characters.", sal_Int32(0), nValue); + } + + void compare_004() + { + OString aStr1 = "Line must differ."; + OString aStr2 = "Line foo bar, ok, differ."; + + sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), + aStr2.getStr(), aStr2.getLength(), + aStr1.getLength()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(shortenedCompareIgnoreAsciiCase_WithLength); + CPPUNIT_TEST(compare_000); + CPPUNIT_TEST(compare_000_1); + CPPUNIT_TEST(compare_001); + CPPUNIT_TEST(compare_002); + CPPUNIT_TEST(compare_002_1); + CPPUNIT_TEST(compare_003); + CPPUNIT_TEST(compare_004); + CPPUNIT_TEST_SUITE_END(); + }; // class compare + + class hashCode : public CppUnit::TestFixture + { + void hashCode_001() + { + OString aStr1 = "Line for a hashCode."; + sal_Int32 nHashCode = rtl_str_hashCode( aStr1.getStr() ); + printf("hashcode: %" SAL_PRIdINT32 "\n", nHashCode); + // CPPUNIT_ASSERT_MESSAGE("failed.", nValue == 0); + } + + void hashCode_002() + { + OString aStr1 = "Line for a hashCode."; + sal_Int32 nHashCode1 = rtl_str_hashCode( aStr1.getStr() ); + + OString aStr2 = "Line for a hashCode."; + sal_Int32 nHashCode2 = rtl_str_hashCode( aStr2.getStr() ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("hashcodes must be equal.", nHashCode1, nHashCode2 ); + } + + void hashCode_003() + { + OString aStr1 = "Line for a hashCode."; + sal_Int32 nHashCode1 = rtl_str_hashCode( aStr1.getStr() ); + + OString aStr2 = "Line for another hashcode."; + sal_Int32 nHashCode2 = rtl_str_hashCode( aStr2.getStr() ); + + CPPUNIT_ASSERT_MESSAGE("hashcodes must differ.", nHashCode1 != nHashCode2 ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(hashCode); + CPPUNIT_TEST(hashCode_001); + CPPUNIT_TEST(hashCode_002); + CPPUNIT_TEST(hashCode_003); + CPPUNIT_TEST_SUITE_END(); + }; // class compare + + class indexOfChar : public CppUnit::TestFixture + { + void indexOfChar_000() + { + sal_Int32 nIndex = rtl_str_indexOfChar("", 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Trailing zero character is not part of the string", + sal_Int32(-1), nIndex); + } + + void indexOfChar_001() + { + OString aStr1 = "Line for an indexOfChar."; + + sal_Int32 nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'L' ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(0), nIndex); + + /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'i' ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(1), nIndex); + + /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'n' ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(2), nIndex); + + /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'e' ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(3), nIndex); + } + + void indexOfChar_002() + { + OString aStr1 = "Line for an indexOfChar."; + sal_Int32 nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'y' ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(-1), nIndex); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(indexOfChar); + CPPUNIT_TEST(indexOfChar_000); + CPPUNIT_TEST(indexOfChar_001); + CPPUNIT_TEST(indexOfChar_002); + CPPUNIT_TEST_SUITE_END(); + }; // class compare + + class lastIndexOfChar : public CppUnit::TestFixture + { + void lastIndexOfChar_000() + { + sal_Int32 nIndex = rtl_str_lastIndexOfChar("", 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Trailing zero character is not part of the string", + sal_Int32(-1), nIndex); + } + + void lastIndexOfChar_001() + { + OString aStr1 = "Line for a lastIndexOfChar."; + + sal_Int32 nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'C' ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(22), nIndex); + + /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'h' ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(23), nIndex); + + /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'a' ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(24), nIndex); + + /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'r' ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(25), nIndex); + } + + void lastIndexOfChar_002() + { + OString aStr1 = "Line for a lastIndexOfChar."; + sal_Int32 nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'y' ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(-1), nIndex); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(lastIndexOfChar); + CPPUNIT_TEST(lastIndexOfChar_000); + CPPUNIT_TEST(lastIndexOfChar_001); + CPPUNIT_TEST(lastIndexOfChar_002); + CPPUNIT_TEST_SUITE_END(); + }; // class lastIndexOfChar + + class indexOfStr : public CppUnit::TestFixture + { + void indexOfStr_000() + { + OString aStr1("Line for an indexOfStr."); + sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "" ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("an empty substring is always not findable", + sal_Int32(-1), nIndex); + } + + void indexOfStr_001() + { + OString aStr1 = "Line for an indexOfStr."; + + sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "Line" ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(0), nIndex); + + /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "for" ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(5), nIndex); + + /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "a" ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(9), nIndex); + + /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "an index" ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(9), nIndex); + } + + void indexOfStr_002() + { + OString aStr1 = "Line for an indexOfStr."; + sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "not exist" ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(-1), nIndex); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(indexOfStr); + CPPUNIT_TEST(indexOfStr_000); + CPPUNIT_TEST(indexOfStr_001); + CPPUNIT_TEST(indexOfStr_002); + CPPUNIT_TEST_SUITE_END(); + }; // class compare + + class lastIndexOfStr : public CppUnit::TestFixture + { + void lastIndexOfStr_000() + { + OString aStr1("Line for a lastIndexOfStr."); + sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), "" ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("an empty substring is always not findable", + sal_Int32(-1), nIndex); + } + + void lastIndexOfStr_001() + { + OString aStr1 = "Line for a lastIndexOfStr."; + OString aSearchStr = "Index"; + + sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + 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_EQUAL_MESSAGE("index is wrong.", sal_Int32(0), nIndex); + + /* OString */ aSearchStr = ""; + /* sal_Int32 */ nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(-1), nIndex); + } + + void lastIndexOfStr_002() + { + OString aStr1 = "Line for a lastIndexOfStr."; + OString aSearchStr = "foo"; + sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(-1), nIndex); + } + + void lastIndexOfStr_003() + { + OString aStr1 = "Line for a lastIndexOfStr."; + OString aSearchStr = "O"; + sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("index is wrong.", sal_Int32(20), nIndex); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(lastIndexOfStr); + CPPUNIT_TEST(lastIndexOfStr_000); + CPPUNIT_TEST(lastIndexOfStr_001); + CPPUNIT_TEST(lastIndexOfStr_002); + CPPUNIT_TEST(lastIndexOfStr_003); + CPPUNIT_TEST_SUITE_END(); + }; // class lastIndexOfStr + + class replaceChar : public CppUnit::TestFixture + { + void replaceChar_001() + { + OString aStr1 = "replace char."; + OString aShouldStr1 = "ruplacu char."; + + 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))); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(replaceChar); + CPPUNIT_TEST(replaceChar_001); + CPPUNIT_TEST_SUITE_END(); + }; // class replaceChar + + class replaceChar_WithLength : public CppUnit::TestFixture + { + void replaceChar_WithLength_000() + { + rtl_str_replaceChar_WithLength( nullptr, 0, 0, 0 ); + } + + void replaceChar_WithLength_001() + { + OString aStr1 = "replace char."; + OString aShouldStr1 = "ruplace char."; + + 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))); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(replaceChar_WithLength); + CPPUNIT_TEST(replaceChar_WithLength_000); + CPPUNIT_TEST(replaceChar_WithLength_001); + CPPUNIT_TEST_SUITE_END(); + }; // class replaceChar + + class toAsciiLowerCase : public CppUnit::TestFixture + { + void toAsciiLowerCase_001() + { + OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE."; + OString aShouldStr1 = "change this to ascii lower case."; + + 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))); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(toAsciiLowerCase); + CPPUNIT_TEST(toAsciiLowerCase_001); + CPPUNIT_TEST_SUITE_END(); + }; // class replaceChar + + class toAsciiLowerCase_WithLength : public CppUnit::TestFixture + { + void toAsciiLowerCase_WithLength_000() + { + rtl_str_toAsciiLowerCase_WithLength( nullptr, 0 ); + } + + void toAsciiLowerCase_WithLength_001() + { + OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE."; + OString aShouldStr1 = "change thiS TO ASCII LOWER CASE."; + + 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))); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(toAsciiLowerCase_WithLength); + CPPUNIT_TEST(toAsciiLowerCase_WithLength_000); + CPPUNIT_TEST(toAsciiLowerCase_WithLength_001); + CPPUNIT_TEST_SUITE_END(); + }; // class replaceChar + + class toAsciiUpperCase : public CppUnit::TestFixture + { + void toAsciiUpperCase_001() + { + OString aStr1 = "change this to ascii upper case."; + OString aShouldStr1 = "CHANGE THIS TO ASCII UPPER CASE."; + + 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))); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(toAsciiUpperCase); + CPPUNIT_TEST(toAsciiUpperCase_001); + CPPUNIT_TEST_SUITE_END(); + }; // class replaceChar + + class toAsciiUpperCase_WithLength : public CppUnit::TestFixture + { + void toAsciiUpperCase_WithLength_000() + { + rtl_str_toAsciiUpperCase_WithLength( nullptr, 0 ); + } + + void toAsciiUpperCase_WithLength_001() + { + OString aStr1 = "change this to ascii lower case."; + OString aShouldStr1 = "CHANGE THIs to ascii lower case."; + + 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))); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(toAsciiUpperCase_WithLength); + CPPUNIT_TEST(toAsciiUpperCase_WithLength_000); + CPPUNIT_TEST(toAsciiUpperCase_WithLength_001); + CPPUNIT_TEST_SUITE_END(); + }; // class replaceChar + + class trim_WithLength : public CppUnit::TestFixture + { + void trim_WithLength_000() + { + rtl_str_trim_WithLength(nullptr, 0); + // should not GPF + } + + void trim_WithLength_000_1() + { + char pStr[] = { " trim this" }; + rtl_str_trim_WithLength( pStr, 0 ); + } + + void trim_WithLength_001() + { + char pStr[] = { " trim this" }; + rtl_str_trim_WithLength( pStr, 2 ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("string should be empty", size_t(0), strlen(pStr)); + } + + void trim_WithLength_002() + { + char pStr[] = { "trim this" }; + rtl_str_trim_WithLength( pStr, 5 ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("string should contain 'trim'", size_t(4), strlen(pStr)); + } + + void trim_WithLength_003() + { + char pStr[] = {" trim this"}; + rtl_str_trim_WithLength( pStr, 11 ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("string should contain 'trim'", size_t(4), strlen(pStr)); + } + + void trim_WithLength_004() + { + char pStr[] = { "\r\n\t \n\r trim \n this" }; + rtl_str_trim_WithLength( pStr, 17 ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("string should contain 'trim'", size_t(4), strlen(pStr)); + } + + void trim_WithLength_005() + { + char pStr[] = { "\r\n\t \n\r trim \t this \n\r\t\t " }; + rtl_str_trim_WithLength( pStr, strlen(pStr) ); + + 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 + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(trim_WithLength); + CPPUNIT_TEST(trim_WithLength_000); + CPPUNIT_TEST(trim_WithLength_000_1); + CPPUNIT_TEST(trim_WithLength_001); + CPPUNIT_TEST(trim_WithLength_002); + CPPUNIT_TEST(trim_WithLength_003); + CPPUNIT_TEST(trim_WithLength_004); + CPPUNIT_TEST(trim_WithLength_005); + CPPUNIT_TEST_SUITE_END(); + }; + + class valueOfChar : public CppUnit::TestFixture + { + void valueOfChar_001() + { + char pStr[RTL_STR_MAX_VALUEOFCHAR]; + rtl_str_valueOfChar(pStr, 'A'); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("string should contain 'A'", 'A', pStr[0]); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(valueOfChar); + CPPUNIT_TEST(valueOfChar_001); + CPPUNIT_TEST_SUITE_END(); + }; + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::compare); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::compareIgnoreAsciiCase); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::shortenedCompareIgnoreAsciiCase_WithLength); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::hashCode); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::indexOfChar); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::lastIndexOfChar); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::indexOfStr); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::lastIndexOfStr); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::replaceChar); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::replaceChar_WithLength); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::toAsciiLowerCase); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::toAsciiLowerCase_WithLength); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::toAsciiUpperCase); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::toAsciiUpperCase_WithLength); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::trim_WithLength); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::valueOfChar); + +} // namespace rtl_str + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/ostring/rtl_str.xsce b/sal/qa/rtl/ostring/rtl_str.xsce new file mode 100644 index 000000000..cd12e72f7 --- /dev/null +++ b/sal/qa/rtl/ostring/rtl_str.xsce @@ -0,0 +1,43 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +# signaled with SIGNAL 11 +rtl_str.compare.compare_000 +rtl_str.compare.compare_000_1 + +rtl_str.compareIgnoreAsciiCase.compare_000 +rtl_str.compareIgnoreAsciiCase.compare_000_1 + +rtl_str.hashCode.hashCode_000 + +rtl_str.indexOfChar.indexOfChar_000 + +rtl_str.lastIndexOfChar.lastIndexOfChar_000 + +rtl_str.indexOfStr.indexOfStr_000 + +rtl_str.lastIndexOfStr.lastIndexOfStr_000 + +rtl_str.replaceChar.replaceChar_000 + +rtl_str.replaceChar_WithLength.replaceChar_WithLength_000_1 + +rtl_str.toAsciiLowerCase.toAsciiLowerCase_000 + +rtl_str.toAsciiUpperCase.toAsciiUpperCase_000 + +rtl_str.valueOfChar.valueOfChar_000 diff --git a/sal/qa/rtl/ostring/rtl_string.cxx b/sal/qa/rtl/ostring/rtl_string.cxx new file mode 100644 index 000000000..71c709519 --- /dev/null +++ b/sal/qa/rtl/ostring/rtl_string.cxx @@ -0,0 +1,169 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <rtl/ustring.hxx> +#include <cstring> + +namespace rtl_string +{ + + class getLength : public CppUnit::TestFixture + { + public: + + void getLength_000() + { + rtl_string_getLength( NULL ); + // should not GPF + } + + void getLength_001() + { + OString aStr("Test Length."); + sal_Int32 nValue = rtl_string_getLength( aStr.pData ); + + CPPUNIT_ASSERT_MESSAGE("Length must equal getLength()", aStr.getLength() == nValue); + CPPUNIT_ASSERT_MESSAGE( + "Length must equal strlen()", + nValue >= 0 + && (strlen(aStr.getStr()) + == sal::static_int_cast< sal_uInt32 >(nValue))); + } + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(getLength); + CPPUNIT_TEST(getLength_000); + CPPUNIT_TEST(getLength_001); + CPPUNIT_TEST_SUITE_END(); + }; // class getLength + + class newFromString : public CppUnit::TestFixture + { + public: + + // void newFromString_000() + // { + // sal_Int32 nValue = rtl_string_newFromString( NULL, NULL ); + // // should not GPF + // } + + void newFromString_001() + { + OString aStr("Test Length."); + rtl_String *pStr = NULL; + + rtl_string_newFromString( &pStr, aStr.pData ); + + OString aNewStr(pStr); + CPPUNIT_ASSERT_MESSAGE("Strings must be equal", aStr.equals(aNewStr) == sal_True); + + rtl_string_release(pStr); + } + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(newFromString); + // CPPUNIT_TEST(newFromString_000); + CPPUNIT_TEST(newFromString_001); + CPPUNIT_TEST_SUITE_END(); + }; // class newFromString + + class convertUStringToString : public CppUnit::TestFixture + { + public: + + // void newFromString_000() + // { + // sal_Int32 nValue = rtl_string_newFromString( NULL, NULL ); + // // should not GPF + // } + + void convertUStringToString_001() + { + OUString suString("Hello"); + OString sString; + sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ASCII_US, OUSTRING_TO_OSTRING_CVTFLAGS); + + CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(OString("Hello")) == sal_True); + } + + void convertUStringToString_002() + { + OString sStr("H\xE4llo"); + OUString suString = OStringToOUString(sStr, RTL_TEXTENCODING_ISO_8859_15); + + OString sString; + sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ISO_8859_15, OUSTRING_TO_OSTRING_CVTFLAGS); + + CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(OString("H\xE4llo")) == sal_True); + } + + void convertUStringToString_003() + { + OString sStr("H\xC3\xA4llo"); + OUString suString = OStringToOUString(sStr, RTL_TEXTENCODING_UTF8); + + OString sString; + sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ISO_8859_15, OUSTRING_TO_OSTRING_CVTFLAGS); + + CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(OString("H\xE4llo")) == sal_True); + } + + void convertUStringToString_004() + { + OString sStr("Tsch\xFC\xDF"); + OUString suString = OStringToOUString(sStr, RTL_TEXTENCODING_ISO_8859_15); + OString sString; + + sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); + /* sal_Bool */ bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ISO_8859_15, OUSTRING_TO_OSTRING_CVTFLAGS); + CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(OString("Tsch\xFC\xDF")) == sal_True); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(convertUStringToString); + CPPUNIT_TEST(convertUStringToString_001); + CPPUNIT_TEST(convertUStringToString_002); + CPPUNIT_TEST(convertUStringToString_003); + CPPUNIT_TEST(convertUStringToString_004); + CPPUNIT_TEST_SUITE_END(); + }; // class convertUStringToString + +} // namespace rtl_string + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_string::getLength); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_string::newFromString); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_string::convertUStringToString); + +// 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: */ diff --git a/sal/qa/rtl/ostring/rtl_string.xsce b/sal/qa/rtl/ostring/rtl_string.xsce new file mode 100644 index 000000000..7c8227e49 --- /dev/null +++ b/sal/qa/rtl/ostring/rtl_string.xsce @@ -0,0 +1,18 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +rtl_string.getLength.getLength_000 |