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