Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sal / qa / rtl / ostring / rtl_string.cxx
blob71c70951926483d6d2463ac46986146c978e983f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/types.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
23 #include <cppunit/plugin/TestPlugIn.h>
25 #include <rtl/ustring.hxx>
26 #include <cstring>
28 namespace rtl_string
31 class getLength : public CppUnit::TestFixture
33 public:
35 void getLength_000()
37 rtl_string_getLength( NULL );
38 // should not GPF
41 void getLength_001()
43 OString aStr("Test Length.");
44 sal_Int32 nValue = rtl_string_getLength( aStr.pData );
46 CPPUNIT_ASSERT_MESSAGE("Length must equal getLength()", aStr.getLength() == nValue);
47 CPPUNIT_ASSERT_MESSAGE(
48 "Length must equal strlen()",
49 nValue >= 0
50 && (strlen(aStr.getStr())
51 == sal::static_int_cast< sal_uInt32 >(nValue)));
53 // Change the following lines only, if you add, remove or rename
54 // member functions of the current class,
55 // because these macros are need by auto register mechanism.
57 CPPUNIT_TEST_SUITE(getLength);
58 CPPUNIT_TEST(getLength_000);
59 CPPUNIT_TEST(getLength_001);
60 CPPUNIT_TEST_SUITE_END();
61 }; // class getLength
63 class newFromString : public CppUnit::TestFixture
65 public:
67 // void newFromString_000()
68 // {
69 // sal_Int32 nValue = rtl_string_newFromString( NULL, NULL );
70 // // should not GPF
71 // }
73 void newFromString_001()
75 OString aStr("Test Length.");
76 rtl_String *pStr = NULL;
78 rtl_string_newFromString( &pStr, aStr.pData );
80 OString aNewStr(pStr);
81 CPPUNIT_ASSERT_MESSAGE("Strings must be equal", aStr.equals(aNewStr) == sal_True);
83 rtl_string_release(pStr);
85 // Change the following lines only, if you add, remove or rename
86 // member functions of the current class,
87 // because these macros are need by auto register mechanism.
89 CPPUNIT_TEST_SUITE(newFromString);
90 // CPPUNIT_TEST(newFromString_000);
91 CPPUNIT_TEST(newFromString_001);
92 CPPUNIT_TEST_SUITE_END();
93 }; // class newFromString
95 class convertUStringToString : public CppUnit::TestFixture
97 public:
99 // void newFromString_000()
100 // {
101 // sal_Int32 nValue = rtl_string_newFromString( NULL, NULL );
102 // // should not GPF
103 // }
105 void convertUStringToString_001()
107 OUString suString("Hello");
108 OString sString;
109 sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ASCII_US, OUSTRING_TO_OSTRING_CVTFLAGS);
111 CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(OString("Hello")) == sal_True);
114 void convertUStringToString_002()
116 OString sStr("H\xE4llo");
117 OUString suString = OStringToOUString(sStr, RTL_TEXTENCODING_ISO_8859_15);
119 OString sString;
120 sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ISO_8859_15, OUSTRING_TO_OSTRING_CVTFLAGS);
122 CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(OString("H\xE4llo")) == sal_True);
125 void convertUStringToString_003()
127 OString sStr("H\xC3\xA4llo");
128 OUString suString = OStringToOUString(sStr, RTL_TEXTENCODING_UTF8);
130 OString sString;
131 sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ISO_8859_15, OUSTRING_TO_OSTRING_CVTFLAGS);
133 CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(OString("H\xE4llo")) == sal_True);
136 void convertUStringToString_004()
138 OString sStr("Tsch\xFC\xDF");
139 OUString suString = OStringToOUString(sStr, RTL_TEXTENCODING_ISO_8859_15);
140 OString sString;
142 sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS);
143 /* sal_Bool */ bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ISO_8859_15, OUSTRING_TO_OSTRING_CVTFLAGS);
144 CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(OString("Tsch\xFC\xDF")) == sal_True);
147 // Change the following lines only, if you add, remove or rename
148 // member functions of the current class,
149 // because these macros are need by auto register mechanism.
151 CPPUNIT_TEST_SUITE(convertUStringToString);
152 CPPUNIT_TEST(convertUStringToString_001);
153 CPPUNIT_TEST(convertUStringToString_002);
154 CPPUNIT_TEST(convertUStringToString_003);
155 CPPUNIT_TEST(convertUStringToString_004);
156 CPPUNIT_TEST_SUITE_END();
157 }; // class convertUStringToString
159 } // namespace rtl_string
161 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_string::getLength);
162 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_string::newFromString);
163 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_string::convertUStringToString);
165 // this macro creates an empty function, which will called by the RegisterAllFunctions()
166 // to let the user the possibility to also register some functions by hand.
167 CPPUNIT_PLUGIN_IMPLEMENT();
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */