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