1*87d2adbcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*87d2adbcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*87d2adbcSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*87d2adbcSAndrew Rist * distributed with this work for additional information 6*87d2adbcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*87d2adbcSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*87d2adbcSAndrew Rist * "License"); you may not use this file except in compliance 9*87d2adbcSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*87d2adbcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*87d2adbcSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*87d2adbcSAndrew Rist * software distributed under the License is distributed on an 15*87d2adbcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*87d2adbcSAndrew Rist * KIND, either express or implied. See the License for the 17*87d2adbcSAndrew Rist * specific language governing permissions and limitations 18*87d2adbcSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*87d2adbcSAndrew Rist *************************************************************/ 21*87d2adbcSAndrew Rist 22*87d2adbcSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir 25cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 26cdf0e10cSrcweir #include "precompiled_sal.hxx" 27cdf0e10cSrcweir #include <testshl/simpleheader.hxx> 28cdf0e10cSrcweir 29cdf0e10cSrcweir namespace rtl_string 30cdf0e10cSrcweir { 31cdf0e10cSrcweir 32cdf0e10cSrcweir class getLength : public CppUnit::TestFixture 33cdf0e10cSrcweir { 34cdf0e10cSrcweir public: 35cdf0e10cSrcweir getLength_000()36cdf0e10cSrcweir void getLength_000() 37cdf0e10cSrcweir { 38cdf0e10cSrcweir rtl_string_getLength( NULL ); 39cdf0e10cSrcweir // should not GPF 40cdf0e10cSrcweir } 41cdf0e10cSrcweir getLength_001()42cdf0e10cSrcweir void getLength_001() 43cdf0e10cSrcweir { 44cdf0e10cSrcweir rtl::OString aStr("Test Length."); 45cdf0e10cSrcweir sal_Int32 nValue = rtl_string_getLength( aStr.pData ); 46cdf0e10cSrcweir 47cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Length must equal getLength()", aStr.getLength() == nValue); 48cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( 49cdf0e10cSrcweir "Length must equal strlen()", 50cdf0e10cSrcweir nValue >= 0 51cdf0e10cSrcweir && (strlen(aStr.getStr()) 52cdf0e10cSrcweir == sal::static_int_cast< sal_uInt32 >(nValue))); 53cdf0e10cSrcweir } 54cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 55cdf0e10cSrcweir // member functions of the current class, 56cdf0e10cSrcweir // because these macros are need by auto register mechanism. 57cdf0e10cSrcweir 58cdf0e10cSrcweir CPPUNIT_TEST_SUITE(getLength); 59cdf0e10cSrcweir CPPUNIT_TEST(getLength_000); 60cdf0e10cSrcweir CPPUNIT_TEST(getLength_001); 61cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 62cdf0e10cSrcweir }; // class getLength 63cdf0e10cSrcweir 64cdf0e10cSrcweir // ----------------------------------------------------------------------------- 65cdf0e10cSrcweir 66cdf0e10cSrcweir class newFromString : public CppUnit::TestFixture 67cdf0e10cSrcweir { 68cdf0e10cSrcweir public: 69cdf0e10cSrcweir 70cdf0e10cSrcweir // void newFromString_000() 71cdf0e10cSrcweir // { 72cdf0e10cSrcweir // sal_Int32 nValue = rtl_string_newFromString( NULL, NULL ); 73cdf0e10cSrcweir // // should not GPF 74cdf0e10cSrcweir // } 75cdf0e10cSrcweir newFromString_001()76cdf0e10cSrcweir void newFromString_001() 77cdf0e10cSrcweir { 78cdf0e10cSrcweir rtl::OString aStr("Test Length."); 79cdf0e10cSrcweir rtl_String *pStr = NULL; 80cdf0e10cSrcweir 81cdf0e10cSrcweir rtl_string_newFromString( &pStr, aStr.pData ); 82cdf0e10cSrcweir 83cdf0e10cSrcweir rtl::OString aNewStr(pStr); 84cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Strings must be equal", aStr.equals(aNewStr) == sal_True); 85cdf0e10cSrcweir 86cdf0e10cSrcweir rtl_string_release(pStr); 87cdf0e10cSrcweir } 88cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 89cdf0e10cSrcweir // member functions of the current class, 90cdf0e10cSrcweir // because these macros are need by auto register mechanism. 91cdf0e10cSrcweir 92cdf0e10cSrcweir CPPUNIT_TEST_SUITE(newFromString); 93cdf0e10cSrcweir // CPPUNIT_TEST(newFromString_000); 94cdf0e10cSrcweir CPPUNIT_TEST(newFromString_001); 95cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 96cdf0e10cSrcweir }; // class newFromString 97cdf0e10cSrcweir 98cdf0e10cSrcweir // ----------------------------------------------------------------------------- 99cdf0e10cSrcweir 100cdf0e10cSrcweir class convertUStringToString : public CppUnit::TestFixture 101cdf0e10cSrcweir { 102cdf0e10cSrcweir public: 103cdf0e10cSrcweir 104cdf0e10cSrcweir // void newFromString_000() 105cdf0e10cSrcweir // { 106cdf0e10cSrcweir // sal_Int32 nValue = rtl_string_newFromString( NULL, NULL ); 107cdf0e10cSrcweir // // should not GPF 108cdf0e10cSrcweir // } 109cdf0e10cSrcweir convertUStringToString_001()110cdf0e10cSrcweir void convertUStringToString_001() 111cdf0e10cSrcweir { 112cdf0e10cSrcweir rtl::OUString suString = rtl::OUString::createFromAscii("Hello"); 113cdf0e10cSrcweir rtl::OString sString; 114cdf0e10cSrcweir sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ASCII_US, OUSTRING_TO_OSTRING_CVTFLAGS); 115cdf0e10cSrcweir 116cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(rtl::OString("Hello")) == sal_True); 117cdf0e10cSrcweir } 118cdf0e10cSrcweir convertUStringToString_002()119cdf0e10cSrcweir void convertUStringToString_002() 120cdf0e10cSrcweir { 121cdf0e10cSrcweir rtl::OString sStr("H\xE4llo"); 122cdf0e10cSrcweir rtl::OUString suString = rtl::OStringToOUString(sStr, RTL_TEXTENCODING_ISO_8859_15); 123cdf0e10cSrcweir 124cdf0e10cSrcweir rtl::OString sString; 125cdf0e10cSrcweir sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ISO_8859_15, OUSTRING_TO_OSTRING_CVTFLAGS); 126cdf0e10cSrcweir 127cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(rtl::OString("H\xE4llo")) == sal_True); 128cdf0e10cSrcweir } 129cdf0e10cSrcweir convertUStringToString_003()130cdf0e10cSrcweir void convertUStringToString_003() 131cdf0e10cSrcweir { 132cdf0e10cSrcweir rtl::OString sStr("H\xC3\xA4llo"); 133cdf0e10cSrcweir rtl::OUString suString = rtl::OStringToOUString(sStr, RTL_TEXTENCODING_UTF8); 134cdf0e10cSrcweir 135cdf0e10cSrcweir rtl::OString sString; 136cdf0e10cSrcweir sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ISO_8859_15, OUSTRING_TO_OSTRING_CVTFLAGS); 137cdf0e10cSrcweir 138cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(rtl::OString("H\xE4llo")) == sal_True); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir convertUStringToString_004()141cdf0e10cSrcweir void convertUStringToString_004() 142cdf0e10cSrcweir { 143cdf0e10cSrcweir rtl::OString sStr("Tsch\xFC\xDF"); 144cdf0e10cSrcweir rtl::OUString suString = rtl::OStringToOUString(sStr, RTL_TEXTENCODING_ISO_8859_15); 145cdf0e10cSrcweir rtl::OString sString; 146cdf0e10cSrcweir 147cdf0e10cSrcweir sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); 148cdf0e10cSrcweir /* sal_Bool */ bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ISO_8859_15, OUSTRING_TO_OSTRING_CVTFLAGS); 149cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(rtl::OString("Tsch\xFC\xDF")) == sal_True); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir 153cdf0e10cSrcweir 154cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 155cdf0e10cSrcweir // member functions of the current class, 156cdf0e10cSrcweir // because these macros are need by auto register mechanism. 157cdf0e10cSrcweir 158cdf0e10cSrcweir CPPUNIT_TEST_SUITE(convertUStringToString); 159cdf0e10cSrcweir CPPUNIT_TEST(convertUStringToString_001); 160cdf0e10cSrcweir CPPUNIT_TEST(convertUStringToString_002); 161cdf0e10cSrcweir CPPUNIT_TEST(convertUStringToString_003); 162cdf0e10cSrcweir CPPUNIT_TEST(convertUStringToString_004); 163cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 164cdf0e10cSrcweir }; // class convertUStringToString 165cdf0e10cSrcweir 166cdf0e10cSrcweir 167cdf0e10cSrcweir 168cdf0e10cSrcweir } // namespace rtl_string 169cdf0e10cSrcweir 170cdf0e10cSrcweir // ----------------------------------------------------------------------------- 171cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_string::getLength, "rtl_string"); 172cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_string::newFromString, "rtl_string"); 173cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_string::convertUStringToString, "rtl_string"); 174cdf0e10cSrcweir 175cdf0e10cSrcweir // ----------------------------------------------------------------------------- 176cdf0e10cSrcweir 177cdf0e10cSrcweir // this macro creates an empty function, which will called by the RegisterAllFunctions() 178cdf0e10cSrcweir // to let the user the possibility to also register some functions by hand. 179cdf0e10cSrcweir NOADDITIONAL; 180