update dev300-m57
[ooovba.git] / sal / qa / rtl / ostring / rtl_string.cxx
blob9b692a818db6ad436b42985b9e205edeef02a21b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rtl_string.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sal.hxx"
34 #include <cppunit/simpleheader.hxx>
36 namespace rtl_string
39 class getLength : public CppUnit::TestFixture
41 public:
43 void getLength_000()
45 rtl_string_getLength( NULL );
46 // should not GPF
49 void getLength_001()
51 rtl::OString aStr("Test Length.");
52 sal_Int32 nValue = rtl_string_getLength( aStr.pData );
54 CPPUNIT_ASSERT_MESSAGE("Length must equal getLength()", aStr.getLength() == nValue);
55 CPPUNIT_ASSERT_MESSAGE(
56 "Length must equal strlen()",
57 nValue >= 0
58 && (strlen(aStr.getStr())
59 == sal::static_int_cast< sal_uInt32 >(nValue)));
61 // Change the following lines only, if you add, remove or rename
62 // member functions of the current class,
63 // because these macros are need by auto register mechanism.
65 CPPUNIT_TEST_SUITE(getLength);
66 CPPUNIT_TEST(getLength_000);
67 CPPUNIT_TEST(getLength_001);
68 CPPUNIT_TEST_SUITE_END();
69 }; // class getLength
71 // -----------------------------------------------------------------------------
73 class newFromString : public CppUnit::TestFixture
75 public:
77 // void newFromString_000()
78 // {
79 // sal_Int32 nValue = rtl_string_newFromString( NULL, NULL );
80 // // should not GPF
81 // }
83 void newFromString_001()
85 rtl::OString aStr("Test Length.");
86 rtl_String *pStr = NULL;
88 rtl_string_newFromString( &pStr, aStr.pData );
90 rtl::OString aNewStr(pStr);
91 CPPUNIT_ASSERT_MESSAGE("Strings must be equal", aStr.equals(aNewStr) == sal_True);
93 rtl_string_release(pStr);
95 // Change the following lines only, if you add, remove or rename
96 // member functions of the current class,
97 // because these macros are need by auto register mechanism.
99 CPPUNIT_TEST_SUITE(newFromString);
100 // CPPUNIT_TEST(newFromString_000);
101 CPPUNIT_TEST(newFromString_001);
102 CPPUNIT_TEST_SUITE_END();
103 }; // class newFromString
105 // -----------------------------------------------------------------------------
107 class convertUStringToString : public CppUnit::TestFixture
109 public:
111 // void newFromString_000()
112 // {
113 // sal_Int32 nValue = rtl_string_newFromString( NULL, NULL );
114 // // should not GPF
115 // }
117 void convertUStringToString_001()
119 rtl::OUString suString = rtl::OUString::createFromAscii("Hello");
120 rtl::OString sString;
121 sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ASCII_US, OUSTRING_TO_OSTRING_CVTFLAGS);
123 CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(rtl::OString("Hello")) == sal_True);
126 void convertUStringToString_002()
128 rtl::OString sStr("H\xE4llo");
129 rtl::OUString suString = rtl::OStringToOUString(sStr, RTL_TEXTENCODING_ISO_8859_15);
131 rtl::OString sString;
132 sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ISO_8859_15, OUSTRING_TO_OSTRING_CVTFLAGS);
134 CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(rtl::OString("H\xE4llo")) == sal_True);
137 void convertUStringToString_003()
139 rtl::OString sStr("H\xC3\xA4llo");
140 rtl::OUString suString = rtl::OStringToOUString(sStr, RTL_TEXTENCODING_UTF8);
142 rtl::OString sString;
143 sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ISO_8859_15, OUSTRING_TO_OSTRING_CVTFLAGS);
145 CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(rtl::OString("H\xE4llo")) == sal_True);
148 void convertUStringToString_004()
150 rtl::OString sStr("Tsch\xFC\xDF");
151 rtl::OUString suString = rtl::OStringToOUString(sStr, RTL_TEXTENCODING_ISO_8859_15);
152 rtl::OString sString;
154 sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS);
155 /* sal_Bool */ bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ISO_8859_15, OUSTRING_TO_OSTRING_CVTFLAGS);
156 CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(rtl::OString("Tsch\xFC\xDF")) == sal_True);
161 // Change the following lines only, if you add, remove or rename
162 // member functions of the current class,
163 // because these macros are need by auto register mechanism.
165 CPPUNIT_TEST_SUITE(convertUStringToString);
166 CPPUNIT_TEST(convertUStringToString_001);
167 CPPUNIT_TEST(convertUStringToString_002);
168 CPPUNIT_TEST(convertUStringToString_003);
169 CPPUNIT_TEST(convertUStringToString_004);
170 CPPUNIT_TEST_SUITE_END();
171 }; // class convertUStringToString
175 } // namespace rtl_string
177 // -----------------------------------------------------------------------------
178 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_string::getLength, "rtl_string");
179 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_string::newFromString, "rtl_string");
180 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_string::convertUStringToString, "rtl_string");
182 // -----------------------------------------------------------------------------
184 // this macro creates an empty function, which will called by the RegisterAllFunctions()
185 // to let the user the possibility to also register some functions by hand.
186 NOADDITIONAL;