1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
31 // this file is converted to use with testshl2
32 // original was placed in sal/test/textenc.cxx
37 #include <rtl/strbuf.hxx>
39 #include <rtl/ustrbuf.hxx>
41 #include <testshl/simpleheader.hxx>
43 using ::rtl::OUString
;
45 using ::rtl::OUStringBuffer
;
46 using ::rtl::OStringBuffer
;
47 #define TEST_ENSURE(c, m) CPPUNIT_ASSERT_MESSAGE((m), (c))
50 namespace rtl_OStringBuffer
52 class oldtests
: public CppUnit::TestFixture
55 void test_OStringBuffer();
57 CPPUNIT_TEST_SUITE( oldtests
);
58 CPPUNIT_TEST( test_OStringBuffer
);
59 CPPUNIT_TEST_SUITE_END( );
63 void oldtests::test_OStringBuffer()
65 // "Mein erster RTL OString\n"
68 OString
s1("Mein erster RTL OString\n");
72 TEST_ENSURE( b1
.getCapacity() == 16 + s1
.getLength(), "test_OStringBuffer error 1");
74 b1
.insert(b1
.getLength() - 1, "Buffer");
75 s1
= "Mein erster RTL OStringBuffer\n";
76 TEST_ENSURE( s1
== b1
.getStr(), "test_OStringBuffer error 2");
78 b1
.insert(b1
.getLength() - 1, " ist viel zu gross fuer den alten Buffer");
79 TEST_ENSURE( b1
.getCapacity() == b1
.getLength(), "test_OStringBuffer error 3");
84 sal_Bool b
= sal_False
;
86 TEST_ENSURE( s1
== b2
.getStr(), "test_OStringBuffer error 4");
88 sal_Int32 n
= 123456789L;
92 TEST_ENSURE( s1
== b2
.getStr(), "test_OStringBuffer error 5");
95 sal_Int64 m
= -3223372036854775807LL;
97 sal_Int64 m
= -3223372036854775807;
99 s1
+= " -3223372036854775807";
102 TEST_ENSURE( s1
== b2
.getStr(), "test_OStringBuffer error 6");
104 OString
s2(b2
.makeStringAndClear());
105 TEST_ENSURE( s1
== s2
, "test_OStringBuffer error 7");
107 b2
.ensureCapacity(50);
108 TEST_ENSURE( b2
.getCapacity() == 50, "test_OStringBuffer error 8");
110 b2
.append("Hier fuege ich jetzt ein > <\n");
111 b2
.insert(26, " Hallo");
112 s2
= "Hier fuege ich jetzt ein > Hallo <\n";
113 TEST_ENSURE( s2
== b2
.getStr(), "test_OStringBuffer error 9");
117 s2
= "Hier fuege ich jetzt ein > false Hallo <\n";
118 TEST_ENSURE( s2
== b2
.getStr(), "test_OStringBuffer error 10");
122 s2
= "Hier fuege ich jetzt ein > 123456789 false Hallo <\n";
123 TEST_ENSURE( s2
== b2
.getStr(), "test_OStringBuffer error 11");
127 s2
= "Hier fuege ich jetzt ein > -3223372036854775807 123456789 false Hallo <\n";
128 TEST_ENSURE( s2
== b2
.getStr(), "test_OStringBuffer error 12");
130 printf("test_OStringBuffer OK !!!\n");
133 } // namespace rtl_OStringBuffer
135 // -----------------------------------------------------------------------------
137 namespace rtl_OUStringBuffer
139 class oldtests
: public CppUnit::TestFixture
142 void test_OUStringBuffer();
144 CPPUNIT_TEST_SUITE( oldtests
);
145 CPPUNIT_TEST( test_OUStringBuffer
);
146 CPPUNIT_TEST_SUITE_END( );
150 void oldtests::test_OUStringBuffer()
152 // "Mein erster RTL OUString\n"
154 // Index 0 5 10 15 20
155 OUString
s1(OUString("Mein erster RTL OUString\n"));
157 OUStringBuffer
b1(s1
);
159 TEST_ENSURE( b1
.getCapacity() == 16 + s1
.getLength(), "test_OWStringBuffer error 1");
161 b1
.insert(b1
.getLength() - 1, OUString("Buffer"));
162 s1
= OUString("Mein erster RTL OUStringBuffer\n");
163 TEST_ENSURE( s1
== b1
.getStr(), "test_OWStringBuffer error 2");
165 b1
.insert(b1
.getLength() - 1, OUString(" ist viel zu gross fuer den alten Buffer"));
166 //TEST_ENSURE( b1.getCapacity() == b1.getLength(), "test_OWStringBuffer error 3");
168 OUStringBuffer
b2(30);
170 s1
= OUString("false");
171 sal_Bool b
= sal_False
;
173 TEST_ENSURE( s1
== b2
.getStr(), "test_OWStringBuffer error 4");
175 sal_Int32 n
= 123456789L;
176 s1
+= OUString(" 123456789");
177 b2
.append(OUString(" "));
179 TEST_ENSURE( s1
== b2
.getStr(), "test_OWStringBuffer error 5");
182 sal_Int64 m
= -3223372036854775807LL;
184 sal_Int64 m
= -3223372036854775807;
186 s1
+= OUString(" -3223372036854775807");
187 b2
.append(OUString(" "));
189 TEST_ENSURE( s1
== b2
.getStr(), "test_OWStringBuffer error 6");
191 OUString
s2(b2
.makeStringAndClear());
192 TEST_ENSURE( s1
== s2
, "test_OWStringBuffer error 7");
194 b2
.ensureCapacity(50);
195 TEST_ENSURE( b2
.getCapacity() == 50, "test_OWStringBuffer error 8");
197 b2
.append(OUString("Hier fuege ich jetzt ein > <\n"));
198 b2
.insert(26, OUString(" Hallo"));
199 s2
= OUString("Hier fuege ich jetzt ein > Hallo <\n");
200 TEST_ENSURE( s2
== b2
.getStr(), "test_OWStringBuffer error 9");
203 b2
.insert(26, OUString(" "));
204 s2
= OUString("Hier fuege ich jetzt ein > false Hallo <\n");
205 TEST_ENSURE( s2
== b2
.getStr(), "test_OWStringBuffer error 10");
208 b2
.insert(26, OUString(" "));
209 s2
= OUString("Hier fuege ich jetzt ein > 123456789 false Hallo <\n");
210 TEST_ENSURE( s2
== b2
.getStr(), "test_OWStringBuffer error 11");
213 b2
.insert(26, OUString(" "));
214 s2
= OUString("Hier fuege ich jetzt ein > -3223372036854775807 123456789 false Hallo <\n");
215 TEST_ENSURE( s2
== b2
.getStr(), "test_OWStringBuffer error 12");
217 // ASCII-Schnittstelle, AB 15.10.1999
218 OUString
s3(OUString("Noch'n RTL OUString"));
219 OUStringBuffer
b3(s3
);
220 sal_Char aAsciiStr
[] = " mit appendetem ASCII\n";
221 b3
.appendAscii( aAsciiStr
);
222 s3
= OUString("Noch'n RTL OUString mit appendetem ASCII\n");
223 TEST_ENSURE( b3
.getStr() == s3
, "test_OWStringBuffer error 13");
227 printf("test_OWStringBuffer OK !!!\n");
231 } // namespace rtl_OUStringBuffer
234 // -----------------------------------------------------------------------------
235 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_OUStringBuffer::oldtests
, "rtl_OUStringBuffer" );
236 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_OStringBuffer::oldtests
, "rtl_OStringBuffer" );
238 // -----------------------------------------------------------------------------
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */