1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sal.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // LLA:
32*cdf0e10cSrcweir // this file is converted to use with testshl2
33*cdf0e10cSrcweir // original was placed in sal/test/textenc.cxx
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir // -----------------------------------------------------------------------------
37*cdf0e10cSrcweir #include <string.h>
38*cdf0e10cSrcweir #include <stdio.h>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #ifdef UNX
41*cdf0e10cSrcweir #include <wchar.h>
42*cdf0e10cSrcweir #endif
43*cdf0e10cSrcweir #ifdef OS2__00
44*cdf0e10cSrcweir #include <wcstr.h>
45*cdf0e10cSrcweir #endif
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir // #ifndef	_OSL_DIAGNOSE_H_
48*cdf0e10cSrcweir // #include <osl/diagnose.h>
49*cdf0e10cSrcweir // #endif
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir #ifndef	_RTL_USTRING_HXX
52*cdf0e10cSrcweir #include <rtl/ustring.hxx>
53*cdf0e10cSrcweir #endif
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir #ifndef	_RTL_STRING_HXX
56*cdf0e10cSrcweir #include <rtl/string.hxx>
57*cdf0e10cSrcweir #endif
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir #include <rtl/locale.hxx>
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir #include <testshl/simpleheader.hxx>
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir #define TEST_ENSURE(c, m) CPPUNIT_ASSERT_MESSAGE((m), (c))
64*cdf0e10cSrcweir // #if OSL_DEBUG_LEVEL > 0
65*cdf0e10cSrcweir // #define TEST_ENSHURE(c, m)   OSL_ENSURE(c, m)
66*cdf0e10cSrcweir // #else
67*cdf0e10cSrcweir // #define TEST_ENSHURE(c, m)   OSL_VERIFY(c)
68*cdf0e10cSrcweir // #endif
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir using namespace rtl;
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir // -----------------------------------------------------------------------------
73*cdf0e10cSrcweir namespace rtl_OUString
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir     class oldtests : public CppUnit::TestFixture
76*cdf0e10cSrcweir     {
77*cdf0e10cSrcweir     public:
78*cdf0e10cSrcweir         void test_OUString();
79*cdf0e10cSrcweir         void test_OString2OUStringAndViceVersa();
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir         CPPUNIT_TEST_SUITE( oldtests );
82*cdf0e10cSrcweir         CPPUNIT_TEST( test_OUString );
83*cdf0e10cSrcweir         CPPUNIT_TEST( test_OString2OUStringAndViceVersa );
84*cdf0e10cSrcweir         CPPUNIT_TEST_SUITE_END( );
85*cdf0e10cSrcweir     };
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir void oldtests::test_OUString()
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir 	//          "Mein erster RTL OUString\n"
91*cdf0e10cSrcweir 	//	         |	  |    |    |	 |
92*cdf0e10cSrcweir 	//	Index    0	  5	   10   15	 20
93*cdf0e10cSrcweir 	OUString s1(OUString::createFromAscii("Mein erster RTL OUString\n"));
94*cdf0e10cSrcweir 	TEST_ENSURE( s1 == OUString::createFromAscii("Mein erster RTL OUString\n"), "test_OWString error 1");
95*cdf0e10cSrcweir 	TEST_ENSURE( s1.getLength() == 25, "test_OWString error 2");
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 	OUString s2 = s1;
98*cdf0e10cSrcweir 	TEST_ENSURE( s2[16] == (sal_Unicode)'O', "test_OWString error 3");
99*cdf0e10cSrcweir 	TEST_ENSURE( s2.equals(s1), "test_OWString error 4");
100*cdf0e10cSrcweir 	TEST_ENSURE( OUString( OUString::createFromAscii("hallo")) == OUString::createFromAscii( "hallo"), "test_OWString error 4");
101*cdf0e10cSrcweir 	TEST_ENSURE( s2.indexOf((sal_Unicode)'O') == 16, "test_OWString error 5");
102*cdf0e10cSrcweir 	TEST_ENSURE( s2.indexOf((sal_Unicode)'O', 5) == 16, "test_OWString error 5a");
103*cdf0e10cSrcweir 	TEST_ENSURE( s2.lastIndexOf((sal_Unicode)'r') == 20, "test_OWString error 6");
104*cdf0e10cSrcweir 	TEST_ENSURE( s2[20] == (sal_Unicode)'r', "test_OWString error 7");
105*cdf0e10cSrcweir 	TEST_ENSURE( s2[24] == (sal_Unicode)'\n', "test_OWString error 8");
106*cdf0e10cSrcweir 	TEST_ENSURE( s2.lastIndexOf((sal_Unicode)'\n') == 24, "test_OWString error 9");
107*cdf0e10cSrcweir 	TEST_ENSURE( s2.lastIndexOf((sal_Unicode)'M') == 0, "test_OWString error 10");
108*cdf0e10cSrcweir 	TEST_ENSURE( s2.lastIndexOf((sal_Unicode)'t', s2.getLength() - 8) == 8, "test_OWString error 9");
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir 	//          "Mein erster RTL OUString ist ein String aus der RTL Library\n"
112*cdf0e10cSrcweir 	//           |    |    |    |	 |	  |	   |	| 	 |	  |	   |	|
113*cdf0e10cSrcweir 	//  Index    0    5	   10   15	 20   25   30	35	 40   45   50	55
114*cdf0e10cSrcweir 	OUString s3 = s2.copy(0, s2.getLength() - 1);
115*cdf0e10cSrcweir 	OUString s4 = s3.concat( OUString::createFromAscii(" ist ein String aus der RTL Library\n") );
116*cdf0e10cSrcweir 	TEST_ENSURE( s4.getLength() == 60, "test_OWString error 11");
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 	s1 = s4.copy(0, 39);
119*cdf0e10cSrcweir 	OUString s5;
120*cdf0e10cSrcweir 	s5 = s1 + OUString::createFromAscii( " aus der RTL Library\n" );
121*cdf0e10cSrcweir 	TEST_ENSURE( s5.compareTo(s4) == 0 , "test_OWString error 12");
122*cdf0e10cSrcweir 	TEST_ENSURE( s5.indexOf(OUString::createFromAscii("RTL")) == 12, "test_OWString error 13");
123*cdf0e10cSrcweir 	TEST_ENSURE( s5.lastIndexOf(OUString::createFromAscii("RTL")) == 48, "test_OWString error 13");
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir 	sal_Bool b = sal_False;
126*cdf0e10cSrcweir 	OUString s6 = s5.valueOf(b);
127*cdf0e10cSrcweir //	TEST_ENSURE( s6.compareTo(OUString::createFromAscii("False")) == 0, "test_OWString error 14");
128*cdf0e10cSrcweir 	s6 = s5.valueOf((sal_Unicode)'H');
129*cdf0e10cSrcweir 	TEST_ENSURE( s6.compareTo(OUString::createFromAscii("H")) == 0, "test_OWString error 15");
130*cdf0e10cSrcweir 	sal_Int32 n = 123456789L;
131*cdf0e10cSrcweir 	s6 = s5.valueOf(n);
132*cdf0e10cSrcweir 	TEST_ENSURE( s6.compareTo(OUString::createFromAscii("123456789")) == 0, "test_OWString error 16");
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir #ifndef SAL_OS2
135*cdf0e10cSrcweir #ifdef SAL_UNX
136*cdf0e10cSrcweir 	sal_Int64 m = -3223372036854775807LL;
137*cdf0e10cSrcweir #elif defined(SAL_OS2)
138*cdf0e10cSrcweir     sal_Int64 m;
139*cdf0e10cSrcweir     sal_setInt64(&m, 3965190145L, -750499787L);
140*cdf0e10cSrcweir #else
141*cdf0e10cSrcweir 	sal_Int64 m = -3223372036854775807;
142*cdf0e10cSrcweir #endif
143*cdf0e10cSrcweir 	s6 = s5.valueOf(m);
144*cdf0e10cSrcweir 	TEST_ENSURE( s6.compareTo( OUString::createFromAscii( "-3223372036854775807" ) ) == 0, "test_OWString error 17");
145*cdf0e10cSrcweir #endif
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir // LLA: locale tests removed    	::rtl::OLocale locale = ::rtl::OLocale::getDefault();
148*cdf0e10cSrcweir // LLA: locale tests removed
149*cdf0e10cSrcweir // LLA: locale tests removed 	OUString s61(OUString::createFromAscii("HaLLo"));
150*cdf0e10cSrcweir // LLA: locale tests removed 	s61 = s61.toLowerCase(locale);
151*cdf0e10cSrcweir // LLA: locale tests removed 	TEST_ENSURE( s61 == OUString::createFromAscii("hallo"), "test_OWString error 17a");
152*cdf0e10cSrcweir // LLA: locale tests removed 	s61 = s61.toUpperCase();
153*cdf0e10cSrcweir // LLA: locale tests removed 	TEST_ENSURE( s61 == OUString::createFromAscii("HALLO"), "test_OWString error 17b");
154*cdf0e10cSrcweir // LLA: locale tests removed 	s61 = s61.toLowerCase();
155*cdf0e10cSrcweir // LLA: locale tests removed 	TEST_ENSURE( s61 == OUString::createFromAscii("hallo"), "test_OWString error 17c");
156*cdf0e10cSrcweir // LLA: locale tests removed
157*cdf0e10cSrcweir // LLA: locale tests removed 	::rtl::OLocale::setDefault( OUString::createFromAscii( "de" ), OUString::createFromAscii( "DE" ), OUString() );
158*cdf0e10cSrcweir // LLA: locale tests removed 	locale = OLocale::getDefault();
159*cdf0e10cSrcweir // LLA: locale tests removed
160*cdf0e10cSrcweir // LLA: locale tests removed 	// AB, 24.3.2000, removed NAMESPACE_RTL(OLocale)::getENGLISH() and error 18
161*cdf0e10cSrcweir // LLA: locale tests removed
162*cdf0e10cSrcweir // LLA: locale tests removed  	OUString s7(OUString::createFromAscii("HaLLo"));
163*cdf0e10cSrcweir // LLA: locale tests removed 	s7 = s7.toLowerCase(locale);
164*cdf0e10cSrcweir // LLA: locale tests removed 	TEST_ENSURE( s7 == OUString::createFromAscii("hallo"), "test_OWString error 19");
165*cdf0e10cSrcweir // LLA: locale tests removed 	s7 = s7.toUpperCase(locale);
166*cdf0e10cSrcweir // LLA: locale tests removed 	TEST_ENSURE( s7 == OUString::createFromAscii("HALLO"), "test_OWString error 20");
167*cdf0e10cSrcweir // LLA: locale tests removed
168*cdf0e10cSrcweir // LLA: locale tests removed 	OUString s8(OUString::createFromAscii("HaLLo ICH BIn eIn "));
169*cdf0e10cSrcweir // LLA: locale tests removed 	s8 += OUString::valueOf( (sal_Unicode)0xDF );
170*cdf0e10cSrcweir // LLA: locale tests removed 	locale = OLocale::registerLocale( OUString::createFromAscii("tr"), OUString::createFromAscii("TR"), OUString());
171*cdf0e10cSrcweir // LLA: locale tests removed 	s8 = s8.toLowerCase(locale);
172*cdf0e10cSrcweir // LLA: locale tests removed 	s8 = s8.toUpperCase(locale);
173*cdf0e10cSrcweir // LLA: locale tests removed 	TEST_ENSURE( s8 == OUString::createFromAscii("HALLO ICH BIN EIN SS"), "test_OWString error 21");
174*cdf0e10cSrcweir // LLA: locale tests removed
175*cdf0e10cSrcweir // LLA: locale tests removed 	s7 = OUString::createFromAscii("Hallo ich bIn ein I");
176*cdf0e10cSrcweir // LLA: locale tests removed 	s7 = s8.toUpperCase(locale);
177*cdf0e10cSrcweir // LLA: locale tests removed 	TEST_ENSURE( s7 != OUString::createFromAscii("HALLO ICH BIN EIN I"), "test_OWString error 21.b");
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir  	OUString s7;
180*cdf0e10cSrcweir 	OUString s8(OUString::createFromAscii("HALLO ICH BIN EIN SS"));
181*cdf0e10cSrcweir 	s7 = OUString::createFromAscii("          ");
182*cdf0e10cSrcweir 	s8 = s7 + s8 + OUString::createFromAscii("          " );
183*cdf0e10cSrcweir 	TEST_ENSURE( s8 == OUString::createFromAscii("          HALLO ICH BIN EIN SS          "),
184*cdf0e10cSrcweir 				  "test_OWString error 22");
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 	s7 = s8.trim();
187*cdf0e10cSrcweir 	TEST_ENSURE( s7 == OUString::createFromAscii("HALLO ICH BIN EIN SS"), "test_OWString error 23");
188*cdf0e10cSrcweir //	TEST_ENSURE( wcscmp(s7.getStr(), L"HALLO ICH BIN EIN SS") == 0, "test_OWString error 24");
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 	s7 = OUString::createFromAscii("Hallo");
191*cdf0e10cSrcweir 	s8 = OUString::createFromAscii("aber Hallo");
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 	TEST_ENSURE( s7 < s8, "test_OWString error 25");
194*cdf0e10cSrcweir 	TEST_ENSURE( s8 > s7, "test_OWString error 26");
195*cdf0e10cSrcweir 	TEST_ENSURE( s7 != s8, "test_OWString error 27");
196*cdf0e10cSrcweir 	TEST_ENSURE( s7 != OUString::createFromAscii("blabla"), "test_OWString error 28");
197*cdf0e10cSrcweir 	TEST_ENSURE( OUString::createFromAscii("blabla") != s7, "test_OWString error 29");
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir 	s8 = OUString::createFromAscii("Hallo");
200*cdf0e10cSrcweir 	TEST_ENSURE( s7 <= s8, "test_OWString error 30");
201*cdf0e10cSrcweir 	TEST_ENSURE( s7 >= s8, "test_OwString error 31");
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 	s8 = s8.replace((sal_Unicode)'l', (sal_Unicode)'r');
204*cdf0e10cSrcweir 	TEST_ENSURE( s8 == OUString::createFromAscii("Harro"), "test_OWString error 32");
205*cdf0e10cSrcweir // LLA: len() unknown	TEST_ENSURE( s8.len() == 5, "test_OWString error 33");
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir 	//       "Ich bin ein String mit einem A und C und vielen m, m, m, m"
208*cdf0e10cSrcweir 	//		  |	   |	|	 |	  |	   |	|	 |	  |	   |	|	 |
209*cdf0e10cSrcweir 	//index	  0	   5	10	 15	  20   25	30	 35	  40   45	50	 55
210*cdf0e10cSrcweir 	s8 = OUString::createFromAscii("Ich bin ein String mit einem A und C und vielen m, m, m, m");
211*cdf0e10cSrcweir // LLA: no matching 	TEST_ENSURE( s8.search((sal_Unicode)'I') == 0, "test_OWString error 34");
212*cdf0e10cSrcweir // LLA: no matching 	TEST_ENSURE( s8.search((sal_Unicode)'A') == 29, "test_OWString error 35");
213*cdf0e10cSrcweir // LLA: no matching 	s7 = OUString::createFromAscii("A und C");
214*cdf0e10cSrcweir // LLA: no matching 	TEST_ENSURE( s8.search(s7) == 29, "test_OWString error 36");
215*cdf0e10cSrcweir // LLA: no matching 	TEST_ENSURE( s8.search(OUString::createFromAscii("mit einem A")) == 19, "test_OWString error 37");
216*cdf0e10cSrcweir // LLA: no matching
217*cdf0e10cSrcweir // LLA: no matching 	s8 = OUString::createFromAscii("||token1|token2|token3||token4|token5||" );
218*cdf0e10cSrcweir // LLA: no matching 	TEST_ENSURE( s8.getTokenCount('|') == 10, "test_OWString error 38a");
219*cdf0e10cSrcweir // LLA: no matching 	TEST_ENSURE( s8.getToken(10,'|') == OUString(), "test_OWString error 39a");
220*cdf0e10cSrcweir // LLA: no matching
221*cdf0e10cSrcweir // LLA: no matching 	s8 = OUString::createFromAscii("token1");
222*cdf0e10cSrcweir // LLA: no matching 	TEST_ENSURE( s8.getTokenCount('|') == 1, "test_OWString error 38b");
223*cdf0e10cSrcweir // LLA: no matching 	TEST_ENSURE( s8.getToken(0,'|') == OUString::createFromAscii("token1"), "test_OWString error 39b");
224*cdf0e10cSrcweir // LLA: no matching 	TEST_ENSURE( s8.getToken(-1,'|') == OUString(), "test_OWString error 39c");
225*cdf0e10cSrcweir // LLA: no matching 	TEST_ENSURE( s8.getToken(1,'|') == OUString(), "test_OWString error 39d");
226*cdf0e10cSrcweir // LLA: no matching
227*cdf0e10cSrcweir // LLA: no matching 	s8 = OUString::createFromAscii("|hallo1|hallo2|hallo3|hallo4|hallo5|hallo6|hallo7|hallo8|");
228*cdf0e10cSrcweir // LLA: no matching 	TEST_ENSURE( s8.getTokenCount((sal_Unicode)'|') == 10, "test_OWString error 38");
229*cdf0e10cSrcweir // LLA: no matching 	TEST_ENSURE( s8.getToken(3, (sal_Unicode)'|') == OUString::createFromAscii("hallo3"), "test_OWString error 39");
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir // LLA: removed due to the fact, this is not a clean test!
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir // LLA: 	s7 = OUString();
234*cdf0e10cSrcweir // LLA: 	s7 += s8;
235*cdf0e10cSrcweir // LLA: 	TEST_ENSURE( s7 == s8, "test_OWString error 40");
236*cdf0e10cSrcweir // LLA:
237*cdf0e10cSrcweir // LLA: 	s7 = s8.replaceAt(8, 6, OUString::createFromAscii("mmmmmmmmmm"));
238*cdf0e10cSrcweir // LLA: 	TEST_ENSURE( s7.getLength() == 61, "test_OWString error 41");
239*cdf0e10cSrcweir // LLA:
240*cdf0e10cSrcweir // LLA: 	s8 = s7.replaceAt(8, 11, OUString());
241*cdf0e10cSrcweir // LLA: 	TEST_ENSURE( s8.getLength() == 50, "test_OWString error 42");
242*cdf0e10cSrcweir // LLA:
243*cdf0e10cSrcweir // LLA: 	s7 = s8.replaceAt(8, 0, OUString::createFromAscii("hallo2|"));
244*cdf0e10cSrcweir // LLA: 	TEST_ENSURE( s7.getLength() == 57, "test_OWString error 43");
245*cdf0e10cSrcweir // LLA:
246*cdf0e10cSrcweir // LLA: 	sal_Int32 pos = 0;
247*cdf0e10cSrcweir // LLA: 	while ((pos = s7.indexOf(OUString::createFromAscii("|"))) >= 0)
248*cdf0e10cSrcweir // LLA: 	{
249*cdf0e10cSrcweir // LLA: 		s8 = s7.replaceAt(pos, 1, OUString::createFromAscii("**"));
250*cdf0e10cSrcweir // LLA: 		s7 = s8;
251*cdf0e10cSrcweir // LLA: 	}
252*cdf0e10cSrcweir // LLA: 	TEST_ENSURE( s7.getLength() == 66, "test_OWString error 44");
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 	TEST_ENSURE( OUString::createFromAscii("aaa" ).compareTo( OUString::createFromAscii("bbb" ) ) < 0, "test_OWString error 46" );
255*cdf0e10cSrcweir 	TEST_ENSURE( OUString::createFromAscii("aaa" ).compareTo( OUString::createFromAscii("aaa" ) ) == 0, "test_OWString error 46" );
256*cdf0e10cSrcweir 	TEST_ENSURE( OUString::createFromAscii("bbb" ).compareTo( OUString::createFromAscii("aaa" ) ) > 0, "test_OWString error 47" );
257*cdf0e10cSrcweir 	TEST_ENSURE( OUString::createFromAscii("aaaa" ).compareTo( OUString::createFromAscii("bbb" ) ) < 0, "test_OWString error 48" );
258*cdf0e10cSrcweir 	TEST_ENSURE( OUString::createFromAscii("aaa" ).compareTo( OUString::createFromAscii("bbbb" ) ) < 0, "test_OWString error 49" );
259*cdf0e10cSrcweir 	TEST_ENSURE( OUString::createFromAscii("aaa" ).compareTo( OUString::createFromAscii("aaaa" ) ) < 0, "test_OWString error 50" );
260*cdf0e10cSrcweir 	TEST_ENSURE( OUString::createFromAscii("aaaa" ).compareTo( OUString::createFromAscii("aaa" ) ) > 0, "test_OWString error 51" );
261*cdf0e10cSrcweir 	TEST_ENSURE( OUString::createFromAscii("bbbb" ).compareTo( OUString::createFromAscii("bbb" ) ) > 0, "test_OWString error 52" );
262*cdf0e10cSrcweir 	TEST_ENSURE( OUString::createFromAscii("bbb" ) == OUString::createFromAscii("bbb" ), "test_OWString error 53" );
263*cdf0e10cSrcweir 	TEST_ENSURE( OUString::createFromAscii("bbb" ) == OUString::createFromAscii("bbb" ), "test_OWString error 54" );
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir 	{
266*cdf0e10cSrcweir 		OUString uStr = OUString::createFromAscii( "Hallo" );
267*cdf0e10cSrcweir 		TEST_ENSURE( uStr.compareTo( OUString::createFromAscii("Hallo"), 5 ) == 0, "test_OWString error 54.2.1" );
268*cdf0e10cSrcweir 		TEST_ENSURE( uStr.compareTo( OUString::createFromAscii("Halloa"), 6 ) < 0 , "test_OWString error 54.2.2" );
269*cdf0e10cSrcweir 		TEST_ENSURE( uStr.compareTo( OUString::createFromAscii("1Hallo"), 6 ) > 0, "test_OWString error 54.2.3" );
270*cdf0e10cSrcweir 		TEST_ENSURE( uStr.compareTo( OUString::createFromAscii("Aallo"), 5 ) > 0, "test_OWString error 54.2.4" );
271*cdf0e10cSrcweir 		TEST_ENSURE( uStr.compareTo( OUString::createFromAscii("Halla"), 5 ) > 0, "test_OWString error 54.2.5" );
272*cdf0e10cSrcweir 		TEST_ENSURE( uStr.compareTo( OUString::createFromAscii("Mallo"), 5 ) < 0, "test_OWString error 54.2.6" );
273*cdf0e10cSrcweir 		TEST_ENSURE( uStr.compareTo( OUString::createFromAscii("Hallp"), 5 ) < 0, "test_OWString error 54.2.7" );
274*cdf0e10cSrcweir 	}
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL == 0
277*cdf0e10cSrcweir //YD will fail copy assert on indexes, because ':' returns -1
278*cdf0e10cSrcweir 	s7 = OUString::createFromAscii("Hallo jetzt komm ich");
279*cdf0e10cSrcweir 	s8 = s7.copy(0, s7.indexOf((sal_Unicode)':'));
280*cdf0e10cSrcweir 	TEST_ENSURE( s8.getLength() == 0, "test_OWString error 55");
281*cdf0e10cSrcweir 	TEST_ENSURE( s8.compareTo(OUString()) == 0, "test_OWString error 56");
282*cdf0e10cSrcweir #endif
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir 	// ASCII-Schnittstellen, AB 15.10.1999
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir 	//       "Ich bin ein reiner ASCII-String mit ein paar Zahlen 0123456789 und Zeichen"
287*cdf0e10cSrcweir 	//		  |	   |	|	 |	  |	   |	|	 |	  |	   |	|    |    |    |    |
288*cdf0e10cSrcweir 	//index	  0	   5	10	 15	  20   25	30	 35	  40   45	50	 55   60   65   70
289*cdf0e10cSrcweir 	//
290*cdf0e10cSrcweir 	//       "Ich bin ein weiterer ASCII-String"
291*cdf0e10cSrcweir 	//		  |	   |	|	 |	  |	   |	|
292*cdf0e10cSrcweir 	//index	  0	   5	10	 15	  20   25	30
293*cdf0e10cSrcweir 	sal_Char ascii_str1[] = "Ich bin ein reiner ASCII-String mit ein paar Zahlen 0123456789 und Zeichen";
294*cdf0e10cSrcweir 	sal_Char ascii_str2[] = "Ich bin ein weiterer ASCII-String";
295*cdf0e10cSrcweir 	OUString OWAsciiStr1 = OUString::createFromAscii( ascii_str1 );
296*cdf0e10cSrcweir 	sal_Int32 nLen1 = OWAsciiStr1.getLength();
297*cdf0e10cSrcweir 	TEST_ENSURE( nLen1 == 74, "test_OWString error 57" );
298*cdf0e10cSrcweir 	OUString OWAsciiStr2 = OUString::createFromAscii( ascii_str2 );
299*cdf0e10cSrcweir 	sal_Int32 nLen2 = OWAsciiStr2.getLength();
300*cdf0e10cSrcweir 	TEST_ENSURE( nLen2 == 33, "test_OWString error 58" );
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir 	sal_Int32 nCompareResult11 = OWAsciiStr1.compareToAscii( ascii_str1 );
303*cdf0e10cSrcweir 	TEST_ENSURE( nCompareResult11 == 0, "test_OWString error 59" );
304*cdf0e10cSrcweir 	sal_Int32 nCompareResult12 = OWAsciiStr1.compareToAscii( ascii_str2 );
305*cdf0e10cSrcweir 	TEST_ENSURE( nCompareResult12 < 0, "test_OWString error 60" );
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir 	sal_Int32 nCompareResult21 = OWAsciiStr2.compareToAscii( ascii_str1 );
308*cdf0e10cSrcweir 	TEST_ENSURE( nCompareResult21 > 0, "test_OWString error 61" );
309*cdf0e10cSrcweir 	sal_Int32 nCompareResult22 = OWAsciiStr2.compareToAscii( ascii_str2 );
310*cdf0e10cSrcweir 	TEST_ENSURE( nCompareResult22 == 0, "test_OWString error 62" );
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir 	sal_Int32 nCompareResult12_Len12 = OWAsciiStr1.compareToAscii( ascii_str2, 12 );
313*cdf0e10cSrcweir 	TEST_ENSURE( nCompareResult12_Len12 == 0, "test_OWString error 63" );
314*cdf0e10cSrcweir 	sal_Int32 nCompareResult12_Len13 = OWAsciiStr1.compareToAscii( ascii_str2, 13 );
315*cdf0e10cSrcweir 	TEST_ENSURE( nCompareResult12_Len13 < 0, "test_OWString error 64" );
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir 	sal_Int32 nCompareResult21_Len12 = OWAsciiStr2.compareToAscii( ascii_str1, 12 );
318*cdf0e10cSrcweir 	TEST_ENSURE( nCompareResult21_Len12 == 0, "test_OWString error 65" );
319*cdf0e10cSrcweir 	sal_Int32 nCompareResult21_Len13 = OWAsciiStr2.compareToAscii( ascii_str1, 13 );
320*cdf0e10cSrcweir 	TEST_ENSURE( nCompareResult21_Len13 > 0, "test_OWString error 66" );
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir 	{
323*cdf0e10cSrcweir 		OUString uStr = OUString::createFromAscii( "Hallo" );
324*cdf0e10cSrcweir 		TEST_ENSURE( uStr.equalsAsciiL( "Hallo", 5 ), "test_OWString error 66.1.1" );
325*cdf0e10cSrcweir 		TEST_ENSURE( !uStr.equalsAsciiL( "Hallo1", 6 ), "test_OWString error 66.1.2" );
326*cdf0e10cSrcweir 		TEST_ENSURE( !uStr.equalsAsciiL( "1Hallo", 6 ), "test_OWString error 66.1.3" );
327*cdf0e10cSrcweir 		TEST_ENSURE( !uStr.equalsAsciiL( "aallo", 5 ), "test_OWString error 66.1.2" );
328*cdf0e10cSrcweir 		TEST_ENSURE( !uStr.equalsAsciiL( "Halla", 5 ), "test_OWString error 66.1.3" );
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir 		TEST_ENSURE( uStr.reverseCompareToAsciiL( "Hallo", 5 ) == 0, "test_OWString error 66.2.1" );
331*cdf0e10cSrcweir 		TEST_ENSURE( uStr.reverseCompareToAsciiL( "Halloa", 6 ) > 0 , "test_OWString error 66.2.2" );
332*cdf0e10cSrcweir 		TEST_ENSURE( uStr.reverseCompareToAsciiL( "1Hallo", 6 ) < 0, "test_OWString error 66.2.3" );
333*cdf0e10cSrcweir 		TEST_ENSURE( uStr.reverseCompareToAsciiL( "Aallo", 5 ) > 0, "test_OWString error 66.2.4" );
334*cdf0e10cSrcweir 		TEST_ENSURE( uStr.reverseCompareToAsciiL( "Halla", 5 ) > 0, "test_OWString error 66.2.5" );
335*cdf0e10cSrcweir 		TEST_ENSURE( uStr.reverseCompareToAsciiL( "Mallo", 5 ) < 0, "test_OWString error 66.2.6" );
336*cdf0e10cSrcweir 		TEST_ENSURE( uStr.reverseCompareToAsciiL( "Hallp", 5 ) < 0, "test_OWString error 66.2.7" );
337*cdf0e10cSrcweir 	}
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir 	// toInt64
340*cdf0e10cSrcweir 	OUString s9( OUString::createFromAscii(" -3223372036854775807") );
341*cdf0e10cSrcweir 	sal_Int64 ln1 = s9.toInt64();
342*cdf0e10cSrcweir #if (defined UNX) || (defined OS2)
343*cdf0e10cSrcweir 	TEST_ENSURE( ln1 == -3223372036854775807LL, "test_OWString error 67" );
344*cdf0e10cSrcweir #else
345*cdf0e10cSrcweir 	TEST_ENSURE( ln1 == -3223372036854775807, "test_OWString error 67" );
346*cdf0e10cSrcweir #endif
347*cdf0e10cSrcweir 	OUString s10( OUString::createFromAscii("13243A65f1H45") );
348*cdf0e10cSrcweir 	sal_Int64 ln2 = s10.toInt64();
349*cdf0e10cSrcweir 	TEST_ENSURE( ln2 == 13243, "test_OWString error 68" );
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir 	sal_Int64 ln3 = s10.toInt64( 16 );
352*cdf0e10cSrcweir #if (defined UNX) || (defined OS2)
353*cdf0e10cSrcweir 	TEST_ENSURE( ln3 == 0x13243A65F1LL, "test_OWString error 69" );
354*cdf0e10cSrcweir #else
355*cdf0e10cSrcweir 	TEST_ENSURE( ln3 == 0x13243A65F1, "test_OWString error 69" );
356*cdf0e10cSrcweir #endif
357*cdf0e10cSrcweir 	// Exotic base
358*cdf0e10cSrcweir 	OUString s11( OUString::createFromAscii("H4A") );
359*cdf0e10cSrcweir 	sal_Int64 ln4 = s11.toInt64( 23 );
360*cdf0e10cSrcweir 	TEST_ENSURE( ln4 == 23*23*17 + 4 * 23 + 10, "test_OWString error 70" );
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir 	// toInt32
363*cdf0e10cSrcweir 	OUString s12( OUString::createFromAscii(" -220368507") );
364*cdf0e10cSrcweir 	sal_Int32 n1 = s12.toInt32();
365*cdf0e10cSrcweir 	TEST_ENSURE( n1 == -220368507, "test_OWString error 71" );
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir 	OUString s13( OUString::createFromAscii("4423A61H45") );
368*cdf0e10cSrcweir 	sal_Int64 n2 = s13.toInt32();
369*cdf0e10cSrcweir 	TEST_ENSURE( n2 == 4423, "test_OWString error 72" );
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir 	sal_Int64 n3 = s13.toInt64( 16 );
372*cdf0e10cSrcweir 	TEST_ENSURE( n3 == 0x4423A61, "test_OWString error 73" );
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir // LLA: Value tests fails most the time, this is not a good test
375*cdf0e10cSrcweir // LLA: 	double d = 1.23456781;
376*cdf0e10cSrcweir // LLA: 	OUString sDouble = OUString::valueOf( d );
377*cdf0e10cSrcweir // LLA: 	char str[] = "1.2345678099999999";
378*cdf0e10cSrcweir // LLA: 	sal_Int32 nLength = sDouble.getLength();
379*cdf0e10cSrcweir // LLA: 	TEST_ENSURE( nLength == strlen( str ), "test_OWString error 74" );
380*cdf0e10cSrcweir // LLA: 	sal_Int32 nCompare = sDouble.compareToAscii( str );
381*cdf0e10cSrcweir // LLA: 	TEST_ENSURE( nCompare == 0, "test_OWString error 75" );
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir 	printf("test_OWString OK !!!\n");
384*cdf0e10cSrcweir 	return;
385*cdf0e10cSrcweir }
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir // -----------------------------------------------------------------------------
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir void oldtests::test_OString2OUStringAndViceVersa()
390*cdf0e10cSrcweir {
391*cdf0e10cSrcweir 	OString s1("Hallo jetzt komm ich");
392*cdf0e10cSrcweir 	OUString u1 = OStringToOUString(s1, RTL_TEXTENCODING_MS_1252);
393*cdf0e10cSrcweir 	TEST_ENSURE( u1.equals(OUString::createFromAscii("Hallo jetzt komm ich")), "test_OString2OWStringAndViceVersa error 1" );
394*cdf0e10cSrcweir 	u1 = OStringToOUString(s1, RTL_TEXTENCODING_IBM_850);
395*cdf0e10cSrcweir 	TEST_ENSURE( u1.equals(OUString::createFromAscii("Hallo jetzt komm ich")), "test_OString2OWStringAndViceVersa error 2" );
396*cdf0e10cSrcweir 	u1 = OStringToOUString(s1, RTL_TEXTENCODING_ISO_8859_15);
397*cdf0e10cSrcweir 	TEST_ENSURE( u1.equals(OUString::createFromAscii("Hallo jetzt komm ich")), "test_OString2OWStringAndViceVersa error 3" );
398*cdf0e10cSrcweir 	u1 = OStringToOUString(s1, RTL_TEXTENCODING_ASCII_US);
399*cdf0e10cSrcweir 	TEST_ENSURE( u1.equals(OUString::createFromAscii("Hallo jetzt komm ich")), "test_OString2OWStringAndViceVersa error 4" );
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir 	OString s2 = OUStringToOString(u1, RTL_TEXTENCODING_MS_1252);
402*cdf0e10cSrcweir 	TEST_ENSURE( s2.equals("Hallo jetzt komm ich"), "test_OString2OWStringAndViceVersa error 5" );
403*cdf0e10cSrcweir 	s2 = OUStringToOString(u1, RTL_TEXTENCODING_IBM_850);
404*cdf0e10cSrcweir 	TEST_ENSURE( s2.equals("Hallo jetzt komm ich"), "test_OString2OWStringAndViceVersa error 6" );
405*cdf0e10cSrcweir 	s2 = OUStringToOString(u1, RTL_TEXTENCODING_ISO_8859_15);
406*cdf0e10cSrcweir 	TEST_ENSURE( s2.equals("Hallo jetzt komm ich"), "test_OString2OWStringAndViceVersa error 7" );
407*cdf0e10cSrcweir 	s2 = OUStringToOString(u1, RTL_TEXTENCODING_ASCII_US);
408*cdf0e10cSrcweir 	TEST_ENSURE( s2.equals("Hallo jetzt komm ich"), "test_OString2OWStringAndViceVersa error 8" );
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir 	printf("test_OString2OWStringAndViceVersa OK !!!\n");
411*cdf0e10cSrcweir }
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir } // namespace rtl_OUString
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir // -----------------------------------------------------------------------------
416*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_OUString::oldtests, "rtl_OUString" );
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir // -----------------------------------------------------------------------------
419*cdf0e10cSrcweir NOADDITIONAL;
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir 
422