1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sal.hxx"
30 
31 // LLA:
32 // this file is converted to use with testshl2
33 // original was placed in sal/test/textenc.cxx
34 
35 
36 // -----------------------------------------------------------------------------
37 
38 #include <string.h>
39 #include <stdio.h>
40 
41 // #ifndef _OSL_DIAGNOSE_H_
42 // #include <osl/diagnose.h>
43 // #endif
44 
45 #ifndef _RTL_STRBUF_HXX
46 #include <rtl/strbuf.hxx>
47 #endif
48 
49 #ifndef _RTL_WSTRBUF_HXX
50 #include <rtl/ustrbuf.hxx>
51 #endif
52 
53 #include <testshl/simpleheader.hxx>
54 
55 using namespace rtl;
56 
57 #define TEST_ENSURE(c, m) CPPUNIT_ASSERT_MESSAGE((m), (c))
58 
59 // #if OSL_DEBUG_LEVEL > 0
60 // #define TEST_ENSHURE(c, m)   OSL_ENSURE(c, m)
61 // #else
62 // #define TEST_ENSHURE(c, m)   OSL_VERIFY(c)
63 // #endif
64 
65 // -----------------------------------------------------------------------------
66 namespace rtl_OStringBuffer
67 {
68     class oldtests : public CppUnit::TestFixture
69     {
70     public:
71         void test_OStringBuffer();
72 
73         CPPUNIT_TEST_SUITE( oldtests );
74         CPPUNIT_TEST( test_OStringBuffer );
75         CPPUNIT_TEST_SUITE_END( );
76     };
77 
78 
79 void oldtests::test_OStringBuffer()
80 {
81     //         "Mein erster RTL OString\n"
82     //          |    |    |    |    |
83     //  Index   0    5    10   15   20
84     OString s1("Mein erster RTL OString\n");
85 
86     OStringBuffer b1(s1);
87 
88     TEST_ENSURE( b1.getCapacity() == 16 + s1.getLength(), "test_OStringBuffer error 1");
89 
90     b1.insert(b1.getLength() - 1, "Buffer");
91     s1 = "Mein erster RTL OStringBuffer\n";
92     TEST_ENSURE( s1 == b1.getStr(), "test_OStringBuffer error 2");
93 
94     b1.insert(b1.getLength() - 1, " ist viel zu gross fuer den alten Buffer");
95     TEST_ENSURE( b1.getCapacity() == b1.getLength(), "test_OStringBuffer error 3");
96 
97     OStringBuffer b2(30);
98 
99     s1 = "false";
100     sal_Bool b = sal_False;
101     b2.append(b);
102     TEST_ENSURE( s1 == b2.getStr(), "test_OStringBuffer error 4");
103 
104     sal_Int32 n = 123456789L;
105     s1 += " 123456789";
106     b2.append(" ");
107     b2.append(n);
108     TEST_ENSURE( s1 == b2.getStr(), "test_OStringBuffer error 5");
109 
110 #ifndef SAL_OS2
111 #ifdef SAL_UNX
112     sal_Int64 m = -3223372036854775807LL;
113 #elif defined(SAL_OS2)
114     sal_Int64 m;
115     sal_setInt64(&m, 3965190145L, -750499787L);
116 #else
117     sal_Int64 m = -3223372036854775807;
118 #endif
119     s1 += " -3223372036854775807";
120     b2.append(" ");
121     b2.append(m);
122     TEST_ENSURE( s1 == b2.getStr(), "test_OStringBuffer error 6");
123 #endif
124 
125     OString s2(b2.makeStringAndClear());
126     TEST_ENSURE( s1 == s2, "test_OStringBuffer error 7");
127 
128     b2.ensureCapacity(50);
129     TEST_ENSURE( b2.getCapacity() == 50, "test_OStringBuffer error 8");
130 
131     b2.append("Hier fuege ich jetzt ein > <\n");
132     b2.insert(26, " Hallo");
133     s2 = "Hier fuege ich jetzt ein > Hallo <\n";
134     TEST_ENSURE( s2 == b2.getStr(), "test_OStringBuffer error 9");
135 
136     b2.insert(26, b);
137     b2.insert(26, " ");
138     s2 = "Hier fuege ich jetzt ein > false Hallo <\n";
139     TEST_ENSURE( s2 == b2.getStr(), "test_OStringBuffer error 10");
140 
141     b2.insert(26, n);
142     b2.insert(26, " ");
143     s2 = "Hier fuege ich jetzt ein > 123456789 false Hallo <\n";
144     TEST_ENSURE( s2 == b2.getStr(), "test_OStringBuffer error 11");
145 
146 #ifndef SAL_OS2
147     b2.insert(26, m);
148     b2.insert(26, " ");
149     s2 = "Hier fuege ich jetzt ein > -3223372036854775807 123456789 false Hallo <\n";
150     TEST_ENSURE( s2 == b2.getStr(), "test_OStringBuffer error 12");
151 #endif
152 
153     printf("test_OStringBuffer OK !!!\n");
154     return;
155 }
156 } // namespace rtl_OStringBuffer
157 
158 // -----------------------------------------------------------------------------
159 
160 namespace rtl_OUStringBuffer
161 {
162     class oldtests : public CppUnit::TestFixture
163     {
164     public:
165         void test_OUStringBuffer();
166 
167         CPPUNIT_TEST_SUITE( oldtests );
168         CPPUNIT_TEST( test_OUStringBuffer );
169         CPPUNIT_TEST_SUITE_END( );
170     };
171 
172 
173 void oldtests::test_OUStringBuffer()
174 {
175     //          "Mein erster RTL OUString\n"
176     //           |    |    |    |    |
177     //  Index    0    5    10   15   20
178     OUString s1(OUString::createFromAscii("Mein erster RTL OUString\n"));
179 
180     OUStringBuffer b1(s1);
181 
182     TEST_ENSURE( b1.getCapacity() == 16 + s1.getLength(), "test_OWStringBuffer error 1");
183 
184     b1.insert(b1.getLength() - 1, OUString::createFromAscii("Buffer"));
185     s1 = OUString::createFromAscii("Mein erster RTL OUStringBuffer\n");
186     TEST_ENSURE( s1 == b1.getStr(), "test_OWStringBuffer error 2");
187 
188     b1.insert(b1.getLength() - 1, OUString::createFromAscii(" ist viel zu gross fuer den alten Buffer"));
189     //TEST_ENSURE( b1.getCapacity() == b1.getLength(), "test_OWStringBuffer error 3");
190 
191     OUStringBuffer b2(30);
192 
193     s1 = OUString::createFromAscii("false");
194     sal_Bool b = sal_False;
195     b2.append(b);
196     TEST_ENSURE( s1 == b2.getStr(), "test_OWStringBuffer error 4");
197 
198     sal_Int32 n = 123456789L;
199     s1 += OUString::createFromAscii(" 123456789");
200     b2.append(OUString::createFromAscii(" "));
201     b2.append(n);
202     TEST_ENSURE( s1 == b2.getStr(), "test_OWStringBuffer error 5");
203 
204 #ifndef SAL_OS2
205 #ifdef SAL_UNX
206     sal_Int64 m = -3223372036854775807LL;
207 #elif defined(SAL_OS2)
208     sal_Int64 m;
209     sal_setInt64(&m, 3965190145L, -750499787L);
210 #else
211     sal_Int64 m = -3223372036854775807;
212 #endif
213     s1 += OUString::createFromAscii(" -3223372036854775807");
214     b2.append(OUString::createFromAscii(" "));
215     b2.append(m);
216     TEST_ENSURE( s1 == b2.getStr(), "test_OWStringBuffer error 6");
217 #endif
218 
219     OUString s2(b2.makeStringAndClear());
220     TEST_ENSURE( s1 == s2, "test_OWStringBuffer error 7");
221 
222     b2.ensureCapacity(50);
223     TEST_ENSURE( b2.getCapacity() == 50, "test_OWStringBuffer error 8");
224 
225     b2.append(OUString::createFromAscii("Hier fuege ich jetzt ein > <\n"));
226     b2.insert(26, OUString::createFromAscii(" Hallo"));
227     s2 = OUString::createFromAscii("Hier fuege ich jetzt ein > Hallo <\n");
228     TEST_ENSURE( s2 == b2.getStr(), "test_OWStringBuffer error 9");
229 
230     b2.insert(26, b);
231     b2.insert(26, OUString::createFromAscii(" "));
232     s2 = OUString::createFromAscii("Hier fuege ich jetzt ein > false Hallo <\n");
233     TEST_ENSURE( s2 == b2.getStr(), "test_OWStringBuffer error 10");
234 
235     b2.insert(26, n);
236     b2.insert(26, OUString::createFromAscii(" "));
237     s2 = OUString::createFromAscii("Hier fuege ich jetzt ein > 123456789 false Hallo <\n");
238     TEST_ENSURE( s2 == b2.getStr(), "test_OWStringBuffer error 11");
239 
240 #ifndef SAL_OS2
241     b2.insert(26, m);
242     b2.insert(26, OUString::createFromAscii(" "));
243     s2 = OUString::createFromAscii("Hier fuege ich jetzt ein > -3223372036854775807 123456789 false Hallo <\n");
244     TEST_ENSURE( s2 == b2.getStr(), "test_OWStringBuffer error 12");
245 #endif
246 
247     // ASCII-Schnittstelle, AB 15.10.1999
248     OUString s3(OUString::createFromAscii("Noch'n RTL OUString"));
249     OUStringBuffer b3(s3);
250     sal_Char aAsciiStr[] = " mit appendetem ASCII\n";
251     b3.appendAscii( aAsciiStr );
252     s3 = OUString::createFromAscii("Noch'n RTL OUString mit appendetem ASCII\n");
253     TEST_ENSURE( b3.getStr() == s3 , "test_OWStringBuffer error 13");
254 
255 
256 
257     printf("test_OWStringBuffer OK !!!\n");
258     return;
259 }
260 
261 } // namespace rtl_OUStringBuffer
262 
263 
264 // -----------------------------------------------------------------------------
265 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_OUStringBuffer::oldtests, "rtl_OUStringBuffer" );
266 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_OStringBuffer::oldtests, "rtl_OStringBuffer" );
267 
268 // -----------------------------------------------------------------------------
269 NOADDITIONAL;
270