merged tag ooo/DEV300_m102
[LibreOffice.git] / sal / qa / rtl_strings / rtl_old_teststrbuf.cxx
blobef04f3f60c385980211ad6a763650f0e1df92063
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"
31 // LLA:
32 // this file is converted to use with testshl2
33 // original was placed in sal/test/textenc.cxx
36 // -----------------------------------------------------------------------------
38 #include <string.h>
39 #include <stdio.h>
41 // #ifndef _OSL_DIAGNOSE_H_
42 // #include <osl/diagnose.h>
43 // #endif
45 #ifndef _RTL_STRBUF_HXX
46 #include <rtl/strbuf.hxx>
47 #endif
49 #ifndef _RTL_WSTRBUF_HXX
50 #include <rtl/ustrbuf.hxx>
51 #endif
53 #include <testshl/simpleheader.hxx>
55 using namespace rtl;
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)
61 // #else
62 // #define TEST_ENSHURE(c, m) OSL_VERIFY(c)
63 // #endif
65 // -----------------------------------------------------------------------------
66 namespace rtl_OStringBuffer
68 class oldtests : public CppUnit::TestFixture
70 public:
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"
82 // | | | | |
83 // Index 0 5 10 15 20
84 OString s1("Mein erster RTL OString\n");
86 OStringBuffer b1(s1);
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");
97 OStringBuffer b2(30);
99 s1 = "false";
100 sal_Bool b = sal_False;
101 b2.append(b);
102 TEST_ENSURE( s1 == b2.getStr(), "test_OStringBuffer error 4");
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");
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
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");
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");
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");
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
153 printf("test_OStringBuffer OK !!!\n");
154 return;
156 } // namespace rtl_OStringBuffer
158 // -----------------------------------------------------------------------------
160 namespace rtl_OUStringBuffer
162 class oldtests : public CppUnit::TestFixture
164 public:
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"
176 // | | | | |
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;
195 b2.append(b);
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(" "));
201 b2.append(n);
202 TEST_ENSURE( s1 == b2.getStr(), "test_OWStringBuffer error 5");
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
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");
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");
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");
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
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");
258 return;
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 // -----------------------------------------------------------------------------
269 NOADDITIONAL;