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 "gtest/gtest.h"
28 #include <rtl/string.hxx>
29 #include <rtl/ustring.hxx>
30
31 namespace rtl_string
32 {
33
34 class getLength : public ::testing::Test
35 {
36 public:
37 }; // class getLength
38
TEST_F(getLength,getLength_000)39 TEST_F(getLength, getLength_000)
40 {
41 rtl_string_getLength( NULL );
42 // should not GPF
43 }
44
TEST_F(getLength,getLength_001)45 TEST_F(getLength, getLength_001)
46 {
47 rtl::OString aStr("Test Length.");
48 sal_Int32 nValue = rtl_string_getLength( aStr.pData );
49
50 ASSERT_TRUE(aStr.getLength() == nValue) << "Length must equal getLength()";
51 ASSERT_TRUE(nValue >= 0
52 && (strlen(aStr.getStr())
53 == sal::static_int_cast< sal_uInt32 >(nValue))) << "Length must equal strlen()";
54 }
55 // -----------------------------------------------------------------------------
56
57 class newFromString : public ::testing::Test
58 {
59 public:
60 }; // class newFromString
61
62 // TEST_F(newFromString, newFromString_000)
63 // {
64 // sal_Int32 nValue = rtl_string_newFromString( NULL, NULL );
65 // // should not GPF
66 // }
67
TEST_F(newFromString,newFromString_001)68 TEST_F(newFromString, newFromString_001)
69 {
70 rtl::OString aStr("Test Length.");
71 rtl_String *pStr = NULL;
72
73 rtl_string_newFromString( &pStr, aStr.pData );
74
75 rtl::OString aNewStr(pStr);
76 ASSERT_TRUE(aStr.equals(aNewStr) == sal_True) << "Strings must be equal";
77
78 rtl_string_release(pStr);
79 }
80
81 // -----------------------------------------------------------------------------
82
83 class convertUStringToString : public ::testing::Test
84 {
85 public:
86 }; // class convertUStringToString
87
88
89 // TEST_F(convertUStringToString, newFromString_000)
90 // {
91 // sal_Int32 nValue = rtl_string_newFromString( NULL, NULL );
92 // // should not GPF
93 // }
94
TEST_F(convertUStringToString,convertUStringToString_001)95 TEST_F(convertUStringToString, convertUStringToString_001)
96 {
97 rtl::OUString suString = rtl::OUString::createFromAscii("Hello");
98 rtl::OString sString;
99 sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ASCII_US, OUSTRING_TO_OSTRING_CVTFLAGS);
100
101 ASSERT_TRUE(bRet == sal_True && sString.equals(rtl::OString("Hello")) == sal_True) << "Strings must be equal";
102 }
103
TEST_F(convertUStringToString,convertUStringToString_002)104 TEST_F(convertUStringToString, convertUStringToString_002)
105 {
106 rtl::OString sStr("H\xE4llo");
107 rtl::OUString suString = rtl::OStringToOUString(sStr, RTL_TEXTENCODING_ISO_8859_15);
108
109 rtl::OString sString;
110 sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ISO_8859_15, OUSTRING_TO_OSTRING_CVTFLAGS);
111
112 ASSERT_TRUE(bRet == sal_True && sString.equals(rtl::OString("H\xE4llo")) == sal_True) << "Strings must be equal";
113 }
114
TEST_F(convertUStringToString,convertUStringToString_003)115 TEST_F(convertUStringToString, convertUStringToString_003)
116 {
117 rtl::OString sStr("H\xC3\xA4llo");
118 rtl::OUString suString = rtl::OStringToOUString(sStr, RTL_TEXTENCODING_UTF8);
119
120 rtl::OString sString;
121 sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ISO_8859_15, OUSTRING_TO_OSTRING_CVTFLAGS);
122
123 ASSERT_TRUE(bRet == sal_True && sString.equals(rtl::OString("H\xE4llo")) == sal_True) << "Strings must be equal";
124 }
125
TEST_F(convertUStringToString,convertUStringToString_004)126 TEST_F(convertUStringToString, convertUStringToString_004)
127 {
128 rtl::OString sStr("Tsch\xFC\xDF");
129 rtl::OUString suString = rtl::OStringToOUString(sStr, RTL_TEXTENCODING_ISO_8859_15);
130 rtl::OString sString;
131
132 sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS);
133 /* sal_Bool */ bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ISO_8859_15, OUSTRING_TO_OSTRING_CVTFLAGS);
134 ASSERT_TRUE(bRet == sal_True && sString.equals(rtl::OString("Tsch\xFC\xDF")) == sal_True) << "Strings must be equal";
135 }
136
137 } // namespace rtl_string
138
139
main(int argc,char ** argv)140 int main(int argc, char **argv)
141 {
142 ::testing::InitGoogleTest(&argc, argv);
143 return RUN_ALL_TESTS();
144 }
145