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