1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sal.hxx"
32 // this file is converted to use with testshl2
33 // original was placed in sal/test/textenc.cxx
36 // -----------------------------------------------------------------------------
41 // #ifndef _OSL_DIAGNOSE_H_
42 // #include <osl/diagnose.h>
45 #ifndef _RTL_STRBUF_HXX
46 #include <rtl/strbuf.hxx>
49 #ifndef _RTL_WSTRBUF_HXX
50 #include <rtl/ustrbuf.hxx>
53 #include <testshl/simpleheader.hxx>
57 #define TEST_ENSURE(c, m) CPPUNIT_ASSERT_MESSAGE((m), (c))
59 // #if OSL_DEBUG_LEVEL > 0
60 // #define TEST_ENSHURE(c, m) OSL_ENSURE(c, m)
62 // #define TEST_ENSHURE(c, m) OSL_VERIFY(c)
65 // -----------------------------------------------------------------------------
66 namespace rtl_OStringBuffer
68 class oldtests
: public CppUnit::TestFixture
71 void test_OStringBuffer();
73 CPPUNIT_TEST_SUITE( oldtests
);
74 CPPUNIT_TEST( test_OStringBuffer
);
75 CPPUNIT_TEST_SUITE_END( );
79 void oldtests::test_OStringBuffer()
81 // "Mein erster RTL OString\n"
84 OString
s1("Mein erster RTL OString\n");
88 TEST_ENSURE( b1
.getCapacity() == 16 + s1
.getLength(), "test_OStringBuffer error 1");
90 b1
.insert(b1
.getLength() - 1, "Buffer");
91 s1
= "Mein erster RTL OStringBuffer\n";
92 TEST_ENSURE( s1
== b1
.getStr(), "test_OStringBuffer error 2");
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");
100 sal_Bool b
= sal_False
;
102 TEST_ENSURE( s1
== b2
.getStr(), "test_OStringBuffer error 4");
104 sal_Int32 n
= 123456789L;
108 TEST_ENSURE( s1
== b2
.getStr(), "test_OStringBuffer error 5");
112 sal_Int64 m
= -3223372036854775807LL;
113 #elif defined(SAL_OS2)
115 sal_setInt64(&m
, 3965190145L, -750499787L);
117 sal_Int64 m
= -3223372036854775807;
119 s1
+= " -3223372036854775807";
122 TEST_ENSURE( s1
== b2
.getStr(), "test_OStringBuffer error 6");
125 OString
s2(b2
.makeStringAndClear());
126 TEST_ENSURE( s1
== s2
, "test_OStringBuffer error 7");
128 b2
.ensureCapacity(50);
129 TEST_ENSURE( b2
.getCapacity() == 50, "test_OStringBuffer error 8");
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");
138 s2
= "Hier fuege ich jetzt ein > false Hallo <\n";
139 TEST_ENSURE( s2
== b2
.getStr(), "test_OStringBuffer error 10");
143 s2
= "Hier fuege ich jetzt ein > 123456789 false Hallo <\n";
144 TEST_ENSURE( s2
== b2
.getStr(), "test_OStringBuffer error 11");
149 s2
= "Hier fuege ich jetzt ein > -3223372036854775807 123456789 false Hallo <\n";
150 TEST_ENSURE( s2
== b2
.getStr(), "test_OStringBuffer error 12");
153 printf("test_OStringBuffer OK !!!\n");
156 } // namespace rtl_OStringBuffer
158 // -----------------------------------------------------------------------------
160 namespace rtl_OUStringBuffer
162 class oldtests
: public CppUnit::TestFixture
165 void test_OUStringBuffer();
167 CPPUNIT_TEST_SUITE( oldtests
);
168 CPPUNIT_TEST( test_OUStringBuffer
);
169 CPPUNIT_TEST_SUITE_END( );
173 void oldtests::test_OUStringBuffer()
175 // "Mein erster RTL OUString\n"
177 // Index 0 5 10 15 20
178 OUString
s1(OUString::createFromAscii("Mein erster RTL OUString\n"));
180 OUStringBuffer
b1(s1
);
182 TEST_ENSURE( b1
.getCapacity() == 16 + s1
.getLength(), "test_OWStringBuffer error 1");
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");
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");
191 OUStringBuffer
b2(30);
193 s1
= OUString::createFromAscii("false");
194 sal_Bool b
= sal_False
;
196 TEST_ENSURE( s1
== b2
.getStr(), "test_OWStringBuffer error 4");
198 sal_Int32 n
= 123456789L;
199 s1
+= OUString::createFromAscii(" 123456789");
200 b2
.append(OUString::createFromAscii(" "));
202 TEST_ENSURE( s1
== b2
.getStr(), "test_OWStringBuffer error 5");
206 sal_Int64 m
= -3223372036854775807LL;
207 #elif defined(SAL_OS2)
209 sal_setInt64(&m
, 3965190145L, -750499787L);
211 sal_Int64 m
= -3223372036854775807;
213 s1
+= OUString::createFromAscii(" -3223372036854775807");
214 b2
.append(OUString::createFromAscii(" "));
216 TEST_ENSURE( s1
== b2
.getStr(), "test_OWStringBuffer error 6");
219 OUString
s2(b2
.makeStringAndClear());
220 TEST_ENSURE( s1
== s2
, "test_OWStringBuffer error 7");
222 b2
.ensureCapacity(50);
223 TEST_ENSURE( b2
.getCapacity() == 50, "test_OWStringBuffer error 8");
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");
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");
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");
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");
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");
257 printf("test_OWStringBuffer OK !!!\n");
261 } // namespace rtl_OUStringBuffer
264 // -----------------------------------------------------------------------------
265 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_OUStringBuffer::oldtests
, "rtl_OUStringBuffer" );
266 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_OStringBuffer::oldtests
, "rtl_OStringBuffer" );
268 // -----------------------------------------------------------------------------