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