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
10cdf0e10cSrcweir *
11*87d2adbcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
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.
19cdf0e10cSrcweir *
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 #include <string.h>
27cdf0e10cSrcweir
28cdf0e10cSrcweir #ifndef _SAL_TYPES_H_
29cdf0e10cSrcweir #include <sal/types.h>
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir
32cdf0e10cSrcweir // #ifndef _RTL_TRES_H_
33cdf0e10cSrcweir // #include <rtl/tres.h>
34cdf0e10cSrcweir // #endif
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include <testshl/tresstatewrapper.hxx>
37cdf0e10cSrcweir
38cdf0e10cSrcweir #ifndef _RTL_STRING_HXX_
39cdf0e10cSrcweir #include <rtl/string.hxx>
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir
42cdf0e10cSrcweir #ifndef _RTL_STRING_CONST_H_
43cdf0e10cSrcweir #include <rtl_String_Const.h>
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir
46cdf0e10cSrcweir #ifndef _RTL_STRING_UTILS_HXX_
47cdf0e10cSrcweir #include <rtl_String_Utils.hxx>
48cdf0e10cSrcweir #endif
49cdf0e10cSrcweir #include <rtl/ustring.h>
50cdf0e10cSrcweir
51cdf0e10cSrcweir using namespace rtl;
52cdf0e10cSrcweir
53cdf0e10cSrcweir //------------------------------------------------------------------------
54cdf0e10cSrcweir // test classes
55cdf0e10cSrcweir //------------------------------------------------------------------------
56cdf0e10cSrcweir const int MAXBUFLENGTH = 255;
57cdf0e10cSrcweir //------------------------------------------------------------------------
58cdf0e10cSrcweir // helper functions
59cdf0e10cSrcweir //------------------------------------------------------------------------
60cdf0e10cSrcweir
unused()61cdf0e10cSrcweir static void unused()
62cdf0e10cSrcweir {
63cdf0e10cSrcweir test_ini_uString();
64cdf0e10cSrcweir (void)inputChar;
65cdf0e10cSrcweir (void)input1StrDefault;
66cdf0e10cSrcweir (void)input1StrNormal;
67cdf0e10cSrcweir (void)input1StrLastDefault;
68cdf0e10cSrcweir (void)input1StrLastNormal;
69cdf0e10cSrcweir unused();
70cdf0e10cSrcweir }
71cdf0e10cSrcweir
72cdf0e10cSrcweir //------------------------------------------------------------------------
73cdf0e10cSrcweir // testing constructors
74cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_ctor_001(hTestResult hRtlTestResult)75cdf0e10cSrcweir static sal_Bool test_rtl_OString_ctor_001( hTestResult hRtlTestResult )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir ::rtl::OString aStr;
78cdf0e10cSrcweir rtl_String* pData = aStr.pData;
79cdf0e10cSrcweir
80cdf0e10cSrcweir
81cdf0e10cSrcweir return
82cdf0e10cSrcweir (
83cdf0e10cSrcweir c_rtl_tres_state
84cdf0e10cSrcweir (
85cdf0e10cSrcweir hRtlTestResult,
86cdf0e10cSrcweir pData->length == 0 &&
87cdf0e10cSrcweir ! *pData->buffer,
88cdf0e10cSrcweir "New OString containing no characters",
89cdf0e10cSrcweir "ctor_001"
90cdf0e10cSrcweir )
91cdf0e10cSrcweir );
92cdf0e10cSrcweir }
93cdf0e10cSrcweir
94cdf0e10cSrcweir //------------------------------------------------------------------------
95cdf0e10cSrcweir
test_rtl_OString_ctor_002(hTestResult hRtlTestResult)96cdf0e10cSrcweir static sal_Bool SAL_CALL test_rtl_OString_ctor_002(
97cdf0e10cSrcweir hTestResult hRtlTestResult )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir ::rtl::OString aStr(kTestStr1);
100cdf0e10cSrcweir rtl_String* pData = aStr.pData;
101cdf0e10cSrcweir
102cdf0e10cSrcweir return
103cdf0e10cSrcweir (
104cdf0e10cSrcweir c_rtl_tres_state
105cdf0e10cSrcweir (
106cdf0e10cSrcweir hRtlTestResult,
107cdf0e10cSrcweir pData->refCount == 1 &&
108cdf0e10cSrcweir pData->length == kTestStr1Len &&
109cdf0e10cSrcweir cmpstr( (const sal_Char*)pData->buffer, kTestStr1, kTestStr1Len ),
110cdf0e10cSrcweir "New OString from a character buffer array",
111cdf0e10cSrcweir "ctor_002"
112cdf0e10cSrcweir )
113cdf0e10cSrcweir );
114cdf0e10cSrcweir }
115cdf0e10cSrcweir //------------------------------------------------------------------------
116cdf0e10cSrcweir
test_rtl_OString_ctor_003(hTestResult hRtlTestResult)117cdf0e10cSrcweir static sal_Bool SAL_CALL test_rtl_OString_ctor_003(
118cdf0e10cSrcweir hTestResult hRtlTestResult )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir ::rtl::OString aStr(kTestStr2, kTestStr1Len);
121cdf0e10cSrcweir rtl_String* pData = aStr.pData;
122cdf0e10cSrcweir
123cdf0e10cSrcweir return
124cdf0e10cSrcweir (
125cdf0e10cSrcweir c_rtl_tres_state
126cdf0e10cSrcweir (
127cdf0e10cSrcweir hRtlTestResult,
128cdf0e10cSrcweir pData->refCount == 1 &&
129cdf0e10cSrcweir pData->length == kTestStr1Len &&
130cdf0e10cSrcweir cmpstr( (const sal_Char*)pData->buffer, kTestStr2, kTestStr1Len ),
131cdf0e10cSrcweir "New OString from the first n chars of ascii string",
132cdf0e10cSrcweir "ctor_003"
133cdf0e10cSrcweir )
134cdf0e10cSrcweir );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir
137cdf0e10cSrcweir //------------------------------------------------------------------------
138cdf0e10cSrcweir
test_rtl_OString_ctor_004(hTestResult hRtlTestResult)139cdf0e10cSrcweir static sal_Bool SAL_CALL test_rtl_OString_ctor_004(
140cdf0e10cSrcweir hTestResult hRtlTestResult)
141cdf0e10cSrcweir {
142cdf0e10cSrcweir ::rtl::OString aStr1(kTestStr1);
143cdf0e10cSrcweir ::rtl::OString aStr2(aStr1);
144cdf0e10cSrcweir rtl_String* pData1 = aStr1.pData;
145cdf0e10cSrcweir rtl_String* pData2 = aStr2.pData;
146cdf0e10cSrcweir
147cdf0e10cSrcweir return
148cdf0e10cSrcweir (
149cdf0e10cSrcweir c_rtl_tres_state
150cdf0e10cSrcweir (
151cdf0e10cSrcweir hRtlTestResult,
152cdf0e10cSrcweir pData1->refCount == pData2->refCount &&
153cdf0e10cSrcweir pData1->length == kTestStr1Len &&
154cdf0e10cSrcweir pData1->buffer == pData2->buffer,
155cdf0e10cSrcweir "New OString from an OString",
156cdf0e10cSrcweir "ctor_004"
157cdf0e10cSrcweir )
158cdf0e10cSrcweir );
159cdf0e10cSrcweir }
160cdf0e10cSrcweir //------------------------------------------------------------------------
161cdf0e10cSrcweir
test_rtl_OString_ctor_005(hTestResult hRtlTestResult)162cdf0e10cSrcweir static sal_Bool test_rtl_OString_ctor_005( hTestResult hRtlTestResult )
163cdf0e10cSrcweir {
164cdf0e10cSrcweir rtl_String *aStr1 = NULL;
165cdf0e10cSrcweir
166cdf0e10cSrcweir rtl_string_newFromStr( &aStr1, kTestStr1 );
167cdf0e10cSrcweir
168cdf0e10cSrcweir if ( aStr1 != NULL )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir ::rtl::OString aStr2(aStr1);
171cdf0e10cSrcweir rtl_String* pData2 = aStr2.pData;
172cdf0e10cSrcweir
173cdf0e10cSrcweir sal_Bool bOK = c_rtl_tres_state
174cdf0e10cSrcweir (
175cdf0e10cSrcweir hRtlTestResult,
176cdf0e10cSrcweir aStr1->refCount == pData2->refCount &&
177cdf0e10cSrcweir pData2->length == kTestStr1Len &&
178cdf0e10cSrcweir aStr1->buffer == pData2->buffer,
179cdf0e10cSrcweir "new OString from a RTL String",
180cdf0e10cSrcweir "ctor_005"
181cdf0e10cSrcweir );
182cdf0e10cSrcweir
183cdf0e10cSrcweir rtl_string_release( aStr1 );
184cdf0e10cSrcweir aStr1 = NULL;
185cdf0e10cSrcweir return ( bOK );
186cdf0e10cSrcweir }
187cdf0e10cSrcweir return
188cdf0e10cSrcweir (
189cdf0e10cSrcweir c_rtl_tres_state
190cdf0e10cSrcweir (
191cdf0e10cSrcweir hRtlTestResult,
192cdf0e10cSrcweir sal_False,
193cdf0e10cSrcweir "copying an ascii string to a RTL String!",
194cdf0e10cSrcweir "ctor_005"
195cdf0e10cSrcweir )
196cdf0e10cSrcweir );
197cdf0e10cSrcweir }
198cdf0e10cSrcweir
199cdf0e10cSrcweir //------------------------------------------------------------------------
200cdf0e10cSrcweir
test_rtl_OString_ctor_006(hTestResult hRtlTestResult)201cdf0e10cSrcweir static sal_Bool test_rtl_OString_ctor_006( hTestResult hRtlTestResult )
202cdf0e10cSrcweir {
203cdf0e10cSrcweir
204cdf0e10cSrcweir sal_Unicode aStr1[kTestStr1Len+1];
205cdf0e10cSrcweir
206cdf0e10cSrcweir if ( AStringToUStringNCopy( aStr1, kTestStr1, kTestStr1Len ) )
207cdf0e10cSrcweir {
208cdf0e10cSrcweir if ( AStringToUStringNCompare( aStr1, kTestStr1, kTestStr1Len ) == 0 )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir // const sal_Char *kTCMessage[2] = { "", "array." };
211cdf0e10cSrcweir
212cdf0e10cSrcweir ::rtl::OString aStr2
213cdf0e10cSrcweir (
214cdf0e10cSrcweir aStr1,
215cdf0e10cSrcweir kTestStr1Len,
216cdf0e10cSrcweir kEncodingRTLTextUSASCII,
217cdf0e10cSrcweir kConvertFlagsOUStringToOString
218cdf0e10cSrcweir );
219cdf0e10cSrcweir
220cdf0e10cSrcweir return
221cdf0e10cSrcweir (
222cdf0e10cSrcweir c_rtl_tres_state
223cdf0e10cSrcweir (
224cdf0e10cSrcweir hRtlTestResult,
225cdf0e10cSrcweir aStr2 == kTestStr1,
226cdf0e10cSrcweir "new OString from a unicode character buffer",
227cdf0e10cSrcweir "ctor_006"
228cdf0e10cSrcweir )
229cdf0e10cSrcweir );
230cdf0e10cSrcweir } /// end if AStringToUStringNCompare
231cdf0e10cSrcweir
232cdf0e10cSrcweir return
233cdf0e10cSrcweir (
234cdf0e10cSrcweir c_rtl_tres_state
235cdf0e10cSrcweir (
236cdf0e10cSrcweir hRtlTestResult,
237cdf0e10cSrcweir sal_False,
238cdf0e10cSrcweir "compare ascii string with unicode string!",
239cdf0e10cSrcweir "ctor_006"
240cdf0e10cSrcweir )
241cdf0e10cSrcweir );
242cdf0e10cSrcweir } /// end if AStringToUStringNCopy
243cdf0e10cSrcweir
244cdf0e10cSrcweir return
245cdf0e10cSrcweir (
246cdf0e10cSrcweir c_rtl_tres_state
247cdf0e10cSrcweir (
248cdf0e10cSrcweir hRtlTestResult,
249cdf0e10cSrcweir sal_False,
250cdf0e10cSrcweir "copy ascii string to unicode string!",
251cdf0e10cSrcweir "ctor_006"
252cdf0e10cSrcweir )
253cdf0e10cSrcweir );
254cdf0e10cSrcweir }
test_rtl_OString_ctors(hTestResult hRtlTestResult)255cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_ctors(
256cdf0e10cSrcweir hTestResult hRtlTestResult )
257cdf0e10cSrcweir {
258cdf0e10cSrcweir
259cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "ctor");
260cdf0e10cSrcweir sal_Bool bTSState = test_rtl_OString_ctor_001( hRtlTestResult );
261cdf0e10cSrcweir
262cdf0e10cSrcweir bTSState &= test_rtl_OString_ctor_002( hRtlTestResult);
263cdf0e10cSrcweir bTSState &= test_rtl_OString_ctor_003( hRtlTestResult);
264cdf0e10cSrcweir bTSState &= test_rtl_OString_ctor_004( hRtlTestResult);
265cdf0e10cSrcweir bTSState &= test_rtl_OString_ctor_005( hRtlTestResult);
266cdf0e10cSrcweir bTSState &= test_rtl_OString_ctor_006( hRtlTestResult);
267cdf0e10cSrcweir
268cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "ctor");
269cdf0e10cSrcweir
270cdf0e10cSrcweir // return( bTSState );
271cdf0e10cSrcweir }
272cdf0e10cSrcweir
273cdf0e10cSrcweir
274cdf0e10cSrcweir
275cdf0e10cSrcweir //------------------------------------------------------------------------
276cdf0e10cSrcweir // testing the method getLength
277cdf0e10cSrcweir //------------------------------------------------------------------------
278cdf0e10cSrcweir
test_rtl_OString_getLength(hTestResult hRtlTestResult)279cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_getLength(
280cdf0e10cSrcweir hTestResult hRtlTestResult)
281cdf0e10cSrcweir {
282cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
283cdf0e10cSrcweir sal_Char* pMeth = methName;
284cdf0e10cSrcweir
285cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "getLength");
286cdf0e10cSrcweir
287cdf0e10cSrcweir typedef struct TestCase
288cdf0e10cSrcweir {
289cdf0e10cSrcweir sal_Char* comments;
290cdf0e10cSrcweir sal_Int32 expVal;
291cdf0e10cSrcweir OString* input;
292cdf0e10cSrcweir ~TestCase() { delete input;}
293cdf0e10cSrcweir } TestCase;
294cdf0e10cSrcweir
295cdf0e10cSrcweir TestCase arrTestCase[]={
296cdf0e10cSrcweir
297cdf0e10cSrcweir {"length of ascii string", kTestStr1Len, new OString(kTestStr1)},
298cdf0e10cSrcweir {"length of ascci string of size 1", 1, new OString("1")},
299cdf0e10cSrcweir {"length of empty string (default constructor)", 0, new OString()},
300cdf0e10cSrcweir {"length of empty string (empty ascii string arg)",0,new OString("")},
301cdf0e10cSrcweir {"length of empty string (string arg = '\\0')",0,new OString("\0")}
302cdf0e10cSrcweir };
303cdf0e10cSrcweir
304cdf0e10cSrcweir
305cdf0e10cSrcweir sal_Bool res = sal_True;
306cdf0e10cSrcweir sal_uInt32 i;
307cdf0e10cSrcweir
308cdf0e10cSrcweir for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
309cdf0e10cSrcweir {
310cdf0e10cSrcweir sal_Int32 length = arrTestCase[i].input->getLength();
311cdf0e10cSrcweir sal_Bool lastRes = (length == arrTestCase[i].expVal);
312cdf0e10cSrcweir c_rtl_tres_state
313cdf0e10cSrcweir (
314cdf0e10cSrcweir hRtlTestResult,
315cdf0e10cSrcweir lastRes,
316cdf0e10cSrcweir arrTestCase[i].comments,
317cdf0e10cSrcweir createName( pMeth, "getLength", i )
318cdf0e10cSrcweir
319cdf0e10cSrcweir );
320cdf0e10cSrcweir res &= lastRes;
321cdf0e10cSrcweir }
322cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "getLength");
323cdf0e10cSrcweir // return ( res );
324cdf0e10cSrcweir }
325cdf0e10cSrcweir
326cdf0e10cSrcweir
327cdf0e10cSrcweir
328cdf0e10cSrcweir //------------------------------------------------------------------------
329cdf0e10cSrcweir // testing the method equals( const OString & aStr )
330cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_equals(hTestResult hRtlTestResult)331cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_equals(
332cdf0e10cSrcweir hTestResult hRtlTestResult )
333cdf0e10cSrcweir {
334cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
335cdf0e10cSrcweir sal_Char* pMeth = methName;
336cdf0e10cSrcweir
337cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "equals");
338cdf0e10cSrcweir
339cdf0e10cSrcweir typedef struct TestCase
340cdf0e10cSrcweir {
341cdf0e10cSrcweir sal_Char* comments;
342cdf0e10cSrcweir sal_Bool expVal;
343cdf0e10cSrcweir OString* input1;
344cdf0e10cSrcweir OString* input2;
345cdf0e10cSrcweir ~TestCase() { delete input1;delete input2;}
346cdf0e10cSrcweir } TestCase;
347cdf0e10cSrcweir
348cdf0e10cSrcweir TestCase arrTestCase[]={
349cdf0e10cSrcweir
350cdf0e10cSrcweir {"same size", sal_True, new OString(kTestStr1),new OString(kTestStr1)},
351cdf0e10cSrcweir {"different size", sal_False, new OString(kTestStr1),
352cdf0e10cSrcweir new OString(kTestStr2)},
353cdf0e10cSrcweir {"same size, no case match", sal_False, new OString(kTestStr1),
354cdf0e10cSrcweir new OString(kTestStr3)},
355cdf0e10cSrcweir {"two empty strings(def. constructor)", sal_True, new OString(),
356cdf0e10cSrcweir new OString()},
357cdf0e10cSrcweir {"empty(def.constructor) and non empty", sal_False, new OString(),
358cdf0e10cSrcweir new OString(kTestStr2)},
359cdf0e10cSrcweir {"non empty and empty(def. constructor)", sal_False,
360cdf0e10cSrcweir new OString(kTestStr1),new OString()},
361cdf0e10cSrcweir {"two empty strings(string arg = '\\0')", sal_True,
362cdf0e10cSrcweir new OString(""),new OString("")},
363cdf0e10cSrcweir {"empty(string arg = '\\0') and non empty", sal_False,
364cdf0e10cSrcweir new OString(""),new OString(kTestStr2)},
365cdf0e10cSrcweir {"non empty and empty(string arg = '\\0')", sal_False,
366cdf0e10cSrcweir new OString(kTestStr1),new OString("")}
367cdf0e10cSrcweir };
368cdf0e10cSrcweir
369cdf0e10cSrcweir sal_Bool res = sal_True;
370cdf0e10cSrcweir sal_uInt32 i;
371cdf0e10cSrcweir
372cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
373cdf0e10cSrcweir {
374cdf0e10cSrcweir sal_Bool lastRes =
375cdf0e10cSrcweir ( arrTestCase[i].input1->equals(*(arrTestCase[i].input2)) ==
376cdf0e10cSrcweir arrTestCase[i].expVal );
377cdf0e10cSrcweir
378cdf0e10cSrcweir c_rtl_tres_state
379cdf0e10cSrcweir (
380cdf0e10cSrcweir hRtlTestResult,
381cdf0e10cSrcweir lastRes,
382cdf0e10cSrcweir arrTestCase[i].comments,
383cdf0e10cSrcweir createName( pMeth, "equals", i )
384cdf0e10cSrcweir );
385cdf0e10cSrcweir
386cdf0e10cSrcweir res &= lastRes;
387cdf0e10cSrcweir }
388cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "equals");
389cdf0e10cSrcweir // return (res);
390cdf0e10cSrcweir }
391cdf0e10cSrcweir
392cdf0e10cSrcweir //------------------------------------------------------------------------
393cdf0e10cSrcweir // testing the method equalsIgnoreAsciiCase( const OString & aStr )
394cdf0e10cSrcweir //------------------------------------------------------------------------
395cdf0e10cSrcweir
test_rtl_OString_equalsIgnoreAsciiCase(hTestResult hRtlTestResult)396cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_equalsIgnoreAsciiCase(
397cdf0e10cSrcweir hTestResult hRtlTestResult )
398cdf0e10cSrcweir {
399cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
400cdf0e10cSrcweir sal_Char* pMeth = methName;
401cdf0e10cSrcweir
402cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "equalsIgnoreAsciiCase");
403cdf0e10cSrcweir typedef struct TestCase
404cdf0e10cSrcweir {
405cdf0e10cSrcweir sal_Char* comments;
406cdf0e10cSrcweir sal_Bool expVal;
407cdf0e10cSrcweir OString* input1;
408cdf0e10cSrcweir OString* input2;
409cdf0e10cSrcweir ~TestCase() { delete input1;delete input2;}
410cdf0e10cSrcweir } TestCase;
411cdf0e10cSrcweir
412cdf0e10cSrcweir TestCase arrTestCase[]={
413cdf0e10cSrcweir {"same strings but different cases",sal_True,new OString(kTestStr4),
414cdf0e10cSrcweir new OString(kTestStr5)},
415cdf0e10cSrcweir {"same strings",sal_True,new OString(kTestStr4),
416cdf0e10cSrcweir new OString(kTestStr4)},
417cdf0e10cSrcweir {"with equal beginning",sal_False,new OString(kTestStr2),
418cdf0e10cSrcweir new OString(kTestStr4)},
419cdf0e10cSrcweir {"empty(def.constructor) and non empty",sal_False,new OString(),
420cdf0e10cSrcweir new OString(kTestStr5)},
421cdf0e10cSrcweir {"non empty and empty(def.constructor)",sal_False,
422cdf0e10cSrcweir new OString(kTestStr4), new OString()},
423cdf0e10cSrcweir {"two empty strings(def.constructor)",sal_True,new OString(),
424cdf0e10cSrcweir new OString()},
425cdf0e10cSrcweir {"different strings with equal length",sal_False,
426cdf0e10cSrcweir new OString(kTestStr10), new OString(kTestStr11)}
427cdf0e10cSrcweir };
428cdf0e10cSrcweir
429cdf0e10cSrcweir sal_Bool res = sal_True;
430cdf0e10cSrcweir sal_uInt32 i;
431cdf0e10cSrcweir
432cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
433cdf0e10cSrcweir {
434cdf0e10cSrcweir sal_Bool lastRes =
435cdf0e10cSrcweir (arrTestCase[i].input1->equalsIgnoreAsciiCase(*arrTestCase[i].input2)
436cdf0e10cSrcweir == arrTestCase[i].expVal);
437cdf0e10cSrcweir
438cdf0e10cSrcweir c_rtl_tres_state
439cdf0e10cSrcweir (
440cdf0e10cSrcweir hRtlTestResult,
441cdf0e10cSrcweir lastRes,
442cdf0e10cSrcweir arrTestCase[i].comments,
443cdf0e10cSrcweir createName( pMeth, "equalsIgnoreAsciiCase", i )
444cdf0e10cSrcweir );
445cdf0e10cSrcweir
446cdf0e10cSrcweir res &= lastRes;
447cdf0e10cSrcweir }
448cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "equalsIgnoreAsciiCase");
449cdf0e10cSrcweir
450cdf0e10cSrcweir // return (res);
451cdf0e10cSrcweir }
452cdf0e10cSrcweir
test_rtl_OString_compareTo_001(hTestResult hRtlTestResult)453cdf0e10cSrcweir static sal_Bool SAL_CALL test_rtl_OString_compareTo_001(
454cdf0e10cSrcweir hTestResult hRtlTestResult )
455cdf0e10cSrcweir {
456cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
457cdf0e10cSrcweir sal_Char* pMeth = methName;
458cdf0e10cSrcweir
459cdf0e10cSrcweir typedef struct TestCase
460cdf0e10cSrcweir {
461cdf0e10cSrcweir sal_Char* comments;
462cdf0e10cSrcweir sal_Int32 expVal;
463cdf0e10cSrcweir OString* input1;
464cdf0e10cSrcweir OString* input2;
465cdf0e10cSrcweir ~TestCase() { delete input1;delete input2;}
466cdf0e10cSrcweir } TestCase;
467cdf0e10cSrcweir
468cdf0e10cSrcweir TestCase arrTestCase[]={
469cdf0e10cSrcweir
470cdf0e10cSrcweir {"simple compare, str1 to str5",-1,new OString(kTestStr1),
471cdf0e10cSrcweir new OString(kTestStr5)},
472cdf0e10cSrcweir {"simple compare, str2 to str5",-1,new OString(kTestStr2),
473cdf0e10cSrcweir new OString(kTestStr5)},
474cdf0e10cSrcweir {"simple compare, str1 to str9",-1,new OString(kTestStr1),
475cdf0e10cSrcweir new OString(kTestStr9)},
476cdf0e10cSrcweir {"simple compare, str1 to str2",-1,new OString(kTestStr1),
477cdf0e10cSrcweir new OString(kTestStr2)},
478cdf0e10cSrcweir {"simple compare, str4 to str5",-1,new OString(kTestStr4),
479cdf0e10cSrcweir new OString(kTestStr5)},
480cdf0e10cSrcweir {"simple compare, str1 to str3",-1,new OString(kTestStr1),
481cdf0e10cSrcweir new OString(kTestStr3)},
482cdf0e10cSrcweir {"simple compare, str5 to str1",+1,new OString(kTestStr5),
483cdf0e10cSrcweir new OString(kTestStr1)},
484cdf0e10cSrcweir {"simple compare, str2 to str1",+1,new OString(kTestStr2),
485cdf0e10cSrcweir new OString(kTestStr1)},
486cdf0e10cSrcweir {"simple compare, str9 to str5",+1,new OString(kTestStr9),
487cdf0e10cSrcweir new OString(kTestStr5)},
488cdf0e10cSrcweir {"simple compare, str5 to str4",+1,new OString(kTestStr5),
489cdf0e10cSrcweir new OString(kTestStr4)},
490cdf0e10cSrcweir {"simple compare, str1 to str1",0,new OString(kTestStr1),
491cdf0e10cSrcweir new OString(kTestStr1)},
492cdf0e10cSrcweir {"simple compare, nullString to nullString",0,new OString(),
493cdf0e10cSrcweir new OString()},
494cdf0e10cSrcweir {"simple compare, nullString to str2",-1,new OString(),
495cdf0e10cSrcweir new OString(kTestStr2)},
496cdf0e10cSrcweir {"simple compare, str1 to nullString",+1,new OString(kTestStr1),
497cdf0e10cSrcweir new OString()}
498cdf0e10cSrcweir };
499cdf0e10cSrcweir
500cdf0e10cSrcweir sal_Bool res = sal_True;
501cdf0e10cSrcweir sal_uInt32 i;
502cdf0e10cSrcweir
503cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
504cdf0e10cSrcweir {
505cdf0e10cSrcweir sal_Int32 cmpRes =
506cdf0e10cSrcweir arrTestCase[i].input1->compareTo(*arrTestCase[i].input2);
507cdf0e10cSrcweir cmpRes = ( cmpRes == 0 ) ? 0 : ( cmpRes > 0 ) ? +1 : -1 ;
508cdf0e10cSrcweir sal_Bool lastRes = ( cmpRes == arrTestCase[i].expVal);
509cdf0e10cSrcweir
510cdf0e10cSrcweir c_rtl_tres_state
511cdf0e10cSrcweir (
512cdf0e10cSrcweir hRtlTestResult,
513cdf0e10cSrcweir lastRes,
514cdf0e10cSrcweir arrTestCase[i].comments,
515cdf0e10cSrcweir createName( pMeth, "compareTo(const OString&)", i )
516cdf0e10cSrcweir );
517cdf0e10cSrcweir
518cdf0e10cSrcweir res &= lastRes;
519cdf0e10cSrcweir }
520cdf0e10cSrcweir
521cdf0e10cSrcweir return (res);
522cdf0e10cSrcweir }
523cdf0e10cSrcweir
524cdf0e10cSrcweir
525cdf0e10cSrcweir //------------------------------------------------------------------------
526cdf0e10cSrcweir // testing the method compareTo( const OString & rObj, sal_Int32 length )
527cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_compareTo_002(hTestResult hRtlTestResult)528cdf0e10cSrcweir static sal_Bool SAL_CALL test_rtl_OString_compareTo_002(
529cdf0e10cSrcweir hTestResult hRtlTestResult )
530cdf0e10cSrcweir {
531cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
532cdf0e10cSrcweir sal_Char* pMeth = methName;
533cdf0e10cSrcweir
534cdf0e10cSrcweir typedef struct TestCase
535cdf0e10cSrcweir {
536cdf0e10cSrcweir sal_Char* comments;
537cdf0e10cSrcweir sal_Int32 expVal;
538cdf0e10cSrcweir sal_Int32 maxLength;
539cdf0e10cSrcweir OString* input1;
540cdf0e10cSrcweir OString* input2;
541cdf0e10cSrcweir ~TestCase() { delete input1;delete input2;}
542cdf0e10cSrcweir } TestCase;
543cdf0e10cSrcweir
544cdf0e10cSrcweir TestCase arrTestCase[] =
545cdf0e10cSrcweir {
546cdf0e10cSrcweir {"compare with maxlength, str1 to str9, 16",-1,16,
547cdf0e10cSrcweir new OString(kTestStr1), new OString(kTestStr9)},
548cdf0e10cSrcweir {"compare with maxlength, str2 to str9, 32",-1,32,
549cdf0e10cSrcweir new OString(kTestStr2), new OString(kTestStr9)},
550cdf0e10cSrcweir {"compare with maxlength, str9 to str4, 16",+1,16,
551cdf0e10cSrcweir new OString(kTestStr9), new OString(kTestStr4)},
552cdf0e10cSrcweir {"compare with maxlength, str9 to str22, 32",+1,32,
553cdf0e10cSrcweir new OString(kTestStr9), new OString(kTestStr22)},
554cdf0e10cSrcweir {"compare with maxlength, str9 to str5, 16",0,16,
555cdf0e10cSrcweir new OString(kTestStr9), new OString(kTestStr5)},
556cdf0e10cSrcweir {"compare with maxlength, str9 to str9, 32",0,32,
557cdf0e10cSrcweir new OString(kTestStr9), new OString(kTestStr9)},
558cdf0e10cSrcweir {"compare with maxlength, str1 to str2, 32",-1,32,
559cdf0e10cSrcweir new OString(kTestStr1), new OString(kTestStr2)},
560cdf0e10cSrcweir {"compare with maxlength, str1 to str2, 32",-1,32,
561cdf0e10cSrcweir new OString(kTestStr1), new OString(kTestStr2)}
562cdf0e10cSrcweir };
563cdf0e10cSrcweir
564cdf0e10cSrcweir sal_Bool res = sal_True;
565cdf0e10cSrcweir sal_uInt32 i;
566cdf0e10cSrcweir
567cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
568cdf0e10cSrcweir {
569cdf0e10cSrcweir sal_Int32 cmpRes =
570cdf0e10cSrcweir arrTestCase[i].input1->compareTo(*arrTestCase[i].input2,
571cdf0e10cSrcweir arrTestCase[i].maxLength);
572cdf0e10cSrcweir cmpRes = (cmpRes == 0) ? 0 : (cmpRes > 0) ? +1 : -1 ;
573cdf0e10cSrcweir sal_Bool lastRes = (cmpRes == arrTestCase[i].expVal);
574cdf0e10cSrcweir
575cdf0e10cSrcweir c_rtl_tres_state
576cdf0e10cSrcweir (
577cdf0e10cSrcweir hRtlTestResult,
578cdf0e10cSrcweir lastRes,
579cdf0e10cSrcweir arrTestCase[i].comments,
580cdf0e10cSrcweir createName( pMeth, "compareTo(const OString&, sal_Int32)", i )
581cdf0e10cSrcweir );
582cdf0e10cSrcweir
583cdf0e10cSrcweir res &= lastRes;
584cdf0e10cSrcweir }
585cdf0e10cSrcweir
586cdf0e10cSrcweir return (res);
587cdf0e10cSrcweir }
588cdf0e10cSrcweir
test_rtl_OString_compareTo(hTestResult hRtlTestResult)589cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_compareTo(
590cdf0e10cSrcweir hTestResult hRtlTestResult )
591cdf0e10cSrcweir {
592cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "compareTo");
593cdf0e10cSrcweir sal_Bool res = test_rtl_OString_compareTo_001(hRtlTestResult);
594cdf0e10cSrcweir res &= test_rtl_OString_compareTo_002(hRtlTestResult);
595cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "compareTo");
596cdf0e10cSrcweir // return (res);
597cdf0e10cSrcweir }
598cdf0e10cSrcweir
599cdf0e10cSrcweir //------------------------------------------------------------------------
600cdf0e10cSrcweir // testing the operator == ( const OString& rStr1, const OString& rStr2 )
601cdf0e10cSrcweir // testing the operator == ( const OString& rStr1, const sal_Char *rStr2 )
602cdf0e10cSrcweir // testing the operator == ( const sal_Char *rStr1, const OString& rStr2 )
603cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_op_cmp(hTestResult hRtlTestResult)604cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_cmp(
605cdf0e10cSrcweir hTestResult hRtlTestResult )
606cdf0e10cSrcweir {
607cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "op_cmp");
608cdf0e10cSrcweir const sal_Int16 NCASES = 7;
609cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
610cdf0e10cSrcweir sal_Char* pMeth = methName;
611cdf0e10cSrcweir const sal_Char *arrOStr[NCASES][2] =
612cdf0e10cSrcweir {
613cdf0e10cSrcweir {kTestStr1, kTestStr1},
614cdf0e10cSrcweir {kTestStr1, kTestStr3},
615cdf0e10cSrcweir {kTestStr1, kTestStr2},
616cdf0e10cSrcweir {0, 0},
617cdf0e10cSrcweir {0, kTestStr2},
618cdf0e10cSrcweir {kTestStr1, 0},
619cdf0e10cSrcweir {"", ""}
620cdf0e10cSrcweir };
621cdf0e10cSrcweir
622cdf0e10cSrcweir sal_Bool arrExpVal[NCASES] =
623cdf0e10cSrcweir {
624cdf0e10cSrcweir sal_True,
625cdf0e10cSrcweir sal_False,
626cdf0e10cSrcweir sal_False,
627cdf0e10cSrcweir sal_True,
628cdf0e10cSrcweir sal_False,
629cdf0e10cSrcweir sal_False,
630cdf0e10cSrcweir sal_True
631cdf0e10cSrcweir };
632cdf0e10cSrcweir
633cdf0e10cSrcweir sal_Char *arrComments[NCASES] =
634cdf0e10cSrcweir {
635cdf0e10cSrcweir "'Sun Microsystems'=='Sun Microsystems'",
636cdf0e10cSrcweir "!('Sun Microsystems'=='Sun microsystems')",
637cdf0e10cSrcweir "!('Sun Microsystems'=='Sun Microsystems Java Technology')",
638cdf0e10cSrcweir "two empty strings(def.constructor)",
639cdf0e10cSrcweir "!(empty string=='Sun Microsystems Java Technology')",
640cdf0e10cSrcweir "!('Sun Microsystems Java Technology'==empty string)",
641cdf0e10cSrcweir "''==''"
642cdf0e10cSrcweir };
643cdf0e10cSrcweir
644cdf0e10cSrcweir sal_Bool res = sal_True;
645cdf0e10cSrcweir sal_Int32 i;
646cdf0e10cSrcweir
647cdf0e10cSrcweir for(i = 0; i < NCASES; i++)
648cdf0e10cSrcweir {
649cdf0e10cSrcweir OString *str1, *str2;
650cdf0e10cSrcweir str1 = (arrOStr[i][0]) ? new OString(arrOStr[i][0]) : new OString() ;
651cdf0e10cSrcweir str2 = (arrOStr[i][1]) ? new OString(arrOStr[i][1]) : new OString() ;
652cdf0e10cSrcweir
653cdf0e10cSrcweir sal_Bool cmpRes = (*str1 == *str2);
654cdf0e10cSrcweir sal_Bool lastRes = (cmpRes == arrExpVal[i]);
655cdf0e10cSrcweir res &= lastRes;
656cdf0e10cSrcweir
657cdf0e10cSrcweir c_rtl_tres_state
658cdf0e10cSrcweir (
659cdf0e10cSrcweir hRtlTestResult,
660cdf0e10cSrcweir lastRes,
661cdf0e10cSrcweir arrComments[i],
662cdf0e10cSrcweir createName( pMeth, "operator ==(OString&, OString&)", i )
663cdf0e10cSrcweir );
664cdf0e10cSrcweir
665cdf0e10cSrcweir cmpRes = (*str1 == arrOStr[i][1]);
666cdf0e10cSrcweir lastRes = (cmpRes == arrExpVal[i]);
667cdf0e10cSrcweir res &= lastRes;
668cdf0e10cSrcweir c_rtl_tres_state
669cdf0e10cSrcweir (
670cdf0e10cSrcweir hRtlTestResult,
671cdf0e10cSrcweir lastRes,
672cdf0e10cSrcweir arrComments[i],
673cdf0e10cSrcweir createName( pMeth, "operator ==(OString&, sal_Char *)", i )
674cdf0e10cSrcweir );
675cdf0e10cSrcweir
676cdf0e10cSrcweir cmpRes = (arrOStr[i][0] == *str2);
677cdf0e10cSrcweir lastRes = (cmpRes == arrExpVal[i]);
678cdf0e10cSrcweir res &= lastRes;
679cdf0e10cSrcweir c_rtl_tres_state
680cdf0e10cSrcweir (
681cdf0e10cSrcweir hRtlTestResult,
682cdf0e10cSrcweir lastRes,
683cdf0e10cSrcweir arrComments[i],
684cdf0e10cSrcweir createName( pMeth, "operator ==(sal_Char *, OString&)", i )
685cdf0e10cSrcweir );
686cdf0e10cSrcweir
687cdf0e10cSrcweir delete str2;
688cdf0e10cSrcweir delete str1;
689cdf0e10cSrcweir }
690cdf0e10cSrcweir
691cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "op_cmp");
692cdf0e10cSrcweir // return ( res );
693cdf0e10cSrcweir }
694cdf0e10cSrcweir
695cdf0e10cSrcweir //------------------------------------------------------------------------
696cdf0e10cSrcweir // testing the operator != (const OString& rStr1, const OString& rStr2)
697cdf0e10cSrcweir // testing the operator != (const OString& rStr1, const sal_Char *rStr2)
698cdf0e10cSrcweir // testing the operator != (const sal_Char *rStr1, const OString& rStr2)
699cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_op_neq(hTestResult hRtlTestResult)700cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_neq(
701cdf0e10cSrcweir hTestResult hRtlTestResult )
702cdf0e10cSrcweir {
703cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "op_neq");
704cdf0e10cSrcweir const sal_Int16 NCASES = 6;
705cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
706cdf0e10cSrcweir sal_Char* pMeth = methName;
707cdf0e10cSrcweir
708cdf0e10cSrcweir const sal_Char *arrOStr[NCASES][2] =
709cdf0e10cSrcweir {
710cdf0e10cSrcweir {kTestStr1, kTestStr3},
711cdf0e10cSrcweir {kTestStr1, kTestStr2},
712cdf0e10cSrcweir {kTestStr1, kTestStr1},
713cdf0e10cSrcweir {0, kTestStr2},
714cdf0e10cSrcweir {kTestStr1, 0},
715cdf0e10cSrcweir {0, 0}
716cdf0e10cSrcweir };
717cdf0e10cSrcweir
718cdf0e10cSrcweir sal_Bool arrExpVal[NCASES] =
719cdf0e10cSrcweir {
720cdf0e10cSrcweir sal_True,
721cdf0e10cSrcweir sal_True,
722cdf0e10cSrcweir sal_False,
723cdf0e10cSrcweir sal_True,
724cdf0e10cSrcweir sal_True,
725cdf0e10cSrcweir sal_False
726cdf0e10cSrcweir };
727cdf0e10cSrcweir
728cdf0e10cSrcweir sal_Char *arrComments[NCASES] =
729cdf0e10cSrcweir {
730cdf0e10cSrcweir "'Sun Microsystems'!='Sun microsystems'",
731cdf0e10cSrcweir "'Sun Microsystems'!='Sun Microsystems Java Technology'",
732cdf0e10cSrcweir "!('Sun Microsystems'!='Sun Microsystems')",
733cdf0e10cSrcweir "empty string!='Sun Microsystems Java Technology'",
734cdf0e10cSrcweir "'Sun Microsystems Java Technology'!=empty string", "!(''!='')"
735cdf0e10cSrcweir };
736cdf0e10cSrcweir
737cdf0e10cSrcweir sal_Bool res = sal_True;
738cdf0e10cSrcweir sal_Int32 i;
739cdf0e10cSrcweir
740cdf0e10cSrcweir for(i = 0; i < NCASES; i++)
741cdf0e10cSrcweir {
742cdf0e10cSrcweir OString *str1, *str2;
743cdf0e10cSrcweir str1 = (arrOStr[i][0]) ? new OString(arrOStr[i][0]) : new OString() ;
744cdf0e10cSrcweir str2 = (arrOStr[i][1]) ? new OString(arrOStr[i][1]) : new OString() ;
745cdf0e10cSrcweir
746cdf0e10cSrcweir sal_Bool cmpRes = (*str1 != *str2);
747cdf0e10cSrcweir sal_Bool lastRes = (cmpRes == arrExpVal[i]);
748cdf0e10cSrcweir res &= lastRes;
749cdf0e10cSrcweir c_rtl_tres_state
750cdf0e10cSrcweir (
751cdf0e10cSrcweir hRtlTestResult,
752cdf0e10cSrcweir lastRes,
753cdf0e10cSrcweir arrComments[i],
754cdf0e10cSrcweir createName( pMeth, "operator !=(OString&, OString&)", i )
755cdf0e10cSrcweir );
756cdf0e10cSrcweir
757cdf0e10cSrcweir cmpRes = (*str1 != arrOStr[i][1]);
758cdf0e10cSrcweir lastRes = (cmpRes == arrExpVal[i]);
759cdf0e10cSrcweir res &= lastRes;
760cdf0e10cSrcweir c_rtl_tres_state
761cdf0e10cSrcweir (
762cdf0e10cSrcweir hRtlTestResult,
763cdf0e10cSrcweir lastRes,
764cdf0e10cSrcweir arrComments[i],
765cdf0e10cSrcweir createName( pMeth, "operator !=(OString&, sal_Char *)", i )
766cdf0e10cSrcweir );
767cdf0e10cSrcweir
768cdf0e10cSrcweir cmpRes = (arrOStr[i][0] != *str2);
769cdf0e10cSrcweir lastRes = (cmpRes == arrExpVal[i]);
770cdf0e10cSrcweir res &= lastRes;
771cdf0e10cSrcweir c_rtl_tres_state
772cdf0e10cSrcweir (
773cdf0e10cSrcweir hRtlTestResult,
774cdf0e10cSrcweir lastRes,
775cdf0e10cSrcweir arrComments[i],
776cdf0e10cSrcweir createName( pMeth, "operator !=(sal_Char *, OString&)", i )
777cdf0e10cSrcweir );
778cdf0e10cSrcweir
779cdf0e10cSrcweir delete str2;
780cdf0e10cSrcweir delete str1;
781cdf0e10cSrcweir }
782cdf0e10cSrcweir
783cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "op_neq");
784cdf0e10cSrcweir // return ( res );
785cdf0e10cSrcweir }
786cdf0e10cSrcweir
787cdf0e10cSrcweir
788cdf0e10cSrcweir //------------------------------------------------------------------------
789cdf0e10cSrcweir // testing the operator > (const OString& rStr1, const OString& rStr2)
790cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_op_g(hTestResult hRtlTestResult)791cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_g(
792cdf0e10cSrcweir hTestResult hRtlTestResult )
793cdf0e10cSrcweir {
794cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
795cdf0e10cSrcweir sal_Char* pMeth = methName;
796cdf0e10cSrcweir
797cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "op_g");
798cdf0e10cSrcweir typedef struct TestCase
799cdf0e10cSrcweir {
800cdf0e10cSrcweir sal_Char* comments;
801cdf0e10cSrcweir sal_Bool expVal;
802cdf0e10cSrcweir OString* input1;
803cdf0e10cSrcweir OString* input2;
804cdf0e10cSrcweir ~TestCase() { delete input1;delete input2;}
805cdf0e10cSrcweir } TestCase;
806cdf0e10cSrcweir
807cdf0e10cSrcweir TestCase arrTestCase[] =
808cdf0e10cSrcweir {
809cdf0e10cSrcweir { "'Sun microsystems'>'Sun Microsystems'",sal_True,
810cdf0e10cSrcweir new OString(kTestStr3), new OString(kTestStr1)},
811cdf0e10cSrcweir {"!('Sun Microsystems'>'Sun microsystems')",sal_False,
812cdf0e10cSrcweir new OString(kTestStr1), new OString(kTestStr3)},
813cdf0e10cSrcweir {"'Sun Microsystems Java Technology'>'Sun Microsystems'",sal_True,
814cdf0e10cSrcweir new OString(kTestStr2), new OString(kTestStr1)},
815cdf0e10cSrcweir {"!('Sun Microsystems'>'Sun Microsystems Java Technology')",sal_False,
816cdf0e10cSrcweir new OString(kTestStr1), new OString(kTestStr2)},
817cdf0e10cSrcweir {"!('Sun Microsystems'>'Sun Microsystems'",sal_False,
818cdf0e10cSrcweir new OString(kTestStr1), new OString(kTestStr1)},
819cdf0e10cSrcweir {"'Sun Microsystems'>''",sal_True,new OString(kTestStr1),
820cdf0e10cSrcweir new OString()},
821cdf0e10cSrcweir {"!(''>'Sun Microsystems')",sal_False,new OString(),
822cdf0e10cSrcweir new OString(kTestStr1)},
823cdf0e10cSrcweir {"!(''>'')",sal_False,new OString(), new OString()}
824cdf0e10cSrcweir };
825cdf0e10cSrcweir
826cdf0e10cSrcweir sal_Bool res = sal_True;
827cdf0e10cSrcweir sal_uInt32 i;
828cdf0e10cSrcweir
829cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
830cdf0e10cSrcweir {
831cdf0e10cSrcweir sal_Bool cmpRes = (*arrTestCase[i].input1 > *arrTestCase[i].input2);
832cdf0e10cSrcweir sal_Bool lastRes = (cmpRes == arrTestCase[i].expVal);
833cdf0e10cSrcweir
834cdf0e10cSrcweir c_rtl_tres_state
835cdf0e10cSrcweir (
836cdf0e10cSrcweir hRtlTestResult,
837cdf0e10cSrcweir lastRes,
838cdf0e10cSrcweir arrTestCase[i].comments,
839cdf0e10cSrcweir createName( pMeth, "operator >", i )
840cdf0e10cSrcweir );
841cdf0e10cSrcweir
842cdf0e10cSrcweir res &= lastRes;
843cdf0e10cSrcweir
844cdf0e10cSrcweir }
845cdf0e10cSrcweir
846cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "op_g");
847cdf0e10cSrcweir // return ( res );
848cdf0e10cSrcweir }
849cdf0e10cSrcweir
850cdf0e10cSrcweir //------------------------------------------------------------------------
851cdf0e10cSrcweir // testing the operator < (const OString& rStr1, const OString& rStr2)
852cdf0e10cSrcweir //------------------------------------------------------------------------
853cdf0e10cSrcweir
test_rtl_OString_op_l(hTestResult hRtlTestResult)854cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_l(
855cdf0e10cSrcweir hTestResult hRtlTestResult )
856cdf0e10cSrcweir {
857cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
858cdf0e10cSrcweir sal_Char* pMeth = methName;
859cdf0e10cSrcweir
860cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "op_l");
861cdf0e10cSrcweir typedef struct TestCase
862cdf0e10cSrcweir {
863cdf0e10cSrcweir sal_Char* comments;
864cdf0e10cSrcweir sal_Bool expVal;
865cdf0e10cSrcweir OString* input1;
866cdf0e10cSrcweir OString* input2;
867cdf0e10cSrcweir ~TestCase() { delete input1;delete input2;}
868cdf0e10cSrcweir } TestCase;
869cdf0e10cSrcweir
870cdf0e10cSrcweir TestCase arrTestCase[] =
871cdf0e10cSrcweir {
872cdf0e10cSrcweir {"!('Sun microsystems'<'Sun Microsystems')",sal_False,
873cdf0e10cSrcweir new OString(kTestStr3), new OString(kTestStr1)},
874cdf0e10cSrcweir {"'Sun Microsystems'<'Sun microsystems'",sal_True,
875cdf0e10cSrcweir new OString(kTestStr1), new OString(kTestStr3)},
876cdf0e10cSrcweir {"'Sun Microsystems'<'Sun Microsystems Java Technology'",sal_True,
877cdf0e10cSrcweir new OString(kTestStr1), new OString(kTestStr2)},
878cdf0e10cSrcweir {"!('Sun Microsystems Java Technology'<'Sun Microsystems')",sal_False,
879cdf0e10cSrcweir new OString(kTestStr2), new OString(kTestStr1)},
880cdf0e10cSrcweir {"!('Sun Microsystems'<'Sun Microsystems'", sal_False,
881cdf0e10cSrcweir new OString(kTestStr1), new OString(kTestStr1)},
882cdf0e10cSrcweir {"'Sun Microsystems'<''",sal_False,new OString(kTestStr1),
883cdf0e10cSrcweir new OString()},
884cdf0e10cSrcweir {"''<'Sun Microsystems Java Technology'",sal_True,new OString(),
885cdf0e10cSrcweir new OString(kTestStr2)},
886cdf0e10cSrcweir {"!(''<'')",sal_False,new OString(), new OString()}
887cdf0e10cSrcweir };
888cdf0e10cSrcweir
889cdf0e10cSrcweir sal_Bool res = sal_True;
890cdf0e10cSrcweir sal_uInt32 i;
891cdf0e10cSrcweir
892cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
893cdf0e10cSrcweir {
894cdf0e10cSrcweir sal_Bool cmpRes = (*arrTestCase[i].input1 < *arrTestCase[i].input2);
895cdf0e10cSrcweir sal_Bool lastRes = (cmpRes == arrTestCase[i].expVal);
896cdf0e10cSrcweir
897cdf0e10cSrcweir c_rtl_tres_state
898cdf0e10cSrcweir (
899cdf0e10cSrcweir hRtlTestResult,
900cdf0e10cSrcweir lastRes,
901cdf0e10cSrcweir arrTestCase[i].comments,
902cdf0e10cSrcweir createName( pMeth, "operator <", i )
903cdf0e10cSrcweir );
904cdf0e10cSrcweir
905cdf0e10cSrcweir res &= lastRes;
906cdf0e10cSrcweir
907cdf0e10cSrcweir }
908cdf0e10cSrcweir
909cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "op_l");
910cdf0e10cSrcweir // return ( res );
911cdf0e10cSrcweir }
912cdf0e10cSrcweir
913cdf0e10cSrcweir //------------------------------------------------------------------------
914cdf0e10cSrcweir // testing the operator >= (const OString& rStr1, const OString& rStr2)
915cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_op_ge(hTestResult hRtlTestResult)916cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_ge(
917cdf0e10cSrcweir hTestResult hRtlTestResult )
918cdf0e10cSrcweir {
919cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
920cdf0e10cSrcweir sal_Char* pMeth = methName;
921cdf0e10cSrcweir
922cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "op_ge");
923cdf0e10cSrcweir typedef struct TestCase
924cdf0e10cSrcweir {
925cdf0e10cSrcweir sal_Char* comments;
926cdf0e10cSrcweir sal_Bool expVal;
927cdf0e10cSrcweir OString* input1;
928cdf0e10cSrcweir OString* input2;
929cdf0e10cSrcweir ~TestCase() { delete input1;delete input2;}
930cdf0e10cSrcweir } TestCase;
931cdf0e10cSrcweir
932cdf0e10cSrcweir TestCase arrTestCase[] =
933cdf0e10cSrcweir {
934cdf0e10cSrcweir {"'Sun microsystems'>='Sun Microsystems'",sal_True,
935cdf0e10cSrcweir new OString(kTestStr3), new OString(kTestStr1)},
936cdf0e10cSrcweir {"!('Sun Microsystems'>='Sun microsystems')",sal_False,
937cdf0e10cSrcweir new OString(kTestStr1), new OString(kTestStr3)},
938cdf0e10cSrcweir {"!('Sun Microsystems'>='Sun Microsystems Java Technology')",sal_False,
939cdf0e10cSrcweir new OString(kTestStr1), new OString(kTestStr2)},
940cdf0e10cSrcweir {"'Sun Microsystems Java Technology'>='Sun Microsystems'",sal_True,
941cdf0e10cSrcweir new OString(kTestStr2), new OString(kTestStr1)},
942cdf0e10cSrcweir {"'Sun Microsystems'>='Sun Microsystems'", sal_True,
943cdf0e10cSrcweir new OString(kTestStr1), new OString(kTestStr1)},
944cdf0e10cSrcweir {"'Sun Microsystems'>=''",sal_True,new OString(kTestStr1),
945cdf0e10cSrcweir new OString()},
946cdf0e10cSrcweir { "''>='Sun microsystems'",sal_False,new OString(),
947cdf0e10cSrcweir new OString(kTestStr3)},
948cdf0e10cSrcweir {"''>=''",sal_True,new OString(), new OString()}
949cdf0e10cSrcweir };
950cdf0e10cSrcweir
951cdf0e10cSrcweir sal_Bool res = sal_True;
952cdf0e10cSrcweir sal_uInt32 i;
953cdf0e10cSrcweir
954cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
955cdf0e10cSrcweir {
956cdf0e10cSrcweir sal_Bool cmpRes = (*arrTestCase[i].input1 >= *arrTestCase[i].input2);
957cdf0e10cSrcweir sal_Bool lastRes = (cmpRes == arrTestCase[i].expVal);
958cdf0e10cSrcweir
959cdf0e10cSrcweir c_rtl_tres_state
960cdf0e10cSrcweir (
961cdf0e10cSrcweir hRtlTestResult,
962cdf0e10cSrcweir lastRes,
963cdf0e10cSrcweir arrTestCase[i].comments,
964cdf0e10cSrcweir createName( pMeth, "operator >=", i )
965cdf0e10cSrcweir );
966cdf0e10cSrcweir
967cdf0e10cSrcweir res &= lastRes;
968cdf0e10cSrcweir
969cdf0e10cSrcweir }
970cdf0e10cSrcweir
971cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "op_ge");
972cdf0e10cSrcweir // return ( res );
973cdf0e10cSrcweir }
974cdf0e10cSrcweir
975cdf0e10cSrcweir //------------------------------------------------------------------------
976cdf0e10cSrcweir // testing the operator <= (const OString& rStr1, const OString& rStr2)
977cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_op_le(hTestResult hRtlTestResult)978cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_le(
979cdf0e10cSrcweir hTestResult hRtlTestResult )
980cdf0e10cSrcweir {
981cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
982cdf0e10cSrcweir sal_Char* pMeth = methName;
983cdf0e10cSrcweir
984cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "op_le");
985cdf0e10cSrcweir typedef struct TestCase
986cdf0e10cSrcweir {
987cdf0e10cSrcweir sal_Char* comments;
988cdf0e10cSrcweir sal_Bool expVal;
989cdf0e10cSrcweir OString* input1;
990cdf0e10cSrcweir OString* input2;
991cdf0e10cSrcweir ~TestCase() { delete input1;delete input2;}
992cdf0e10cSrcweir } TestCase;
993cdf0e10cSrcweir
994cdf0e10cSrcweir TestCase arrTestCase[] =
995cdf0e10cSrcweir {
996cdf0e10cSrcweir {"!('Sun microsystems'<='Sun Microsystems')",sal_False,
997cdf0e10cSrcweir new OString(kTestStr3), new OString(kTestStr1)},
998cdf0e10cSrcweir {"'Sun Microsystems'<='Sun microsystems'",sal_True,
999cdf0e10cSrcweir new OString(kTestStr1), new OString(kTestStr3)},
1000cdf0e10cSrcweir {"'Sun Microsystems'<='Sun Microsystems Java Technology'",sal_True,
1001cdf0e10cSrcweir new OString(kTestStr1),
1002cdf0e10cSrcweir new OString(kTestStr2)},
1003cdf0e10cSrcweir {"!('Sun Microsystems Java Technology'<='Sun Microsystems')",sal_False,
1004cdf0e10cSrcweir new OString(kTestStr2),
1005cdf0e10cSrcweir new OString(kTestStr1)},
1006cdf0e10cSrcweir {"!('Sun Microsystems'<='Sun Microsystems'", sal_True,
1007cdf0e10cSrcweir new OString(kTestStr1), new OString(kTestStr1)},
1008cdf0e10cSrcweir {"'Sun Microsystems'<=''",sal_False,new OString(kTestStr1),
1009cdf0e10cSrcweir new OString()},
1010cdf0e10cSrcweir {"''<='Sun Microsystems Java Technology'",sal_True,new OString(),
1011cdf0e10cSrcweir new OString(kTestStr2)},
1012cdf0e10cSrcweir {"!(''<='')",sal_True,new OString(), new OString()}
1013cdf0e10cSrcweir };
1014cdf0e10cSrcweir
1015cdf0e10cSrcweir sal_Bool res = sal_True;
1016cdf0e10cSrcweir sal_uInt32 i;
1017cdf0e10cSrcweir
1018cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
1019cdf0e10cSrcweir {
1020cdf0e10cSrcweir sal_Bool cmpRes = (*arrTestCase[i].input1 <= *arrTestCase[i].input2);
1021cdf0e10cSrcweir sal_Bool lastRes = (cmpRes == arrTestCase[i].expVal);
1022cdf0e10cSrcweir
1023cdf0e10cSrcweir c_rtl_tres_state
1024cdf0e10cSrcweir (
1025cdf0e10cSrcweir hRtlTestResult,
1026cdf0e10cSrcweir lastRes,
1027cdf0e10cSrcweir arrTestCase[i].comments,
1028cdf0e10cSrcweir createName( pMeth, "operator <=", i )
1029cdf0e10cSrcweir );
1030cdf0e10cSrcweir
1031cdf0e10cSrcweir res &= lastRes;
1032cdf0e10cSrcweir
1033cdf0e10cSrcweir }
1034cdf0e10cSrcweir
1035cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "op_le");
1036cdf0e10cSrcweir // return ( res );
1037cdf0e10cSrcweir }
1038cdf0e10cSrcweir
1039cdf0e10cSrcweir
1040cdf0e10cSrcweir //------------------------------------------------------------------------
1041cdf0e10cSrcweir // testing the operator =
1042cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_op_eq_001(hTestResult hRtlTestResult)1043cdf0e10cSrcweir static sal_Bool test_rtl_OString_op_eq_001( hTestResult hRtlTestResult )
1044cdf0e10cSrcweir {
1045cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
1046cdf0e10cSrcweir sal_Char* pMeth = methName;
1047cdf0e10cSrcweir
1048cdf0e10cSrcweir typedef struct TestCase
1049cdf0e10cSrcweir {
1050cdf0e10cSrcweir sal_Char* comments;
1051cdf0e10cSrcweir sal_Bool expVal;
1052cdf0e10cSrcweir OString* input1;
1053cdf0e10cSrcweir OString* input2;
1054cdf0e10cSrcweir ~TestCase() { delete input1;delete input2;}
1055cdf0e10cSrcweir } TestCase;
1056cdf0e10cSrcweir
1057cdf0e10cSrcweir TestCase arrTestCase[] =
1058cdf0e10cSrcweir {
1059cdf0e10cSrcweir {"'' = str1, str1 == str2",sal_True,new OString(kTestStr1),
1060cdf0e10cSrcweir new OString()},
1061cdf0e10cSrcweir {"str1 = str2, str1 == str2",sal_True,new OString(kTestStr1),
1062cdf0e10cSrcweir new OString(kTestStr6)},
1063cdf0e10cSrcweir {"str2 = '', str1 == str2",sal_True,new OString(),
1064cdf0e10cSrcweir new OString(kTestStr2)},
1065cdf0e10cSrcweir {"'' = '', str1 == str2",sal_True,new OString(),
1066cdf0e10cSrcweir new OString()}
1067cdf0e10cSrcweir };
1068cdf0e10cSrcweir
1069cdf0e10cSrcweir sal_Bool res = sal_True;
1070cdf0e10cSrcweir sal_uInt32 i;
1071cdf0e10cSrcweir
1072cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
1073cdf0e10cSrcweir {
1074cdf0e10cSrcweir *(arrTestCase[i].input1) = *(arrTestCase[i].input2);
1075cdf0e10cSrcweir
1076cdf0e10cSrcweir sal_Bool cmpRes =
1077cdf0e10cSrcweir (*(arrTestCase[i].input1) == *(arrTestCase[i].input2));
1078cdf0e10cSrcweir sal_Bool lastRes = (cmpRes == arrTestCase[i].expVal);
1079cdf0e10cSrcweir
1080cdf0e10cSrcweir c_rtl_tres_state
1081cdf0e10cSrcweir (
1082cdf0e10cSrcweir hRtlTestResult,
1083cdf0e10cSrcweir lastRes,
1084cdf0e10cSrcweir arrTestCase[i].comments,
1085cdf0e10cSrcweir createName( pMeth, "operator =", i )
1086cdf0e10cSrcweir );
1087cdf0e10cSrcweir
1088cdf0e10cSrcweir res &= lastRes;
1089cdf0e10cSrcweir }
1090cdf0e10cSrcweir
1091cdf0e10cSrcweir return ( res );
1092cdf0e10cSrcweir }
1093cdf0e10cSrcweir
test_rtl_OString_op_eq_002(hTestResult hRtlTestResult)1094cdf0e10cSrcweir static sal_Bool test_rtl_OString_op_eq_002(
1095cdf0e10cSrcweir hTestResult hRtlTestResult )
1096cdf0e10cSrcweir {
1097cdf0e10cSrcweir ::rtl::OString aStr;
1098cdf0e10cSrcweir aStr = OString(kTestStr1);
1099cdf0e10cSrcweir
1100cdf0e10cSrcweir return
1101cdf0e10cSrcweir (
1102cdf0e10cSrcweir c_rtl_tres_state
1103cdf0e10cSrcweir (
1104cdf0e10cSrcweir hRtlTestResult,
1105cdf0e10cSrcweir aStr == kTestStr1,
1106cdf0e10cSrcweir "str = OString(\"%s\"), str == \"%s\"",
1107cdf0e10cSrcweir "operator ="
1108cdf0e10cSrcweir )
1109cdf0e10cSrcweir );
1110cdf0e10cSrcweir }
1111cdf0e10cSrcweir
test_rtl_OString_op_eq_003(hTestResult hRtlTestResult)1112cdf0e10cSrcweir static sal_Bool test_rtl_OString_op_eq_003(
1113cdf0e10cSrcweir hTestResult hRtlTestResult )
1114cdf0e10cSrcweir {
1115cdf0e10cSrcweir sal_Bool bTCState = false;
1116cdf0e10cSrcweir
1117cdf0e10cSrcweir ::rtl::OString aStr1(kTestStr1);
1118cdf0e10cSrcweir ::rtl::OString aStr2;
1119cdf0e10cSrcweir ::rtl::OString aStr3;
1120cdf0e10cSrcweir
1121cdf0e10cSrcweir aStr3 = aStr2 = aStr1;
1122cdf0e10cSrcweir
1123cdf0e10cSrcweir bTCState = ( aStr1 == aStr2 )
1124cdf0e10cSrcweir && ( aStr1 == aStr3 )
1125cdf0e10cSrcweir && ( aStr2 == aStr3 );
1126cdf0e10cSrcweir
1127cdf0e10cSrcweir c_rtl_tres_state
1128cdf0e10cSrcweir (
1129cdf0e10cSrcweir hRtlTestResult,
1130cdf0e10cSrcweir bTCState,
1131cdf0e10cSrcweir "str3=str2=str1,(str1 == str2)&&(str1 == str3)&&(str2 == str3)",
1132cdf0e10cSrcweir "operator ="
1133cdf0e10cSrcweir );
1134cdf0e10cSrcweir
1135cdf0e10cSrcweir return bTCState;
1136cdf0e10cSrcweir }
1137cdf0e10cSrcweir
test_rtl_OString_op_eq(hTestResult hRtlTestResult)1138cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_eq(
1139cdf0e10cSrcweir hTestResult hRtlTestResult )
1140cdf0e10cSrcweir {
1141cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "op_eq");
1142cdf0e10cSrcweir sal_Bool res = test_rtl_OString_op_eq_001( hRtlTestResult );
1143cdf0e10cSrcweir res &= test_rtl_OString_op_eq_002( hRtlTestResult );
1144cdf0e10cSrcweir res &= test_rtl_OString_op_eq_003( hRtlTestResult );
1145cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "op_eq");
1146cdf0e10cSrcweir
1147cdf0e10cSrcweir // return ( res );
1148cdf0e10cSrcweir }
1149cdf0e10cSrcweir
1150cdf0e10cSrcweir //------------------------------------------------------------------------
1151cdf0e10cSrcweir // testing the operator +
1152cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_op_plus(hTestResult hRtlTestResult)1153cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_plus(
1154cdf0e10cSrcweir hTestResult hRtlTestResult )
1155cdf0e10cSrcweir {
1156cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
1157cdf0e10cSrcweir sal_Char* pMeth = methName;
1158cdf0e10cSrcweir
1159cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "op_plus");
1160cdf0e10cSrcweir typedef struct TestCase
1161cdf0e10cSrcweir {
1162cdf0e10cSrcweir sal_Char* comments;
1163cdf0e10cSrcweir OString* expVal;
1164cdf0e10cSrcweir OString* input1;
1165cdf0e10cSrcweir OString* input2;
1166cdf0e10cSrcweir ~TestCase() { delete input1;delete input2; delete expVal;}
1167cdf0e10cSrcweir } TestCase;
1168cdf0e10cSrcweir
1169cdf0e10cSrcweir TestCase arrTestCase[] =
1170cdf0e10cSrcweir {
1171cdf0e10cSrcweir {"str1 = str7 + str8",new OString(kTestStr1),
1172cdf0e10cSrcweir new OString(kTestStr7), new OString(kTestStr8)},
1173cdf0e10cSrcweir {"str1 = str1 + '' ",new OString(kTestStr1),
1174cdf0e10cSrcweir new OString(kTestStr1), new OString("")},
1175cdf0e10cSrcweir {"str1 = '' + str1", new OString(kTestStr1),
1176cdf0e10cSrcweir new OString(""), new OString(kTestStr1)},
1177cdf0e10cSrcweir {" '' = '' + '' ", new OString(""),new OString(""),
1178cdf0e10cSrcweir new OString("")},
1179cdf0e10cSrcweir {"str1 = str1 + def.constr", new OString(kTestStr1),
1180cdf0e10cSrcweir new OString(kTestStr1), new OString()},
1181cdf0e10cSrcweir {" str1 = def.constr + str1 ",new OString(kTestStr1),
1182cdf0e10cSrcweir new OString(), new OString(kTestStr1)},
1183cdf0e10cSrcweir {" def.constr= def.constr + def.constr", new OString(),
1184cdf0e10cSrcweir new OString(), new OString()}
1185cdf0e10cSrcweir };
1186cdf0e10cSrcweir
1187cdf0e10cSrcweir sal_Bool res = sal_True;
1188cdf0e10cSrcweir sal_uInt32 i;
1189cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
1190cdf0e10cSrcweir {
1191cdf0e10cSrcweir OString str = (*arrTestCase[i].input1) + (*arrTestCase[i].input2);
1192cdf0e10cSrcweir sal_Bool lastRes = (str == *arrTestCase[i].expVal);
1193cdf0e10cSrcweir
1194cdf0e10cSrcweir c_rtl_tres_state
1195cdf0e10cSrcweir (
1196cdf0e10cSrcweir hRtlTestResult,
1197cdf0e10cSrcweir lastRes,
1198cdf0e10cSrcweir arrTestCase[i].comments,
1199cdf0e10cSrcweir createName( pMeth, "operator +", i )
1200cdf0e10cSrcweir );
1201cdf0e10cSrcweir
1202cdf0e10cSrcweir res &= lastRes;
1203cdf0e10cSrcweir
1204cdf0e10cSrcweir }
1205cdf0e10cSrcweir
1206cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "op_plus");
1207cdf0e10cSrcweir // return ( res );
1208cdf0e10cSrcweir }
1209cdf0e10cSrcweir
1210cdf0e10cSrcweir //------------------------------------------------------------------------
1211cdf0e10cSrcweir // testing the operator +=
1212cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_op_peq(hTestResult hRtlTestResult)1213cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_peq(
1214cdf0e10cSrcweir hTestResult hRtlTestResult )
1215cdf0e10cSrcweir {
1216cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
1217cdf0e10cSrcweir sal_Char* pMeth = methName;
1218cdf0e10cSrcweir
1219cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "op_peq");
1220cdf0e10cSrcweir typedef struct TestCase
1221cdf0e10cSrcweir {
1222cdf0e10cSrcweir sal_Char* comments;
1223cdf0e10cSrcweir OString* expVal;
1224cdf0e10cSrcweir OString* input1;
1225cdf0e10cSrcweir OString* input2;
1226cdf0e10cSrcweir ~TestCase() { delete input1;delete input2; delete expVal;}
1227cdf0e10cSrcweir } TestCase;
1228cdf0e10cSrcweir
1229cdf0e10cSrcweir TestCase arrTestCase[] =
1230cdf0e10cSrcweir {
1231cdf0e10cSrcweir {"str1 == (str7 += str8)",new OString(kTestStr1),
1232cdf0e10cSrcweir new OString(kTestStr7), new OString(kTestStr8)},
1233cdf0e10cSrcweir {"str1 == (str1 += '')",new OString(kTestStr1),
1234cdf0e10cSrcweir new OString(kTestStr1), new OString("")},
1235cdf0e10cSrcweir {"str1 == ('' += str1)", new OString(kTestStr1),
1236cdf0e10cSrcweir new OString(""), new OString(kTestStr1)},
1237cdf0e10cSrcweir {" '' == ('' += '')", new OString(""),
1238cdf0e10cSrcweir new OString(""), new OString("")},
1239cdf0e10cSrcweir {"str1 == (str1 += def.constr)", new OString(kTestStr1),
1240cdf0e10cSrcweir new OString(kTestStr1), new OString()},
1241cdf0e10cSrcweir {" str1 == (def.constr += str1)",new OString(kTestStr1),
1242cdf0e10cSrcweir new OString(), new OString(kTestStr1)},
1243cdf0e10cSrcweir {" def.constr== (def.constr += def.constr)",
1244cdf0e10cSrcweir new OString(),new OString(), new OString()}
1245cdf0e10cSrcweir };
1246cdf0e10cSrcweir
1247cdf0e10cSrcweir sal_Bool res = sal_True;
1248cdf0e10cSrcweir sal_uInt32 i;
1249cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
1250cdf0e10cSrcweir { OString str;
1251cdf0e10cSrcweir str += (*arrTestCase[i].input1); str += (*arrTestCase[i].input2);
1252cdf0e10cSrcweir sal_Bool lastRes = (str == *arrTestCase[i].expVal);
1253cdf0e10cSrcweir
1254cdf0e10cSrcweir c_rtl_tres_state
1255cdf0e10cSrcweir (
1256cdf0e10cSrcweir hRtlTestResult,
1257cdf0e10cSrcweir lastRes,
1258cdf0e10cSrcweir arrTestCase[i].comments,
1259cdf0e10cSrcweir createName( pMeth, "operator +", i )
1260cdf0e10cSrcweir );
1261cdf0e10cSrcweir
1262cdf0e10cSrcweir res &= lastRes;
1263cdf0e10cSrcweir
1264cdf0e10cSrcweir }
1265cdf0e10cSrcweir
1266cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "op_peq");
1267cdf0e10cSrcweir // return ( res );
1268cdf0e10cSrcweir }
1269cdf0e10cSrcweir
1270cdf0e10cSrcweir //------------------------------------------------------------------------
1271cdf0e10cSrcweir // testing the operator const sal_Char * (cscs for short)
1272cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_op_cscs(hTestResult hRtlTestResult)1273cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_cscs(
1274cdf0e10cSrcweir hTestResult hRtlTestResult )
1275cdf0e10cSrcweir {
1276cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
1277cdf0e10cSrcweir sal_Char* pMeth = methName;
1278cdf0e10cSrcweir
1279cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "op_cscs");
1280cdf0e10cSrcweir typedef struct TestCase
1281cdf0e10cSrcweir {
1282cdf0e10cSrcweir sal_Char* comments;
1283cdf0e10cSrcweir const sal_Char* expVal;
1284cdf0e10cSrcweir sal_Int32 cmpLen;
1285cdf0e10cSrcweir OString* input1;
1286cdf0e10cSrcweir ~TestCase() { delete input1;}
1287cdf0e10cSrcweir } TestCase;
1288cdf0e10cSrcweir
1289cdf0e10cSrcweir TestCase arrTestCase[] =
1290cdf0e10cSrcweir {
1291cdf0e10cSrcweir {"test normal string",kTestStr1,kTestStr1Len,new OString(kTestStr1)},
1292cdf0e10cSrcweir {"test empty string","",1,new OString()}
1293cdf0e10cSrcweir };
1294cdf0e10cSrcweir
1295cdf0e10cSrcweir sal_Bool res = sal_True;
1296cdf0e10cSrcweir sal_uInt32 i;
1297cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
1298cdf0e10cSrcweir {
1299cdf0e10cSrcweir const sal_Char* pstr = (*arrTestCase[i].input1);
1300cdf0e10cSrcweir
1301cdf0e10cSrcweir res &= c_rtl_tres_state
1302cdf0e10cSrcweir (
1303cdf0e10cSrcweir hRtlTestResult,
1304cdf0e10cSrcweir cmpstr((sal_Char*)pstr,(sal_Char*)arrTestCase[i].expVal,
1305cdf0e10cSrcweir arrTestCase[i].cmpLen),
1306cdf0e10cSrcweir arrTestCase[i].comments,
1307cdf0e10cSrcweir createName( pMeth, "const sal_Char*", i )
1308cdf0e10cSrcweir );
1309cdf0e10cSrcweir }
1310cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "op_cscs");
1311cdf0e10cSrcweir // return ( res );
1312cdf0e10cSrcweir }
1313cdf0e10cSrcweir
1314cdf0e10cSrcweir
1315cdf0e10cSrcweir //------------------------------------------------------------------------
1316cdf0e10cSrcweir // testing the method getStr()
1317cdf0e10cSrcweir //------------------------------------------------------------------------
1318cdf0e10cSrcweir
1319cdf0e10cSrcweir
test_rtl_OString_getStr(hTestResult hRtlTestResult)1320cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_getStr(
1321cdf0e10cSrcweir hTestResult hRtlTestResult )
1322cdf0e10cSrcweir {
1323cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
1324cdf0e10cSrcweir sal_Char* pMeth = methName;
1325cdf0e10cSrcweir
1326cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "getStr");
1327cdf0e10cSrcweir typedef struct TestCase
1328cdf0e10cSrcweir {
1329cdf0e10cSrcweir sal_Char* comments;
1330cdf0e10cSrcweir const sal_Char* expVal;
1331cdf0e10cSrcweir sal_Int32 cmpLen;
1332cdf0e10cSrcweir OString* input1;
1333cdf0e10cSrcweir ~TestCase() { delete input1;}
1334cdf0e10cSrcweir } TestCase;
1335cdf0e10cSrcweir
1336cdf0e10cSrcweir TestCase arrTestCase[] =
1337cdf0e10cSrcweir {
1338cdf0e10cSrcweir {"test normal string",kTestStr1,kTestStr1Len,new OString(kTestStr1)},
1339cdf0e10cSrcweir {"test empty string","",0,new OString()}
1340cdf0e10cSrcweir };
1341cdf0e10cSrcweir
1342cdf0e10cSrcweir sal_Bool res = sal_True;
1343cdf0e10cSrcweir sal_uInt32 i;
1344cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
1345cdf0e10cSrcweir {
1346cdf0e10cSrcweir const sal_Char* pstr = arrTestCase[i].input1->getStr();
1347cdf0e10cSrcweir res &= c_rtl_tres_state
1348cdf0e10cSrcweir (
1349cdf0e10cSrcweir hRtlTestResult,
1350cdf0e10cSrcweir cmpstr(pstr, arrTestCase[i].expVal,
1351cdf0e10cSrcweir arrTestCase[i].cmpLen),
1352cdf0e10cSrcweir arrTestCase[i].comments,
1353cdf0e10cSrcweir createName( pMeth, "getStr", i )
1354cdf0e10cSrcweir );
1355cdf0e10cSrcweir }
1356cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "getStr");
1357cdf0e10cSrcweir // return ( res );
1358cdf0e10cSrcweir }
1359cdf0e10cSrcweir
1360cdf0e10cSrcweir
1361cdf0e10cSrcweir
1362cdf0e10cSrcweir //------------------------------------------------------------------------
1363cdf0e10cSrcweir // testing the method copy( sal_Int32 beginIndex )
1364cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_copy_001(hTestResult hRtlTestResult)1365cdf0e10cSrcweir static sal_Bool SAL_CALL test_rtl_OString_copy_001(
1366cdf0e10cSrcweir hTestResult hRtlTestResult )
1367cdf0e10cSrcweir {
1368cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
1369cdf0e10cSrcweir sal_Char* pMeth = methName;
1370cdf0e10cSrcweir
1371cdf0e10cSrcweir typedef struct TestCase
1372cdf0e10cSrcweir {
1373cdf0e10cSrcweir sal_Char* comments;
1374cdf0e10cSrcweir const sal_Char* srcStr;
1375cdf0e10cSrcweir const sal_Char* arrExpStr;
1376cdf0e10cSrcweir // string for comparing with result
1377cdf0e10cSrcweir sal_Int32 beginIndex;
1378cdf0e10cSrcweir // beginIndex for the method copy
1379cdf0e10cSrcweir sal_Int32 lengthForCmp;
1380cdf0e10cSrcweir // number of symbols for comparing
1381cdf0e10cSrcweir // (if value is equal to 0 then pointers to buffers must be equal)
1382cdf0e10cSrcweir sal_Int32 expLength;
1383cdf0e10cSrcweir //expected length of the result string
1384cdf0e10cSrcweir } TestCase;
1385cdf0e10cSrcweir
1386cdf0e10cSrcweir TestCase arrTestCase[] =
1387cdf0e10cSrcweir {
1388cdf0e10cSrcweir {"beginIndex == 0 ( whole string )", kTestStr2,kTestStr2,
1389cdf0e10cSrcweir 0, kTestStr2Len, kTestStr2Len},
1390cdf0e10cSrcweir {"beginIndex == strlen-2 ( last two char )", kTestStr2,"gy",
1391cdf0e10cSrcweir kTestStr2Len-2, 2, 2},
1392cdf0e10cSrcweir {"beginIndex == strlen-1( last char )", kTestStr2, "y",
1393cdf0e10cSrcweir kTestStr2Len-1, 1, 1}
1394cdf0e10cSrcweir };
1395cdf0e10cSrcweir
1396cdf0e10cSrcweir sal_Bool res = sal_True;
1397cdf0e10cSrcweir sal_uInt32 i;
1398cdf0e10cSrcweir
1399cdf0e10cSrcweir for(i = 0; i <(sizeof (arrTestCase))/(sizeof (TestCase)); i++)
1400cdf0e10cSrcweir {
1401cdf0e10cSrcweir OString src(arrTestCase[i].srcStr);
1402cdf0e10cSrcweir OString dst;
1403cdf0e10cSrcweir // rtl_String* pDataSrc = src.pData;
1404cdf0e10cSrcweir
1405cdf0e10cSrcweir dst = src.copy(arrTestCase[i].beginIndex);
1406cdf0e10cSrcweir
1407cdf0e10cSrcweir // rtl_String* pDataDst = dst.pData;
1408cdf0e10cSrcweir
1409cdf0e10cSrcweir sal_Bool lastRes;
1410cdf0e10cSrcweir
1411cdf0e10cSrcweir lastRes= (dst== arrTestCase[i].arrExpStr);
1412cdf0e10cSrcweir
1413cdf0e10cSrcweir
1414cdf0e10cSrcweir c_rtl_tres_state
1415cdf0e10cSrcweir (
1416cdf0e10cSrcweir hRtlTestResult,
1417cdf0e10cSrcweir lastRes,
1418cdf0e10cSrcweir arrTestCase[i].comments,
1419cdf0e10cSrcweir createName( pMeth,
1420cdf0e10cSrcweir "copy_001(beginIndex)(check buffer and length)", i )
1421cdf0e10cSrcweir );
1422cdf0e10cSrcweir
1423cdf0e10cSrcweir res &= lastRes;
1424cdf0e10cSrcweir
1425cdf0e10cSrcweir }
1426cdf0e10cSrcweir
1427cdf0e10cSrcweir return (res);
1428cdf0e10cSrcweir }
1429cdf0e10cSrcweir
1430cdf0e10cSrcweir
1431cdf0e10cSrcweir //------------------------------------------------------------------------
1432cdf0e10cSrcweir // testing the method copy( sal_Int32 beginIndex, sal_Int32 count )
1433cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_copy_002(hTestResult hRtlTestResult)1434cdf0e10cSrcweir static sal_Bool SAL_CALL test_rtl_OString_copy_002(
1435cdf0e10cSrcweir hTestResult hRtlTestResult )
1436cdf0e10cSrcweir {
1437cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
1438cdf0e10cSrcweir sal_Char* pMeth = methName;
1439cdf0e10cSrcweir
1440cdf0e10cSrcweir typedef struct TestCase
1441cdf0e10cSrcweir {
1442cdf0e10cSrcweir sal_Char* comments;
1443cdf0e10cSrcweir const sal_Char* arrExpStr;
1444cdf0e10cSrcweir sal_Int32 beginIndex;
1445cdf0e10cSrcweir sal_Int32 count;
1446cdf0e10cSrcweir sal_Int32 expLen;
1447cdf0e10cSrcweir
1448cdf0e10cSrcweir } TestCase;
1449cdf0e10cSrcweir
1450cdf0e10cSrcweir TestCase arrTestCase[] ={
1451cdf0e10cSrcweir
1452cdf0e10cSrcweir {"copy substring", kTestStr6, kTestStr11Len, kTestStr2Len - kTestStr11Len,kTestStr6Len},
1453cdf0e10cSrcweir /* LLA: it is a bug, beginIndex + count > kTestStr2.getLength() */
1454cdf0e10cSrcweir /* {"copy normal substring with incorrect count",kTestStr6, kTestStr11Len, 31, 15}, */
1455cdf0e10cSrcweir {"copy whole string", kTestStr2, 0, kTestStr2Len, kTestStr2Len},
1456cdf0e10cSrcweir /* {"copy whole string with incorrect count larger than len and index 0", kTestStr2, 0, 40, 32}, */
1457cdf0e10cSrcweir /* LLA: bug beginIndex + count > kTestStr2 {"copy last character", "y",kTestStr2Len - 1, 31,1}, */
1458cdf0e10cSrcweir {"copy last character", "y",kTestStr2Len - 1, 1,1},
1459cdf0e10cSrcweir /* LLA: bug, beginIndex > kTestStr2 {"beginindex larger than len","",60, 0,0}, */
1460cdf0e10cSrcweir {"beginindex exact as large as it's length","",kTestStr2Len, 0,0}
1461cdf0e10cSrcweir /* LLA: bug, negative count is not allowed. {"count is nagative int","",3, -1,0} */
1462cdf0e10cSrcweir };
1463cdf0e10cSrcweir sal_Bool res = sal_True;
1464cdf0e10cSrcweir
1465cdf0e10cSrcweir sal_uInt32 i;
1466cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) {
1467cdf0e10cSrcweir OString src(kTestStr2);
1468cdf0e10cSrcweir OString dst;
1469cdf0e10cSrcweir dst = src.copy(arrTestCase[i].beginIndex, arrTestCase[i].count);
1470cdf0e10cSrcweir // rtl_String* pDataSrc = src.pData;
1471cdf0e10cSrcweir // rtl_String* pDataDst = dst.pData;
1472cdf0e10cSrcweir
1473cdf0e10cSrcweir sal_Bool lastRes=sal_True;
1474cdf0e10cSrcweir // checks buffer and length
1475cdf0e10cSrcweir //t_print("this is copy__002 #%d\n", i);
1476cdf0e10cSrcweir //t_print("dst buffer =%s\n", pDataDst->buffer);
1477cdf0e10cSrcweir //t_print("expStr =%s\n", arrTestCase[i].arrExpStr);
1478cdf0e10cSrcweir //t_print("dst length =%d\n", pDataDst->length);
1479cdf0e10cSrcweir //t_print("count =%d\n", arrTestCase[i].count);
1480cdf0e10cSrcweir //t_print("expLen =%d\n", arrTestCase[i].expLen);
1481cdf0e10cSrcweir
1482cdf0e10cSrcweir lastRes = (dst.equals(arrTestCase[i].arrExpStr)) ? sal_True : sal_False;
1483cdf0e10cSrcweir
1484cdf0e10cSrcweir c_rtl_tres_state
1485cdf0e10cSrcweir (
1486cdf0e10cSrcweir hRtlTestResult,
1487cdf0e10cSrcweir lastRes,
1488cdf0e10cSrcweir arrTestCase[i].comments,
1489cdf0e10cSrcweir createName( pMeth,
1490cdf0e10cSrcweir "copy_002(beginIndex,count)(check buffer and length)", i)
1491cdf0e10cSrcweir );
1492cdf0e10cSrcweir res &= lastRes;
1493cdf0e10cSrcweir
1494cdf0e10cSrcweir
1495cdf0e10cSrcweir }
1496cdf0e10cSrcweir
1497cdf0e10cSrcweir return (res);
1498cdf0e10cSrcweir }
1499cdf0e10cSrcweir
1500cdf0e10cSrcweir
test_rtl_OString_copy_003(hTestResult hRtlTestResult)1501cdf0e10cSrcweir static sal_Bool SAL_CALL test_rtl_OString_copy_003(
1502cdf0e10cSrcweir hTestResult hRtlTestResult )
1503cdf0e10cSrcweir {
1504cdf0e10cSrcweir sal_Bool res = sal_True;
1505cdf0e10cSrcweir char comment[] = "copy whole short string to long string";
1506cdf0e10cSrcweir
1507cdf0e10cSrcweir OString src(kTestStr1);
1508cdf0e10cSrcweir // rtl_String* pDataSrc = src.pData;
1509cdf0e10cSrcweir OString dst(kTestStr2);
1510cdf0e10cSrcweir
1511cdf0e10cSrcweir dst = src.copy(0);
1512cdf0e10cSrcweir // rtl_String* pDataDst = dst.pData;
1513cdf0e10cSrcweir //check buffer and length
1514cdf0e10cSrcweir sal_Bool lastRes =(dst==src);
1515cdf0e10cSrcweir c_rtl_tres_state
1516cdf0e10cSrcweir (
1517cdf0e10cSrcweir hRtlTestResult,
1518cdf0e10cSrcweir lastRes,
1519cdf0e10cSrcweir comment,
1520cdf0e10cSrcweir "copy_003(beginIndex)(check buffer and length)"
1521cdf0e10cSrcweir );
1522cdf0e10cSrcweir res &= lastRes;
1523cdf0e10cSrcweir
1524cdf0e10cSrcweir return (res);
1525cdf0e10cSrcweir }
1526cdf0e10cSrcweir
1527cdf0e10cSrcweir
test_rtl_OString_copy_004(hTestResult hRtlTestResult)1528cdf0e10cSrcweir static sal_Bool SAL_CALL test_rtl_OString_copy_004(
1529cdf0e10cSrcweir hTestResult hRtlTestResult )
1530cdf0e10cSrcweir {
1531cdf0e10cSrcweir sal_Bool res = sal_True;
1532cdf0e10cSrcweir sal_Char comment[] = "copy whole long string to short string";
1533cdf0e10cSrcweir
1534cdf0e10cSrcweir OString src(kTestStr2);
1535cdf0e10cSrcweir // rtl_String* pDataSrc = src.pData;
1536cdf0e10cSrcweir OString dst(kTestStr1);
1537cdf0e10cSrcweir
1538cdf0e10cSrcweir dst = src.copy(0);
1539cdf0e10cSrcweir // rtl_String* pDataDst = dst.pData;
1540cdf0e10cSrcweir //check buffer and length
1541cdf0e10cSrcweir sal_Bool lastRes =(dst==src);
1542cdf0e10cSrcweir c_rtl_tres_state
1543cdf0e10cSrcweir (
1544cdf0e10cSrcweir hRtlTestResult,
1545cdf0e10cSrcweir lastRes,
1546cdf0e10cSrcweir comment,
1547cdf0e10cSrcweir "copy_004(beginIndex)(check buffer and length)"
1548cdf0e10cSrcweir );
1549cdf0e10cSrcweir
1550cdf0e10cSrcweir res &= lastRes;
1551cdf0e10cSrcweir return (res);
1552cdf0e10cSrcweir }
1553cdf0e10cSrcweir
test_rtl_OString_copy(hTestResult hRtlTestResult)1554cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_copy(
1555cdf0e10cSrcweir hTestResult hRtlTestResult )
1556cdf0e10cSrcweir {
1557cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "copy");
1558cdf0e10cSrcweir sal_Bool res = test_rtl_OString_copy_001(hRtlTestResult);
1559cdf0e10cSrcweir res &= test_rtl_OString_copy_002(hRtlTestResult);
1560cdf0e10cSrcweir res &= test_rtl_OString_copy_003(hRtlTestResult);
1561cdf0e10cSrcweir res &= test_rtl_OString_copy_004(hRtlTestResult);
1562cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "copy");
1563cdf0e10cSrcweir
1564cdf0e10cSrcweir // return ( res );
1565cdf0e10cSrcweir }
1566cdf0e10cSrcweir
1567cdf0e10cSrcweir //------------------------------------------------------------------------
1568cdf0e10cSrcweir // testing the method concat( const OString & aStr )
1569cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_concat(hTestResult hRtlTestResult)1570cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_concat(
1571cdf0e10cSrcweir hTestResult hRtlTestResult )
1572cdf0e10cSrcweir {
1573cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
1574cdf0e10cSrcweir sal_Char* pMeth =methName;
1575cdf0e10cSrcweir
1576cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "concat");
1577cdf0e10cSrcweir typedef struct TestCase
1578cdf0e10cSrcweir {
1579cdf0e10cSrcweir sal_Char* comments;
1580cdf0e10cSrcweir OString* expVal;
1581cdf0e10cSrcweir OString* input1;
1582cdf0e10cSrcweir OString* input2;
1583cdf0e10cSrcweir ~TestCase() { delete input1;delete input2; delete expVal;}
1584cdf0e10cSrcweir } TestCase;
1585cdf0e10cSrcweir
1586cdf0e10cSrcweir TestCase arrTestCase[] =
1587cdf0e10cSrcweir {
1588cdf0e10cSrcweir {"concatenates two strings",new OString(kTestStr1),
1589cdf0e10cSrcweir new OString(kTestStr7),
1590cdf0e10cSrcweir new OString(kTestStr8)},
1591cdf0e10cSrcweir {"concatenates empty string",new OString(kTestStr1),
1592cdf0e10cSrcweir new OString(kTestStr1),
1593cdf0e10cSrcweir new OString("")},
1594cdf0e10cSrcweir {"concatenates to empty string",new OString(kTestStr1),
1595cdf0e10cSrcweir new OString(""),
1596cdf0e10cSrcweir new OString(kTestStr1)},
1597cdf0e10cSrcweir {"concatenates two empty strings",new OString(""),new OString(""),
1598cdf0e10cSrcweir new OString("")},
1599cdf0e10cSrcweir {"concatenates string constructed by default constructor",
1600cdf0e10cSrcweir new OString(kTestStr1),
1601cdf0e10cSrcweir new OString(kTestStr1), new OString()},
1602cdf0e10cSrcweir {"concatenates to string constructed by default constructor",
1603cdf0e10cSrcweir new OString(kTestStr1),
1604cdf0e10cSrcweir new OString(), new OString(kTestStr1)},
1605cdf0e10cSrcweir {"concatenates two strings constructed by default constructor",
1606cdf0e10cSrcweir new OString(),
1607cdf0e10cSrcweir new OString(), new OString()}
1608cdf0e10cSrcweir };
1609cdf0e10cSrcweir
1610cdf0e10cSrcweir sal_Bool res = sal_True;
1611cdf0e10cSrcweir sal_uInt32 i;
1612cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
1613cdf0e10cSrcweir {
1614cdf0e10cSrcweir OString str =
1615cdf0e10cSrcweir arrTestCase[i].input1->concat(*arrTestCase[i].input2);
1616cdf0e10cSrcweir sal_Bool lastRes = (str == *arrTestCase[i].expVal);
1617cdf0e10cSrcweir
1618cdf0e10cSrcweir c_rtl_tres_state
1619cdf0e10cSrcweir (
1620cdf0e10cSrcweir hRtlTestResult,
1621cdf0e10cSrcweir lastRes,
1622cdf0e10cSrcweir arrTestCase[i].comments,
1623cdf0e10cSrcweir createName( pMeth, "concat", i)
1624cdf0e10cSrcweir );
1625cdf0e10cSrcweir
1626cdf0e10cSrcweir res &= lastRes;
1627cdf0e10cSrcweir
1628cdf0e10cSrcweir }
1629cdf0e10cSrcweir
1630cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "concat");
1631cdf0e10cSrcweir // return ( res );
1632cdf0e10cSrcweir }
1633cdf0e10cSrcweir
1634cdf0e10cSrcweir
1635cdf0e10cSrcweir //------------------------------------------------------------------------
1636cdf0e10cSrcweir // testing the method toAsciiLowerCase()
1637cdf0e10cSrcweir //-----------------------------------------------------------------------
test_rtl_OString_toAsciiLowerCase(hTestResult hRtlTestResult)1638cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_toAsciiLowerCase(
1639cdf0e10cSrcweir hTestResult hRtlTestResult )
1640cdf0e10cSrcweir {
1641cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
1642cdf0e10cSrcweir sal_Char* pMeth =methName;
1643cdf0e10cSrcweir
1644cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "toAsciiLowerCase");
1645cdf0e10cSrcweir typedef struct TestCase
1646cdf0e10cSrcweir {
1647cdf0e10cSrcweir sal_Char* comments;
1648cdf0e10cSrcweir OString* expVal;
1649cdf0e10cSrcweir OString* input1;
1650cdf0e10cSrcweir ~TestCase() { delete input1; delete expVal;}
1651cdf0e10cSrcweir } TestCase;
1652cdf0e10cSrcweir
1653cdf0e10cSrcweir TestCase arrTestCase[] =
1654cdf0e10cSrcweir {
1655cdf0e10cSrcweir
1656cdf0e10cSrcweir {"only uppercase",new OString(kTestStr5),new OString(kTestStr4)},
1657cdf0e10cSrcweir {"different cases",new OString(kTestStr5),new OString(kTestStr1)},
1658cdf0e10cSrcweir {"different cases",new OString(kTestStr5),new OString(kTestStr3)},
1659cdf0e10cSrcweir {"only lowercase",new OString(kTestStr5),new OString(kTestStr5)},
1660cdf0e10cSrcweir {"empty string",new OString(""),new OString("")},
1661cdf0e10cSrcweir {"string constructed by default constructor",
1662cdf0e10cSrcweir new OString(),new OString()}
1663cdf0e10cSrcweir };
1664cdf0e10cSrcweir
1665cdf0e10cSrcweir sal_Bool res = sal_True;
1666cdf0e10cSrcweir sal_uInt32 i;
1667cdf0e10cSrcweir
1668cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
1669cdf0e10cSrcweir {
1670cdf0e10cSrcweir OString str = arrTestCase[i].input1->toAsciiLowerCase();
1671cdf0e10cSrcweir sal_Bool lastRes = (str ==* arrTestCase[i].expVal);
1672cdf0e10cSrcweir
1673cdf0e10cSrcweir c_rtl_tres_state
1674cdf0e10cSrcweir (
1675cdf0e10cSrcweir hRtlTestResult,
1676cdf0e10cSrcweir lastRes,
1677cdf0e10cSrcweir arrTestCase[i].comments,
1678cdf0e10cSrcweir createName( pMeth, "toAsciiLowerCase", i)
1679cdf0e10cSrcweir );
1680cdf0e10cSrcweir
1681cdf0e10cSrcweir res &= lastRes;
1682cdf0e10cSrcweir }
1683cdf0e10cSrcweir
1684cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "toAsciiLowerCase");
1685cdf0e10cSrcweir // return ( res );
1686cdf0e10cSrcweir }
1687cdf0e10cSrcweir
1688cdf0e10cSrcweir //------------------------------------------------------------------------
1689cdf0e10cSrcweir // testing the method toAsciiUpperCase()
1690cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_toAsciiUpperCase(hTestResult hRtlTestResult)1691cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_toAsciiUpperCase(
1692cdf0e10cSrcweir hTestResult hRtlTestResult )
1693cdf0e10cSrcweir {
1694cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
1695cdf0e10cSrcweir sal_Char* pMeth =methName;
1696cdf0e10cSrcweir
1697cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "toAsciiUpperCase");
1698cdf0e10cSrcweir typedef struct TestCase
1699cdf0e10cSrcweir {
1700cdf0e10cSrcweir sal_Char* comments;
1701cdf0e10cSrcweir OString* expVal;
1702cdf0e10cSrcweir OString* input1;
1703cdf0e10cSrcweir ~TestCase() { delete input1; delete expVal;}
1704cdf0e10cSrcweir } TestCase;
1705cdf0e10cSrcweir
1706cdf0e10cSrcweir TestCase arrTestCase[] =
1707cdf0e10cSrcweir {
1708cdf0e10cSrcweir {"only lowercase",new OString(kTestStr4),new OString(kTestStr5)},
1709cdf0e10cSrcweir {"mixed cases",new OString(kTestStr4),new OString(kTestStr3)},
1710cdf0e10cSrcweir {"miced cases",new OString(kTestStr4),new OString(kTestStr1)},
1711cdf0e10cSrcweir {"only uppercase",new OString(kTestStr4),new OString(kTestStr4)},
1712cdf0e10cSrcweir {"empty string",new OString(""),new OString("")},
1713cdf0e10cSrcweir {"string constructed by default constructor",
1714cdf0e10cSrcweir new OString(),new OString()}
1715cdf0e10cSrcweir };
1716cdf0e10cSrcweir
1717cdf0e10cSrcweir sal_Bool res = sal_True;
1718cdf0e10cSrcweir sal_uInt32 i;
1719cdf0e10cSrcweir
1720cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
1721cdf0e10cSrcweir {
1722cdf0e10cSrcweir OString str = arrTestCase[i].input1->toAsciiUpperCase();
1723cdf0e10cSrcweir sal_Bool lastRes = (str == *arrTestCase[i].expVal);
1724cdf0e10cSrcweir
1725cdf0e10cSrcweir c_rtl_tres_state
1726cdf0e10cSrcweir (
1727cdf0e10cSrcweir hRtlTestResult,
1728cdf0e10cSrcweir lastRes,
1729cdf0e10cSrcweir arrTestCase[i].comments,
1730cdf0e10cSrcweir createName( pMeth, "toAsciiLowerCase", i)
1731cdf0e10cSrcweir );
1732cdf0e10cSrcweir
1733cdf0e10cSrcweir res &= lastRes;
1734cdf0e10cSrcweir }
1735cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "toAsciiUpperCase");
1736cdf0e10cSrcweir
1737cdf0e10cSrcweir // return ( res );
1738cdf0e10cSrcweir }
1739cdf0e10cSrcweir
1740cdf0e10cSrcweir
1741cdf0e10cSrcweir //------------------------------------------------------------------------
1742cdf0e10cSrcweir // testing the method trim()
1743cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_trim(hTestResult hRtlTestResult)1744cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_trim(
1745cdf0e10cSrcweir hTestResult hRtlTestResult )
1746cdf0e10cSrcweir {
1747cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
1748cdf0e10cSrcweir sal_Char* pMeth =methName;
1749cdf0e10cSrcweir
1750cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "trim");
1751cdf0e10cSrcweir typedef struct TestCase
1752cdf0e10cSrcweir {
1753cdf0e10cSrcweir sal_Char* comments;
1754cdf0e10cSrcweir OString* expVal;
1755cdf0e10cSrcweir OString* input1;
1756cdf0e10cSrcweir ~TestCase() { delete input1; delete expVal;}
1757cdf0e10cSrcweir } TestCase;
1758cdf0e10cSrcweir
1759cdf0e10cSrcweir TestCase arrTestCase[] =
1760cdf0e10cSrcweir {
1761cdf0e10cSrcweir {"removes space from the front",new OString(kTestStr1),
1762cdf0e10cSrcweir new OString(kTestStr10)},
1763cdf0e10cSrcweir {"removes space from the end",new OString(kTestStr1),
1764cdf0e10cSrcweir new OString(kTestStr11)},
1765cdf0e10cSrcweir {"removes space from the front and end",new OString(kTestStr1),
1766cdf0e10cSrcweir new OString(kTestStr12)},
1767cdf0e10cSrcweir {"removes several spaces from the end",new OString(kTestStr1),
1768cdf0e10cSrcweir new OString(kTestStr13)},
1769cdf0e10cSrcweir {"removes several spaces from the front",new OString(kTestStr1),
1770cdf0e10cSrcweir new OString(kTestStr14)},
1771cdf0e10cSrcweir {"removes several spaces from the front and one from the end",
1772cdf0e10cSrcweir new OString(kTestStr1),
1773cdf0e10cSrcweir new OString(kTestStr15)},
1774cdf0e10cSrcweir {"removes one space from the front and several from the end",
1775cdf0e10cSrcweir new OString(kTestStr1),
1776cdf0e10cSrcweir new OString(kTestStr16)},
1777cdf0e10cSrcweir {"removes several spaces from the front and end",
1778cdf0e10cSrcweir new OString(kTestStr1),
1779cdf0e10cSrcweir new OString(kTestStr17)},
1780cdf0e10cSrcweir {"removes characters that have codes <= 32",new OString(kTestStr20),
1781cdf0e10cSrcweir new OString("\1\3\5\7\11\13\15\17sun\21\23\25\27\31\33\40")},
1782cdf0e10cSrcweir {"no spaces",new OString(kTestStr8),new OString(kTestStr8)}
1783cdf0e10cSrcweir };
1784cdf0e10cSrcweir
1785cdf0e10cSrcweir sal_Bool res = sal_True;
1786cdf0e10cSrcweir sal_uInt32 i;
1787cdf0e10cSrcweir
1788cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
1789cdf0e10cSrcweir {
1790cdf0e10cSrcweir OString strRes = arrTestCase[i].input1->trim();
1791cdf0e10cSrcweir sal_Bool lastRes = (strRes == *arrTestCase[i].expVal);
1792cdf0e10cSrcweir
1793cdf0e10cSrcweir c_rtl_tres_state
1794cdf0e10cSrcweir (
1795cdf0e10cSrcweir hRtlTestResult,
1796cdf0e10cSrcweir lastRes,
1797cdf0e10cSrcweir arrTestCase[i].comments,
1798cdf0e10cSrcweir createName( pMeth, "trim", i)
1799cdf0e10cSrcweir );
1800cdf0e10cSrcweir
1801cdf0e10cSrcweir res &= lastRes;
1802cdf0e10cSrcweir
1803cdf0e10cSrcweir }
1804cdf0e10cSrcweir
1805cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "trim");
1806cdf0e10cSrcweir // return ( res );
1807cdf0e10cSrcweir }
1808cdf0e10cSrcweir
1809cdf0e10cSrcweir
1810cdf0e10cSrcweir
1811cdf0e10cSrcweir //------------------------------------------------------------------------
1812cdf0e10cSrcweir // testing the method valueOf( sal_Bool b )
1813cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_valueOf_sal_Bool(hTestResult hRtlTestResult)1814cdf0e10cSrcweir sal_Bool SAL_CALL test_rtl_OString_valueOf_sal_Bool(
1815cdf0e10cSrcweir hTestResult hRtlTestResult )
1816cdf0e10cSrcweir {
1817cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
1818cdf0e10cSrcweir sal_Char* pMeth =methName;
1819cdf0e10cSrcweir
1820cdf0e10cSrcweir typedef struct TestCase
1821cdf0e10cSrcweir {
1822cdf0e10cSrcweir sal_Char* comments;
1823cdf0e10cSrcweir sal_Bool input1;
1824cdf0e10cSrcweir OString* expVal;
1825cdf0e10cSrcweir ~TestCase() {delete expVal;}
1826cdf0e10cSrcweir } TestCase;
1827cdf0e10cSrcweir
1828cdf0e10cSrcweir TestCase arrTestCase[] =
1829cdf0e10cSrcweir {
1830cdf0e10cSrcweir {"true",sal_True,new OString("true")},
1831cdf0e10cSrcweir {"false",sal_False, new OString("false")}
1832cdf0e10cSrcweir };
1833cdf0e10cSrcweir
1834cdf0e10cSrcweir sal_Bool res = sal_True;
1835cdf0e10cSrcweir sal_uInt32 i;
1836cdf0e10cSrcweir
1837cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
1838cdf0e10cSrcweir {
1839cdf0e10cSrcweir ::rtl::OString aStr1;
1840cdf0e10cSrcweir aStr1 = aStr1.valueOf( arrTestCase[i].input1 );
1841cdf0e10cSrcweir sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0);
1842cdf0e10cSrcweir
1843cdf0e10cSrcweir c_rtl_tres_state
1844cdf0e10cSrcweir (
1845cdf0e10cSrcweir hRtlTestResult,
1846cdf0e10cSrcweir lastRes,
1847cdf0e10cSrcweir arrTestCase[i].comments,
1848cdf0e10cSrcweir createName( pMeth, "valueof_bool", i)
1849cdf0e10cSrcweir );
1850cdf0e10cSrcweir
1851cdf0e10cSrcweir res &= lastRes;
1852cdf0e10cSrcweir
1853cdf0e10cSrcweir }
1854cdf0e10cSrcweir
1855cdf0e10cSrcweir return ( res );
1856cdf0e10cSrcweir }
1857cdf0e10cSrcweir
test_rtl_OString_valueOf_sal_Char(hTestResult hRtlTestResult)1858cdf0e10cSrcweir sal_Bool SAL_CALL test_rtl_OString_valueOf_sal_Char(
1859cdf0e10cSrcweir hTestResult hRtlTestResult )
1860cdf0e10cSrcweir {
1861cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
1862cdf0e10cSrcweir sal_Char* pMeth =methName;
1863cdf0e10cSrcweir
1864cdf0e10cSrcweir typedef struct TestCase
1865cdf0e10cSrcweir {
1866cdf0e10cSrcweir sal_Char* comments;
1867cdf0e10cSrcweir sal_Char input1;
1868cdf0e10cSrcweir OString* expVal;
1869cdf0e10cSrcweir ~TestCase() {delete expVal;}
1870cdf0e10cSrcweir } TestCase;
1871cdf0e10cSrcweir
1872cdf0e10cSrcweir TestCase arrTestCase[] =
1873cdf0e10cSrcweir {
1874cdf0e10cSrcweir {"A",'A',new OString("A")},
1875cdf0e10cSrcweir {"a",'a', new OString("a")},
1876cdf0e10cSrcweir {"0",'0', new OString("0")},
1877cdf0e10cSrcweir {"-",'-', new OString("-")},
1878cdf0e10cSrcweir {"_",'_', new OString("_")},
1879cdf0e10cSrcweir {"|",'|', new OString("|")},
1880cdf0e10cSrcweir {"?",'?', new OString("?")},
1881cdf0e10cSrcweir {"?",'?', new OString("?")},
1882cdf0e10cSrcweir {"\n",'\n', new OString("\n")},
1883cdf0e10cSrcweir {"\'",'\'', new OString("\'")},
1884cdf0e10cSrcweir {"\"",'\"', new OString("\"")}
1885cdf0e10cSrcweir
1886cdf0e10cSrcweir };
1887cdf0e10cSrcweir
1888cdf0e10cSrcweir sal_Bool res = sal_True;
1889cdf0e10cSrcweir sal_uInt32 i;
1890cdf0e10cSrcweir
1891cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
1892cdf0e10cSrcweir {
1893cdf0e10cSrcweir ::rtl::OString aStr1;
1894cdf0e10cSrcweir aStr1 = aStr1.valueOf( arrTestCase[i].input1 );
1895cdf0e10cSrcweir sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0);
1896cdf0e10cSrcweir
1897cdf0e10cSrcweir c_rtl_tres_state
1898cdf0e10cSrcweir (
1899cdf0e10cSrcweir hRtlTestResult,
1900cdf0e10cSrcweir lastRes,
1901cdf0e10cSrcweir arrTestCase[i].comments,
1902cdf0e10cSrcweir createName( pMeth, "valueof_char", i)
1903cdf0e10cSrcweir );
1904cdf0e10cSrcweir
1905cdf0e10cSrcweir res &= lastRes;
1906cdf0e10cSrcweir
1907cdf0e10cSrcweir }
1908cdf0e10cSrcweir
1909cdf0e10cSrcweir return ( res );
1910cdf0e10cSrcweir }
1911cdf0e10cSrcweir
1912cdf0e10cSrcweir /**
1913cdf0e10cSrcweir * Calls the method valueOf(T, radix) and compares
1914cdf0e10cSrcweir * returned strings with strings that passed in the array resArray.
1915cdf0e10cSrcweir *
1916cdf0e10cSrcweir * @param T, type of argument, passed to valueOf
1917cdf0e10cSrcweir * @param resArray, array of result strings to compare to
1918cdf0e10cSrcweir * @param n the number of elements in the array resArray (testcases)
1919cdf0e10cSrcweir * @param pTestResult the instance of the class TestResult
1920cdf0e10cSrcweir * @param inArray [optional], array of value that is passed as first argument
1921cdf0e10cSrcweir * to valueOf
1922cdf0e10cSrcweir *
1923cdf0e10cSrcweir * @return true, if all returned strings are equal to corresponding string in
1924cdf0e10cSrcweir * resArray else, false.
1925cdf0e10cSrcweir */
1926cdf0e10cSrcweir template <class T>
test_valueOf(const char ** resArray,int n,sal_Int16 radix,hTestResult hRtlTestResult,const T * inArray)1927cdf0e10cSrcweir sal_Bool test_valueOf( const char** resArray, int n, sal_Int16 radix,
1928cdf0e10cSrcweir hTestResult hRtlTestResult, const T *inArray )
1929cdf0e10cSrcweir {
1930cdf0e10cSrcweir sal_Bool bRes = sal_True;
1931cdf0e10cSrcweir
1932cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
1933cdf0e10cSrcweir sal_Char* pMeth = methName;
1934cdf0e10cSrcweir sal_Int32 i;
1935cdf0e10cSrcweir
1936cdf0e10cSrcweir for (i = 0; i < n; i++)
1937cdf0e10cSrcweir {
1938cdf0e10cSrcweir ::rtl::OString aStr1;
1939cdf0e10cSrcweir ::rtl::OString aStr2( resArray[i] );
1940cdf0e10cSrcweir
1941cdf0e10cSrcweir if (inArray == 0)
1942cdf0e10cSrcweir aStr1 = ::rtl::OString::valueOf((T)i, radix);
1943cdf0e10cSrcweir else
1944cdf0e10cSrcweir {
1945cdf0e10cSrcweir if ( inArray[i] < 0 )
1946cdf0e10cSrcweir {
1947cdf0e10cSrcweir aStr2 = "-";
1948cdf0e10cSrcweir aStr2 += resArray[i];
1949cdf0e10cSrcweir }
1950cdf0e10cSrcweir aStr1 = ::rtl::OString::valueOf((T)inArray[i], radix);
1951cdf0e10cSrcweir }
1952cdf0e10cSrcweir
1953cdf0e10cSrcweir bRes &= c_rtl_tres_state
1954cdf0e10cSrcweir (
1955cdf0e10cSrcweir hRtlTestResult,
1956cdf0e10cSrcweir aStr2.compareTo(aStr1) == 0,
1957cdf0e10cSrcweir (sal_Char*)resArray[i],
1958cdf0e10cSrcweir createName( pMeth, "valueOf", i )
1959cdf0e10cSrcweir );
1960cdf0e10cSrcweir }
1961cdf0e10cSrcweir
1962cdf0e10cSrcweir return (bRes);
1963cdf0e10cSrcweir }
1964cdf0e10cSrcweir
1965cdf0e10cSrcweir
1966cdf0e10cSrcweir #define test_valueOf_Int32 test_valueOf<sal_Int32>
1967cdf0e10cSrcweir #define test_valueOf_Int64 test_valueOf<sal_Int64>
1968cdf0e10cSrcweir // LLA: #define test_valueOf_float test_valueOf<float>
1969cdf0e10cSrcweir // LLA: #define test_valueOf_double test_valueOf<double>
1970cdf0e10cSrcweir
1971cdf0e10cSrcweir //------------------------------------------------------------------------
1972cdf0e10cSrcweir // testing the method valueOf( sal_Int32 i, sal_Int16 radix=2 )
1973cdf0e10cSrcweir // testing the method valueOf( sal_Int32 i, sal_Int16 radix=8 )
1974cdf0e10cSrcweir // testing the method valueOf( sal_Int32 i, sal_Int16 radix=10 )
1975cdf0e10cSrcweir // testing the method valueOf( sal_Int32 i, sal_Int16 radix=16 )
1976cdf0e10cSrcweir // testing the method valueOf( sal_Int32 i, sal_Int16 radix=36 )
1977cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_valueOf_Int32(hTestResult hRtlTestResult)1978cdf0e10cSrcweir sal_Bool SAL_CALL test_rtl_OString_valueOf_Int32(
1979cdf0e10cSrcweir hTestResult hRtlTestResult )
1980cdf0e10cSrcweir {
1981cdf0e10cSrcweir sal_Bool bRes = sal_False;
1982cdf0e10cSrcweir
1983cdf0e10cSrcweir bRes = c_rtl_tres_state
1984cdf0e10cSrcweir (
1985cdf0e10cSrcweir hRtlTestResult,
1986cdf0e10cSrcweir test_valueOf_Int32((const char**)kBinaryNumsStr,
1987cdf0e10cSrcweir kBinaryNumsCount, kRadixBinary, hRtlTestResult, 0 ),
1988cdf0e10cSrcweir "kRadixBinary",
1989cdf0e10cSrcweir "valueOf(sal_Int32, radix 2)"
1990cdf0e10cSrcweir );
1991cdf0e10cSrcweir
1992cdf0e10cSrcweir
1993cdf0e10cSrcweir bRes &= c_rtl_tres_state
1994cdf0e10cSrcweir (
1995cdf0e10cSrcweir hRtlTestResult,
1996cdf0e10cSrcweir test_valueOf_Int32((const char**)kOctolNumsStr,
1997cdf0e10cSrcweir kOctolNumsCount, kRadixOctol, hRtlTestResult, 0),
1998cdf0e10cSrcweir "kRadixOctol",
1999cdf0e10cSrcweir "valueOf(sal_Int32, radix 8)"
2000cdf0e10cSrcweir );
2001cdf0e10cSrcweir
2002cdf0e10cSrcweir bRes &= c_rtl_tres_state
2003cdf0e10cSrcweir (
2004cdf0e10cSrcweir hRtlTestResult,
2005cdf0e10cSrcweir test_valueOf_Int32((const char**)kDecimalNumsStr,
2006cdf0e10cSrcweir kDecimalNumsCount, kRadixDecimal, hRtlTestResult, 0),
2007cdf0e10cSrcweir "kRadixDecimal",
2008cdf0e10cSrcweir "valueOf(sal_Int32, radix 10)"
2009cdf0e10cSrcweir );
2010cdf0e10cSrcweir
2011cdf0e10cSrcweir bRes &= c_rtl_tres_state
2012cdf0e10cSrcweir (
2013cdf0e10cSrcweir hRtlTestResult,
2014cdf0e10cSrcweir test_valueOf_Int32((const char**)kHexDecimalNumsStr,
2015cdf0e10cSrcweir kHexDecimalNumsCount, kRadixHexdecimal, hRtlTestResult, 0),
2016cdf0e10cSrcweir "kRadixHexdecimal",
2017cdf0e10cSrcweir "valueOf(sal_Int32, radix 16)"
2018cdf0e10cSrcweir );
2019cdf0e10cSrcweir
2020cdf0e10cSrcweir bRes &= c_rtl_tres_state
2021cdf0e10cSrcweir (
2022cdf0e10cSrcweir hRtlTestResult,
2023cdf0e10cSrcweir test_valueOf_Int32((const char**)kBase36NumsStr,
2024cdf0e10cSrcweir kBase36NumsCount, kRadixBase36, hRtlTestResult, 0),
2025cdf0e10cSrcweir "kRadixBase36",
2026cdf0e10cSrcweir "valueOf(sal_Int32, radix 36)"
2027cdf0e10cSrcweir );
2028cdf0e10cSrcweir
2029cdf0e10cSrcweir
2030cdf0e10cSrcweir return ( bRes );
2031cdf0e10cSrcweir }
2032cdf0e10cSrcweir
2033cdf0e10cSrcweir //------------------------------------------------------------------------
2034cdf0e10cSrcweir // testing the method valueOf( sal_Int32 l, sal_Int32 radix=2 )
2035cdf0e10cSrcweir // where l = large constants
2036cdf0e10cSrcweir // testing the method valueOf( sal_Int32 l, sal_Int32 radix=8 )
2037cdf0e10cSrcweir // where l = large constants
2038cdf0e10cSrcweir // testing the method valueOf( sal_Int32 l, sal_Int32 radix=10 )
2039cdf0e10cSrcweir // where l = large constants
2040cdf0e10cSrcweir // testing the method valueOf( sal_Int32 l, sal_Int32 radix=16 )
2041cdf0e10cSrcweir // where l = large constants
2042cdf0e10cSrcweir // testing the method valueOf( sal_Int32 l, sal_Int32 radix=36 )
2043cdf0e10cSrcweir // where l = large constants
2044cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_valueOf_Int32_Bounderies(hTestResult hRtlTestResult)2045cdf0e10cSrcweir sal_Bool SAL_CALL test_rtl_OString_valueOf_Int32_Bounderies(
2046cdf0e10cSrcweir hTestResult hRtlTestResult )
2047cdf0e10cSrcweir {
2048cdf0e10cSrcweir sal_Bool bRes = sal_False;
2049cdf0e10cSrcweir
2050cdf0e10cSrcweir bRes = c_rtl_tres_state
2051cdf0e10cSrcweir (
2052cdf0e10cSrcweir hRtlTestResult,
2053cdf0e10cSrcweir test_valueOf_Int32((const char**)kBinaryMaxNumsStr,
2054cdf0e10cSrcweir kInt32MaxNumsCount, kRadixBinary, hRtlTestResult,
2055cdf0e10cSrcweir kInt32MaxNums),
2056cdf0e10cSrcweir "kRadixBinary",
2057cdf0e10cSrcweir "valueOf(salInt32, radix 2) Bounderies"
2058cdf0e10cSrcweir );
2059cdf0e10cSrcweir
2060cdf0e10cSrcweir bRes &= c_rtl_tres_state
2061cdf0e10cSrcweir (
2062cdf0e10cSrcweir hRtlTestResult,
2063cdf0e10cSrcweir test_valueOf_Int32((const char**)kOctolMaxNumsStr,
2064cdf0e10cSrcweir kInt32MaxNumsCount, kRadixOctol, hRtlTestResult,
2065cdf0e10cSrcweir kInt32MaxNums),
2066cdf0e10cSrcweir "kRadixOctol",
2067cdf0e10cSrcweir "valueOf(salInt32, radix 8) Bounderies"
2068cdf0e10cSrcweir );
2069cdf0e10cSrcweir
2070cdf0e10cSrcweir bRes &= c_rtl_tres_state
2071cdf0e10cSrcweir (
2072cdf0e10cSrcweir hRtlTestResult,
2073cdf0e10cSrcweir test_valueOf_Int32((const char**)kDecimalMaxNumsStr,
2074cdf0e10cSrcweir kInt32MaxNumsCount, kRadixDecimal,
2075cdf0e10cSrcweir hRtlTestResult, kInt32MaxNums),
2076cdf0e10cSrcweir "kRadixDecimal",
2077cdf0e10cSrcweir "valueOf(salInt32, radix 10) Bounderies"
2078cdf0e10cSrcweir );
2079cdf0e10cSrcweir
2080cdf0e10cSrcweir bRes &= c_rtl_tres_state
2081cdf0e10cSrcweir (
2082cdf0e10cSrcweir hRtlTestResult,
2083cdf0e10cSrcweir test_valueOf_Int32((const char**)kHexDecimalMaxNumsStr,
2084cdf0e10cSrcweir kInt32MaxNumsCount, kRadixHexdecimal,
2085cdf0e10cSrcweir hRtlTestResult, kInt32MaxNums),
2086cdf0e10cSrcweir "kRadixHexdecimal",
2087cdf0e10cSrcweir "valueOf(salInt32, radix 16) Bounderies"
2088cdf0e10cSrcweir );
2089cdf0e10cSrcweir
2090cdf0e10cSrcweir bRes &= c_rtl_tres_state
2091cdf0e10cSrcweir (
2092cdf0e10cSrcweir hRtlTestResult,
2093cdf0e10cSrcweir test_valueOf_Int32((const char**)kBase36MaxNumsStr,
2094cdf0e10cSrcweir kInt32MaxNumsCount, kRadixBase36,
2095cdf0e10cSrcweir hRtlTestResult, kInt32MaxNums),
2096cdf0e10cSrcweir "kRadixBase36",
2097cdf0e10cSrcweir "valueOf(salInt32, radix 36) Bounderies"
2098cdf0e10cSrcweir );
2099cdf0e10cSrcweir
2100cdf0e10cSrcweir return ( bRes );
2101cdf0e10cSrcweir }
2102cdf0e10cSrcweir
2103cdf0e10cSrcweir //------------------------------------------------------------------------
2104cdf0e10cSrcweir // testing the method valueOf( sal_Int32 i, sal_Int16 radix=2 )
2105cdf0e10cSrcweir // for negative value
2106cdf0e10cSrcweir // testing the method valueOf( sal_Int32 i, sal_Int16 radix=8 )
2107cdf0e10cSrcweir // for negative value
2108cdf0e10cSrcweir // testing the method valueOf( sal_Int32 i, sal_Int16 radix=10 )
2109cdf0e10cSrcweir // for negative value
2110cdf0e10cSrcweir // testing the method valueOf( sal_Int32 i, sal_Int16 radix=16 )
2111cdf0e10cSrcweir // for negative value
2112cdf0e10cSrcweir // testing the method valueOf( sal_Int32 i, sal_Int16 radix=36 )
2113cdf0e10cSrcweir // for negative value
2114cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_valueOf_Int32_Negative(hTestResult hRtlTestResult)2115cdf0e10cSrcweir sal_Bool SAL_CALL test_rtl_OString_valueOf_Int32_Negative(
2116cdf0e10cSrcweir hTestResult hRtlTestResult )
2117cdf0e10cSrcweir {
2118cdf0e10cSrcweir sal_Bool bRes = sal_False;
2119cdf0e10cSrcweir sal_Int32 inArr[kBase36NumsCount];
2120cdf0e10cSrcweir sal_Int32 i;
2121cdf0e10cSrcweir
2122cdf0e10cSrcweir for (i = 0; i < kBase36NumsCount; i++ )
2123cdf0e10cSrcweir inArr[i] = -i;
2124cdf0e10cSrcweir
2125cdf0e10cSrcweir bRes = c_rtl_tres_state
2126cdf0e10cSrcweir (
2127cdf0e10cSrcweir hRtlTestResult,
2128cdf0e10cSrcweir test_valueOf_Int32( kBinaryNumsStr, kBinaryNumsCount,
2129cdf0e10cSrcweir kRadixBinary, hRtlTestResult, inArr ),
2130cdf0e10cSrcweir "negative Int32, kRadixBinary",
2131cdf0e10cSrcweir "valueOf( negative Int32, radix 2 )"
2132cdf0e10cSrcweir );
2133cdf0e10cSrcweir
2134cdf0e10cSrcweir bRes &= c_rtl_tres_state
2135cdf0e10cSrcweir (
2136cdf0e10cSrcweir hRtlTestResult,
2137cdf0e10cSrcweir test_valueOf_Int32( kOctolNumsStr, kOctolNumsCount,
2138cdf0e10cSrcweir kRadixOctol, hRtlTestResult, inArr ),
2139cdf0e10cSrcweir "negative Int32, kRadixOctol",
2140cdf0e10cSrcweir "valueOf( negative Int32, radix 8 )"
2141cdf0e10cSrcweir );
2142cdf0e10cSrcweir
2143cdf0e10cSrcweir
2144cdf0e10cSrcweir bRes &= c_rtl_tres_state
2145cdf0e10cSrcweir (
2146cdf0e10cSrcweir hRtlTestResult,
2147cdf0e10cSrcweir test_valueOf_Int32( kDecimalNumsStr, kDecimalNumsCount,
2148cdf0e10cSrcweir kRadixDecimal, hRtlTestResult, inArr ),
2149cdf0e10cSrcweir "negative Int32, kRadixDecimal",
2150cdf0e10cSrcweir "valueOf( negative Int32, radix 10 )"
2151cdf0e10cSrcweir );
2152cdf0e10cSrcweir
2153cdf0e10cSrcweir bRes &= c_rtl_tres_state
2154cdf0e10cSrcweir (
2155cdf0e10cSrcweir hRtlTestResult,
2156cdf0e10cSrcweir test_valueOf_Int32( kHexDecimalNumsStr, kHexDecimalNumsCount,
2157cdf0e10cSrcweir kRadixHexdecimal, hRtlTestResult, inArr ),
2158cdf0e10cSrcweir "negative Int32, kRadixHexdecimal",
2159cdf0e10cSrcweir "valueOf( negative Int32, radix 16 )"
2160cdf0e10cSrcweir );
2161cdf0e10cSrcweir
2162cdf0e10cSrcweir
2163cdf0e10cSrcweir bRes &= c_rtl_tres_state
2164cdf0e10cSrcweir (
2165cdf0e10cSrcweir hRtlTestResult,
2166cdf0e10cSrcweir test_valueOf_Int32( kBase36NumsStr, kBase36NumsCount,
2167cdf0e10cSrcweir kRadixBase36, hRtlTestResult, inArr ),
2168cdf0e10cSrcweir "negative Int32, kRadixBase36",
2169cdf0e10cSrcweir "valueOf( negative Int32, radix 36 )"
2170cdf0e10cSrcweir );
2171cdf0e10cSrcweir
2172cdf0e10cSrcweir return ( bRes );
2173cdf0e10cSrcweir }
2174cdf0e10cSrcweir //------------------------------------------------------------------------
2175cdf0e10cSrcweir // testing the method valueOf( sal_Int32 l, sal_Int32 radix ) where radix = -5
2176cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_valueOf_Int32_WrongRadix(hTestResult hRtlTestResult)2177cdf0e10cSrcweir sal_Bool SAL_CALL test_rtl_OString_valueOf_Int32_WrongRadix(
2178cdf0e10cSrcweir hTestResult hRtlTestResult )
2179cdf0e10cSrcweir {
2180cdf0e10cSrcweir sal_Bool bRes = sal_False;
2181cdf0e10cSrcweir
2182cdf0e10cSrcweir sal_Int32 intVal = 11;
2183cdf0e10cSrcweir
2184cdf0e10cSrcweir ::rtl::OString aStr1;
2185cdf0e10cSrcweir ::rtl::OString aStr2("11");
2186cdf0e10cSrcweir
2187cdf0e10cSrcweir aStr1 = aStr1.valueOf( intVal, -5 );
2188cdf0e10cSrcweir
2189cdf0e10cSrcweir bRes = c_rtl_tres_state
2190cdf0e10cSrcweir (
2191cdf0e10cSrcweir hRtlTestResult,
2192cdf0e10cSrcweir aStr2.compareTo( aStr1 ) == 0,
2193cdf0e10cSrcweir "if radix not valid then radix must be 10",
2194cdf0e10cSrcweir "valueOf(sal_Int32, sal_Int32 radix): radix = -5"
2195cdf0e10cSrcweir );
2196cdf0e10cSrcweir
2197cdf0e10cSrcweir return (bRes);
2198cdf0e10cSrcweir }
2199cdf0e10cSrcweir
2200cdf0e10cSrcweir //------------------------------------------------------------------------
2201cdf0e10cSrcweir // testing the method valueOf( sal_Int32 l, sal_Int32 radix )
2202cdf0e10cSrcweir // where l = -2147483648 (smallest negative value)
2203cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_valueOf_Int32_SmallestNegativeValue(hTestResult hRtlTestResult)2204cdf0e10cSrcweir sal_Bool SAL_CALL test_rtl_OString_valueOf_Int32_SmallestNegativeValue(
2205cdf0e10cSrcweir hTestResult hRtlTestResult)
2206cdf0e10cSrcweir {
2207cdf0e10cSrcweir // Standard-conforming way to assign -2147483648 to n:
2208cdf0e10cSrcweir sal_Int32 n = -1;
2209cdf0e10cSrcweir for (int i = 1; i < 32; ++i)
2210cdf0e10cSrcweir n *= 2;
2211cdf0e10cSrcweir return c_rtl_tres_state
2212cdf0e10cSrcweir (
2213cdf0e10cSrcweir hRtlTestResult,
2214cdf0e10cSrcweir ::rtl::OString::valueOf(n) == "-2147483648",
2215cdf0e10cSrcweir "-2147483648",
2216cdf0e10cSrcweir "valueOf(sal_Int32 -2147483648)"
2217cdf0e10cSrcweir );
2218cdf0e10cSrcweir }
2219cdf0e10cSrcweir
2220cdf0e10cSrcweir //------------------------------------------------------------------------
2221cdf0e10cSrcweir // testing the method valueOf( sal_Int64 l, sal_Int16 radix=2 )
2222cdf0e10cSrcweir // testing the method valueOf( sal_Int64 l, sal_Int16 radix=8 )
2223cdf0e10cSrcweir // testing the method valueOf( sal_Int64 l, sal_Int16 radix=10 )
2224cdf0e10cSrcweir // testing the method valueOf( sal_Int64 l, sal_Int16 radix=16 )
2225cdf0e10cSrcweir // testing the method valueOf( sal_Int64 l, sal_Int16 radix=36 )
2226cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_valueOf_Int64(hTestResult hRtlTestResult)2227cdf0e10cSrcweir sal_Bool SAL_CALL test_rtl_OString_valueOf_Int64(
2228cdf0e10cSrcweir hTestResult hRtlTestResult )
2229cdf0e10cSrcweir {
2230cdf0e10cSrcweir sal_Bool bRes = sal_False;
2231cdf0e10cSrcweir
2232cdf0e10cSrcweir bRes = c_rtl_tres_state
2233cdf0e10cSrcweir (
2234cdf0e10cSrcweir hRtlTestResult,
2235cdf0e10cSrcweir test_valueOf_Int64((const char**)kBinaryNumsStr,
2236cdf0e10cSrcweir kBinaryNumsCount, kRadixBinary, hRtlTestResult, 0),
2237cdf0e10cSrcweir "kRadixBinary",
2238cdf0e10cSrcweir "valueOf(sal_Int64, radix 2)_"
2239cdf0e10cSrcweir );
2240cdf0e10cSrcweir
2241cdf0e10cSrcweir bRes &= c_rtl_tres_state
2242cdf0e10cSrcweir (
2243cdf0e10cSrcweir hRtlTestResult,
2244cdf0e10cSrcweir test_valueOf_Int64((const char**)kOctolNumsStr,
2245cdf0e10cSrcweir kOctolNumsCount, kRadixOctol, hRtlTestResult, 0),
2246cdf0e10cSrcweir "kRadixOctol",
2247cdf0e10cSrcweir "valueOf(sal_Int64, radix 8)_"
2248cdf0e10cSrcweir );
2249cdf0e10cSrcweir
2250cdf0e10cSrcweir bRes &= c_rtl_tres_state
2251cdf0e10cSrcweir (
2252cdf0e10cSrcweir hRtlTestResult,
2253cdf0e10cSrcweir test_valueOf_Int64((const char**)kDecimalNumsStr,
2254cdf0e10cSrcweir kDecimalNumsCount, kRadixDecimal, hRtlTestResult, 0),
2255cdf0e10cSrcweir "kRadixDecimal",
2256cdf0e10cSrcweir "valueOf(sal_Int64, radix 10)_"
2257cdf0e10cSrcweir );
2258cdf0e10cSrcweir bRes &= c_rtl_tres_state
2259cdf0e10cSrcweir (
2260cdf0e10cSrcweir hRtlTestResult,
2261cdf0e10cSrcweir test_valueOf_Int64((const char**)kHexDecimalNumsStr,
2262cdf0e10cSrcweir kHexDecimalNumsCount, kRadixHexdecimal, hRtlTestResult, 0),
2263cdf0e10cSrcweir "kRadixHexdecimal",
2264cdf0e10cSrcweir "valueOf(sal_Int64, radix 16)_"
2265cdf0e10cSrcweir );
2266cdf0e10cSrcweir
2267cdf0e10cSrcweir bRes &= c_rtl_tres_state
2268cdf0e10cSrcweir (
2269cdf0e10cSrcweir hRtlTestResult,
2270cdf0e10cSrcweir test_valueOf_Int64((const char**)kBase36NumsStr,
2271cdf0e10cSrcweir kBase36NumsCount, kRadixBase36, hRtlTestResult, 0),
2272cdf0e10cSrcweir "kRadixBase36",
2273cdf0e10cSrcweir "valueOf(sal_Int64, radix 36)_"
2274cdf0e10cSrcweir );
2275cdf0e10cSrcweir
2276cdf0e10cSrcweir return (bRes);
2277cdf0e10cSrcweir }
2278cdf0e10cSrcweir
2279cdf0e10cSrcweir //------------------------------------------------------------------------
2280cdf0e10cSrcweir // testing the method valueOf( sal_Int64 l, sal_Int32 radix=2 )
2281cdf0e10cSrcweir // where l = large constants
2282cdf0e10cSrcweir // testing the method valueOf( sal_Int64 l, sal_Int32 radix=8 )
2283cdf0e10cSrcweir // where l = large constants
2284cdf0e10cSrcweir // testing the method valueOf( sal_Int64 l, sal_Int32 radix=10 )
2285cdf0e10cSrcweir // where l = large constants
2286cdf0e10cSrcweir // testing the method valueOf( sal_Int64 l, sal_Int32 radix=16 )
2287cdf0e10cSrcweir // where l = large constants
2288cdf0e10cSrcweir // testing the method valueOf( sal_Int64 l, sal_Int32 radix=36 )
2289cdf0e10cSrcweir // where l = large constants
2290cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_valueOf_Int64_Bounderies(hTestResult hRtlTestResult)2291cdf0e10cSrcweir sal_Bool SAL_CALL test_rtl_OString_valueOf_Int64_Bounderies(
2292cdf0e10cSrcweir hTestResult hRtlTestResult )
2293cdf0e10cSrcweir {
2294cdf0e10cSrcweir sal_Bool bRes = sal_False;
2295cdf0e10cSrcweir
2296cdf0e10cSrcweir bRes = c_rtl_tres_state
2297cdf0e10cSrcweir (
2298cdf0e10cSrcweir hRtlTestResult,
2299cdf0e10cSrcweir test_valueOf_Int64((const char**)kBinaryMaxNumsStr,
2300cdf0e10cSrcweir kInt64MaxNumsCount, kRadixBinary,
2301cdf0e10cSrcweir hRtlTestResult, kInt64MaxNums),
2302cdf0e10cSrcweir "kRadixBinary",
2303cdf0e10cSrcweir "valueOf(salInt64, radix 2) Bounderies"
2304cdf0e10cSrcweir );
2305cdf0e10cSrcweir
2306cdf0e10cSrcweir bRes &= c_rtl_tres_state
2307cdf0e10cSrcweir (
2308cdf0e10cSrcweir hRtlTestResult,
2309cdf0e10cSrcweir test_valueOf_Int64((const char**)kOctolMaxNumsStr,
2310cdf0e10cSrcweir kInt64MaxNumsCount, kRadixOctol,
2311cdf0e10cSrcweir hRtlTestResult, kInt64MaxNums),
2312cdf0e10cSrcweir "kRadixOctol",
2313cdf0e10cSrcweir "valueOf(salInt64, radix 8) Bounderies"
2314cdf0e10cSrcweir );
2315cdf0e10cSrcweir
2316cdf0e10cSrcweir bRes &= c_rtl_tres_state
2317cdf0e10cSrcweir (
2318cdf0e10cSrcweir hRtlTestResult,
2319cdf0e10cSrcweir test_valueOf_Int64((const char**)kDecimalMaxNumsStr,
2320cdf0e10cSrcweir kInt64MaxNumsCount, kRadixDecimal,
2321cdf0e10cSrcweir hRtlTestResult, kInt64MaxNums),
2322cdf0e10cSrcweir "kRadixDecimal",
2323cdf0e10cSrcweir "valueOf(salInt64, radix 10) Bounderies"
2324cdf0e10cSrcweir );
2325cdf0e10cSrcweir
2326cdf0e10cSrcweir bRes &= c_rtl_tres_state
2327cdf0e10cSrcweir (
2328cdf0e10cSrcweir hRtlTestResult,
2329cdf0e10cSrcweir test_valueOf_Int64((const char**)kHexDecimalMaxNumsStr,
2330cdf0e10cSrcweir kInt64MaxNumsCount, kRadixHexdecimal,
2331cdf0e10cSrcweir hRtlTestResult, kInt64MaxNums),
2332cdf0e10cSrcweir "kRadixHexdecimal",
2333cdf0e10cSrcweir "valueOf(salInt64, radix 16) Bounderies"
2334cdf0e10cSrcweir );
2335cdf0e10cSrcweir
2336cdf0e10cSrcweir bRes &= c_rtl_tres_state
2337cdf0e10cSrcweir (
2338cdf0e10cSrcweir hRtlTestResult,
2339cdf0e10cSrcweir test_valueOf_Int64((const char**)kBase36MaxNumsStr,
2340cdf0e10cSrcweir kInt64MaxNumsCount, kRadixBase36,
2341cdf0e10cSrcweir hRtlTestResult, kInt64MaxNums),
2342cdf0e10cSrcweir "kRadixBase36",
2343cdf0e10cSrcweir "valueOf(salInt64, radix 36) Bounderies"
2344cdf0e10cSrcweir );
2345cdf0e10cSrcweir
2346cdf0e10cSrcweir return ( bRes );
2347cdf0e10cSrcweir }
2348cdf0e10cSrcweir
2349cdf0e10cSrcweir //------------------------------------------------------------------------
2350cdf0e10cSrcweir // testing the method valueOf( sal_Int64 l, sal_Int16 radix=2 )
2351cdf0e10cSrcweir // for negative value
2352cdf0e10cSrcweir // testing the method valueOf( sal_Int64 l, sal_Int16 radix=8 )
2353cdf0e10cSrcweir // for negative value
2354cdf0e10cSrcweir // testing the method valueOf( sal_Int64 l, sal_Int16 radix=10 )
2355cdf0e10cSrcweir // for negative value
2356cdf0e10cSrcweir // testing the method valueOf( sal_Int64 l, sal_Int16 radix=16 )
2357cdf0e10cSrcweir // for negative value
2358cdf0e10cSrcweir // testing the method valueOf( sal_Int64 l, sal_Int16 radix=36 )
2359cdf0e10cSrcweir // for negative value
2360cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_valueOf_Int64_Negative(hTestResult hRtlTestResult)2361cdf0e10cSrcweir sal_Bool SAL_CALL test_rtl_OString_valueOf_Int64_Negative(
2362cdf0e10cSrcweir hTestResult hRtlTestResult )
2363cdf0e10cSrcweir {
2364cdf0e10cSrcweir sal_Bool bRes = sal_False;
2365cdf0e10cSrcweir
2366cdf0e10cSrcweir sal_Int64 inArr[36];
2367cdf0e10cSrcweir sal_Int32 i;
2368cdf0e10cSrcweir
2369cdf0e10cSrcweir for (i = 0; i < 36; i++) {
2370cdf0e10cSrcweir inArr[i] = -i;
2371cdf0e10cSrcweir }
2372cdf0e10cSrcweir
2373cdf0e10cSrcweir
2374cdf0e10cSrcweir bRes = c_rtl_tres_state
2375cdf0e10cSrcweir (
2376cdf0e10cSrcweir hRtlTestResult,
2377cdf0e10cSrcweir test_valueOf_Int64( kBinaryNumsStr, kBinaryNumsCount,
2378cdf0e10cSrcweir kRadixBinary, hRtlTestResult, inArr ),
2379cdf0e10cSrcweir "negative Int64, kRadixBinary",
2380cdf0e10cSrcweir "valueOf( negative Int64, radix 2 )"
2381cdf0e10cSrcweir );
2382cdf0e10cSrcweir
2383cdf0e10cSrcweir bRes &= c_rtl_tres_state
2384cdf0e10cSrcweir (
2385cdf0e10cSrcweir hRtlTestResult,
2386cdf0e10cSrcweir test_valueOf_Int64( kOctolNumsStr, kOctolNumsCount,
2387cdf0e10cSrcweir kRadixOctol, hRtlTestResult, inArr ),
2388cdf0e10cSrcweir "negative Int64, kRadixOctol",
2389cdf0e10cSrcweir "valueOf( negative Int64, radix 8 )"
2390cdf0e10cSrcweir );
2391cdf0e10cSrcweir
2392cdf0e10cSrcweir bRes &= c_rtl_tres_state
2393cdf0e10cSrcweir (
2394cdf0e10cSrcweir hRtlTestResult,
2395cdf0e10cSrcweir test_valueOf_Int64( kDecimalNumsStr, kDecimalNumsCount,
2396cdf0e10cSrcweir kRadixDecimal, hRtlTestResult, inArr ),
2397cdf0e10cSrcweir "negative Int64, kRadixDecimal",
2398cdf0e10cSrcweir "valueOf( negative Int64, radix 10 )"
2399cdf0e10cSrcweir );
2400cdf0e10cSrcweir
2401cdf0e10cSrcweir bRes &= c_rtl_tres_state
2402cdf0e10cSrcweir (
2403cdf0e10cSrcweir hRtlTestResult,
2404cdf0e10cSrcweir test_valueOf_Int64( kHexDecimalNumsStr, kHexDecimalNumsCount,
2405cdf0e10cSrcweir kRadixHexdecimal, hRtlTestResult, inArr ),
2406cdf0e10cSrcweir "negative Int64, kRadixHexDecimal",
2407cdf0e10cSrcweir "valueOf( negative Int64, radix 16 )"
2408cdf0e10cSrcweir );
2409cdf0e10cSrcweir
2410cdf0e10cSrcweir bRes &= c_rtl_tres_state
2411cdf0e10cSrcweir (
2412cdf0e10cSrcweir hRtlTestResult,
2413cdf0e10cSrcweir test_valueOf_Int64( kBase36NumsStr, kBase36NumsCount,
2414cdf0e10cSrcweir kRadixBase36, hRtlTestResult, inArr),
2415cdf0e10cSrcweir "negative Int64, kRadixBase36",
2416cdf0e10cSrcweir "valueOf( negative Int64, radix 36 )"
2417cdf0e10cSrcweir );
2418cdf0e10cSrcweir
2419cdf0e10cSrcweir return (bRes);
2420cdf0e10cSrcweir }
2421cdf0e10cSrcweir //------------------------------------------------------------------------
2422cdf0e10cSrcweir // testing the method valueOf( sal_Int64 l, sal_Int32 radix )
2423cdf0e10cSrcweir // where radix = -5
2424cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_valueOf_Int64_WrongRadix(hTestResult hRtlTestResult)2425cdf0e10cSrcweir sal_Bool SAL_CALL test_rtl_OString_valueOf_Int64_WrongRadix(
2426cdf0e10cSrcweir hTestResult hRtlTestResult )
2427cdf0e10cSrcweir {
2428cdf0e10cSrcweir sal_Bool bRes = sal_False;
2429cdf0e10cSrcweir
2430cdf0e10cSrcweir sal_Int64 intVal = 11;
2431cdf0e10cSrcweir
2432cdf0e10cSrcweir ::rtl::OString aStr1;
2433cdf0e10cSrcweir ::rtl::OString aStr2("11");
2434cdf0e10cSrcweir
2435cdf0e10cSrcweir aStr1 = aStr1.valueOf( intVal, -5 );
2436cdf0e10cSrcweir
2437cdf0e10cSrcweir bRes = c_rtl_tres_state
2438cdf0e10cSrcweir (
2439cdf0e10cSrcweir hRtlTestResult,
2440cdf0e10cSrcweir aStr2.compareTo(aStr1) == 0,
2441cdf0e10cSrcweir "if radix not valid then radix must be 10",
2442cdf0e10cSrcweir "valueOf(sal_Int64, sal_Int32 radix): radix = -5"
2443cdf0e10cSrcweir );
2444cdf0e10cSrcweir
2445cdf0e10cSrcweir return (bRes);
2446cdf0e10cSrcweir }
2447cdf0e10cSrcweir
2448cdf0e10cSrcweir //------------------------------------------------------------------------
2449cdf0e10cSrcweir // testing the method valueOf( sal_Int64 l, sal_Int32 radix )
2450cdf0e10cSrcweir // where l = -9223372036854775808 (smallest negative value)
2451cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_valueOf_Int64_SmallestNegativeValue(hTestResult hRtlTestResult)2452cdf0e10cSrcweir sal_Bool SAL_CALL test_rtl_OString_valueOf_Int64_SmallestNegativeValue(
2453cdf0e10cSrcweir hTestResult hRtlTestResult)
2454cdf0e10cSrcweir {
2455cdf0e10cSrcweir // Standard-conforming way to assign -9223372036854775808 to n:
2456cdf0e10cSrcweir sal_Int64 n = -1;
2457cdf0e10cSrcweir for (int i = 1; i < 64; ++i)
2458cdf0e10cSrcweir n *= 2;
2459cdf0e10cSrcweir return c_rtl_tres_state
2460cdf0e10cSrcweir (
2461cdf0e10cSrcweir hRtlTestResult,
2462cdf0e10cSrcweir ::rtl::OString::valueOf(n) == "-9223372036854775808",
2463cdf0e10cSrcweir "-9223372036854775808",
2464cdf0e10cSrcweir "valueOf(sal_Int64 -9223372036854775808)"
2465cdf0e10cSrcweir );
2466cdf0e10cSrcweir }
2467cdf0e10cSrcweir
2468cdf0e10cSrcweir //------------------------------------------------------------------------
2469cdf0e10cSrcweir // testing the method valueOf( float f )
2470cdf0e10cSrcweir //------------------------------------------------------------------------
2471cdf0e10cSrcweir // LLA: sal_Bool SAL_CALL test_rtl_OString_valueOf_float(
2472cdf0e10cSrcweir // LLA: hTestResult hRtlTestResult )
2473cdf0e10cSrcweir // LLA: {
2474cdf0e10cSrcweir // LLA: sal_Char methName[MAXBUFLENGTH];
2475cdf0e10cSrcweir // LLA: sal_Char* pMeth =methName;
2476cdf0e10cSrcweir // LLA:
2477cdf0e10cSrcweir // LLA: typedef struct TestCase
2478cdf0e10cSrcweir // LLA: {
2479cdf0e10cSrcweir // LLA: sal_Char* comments;
2480cdf0e10cSrcweir // LLA: float input1;
2481cdf0e10cSrcweir // LLA: OString* expVal;
2482cdf0e10cSrcweir // LLA:
2483cdf0e10cSrcweir // LLA: ~TestCase() {delete expVal;}
2484cdf0e10cSrcweir // LLA: } TestCase;
2485cdf0e10cSrcweir // LLA:
2486cdf0e10cSrcweir // LLA: TestCase arrTestCase[] =
2487cdf0e10cSrcweir // LLA: {
2488cdf0e10cSrcweir // LLA: { "3.0", 3.0, new OString("3.0") },
2489cdf0e10cSrcweir // LLA: { "3.5", 3.5f, new OString("3.5")},
2490cdf0e10cSrcweir // LLA: { "3.0625", 3.0625f, new OString("3.0625")},
2491cdf0e10cSrcweir // LLA: { "3.502525", 3.502525f, new OString("3.502525") },
2492cdf0e10cSrcweir // LLA: { "3.141592", 3.141592f, new OString("3.141592") },
2493cdf0e10cSrcweir // LLA: { "3.5025255", 3.5025255f, new OString("3.5025255") },
2494cdf0e10cSrcweir // LLA: { "3.0039062", 3.00390625f, new OString("3.0039062") }
2495cdf0e10cSrcweir // LLA: };
2496cdf0e10cSrcweir // LLA:
2497cdf0e10cSrcweir // LLA: sal_Bool res = sal_True;
2498cdf0e10cSrcweir // LLA: sal_Int32 i;
2499cdf0e10cSrcweir // LLA:
2500cdf0e10cSrcweir // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
2501cdf0e10cSrcweir // LLA: {
2502cdf0e10cSrcweir // LLA: ::rtl::OString aStr1;
2503cdf0e10cSrcweir // LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 );
2504cdf0e10cSrcweir // LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0);
2505cdf0e10cSrcweir // LLA:
2506cdf0e10cSrcweir // LLA: c_rtl_tres_state
2507cdf0e10cSrcweir // LLA: (
2508cdf0e10cSrcweir // LLA: hRtlTestResult,
2509cdf0e10cSrcweir // LLA: lastRes,
2510cdf0e10cSrcweir // LLA: arrTestCase[i].comments,
2511cdf0e10cSrcweir // LLA: createName( pMeth, "valueof_float", i)
2512cdf0e10cSrcweir // LLA: );
2513cdf0e10cSrcweir // LLA:
2514cdf0e10cSrcweir // LLA: res &= lastRes;
2515cdf0e10cSrcweir // LLA:
2516cdf0e10cSrcweir // LLA: }
2517cdf0e10cSrcweir // LLA:
2518cdf0e10cSrcweir // LLA: return ( res );
2519cdf0e10cSrcweir // LLA: }
2520cdf0e10cSrcweir
2521cdf0e10cSrcweir
2522cdf0e10cSrcweir
2523cdf0e10cSrcweir
2524cdf0e10cSrcweir //------------------------------------------------------------------------
2525cdf0e10cSrcweir // testing the method valueOf( float f ) for negative value
2526cdf0e10cSrcweir //------------------------------------------------------------------------
2527cdf0e10cSrcweir // LLA: sal_Bool SAL_CALL test_rtl_OString_valueOf_Float_Negative(
2528cdf0e10cSrcweir // LLA: hTestResult hRtlTestResult )
2529cdf0e10cSrcweir // LLA: {
2530cdf0e10cSrcweir // LLA: sal_Char methName[MAXBUFLENGTH];
2531cdf0e10cSrcweir // LLA: sal_Char* pMeth =methName;
2532cdf0e10cSrcweir // LLA:
2533cdf0e10cSrcweir // LLA: typedef struct TestCase
2534cdf0e10cSrcweir // LLA: {
2535cdf0e10cSrcweir // LLA: sal_Char* comments;
2536cdf0e10cSrcweir // LLA: float input1;
2537cdf0e10cSrcweir // LLA: OString* expVal;
2538cdf0e10cSrcweir // LLA:
2539cdf0e10cSrcweir // LLA: ~TestCase() {delete expVal;}
2540cdf0e10cSrcweir // LLA: } TestCase;
2541cdf0e10cSrcweir // LLA:
2542cdf0e10cSrcweir // LLA: TestCase arrTestCase[] =
2543cdf0e10cSrcweir // LLA: {
2544cdf0e10cSrcweir // LLA: { "-3.0", -3.0, new OString("-3.0") },
2545cdf0e10cSrcweir // LLA: { "-3.5", -3.5f, new OString("-3.5")},
2546cdf0e10cSrcweir // LLA: { "-3.0625", -3.0625f, new OString("-3.0625")},
2547cdf0e10cSrcweir // LLA: { "-3.502525", -3.502525f, new OString("-3.502525") },
2548cdf0e10cSrcweir // LLA: { "-3.141592", -3.141592f, new OString("-3.141592") },
2549cdf0e10cSrcweir // LLA: { "-3.5025255", -3.5025255f, new OString("-3.5025255") },
2550cdf0e10cSrcweir // LLA: { "-3.0039062", -3.00390625f, new OString("-3.0039062") }
2551cdf0e10cSrcweir // LLA: };
2552cdf0e10cSrcweir // LLA:
2553cdf0e10cSrcweir // LLA: sal_Bool res = sal_True;
2554cdf0e10cSrcweir // LLA: sal_Int32 i;
2555cdf0e10cSrcweir // LLA:
2556cdf0e10cSrcweir // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
2557cdf0e10cSrcweir // LLA: {
2558cdf0e10cSrcweir // LLA: ::rtl::OString aStr1;
2559cdf0e10cSrcweir // LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 );
2560cdf0e10cSrcweir // LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0);
2561cdf0e10cSrcweir // LLA:
2562cdf0e10cSrcweir // LLA: c_rtl_tres_state
2563cdf0e10cSrcweir // LLA: (
2564cdf0e10cSrcweir // LLA: hRtlTestResult,
2565cdf0e10cSrcweir // LLA: lastRes,
2566cdf0e10cSrcweir // LLA: arrTestCase[i].comments,
2567cdf0e10cSrcweir // LLA: createName( pMeth, "valueof_negative float", i)
2568cdf0e10cSrcweir // LLA: );
2569cdf0e10cSrcweir // LLA:
2570cdf0e10cSrcweir // LLA: res &= lastRes;
2571cdf0e10cSrcweir // LLA:
2572cdf0e10cSrcweir // LLA: }
2573cdf0e10cSrcweir // LLA:
2574cdf0e10cSrcweir // LLA: return ( res );
2575cdf0e10cSrcweir // LLA: }
2576cdf0e10cSrcweir
2577cdf0e10cSrcweir //------------------------------------------------------------------------
2578cdf0e10cSrcweir // testing the method valueOf( double f )
2579cdf0e10cSrcweir //------------------------------------------------------------------------
2580cdf0e10cSrcweir // LLA: sal_Bool SAL_CALL test_rtl_OString_valueOf_double(
2581cdf0e10cSrcweir // LLA: hTestResult hRtlTestResult )
2582cdf0e10cSrcweir // LLA: {
2583cdf0e10cSrcweir // LLA: sal_Char methName[MAXBUFLENGTH];
2584cdf0e10cSrcweir // LLA: sal_Char* pMeth =methName;
2585cdf0e10cSrcweir // LLA:
2586cdf0e10cSrcweir // LLA: typedef struct TestCase
2587cdf0e10cSrcweir // LLA: {
2588cdf0e10cSrcweir // LLA: sal_Char* comments;
2589cdf0e10cSrcweir // LLA: double input1;
2590cdf0e10cSrcweir // LLA: OString* expVal;
2591cdf0e10cSrcweir // LLA:
2592cdf0e10cSrcweir // LLA: ~TestCase() {delete expVal;}
2593cdf0e10cSrcweir // LLA: } TestCase;
2594cdf0e10cSrcweir // LLA:
2595cdf0e10cSrcweir // LLA: TestCase arrTestCase[] =
2596cdf0e10cSrcweir // LLA: {
2597cdf0e10cSrcweir // LLA: {"3.0", 3.0, new OString("3.0")},
2598cdf0e10cSrcweir // LLA: {"3.5", 3.5, new OString("3.5")},
2599cdf0e10cSrcweir // LLA: {"3.0625", 3.0625, new OString("3.0625")},
2600cdf0e10cSrcweir // LLA: {"3.1415926535", 3.1415926535, new OString("3.1415926535")},
2601cdf0e10cSrcweir // LLA: {"3.1415926535897931", 3.141592653589793,
2602cdf0e10cSrcweir // LLA: new OString("3.1415926535897931")},
2603cdf0e10cSrcweir // LLA: {"3.1415926535897931", 3.1415926535897932,
2604cdf0e10cSrcweir // LLA: new OString("3.1415926535897931")},
2605cdf0e10cSrcweir // LLA: {"3.1415926535897931", 3.14159265358979323,
2606cdf0e10cSrcweir // LLA: new OString("3.1415926535897931")},
2607cdf0e10cSrcweir // LLA: {"3.1415926535897931", 3.141592653589793238462643,
2608cdf0e10cSrcweir // LLA: new OString("3.1415926535897931")}
2609cdf0e10cSrcweir // LLA: };
2610cdf0e10cSrcweir // LLA:
2611cdf0e10cSrcweir // LLA: sal_Bool res = sal_True;
2612cdf0e10cSrcweir // LLA: sal_Int32 i;
2613cdf0e10cSrcweir // LLA:
2614cdf0e10cSrcweir // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
2615cdf0e10cSrcweir // LLA: {
2616cdf0e10cSrcweir // LLA: ::rtl::OString aStr1;
2617cdf0e10cSrcweir // LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 );
2618cdf0e10cSrcweir // LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0);
2619cdf0e10cSrcweir // LLA:
2620cdf0e10cSrcweir // LLA: c_rtl_tres_state
2621cdf0e10cSrcweir // LLA: (
2622cdf0e10cSrcweir // LLA: hRtlTestResult,
2623cdf0e10cSrcweir // LLA: lastRes,
2624cdf0e10cSrcweir // LLA: arrTestCase[i].comments,
2625cdf0e10cSrcweir // LLA: createName( pMeth, "valueof_double", i)
2626cdf0e10cSrcweir // LLA: );
2627cdf0e10cSrcweir // LLA:
2628cdf0e10cSrcweir // LLA: res &= lastRes;
2629cdf0e10cSrcweir // LLA:
2630cdf0e10cSrcweir // LLA: }
2631cdf0e10cSrcweir // LLA:
2632cdf0e10cSrcweir // LLA: return ( res );
2633cdf0e10cSrcweir // LLA: }
2634cdf0e10cSrcweir
2635cdf0e10cSrcweir
2636cdf0e10cSrcweir //------------------------------------------------------------------------
2637cdf0e10cSrcweir // testing the method valueOf( double f ) for negative value
2638cdf0e10cSrcweir //------------------------------------------------------------------------
2639cdf0e10cSrcweir // LLA: sal_Bool SAL_CALL test_rtl_OString_valueOf_Double_Negative(
2640cdf0e10cSrcweir // LLA: hTestResult hRtlTestResult )
2641cdf0e10cSrcweir // LLA: {
2642cdf0e10cSrcweir // LLA: sal_Char methName[MAXBUFLENGTH];
2643cdf0e10cSrcweir // LLA: sal_Char* pMeth =methName;
2644cdf0e10cSrcweir // LLA:
2645cdf0e10cSrcweir // LLA: typedef struct TestCase
2646cdf0e10cSrcweir // LLA: {
2647cdf0e10cSrcweir // LLA: sal_Char* comments;
2648cdf0e10cSrcweir // LLA: double input1;
2649cdf0e10cSrcweir // LLA: OString* expVal;
2650cdf0e10cSrcweir // LLA:
2651cdf0e10cSrcweir // LLA: ~TestCase() {delete expVal;}
2652cdf0e10cSrcweir // LLA: } TestCase;
2653cdf0e10cSrcweir // LLA:
2654cdf0e10cSrcweir // LLA: TestCase arrTestCase[] =
2655cdf0e10cSrcweir // LLA: {
2656cdf0e10cSrcweir // LLA: {"-3.0", -3.0, new OString("-3.0")},
2657cdf0e10cSrcweir // LLA: {"-3.5", -3.5, new OString("-3.5")},
2658cdf0e10cSrcweir // LLA: {"-3.0625", -3.0625, new OString("-3.0625")},
2659cdf0e10cSrcweir // LLA: {"-3.1415926535", -3.1415926535, new OString("-3.1415926535")},
2660cdf0e10cSrcweir // LLA: {"-3.1415926535897931", -3.141592653589793,
2661cdf0e10cSrcweir // LLA: new OString("-3.1415926535897931")},
2662cdf0e10cSrcweir // LLA: {"-3.1415926535897931", -3.1415926535897932,
2663cdf0e10cSrcweir // LLA: new OString("-3.1415926535897931")},
2664cdf0e10cSrcweir // LLA: {"-3.1415926535897931", -3.14159265358979323,
2665cdf0e10cSrcweir // LLA: new OString("-3.1415926535897931")},
2666cdf0e10cSrcweir // LLA: {"-3.1415926535897931", -3.141592653589793238462643,
2667cdf0e10cSrcweir // LLA: new OString("-3.1415926535897931")}
2668cdf0e10cSrcweir // LLA: };
2669cdf0e10cSrcweir // LLA:
2670cdf0e10cSrcweir // LLA: sal_Bool res = sal_True;
2671cdf0e10cSrcweir // LLA: sal_Int32 i;
2672cdf0e10cSrcweir // LLA:
2673cdf0e10cSrcweir // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
2674cdf0e10cSrcweir // LLA: {
2675cdf0e10cSrcweir // LLA: ::rtl::OString aStr1;
2676cdf0e10cSrcweir // LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 );
2677cdf0e10cSrcweir // LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0);
2678cdf0e10cSrcweir // LLA:
2679cdf0e10cSrcweir // LLA: c_rtl_tres_state
2680cdf0e10cSrcweir // LLA: (
2681cdf0e10cSrcweir // LLA: hRtlTestResult,
2682cdf0e10cSrcweir // LLA: lastRes,
2683cdf0e10cSrcweir // LLA: arrTestCase[i].comments,
2684cdf0e10cSrcweir // LLA: createName( pMeth, "valueof_nagative double", i)
2685cdf0e10cSrcweir // LLA: );
2686cdf0e10cSrcweir // LLA:
2687cdf0e10cSrcweir // LLA: res &= lastRes;
2688cdf0e10cSrcweir // LLA:
2689cdf0e10cSrcweir // LLA: }
2690cdf0e10cSrcweir // LLA:
2691cdf0e10cSrcweir // LLA: return ( res );
2692cdf0e10cSrcweir // LLA: }
2693cdf0e10cSrcweir
2694cdf0e10cSrcweir //------------------------------------------------------------------------
2695cdf0e10cSrcweir // testing the method valueOf()
2696cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_valueOf(hTestResult hRtlTestResult)2697cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_valueOf(
2698cdf0e10cSrcweir hTestResult hRtlTestResult )
2699cdf0e10cSrcweir {
2700cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "valueOf");
2701cdf0e10cSrcweir sal_Bool bTState = test_rtl_OString_valueOf_sal_Bool( hRtlTestResult );
2702cdf0e10cSrcweir
2703cdf0e10cSrcweir bTState &= test_rtl_OString_valueOf_sal_Char( hRtlTestResult );
2704cdf0e10cSrcweir
2705cdf0e10cSrcweir bTState &= test_rtl_OString_valueOf_Int32( hRtlTestResult );
2706cdf0e10cSrcweir bTState &= test_rtl_OString_valueOf_Int32_Bounderies( hRtlTestResult );
2707cdf0e10cSrcweir bTState &= test_rtl_OString_valueOf_Int32_Negative( hRtlTestResult );
2708cdf0e10cSrcweir bTState &= test_rtl_OString_valueOf_Int32_WrongRadix( hRtlTestResult );
2709cdf0e10cSrcweir bTState &= test_rtl_OString_valueOf_Int32_SmallestNegativeValue(
2710cdf0e10cSrcweir hRtlTestResult );
2711cdf0e10cSrcweir
2712cdf0e10cSrcweir bTState &= test_rtl_OString_valueOf_Int64( hRtlTestResult );
2713cdf0e10cSrcweir bTState &= test_rtl_OString_valueOf_Int64_Bounderies( hRtlTestResult );
2714cdf0e10cSrcweir bTState &= test_rtl_OString_valueOf_Int64_Negative( hRtlTestResult );
2715cdf0e10cSrcweir bTState &= test_rtl_OString_valueOf_Int64_WrongRadix( hRtlTestResult );
2716cdf0e10cSrcweir bTState &= test_rtl_OString_valueOf_Int64_SmallestNegativeValue(
2717cdf0e10cSrcweir hRtlTestResult );
2718cdf0e10cSrcweir
2719cdf0e10cSrcweir // LLA: the tests for valueOf(float) and valueOf(double) are moved to file
2720cdf0e10cSrcweir // sal/qa/rtl/ostring/rtl_OString2.cxx
2721cdf0e10cSrcweir
2722cdf0e10cSrcweir // LLA: bTState &= test_rtl_OString_valueOf_float( hRtlTestResult );
2723cdf0e10cSrcweir // LLA: bTState &= test_rtl_OString_valueOf_Float_Negative( hRtlTestResult );
2724cdf0e10cSrcweir
2725cdf0e10cSrcweir // LLA: bTState &= test_rtl_OString_valueOf_double( hRtlTestResult );
2726cdf0e10cSrcweir // LLA: bTState &= test_rtl_OString_valueOf_Double_Negative( hRtlTestResult );
2727cdf0e10cSrcweir
2728cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "valueOf");
2729cdf0e10cSrcweir // return ( bTState );
2730cdf0e10cSrcweir }
2731cdf0e10cSrcweir
2732cdf0e10cSrcweir
2733cdf0e10cSrcweir //------------------------------------------------------------------------
2734cdf0e10cSrcweir // testing the method toChar()
2735cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_toChar(hTestResult hRtlTestResult)2736cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_toChar(
2737cdf0e10cSrcweir hTestResult hRtlTestResult )
2738cdf0e10cSrcweir {
2739cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
2740cdf0e10cSrcweir sal_Char* pMeth = methName;
2741cdf0e10cSrcweir
2742cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "toChar");
2743cdf0e10cSrcweir typedef struct TestCase
2744cdf0e10cSrcweir {
2745cdf0e10cSrcweir sal_Char* comments;
2746cdf0e10cSrcweir sal_Char expVal;
2747cdf0e10cSrcweir OString* input1;
2748cdf0e10cSrcweir ~TestCase() {delete input1;}
2749cdf0e10cSrcweir } TestCase;
2750cdf0e10cSrcweir
2751cdf0e10cSrcweir
2752cdf0e10cSrcweir TestCase arrTestCase[] =
2753cdf0e10cSrcweir {
2754cdf0e10cSrcweir {"A", 'A', new OString("A")},
2755cdf0e10cSrcweir {"a", 'a', new OString("a")},
2756cdf0e10cSrcweir {"0", '0',new OString("0")},
2757cdf0e10cSrcweir {"-", '-',new OString("-")},
2758cdf0e10cSrcweir {"_", '_',new OString("_")},
2759cdf0e10cSrcweir
2760cdf0e10cSrcweir // TODO: may be UTF-8 values
2761cdf0e10cSrcweir // {"�0�6", '�0�6',new OString("�0�6")},
2762cdf0e10cSrcweir // { "�0�7", '�0�7',new OString("�0�7")},
2763cdf0e10cSrcweir // {"�0�0", '�0�0',new OString("�0�0")},
2764cdf0e10cSrcweir // {"�0�6", '�0�6',new OString("�0�6")},
2765cdf0e10cSrcweir {"\n", '\n',new OString("\n")},
2766cdf0e10cSrcweir {"\'", '\'',new OString("\'")},
2767cdf0e10cSrcweir {"\"", '\"',new OString("\"")},
2768cdf0e10cSrcweir {"\0", '\0',new OString("\0")},
2769cdf0e10cSrcweir {"", '\0',new OString("")},
2770cdf0e10cSrcweir {"Sun Microsystems", 'S', new OString(kTestStr1)}
2771cdf0e10cSrcweir };
2772cdf0e10cSrcweir
2773cdf0e10cSrcweir
2774cdf0e10cSrcweir // sal_Bool res = sal_True;
2775cdf0e10cSrcweir sal_uInt32 i;
2776cdf0e10cSrcweir
2777cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++ )
2778cdf0e10cSrcweir {
2779cdf0e10cSrcweir sal_Char strRes = arrTestCase[i].input1->toChar();
2780cdf0e10cSrcweir sal_Bool lastRes = ( strRes == arrTestCase[i].expVal );
2781cdf0e10cSrcweir
2782cdf0e10cSrcweir char com[MAXBUFLENGTH];
2783cdf0e10cSrcweir com[0] = '\'';
2784cdf0e10cSrcweir cpynstr(com + 1, (*arrTestCase[i].input1), MAXBUFLENGTH);
2785cdf0e10cSrcweir int length = AStringLen( (*arrTestCase[i].input1) );
2786cdf0e10cSrcweir com[length + 1] = '\'';
2787cdf0e10cSrcweir com[length + 2] = 0;
2788cdf0e10cSrcweir
2789cdf0e10cSrcweir c_rtl_tres_state
2790cdf0e10cSrcweir (
2791cdf0e10cSrcweir hRtlTestResult,
2792cdf0e10cSrcweir lastRes,
2793cdf0e10cSrcweir com,
2794cdf0e10cSrcweir createName( pMeth, "toChar", i )
2795cdf0e10cSrcweir );
2796cdf0e10cSrcweir
2797cdf0e10cSrcweir }
2798cdf0e10cSrcweir
2799cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "toChar");
2800cdf0e10cSrcweir // return (res);
2801cdf0e10cSrcweir }
2802cdf0e10cSrcweir
2803cdf0e10cSrcweir
2804cdf0e10cSrcweir //------------------------------------------------------------------------
2805cdf0e10cSrcweir // testing the method toFloat()
2806cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_toFloat(hTestResult hRtlTestResult)2807cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_toFloat(
2808cdf0e10cSrcweir hTestResult hRtlTestResult )
2809cdf0e10cSrcweir {
2810cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
2811cdf0e10cSrcweir sal_Char* pMeth = methName;
2812cdf0e10cSrcweir
2813cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "toFloat");
2814cdf0e10cSrcweir typedef struct TestCase
2815cdf0e10cSrcweir {
2816cdf0e10cSrcweir float expVal;
2817cdf0e10cSrcweir OString* input1;
2818cdf0e10cSrcweir float m_nPrecision;
2819cdf0e10cSrcweir ~TestCase() {delete input1;}
2820cdf0e10cSrcweir } TestCase;
2821cdf0e10cSrcweir
2822cdf0e10cSrcweir
2823cdf0e10cSrcweir TestCase arrTestCase[] =
2824cdf0e10cSrcweir {
2825cdf0e10cSrcweir {3.0f, new OString("3"), 3e-7f},
2826cdf0e10cSrcweir {3.1f, new OString("3.1"), 3e-7f},
2827cdf0e10cSrcweir {3.1415f, new OString("3.1415"), 3e-7f},
2828cdf0e10cSrcweir {3.14159f, new OString("3.14159"), 3e-7f},
2829cdf0e10cSrcweir {3.141592f, new OString("3.141592"), 3e-7f},
2830cdf0e10cSrcweir {3.1415926f, new OString("3.1415926"), 3e-7f},
2831cdf0e10cSrcweir {3.14159265f, new OString("3.14159265"), 3e-7f},
2832cdf0e10cSrcweir {3.141592653589793238462643f,
2833cdf0e10cSrcweir new OString("3.141592653589793238462643"), 3e-7f},
2834cdf0e10cSrcweir {6.5822e-16f, new OString("6.5822e-16"), 6e-16f * 1e-7f},
2835cdf0e10cSrcweir {9.1096e-31f, new OString("9.1096e-31"), 9e-31f * 1e-7f},
2836cdf0e10cSrcweir {2.997925e8f, new OString("2.997925e8"), 3e8f * 1e-7f},
2837cdf0e10cSrcweir {6.241e18f, new OString("6.241e18"), 6e18f * 1e-7f},
2838cdf0e10cSrcweir {3.1f, new OString("03.1"), 3e-7f},
2839cdf0e10cSrcweir {3.1f, new OString(" 3.1"), 3e-7f},
2840cdf0e10cSrcweir {-3.1f, new OString("-3.1"), 3e-7f},
2841cdf0e10cSrcweir {3.1f, new OString("+3.1"), 3e-7f},
2842cdf0e10cSrcweir {0.0f, new OString("-0.0"), 1e-7f}
2843cdf0e10cSrcweir };
2844cdf0e10cSrcweir
2845cdf0e10cSrcweir
2846cdf0e10cSrcweir // sal_Bool res = sal_True;
2847cdf0e10cSrcweir sal_uInt32 i;
2848cdf0e10cSrcweir
2849cdf0e10cSrcweir t_print("sizeof(float)=%d, sizeof(double)=%d\n", sizeof(float), sizeof(double));
2850cdf0e10cSrcweir
2851cdf0e10cSrcweir for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++ )
2852cdf0e10cSrcweir {
2853cdf0e10cSrcweir float fA = arrTestCase[i].input1->toFloat();
2854cdf0e10cSrcweir float fB = arrTestCase[i].expVal;
2855cdf0e10cSrcweir float fPrec = arrTestCase[i].m_nPrecision;
2856cdf0e10cSrcweir float fResult = (float) fabs(fA - fB);
2857cdf0e10cSrcweir // t_print("float result: A:(%.9f) B:(%.9f) fabs(A-B):%E\n", fA, fB, fResult);
2858cdf0e10cSrcweir t_print("float result: A:(%E) B:(%E) fabs(A-B):%E\n", fA, fB, (float) fResult);
2859cdf0e10cSrcweir sal_Bool lastRes = ( fResult <= fPrec );
2860cdf0e10cSrcweir
2861cdf0e10cSrcweir char com[MAXBUFLENGTH];
2862cdf0e10cSrcweir com[0] = '\'';
2863cdf0e10cSrcweir cpynstr(com + 1, (*arrTestCase[i].input1), MAXBUFLENGTH);
2864cdf0e10cSrcweir int length = AStringLen( (*arrTestCase[i].input1) );
2865cdf0e10cSrcweir com[length + 1] = '\'';
2866cdf0e10cSrcweir com[length + 2] = 0;
2867cdf0e10cSrcweir
2868cdf0e10cSrcweir c_rtl_tres_state
2869cdf0e10cSrcweir (
2870cdf0e10cSrcweir hRtlTestResult,
2871cdf0e10cSrcweir lastRes,
2872cdf0e10cSrcweir com,
2873cdf0e10cSrcweir createName( pMeth, "toFloat", i )
2874cdf0e10cSrcweir );
2875cdf0e10cSrcweir
2876cdf0e10cSrcweir }
2877cdf0e10cSrcweir
2878cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "toFloat");
2879cdf0e10cSrcweir // return (res);
2880cdf0e10cSrcweir }
2881cdf0e10cSrcweir
2882cdf0e10cSrcweir
2883cdf0e10cSrcweir //------------------------------------------------------------------------
2884cdf0e10cSrcweir // testing the method toDouble()
2885cdf0e10cSrcweir //------------------------------------------------------------------------
2886cdf0e10cSrcweir // LLA: extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_toDouble(
2887cdf0e10cSrcweir // LLA: hTestResult hRtlTestResult )
2888cdf0e10cSrcweir // LLA: {
2889cdf0e10cSrcweir // LLA: sal_Char methName[MAXBUFLENGTH];
2890cdf0e10cSrcweir // LLA: sal_Char* pMeth = methName;
2891cdf0e10cSrcweir // LLA:
2892cdf0e10cSrcweir // LLA: c_rtl_tres_state_start(hRtlTestResult, "toDouble");
2893cdf0e10cSrcweir // LLA: typedef struct TestCase
2894cdf0e10cSrcweir // LLA: {
2895cdf0e10cSrcweir // LLA: double expVal;
2896cdf0e10cSrcweir // LLA: double expDiff;
2897cdf0e10cSrcweir // LLA: OString* input1;
2898cdf0e10cSrcweir // LLA: ~TestCase() {delete input1;}
2899cdf0e10cSrcweir // LLA: } TestCase;
2900cdf0e10cSrcweir // LLA:
2901cdf0e10cSrcweir // LLA:
2902cdf0e10cSrcweir // LLA: TestCase arrTestCase[] =
2903cdf0e10cSrcweir // LLA: {
2904cdf0e10cSrcweir // LLA: {3.0, 1e-35, new OString("3")},
2905cdf0e10cSrcweir // LLA: {3.1, 1e-2, new OString("3.1")},
2906cdf0e10cSrcweir // LLA: {3.1415, 1e-5, new OString("3.1415")},
2907cdf0e10cSrcweir // LLA: {3.1415926535, 1e-11, new OString("3.1415926535")},
2908cdf0e10cSrcweir // LLA: {3.141592653589793, 1e-15,
2909cdf0e10cSrcweir // LLA: new OString("3.141592653589793")},
2910cdf0e10cSrcweir // LLA: {3.1415926535897932, 1e-16,
2911cdf0e10cSrcweir // LLA: new OString("3.1415926535897932")},
2912cdf0e10cSrcweir // LLA: {3.14159265358979323, 1e-15,
2913cdf0e10cSrcweir // LLA: new OString("3.14159265358979323")},
2914cdf0e10cSrcweir // LLA: {3.141592653589793238462643, 1e-15,
2915cdf0e10cSrcweir // LLA: new OString("3.141592653589793238462643")},
2916cdf0e10cSrcweir // LLA: {6.5822e-16, 1e-20, new OString("6.5822e-16")},
2917cdf0e10cSrcweir // LLA: {9.1096e-31, 1e-35, new OString("9.1096e-31")},
2918cdf0e10cSrcweir // LLA: {2.997925e8, 10, new OString("2.997925e8")},
2919cdf0e10cSrcweir // LLA: {6.241e18, 100, new OString("6.241e18")},
2920cdf0e10cSrcweir // LLA: {1.7e-308, 1e-35, new OString("1.7e-308")},
2921cdf0e10cSrcweir // LLA: {1.7e+308, 100, new OString("1.7e+308")},
2922cdf0e10cSrcweir // LLA: {3.1, 1e-2, new OString("03.1")},
2923cdf0e10cSrcweir // LLA: {3.1, 1e-2, new OString(" 3.1")},
2924cdf0e10cSrcweir // LLA: {-3.1, 1e-2, new OString("-3.1")},
2925cdf0e10cSrcweir // LLA: {3.1, 1e-2, new OString("+3.1")},
2926cdf0e10cSrcweir // LLA: {0.0, 1e-2, new OString("-0.0")}
2927cdf0e10cSrcweir // LLA: };
2928cdf0e10cSrcweir // LLA:
2929cdf0e10cSrcweir // LLA: sal_Bool res = sal_True;
2930cdf0e10cSrcweir // LLA: sal_Int32 i;
2931cdf0e10cSrcweir // LLA:
2932cdf0e10cSrcweir // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++ )
2933cdf0e10cSrcweir // LLA: {
2934cdf0e10cSrcweir // LLA: double dRes = arrTestCase[i].input1->toDouble();
2935cdf0e10cSrcweir // LLA: double dErg = dRes - arrTestCase[i].expVal ;
2936cdf0e10cSrcweir // LLA: double dComp = fabs( dErg );
2937cdf0e10cSrcweir // LLA: sal_Bool lastRes = ( dComp <= arrTestCase[i].expDiff );
2938cdf0e10cSrcweir // LLA:
2939cdf0e10cSrcweir // LLA: char com[MAXBUFLENGTH];
2940cdf0e10cSrcweir // LLA: com[0] = '\'';
2941cdf0e10cSrcweir // LLA: cpynstr(com + 1, (*arrTestCase[i].input1), MAXBUFLENGTH);
2942cdf0e10cSrcweir // LLA: int length = AStringLen( (*arrTestCase[i].input1) );
2943cdf0e10cSrcweir // LLA: com[length + 1] = '\'';
2944cdf0e10cSrcweir // LLA: com[length + 2] = 0;
2945cdf0e10cSrcweir // LLA:
2946cdf0e10cSrcweir // LLA: c_rtl_tres_state
2947cdf0e10cSrcweir // LLA: (
2948cdf0e10cSrcweir // LLA: hRtlTestResult,
2949cdf0e10cSrcweir // LLA: lastRes,
2950cdf0e10cSrcweir // LLA: com,
2951cdf0e10cSrcweir // LLA: createName( pMeth, "toDouble", i )
2952cdf0e10cSrcweir // LLA: );
2953cdf0e10cSrcweir // LLA:
2954cdf0e10cSrcweir // LLA: }
2955cdf0e10cSrcweir // LLA:
2956cdf0e10cSrcweir // LLA: c_rtl_tres_state_end(hRtlTestResult, "toDouble");
2957cdf0e10cSrcweir // LLA: // return (res);
2958cdf0e10cSrcweir // LLA: }
2959cdf0e10cSrcweir
2960cdf0e10cSrcweir //------------------------------------------------------------------------
2961cdf0e10cSrcweir // testing the method toBoolean()
2962cdf0e10cSrcweir //------------------------------------------------------------------------
2963cdf0e10cSrcweir
test_rtl_OString_toBoolean(hTestResult hRtlTestResult)2964cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_toBoolean(
2965cdf0e10cSrcweir hTestResult hRtlTestResult)
2966cdf0e10cSrcweir {
2967cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
2968cdf0e10cSrcweir sal_Char* pMeth = methName;
2969cdf0e10cSrcweir
2970cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "toBoolean");
2971cdf0e10cSrcweir typedef struct TestCase
2972cdf0e10cSrcweir {
2973cdf0e10cSrcweir sal_Char* comments;
2974cdf0e10cSrcweir sal_Bool expVal;
2975cdf0e10cSrcweir OString* input;
2976cdf0e10cSrcweir
2977cdf0e10cSrcweir } TestCase;
2978cdf0e10cSrcweir
2979cdf0e10cSrcweir TestCase arrTestCase[]={
2980cdf0e10cSrcweir
2981cdf0e10cSrcweir {"expected true", sal_True, new OString("True")},
2982cdf0e10cSrcweir {"expected false", sal_False, new OString("False")},
2983cdf0e10cSrcweir {"expected true", sal_True, new OString("1")}
2984cdf0e10cSrcweir };
2985cdf0e10cSrcweir
2986cdf0e10cSrcweir
2987cdf0e10cSrcweir sal_Bool res = sal_True;
2988cdf0e10cSrcweir sal_uInt32 i;
2989cdf0e10cSrcweir
2990cdf0e10cSrcweir for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
2991cdf0e10cSrcweir {
2992cdf0e10cSrcweir sal_Bool bRes = arrTestCase[i].input->toBoolean();
2993cdf0e10cSrcweir sal_Bool lastRes = (bRes == arrTestCase[i].expVal);
2994cdf0e10cSrcweir c_rtl_tres_state
2995cdf0e10cSrcweir (
2996cdf0e10cSrcweir hRtlTestResult,
2997cdf0e10cSrcweir lastRes,
2998cdf0e10cSrcweir arrTestCase[i].comments,
2999cdf0e10cSrcweir createName( pMeth, "toBoolean", i )
3000cdf0e10cSrcweir
3001cdf0e10cSrcweir );
3002cdf0e10cSrcweir res &= lastRes;
3003cdf0e10cSrcweir }
3004cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "toBoolean");
3005cdf0e10cSrcweir // return ( res );
3006cdf0e10cSrcweir }
3007cdf0e10cSrcweir
3008cdf0e10cSrcweir
3009cdf0e10cSrcweir
3010cdf0e10cSrcweir //------------------------------------------------------------------------
3011cdf0e10cSrcweir // testing the method toInt32( sal_Int16 radix = 2,8,10,16,36 )
3012cdf0e10cSrcweir //------------------------------------------------------------------------
test_toInt32(int num,const sal_Char ** in,const sal_Int32 * expVal,sal_Int16 radix,hTestResult hRtlTestResult)3013cdf0e10cSrcweir sal_Bool test_toInt32( int num, const sal_Char** in,
3014cdf0e10cSrcweir const sal_Int32 *expVal,sal_Int16 radix, hTestResult hRtlTestResult )
3015cdf0e10cSrcweir {
3016cdf0e10cSrcweir sal_Bool res = sal_True;
3017cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
3018cdf0e10cSrcweir sal_Char* pMeth = methName;
3019cdf0e10cSrcweir sal_Int32 i;
3020cdf0e10cSrcweir
3021cdf0e10cSrcweir for( i = 0; i < num; i++ )
3022cdf0e10cSrcweir {
3023cdf0e10cSrcweir OString str(in[i]);
3024cdf0e10cSrcweir sal_Int32 intRes = str.toInt32(radix);
3025cdf0e10cSrcweir sal_Bool lastRes = (intRes == expVal[i]);
3026cdf0e10cSrcweir
3027cdf0e10cSrcweir char buf[MAXBUFLENGTH];
3028cdf0e10cSrcweir buf[0] = '\'';
3029cdf0e10cSrcweir cpynstr( buf + 1, in[i], MAXBUFLENGTH );
3030cdf0e10cSrcweir int length = AStringLen( in[i] );
3031cdf0e10cSrcweir buf[length + 1] = '\'';
3032cdf0e10cSrcweir buf[length + 2] = 0;
3033cdf0e10cSrcweir
3034cdf0e10cSrcweir c_rtl_tres_state
3035cdf0e10cSrcweir (
3036cdf0e10cSrcweir hRtlTestResult,
3037cdf0e10cSrcweir lastRes,
3038cdf0e10cSrcweir buf,
3039cdf0e10cSrcweir createName( pMeth,"toInt32", i )
3040cdf0e10cSrcweir );
3041cdf0e10cSrcweir
3042cdf0e10cSrcweir res &= lastRes;
3043cdf0e10cSrcweir }
3044cdf0e10cSrcweir
3045cdf0e10cSrcweir return( res );
3046cdf0e10cSrcweir }
3047cdf0e10cSrcweir
test_rtl_OString_toInt32_wrongRadix(hTestResult hRtlTestResult)3048cdf0e10cSrcweir sal_Bool SAL_CALL test_rtl_OString_toInt32_wrongRadix(
3049cdf0e10cSrcweir hTestResult hRtlTestResult )
3050cdf0e10cSrcweir {
3051cdf0e10cSrcweir ::rtl::OString str("0");
3052cdf0e10cSrcweir
3053cdf0e10cSrcweir sal_Int32 iRes = str.toInt32(-1);
3054cdf0e10cSrcweir
3055cdf0e10cSrcweir return
3056cdf0e10cSrcweir (
3057cdf0e10cSrcweir c_rtl_tres_state
3058cdf0e10cSrcweir (
3059cdf0e10cSrcweir hRtlTestResult,
3060cdf0e10cSrcweir iRes == 0,
3061cdf0e10cSrcweir "wrong radix -1",
3062cdf0e10cSrcweir "toInt32( 0, wrong radix -1 )"
3063cdf0e10cSrcweir )
3064cdf0e10cSrcweir );
3065cdf0e10cSrcweir }
3066cdf0e10cSrcweir
test_rtl_OString_toInt32(hTestResult hRtlTestResult)3067cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_toInt32(
3068cdf0e10cSrcweir hTestResult hRtlTestResult )
3069cdf0e10cSrcweir {
3070cdf0e10cSrcweir sal_Int32 expValues[kBase36NumsCount];
3071cdf0e10cSrcweir sal_Int32 i;
3072cdf0e10cSrcweir
3073cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "toInt32");
3074cdf0e10cSrcweir for ( i = 0; i < kBase36NumsCount; i++ )
3075cdf0e10cSrcweir expValues[i] = i;
3076cdf0e10cSrcweir
3077cdf0e10cSrcweir sal_Bool res = c_rtl_tres_state
3078cdf0e10cSrcweir (
3079cdf0e10cSrcweir hRtlTestResult,
3080cdf0e10cSrcweir test_toInt32( kBinaryNumsCount, kBinaryNumsStr,
3081cdf0e10cSrcweir expValues, kRadixBinary, hRtlTestResult ),
3082cdf0e10cSrcweir "kBinaryNumsStr",
3083cdf0e10cSrcweir "toInt32( radix 2 )"
3084cdf0e10cSrcweir );
3085cdf0e10cSrcweir res &= c_rtl_tres_state
3086cdf0e10cSrcweir (
3087cdf0e10cSrcweir hRtlTestResult,
3088cdf0e10cSrcweir test_toInt32( kInt32MaxNumsCount, kBinaryMaxNumsStr,
3089cdf0e10cSrcweir kInt32MaxNums, kRadixBinary, hRtlTestResult ),
3090cdf0e10cSrcweir "kBinaryMaxNumsStr",
3091cdf0e10cSrcweir "toInt32_Boundaries( radix 2 )"
3092cdf0e10cSrcweir );
3093cdf0e10cSrcweir
3094cdf0e10cSrcweir res &= c_rtl_tres_state
3095cdf0e10cSrcweir (
3096cdf0e10cSrcweir hRtlTestResult,
3097cdf0e10cSrcweir test_toInt32( kOctolNumsCount, kOctolNumsStr,
3098cdf0e10cSrcweir expValues, kRadixOctol, hRtlTestResult ),
3099cdf0e10cSrcweir "kOctolNumsStr",
3100cdf0e10cSrcweir "toInt32( radix 8 )"
3101cdf0e10cSrcweir );
3102cdf0e10cSrcweir
3103cdf0e10cSrcweir res &= c_rtl_tres_state
3104cdf0e10cSrcweir (
3105cdf0e10cSrcweir hRtlTestResult,
3106cdf0e10cSrcweir test_toInt32( kInt32MaxNumsCount, kOctolMaxNumsStr,
3107cdf0e10cSrcweir (sal_Int32*)kInt32MaxNums, kRadixOctol, hRtlTestResult ),
3108cdf0e10cSrcweir "kOctolMaxNumsStr",
3109cdf0e10cSrcweir "toInt32_Boundaries( radix 8 )"
3110cdf0e10cSrcweir );
3111cdf0e10cSrcweir
3112cdf0e10cSrcweir res &= c_rtl_tres_state
3113cdf0e10cSrcweir (
3114cdf0e10cSrcweir hRtlTestResult,
3115cdf0e10cSrcweir test_toInt32( kDecimalNumsCount, kDecimalNumsStr, expValues,
3116cdf0e10cSrcweir kRadixDecimal, hRtlTestResult ),
3117cdf0e10cSrcweir "kDecimalNumsStr",
3118cdf0e10cSrcweir "toInt32( radix 10 )"
3119cdf0e10cSrcweir );
3120cdf0e10cSrcweir
3121cdf0e10cSrcweir res &= c_rtl_tres_state
3122cdf0e10cSrcweir (
3123cdf0e10cSrcweir hRtlTestResult,
3124cdf0e10cSrcweir test_toInt32( kInt32MaxNumsCount, kDecimalMaxNumsStr,
3125cdf0e10cSrcweir (sal_Int32*)kInt32MaxNums, kRadixDecimal, hRtlTestResult ),
3126cdf0e10cSrcweir "kDecimalMaxNumsStr",
3127cdf0e10cSrcweir "toInt32_Boundaries( radix 10 )"
3128cdf0e10cSrcweir );
3129cdf0e10cSrcweir
3130cdf0e10cSrcweir res &= c_rtl_tres_state
3131cdf0e10cSrcweir (
3132cdf0e10cSrcweir hRtlTestResult,
3133cdf0e10cSrcweir test_toInt32( kHexDecimalNumsCount, kHexDecimalNumsStr, expValues,
3134cdf0e10cSrcweir kRadixHexdecimal, hRtlTestResult ),
3135cdf0e10cSrcweir "kHexDecimalNumsStr",
3136cdf0e10cSrcweir "toInt32( radix 16 )"
3137cdf0e10cSrcweir );
3138cdf0e10cSrcweir
3139cdf0e10cSrcweir res &= c_rtl_tres_state
3140cdf0e10cSrcweir (
3141cdf0e10cSrcweir hRtlTestResult,
3142cdf0e10cSrcweir test_toInt32( kInt32MaxNumsCount, kHexDecimalMaxNumsStr,
3143cdf0e10cSrcweir (sal_Int32*)kInt32MaxNums, kRadixHexdecimal, hRtlTestResult ),
3144cdf0e10cSrcweir "kHexDecimalMaxNumsStr",
3145cdf0e10cSrcweir "toInt32_Boundaries( radix 16 )"
3146cdf0e10cSrcweir );
3147cdf0e10cSrcweir
3148cdf0e10cSrcweir res &= c_rtl_tres_state
3149cdf0e10cSrcweir (
3150cdf0e10cSrcweir hRtlTestResult,
3151cdf0e10cSrcweir test_toInt32( kBase36NumsCount, kBase36NumsStr, expValues,
3152cdf0e10cSrcweir kRadixBase36, hRtlTestResult ),
3153cdf0e10cSrcweir "kBase36NumsStr",
3154cdf0e10cSrcweir "toInt32( radix 36 )"
3155cdf0e10cSrcweir );
3156cdf0e10cSrcweir
3157cdf0e10cSrcweir res &= c_rtl_tres_state
3158cdf0e10cSrcweir (
3159cdf0e10cSrcweir hRtlTestResult,
3160cdf0e10cSrcweir test_toInt32( kInt32MaxNumsCount, kBase36MaxNumsStr,
3161cdf0e10cSrcweir (sal_Int32*)kInt32MaxNums, kRadixBase36, hRtlTestResult ),
3162cdf0e10cSrcweir "kBase36MaxNumsStr",
3163cdf0e10cSrcweir "toInt32_Boundaries( radix 36 )"
3164cdf0e10cSrcweir );
3165cdf0e10cSrcweir
3166cdf0e10cSrcweir const sal_Int16 nSpecCases = 5;
3167cdf0e10cSrcweir static const sal_Char *spString[nSpecCases] =
3168cdf0e10cSrcweir {
3169cdf0e10cSrcweir "-1",
3170cdf0e10cSrcweir "+1",
3171cdf0e10cSrcweir " 1",
3172cdf0e10cSrcweir " -1",
3173cdf0e10cSrcweir "001"
3174cdf0e10cSrcweir };
3175cdf0e10cSrcweir
3176cdf0e10cSrcweir sal_Int32 expSpecVal[nSpecCases] =
3177cdf0e10cSrcweir {
3178cdf0e10cSrcweir -1,
3179cdf0e10cSrcweir 1,
3180cdf0e10cSrcweir 1,
3181cdf0e10cSrcweir -1,
3182cdf0e10cSrcweir 1
3183cdf0e10cSrcweir };
3184cdf0e10cSrcweir
3185cdf0e10cSrcweir res &= c_rtl_tres_state
3186cdf0e10cSrcweir (
3187cdf0e10cSrcweir hRtlTestResult,
3188cdf0e10cSrcweir test_toInt32( nSpecCases, spString, expSpecVal,
3189cdf0e10cSrcweir kRadixDecimal, hRtlTestResult ),
3190cdf0e10cSrcweir "special cases",
3191cdf0e10cSrcweir "toInt32( specialcases )"
3192cdf0e10cSrcweir );
3193cdf0e10cSrcweir
3194cdf0e10cSrcweir res &= test_rtl_OString_toInt32_wrongRadix( hRtlTestResult );
3195cdf0e10cSrcweir
3196cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "toInt32");
3197cdf0e10cSrcweir // return ( res );
3198cdf0e10cSrcweir }
3199cdf0e10cSrcweir
3200cdf0e10cSrcweir //------------------------------------------------------------------------
3201cdf0e10cSrcweir // testing the method toInt64( sal_Int16 radix = 2,8,10,16,36 )
3202cdf0e10cSrcweir //------------------------------------------------------------------------
test_toInt64(int num,const sal_Char ** in,const sal_Int64 * expVal,sal_Int16 radix,hTestResult hRtlTestResult)3203cdf0e10cSrcweir sal_Bool test_toInt64( int num, const sal_Char** in,
3204cdf0e10cSrcweir const sal_Int64 *expVal,sal_Int16 radix, hTestResult hRtlTestResult )
3205cdf0e10cSrcweir {
3206cdf0e10cSrcweir sal_Bool res = sal_True;
3207cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
3208cdf0e10cSrcweir sal_Char* pMeth = methName;
3209cdf0e10cSrcweir sal_Int32 i;
3210cdf0e10cSrcweir
3211cdf0e10cSrcweir for( i = 0; i < num; i++ )
3212cdf0e10cSrcweir {
3213cdf0e10cSrcweir OString str( in[i] );
3214cdf0e10cSrcweir sal_Int64 intRes = str.toInt64( radix );
3215cdf0e10cSrcweir sal_Bool lastRes = ( intRes == expVal[i] );
3216cdf0e10cSrcweir
3217cdf0e10cSrcweir char buf[MAXBUFLENGTH];
3218cdf0e10cSrcweir buf[0] = '\'';
3219cdf0e10cSrcweir cpynstr( buf + 1, in[i], MAXBUFLENGTH );
3220cdf0e10cSrcweir int length = AStringLen(in[i]);
3221cdf0e10cSrcweir buf[length + 1] = '\'';
3222cdf0e10cSrcweir buf[length + 2] = 0;
3223cdf0e10cSrcweir
3224cdf0e10cSrcweir c_rtl_tres_state
3225cdf0e10cSrcweir (
3226cdf0e10cSrcweir hRtlTestResult,
3227cdf0e10cSrcweir lastRes,
3228cdf0e10cSrcweir buf,
3229cdf0e10cSrcweir createName( pMeth, "toInt64", i )
3230cdf0e10cSrcweir );
3231cdf0e10cSrcweir
3232cdf0e10cSrcweir res &= lastRes;
3233cdf0e10cSrcweir }
3234cdf0e10cSrcweir return (res);
3235cdf0e10cSrcweir }
3236cdf0e10cSrcweir
test_rtl_OString_toInt64_wrongRadix(hTestResult hRtlTestResult)3237cdf0e10cSrcweir sal_Bool SAL_CALL test_rtl_OString_toInt64_wrongRadix(
3238cdf0e10cSrcweir hTestResult hRtlTestResult )
3239cdf0e10cSrcweir {
3240cdf0e10cSrcweir ::rtl::OString str("0");
3241cdf0e10cSrcweir
3242cdf0e10cSrcweir sal_Int64 iRes = str.toInt64(-1);
3243cdf0e10cSrcweir
3244cdf0e10cSrcweir return (
3245cdf0e10cSrcweir
3246cdf0e10cSrcweir c_rtl_tres_state
3247cdf0e10cSrcweir ( hRtlTestResult,
3248cdf0e10cSrcweir iRes == 0,
3249cdf0e10cSrcweir "wrong radix -1",
3250cdf0e10cSrcweir "toInt64( wrong radix -1)"
3251cdf0e10cSrcweir )
3252cdf0e10cSrcweir );
3253cdf0e10cSrcweir }
3254cdf0e10cSrcweir
test_rtl_OString_toInt64(hTestResult hRtlTestResult)3255cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_toInt64(
3256cdf0e10cSrcweir hTestResult hRtlTestResult )
3257cdf0e10cSrcweir {
3258cdf0e10cSrcweir sal_Int64 expValues[kBase36NumsCount];
3259cdf0e10cSrcweir sal_Int32 i;
3260cdf0e10cSrcweir
3261cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "toInt64");
3262cdf0e10cSrcweir for (i = 0; i < kBase36NumsCount; expValues[i] = i, i++);
3263cdf0e10cSrcweir
3264cdf0e10cSrcweir sal_Bool res = c_rtl_tres_state
3265cdf0e10cSrcweir (
3266cdf0e10cSrcweir hRtlTestResult,
3267cdf0e10cSrcweir test_toInt64( kBinaryNumsCount, kBinaryNumsStr, expValues,
3268cdf0e10cSrcweir kRadixBinary, hRtlTestResult ),
3269cdf0e10cSrcweir "kBinaryNumsStr",
3270cdf0e10cSrcweir "toInt64( radix 2 )"
3271cdf0e10cSrcweir );
3272cdf0e10cSrcweir
3273cdf0e10cSrcweir res &= c_rtl_tres_state
3274cdf0e10cSrcweir (
3275cdf0e10cSrcweir hRtlTestResult,
3276cdf0e10cSrcweir test_toInt64( kInt32MaxNumsCount, kBinaryMaxNumsStr,
3277cdf0e10cSrcweir (sal_Int64*)kInt64MaxNums, kRadixBinary, hRtlTestResult ),
3278cdf0e10cSrcweir "kBinaryMaxNumsStr",
3279cdf0e10cSrcweir "toInt64_Boundaries( radix 2 )"
3280cdf0e10cSrcweir );
3281cdf0e10cSrcweir
3282cdf0e10cSrcweir res &= c_rtl_tres_state
3283cdf0e10cSrcweir (
3284cdf0e10cSrcweir hRtlTestResult,
3285cdf0e10cSrcweir test_toInt64( kOctolNumsCount, kOctolNumsStr, expValues,
3286cdf0e10cSrcweir kRadixOctol, hRtlTestResult ),
3287cdf0e10cSrcweir "kOctolNumsStr",
3288cdf0e10cSrcweir "toInt64( radix 8 )"
3289cdf0e10cSrcweir );
3290cdf0e10cSrcweir
3291cdf0e10cSrcweir res &= c_rtl_tres_state
3292cdf0e10cSrcweir (
3293cdf0e10cSrcweir hRtlTestResult,
3294cdf0e10cSrcweir test_toInt64( kInt32MaxNumsCount, kOctolMaxNumsStr,
3295cdf0e10cSrcweir (sal_Int64*)kInt64MaxNums, kRadixOctol, hRtlTestResult ),
3296cdf0e10cSrcweir "kOctolMaxNumsStr",
3297cdf0e10cSrcweir "toInt64_Boundaries( radix 8 )"
3298cdf0e10cSrcweir );
3299cdf0e10cSrcweir
3300cdf0e10cSrcweir res &= c_rtl_tres_state
3301cdf0e10cSrcweir (
3302cdf0e10cSrcweir hRtlTestResult,
3303cdf0e10cSrcweir test_toInt64( kDecimalNumsCount, kDecimalNumsStr, expValues,
3304cdf0e10cSrcweir kRadixDecimal, hRtlTestResult ),
3305cdf0e10cSrcweir "kDecimalNumsStr",
3306cdf0e10cSrcweir "toInt64( radix 10 )"
3307cdf0e10cSrcweir );
3308cdf0e10cSrcweir
3309cdf0e10cSrcweir res &= c_rtl_tres_state
3310cdf0e10cSrcweir (
3311cdf0e10cSrcweir hRtlTestResult,
3312cdf0e10cSrcweir test_toInt64( kInt32MaxNumsCount, kDecimalMaxNumsStr,
3313cdf0e10cSrcweir (sal_Int64*)kInt64MaxNums, kRadixDecimal, hRtlTestResult ),
3314cdf0e10cSrcweir "kDecimalMaxNumsStr",
3315cdf0e10cSrcweir "toInt64_Boundaries( radix 10 )"
3316cdf0e10cSrcweir );
3317cdf0e10cSrcweir
3318cdf0e10cSrcweir res &= c_rtl_tres_state
3319cdf0e10cSrcweir (
3320cdf0e10cSrcweir hRtlTestResult,
3321cdf0e10cSrcweir test_toInt64( kHexDecimalNumsCount, kHexDecimalNumsStr, expValues,
3322cdf0e10cSrcweir kRadixHexdecimal, hRtlTestResult ),
3323cdf0e10cSrcweir "kHexDecimalNumsStr",
3324cdf0e10cSrcweir "toInt64( radix 16 )"
3325cdf0e10cSrcweir );
3326cdf0e10cSrcweir
3327cdf0e10cSrcweir res &= c_rtl_tres_state
3328cdf0e10cSrcweir (
3329cdf0e10cSrcweir hRtlTestResult,
3330cdf0e10cSrcweir test_toInt64( kInt32MaxNumsCount, kHexDecimalMaxNumsStr,
3331cdf0e10cSrcweir (sal_Int64*)kInt64MaxNums, kRadixHexdecimal, hRtlTestResult ),
3332cdf0e10cSrcweir "kHexDecimalMaxNumsStr",
3333cdf0e10cSrcweir "toInt64_Boundaries( radix 16 )"
3334cdf0e10cSrcweir );
3335cdf0e10cSrcweir
3336cdf0e10cSrcweir res &= c_rtl_tres_state
3337cdf0e10cSrcweir (
3338cdf0e10cSrcweir hRtlTestResult,
3339cdf0e10cSrcweir test_toInt64( kBase36NumsCount, kBase36NumsStr, expValues,
3340cdf0e10cSrcweir kRadixBase36, hRtlTestResult ),
3341cdf0e10cSrcweir "kBase36NumsStr",
3342cdf0e10cSrcweir "toInt64( radix 36 )"
3343cdf0e10cSrcweir );
3344cdf0e10cSrcweir
3345cdf0e10cSrcweir res &= c_rtl_tres_state
3346cdf0e10cSrcweir (
3347cdf0e10cSrcweir hRtlTestResult,
3348cdf0e10cSrcweir test_toInt64( kInt32MaxNumsCount, kBase36MaxNumsStr,
3349cdf0e10cSrcweir (sal_Int64*)kInt64MaxNums, kRadixBase36, hRtlTestResult ),
3350cdf0e10cSrcweir "kBase36MaxNumsStr",
3351cdf0e10cSrcweir "toInt64_Boundaries( radix 36 )"
3352cdf0e10cSrcweir );
3353cdf0e10cSrcweir
3354cdf0e10cSrcweir
3355cdf0e10cSrcweir
3356cdf0e10cSrcweir const sal_Int16 nSpecCases = 5;
3357cdf0e10cSrcweir static const sal_Char *spString[nSpecCases] =
3358cdf0e10cSrcweir {
3359cdf0e10cSrcweir "-1",
3360cdf0e10cSrcweir "+1",
3361cdf0e10cSrcweir " 1",
3362cdf0e10cSrcweir " -1",
3363cdf0e10cSrcweir "001"
3364cdf0e10cSrcweir };
3365cdf0e10cSrcweir
3366cdf0e10cSrcweir sal_Int64 expSpecVal[nSpecCases] =
3367cdf0e10cSrcweir {
3368cdf0e10cSrcweir -1,
3369cdf0e10cSrcweir 1,
3370cdf0e10cSrcweir 1,
3371cdf0e10cSrcweir -1,
3372cdf0e10cSrcweir 1
3373cdf0e10cSrcweir };
3374cdf0e10cSrcweir
3375cdf0e10cSrcweir res &= c_rtl_tres_state
3376cdf0e10cSrcweir (
3377cdf0e10cSrcweir hRtlTestResult,
3378cdf0e10cSrcweir test_toInt64( nSpecCases, spString, expSpecVal,
3379cdf0e10cSrcweir kRadixDecimal, hRtlTestResult ),
3380cdf0e10cSrcweir "special cases",
3381cdf0e10cSrcweir "toInt64( specialcases )"
3382cdf0e10cSrcweir );
3383cdf0e10cSrcweir
3384cdf0e10cSrcweir res &= test_rtl_OString_toInt64_wrongRadix( hRtlTestResult );
3385cdf0e10cSrcweir
3386cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "toInt64");
3387cdf0e10cSrcweir // return (res);
3388cdf0e10cSrcweir }
3389cdf0e10cSrcweir
3390cdf0e10cSrcweir //------------------------------------------------------------------------
3391cdf0e10cSrcweir // testing the method replace( sal_Char oldChar, sal_Char newChar )
3392cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_replace(hTestResult hRtlTestResult)3393cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_replace(
3394cdf0e10cSrcweir hTestResult hRtlTestResult)
3395cdf0e10cSrcweir {
3396cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
3397cdf0e10cSrcweir sal_Char* pMeth = methName;
3398cdf0e10cSrcweir
3399cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "replace");
3400cdf0e10cSrcweir typedef struct TestCase
3401cdf0e10cSrcweir {
3402cdf0e10cSrcweir sal_Char* comments;
3403cdf0e10cSrcweir OString* expVal;
3404cdf0e10cSrcweir OString* input;
3405cdf0e10cSrcweir sal_Char oldChar;
3406cdf0e10cSrcweir sal_Char newChar;
3407cdf0e10cSrcweir
3408cdf0e10cSrcweir ~TestCase() { delete input; delete expVal;}
3409cdf0e10cSrcweir } TestCase;
3410cdf0e10cSrcweir
3411cdf0e10cSrcweir TestCase arrTestCase[]={
3412cdf0e10cSrcweir
3413cdf0e10cSrcweir {"string differs", new OString(kTestStr18),
3414cdf0e10cSrcweir new OString(kTestStr4),'S','s'},
3415cdf0e10cSrcweir {"string differs", new OString(kTestStr19),
3416cdf0e10cSrcweir new OString(kTestStr17),(sal_Char)' ',(sal_Char)'-'},
3417cdf0e10cSrcweir {"same string, no replace ", new OString(kTestStr22),
3418cdf0e10cSrcweir new OString(kTestStr22),'*','8'}
3419cdf0e10cSrcweir };
3420cdf0e10cSrcweir
3421cdf0e10cSrcweir
3422cdf0e10cSrcweir sal_Bool res = sal_True;
3423cdf0e10cSrcweir sal_uInt32 i;
3424cdf0e10cSrcweir
3425cdf0e10cSrcweir for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
3426cdf0e10cSrcweir {
3427cdf0e10cSrcweir ::rtl::OString aStr1;
3428cdf0e10cSrcweir aStr1= arrTestCase[i].input->replace(arrTestCase[i].oldChar,
3429cdf0e10cSrcweir arrTestCase[i].newChar);
3430cdf0e10cSrcweir
3431cdf0e10cSrcweir res &= c_rtl_tres_state
3432cdf0e10cSrcweir (
3433cdf0e10cSrcweir hRtlTestResult,
3434cdf0e10cSrcweir (arrTestCase[i].expVal->compareTo(aStr1) == 0),
3435cdf0e10cSrcweir arrTestCase[i].comments,
3436cdf0e10cSrcweir createName( pMeth, "replace", i )
3437cdf0e10cSrcweir
3438cdf0e10cSrcweir );
3439cdf0e10cSrcweir }
3440cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "replace");
3441cdf0e10cSrcweir // return ( res );
3442cdf0e10cSrcweir }
3443cdf0e10cSrcweir
3444cdf0e10cSrcweir
3445cdf0e10cSrcweir
3446cdf0e10cSrcweir //------------------------------------------------------------------------
3447cdf0e10cSrcweir // testing the method replaceAt( sal_Int32 index, sal_Int32 count,
3448cdf0e10cSrcweir // const OString& newStr )
3449cdf0e10cSrcweir //------------------------------------------------------------------------
test_rtl_OString_replaceAt(hTestResult hRtlTestResult)3450cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_replaceAt(
3451cdf0e10cSrcweir hTestResult hRtlTestResult)
3452cdf0e10cSrcweir {
3453cdf0e10cSrcweir sal_Char methName[MAXBUFLENGTH];
3454cdf0e10cSrcweir sal_Char* pMeth = methName;
3455cdf0e10cSrcweir
3456cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "replaceAt");
3457cdf0e10cSrcweir typedef struct TestCase
3458cdf0e10cSrcweir {
3459cdf0e10cSrcweir sal_Char* comments;
3460cdf0e10cSrcweir OString* expVal;
3461cdf0e10cSrcweir OString* input;
3462cdf0e10cSrcweir OString* newStr;
3463cdf0e10cSrcweir sal_Int32 index;
3464cdf0e10cSrcweir sal_Int32 count;
3465cdf0e10cSrcweir
3466cdf0e10cSrcweir ~TestCase() { delete input; delete expVal; delete newStr;}
3467cdf0e10cSrcweir } TestCase;
3468cdf0e10cSrcweir
3469cdf0e10cSrcweir TestCase arrTestCase[]=
3470cdf0e10cSrcweir {
3471cdf0e10cSrcweir
3472cdf0e10cSrcweir { "string differs", new OString(kTestStr2), new OString(kTestStr22),
3473cdf0e10cSrcweir new OString(kTestStr2), 0, kTestStr22Len },
3474cdf0e10cSrcweir
3475cdf0e10cSrcweir { "larger index", new OString(kTestStr1), new OString(kTestStr7),
3476cdf0e10cSrcweir new OString(kTestStr8), 64, kTestStr8Len },
3477cdf0e10cSrcweir
3478cdf0e10cSrcweir { "larger count", new OString(kTestStr2), new OString(kTestStr22),
3479cdf0e10cSrcweir new OString(kTestStr2),0, 64 },
3480cdf0e10cSrcweir
3481cdf0e10cSrcweir { "navigate index", new OString(kTestStr2), new OString(kTestStr22),
3482cdf0e10cSrcweir new OString(kTestStr2), -64, 64 },
3483cdf0e10cSrcweir
3484cdf0e10cSrcweir { "null string", new OString(""),
3485cdf0e10cSrcweir new OString(kTestStr14),new OString(""), 0, kTestStr14Len }
3486cdf0e10cSrcweir };
3487cdf0e10cSrcweir
3488cdf0e10cSrcweir sal_Bool res = sal_True;
3489cdf0e10cSrcweir sal_uInt32 i;
3490cdf0e10cSrcweir
3491cdf0e10cSrcweir for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
3492cdf0e10cSrcweir {
3493cdf0e10cSrcweir ::rtl::OString aStr1;
3494cdf0e10cSrcweir aStr1= arrTestCase[i].input->replaceAt( arrTestCase[i].index,
3495cdf0e10cSrcweir arrTestCase[i].count, *arrTestCase[i].newStr );
3496cdf0e10cSrcweir
3497cdf0e10cSrcweir sal_Bool lastRes = ( arrTestCase[i].expVal->compareTo(aStr1) == 0 );
3498cdf0e10cSrcweir
3499cdf0e10cSrcweir c_rtl_tres_state
3500cdf0e10cSrcweir (
3501cdf0e10cSrcweir hRtlTestResult,
3502cdf0e10cSrcweir lastRes,
3503cdf0e10cSrcweir arrTestCase[i].comments,
3504cdf0e10cSrcweir createName( pMeth, "replaceAt", i )
3505cdf0e10cSrcweir
3506cdf0e10cSrcweir );
3507cdf0e10cSrcweir res &= lastRes;
3508cdf0e10cSrcweir }
3509cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "replaceAt");
3510cdf0e10cSrcweir // return ( res );
3511cdf0e10cSrcweir }
3512cdf0e10cSrcweir
test_rtl_OString(hTestResult hRtlTestResult)3513cdf0e10cSrcweir extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString( hTestResult hRtlTestResult )
3514cdf0e10cSrcweir {
3515cdf0e10cSrcweir
3516cdf0e10cSrcweir c_rtl_tres_state_start(hRtlTestResult, "rtl_OString" );
3517cdf0e10cSrcweir
3518cdf0e10cSrcweir test_rtl_OString_ctors( hRtlTestResult );
3519cdf0e10cSrcweir test_rtl_OString_getLength( hRtlTestResult );
3520cdf0e10cSrcweir test_rtl_OString_equals( hRtlTestResult );
3521cdf0e10cSrcweir test_rtl_OString_equalsIgnoreAsciiCase( hRtlTestResult );
3522cdf0e10cSrcweir test_rtl_OString_compareTo( hRtlTestResult );
3523cdf0e10cSrcweir test_rtl_OString_op_cmp( hRtlTestResult );
3524cdf0e10cSrcweir test_rtl_OString_op_neq( hRtlTestResult );
3525cdf0e10cSrcweir test_rtl_OString_op_g( hRtlTestResult );
3526cdf0e10cSrcweir test_rtl_OString_op_l( hRtlTestResult );
3527cdf0e10cSrcweir test_rtl_OString_op_ge( hRtlTestResult );
3528cdf0e10cSrcweir test_rtl_OString_op_le( hRtlTestResult );
3529cdf0e10cSrcweir test_rtl_OString_op_eq( hRtlTestResult );
3530cdf0e10cSrcweir test_rtl_OString_op_plus( hRtlTestResult );
3531cdf0e10cSrcweir test_rtl_OString_op_peq( hRtlTestResult );
3532cdf0e10cSrcweir test_rtl_OString_op_cscs( hRtlTestResult );
3533cdf0e10cSrcweir test_rtl_OString_getStr( hRtlTestResult );
3534cdf0e10cSrcweir test_rtl_OString_copy( hRtlTestResult );
3535cdf0e10cSrcweir test_rtl_OString_concat( hRtlTestResult );
3536cdf0e10cSrcweir test_rtl_OString_toAsciiLowerCase( hRtlTestResult );
3537cdf0e10cSrcweir test_rtl_OString_toAsciiUpperCase( hRtlTestResult );
3538cdf0e10cSrcweir test_rtl_OString_trim( hRtlTestResult );
3539cdf0e10cSrcweir test_rtl_OString_valueOf( hRtlTestResult );
3540cdf0e10cSrcweir test_rtl_OString_toChar( hRtlTestResult );
3541cdf0e10cSrcweir test_rtl_OString_toFloat( hRtlTestResult );
3542cdf0e10cSrcweir // LLA: test_rtl_OString_toDouble( hRtlTestResult );
3543cdf0e10cSrcweir test_rtl_OString_toBoolean( hRtlTestResult );
3544cdf0e10cSrcweir test_rtl_OString_toInt32( hRtlTestResult );
3545cdf0e10cSrcweir test_rtl_OString_toInt64( hRtlTestResult );
3546cdf0e10cSrcweir test_rtl_OString_replace( hRtlTestResult );
3547cdf0e10cSrcweir test_rtl_OString_replaceAt( hRtlTestResult );
3548cdf0e10cSrcweir
3549cdf0e10cSrcweir c_rtl_tres_state_end(hRtlTestResult, "rtl_OString");
3550cdf0e10cSrcweir }
3551cdf0e10cSrcweir
3552cdf0e10cSrcweir
3553cdf0e10cSrcweir // -----------------------------------------------------------------------------
RegisterAdditionalFunctions(FktRegFuncPtr _pFunc)3554cdf0e10cSrcweir void RegisterAdditionalFunctions(FktRegFuncPtr _pFunc)
3555cdf0e10cSrcweir {
3556cdf0e10cSrcweir if (_pFunc)
3557cdf0e10cSrcweir {
3558cdf0e10cSrcweir (_pFunc)(&test_rtl_OString, "");
3559cdf0e10cSrcweir
3560cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_ctors, "");
3561cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_getLength, "");
3562cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_equals, "");
3563cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_equalsIgnoreAsciiCase, "");
3564cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_compareTo, "");
3565cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_op_cmp, "");
3566cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_op_neq, "");
3567cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_op_g, "");
3568cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_op_l, "");
3569cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_op_ge, "");
3570cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_op_le, "");
3571cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_op_eq, "");
3572cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_op_plus, "");
3573cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_op_peq, "");
3574cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_op_cscs, "");
3575cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_getStr, "");
3576cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_copy, "");
3577cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_concat, "");
3578cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_toAsciiLowerCase, "");
3579cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_toAsciiUpperCase, "");
3580cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_trim, "");
3581cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_valueOf, "");
3582cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_toChar, "");
3583cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_toFloat, "");
3584cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_toDouble, "");
3585cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_toBoolean, "");
3586cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_toInt32, "");
3587cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_toInt64, "");
3588cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_replace, "");
3589cdf0e10cSrcweir //# (_pFunc)(&test_rtl_OString_replaceAt, "");
3590cdf0e10cSrcweir }
3591cdf0e10cSrcweir }
3592cdf0e10cSrcweir
3593cdf0e10cSrcweir /*
3594cdf0e10cSrcweir D:\local\644\SRX644\sal\qa\rtl_OString.cxx(3559) : error C2664:
3595cdf0e10cSrcweir 'unsigned char (void (__cdecl *)(void *),const char *)'
3596cdf0e10cSrcweir : cannot convert parameter 1 from
3597cdf0e10cSrcweir 'unsigned char (__cdecl *)(void *)' to 'void (__cdecl *)(void *)'
3598cdf0e10cSrcweir
3599cdf0e10cSrcweir This conversion requires a reinterpret_cast, a C-style cast or function-
3600cdf0e10cSrcweir style cast
3601cdf0e10cSrcweir */
3602