Bump for 3.6-28
[LibreOffice.git] / sal / qa / rtl_strings / rtl_old_teststrbuf.cxx
blob2fc54cb2367d09fb3619f0530549ecd8ac3d759b
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 ************************************************************************/
30 // LLA:
31 // this file is converted to use with testshl2
32 // original was placed in sal/test/textenc.cxx
34 #include <string.h>
35 #include <stdio.h>
37 #include <rtl/strbuf.hxx>
39 #include <rtl/ustrbuf.hxx>
41 #include <testshl/simpleheader.hxx>
43 using ::rtl::OUString;
44 using ::rtl::OString;
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
54 public:
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"
66 // | | | | |
67 // Index 0 5 10 15 20
68 OString s1("Mein erster RTL OString\n");
70 OStringBuffer b1(s1);
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");
81 OStringBuffer b2(30);
83 s1 = "false";
84 sal_Bool b = sal_False;
85 b2.append(b);
86 TEST_ENSURE( s1 == b2.getStr(), "test_OStringBuffer error 4");
88 sal_Int32 n = 123456789L;
89 s1 += " 123456789";
90 b2.append(" ");
91 b2.append(n);
92 TEST_ENSURE( s1 == b2.getStr(), "test_OStringBuffer error 5");
94 #ifdef SAL_UNX
95 sal_Int64 m = -3223372036854775807LL;
96 #else
97 sal_Int64 m = -3223372036854775807;
98 #endif
99 s1 += " -3223372036854775807";
100 b2.append(" ");
101 b2.append(m);
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");
115 b2.insert(26, b);
116 b2.insert(26, " ");
117 s2 = "Hier fuege ich jetzt ein > false Hallo <\n";
118 TEST_ENSURE( s2 == b2.getStr(), "test_OStringBuffer error 10");
120 b2.insert(26, n);
121 b2.insert(26, " ");
122 s2 = "Hier fuege ich jetzt ein > 123456789 false Hallo <\n";
123 TEST_ENSURE( s2 == b2.getStr(), "test_OStringBuffer error 11");
125 b2.insert(26, m);
126 b2.insert(26, " ");
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");
131 return;
133 } // namespace rtl_OStringBuffer
135 // -----------------------------------------------------------------------------
137 namespace rtl_OUStringBuffer
139 class oldtests : public CppUnit::TestFixture
141 public:
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"
153 // | | | | |
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;
172 b2.append(b);
173 TEST_ENSURE( s1 == b2.getStr(), "test_OWStringBuffer error 4");
175 sal_Int32 n = 123456789L;
176 s1 += OUString(" 123456789");
177 b2.append(OUString(" "));
178 b2.append(n);
179 TEST_ENSURE( s1 == b2.getStr(), "test_OWStringBuffer error 5");
181 #ifdef SAL_UNX
182 sal_Int64 m = -3223372036854775807LL;
183 #else
184 sal_Int64 m = -3223372036854775807;
185 #endif
186 s1 += OUString(" -3223372036854775807");
187 b2.append(OUString(" "));
188 b2.append(m);
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");
202 b2.insert(26, b);
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");
207 b2.insert(26, n);
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");
212 b2.insert(26, m);
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");
228 return;
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 // -----------------------------------------------------------------------------
239 NOADDITIONAL;
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */