1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rtl_old_teststrbuf.cxx,v $
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"
35 // this file is converted to use with testshl2
36 // original was placed in sal/test/textenc.cxx
39 // -----------------------------------------------------------------------------
44 // #ifndef _OSL_DIAGNOSE_H_
45 // #include <osl/diagnose.h>
48 #ifndef _RTL_STRBUF_HXX
49 #include <rtl/strbuf.hxx>
52 #ifndef _RTL_WSTRBUF_HXX
53 #include <rtl/ustrbuf.hxx>
56 #include <cppunit/simpleheader.hxx>
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)
65 // #define TEST_ENSHURE(c, m) OSL_VERIFY(c)
68 // -----------------------------------------------------------------------------
69 namespace rtl_OStringBuffer
71 class oldtests
: public CppUnit::TestFixture
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"
87 OString
s1("Mein erster RTL OString\n");
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);
103 sal_Bool b
= sal_False
;
105 TEST_ENSURE( s1
== b2
.getStr(), "test_OStringBuffer error 4");
107 sal_Int32 n
= 123456789L;
111 TEST_ENSURE( s1
== b2
.getStr(), "test_OStringBuffer error 5");
115 sal_Int64 m
= -3223372036854775807LL;
116 #elif defined(SAL_OS2)
118 sal_setInt64(&m
, 3965190145L, -750499787L);
120 sal_Int64 m
= -3223372036854775807;
122 s1
+= " -3223372036854775807";
125 TEST_ENSURE( s1
== b2
.getStr(), "test_OStringBuffer error 6");
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");
141 s2
= "Hier fuege ich jetzt ein > false Hallo <\n";
142 TEST_ENSURE( s2
== b2
.getStr(), "test_OStringBuffer error 10");
146 s2
= "Hier fuege ich jetzt ein > 123456789 false Hallo <\n";
147 TEST_ENSURE( s2
== b2
.getStr(), "test_OStringBuffer error 11");
152 s2
= "Hier fuege ich jetzt ein > -3223372036854775807 123456789 false Hallo <\n";
153 TEST_ENSURE( s2
== b2
.getStr(), "test_OStringBuffer error 12");
156 printf("test_OStringBuffer OK !!!\n");
159 } // namespace rtl_OStringBuffer
161 // -----------------------------------------------------------------------------
163 namespace rtl_OUStringBuffer
165 class oldtests
: public CppUnit::TestFixture
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"
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
;
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(" "));
205 TEST_ENSURE( s1
== b2
.getStr(), "test_OWStringBuffer error 5");
209 sal_Int64 m
= -3223372036854775807LL;
210 #elif defined(SAL_OS2)
212 sal_setInt64(&m
, 3965190145L, -750499787L);
214 sal_Int64 m
= -3223372036854775807;
216 s1
+= OUString::createFromAscii(" -3223372036854775807");
217 b2
.append(OUString::createFromAscii(" "));
219 TEST_ENSURE( s1
== b2
.getStr(), "test_OWStringBuffer error 6");
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");
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");
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");
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");
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");
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 // -----------------------------------------------------------------------------