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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sal.hxx"
26
27 // LLA:
28 // this file is converted to use with testshl2
29 // original was placed in sal/test/textenc.cxx
30
31
32 // -----------------------------------------------------------------------------
33
34 #include <string.h>
35 #include <stdio.h>
36
37 // #ifndef _OSL_DIAGNOSE_H_
38 // #include <osl/diagnose.h>
39 // #endif
40
41 #ifndef _RTL_STRBUF_HXX
42 #include <rtl/strbuf.hxx>
43 #endif
44
45 #ifndef _RTL_WSTRBUF_HXX
46 #include <rtl/ustrbuf.hxx>
47 #endif
48
49 #include <testshl/simpleheader.hxx>
50
51 using namespace rtl;
52
53 #define TEST_ENSURE(c, m) CPPUNIT_ASSERT_MESSAGE((m), (c))
54
55 // #if OSL_DEBUG_LEVEL > 0
56 // #define TEST_ENSHURE(c, m) OSL_ENSURE(c, m)
57 // #else
58 // #define TEST_ENSHURE(c, m) OSL_VERIFY(c)
59 // #endif
60
61 // -----------------------------------------------------------------------------
62 namespace rtl_OStringBuffer
63 {
64 class oldtests : public CppUnit::TestFixture
65 {
66 public:
67 void test_OStringBuffer();
68
69 CPPUNIT_TEST_SUITE( oldtests );
70 CPPUNIT_TEST( test_OStringBuffer );
71 CPPUNIT_TEST_SUITE_END( );
72 };
73
74
test_OStringBuffer()75 void oldtests::test_OStringBuffer()
76 {
77 // "Mein erster RTL OString\n"
78 // | | | | |
79 // Index 0 5 10 15 20
80 OString s1("Mein erster RTL OString\n");
81
82 OStringBuffer b1(s1);
83
84 TEST_ENSURE( b1.getCapacity() == 16 + s1.getLength(), "test_OStringBuffer error 1");
85
86 b1.insert(b1.getLength() - 1, "Buffer");
87 s1 = "Mein erster RTL OStringBuffer\n";
88 TEST_ENSURE( s1 == b1.getStr(), "test_OStringBuffer error 2");
89
90 b1.insert(b1.getLength() - 1, " ist viel zu gross fuer den alten Buffer");
91 TEST_ENSURE( b1.getCapacity() == b1.getLength(), "test_OStringBuffer error 3");
92
93 OStringBuffer b2(30);
94
95 s1 = "false";
96 sal_Bool b = sal_False;
97 b2.append(b);
98 TEST_ENSURE( s1 == b2.getStr(), "test_OStringBuffer error 4");
99
100 sal_Int32 n = 123456789L;
101 s1 += " 123456789";
102 b2.append(" ");
103 b2.append(n);
104 TEST_ENSURE( s1 == b2.getStr(), "test_OStringBuffer error 5");
105
106 #ifndef SAL_OS2
107 #ifdef SAL_UNX
108 sal_Int64 m = -3223372036854775807LL;
109 #elif defined(SAL_OS2)
110 sal_Int64 m;
111 sal_setInt64(&m, 3965190145L, -750499787L);
112 #else
113 sal_Int64 m = -3223372036854775807;
114 #endif
115 s1 += " -3223372036854775807";
116 b2.append(" ");
117 b2.append(m);
118 TEST_ENSURE( s1 == b2.getStr(), "test_OStringBuffer error 6");
119 #endif
120
121 OString s2(b2.makeStringAndClear());
122 TEST_ENSURE( s1 == s2, "test_OStringBuffer error 7");
123
124 b2.ensureCapacity(50);
125 TEST_ENSURE( b2.getCapacity() == 50, "test_OStringBuffer error 8");
126
127 b2.append("Hier fuege ich jetzt ein > <\n");
128 b2.insert(26, " Hallo");
129 s2 = "Hier fuege ich jetzt ein > Hallo <\n";
130 TEST_ENSURE( s2 == b2.getStr(), "test_OStringBuffer error 9");
131
132 b2.insert(26, b);
133 b2.insert(26, " ");
134 s2 = "Hier fuege ich jetzt ein > false Hallo <\n";
135 TEST_ENSURE( s2 == b2.getStr(), "test_OStringBuffer error 10");
136
137 b2.insert(26, n);
138 b2.insert(26, " ");
139 s2 = "Hier fuege ich jetzt ein > 123456789 false Hallo <\n";
140 TEST_ENSURE( s2 == b2.getStr(), "test_OStringBuffer error 11");
141
142 #ifndef SAL_OS2
143 b2.insert(26, m);
144 b2.insert(26, " ");
145 s2 = "Hier fuege ich jetzt ein > -3223372036854775807 123456789 false Hallo <\n";
146 TEST_ENSURE( s2 == b2.getStr(), "test_OStringBuffer error 12");
147 #endif
148
149 printf("test_OStringBuffer OK !!!\n");
150 return;
151 }
152 } // namespace rtl_OStringBuffer
153
154 // -----------------------------------------------------------------------------
155
156 namespace rtl_OUStringBuffer
157 {
158 class oldtests : public CppUnit::TestFixture
159 {
160 public:
161 void test_OUStringBuffer();
162
163 CPPUNIT_TEST_SUITE( oldtests );
164 CPPUNIT_TEST( test_OUStringBuffer );
165 CPPUNIT_TEST_SUITE_END( );
166 };
167
168
test_OUStringBuffer()169 void oldtests::test_OUStringBuffer()
170 {
171 // "Mein erster RTL OUString\n"
172 // | | | | |
173 // Index 0 5 10 15 20
174 OUString s1(OUString::createFromAscii("Mein erster RTL OUString\n"));
175
176 OUStringBuffer b1(s1);
177
178 TEST_ENSURE( b1.getCapacity() == 16 + s1.getLength(), "test_OWStringBuffer error 1");
179
180 b1.insert(b1.getLength() - 1, OUString::createFromAscii("Buffer"));
181 s1 = OUString::createFromAscii("Mein erster RTL OUStringBuffer\n");
182 TEST_ENSURE( s1 == b1.getStr(), "test_OWStringBuffer error 2");
183
184 b1.insert(b1.getLength() - 1, OUString::createFromAscii(" ist viel zu gross fuer den alten Buffer"));
185 //TEST_ENSURE( b1.getCapacity() == b1.getLength(), "test_OWStringBuffer error 3");
186
187 OUStringBuffer b2(30);
188
189 s1 = OUString::createFromAscii("false");
190 sal_Bool b = sal_False;
191 b2.append(b);
192 TEST_ENSURE( s1 == b2.getStr(), "test_OWStringBuffer error 4");
193
194 sal_Int32 n = 123456789L;
195 s1 += OUString::createFromAscii(" 123456789");
196 b2.append(OUString::createFromAscii(" "));
197 b2.append(n);
198 TEST_ENSURE( s1 == b2.getStr(), "test_OWStringBuffer error 5");
199
200 #ifndef SAL_OS2
201 #ifdef SAL_UNX
202 sal_Int64 m = -3223372036854775807LL;
203 #elif defined(SAL_OS2)
204 sal_Int64 m;
205 sal_setInt64(&m, 3965190145L, -750499787L);
206 #else
207 sal_Int64 m = -3223372036854775807;
208 #endif
209 s1 += OUString::createFromAscii(" -3223372036854775807");
210 b2.append(OUString::createFromAscii(" "));
211 b2.append(m);
212 TEST_ENSURE( s1 == b2.getStr(), "test_OWStringBuffer error 6");
213 #endif
214
215 OUString s2(b2.makeStringAndClear());
216 TEST_ENSURE( s1 == s2, "test_OWStringBuffer error 7");
217
218 b2.ensureCapacity(50);
219 TEST_ENSURE( b2.getCapacity() == 50, "test_OWStringBuffer error 8");
220
221 b2.append(OUString::createFromAscii("Hier fuege ich jetzt ein > <\n"));
222 b2.insert(26, OUString::createFromAscii(" Hallo"));
223 s2 = OUString::createFromAscii("Hier fuege ich jetzt ein > Hallo <\n");
224 TEST_ENSURE( s2 == b2.getStr(), "test_OWStringBuffer error 9");
225
226 b2.insert(26, b);
227 b2.insert(26, OUString::createFromAscii(" "));
228 s2 = OUString::createFromAscii("Hier fuege ich jetzt ein > false Hallo <\n");
229 TEST_ENSURE( s2 == b2.getStr(), "test_OWStringBuffer error 10");
230
231 b2.insert(26, n);
232 b2.insert(26, OUString::createFromAscii(" "));
233 s2 = OUString::createFromAscii("Hier fuege ich jetzt ein > 123456789 false Hallo <\n");
234 TEST_ENSURE( s2 == b2.getStr(), "test_OWStringBuffer error 11");
235
236 #ifndef SAL_OS2
237 b2.insert(26, m);
238 b2.insert(26, OUString::createFromAscii(" "));
239 s2 = OUString::createFromAscii("Hier fuege ich jetzt ein > -3223372036854775807 123456789 false Hallo <\n");
240 TEST_ENSURE( s2 == b2.getStr(), "test_OWStringBuffer error 12");
241 #endif
242
243 // ASCII-Schnittstelle, AB 15.10.1999
244 OUString s3(OUString::createFromAscii("Noch'n RTL OUString"));
245 OUStringBuffer b3(s3);
246 sal_Char aAsciiStr[] = " mit appendetem ASCII\n";
247 b3.appendAscii( aAsciiStr );
248 s3 = OUString::createFromAscii("Noch'n RTL OUString mit appendetem ASCII\n");
249 TEST_ENSURE( b3.getStr() == s3 , "test_OWStringBuffer error 13");
250
251
252
253 printf("test_OWStringBuffer OK !!!\n");
254 return;
255 }
256
257 } // namespace rtl_OUStringBuffer
258
259
260 // -----------------------------------------------------------------------------
261 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_OUStringBuffer::oldtests, "rtl_OUStringBuffer" );
262 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_OStringBuffer::oldtests, "rtl_OStringBuffer" );
263
264 // -----------------------------------------------------------------------------
265 NOADDITIONAL;
266