1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_sal.hxx"
31 #include <testshl/simpleheader.hxx>
36 class getLength
: public CppUnit::TestFixture
42 rtl_string_getLength( NULL
);
48 rtl::OString
aStr("Test Length.");
49 sal_Int32 nValue
= rtl_string_getLength( aStr
.pData
);
51 CPPUNIT_ASSERT_MESSAGE("Length must equal getLength()", aStr
.getLength() == nValue
);
52 CPPUNIT_ASSERT_MESSAGE(
53 "Length must equal strlen()",
55 && (strlen(aStr
.getStr())
56 == sal::static_int_cast
< sal_uInt32
>(nValue
)));
58 // Change the following lines only, if you add, remove or rename
59 // member functions of the current class,
60 // because these macros are need by auto register mechanism.
62 CPPUNIT_TEST_SUITE(getLength
);
63 CPPUNIT_TEST(getLength_000
);
64 CPPUNIT_TEST(getLength_001
);
65 CPPUNIT_TEST_SUITE_END();
68 // -----------------------------------------------------------------------------
70 class newFromString
: public CppUnit::TestFixture
74 // void newFromString_000()
76 // sal_Int32 nValue = rtl_string_newFromString( NULL, NULL );
80 void newFromString_001()
82 rtl::OString
aStr("Test Length.");
83 rtl_String
*pStr
= NULL
;
85 rtl_string_newFromString( &pStr
, aStr
.pData
);
87 rtl::OString
aNewStr(pStr
);
88 CPPUNIT_ASSERT_MESSAGE("Strings must be equal", aStr
.equals(aNewStr
) == sal_True
);
90 rtl_string_release(pStr
);
92 // Change the following lines only, if you add, remove or rename
93 // member functions of the current class,
94 // because these macros are need by auto register mechanism.
96 CPPUNIT_TEST_SUITE(newFromString
);
97 // CPPUNIT_TEST(newFromString_000);
98 CPPUNIT_TEST(newFromString_001
);
99 CPPUNIT_TEST_SUITE_END();
100 }; // class newFromString
102 // -----------------------------------------------------------------------------
104 class convertUStringToString
: public CppUnit::TestFixture
108 // void newFromString_000()
110 // sal_Int32 nValue = rtl_string_newFromString( NULL, NULL );
114 void convertUStringToString_001()
116 rtl::OUString suString
= rtl::OUString::createFromAscii("Hello");
117 rtl::OString sString
;
118 sal_Bool bRet
= rtl_convertUStringToString(&sString
.pData
, suString
.getStr(), suString
.getLength(), RTL_TEXTENCODING_ASCII_US
, OUSTRING_TO_OSTRING_CVTFLAGS
);
120 CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet
== sal_True
&& sString
.equals(rtl::OString("Hello")) == sal_True
);
123 void convertUStringToString_002()
125 rtl::OString
sStr("H\xE4llo");
126 rtl::OUString suString
= rtl::OStringToOUString(sStr
, RTL_TEXTENCODING_ISO_8859_15
);
128 rtl::OString sString
;
129 sal_Bool bRet
= rtl_convertUStringToString(&sString
.pData
, suString
.getStr(), suString
.getLength(), RTL_TEXTENCODING_ISO_8859_15
, OUSTRING_TO_OSTRING_CVTFLAGS
);
131 CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet
== sal_True
&& sString
.equals(rtl::OString("H\xE4llo")) == sal_True
);
134 void convertUStringToString_003()
136 rtl::OString
sStr("H\xC3\xA4llo");
137 rtl::OUString suString
= rtl::OStringToOUString(sStr
, RTL_TEXTENCODING_UTF8
);
139 rtl::OString sString
;
140 sal_Bool bRet
= rtl_convertUStringToString(&sString
.pData
, suString
.getStr(), suString
.getLength(), RTL_TEXTENCODING_ISO_8859_15
, OUSTRING_TO_OSTRING_CVTFLAGS
);
142 CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet
== sal_True
&& sString
.equals(rtl::OString("H\xE4llo")) == sal_True
);
145 void convertUStringToString_004()
147 rtl::OString
sStr("Tsch\xFC\xDF");
148 rtl::OUString suString
= rtl::OStringToOUString(sStr
, RTL_TEXTENCODING_ISO_8859_15
);
149 rtl::OString sString
;
151 sal_Bool bRet
= rtl_convertUStringToString(&sString
.pData
, suString
.getStr(), suString
.getLength(), RTL_TEXTENCODING_UTF8
, OUSTRING_TO_OSTRING_CVTFLAGS
);
152 /* sal_Bool */ bRet
= rtl_convertUStringToString(&sString
.pData
, suString
.getStr(), suString
.getLength(), RTL_TEXTENCODING_ISO_8859_15
, OUSTRING_TO_OSTRING_CVTFLAGS
);
153 CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet
== sal_True
&& sString
.equals(rtl::OString("Tsch\xFC\xDF")) == sal_True
);
158 // Change the following lines only, if you add, remove or rename
159 // member functions of the current class,
160 // because these macros are need by auto register mechanism.
162 CPPUNIT_TEST_SUITE(convertUStringToString
);
163 CPPUNIT_TEST(convertUStringToString_001
);
164 CPPUNIT_TEST(convertUStringToString_002
);
165 CPPUNIT_TEST(convertUStringToString_003
);
166 CPPUNIT_TEST(convertUStringToString_004
);
167 CPPUNIT_TEST_SUITE_END();
168 }; // class convertUStringToString
172 } // namespace rtl_string
174 // -----------------------------------------------------------------------------
175 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_string::getLength
, "rtl_string");
176 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_string::newFromString
, "rtl_string");
177 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_string::convertUStringToString
, "rtl_string");
179 // -----------------------------------------------------------------------------
181 // this macro creates an empty function, which will called by the RegisterAllFunctions()
182 // to let the user the possibility to also register some functions by hand.