1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rtl_OString.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sal.hxx"
36 #include <sal/types.h>
39 // #ifndef _RTL_TRES_H_
40 // #include <rtl/tres.h>
43 #include <testshl/tresstatewrapper.hxx>
45 #ifndef _RTL_STRING_HXX_
46 #include <rtl/string.hxx>
49 #ifndef _RTL_STRING_CONST_H_
50 #include <rtl_String_Const.h>
53 #ifndef _RTL_STRING_UTILS_HXX_
54 #include <rtl_String_Utils.hxx>
56 #include <rtl/ustring.h>
60 //------------------------------------------------------------------------
62 //------------------------------------------------------------------------
63 const int MAXBUFLENGTH
= 255;
64 //------------------------------------------------------------------------
66 //------------------------------------------------------------------------
72 (void)input1StrDefault
;
73 (void)input1StrNormal
;
74 (void)input1StrLastDefault
;
75 (void)input1StrLastNormal
;
79 //------------------------------------------------------------------------
80 // testing constructors
81 //------------------------------------------------------------------------
82 static sal_Bool
test_rtl_OString_ctor_001( hTestResult hRtlTestResult
)
85 rtl_String
* pData
= aStr
.pData
;
95 "New OString containing no characters",
101 //------------------------------------------------------------------------
103 static sal_Bool SAL_CALL
test_rtl_OString_ctor_002(
104 hTestResult hRtlTestResult
)
106 ::rtl::OString
aStr(kTestStr1
);
107 rtl_String
* pData
= aStr
.pData
;
114 pData
->refCount
== 1 &&
115 pData
->length
== kTestStr1Len
&&
116 cmpstr( (const sal_Char
*)pData
->buffer
, kTestStr1
, kTestStr1Len
),
117 "New OString from a character buffer array",
122 //------------------------------------------------------------------------
124 static sal_Bool SAL_CALL
test_rtl_OString_ctor_003(
125 hTestResult hRtlTestResult
)
127 ::rtl::OString
aStr(kTestStr2
, kTestStr1Len
);
128 rtl_String
* pData
= aStr
.pData
;
135 pData
->refCount
== 1 &&
136 pData
->length
== kTestStr1Len
&&
137 cmpstr( (const sal_Char
*)pData
->buffer
, kTestStr2
, kTestStr1Len
),
138 "New OString from the first n chars of ascii string",
144 //------------------------------------------------------------------------
146 static sal_Bool SAL_CALL
test_rtl_OString_ctor_004(
147 hTestResult hRtlTestResult
)
149 ::rtl::OString
aStr1(kTestStr1
);
150 ::rtl::OString
aStr2(aStr1
);
151 rtl_String
* pData1
= aStr1
.pData
;
152 rtl_String
* pData2
= aStr2
.pData
;
159 pData1
->refCount
== pData2
->refCount
&&
160 pData1
->length
== kTestStr1Len
&&
161 pData1
->buffer
== pData2
->buffer
,
162 "New OString from an OString",
167 //------------------------------------------------------------------------
169 static sal_Bool
test_rtl_OString_ctor_005( hTestResult hRtlTestResult
)
171 rtl_String
*aStr1
= NULL
;
173 rtl_string_newFromStr( &aStr1
, kTestStr1
);
177 ::rtl::OString
aStr2(aStr1
);
178 rtl_String
* pData2
= aStr2
.pData
;
180 sal_Bool bOK
= c_rtl_tres_state
183 aStr1
->refCount
== pData2
->refCount
&&
184 pData2
->length
== kTestStr1Len
&&
185 aStr1
->buffer
== pData2
->buffer
,
186 "new OString from a RTL String",
190 rtl_string_release( aStr1
);
200 "copying an ascii string to a RTL String!",
206 //------------------------------------------------------------------------
208 static sal_Bool
test_rtl_OString_ctor_006( hTestResult hRtlTestResult
)
211 sal_Unicode aStr1
[kTestStr1Len
+1];
213 if ( AStringToUStringNCopy( aStr1
, kTestStr1
, kTestStr1Len
) )
215 if ( AStringToUStringNCompare( aStr1
, kTestStr1
, kTestStr1Len
) == 0 )
217 // const sal_Char *kTCMessage[2] = { "", "array." };
223 kEncodingRTLTextUSASCII
,
224 kConvertFlagsOUStringToOString
233 "new OString from a unicode character buffer",
237 } /// end if AStringToUStringNCompare
245 "compare ascii string with unicode string!",
249 } /// end if AStringToUStringNCopy
257 "copy ascii string to unicode string!",
262 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_ctors(
263 hTestResult hRtlTestResult
)
266 c_rtl_tres_state_start(hRtlTestResult
, "ctor");
267 sal_Bool bTSState
= test_rtl_OString_ctor_001( hRtlTestResult
);
269 bTSState
&= test_rtl_OString_ctor_002( hRtlTestResult
);
270 bTSState
&= test_rtl_OString_ctor_003( hRtlTestResult
);
271 bTSState
&= test_rtl_OString_ctor_004( hRtlTestResult
);
272 bTSState
&= test_rtl_OString_ctor_005( hRtlTestResult
);
273 bTSState
&= test_rtl_OString_ctor_006( hRtlTestResult
);
275 c_rtl_tres_state_end(hRtlTestResult
, "ctor");
277 // return( bTSState );
282 //------------------------------------------------------------------------
283 // testing the method getLength
284 //------------------------------------------------------------------------
286 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_getLength(
287 hTestResult hRtlTestResult
)
289 sal_Char methName
[MAXBUFLENGTH
];
290 sal_Char
* pMeth
= methName
;
292 c_rtl_tres_state_start(hRtlTestResult
, "getLength");
294 typedef struct TestCase
299 ~TestCase() { delete input
;}
302 TestCase arrTestCase
[]={
304 {"length of ascii string", kTestStr1Len
, new OString(kTestStr1
)},
305 {"length of ascci string of size 1", 1, new OString("1")},
306 {"length of empty string (default constructor)", 0, new OString()},
307 {"length of empty string (empty ascii string arg)",0,new OString("")},
308 {"length of empty string (string arg = '\\0')",0,new OString("\0")}
312 sal_Bool res
= sal_True
;
315 for (i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
317 sal_Int32 length
= arrTestCase
[i
].input
->getLength();
318 sal_Bool lastRes
= (length
== arrTestCase
[i
].expVal
);
323 arrTestCase
[i
].comments
,
324 createName( pMeth
, "getLength", i
)
329 c_rtl_tres_state_end(hRtlTestResult
, "getLength");
335 //------------------------------------------------------------------------
336 // testing the method equals( const OString & aStr )
337 //------------------------------------------------------------------------
338 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_equals(
339 hTestResult hRtlTestResult
)
341 sal_Char methName
[MAXBUFLENGTH
];
342 sal_Char
* pMeth
= methName
;
344 c_rtl_tres_state_start(hRtlTestResult
, "equals");
346 typedef struct TestCase
352 ~TestCase() { delete input1
;delete input2
;}
355 TestCase arrTestCase
[]={
357 {"same size", sal_True
, new OString(kTestStr1
),new OString(kTestStr1
)},
358 {"different size", sal_False
, new OString(kTestStr1
),
359 new OString(kTestStr2
)},
360 {"same size, no case match", sal_False
, new OString(kTestStr1
),
361 new OString(kTestStr3
)},
362 {"two empty strings(def. constructor)", sal_True
, new OString(),
364 {"empty(def.constructor) and non empty", sal_False
, new OString(),
365 new OString(kTestStr2
)},
366 {"non empty and empty(def. constructor)", sal_False
,
367 new OString(kTestStr1
),new OString()},
368 {"two empty strings(string arg = '\\0')", sal_True
,
369 new OString(""),new OString("")},
370 {"empty(string arg = '\\0') and non empty", sal_False
,
371 new OString(""),new OString(kTestStr2
)},
372 {"non empty and empty(string arg = '\\0')", sal_False
,
373 new OString(kTestStr1
),new OString("")}
376 sal_Bool res
= sal_True
;
379 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
382 ( arrTestCase
[i
].input1
->equals(*(arrTestCase
[i
].input2
)) ==
383 arrTestCase
[i
].expVal
);
389 arrTestCase
[i
].comments
,
390 createName( pMeth
, "equals", i
)
395 c_rtl_tres_state_end(hRtlTestResult
, "equals");
399 //------------------------------------------------------------------------
400 // testing the method equalsIgnoreAsciiCase( const OString & aStr )
401 //------------------------------------------------------------------------
403 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_equalsIgnoreAsciiCase(
404 hTestResult hRtlTestResult
)
406 sal_Char methName
[MAXBUFLENGTH
];
407 sal_Char
* pMeth
= methName
;
409 c_rtl_tres_state_start(hRtlTestResult
, "equalsIgnoreAsciiCase");
410 typedef struct TestCase
416 ~TestCase() { delete input1
;delete input2
;}
419 TestCase arrTestCase
[]={
420 {"same strings but different cases",sal_True
,new OString(kTestStr4
),
421 new OString(kTestStr5
)},
422 {"same strings",sal_True
,new OString(kTestStr4
),
423 new OString(kTestStr4
)},
424 {"with equal beginning",sal_False
,new OString(kTestStr2
),
425 new OString(kTestStr4
)},
426 {"empty(def.constructor) and non empty",sal_False
,new OString(),
427 new OString(kTestStr5
)},
428 {"non empty and empty(def.constructor)",sal_False
,
429 new OString(kTestStr4
), new OString()},
430 {"two empty strings(def.constructor)",sal_True
,new OString(),
432 {"different strings with equal length",sal_False
,
433 new OString(kTestStr10
), new OString(kTestStr11
)}
436 sal_Bool res
= sal_True
;
439 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
442 (arrTestCase
[i
].input1
->equalsIgnoreAsciiCase(*arrTestCase
[i
].input2
)
443 == arrTestCase
[i
].expVal
);
449 arrTestCase
[i
].comments
,
450 createName( pMeth
, "equalsIgnoreAsciiCase", i
)
455 c_rtl_tres_state_end(hRtlTestResult
, "equalsIgnoreAsciiCase");
460 static sal_Bool SAL_CALL
test_rtl_OString_compareTo_001(
461 hTestResult hRtlTestResult
)
463 sal_Char methName
[MAXBUFLENGTH
];
464 sal_Char
* pMeth
= methName
;
466 typedef struct TestCase
472 ~TestCase() { delete input1
;delete input2
;}
475 TestCase arrTestCase
[]={
477 {"simple compare, str1 to str5",-1,new OString(kTestStr1
),
478 new OString(kTestStr5
)},
479 {"simple compare, str2 to str5",-1,new OString(kTestStr2
),
480 new OString(kTestStr5
)},
481 {"simple compare, str1 to str9",-1,new OString(kTestStr1
),
482 new OString(kTestStr9
)},
483 {"simple compare, str1 to str2",-1,new OString(kTestStr1
),
484 new OString(kTestStr2
)},
485 {"simple compare, str4 to str5",-1,new OString(kTestStr4
),
486 new OString(kTestStr5
)},
487 {"simple compare, str1 to str3",-1,new OString(kTestStr1
),
488 new OString(kTestStr3
)},
489 {"simple compare, str5 to str1",+1,new OString(kTestStr5
),
490 new OString(kTestStr1
)},
491 {"simple compare, str2 to str1",+1,new OString(kTestStr2
),
492 new OString(kTestStr1
)},
493 {"simple compare, str9 to str5",+1,new OString(kTestStr9
),
494 new OString(kTestStr5
)},
495 {"simple compare, str5 to str4",+1,new OString(kTestStr5
),
496 new OString(kTestStr4
)},
497 {"simple compare, str1 to str1",0,new OString(kTestStr1
),
498 new OString(kTestStr1
)},
499 {"simple compare, nullString to nullString",0,new OString(),
501 {"simple compare, nullString to str2",-1,new OString(),
502 new OString(kTestStr2
)},
503 {"simple compare, str1 to nullString",+1,new OString(kTestStr1
),
507 sal_Bool res
= sal_True
;
510 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
513 arrTestCase
[i
].input1
->compareTo(*arrTestCase
[i
].input2
);
514 cmpRes
= ( cmpRes
== 0 ) ? 0 : ( cmpRes
> 0 ) ? +1 : -1 ;
515 sal_Bool lastRes
= ( cmpRes
== arrTestCase
[i
].expVal
);
521 arrTestCase
[i
].comments
,
522 createName( pMeth
, "compareTo(const OString&)", i
)
532 //------------------------------------------------------------------------
533 // testing the method compareTo( const OString & rObj, sal_Int32 length )
534 //------------------------------------------------------------------------
535 static sal_Bool SAL_CALL
test_rtl_OString_compareTo_002(
536 hTestResult hRtlTestResult
)
538 sal_Char methName
[MAXBUFLENGTH
];
539 sal_Char
* pMeth
= methName
;
541 typedef struct TestCase
548 ~TestCase() { delete input1
;delete input2
;}
551 TestCase arrTestCase
[] =
553 {"compare with maxlength, str1 to str9, 16",-1,16,
554 new OString(kTestStr1
), new OString(kTestStr9
)},
555 {"compare with maxlength, str2 to str9, 32",-1,32,
556 new OString(kTestStr2
), new OString(kTestStr9
)},
557 {"compare with maxlength, str9 to str4, 16",+1,16,
558 new OString(kTestStr9
), new OString(kTestStr4
)},
559 {"compare with maxlength, str9 to str22, 32",+1,32,
560 new OString(kTestStr9
), new OString(kTestStr22
)},
561 {"compare with maxlength, str9 to str5, 16",0,16,
562 new OString(kTestStr9
), new OString(kTestStr5
)},
563 {"compare with maxlength, str9 to str9, 32",0,32,
564 new OString(kTestStr9
), new OString(kTestStr9
)},
565 {"compare with maxlength, str1 to str2, 32",-1,32,
566 new OString(kTestStr1
), new OString(kTestStr2
)},
567 {"compare with maxlength, str1 to str2, 32",-1,32,
568 new OString(kTestStr1
), new OString(kTestStr2
)}
571 sal_Bool res
= sal_True
;
574 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
577 arrTestCase
[i
].input1
->compareTo(*arrTestCase
[i
].input2
,
578 arrTestCase
[i
].maxLength
);
579 cmpRes
= (cmpRes
== 0) ? 0 : (cmpRes
> 0) ? +1 : -1 ;
580 sal_Bool lastRes
= (cmpRes
== arrTestCase
[i
].expVal
);
586 arrTestCase
[i
].comments
,
587 createName( pMeth
, "compareTo(const OString&, sal_Int32)", i
)
596 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_compareTo(
597 hTestResult hRtlTestResult
)
599 c_rtl_tres_state_start(hRtlTestResult
, "compareTo");
600 sal_Bool res
= test_rtl_OString_compareTo_001(hRtlTestResult
);
601 res
&= test_rtl_OString_compareTo_002(hRtlTestResult
);
602 c_rtl_tres_state_end(hRtlTestResult
, "compareTo");
606 //------------------------------------------------------------------------
607 // testing the operator == ( const OString& rStr1, const OString& rStr2 )
608 // testing the operator == ( const OString& rStr1, const sal_Char *rStr2 )
609 // testing the operator == ( const sal_Char *rStr1, const OString& rStr2 )
610 //------------------------------------------------------------------------
611 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_cmp(
612 hTestResult hRtlTestResult
)
614 c_rtl_tres_state_start(hRtlTestResult
, "op_cmp");
615 const sal_Int16 NCASES
= 7;
616 sal_Char methName
[MAXBUFLENGTH
];
617 sal_Char
* pMeth
= methName
;
618 const sal_Char
*arrOStr
[NCASES
][2] =
620 {kTestStr1
, kTestStr1
},
621 {kTestStr1
, kTestStr3
},
622 {kTestStr1
, kTestStr2
},
629 sal_Bool arrExpVal
[NCASES
] =
640 sal_Char
*arrComments
[NCASES
] =
642 "'Sun Microsystems'=='Sun Microsystems'",
643 "!('Sun Microsystems'=='Sun microsystems')",
644 "!('Sun Microsystems'=='Sun Microsystems Java Technology')",
645 "two empty strings(def.constructor)",
646 "!(empty string=='Sun Microsystems Java Technology')",
647 "!('Sun Microsystems Java Technology'==empty string)",
651 sal_Bool res
= sal_True
;
654 for(i
= 0; i
< NCASES
; i
++)
656 OString
*str1
, *str2
;
657 str1
= (arrOStr
[i
][0]) ? new OString(arrOStr
[i
][0]) : new OString() ;
658 str2
= (arrOStr
[i
][1]) ? new OString(arrOStr
[i
][1]) : new OString() ;
660 sal_Bool cmpRes
= (*str1
== *str2
);
661 sal_Bool lastRes
= (cmpRes
== arrExpVal
[i
]);
669 createName( pMeth
, "operator ==(OString&, OString&)", i
)
672 cmpRes
= (*str1
== arrOStr
[i
][1]);
673 lastRes
= (cmpRes
== arrExpVal
[i
]);
680 createName( pMeth
, "operator ==(OString&, sal_Char *)", i
)
683 cmpRes
= (arrOStr
[i
][0] == *str2
);
684 lastRes
= (cmpRes
== arrExpVal
[i
]);
691 createName( pMeth
, "operator ==(sal_Char *, OString&)", i
)
698 c_rtl_tres_state_end(hRtlTestResult
, "op_cmp");
702 //------------------------------------------------------------------------
703 // testing the operator != (const OString& rStr1, const OString& rStr2)
704 // testing the operator != (const OString& rStr1, const sal_Char *rStr2)
705 // testing the operator != (const sal_Char *rStr1, const OString& rStr2)
706 //------------------------------------------------------------------------
707 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_neq(
708 hTestResult hRtlTestResult
)
710 c_rtl_tres_state_start(hRtlTestResult
, "op_neq");
711 const sal_Int16 NCASES
= 6;
712 sal_Char methName
[MAXBUFLENGTH
];
713 sal_Char
* pMeth
= methName
;
715 const sal_Char
*arrOStr
[NCASES
][2] =
717 {kTestStr1
, kTestStr3
},
718 {kTestStr1
, kTestStr2
},
719 {kTestStr1
, kTestStr1
},
725 sal_Bool arrExpVal
[NCASES
] =
735 sal_Char
*arrComments
[NCASES
] =
737 "'Sun Microsystems'!='Sun microsystems'",
738 "'Sun Microsystems'!='Sun Microsystems Java Technology'",
739 "!('Sun Microsystems'!='Sun Microsystems')",
740 "empty string!='Sun Microsystems Java Technology'",
741 "'Sun Microsystems Java Technology'!=empty string", "!(''!='')"
744 sal_Bool res
= sal_True
;
747 for(i
= 0; i
< NCASES
; i
++)
749 OString
*str1
, *str2
;
750 str1
= (arrOStr
[i
][0]) ? new OString(arrOStr
[i
][0]) : new OString() ;
751 str2
= (arrOStr
[i
][1]) ? new OString(arrOStr
[i
][1]) : new OString() ;
753 sal_Bool cmpRes
= (*str1
!= *str2
);
754 sal_Bool lastRes
= (cmpRes
== arrExpVal
[i
]);
761 createName( pMeth
, "operator !=(OString&, OString&)", i
)
764 cmpRes
= (*str1
!= arrOStr
[i
][1]);
765 lastRes
= (cmpRes
== arrExpVal
[i
]);
772 createName( pMeth
, "operator !=(OString&, sal_Char *)", i
)
775 cmpRes
= (arrOStr
[i
][0] != *str2
);
776 lastRes
= (cmpRes
== arrExpVal
[i
]);
783 createName( pMeth
, "operator !=(sal_Char *, OString&)", i
)
790 c_rtl_tres_state_end(hRtlTestResult
, "op_neq");
795 //------------------------------------------------------------------------
796 // testing the operator > (const OString& rStr1, const OString& rStr2)
797 //------------------------------------------------------------------------
798 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_g(
799 hTestResult hRtlTestResult
)
801 sal_Char methName
[MAXBUFLENGTH
];
802 sal_Char
* pMeth
= methName
;
804 c_rtl_tres_state_start(hRtlTestResult
, "op_g");
805 typedef struct TestCase
811 ~TestCase() { delete input1
;delete input2
;}
814 TestCase arrTestCase
[] =
816 { "'Sun microsystems'>'Sun Microsystems'",sal_True
,
817 new OString(kTestStr3
), new OString(kTestStr1
)},
818 {"!('Sun Microsystems'>'Sun microsystems')",sal_False
,
819 new OString(kTestStr1
), new OString(kTestStr3
)},
820 {"'Sun Microsystems Java Technology'>'Sun Microsystems'",sal_True
,
821 new OString(kTestStr2
), new OString(kTestStr1
)},
822 {"!('Sun Microsystems'>'Sun Microsystems Java Technology')",sal_False
,
823 new OString(kTestStr1
), new OString(kTestStr2
)},
824 {"!('Sun Microsystems'>'Sun Microsystems'",sal_False
,
825 new OString(kTestStr1
), new OString(kTestStr1
)},
826 {"'Sun Microsystems'>''",sal_True
,new OString(kTestStr1
),
828 {"!(''>'Sun Microsystems')",sal_False
,new OString(),
829 new OString(kTestStr1
)},
830 {"!(''>'')",sal_False
,new OString(), new OString()}
833 sal_Bool res
= sal_True
;
836 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
838 sal_Bool cmpRes
= (*arrTestCase
[i
].input1
> *arrTestCase
[i
].input2
);
839 sal_Bool lastRes
= (cmpRes
== arrTestCase
[i
].expVal
);
845 arrTestCase
[i
].comments
,
846 createName( pMeth
, "operator >", i
)
853 c_rtl_tres_state_end(hRtlTestResult
, "op_g");
857 //------------------------------------------------------------------------
858 // testing the operator < (const OString& rStr1, const OString& rStr2)
859 //------------------------------------------------------------------------
861 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_l(
862 hTestResult hRtlTestResult
)
864 sal_Char methName
[MAXBUFLENGTH
];
865 sal_Char
* pMeth
= methName
;
867 c_rtl_tres_state_start(hRtlTestResult
, "op_l");
868 typedef struct TestCase
874 ~TestCase() { delete input1
;delete input2
;}
877 TestCase arrTestCase
[] =
879 {"!('Sun microsystems'<'Sun Microsystems')",sal_False
,
880 new OString(kTestStr3
), new OString(kTestStr1
)},
881 {"'Sun Microsystems'<'Sun microsystems'",sal_True
,
882 new OString(kTestStr1
), new OString(kTestStr3
)},
883 {"'Sun Microsystems'<'Sun Microsystems Java Technology'",sal_True
,
884 new OString(kTestStr1
), new OString(kTestStr2
)},
885 {"!('Sun Microsystems Java Technology'<'Sun Microsystems')",sal_False
,
886 new OString(kTestStr2
), new OString(kTestStr1
)},
887 {"!('Sun Microsystems'<'Sun Microsystems'", sal_False
,
888 new OString(kTestStr1
), new OString(kTestStr1
)},
889 {"'Sun Microsystems'<''",sal_False
,new OString(kTestStr1
),
891 {"''<'Sun Microsystems Java Technology'",sal_True
,new OString(),
892 new OString(kTestStr2
)},
893 {"!(''<'')",sal_False
,new OString(), new OString()}
896 sal_Bool res
= sal_True
;
899 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
901 sal_Bool cmpRes
= (*arrTestCase
[i
].input1
< *arrTestCase
[i
].input2
);
902 sal_Bool lastRes
= (cmpRes
== arrTestCase
[i
].expVal
);
908 arrTestCase
[i
].comments
,
909 createName( pMeth
, "operator <", i
)
916 c_rtl_tres_state_end(hRtlTestResult
, "op_l");
920 //------------------------------------------------------------------------
921 // testing the operator >= (const OString& rStr1, const OString& rStr2)
922 //------------------------------------------------------------------------
923 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_ge(
924 hTestResult hRtlTestResult
)
926 sal_Char methName
[MAXBUFLENGTH
];
927 sal_Char
* pMeth
= methName
;
929 c_rtl_tres_state_start(hRtlTestResult
, "op_ge");
930 typedef struct TestCase
936 ~TestCase() { delete input1
;delete input2
;}
939 TestCase arrTestCase
[] =
941 {"'Sun microsystems'>='Sun Microsystems'",sal_True
,
942 new OString(kTestStr3
), new OString(kTestStr1
)},
943 {"!('Sun Microsystems'>='Sun microsystems')",sal_False
,
944 new OString(kTestStr1
), new OString(kTestStr3
)},
945 {"!('Sun Microsystems'>='Sun Microsystems Java Technology')",sal_False
,
946 new OString(kTestStr1
), new OString(kTestStr2
)},
947 {"'Sun Microsystems Java Technology'>='Sun Microsystems'",sal_True
,
948 new OString(kTestStr2
), new OString(kTestStr1
)},
949 {"'Sun Microsystems'>='Sun Microsystems'", sal_True
,
950 new OString(kTestStr1
), new OString(kTestStr1
)},
951 {"'Sun Microsystems'>=''",sal_True
,new OString(kTestStr1
),
953 { "''>='Sun microsystems'",sal_False
,new OString(),
954 new OString(kTestStr3
)},
955 {"''>=''",sal_True
,new OString(), new OString()}
958 sal_Bool res
= sal_True
;
961 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
963 sal_Bool cmpRes
= (*arrTestCase
[i
].input1
>= *arrTestCase
[i
].input2
);
964 sal_Bool lastRes
= (cmpRes
== arrTestCase
[i
].expVal
);
970 arrTestCase
[i
].comments
,
971 createName( pMeth
, "operator >=", i
)
978 c_rtl_tres_state_end(hRtlTestResult
, "op_ge");
982 //------------------------------------------------------------------------
983 // testing the operator <= (const OString& rStr1, const OString& rStr2)
984 //------------------------------------------------------------------------
985 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_le(
986 hTestResult hRtlTestResult
)
988 sal_Char methName
[MAXBUFLENGTH
];
989 sal_Char
* pMeth
= methName
;
991 c_rtl_tres_state_start(hRtlTestResult
, "op_le");
992 typedef struct TestCase
998 ~TestCase() { delete input1
;delete input2
;}
1001 TestCase arrTestCase
[] =
1003 {"!('Sun microsystems'<='Sun Microsystems')",sal_False
,
1004 new OString(kTestStr3
), new OString(kTestStr1
)},
1005 {"'Sun Microsystems'<='Sun microsystems'",sal_True
,
1006 new OString(kTestStr1
), new OString(kTestStr3
)},
1007 {"'Sun Microsystems'<='Sun Microsystems Java Technology'",sal_True
,
1008 new OString(kTestStr1
),
1009 new OString(kTestStr2
)},
1010 {"!('Sun Microsystems Java Technology'<='Sun Microsystems')",sal_False
,
1011 new OString(kTestStr2
),
1012 new OString(kTestStr1
)},
1013 {"!('Sun Microsystems'<='Sun Microsystems'", sal_True
,
1014 new OString(kTestStr1
), new OString(kTestStr1
)},
1015 {"'Sun Microsystems'<=''",sal_False
,new OString(kTestStr1
),
1017 {"''<='Sun Microsystems Java Technology'",sal_True
,new OString(),
1018 new OString(kTestStr2
)},
1019 {"!(''<='')",sal_True
,new OString(), new OString()}
1022 sal_Bool res
= sal_True
;
1025 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1027 sal_Bool cmpRes
= (*arrTestCase
[i
].input1
<= *arrTestCase
[i
].input2
);
1028 sal_Bool lastRes
= (cmpRes
== arrTestCase
[i
].expVal
);
1034 arrTestCase
[i
].comments
,
1035 createName( pMeth
, "operator <=", i
)
1042 c_rtl_tres_state_end(hRtlTestResult
, "op_le");
1047 //------------------------------------------------------------------------
1048 // testing the operator =
1049 //------------------------------------------------------------------------
1050 static sal_Bool
test_rtl_OString_op_eq_001( hTestResult hRtlTestResult
)
1052 sal_Char methName
[MAXBUFLENGTH
];
1053 sal_Char
* pMeth
= methName
;
1055 typedef struct TestCase
1061 ~TestCase() { delete input1
;delete input2
;}
1064 TestCase arrTestCase
[] =
1066 {"'' = str1, str1 == str2",sal_True
,new OString(kTestStr1
),
1068 {"str1 = str2, str1 == str2",sal_True
,new OString(kTestStr1
),
1069 new OString(kTestStr6
)},
1070 {"str2 = '', str1 == str2",sal_True
,new OString(),
1071 new OString(kTestStr2
)},
1072 {"'' = '', str1 == str2",sal_True
,new OString(),
1076 sal_Bool res
= sal_True
;
1079 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1081 *(arrTestCase
[i
].input1
) = *(arrTestCase
[i
].input2
);
1084 (*(arrTestCase
[i
].input1
) == *(arrTestCase
[i
].input2
));
1085 sal_Bool lastRes
= (cmpRes
== arrTestCase
[i
].expVal
);
1091 arrTestCase
[i
].comments
,
1092 createName( pMeth
, "operator =", i
)
1101 static sal_Bool
test_rtl_OString_op_eq_002(
1102 hTestResult hRtlTestResult
)
1104 ::rtl::OString aStr
;
1105 aStr
= OString(kTestStr1
);
1113 "str = OString(\"%s\"), str == \"%s\"",
1119 static sal_Bool
test_rtl_OString_op_eq_003(
1120 hTestResult hRtlTestResult
)
1122 sal_Bool bTCState
= false;
1124 ::rtl::OString
aStr1(kTestStr1
);
1125 ::rtl::OString aStr2
;
1126 ::rtl::OString aStr3
;
1128 aStr3
= aStr2
= aStr1
;
1130 bTCState
= ( aStr1
== aStr2
)
1131 && ( aStr1
== aStr3
)
1132 && ( aStr2
== aStr3
);
1138 "str3=str2=str1,(str1 == str2)&&(str1 == str3)&&(str2 == str3)",
1145 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_eq(
1146 hTestResult hRtlTestResult
)
1148 c_rtl_tres_state_start(hRtlTestResult
, "op_eq");
1149 sal_Bool res
= test_rtl_OString_op_eq_001( hRtlTestResult
);
1150 res
&= test_rtl_OString_op_eq_002( hRtlTestResult
);
1151 res
&= test_rtl_OString_op_eq_003( hRtlTestResult
);
1152 c_rtl_tres_state_end(hRtlTestResult
, "op_eq");
1157 //------------------------------------------------------------------------
1158 // testing the operator +
1159 //------------------------------------------------------------------------
1160 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_plus(
1161 hTestResult hRtlTestResult
)
1163 sal_Char methName
[MAXBUFLENGTH
];
1164 sal_Char
* pMeth
= methName
;
1166 c_rtl_tres_state_start(hRtlTestResult
, "op_plus");
1167 typedef struct TestCase
1173 ~TestCase() { delete input1
;delete input2
; delete expVal
;}
1176 TestCase arrTestCase
[] =
1178 {"str1 = str7 + str8",new OString(kTestStr1
),
1179 new OString(kTestStr7
), new OString(kTestStr8
)},
1180 {"str1 = str1 + '' ",new OString(kTestStr1
),
1181 new OString(kTestStr1
), new OString("")},
1182 {"str1 = '' + str1", new OString(kTestStr1
),
1183 new OString(""), new OString(kTestStr1
)},
1184 {" '' = '' + '' ", new OString(""),new OString(""),
1186 {"str1 = str1 + def.constr", new OString(kTestStr1
),
1187 new OString(kTestStr1
), new OString()},
1188 {" str1 = def.constr + str1 ",new OString(kTestStr1
),
1189 new OString(), new OString(kTestStr1
)},
1190 {" def.constr= def.constr + def.constr", new OString(),
1191 new OString(), new OString()}
1194 sal_Bool res
= sal_True
;
1196 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1198 OString str
= (*arrTestCase
[i
].input1
) + (*arrTestCase
[i
].input2
);
1199 sal_Bool lastRes
= (str
== *arrTestCase
[i
].expVal
);
1205 arrTestCase
[i
].comments
,
1206 createName( pMeth
, "operator +", i
)
1213 c_rtl_tres_state_end(hRtlTestResult
, "op_plus");
1217 //------------------------------------------------------------------------
1218 // testing the operator +=
1219 //------------------------------------------------------------------------
1220 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_peq(
1221 hTestResult hRtlTestResult
)
1223 sal_Char methName
[MAXBUFLENGTH
];
1224 sal_Char
* pMeth
= methName
;
1226 c_rtl_tres_state_start(hRtlTestResult
, "op_peq");
1227 typedef struct TestCase
1233 ~TestCase() { delete input1
;delete input2
; delete expVal
;}
1236 TestCase arrTestCase
[] =
1238 {"str1 == (str7 += str8)",new OString(kTestStr1
),
1239 new OString(kTestStr7
), new OString(kTestStr8
)},
1240 {"str1 == (str1 += '')",new OString(kTestStr1
),
1241 new OString(kTestStr1
), new OString("")},
1242 {"str1 == ('' += str1)", new OString(kTestStr1
),
1243 new OString(""), new OString(kTestStr1
)},
1244 {" '' == ('' += '')", new OString(""),
1245 new OString(""), new OString("")},
1246 {"str1 == (str1 += def.constr)", new OString(kTestStr1
),
1247 new OString(kTestStr1
), new OString()},
1248 {" str1 == (def.constr += str1)",new OString(kTestStr1
),
1249 new OString(), new OString(kTestStr1
)},
1250 {" def.constr== (def.constr += def.constr)",
1251 new OString(),new OString(), new OString()}
1254 sal_Bool res
= sal_True
;
1256 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1258 str
+= (*arrTestCase
[i
].input1
); str
+= (*arrTestCase
[i
].input2
);
1259 sal_Bool lastRes
= (str
== *arrTestCase
[i
].expVal
);
1265 arrTestCase
[i
].comments
,
1266 createName( pMeth
, "operator +", i
)
1273 c_rtl_tres_state_end(hRtlTestResult
, "op_peq");
1277 //------------------------------------------------------------------------
1278 // testing the operator const sal_Char * (cscs for short)
1279 //------------------------------------------------------------------------
1280 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_cscs(
1281 hTestResult hRtlTestResult
)
1283 sal_Char methName
[MAXBUFLENGTH
];
1284 sal_Char
* pMeth
= methName
;
1286 c_rtl_tres_state_start(hRtlTestResult
, "op_cscs");
1287 typedef struct TestCase
1290 const sal_Char
* expVal
;
1293 ~TestCase() { delete input1
;}
1296 TestCase arrTestCase
[] =
1298 {"test normal string",kTestStr1
,kTestStr1Len
,new OString(kTestStr1
)},
1299 {"test empty string","",1,new OString()}
1302 sal_Bool res
= sal_True
;
1304 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1306 const sal_Char
* pstr
= (*arrTestCase
[i
].input1
);
1308 res
&= c_rtl_tres_state
1311 cmpstr((sal_Char
*)pstr
,(sal_Char
*)arrTestCase
[i
].expVal
,
1312 arrTestCase
[i
].cmpLen
),
1313 arrTestCase
[i
].comments
,
1314 createName( pMeth
, "const sal_Char*", i
)
1317 c_rtl_tres_state_end(hRtlTestResult
, "op_cscs");
1322 //------------------------------------------------------------------------
1323 // testing the method getStr()
1324 //------------------------------------------------------------------------
1327 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_getStr(
1328 hTestResult hRtlTestResult
)
1330 sal_Char methName
[MAXBUFLENGTH
];
1331 sal_Char
* pMeth
= methName
;
1333 c_rtl_tres_state_start(hRtlTestResult
, "getStr");
1334 typedef struct TestCase
1337 const sal_Char
* expVal
;
1340 ~TestCase() { delete input1
;}
1343 TestCase arrTestCase
[] =
1345 {"test normal string",kTestStr1
,kTestStr1Len
,new OString(kTestStr1
)},
1346 {"test empty string","",0,new OString()}
1349 sal_Bool res
= sal_True
;
1351 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1353 const sal_Char
* pstr
= arrTestCase
[i
].input1
->getStr();
1354 res
&= c_rtl_tres_state
1357 cmpstr(pstr
, arrTestCase
[i
].expVal
,
1358 arrTestCase
[i
].cmpLen
),
1359 arrTestCase
[i
].comments
,
1360 createName( pMeth
, "getStr", i
)
1363 c_rtl_tres_state_end(hRtlTestResult
, "getStr");
1369 //------------------------------------------------------------------------
1370 // testing the method copy( sal_Int32 beginIndex )
1371 //------------------------------------------------------------------------
1372 static sal_Bool SAL_CALL
test_rtl_OString_copy_001(
1373 hTestResult hRtlTestResult
)
1375 sal_Char methName
[MAXBUFLENGTH
];
1376 sal_Char
* pMeth
= methName
;
1378 typedef struct TestCase
1381 const sal_Char
* srcStr
;
1382 const sal_Char
* arrExpStr
;
1383 // string for comparing with result
1384 sal_Int32 beginIndex
;
1385 // beginIndex for the method copy
1386 sal_Int32 lengthForCmp
;
1387 // number of symbols for comparing
1388 // (if value is equal to 0 then pointers to buffers must be equal)
1389 sal_Int32 expLength
;
1390 //expected length of the result string
1393 TestCase arrTestCase
[] =
1395 {"beginIndex == 0 ( whole string )", kTestStr2
,kTestStr2
,
1396 0, kTestStr2Len
, kTestStr2Len
},
1397 {"beginIndex == strlen-2 ( last two char )", kTestStr2
,"gy",
1398 kTestStr2Len
-2, 2, 2},
1399 {"beginIndex == strlen-1( last char )", kTestStr2
, "y",
1400 kTestStr2Len
-1, 1, 1}
1403 sal_Bool res
= sal_True
;
1406 for(i
= 0; i
<(sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1408 OString
src(arrTestCase
[i
].srcStr
);
1410 // rtl_String* pDataSrc = src.pData;
1412 dst
= src
.copy(arrTestCase
[i
].beginIndex
);
1414 // rtl_String* pDataDst = dst.pData;
1418 lastRes
= (dst
== arrTestCase
[i
].arrExpStr
);
1425 arrTestCase
[i
].comments
,
1427 "copy_001(beginIndex)(check buffer and length)", i
)
1438 //------------------------------------------------------------------------
1439 // testing the method copy( sal_Int32 beginIndex, sal_Int32 count )
1440 //------------------------------------------------------------------------
1441 static sal_Bool SAL_CALL
test_rtl_OString_copy_002(
1442 hTestResult hRtlTestResult
)
1444 sal_Char methName
[MAXBUFLENGTH
];
1445 sal_Char
* pMeth
= methName
;
1447 typedef struct TestCase
1450 const sal_Char
* arrExpStr
;
1451 sal_Int32 beginIndex
;
1457 TestCase arrTestCase
[] ={
1459 {"copy substring", kTestStr6
, kTestStr11Len
, kTestStr2Len
- kTestStr11Len
,kTestStr6Len
},
1460 /* LLA: it is a bug, beginIndex + count > kTestStr2.getLength() */
1461 /* {"copy normal substring with incorrect count",kTestStr6, kTestStr11Len, 31, 15}, */
1462 {"copy whole string", kTestStr2
, 0, kTestStr2Len
, kTestStr2Len
},
1463 /* {"copy whole string with incorrect count larger than len and index 0", kTestStr2, 0, 40, 32}, */
1464 /* LLA: bug beginIndex + count > kTestStr2 {"copy last character", "y",kTestStr2Len - 1, 31,1}, */
1465 {"copy last character", "y",kTestStr2Len
- 1, 1,1},
1466 /* LLA: bug, beginIndex > kTestStr2 {"beginindex larger than len","",60, 0,0}, */
1467 {"beginindex exact as large as it's length","",kTestStr2Len
, 0,0}
1468 /* LLA: bug, negative count is not allowed. {"count is nagative int","",3, -1,0} */
1470 sal_Bool res
= sal_True
;
1473 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++) {
1474 OString
src(kTestStr2
);
1476 dst
= src
.copy(arrTestCase
[i
].beginIndex
, arrTestCase
[i
].count
);
1477 // rtl_String* pDataSrc = src.pData;
1478 // rtl_String* pDataDst = dst.pData;
1480 sal_Bool lastRes
=sal_True
;
1481 // checks buffer and length
1482 //t_print("this is copy__002 #%d\n", i);
1483 //t_print("dst buffer =%s\n", pDataDst->buffer);
1484 //t_print("expStr =%s\n", arrTestCase[i].arrExpStr);
1485 //t_print("dst length =%d\n", pDataDst->length);
1486 //t_print("count =%d\n", arrTestCase[i].count);
1487 //t_print("expLen =%d\n", arrTestCase[i].expLen);
1489 lastRes
= (dst
.equals(arrTestCase
[i
].arrExpStr
)) ? sal_True
: sal_False
;
1495 arrTestCase
[i
].comments
,
1497 "copy_002(beginIndex,count)(check buffer and length)", i
)
1508 static sal_Bool SAL_CALL
test_rtl_OString_copy_003(
1509 hTestResult hRtlTestResult
)
1511 sal_Bool res
= sal_True
;
1512 char comment
[] = "copy whole short string to long string";
1514 OString
src(kTestStr1
);
1515 // rtl_String* pDataSrc = src.pData;
1516 OString
dst(kTestStr2
);
1519 // rtl_String* pDataDst = dst.pData;
1520 //check buffer and length
1521 sal_Bool lastRes
=(dst
==src
);
1527 "copy_003(beginIndex)(check buffer and length)"
1535 static sal_Bool SAL_CALL
test_rtl_OString_copy_004(
1536 hTestResult hRtlTestResult
)
1538 sal_Bool res
= sal_True
;
1539 sal_Char comment
[] = "copy whole long string to short string";
1541 OString
src(kTestStr2
);
1542 // rtl_String* pDataSrc = src.pData;
1543 OString
dst(kTestStr1
);
1546 // rtl_String* pDataDst = dst.pData;
1547 //check buffer and length
1548 sal_Bool lastRes
=(dst
==src
);
1554 "copy_004(beginIndex)(check buffer and length)"
1561 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_copy(
1562 hTestResult hRtlTestResult
)
1564 c_rtl_tres_state_start(hRtlTestResult
, "copy");
1565 sal_Bool res
= test_rtl_OString_copy_001(hRtlTestResult
);
1566 res
&= test_rtl_OString_copy_002(hRtlTestResult
);
1567 res
&= test_rtl_OString_copy_003(hRtlTestResult
);
1568 res
&= test_rtl_OString_copy_004(hRtlTestResult
);
1569 c_rtl_tres_state_end(hRtlTestResult
, "copy");
1574 //------------------------------------------------------------------------
1575 // testing the method concat( const OString & aStr )
1576 //------------------------------------------------------------------------
1577 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_concat(
1578 hTestResult hRtlTestResult
)
1580 sal_Char methName
[MAXBUFLENGTH
];
1581 sal_Char
* pMeth
=methName
;
1583 c_rtl_tres_state_start(hRtlTestResult
, "concat");
1584 typedef struct TestCase
1590 ~TestCase() { delete input1
;delete input2
; delete expVal
;}
1593 TestCase arrTestCase
[] =
1595 {"concatenates two strings",new OString(kTestStr1
),
1596 new OString(kTestStr7
),
1597 new OString(kTestStr8
)},
1598 {"concatenates empty string",new OString(kTestStr1
),
1599 new OString(kTestStr1
),
1601 {"concatenates to empty string",new OString(kTestStr1
),
1603 new OString(kTestStr1
)},
1604 {"concatenates two empty strings",new OString(""),new OString(""),
1606 {"concatenates string constructed by default constructor",
1607 new OString(kTestStr1
),
1608 new OString(kTestStr1
), new OString()},
1609 {"concatenates to string constructed by default constructor",
1610 new OString(kTestStr1
),
1611 new OString(), new OString(kTestStr1
)},
1612 {"concatenates two strings constructed by default constructor",
1614 new OString(), new OString()}
1617 sal_Bool res
= sal_True
;
1619 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1622 arrTestCase
[i
].input1
->concat(*arrTestCase
[i
].input2
);
1623 sal_Bool lastRes
= (str
== *arrTestCase
[i
].expVal
);
1629 arrTestCase
[i
].comments
,
1630 createName( pMeth
, "concat", i
)
1637 c_rtl_tres_state_end(hRtlTestResult
, "concat");
1642 //------------------------------------------------------------------------
1643 // testing the method toAsciiLowerCase()
1644 //-----------------------------------------------------------------------
1645 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_toAsciiLowerCase(
1646 hTestResult hRtlTestResult
)
1648 sal_Char methName
[MAXBUFLENGTH
];
1649 sal_Char
* pMeth
=methName
;
1651 c_rtl_tres_state_start(hRtlTestResult
, "toAsciiLowerCase");
1652 typedef struct TestCase
1657 ~TestCase() { delete input1
; delete expVal
;}
1660 TestCase arrTestCase
[] =
1663 {"only uppercase",new OString(kTestStr5
),new OString(kTestStr4
)},
1664 {"different cases",new OString(kTestStr5
),new OString(kTestStr1
)},
1665 {"different cases",new OString(kTestStr5
),new OString(kTestStr3
)},
1666 {"only lowercase",new OString(kTestStr5
),new OString(kTestStr5
)},
1667 {"empty string",new OString(""),new OString("")},
1668 {"string constructed by default constructor",
1669 new OString(),new OString()}
1672 sal_Bool res
= sal_True
;
1675 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1677 OString str
= arrTestCase
[i
].input1
->toAsciiLowerCase();
1678 sal_Bool lastRes
= (str
==* arrTestCase
[i
].expVal
);
1684 arrTestCase
[i
].comments
,
1685 createName( pMeth
, "toAsciiLowerCase", i
)
1691 c_rtl_tres_state_end(hRtlTestResult
, "toAsciiLowerCase");
1695 //------------------------------------------------------------------------
1696 // testing the method toAsciiUpperCase()
1697 //------------------------------------------------------------------------
1698 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_toAsciiUpperCase(
1699 hTestResult hRtlTestResult
)
1701 sal_Char methName
[MAXBUFLENGTH
];
1702 sal_Char
* pMeth
=methName
;
1704 c_rtl_tres_state_start(hRtlTestResult
, "toAsciiUpperCase");
1705 typedef struct TestCase
1710 ~TestCase() { delete input1
; delete expVal
;}
1713 TestCase arrTestCase
[] =
1715 {"only lowercase",new OString(kTestStr4
),new OString(kTestStr5
)},
1716 {"mixed cases",new OString(kTestStr4
),new OString(kTestStr3
)},
1717 {"miced cases",new OString(kTestStr4
),new OString(kTestStr1
)},
1718 {"only uppercase",new OString(kTestStr4
),new OString(kTestStr4
)},
1719 {"empty string",new OString(""),new OString("")},
1720 {"string constructed by default constructor",
1721 new OString(),new OString()}
1724 sal_Bool res
= sal_True
;
1727 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1729 OString str
= arrTestCase
[i
].input1
->toAsciiUpperCase();
1730 sal_Bool lastRes
= (str
== *arrTestCase
[i
].expVal
);
1736 arrTestCase
[i
].comments
,
1737 createName( pMeth
, "toAsciiLowerCase", i
)
1742 c_rtl_tres_state_end(hRtlTestResult
, "toAsciiUpperCase");
1748 //------------------------------------------------------------------------
1749 // testing the method trim()
1750 //------------------------------------------------------------------------
1751 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_trim(
1752 hTestResult hRtlTestResult
)
1754 sal_Char methName
[MAXBUFLENGTH
];
1755 sal_Char
* pMeth
=methName
;
1757 c_rtl_tres_state_start(hRtlTestResult
, "trim");
1758 typedef struct TestCase
1763 ~TestCase() { delete input1
; delete expVal
;}
1766 TestCase arrTestCase
[] =
1768 {"removes space from the front",new OString(kTestStr1
),
1769 new OString(kTestStr10
)},
1770 {"removes space from the end",new OString(kTestStr1
),
1771 new OString(kTestStr11
)},
1772 {"removes space from the front and end",new OString(kTestStr1
),
1773 new OString(kTestStr12
)},
1774 {"removes several spaces from the end",new OString(kTestStr1
),
1775 new OString(kTestStr13
)},
1776 {"removes several spaces from the front",new OString(kTestStr1
),
1777 new OString(kTestStr14
)},
1778 {"removes several spaces from the front and one from the end",
1779 new OString(kTestStr1
),
1780 new OString(kTestStr15
)},
1781 {"removes one space from the front and several from the end",
1782 new OString(kTestStr1
),
1783 new OString(kTestStr16
)},
1784 {"removes several spaces from the front and end",
1785 new OString(kTestStr1
),
1786 new OString(kTestStr17
)},
1787 {"removes characters that have codes <= 32",new OString(kTestStr20
),
1788 new OString("\1\3\5\7\11\13\15\17sun\21\23\25\27\31\33\40")},
1789 {"no spaces",new OString(kTestStr8
),new OString(kTestStr8
)}
1792 sal_Bool res
= sal_True
;
1795 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1797 OString strRes
= arrTestCase
[i
].input1
->trim();
1798 sal_Bool lastRes
= (strRes
== *arrTestCase
[i
].expVal
);
1804 arrTestCase
[i
].comments
,
1805 createName( pMeth
, "trim", i
)
1812 c_rtl_tres_state_end(hRtlTestResult
, "trim");
1818 //------------------------------------------------------------------------
1819 // testing the method valueOf( sal_Bool b )
1820 //------------------------------------------------------------------------
1821 sal_Bool SAL_CALL
test_rtl_OString_valueOf_sal_Bool(
1822 hTestResult hRtlTestResult
)
1824 sal_Char methName
[MAXBUFLENGTH
];
1825 sal_Char
* pMeth
=methName
;
1827 typedef struct TestCase
1832 ~TestCase() {delete expVal
;}
1835 TestCase arrTestCase
[] =
1837 {"true",sal_True
,new OString("true")},
1838 {"false",sal_False
, new OString("false")}
1841 sal_Bool res
= sal_True
;
1844 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1846 ::rtl::OString aStr1
;
1847 aStr1
= aStr1
.valueOf( arrTestCase
[i
].input1
);
1848 sal_Bool lastRes
= (arrTestCase
[i
].expVal
->compareTo(aStr1
) == 0);
1854 arrTestCase
[i
].comments
,
1855 createName( pMeth
, "valueof_bool", i
)
1865 sal_Bool SAL_CALL
test_rtl_OString_valueOf_sal_Char(
1866 hTestResult hRtlTestResult
)
1868 sal_Char methName
[MAXBUFLENGTH
];
1869 sal_Char
* pMeth
=methName
;
1871 typedef struct TestCase
1876 ~TestCase() {delete expVal
;}
1879 TestCase arrTestCase
[] =
1881 {"A",'A',new OString("A")},
1882 {"a",'a', new OString("a")},
1883 {"0",'0', new OString("0")},
1884 {"-",'-', new OString("-")},
1885 {"_",'_', new OString("_")},
1886 {"|",'|', new OString("|")},
1887 {"?",'?', new OString("?")},
1888 {"?",'?', new OString("?")},
1889 {"\n",'\n', new OString("\n")},
1890 {"\'",'\'', new OString("\'")},
1891 {"\"",'\"', new OString("\"")}
1895 sal_Bool res
= sal_True
;
1898 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1900 ::rtl::OString aStr1
;
1901 aStr1
= aStr1
.valueOf( arrTestCase
[i
].input1
);
1902 sal_Bool lastRes
= (arrTestCase
[i
].expVal
->compareTo(aStr1
) == 0);
1908 arrTestCase
[i
].comments
,
1909 createName( pMeth
, "valueof_char", i
)
1920 * Calls the method valueOf(T, radix) and compares
1921 * returned strings with strings that passed in the array resArray.
1923 * @param T, type of argument, passed to valueOf
1924 * @param resArray, array of result strings to compare to
1925 * @param n the number of elements in the array resArray (testcases)
1926 * @param pTestResult the instance of the class TestResult
1927 * @param inArray [optional], array of value that is passed as first argument
1930 * @return true, if all returned strings are equal to corresponding string in
1931 * resArray else, false.
1934 sal_Bool
test_valueOf( const char** resArray
, int n
, sal_Int16 radix
,
1935 hTestResult hRtlTestResult
, const T
*inArray
)
1937 sal_Bool bRes
= sal_True
;
1939 sal_Char methName
[MAXBUFLENGTH
];
1940 sal_Char
* pMeth
= methName
;
1943 for (i
= 0; i
< n
; i
++)
1945 ::rtl::OString aStr1
;
1946 ::rtl::OString
aStr2( resArray
[i
] );
1949 aStr1
= ::rtl::OString::valueOf((T
)i
, radix
);
1952 if ( inArray
[i
] < 0 )
1955 aStr2
+= resArray
[i
];
1957 aStr1
= ::rtl::OString::valueOf((T
)inArray
[i
], radix
);
1960 bRes
&= c_rtl_tres_state
1963 aStr2
.compareTo(aStr1
) == 0,
1964 (sal_Char
*)resArray
[i
],
1965 createName( pMeth
, "valueOf", i
)
1973 #define test_valueOf_Int32 test_valueOf<sal_Int32>
1974 #define test_valueOf_Int64 test_valueOf<sal_Int64>
1975 // LLA: #define test_valueOf_float test_valueOf<float>
1976 // LLA: #define test_valueOf_double test_valueOf<double>
1978 //------------------------------------------------------------------------
1979 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=2 )
1980 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=8 )
1981 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=10 )
1982 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=16 )
1983 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=36 )
1984 //------------------------------------------------------------------------
1985 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int32(
1986 hTestResult hRtlTestResult
)
1988 sal_Bool bRes
= sal_False
;
1990 bRes
= c_rtl_tres_state
1993 test_valueOf_Int32((const char**)kBinaryNumsStr
,
1994 kBinaryNumsCount
, kRadixBinary
, hRtlTestResult
, 0 ),
1996 "valueOf(sal_Int32, radix 2)"
2000 bRes
&= c_rtl_tres_state
2003 test_valueOf_Int32((const char**)kOctolNumsStr
,
2004 kOctolNumsCount
, kRadixOctol
, hRtlTestResult
, 0),
2006 "valueOf(sal_Int32, radix 8)"
2009 bRes
&= c_rtl_tres_state
2012 test_valueOf_Int32((const char**)kDecimalNumsStr
,
2013 kDecimalNumsCount
, kRadixDecimal
, hRtlTestResult
, 0),
2015 "valueOf(sal_Int32, radix 10)"
2018 bRes
&= c_rtl_tres_state
2021 test_valueOf_Int32((const char**)kHexDecimalNumsStr
,
2022 kHexDecimalNumsCount
, kRadixHexdecimal
, hRtlTestResult
, 0),
2024 "valueOf(sal_Int32, radix 16)"
2027 bRes
&= c_rtl_tres_state
2030 test_valueOf_Int32((const char**)kBase36NumsStr
,
2031 kBase36NumsCount
, kRadixBase36
, hRtlTestResult
, 0),
2033 "valueOf(sal_Int32, radix 36)"
2040 //------------------------------------------------------------------------
2041 // testing the method valueOf( sal_Int32 l, sal_Int32 radix=2 )
2042 // where l = large constants
2043 // testing the method valueOf( sal_Int32 l, sal_Int32 radix=8 )
2044 // where l = large constants
2045 // testing the method valueOf( sal_Int32 l, sal_Int32 radix=10 )
2046 // where l = large constants
2047 // testing the method valueOf( sal_Int32 l, sal_Int32 radix=16 )
2048 // where l = large constants
2049 // testing the method valueOf( sal_Int32 l, sal_Int32 radix=36 )
2050 // where l = large constants
2051 //------------------------------------------------------------------------
2052 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int32_Bounderies(
2053 hTestResult hRtlTestResult
)
2055 sal_Bool bRes
= sal_False
;
2057 bRes
= c_rtl_tres_state
2060 test_valueOf_Int32((const char**)kBinaryMaxNumsStr
,
2061 kInt32MaxNumsCount
, kRadixBinary
, hRtlTestResult
,
2064 "valueOf(salInt32, radix 2) Bounderies"
2067 bRes
&= c_rtl_tres_state
2070 test_valueOf_Int32((const char**)kOctolMaxNumsStr
,
2071 kInt32MaxNumsCount
, kRadixOctol
, hRtlTestResult
,
2074 "valueOf(salInt32, radix 8) Bounderies"
2077 bRes
&= c_rtl_tres_state
2080 test_valueOf_Int32((const char**)kDecimalMaxNumsStr
,
2081 kInt32MaxNumsCount
, kRadixDecimal
,
2082 hRtlTestResult
, kInt32MaxNums
),
2084 "valueOf(salInt32, radix 10) Bounderies"
2087 bRes
&= c_rtl_tres_state
2090 test_valueOf_Int32((const char**)kHexDecimalMaxNumsStr
,
2091 kInt32MaxNumsCount
, kRadixHexdecimal
,
2092 hRtlTestResult
, kInt32MaxNums
),
2094 "valueOf(salInt32, radix 16) Bounderies"
2097 bRes
&= c_rtl_tres_state
2100 test_valueOf_Int32((const char**)kBase36MaxNumsStr
,
2101 kInt32MaxNumsCount
, kRadixBase36
,
2102 hRtlTestResult
, kInt32MaxNums
),
2104 "valueOf(salInt32, radix 36) Bounderies"
2110 //------------------------------------------------------------------------
2111 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=2 )
2112 // for negative value
2113 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=8 )
2114 // for negative value
2115 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=10 )
2116 // for negative value
2117 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=16 )
2118 // for negative value
2119 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=36 )
2120 // for negative value
2121 //------------------------------------------------------------------------
2122 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int32_Negative(
2123 hTestResult hRtlTestResult
)
2125 sal_Bool bRes
= sal_False
;
2126 sal_Int32 inArr
[kBase36NumsCount
];
2129 for (i
= 0; i
< kBase36NumsCount
; i
++ )
2132 bRes
= c_rtl_tres_state
2135 test_valueOf_Int32( kBinaryNumsStr
, kBinaryNumsCount
,
2136 kRadixBinary
, hRtlTestResult
, inArr
),
2137 "negative Int32, kRadixBinary",
2138 "valueOf( negative Int32, radix 2 )"
2141 bRes
&= c_rtl_tres_state
2144 test_valueOf_Int32( kOctolNumsStr
, kOctolNumsCount
,
2145 kRadixOctol
, hRtlTestResult
, inArr
),
2146 "negative Int32, kRadixOctol",
2147 "valueOf( negative Int32, radix 8 )"
2151 bRes
&= c_rtl_tres_state
2154 test_valueOf_Int32( kDecimalNumsStr
, kDecimalNumsCount
,
2155 kRadixDecimal
, hRtlTestResult
, inArr
),
2156 "negative Int32, kRadixDecimal",
2157 "valueOf( negative Int32, radix 10 )"
2160 bRes
&= c_rtl_tres_state
2163 test_valueOf_Int32( kHexDecimalNumsStr
, kHexDecimalNumsCount
,
2164 kRadixHexdecimal
, hRtlTestResult
, inArr
),
2165 "negative Int32, kRadixHexdecimal",
2166 "valueOf( negative Int32, radix 16 )"
2170 bRes
&= c_rtl_tres_state
2173 test_valueOf_Int32( kBase36NumsStr
, kBase36NumsCount
,
2174 kRadixBase36
, hRtlTestResult
, inArr
),
2175 "negative Int32, kRadixBase36",
2176 "valueOf( negative Int32, radix 36 )"
2181 //------------------------------------------------------------------------
2182 // testing the method valueOf( sal_Int32 l, sal_Int32 radix ) where radix = -5
2183 //------------------------------------------------------------------------
2184 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int32_WrongRadix(
2185 hTestResult hRtlTestResult
)
2187 sal_Bool bRes
= sal_False
;
2189 sal_Int32 intVal
= 11;
2191 ::rtl::OString aStr1
;
2192 ::rtl::OString
aStr2("11");
2194 aStr1
= aStr1
.valueOf( intVal
, -5 );
2196 bRes
= c_rtl_tres_state
2199 aStr2
.compareTo( aStr1
) == 0,
2200 "if radix not valid then radix must be 10",
2201 "valueOf(sal_Int32, sal_Int32 radix): radix = -5"
2207 //------------------------------------------------------------------------
2208 // testing the method valueOf( sal_Int32 l, sal_Int32 radix )
2209 // where l = -2147483648 (smallest negative value)
2210 //------------------------------------------------------------------------
2211 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int32_SmallestNegativeValue(
2212 hTestResult hRtlTestResult
)
2214 // Standard-conforming way to assign -2147483648 to n:
2216 for (int i
= 1; i
< 32; ++i
)
2218 return c_rtl_tres_state
2221 ::rtl::OString::valueOf(n
) == "-2147483648",
2223 "valueOf(sal_Int32 -2147483648)"
2227 //------------------------------------------------------------------------
2228 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=2 )
2229 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=8 )
2230 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=10 )
2231 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=16 )
2232 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=36 )
2233 //------------------------------------------------------------------------
2234 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int64(
2235 hTestResult hRtlTestResult
)
2237 sal_Bool bRes
= sal_False
;
2239 bRes
= c_rtl_tres_state
2242 test_valueOf_Int64((const char**)kBinaryNumsStr
,
2243 kBinaryNumsCount
, kRadixBinary
, hRtlTestResult
, 0),
2245 "valueOf(sal_Int64, radix 2)_"
2248 bRes
&= c_rtl_tres_state
2251 test_valueOf_Int64((const char**)kOctolNumsStr
,
2252 kOctolNumsCount
, kRadixOctol
, hRtlTestResult
, 0),
2254 "valueOf(sal_Int64, radix 8)_"
2257 bRes
&= c_rtl_tres_state
2260 test_valueOf_Int64((const char**)kDecimalNumsStr
,
2261 kDecimalNumsCount
, kRadixDecimal
, hRtlTestResult
, 0),
2263 "valueOf(sal_Int64, radix 10)_"
2265 bRes
&= c_rtl_tres_state
2268 test_valueOf_Int64((const char**)kHexDecimalNumsStr
,
2269 kHexDecimalNumsCount
, kRadixHexdecimal
, hRtlTestResult
, 0),
2271 "valueOf(sal_Int64, radix 16)_"
2274 bRes
&= c_rtl_tres_state
2277 test_valueOf_Int64((const char**)kBase36NumsStr
,
2278 kBase36NumsCount
, kRadixBase36
, hRtlTestResult
, 0),
2280 "valueOf(sal_Int64, radix 36)_"
2286 //------------------------------------------------------------------------
2287 // testing the method valueOf( sal_Int64 l, sal_Int32 radix=2 )
2288 // where l = large constants
2289 // testing the method valueOf( sal_Int64 l, sal_Int32 radix=8 )
2290 // where l = large constants
2291 // testing the method valueOf( sal_Int64 l, sal_Int32 radix=10 )
2292 // where l = large constants
2293 // testing the method valueOf( sal_Int64 l, sal_Int32 radix=16 )
2294 // where l = large constants
2295 // testing the method valueOf( sal_Int64 l, sal_Int32 radix=36 )
2296 // where l = large constants
2297 //------------------------------------------------------------------------
2298 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int64_Bounderies(
2299 hTestResult hRtlTestResult
)
2301 sal_Bool bRes
= sal_False
;
2303 bRes
= c_rtl_tres_state
2306 test_valueOf_Int64((const char**)kBinaryMaxNumsStr
,
2307 kInt64MaxNumsCount
, kRadixBinary
,
2308 hRtlTestResult
, kInt64MaxNums
),
2310 "valueOf(salInt64, radix 2) Bounderies"
2313 bRes
&= c_rtl_tres_state
2316 test_valueOf_Int64((const char**)kOctolMaxNumsStr
,
2317 kInt64MaxNumsCount
, kRadixOctol
,
2318 hRtlTestResult
, kInt64MaxNums
),
2320 "valueOf(salInt64, radix 8) Bounderies"
2323 bRes
&= c_rtl_tres_state
2326 test_valueOf_Int64((const char**)kDecimalMaxNumsStr
,
2327 kInt64MaxNumsCount
, kRadixDecimal
,
2328 hRtlTestResult
, kInt64MaxNums
),
2330 "valueOf(salInt64, radix 10) Bounderies"
2333 bRes
&= c_rtl_tres_state
2336 test_valueOf_Int64((const char**)kHexDecimalMaxNumsStr
,
2337 kInt64MaxNumsCount
, kRadixHexdecimal
,
2338 hRtlTestResult
, kInt64MaxNums
),
2340 "valueOf(salInt64, radix 16) Bounderies"
2343 bRes
&= c_rtl_tres_state
2346 test_valueOf_Int64((const char**)kBase36MaxNumsStr
,
2347 kInt64MaxNumsCount
, kRadixBase36
,
2348 hRtlTestResult
, kInt64MaxNums
),
2350 "valueOf(salInt64, radix 36) Bounderies"
2356 //------------------------------------------------------------------------
2357 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=2 )
2358 // for negative value
2359 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=8 )
2360 // for negative value
2361 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=10 )
2362 // for negative value
2363 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=16 )
2364 // for negative value
2365 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=36 )
2366 // for negative value
2367 //------------------------------------------------------------------------
2368 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int64_Negative(
2369 hTestResult hRtlTestResult
)
2371 sal_Bool bRes
= sal_False
;
2373 sal_Int64 inArr
[36];
2376 for (i
= 0; i
< 36; i
++) {
2381 bRes
= c_rtl_tres_state
2384 test_valueOf_Int64( kBinaryNumsStr
, kBinaryNumsCount
,
2385 kRadixBinary
, hRtlTestResult
, inArr
),
2386 "negative Int64, kRadixBinary",
2387 "valueOf( negative Int64, radix 2 )"
2390 bRes
&= c_rtl_tres_state
2393 test_valueOf_Int64( kOctolNumsStr
, kOctolNumsCount
,
2394 kRadixOctol
, hRtlTestResult
, inArr
),
2395 "negative Int64, kRadixOctol",
2396 "valueOf( negative Int64, radix 8 )"
2399 bRes
&= c_rtl_tres_state
2402 test_valueOf_Int64( kDecimalNumsStr
, kDecimalNumsCount
,
2403 kRadixDecimal
, hRtlTestResult
, inArr
),
2404 "negative Int64, kRadixDecimal",
2405 "valueOf( negative Int64, radix 10 )"
2408 bRes
&= c_rtl_tres_state
2411 test_valueOf_Int64( kHexDecimalNumsStr
, kHexDecimalNumsCount
,
2412 kRadixHexdecimal
, hRtlTestResult
, inArr
),
2413 "negative Int64, kRadixHexDecimal",
2414 "valueOf( negative Int64, radix 16 )"
2417 bRes
&= c_rtl_tres_state
2420 test_valueOf_Int64( kBase36NumsStr
, kBase36NumsCount
,
2421 kRadixBase36
, hRtlTestResult
, inArr
),
2422 "negative Int64, kRadixBase36",
2423 "valueOf( negative Int64, radix 36 )"
2428 //------------------------------------------------------------------------
2429 // testing the method valueOf( sal_Int64 l, sal_Int32 radix )
2431 //------------------------------------------------------------------------
2432 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int64_WrongRadix(
2433 hTestResult hRtlTestResult
)
2435 sal_Bool bRes
= sal_False
;
2437 sal_Int64 intVal
= 11;
2439 ::rtl::OString aStr1
;
2440 ::rtl::OString
aStr2("11");
2442 aStr1
= aStr1
.valueOf( intVal
, -5 );
2444 bRes
= c_rtl_tres_state
2447 aStr2
.compareTo(aStr1
) == 0,
2448 "if radix not valid then radix must be 10",
2449 "valueOf(sal_Int64, sal_Int32 radix): radix = -5"
2455 //------------------------------------------------------------------------
2456 // testing the method valueOf( sal_Int64 l, sal_Int32 radix )
2457 // where l = -9223372036854775808 (smallest negative value)
2458 //------------------------------------------------------------------------
2459 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int64_SmallestNegativeValue(
2460 hTestResult hRtlTestResult
)
2462 // Standard-conforming way to assign -9223372036854775808 to n:
2464 for (int i
= 1; i
< 64; ++i
)
2466 return c_rtl_tres_state
2469 ::rtl::OString::valueOf(n
) == "-9223372036854775808",
2470 "-9223372036854775808",
2471 "valueOf(sal_Int64 -9223372036854775808)"
2475 //------------------------------------------------------------------------
2476 // testing the method valueOf( float f )
2477 //------------------------------------------------------------------------
2478 // LLA: sal_Bool SAL_CALL test_rtl_OString_valueOf_float(
2479 // LLA: hTestResult hRtlTestResult )
2481 // LLA: sal_Char methName[MAXBUFLENGTH];
2482 // LLA: sal_Char* pMeth =methName;
2484 // LLA: typedef struct TestCase
2486 // LLA: sal_Char* comments;
2487 // LLA: float input1;
2488 // LLA: OString* expVal;
2490 // LLA: ~TestCase() {delete expVal;}
2493 // LLA: TestCase arrTestCase[] =
2495 // LLA: { "3.0", 3.0, new OString("3.0") },
2496 // LLA: { "3.5", 3.5f, new OString("3.5")},
2497 // LLA: { "3.0625", 3.0625f, new OString("3.0625")},
2498 // LLA: { "3.502525", 3.502525f, new OString("3.502525") },
2499 // LLA: { "3.141592", 3.141592f, new OString("3.141592") },
2500 // LLA: { "3.5025255", 3.5025255f, new OString("3.5025255") },
2501 // LLA: { "3.0039062", 3.00390625f, new OString("3.0039062") }
2504 // LLA: sal_Bool res = sal_True;
2505 // LLA: sal_Int32 i;
2507 // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
2509 // LLA: ::rtl::OString aStr1;
2510 // LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 );
2511 // LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0);
2513 // LLA: c_rtl_tres_state
2515 // LLA: hRtlTestResult,
2517 // LLA: arrTestCase[i].comments,
2518 // LLA: createName( pMeth, "valueof_float", i)
2521 // LLA: res &= lastRes;
2525 // LLA: return ( res );
2531 //------------------------------------------------------------------------
2532 // testing the method valueOf( float f ) for negative value
2533 //------------------------------------------------------------------------
2534 // LLA: sal_Bool SAL_CALL test_rtl_OString_valueOf_Float_Negative(
2535 // LLA: hTestResult hRtlTestResult )
2537 // LLA: sal_Char methName[MAXBUFLENGTH];
2538 // LLA: sal_Char* pMeth =methName;
2540 // LLA: typedef struct TestCase
2542 // LLA: sal_Char* comments;
2543 // LLA: float input1;
2544 // LLA: OString* expVal;
2546 // LLA: ~TestCase() {delete expVal;}
2549 // LLA: TestCase arrTestCase[] =
2551 // LLA: { "-3.0", -3.0, new OString("-3.0") },
2552 // LLA: { "-3.5", -3.5f, new OString("-3.5")},
2553 // LLA: { "-3.0625", -3.0625f, new OString("-3.0625")},
2554 // LLA: { "-3.502525", -3.502525f, new OString("-3.502525") },
2555 // LLA: { "-3.141592", -3.141592f, new OString("-3.141592") },
2556 // LLA: { "-3.5025255", -3.5025255f, new OString("-3.5025255") },
2557 // LLA: { "-3.0039062", -3.00390625f, new OString("-3.0039062") }
2560 // LLA: sal_Bool res = sal_True;
2561 // LLA: sal_Int32 i;
2563 // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
2565 // LLA: ::rtl::OString aStr1;
2566 // LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 );
2567 // LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0);
2569 // LLA: c_rtl_tres_state
2571 // LLA: hRtlTestResult,
2573 // LLA: arrTestCase[i].comments,
2574 // LLA: createName( pMeth, "valueof_negative float", i)
2577 // LLA: res &= lastRes;
2581 // LLA: return ( res );
2584 //------------------------------------------------------------------------
2585 // testing the method valueOf( double f )
2586 //------------------------------------------------------------------------
2587 // LLA: sal_Bool SAL_CALL test_rtl_OString_valueOf_double(
2588 // LLA: hTestResult hRtlTestResult )
2590 // LLA: sal_Char methName[MAXBUFLENGTH];
2591 // LLA: sal_Char* pMeth =methName;
2593 // LLA: typedef struct TestCase
2595 // LLA: sal_Char* comments;
2596 // LLA: double input1;
2597 // LLA: OString* expVal;
2599 // LLA: ~TestCase() {delete expVal;}
2602 // LLA: TestCase arrTestCase[] =
2604 // LLA: {"3.0", 3.0, new OString("3.0")},
2605 // LLA: {"3.5", 3.5, new OString("3.5")},
2606 // LLA: {"3.0625", 3.0625, new OString("3.0625")},
2607 // LLA: {"3.1415926535", 3.1415926535, new OString("3.1415926535")},
2608 // LLA: {"3.1415926535897931", 3.141592653589793,
2609 // LLA: new OString("3.1415926535897931")},
2610 // LLA: {"3.1415926535897931", 3.1415926535897932,
2611 // LLA: new OString("3.1415926535897931")},
2612 // LLA: {"3.1415926535897931", 3.14159265358979323,
2613 // LLA: new OString("3.1415926535897931")},
2614 // LLA: {"3.1415926535897931", 3.141592653589793238462643,
2615 // LLA: new OString("3.1415926535897931")}
2618 // LLA: sal_Bool res = sal_True;
2619 // LLA: sal_Int32 i;
2621 // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
2623 // LLA: ::rtl::OString aStr1;
2624 // LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 );
2625 // LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0);
2627 // LLA: c_rtl_tres_state
2629 // LLA: hRtlTestResult,
2631 // LLA: arrTestCase[i].comments,
2632 // LLA: createName( pMeth, "valueof_double", i)
2635 // LLA: res &= lastRes;
2639 // LLA: return ( res );
2643 //------------------------------------------------------------------------
2644 // testing the method valueOf( double f ) for negative value
2645 //------------------------------------------------------------------------
2646 // LLA: sal_Bool SAL_CALL test_rtl_OString_valueOf_Double_Negative(
2647 // LLA: hTestResult hRtlTestResult )
2649 // LLA: sal_Char methName[MAXBUFLENGTH];
2650 // LLA: sal_Char* pMeth =methName;
2652 // LLA: typedef struct TestCase
2654 // LLA: sal_Char* comments;
2655 // LLA: double input1;
2656 // LLA: OString* expVal;
2658 // LLA: ~TestCase() {delete expVal;}
2661 // LLA: TestCase arrTestCase[] =
2663 // LLA: {"-3.0", -3.0, new OString("-3.0")},
2664 // LLA: {"-3.5", -3.5, new OString("-3.5")},
2665 // LLA: {"-3.0625", -3.0625, new OString("-3.0625")},
2666 // LLA: {"-3.1415926535", -3.1415926535, new OString("-3.1415926535")},
2667 // LLA: {"-3.1415926535897931", -3.141592653589793,
2668 // LLA: new OString("-3.1415926535897931")},
2669 // LLA: {"-3.1415926535897931", -3.1415926535897932,
2670 // LLA: new OString("-3.1415926535897931")},
2671 // LLA: {"-3.1415926535897931", -3.14159265358979323,
2672 // LLA: new OString("-3.1415926535897931")},
2673 // LLA: {"-3.1415926535897931", -3.141592653589793238462643,
2674 // LLA: new OString("-3.1415926535897931")}
2677 // LLA: sal_Bool res = sal_True;
2678 // LLA: sal_Int32 i;
2680 // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
2682 // LLA: ::rtl::OString aStr1;
2683 // LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 );
2684 // LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0);
2686 // LLA: c_rtl_tres_state
2688 // LLA: hRtlTestResult,
2690 // LLA: arrTestCase[i].comments,
2691 // LLA: createName( pMeth, "valueof_nagative double", i)
2694 // LLA: res &= lastRes;
2698 // LLA: return ( res );
2701 //------------------------------------------------------------------------
2702 // testing the method valueOf()
2703 //------------------------------------------------------------------------
2704 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_valueOf(
2705 hTestResult hRtlTestResult
)
2707 c_rtl_tres_state_start(hRtlTestResult
, "valueOf");
2708 sal_Bool bTState
= test_rtl_OString_valueOf_sal_Bool( hRtlTestResult
);
2710 bTState
&= test_rtl_OString_valueOf_sal_Char( hRtlTestResult
);
2712 bTState
&= test_rtl_OString_valueOf_Int32( hRtlTestResult
);
2713 bTState
&= test_rtl_OString_valueOf_Int32_Bounderies( hRtlTestResult
);
2714 bTState
&= test_rtl_OString_valueOf_Int32_Negative( hRtlTestResult
);
2715 bTState
&= test_rtl_OString_valueOf_Int32_WrongRadix( hRtlTestResult
);
2716 bTState
&= test_rtl_OString_valueOf_Int32_SmallestNegativeValue(
2719 bTState
&= test_rtl_OString_valueOf_Int64( hRtlTestResult
);
2720 bTState
&= test_rtl_OString_valueOf_Int64_Bounderies( hRtlTestResult
);
2721 bTState
&= test_rtl_OString_valueOf_Int64_Negative( hRtlTestResult
);
2722 bTState
&= test_rtl_OString_valueOf_Int64_WrongRadix( hRtlTestResult
);
2723 bTState
&= test_rtl_OString_valueOf_Int64_SmallestNegativeValue(
2726 // LLA: the tests for valueOf(float) and valueOf(double) are moved to file
2727 // sal/qa/rtl/ostring/rtl_OString2.cxx
2729 // LLA: bTState &= test_rtl_OString_valueOf_float( hRtlTestResult );
2730 // LLA: bTState &= test_rtl_OString_valueOf_Float_Negative( hRtlTestResult );
2732 // LLA: bTState &= test_rtl_OString_valueOf_double( hRtlTestResult );
2733 // LLA: bTState &= test_rtl_OString_valueOf_Double_Negative( hRtlTestResult );
2735 c_rtl_tres_state_end(hRtlTestResult
, "valueOf");
2736 // return ( bTState );
2740 //------------------------------------------------------------------------
2741 // testing the method toChar()
2742 //------------------------------------------------------------------------
2743 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_toChar(
2744 hTestResult hRtlTestResult
)
2746 sal_Char methName
[MAXBUFLENGTH
];
2747 sal_Char
* pMeth
= methName
;
2749 c_rtl_tres_state_start(hRtlTestResult
, "toChar");
2750 typedef struct TestCase
2755 ~TestCase() {delete input1
;}
2759 TestCase arrTestCase
[] =
2761 {"A", 'A', new OString("A")},
2762 {"a", 'a', new OString("a")},
2763 {"0", '0',new OString("0")},
2764 {"-", '-',new OString("-")},
2765 {"_", '_',new OString("_")},
2767 // TODO: may be UTF-8 values
2768 // {"�0„6", '�0„6',new OString("�0„6")},
2769 // { "�0„7", '�0„7',new OString("�0„7")},
2770 // {"�0‹0", '�0‹0',new OString("�0‹0")},
2771 // {"�0�6", '�0�6',new OString("�0�6")},
2772 {"\n", '\n',new OString("\n")},
2773 {"\'", '\'',new OString("\'")},
2774 {"\"", '\"',new OString("\"")},
2775 {"\0", '\0',new OString("\0")},
2776 {"", '\0',new OString("")},
2777 {"Sun Microsystems", 'S', new OString(kTestStr1
)}
2781 // sal_Bool res = sal_True;
2784 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++ )
2786 sal_Char strRes
= arrTestCase
[i
].input1
->toChar();
2787 sal_Bool lastRes
= ( strRes
== arrTestCase
[i
].expVal
);
2789 char com
[MAXBUFLENGTH
];
2791 cpynstr(com
+ 1, (*arrTestCase
[i
].input1
), MAXBUFLENGTH
);
2792 int length
= AStringLen( (*arrTestCase
[i
].input1
) );
2793 com
[length
+ 1] = '\'';
2794 com
[length
+ 2] = 0;
2801 createName( pMeth
, "toChar", i
)
2806 c_rtl_tres_state_end(hRtlTestResult
, "toChar");
2811 //------------------------------------------------------------------------
2812 // testing the method toFloat()
2813 //------------------------------------------------------------------------
2814 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_toFloat(
2815 hTestResult hRtlTestResult
)
2817 sal_Char methName
[MAXBUFLENGTH
];
2818 sal_Char
* pMeth
= methName
;
2820 c_rtl_tres_state_start(hRtlTestResult
, "toFloat");
2821 typedef struct TestCase
2826 ~TestCase() {delete input1
;}
2830 TestCase arrTestCase
[] =
2832 {3.0f
, new OString("3"), 3e-7f
},
2833 {3.1f
, new OString("3.1"), 3e-7f
},
2834 {3.1415f
, new OString("3.1415"), 3e-7f
},
2835 {3.14159f
, new OString("3.14159"), 3e-7f
},
2836 {3.141592f
, new OString("3.141592"), 3e-7f
},
2837 {3.1415926f
, new OString("3.1415926"), 3e-7f
},
2838 {3.14159265f
, new OString("3.14159265"), 3e-7f
},
2839 {3.141592653589793238462643f
,
2840 new OString("3.141592653589793238462643"), 3e-7f
},
2841 {6.5822e-16f
, new OString("6.5822e-16"), 6e-16f
* 1e-7f
},
2842 {9.1096e-31f
, new OString("9.1096e-31"), 9e-31f
* 1e-7f
},
2843 {2.997925e8f
, new OString("2.997925e8"), 3e8f
* 1e-7f
},
2844 {6.241e18f
, new OString("6.241e18"), 6e18f
* 1e-7f
},
2845 {3.1f
, new OString("03.1"), 3e-7f
},
2846 {3.1f
, new OString(" 3.1"), 3e-7f
},
2847 {-3.1f
, new OString("-3.1"), 3e-7f
},
2848 {3.1f
, new OString("+3.1"), 3e-7f
},
2849 {0.0f
, new OString("-0.0"), 1e-7f
}
2853 // sal_Bool res = sal_True;
2856 t_print("sizeof(float)=%d, sizeof(double)=%d\n", sizeof(float), sizeof(double));
2858 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++ )
2860 float fA
= arrTestCase
[i
].input1
->toFloat();
2861 float fB
= arrTestCase
[i
].expVal
;
2862 float fPrec
= arrTestCase
[i
].m_nPrecision
;
2863 float fResult
= (float) fabs(fA
- fB
);
2864 // t_print("float result: A:(%.9f) B:(%.9f) fabs(A-B):%E\n", fA, fB, fResult);
2865 t_print("float result: A:(%E) B:(%E) fabs(A-B):%E\n", fA
, fB
, (float) fResult
);
2866 sal_Bool lastRes
= ( fResult
<= fPrec
);
2868 char com
[MAXBUFLENGTH
];
2870 cpynstr(com
+ 1, (*arrTestCase
[i
].input1
), MAXBUFLENGTH
);
2871 int length
= AStringLen( (*arrTestCase
[i
].input1
) );
2872 com
[length
+ 1] = '\'';
2873 com
[length
+ 2] = 0;
2880 createName( pMeth
, "toFloat", i
)
2885 c_rtl_tres_state_end(hRtlTestResult
, "toFloat");
2890 //------------------------------------------------------------------------
2891 // testing the method toDouble()
2892 //------------------------------------------------------------------------
2893 // LLA: extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_toDouble(
2894 // LLA: hTestResult hRtlTestResult )
2896 // LLA: sal_Char methName[MAXBUFLENGTH];
2897 // LLA: sal_Char* pMeth = methName;
2899 // LLA: c_rtl_tres_state_start(hRtlTestResult, "toDouble");
2900 // LLA: typedef struct TestCase
2902 // LLA: double expVal;
2903 // LLA: double expDiff;
2904 // LLA: OString* input1;
2905 // LLA: ~TestCase() {delete input1;}
2909 // LLA: TestCase arrTestCase[] =
2911 // LLA: {3.0, 1e-35, new OString("3")},
2912 // LLA: {3.1, 1e-2, new OString("3.1")},
2913 // LLA: {3.1415, 1e-5, new OString("3.1415")},
2914 // LLA: {3.1415926535, 1e-11, new OString("3.1415926535")},
2915 // LLA: {3.141592653589793, 1e-15,
2916 // LLA: new OString("3.141592653589793")},
2917 // LLA: {3.1415926535897932, 1e-16,
2918 // LLA: new OString("3.1415926535897932")},
2919 // LLA: {3.14159265358979323, 1e-15,
2920 // LLA: new OString("3.14159265358979323")},
2921 // LLA: {3.141592653589793238462643, 1e-15,
2922 // LLA: new OString("3.141592653589793238462643")},
2923 // LLA: {6.5822e-16, 1e-20, new OString("6.5822e-16")},
2924 // LLA: {9.1096e-31, 1e-35, new OString("9.1096e-31")},
2925 // LLA: {2.997925e8, 10, new OString("2.997925e8")},
2926 // LLA: {6.241e18, 100, new OString("6.241e18")},
2927 // LLA: {1.7e-308, 1e-35, new OString("1.7e-308")},
2928 // LLA: {1.7e+308, 100, new OString("1.7e+308")},
2929 // LLA: {3.1, 1e-2, new OString("03.1")},
2930 // LLA: {3.1, 1e-2, new OString(" 3.1")},
2931 // LLA: {-3.1, 1e-2, new OString("-3.1")},
2932 // LLA: {3.1, 1e-2, new OString("+3.1")},
2933 // LLA: {0.0, 1e-2, new OString("-0.0")}
2936 // LLA: sal_Bool res = sal_True;
2937 // LLA: sal_Int32 i;
2939 // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++ )
2941 // LLA: double dRes = arrTestCase[i].input1->toDouble();
2942 // LLA: double dErg = dRes - arrTestCase[i].expVal ;
2943 // LLA: double dComp = fabs( dErg );
2944 // LLA: sal_Bool lastRes = ( dComp <= arrTestCase[i].expDiff );
2946 // LLA: char com[MAXBUFLENGTH];
2947 // LLA: com[0] = '\'';
2948 // LLA: cpynstr(com + 1, (*arrTestCase[i].input1), MAXBUFLENGTH);
2949 // LLA: int length = AStringLen( (*arrTestCase[i].input1) );
2950 // LLA: com[length + 1] = '\'';
2951 // LLA: com[length + 2] = 0;
2953 // LLA: c_rtl_tres_state
2955 // LLA: hRtlTestResult,
2958 // LLA: createName( pMeth, "toDouble", i )
2963 // LLA: c_rtl_tres_state_end(hRtlTestResult, "toDouble");
2964 // LLA: // return (res);
2967 //------------------------------------------------------------------------
2968 // testing the method toBoolean()
2969 //------------------------------------------------------------------------
2971 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_toBoolean(
2972 hTestResult hRtlTestResult
)
2974 sal_Char methName
[MAXBUFLENGTH
];
2975 sal_Char
* pMeth
= methName
;
2977 c_rtl_tres_state_start(hRtlTestResult
, "toBoolean");
2978 typedef struct TestCase
2986 TestCase arrTestCase
[]={
2988 {"expected true", sal_True
, new OString("True")},
2989 {"expected false", sal_False
, new OString("False")},
2990 {"expected true", sal_True
, new OString("1")}
2994 sal_Bool res
= sal_True
;
2997 for (i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
2999 sal_Bool bRes
= arrTestCase
[i
].input
->toBoolean();
3000 sal_Bool lastRes
= (bRes
== arrTestCase
[i
].expVal
);
3005 arrTestCase
[i
].comments
,
3006 createName( pMeth
, "toBoolean", i
)
3011 c_rtl_tres_state_end(hRtlTestResult
, "toBoolean");
3017 //------------------------------------------------------------------------
3018 // testing the method toInt32( sal_Int16 radix = 2,8,10,16,36 )
3019 //------------------------------------------------------------------------
3020 sal_Bool
test_toInt32( int num
, const sal_Char
** in
,
3021 const sal_Int32
*expVal
,sal_Int16 radix
, hTestResult hRtlTestResult
)
3023 sal_Bool res
= sal_True
;
3024 sal_Char methName
[MAXBUFLENGTH
];
3025 sal_Char
* pMeth
= methName
;
3028 for( i
= 0; i
< num
; i
++ )
3031 sal_Int32 intRes
= str
.toInt32(radix
);
3032 sal_Bool lastRes
= (intRes
== expVal
[i
]);
3034 char buf
[MAXBUFLENGTH
];
3036 cpynstr( buf
+ 1, in
[i
], MAXBUFLENGTH
);
3037 int length
= AStringLen( in
[i
] );
3038 buf
[length
+ 1] = '\'';
3039 buf
[length
+ 2] = 0;
3046 createName( pMeth
,"toInt32", i
)
3055 sal_Bool SAL_CALL
test_rtl_OString_toInt32_wrongRadix(
3056 hTestResult hRtlTestResult
)
3058 ::rtl::OString
str("0");
3060 sal_Int32 iRes
= str
.toInt32(-1);
3069 "toInt32( 0, wrong radix -1 )"
3074 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_toInt32(
3075 hTestResult hRtlTestResult
)
3077 sal_Int32 expValues
[kBase36NumsCount
];
3080 c_rtl_tres_state_start(hRtlTestResult
, "toInt32");
3081 for ( i
= 0; i
< kBase36NumsCount
; i
++ )
3084 sal_Bool res
= c_rtl_tres_state
3087 test_toInt32( kBinaryNumsCount
, kBinaryNumsStr
,
3088 expValues
, kRadixBinary
, hRtlTestResult
),
3090 "toInt32( radix 2 )"
3092 res
&= c_rtl_tres_state
3095 test_toInt32( kInt32MaxNumsCount
, kBinaryMaxNumsStr
,
3096 kInt32MaxNums
, kRadixBinary
, hRtlTestResult
),
3097 "kBinaryMaxNumsStr",
3098 "toInt32_Boundaries( radix 2 )"
3101 res
&= c_rtl_tres_state
3104 test_toInt32( kOctolNumsCount
, kOctolNumsStr
,
3105 expValues
, kRadixOctol
, hRtlTestResult
),
3107 "toInt32( radix 8 )"
3110 res
&= c_rtl_tres_state
3113 test_toInt32( kInt32MaxNumsCount
, kOctolMaxNumsStr
,
3114 (sal_Int32
*)kInt32MaxNums
, kRadixOctol
, hRtlTestResult
),
3116 "toInt32_Boundaries( radix 8 )"
3119 res
&= c_rtl_tres_state
3122 test_toInt32( kDecimalNumsCount
, kDecimalNumsStr
, expValues
,
3123 kRadixDecimal
, hRtlTestResult
),
3125 "toInt32( radix 10 )"
3128 res
&= c_rtl_tres_state
3131 test_toInt32( kInt32MaxNumsCount
, kDecimalMaxNumsStr
,
3132 (sal_Int32
*)kInt32MaxNums
, kRadixDecimal
, hRtlTestResult
),
3133 "kDecimalMaxNumsStr",
3134 "toInt32_Boundaries( radix 10 )"
3137 res
&= c_rtl_tres_state
3140 test_toInt32( kHexDecimalNumsCount
, kHexDecimalNumsStr
, expValues
,
3141 kRadixHexdecimal
, hRtlTestResult
),
3142 "kHexDecimalNumsStr",
3143 "toInt32( radix 16 )"
3146 res
&= c_rtl_tres_state
3149 test_toInt32( kInt32MaxNumsCount
, kHexDecimalMaxNumsStr
,
3150 (sal_Int32
*)kInt32MaxNums
, kRadixHexdecimal
, hRtlTestResult
),
3151 "kHexDecimalMaxNumsStr",
3152 "toInt32_Boundaries( radix 16 )"
3155 res
&= c_rtl_tres_state
3158 test_toInt32( kBase36NumsCount
, kBase36NumsStr
, expValues
,
3159 kRadixBase36
, hRtlTestResult
),
3161 "toInt32( radix 36 )"
3164 res
&= c_rtl_tres_state
3167 test_toInt32( kInt32MaxNumsCount
, kBase36MaxNumsStr
,
3168 (sal_Int32
*)kInt32MaxNums
, kRadixBase36
, hRtlTestResult
),
3169 "kBase36MaxNumsStr",
3170 "toInt32_Boundaries( radix 36 )"
3173 const sal_Int16 nSpecCases
= 5;
3174 static const sal_Char
*spString
[nSpecCases
] =
3183 sal_Int32 expSpecVal
[nSpecCases
] =
3192 res
&= c_rtl_tres_state
3195 test_toInt32( nSpecCases
, spString
, expSpecVal
,
3196 kRadixDecimal
, hRtlTestResult
),
3198 "toInt32( specialcases )"
3201 res
&= test_rtl_OString_toInt32_wrongRadix( hRtlTestResult
);
3203 c_rtl_tres_state_end(hRtlTestResult
, "toInt32");
3207 //------------------------------------------------------------------------
3208 // testing the method toInt64( sal_Int16 radix = 2,8,10,16,36 )
3209 //------------------------------------------------------------------------
3210 sal_Bool
test_toInt64( int num
, const sal_Char
** in
,
3211 const sal_Int64
*expVal
,sal_Int16 radix
, hTestResult hRtlTestResult
)
3213 sal_Bool res
= sal_True
;
3214 sal_Char methName
[MAXBUFLENGTH
];
3215 sal_Char
* pMeth
= methName
;
3218 for( i
= 0; i
< num
; i
++ )
3220 OString
str( in
[i
] );
3221 sal_Int64 intRes
= str
.toInt64( radix
);
3222 sal_Bool lastRes
= ( intRes
== expVal
[i
] );
3224 char buf
[MAXBUFLENGTH
];
3226 cpynstr( buf
+ 1, in
[i
], MAXBUFLENGTH
);
3227 int length
= AStringLen(in
[i
]);
3228 buf
[length
+ 1] = '\'';
3229 buf
[length
+ 2] = 0;
3236 createName( pMeth
, "toInt64", i
)
3244 sal_Bool SAL_CALL
test_rtl_OString_toInt64_wrongRadix(
3245 hTestResult hRtlTestResult
)
3247 ::rtl::OString
str("0");
3249 sal_Int64 iRes
= str
.toInt64(-1);
3257 "toInt64( wrong radix -1)"
3262 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_toInt64(
3263 hTestResult hRtlTestResult
)
3265 sal_Int64 expValues
[kBase36NumsCount
];
3268 c_rtl_tres_state_start(hRtlTestResult
, "toInt64");
3269 for (i
= 0; i
< kBase36NumsCount
; expValues
[i
] = i
, i
++);
3271 sal_Bool res
= c_rtl_tres_state
3274 test_toInt64( kBinaryNumsCount
, kBinaryNumsStr
, expValues
,
3275 kRadixBinary
, hRtlTestResult
),
3277 "toInt64( radix 2 )"
3280 res
&= c_rtl_tres_state
3283 test_toInt64( kInt32MaxNumsCount
, kBinaryMaxNumsStr
,
3284 (sal_Int64
*)kInt64MaxNums
, kRadixBinary
, hRtlTestResult
),
3285 "kBinaryMaxNumsStr",
3286 "toInt64_Boundaries( radix 2 )"
3289 res
&= c_rtl_tres_state
3292 test_toInt64( kOctolNumsCount
, kOctolNumsStr
, expValues
,
3293 kRadixOctol
, hRtlTestResult
),
3295 "toInt64( radix 8 )"
3298 res
&= c_rtl_tres_state
3301 test_toInt64( kInt32MaxNumsCount
, kOctolMaxNumsStr
,
3302 (sal_Int64
*)kInt64MaxNums
, kRadixOctol
, hRtlTestResult
),
3304 "toInt64_Boundaries( radix 8 )"
3307 res
&= c_rtl_tres_state
3310 test_toInt64( kDecimalNumsCount
, kDecimalNumsStr
, expValues
,
3311 kRadixDecimal
, hRtlTestResult
),
3313 "toInt64( radix 10 )"
3316 res
&= c_rtl_tres_state
3319 test_toInt64( kInt32MaxNumsCount
, kDecimalMaxNumsStr
,
3320 (sal_Int64
*)kInt64MaxNums
, kRadixDecimal
, hRtlTestResult
),
3321 "kDecimalMaxNumsStr",
3322 "toInt64_Boundaries( radix 10 )"
3325 res
&= c_rtl_tres_state
3328 test_toInt64( kHexDecimalNumsCount
, kHexDecimalNumsStr
, expValues
,
3329 kRadixHexdecimal
, hRtlTestResult
),
3330 "kHexDecimalNumsStr",
3331 "toInt64( radix 16 )"
3334 res
&= c_rtl_tres_state
3337 test_toInt64( kInt32MaxNumsCount
, kHexDecimalMaxNumsStr
,
3338 (sal_Int64
*)kInt64MaxNums
, kRadixHexdecimal
, hRtlTestResult
),
3339 "kHexDecimalMaxNumsStr",
3340 "toInt64_Boundaries( radix 16 )"
3343 res
&= c_rtl_tres_state
3346 test_toInt64( kBase36NumsCount
, kBase36NumsStr
, expValues
,
3347 kRadixBase36
, hRtlTestResult
),
3349 "toInt64( radix 36 )"
3352 res
&= c_rtl_tres_state
3355 test_toInt64( kInt32MaxNumsCount
, kBase36MaxNumsStr
,
3356 (sal_Int64
*)kInt64MaxNums
, kRadixBase36
, hRtlTestResult
),
3357 "kBase36MaxNumsStr",
3358 "toInt64_Boundaries( radix 36 )"
3363 const sal_Int16 nSpecCases
= 5;
3364 static const sal_Char
*spString
[nSpecCases
] =
3373 sal_Int64 expSpecVal
[nSpecCases
] =
3382 res
&= c_rtl_tres_state
3385 test_toInt64( nSpecCases
, spString
, expSpecVal
,
3386 kRadixDecimal
, hRtlTestResult
),
3388 "toInt64( specialcases )"
3391 res
&= test_rtl_OString_toInt64_wrongRadix( hRtlTestResult
);
3393 c_rtl_tres_state_end(hRtlTestResult
, "toInt64");
3397 //------------------------------------------------------------------------
3398 // testing the method replace( sal_Char oldChar, sal_Char newChar )
3399 //------------------------------------------------------------------------
3400 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_replace(
3401 hTestResult hRtlTestResult
)
3403 sal_Char methName
[MAXBUFLENGTH
];
3404 sal_Char
* pMeth
= methName
;
3406 c_rtl_tres_state_start(hRtlTestResult
, "replace");
3407 typedef struct TestCase
3415 ~TestCase() { delete input
; delete expVal
;}
3418 TestCase arrTestCase
[]={
3420 {"string differs", new OString(kTestStr18
),
3421 new OString(kTestStr4
),'S','s'},
3422 {"string differs", new OString(kTestStr19
),
3423 new OString(kTestStr17
),(sal_Char
)' ',(sal_Char
)'-'},
3424 {"same string, no replace ", new OString(kTestStr22
),
3425 new OString(kTestStr22
),'*','8'}
3429 sal_Bool res
= sal_True
;
3432 for (i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
3434 ::rtl::OString aStr1
;
3435 aStr1
= arrTestCase
[i
].input
->replace(arrTestCase
[i
].oldChar
,
3436 arrTestCase
[i
].newChar
);
3438 res
&= c_rtl_tres_state
3441 (arrTestCase
[i
].expVal
->compareTo(aStr1
) == 0),
3442 arrTestCase
[i
].comments
,
3443 createName( pMeth
, "replace", i
)
3447 c_rtl_tres_state_end(hRtlTestResult
, "replace");
3453 //------------------------------------------------------------------------
3454 // testing the method replaceAt( sal_Int32 index, sal_Int32 count,
3455 // const OString& newStr )
3456 //------------------------------------------------------------------------
3457 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_replaceAt(
3458 hTestResult hRtlTestResult
)
3460 sal_Char methName
[MAXBUFLENGTH
];
3461 sal_Char
* pMeth
= methName
;
3463 c_rtl_tres_state_start(hRtlTestResult
, "replaceAt");
3464 typedef struct TestCase
3473 ~TestCase() { delete input
; delete expVal
; delete newStr
;}
3476 TestCase arrTestCase
[]=
3479 { "string differs", new OString(kTestStr2
), new OString(kTestStr22
),
3480 new OString(kTestStr2
), 0, kTestStr22Len
},
3482 { "larger index", new OString(kTestStr1
), new OString(kTestStr7
),
3483 new OString(kTestStr8
), 64, kTestStr8Len
},
3485 { "larger count", new OString(kTestStr2
), new OString(kTestStr22
),
3486 new OString(kTestStr2
),0, 64 },
3488 { "navigate index", new OString(kTestStr2
), new OString(kTestStr22
),
3489 new OString(kTestStr2
), -64, 64 },
3491 { "null string", new OString(""),
3492 new OString(kTestStr14
),new OString(""), 0, kTestStr14Len
}
3495 sal_Bool res
= sal_True
;
3498 for (i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
3500 ::rtl::OString aStr1
;
3501 aStr1
= arrTestCase
[i
].input
->replaceAt( arrTestCase
[i
].index
,
3502 arrTestCase
[i
].count
, *arrTestCase
[i
].newStr
);
3504 sal_Bool lastRes
= ( arrTestCase
[i
].expVal
->compareTo(aStr1
) == 0 );
3510 arrTestCase
[i
].comments
,
3511 createName( pMeth
, "replaceAt", i
)
3516 c_rtl_tres_state_end(hRtlTestResult
, "replaceAt");
3520 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString( hTestResult hRtlTestResult
)
3523 c_rtl_tres_state_start(hRtlTestResult
, "rtl_OString" );
3525 test_rtl_OString_ctors( hRtlTestResult
);
3526 test_rtl_OString_getLength( hRtlTestResult
);
3527 test_rtl_OString_equals( hRtlTestResult
);
3528 test_rtl_OString_equalsIgnoreAsciiCase( hRtlTestResult
);
3529 test_rtl_OString_compareTo( hRtlTestResult
);
3530 test_rtl_OString_op_cmp( hRtlTestResult
);
3531 test_rtl_OString_op_neq( hRtlTestResult
);
3532 test_rtl_OString_op_g( hRtlTestResult
);
3533 test_rtl_OString_op_l( hRtlTestResult
);
3534 test_rtl_OString_op_ge( hRtlTestResult
);
3535 test_rtl_OString_op_le( hRtlTestResult
);
3536 test_rtl_OString_op_eq( hRtlTestResult
);
3537 test_rtl_OString_op_plus( hRtlTestResult
);
3538 test_rtl_OString_op_peq( hRtlTestResult
);
3539 test_rtl_OString_op_cscs( hRtlTestResult
);
3540 test_rtl_OString_getStr( hRtlTestResult
);
3541 test_rtl_OString_copy( hRtlTestResult
);
3542 test_rtl_OString_concat( hRtlTestResult
);
3543 test_rtl_OString_toAsciiLowerCase( hRtlTestResult
);
3544 test_rtl_OString_toAsciiUpperCase( hRtlTestResult
);
3545 test_rtl_OString_trim( hRtlTestResult
);
3546 test_rtl_OString_valueOf( hRtlTestResult
);
3547 test_rtl_OString_toChar( hRtlTestResult
);
3548 test_rtl_OString_toFloat( hRtlTestResult
);
3549 // LLA: test_rtl_OString_toDouble( hRtlTestResult );
3550 test_rtl_OString_toBoolean( hRtlTestResult
);
3551 test_rtl_OString_toInt32( hRtlTestResult
);
3552 test_rtl_OString_toInt64( hRtlTestResult
);
3553 test_rtl_OString_replace( hRtlTestResult
);
3554 test_rtl_OString_replaceAt( hRtlTestResult
);
3556 c_rtl_tres_state_end(hRtlTestResult
, "rtl_OString");
3560 // -----------------------------------------------------------------------------
3561 void RegisterAdditionalFunctions(FktRegFuncPtr _pFunc
)
3565 (_pFunc
)(&test_rtl_OString
, "");
3567 //# (_pFunc)(&test_rtl_OString_ctors, "");
3568 //# (_pFunc)(&test_rtl_OString_getLength, "");
3569 //# (_pFunc)(&test_rtl_OString_equals, "");
3570 //# (_pFunc)(&test_rtl_OString_equalsIgnoreAsciiCase, "");
3571 //# (_pFunc)(&test_rtl_OString_compareTo, "");
3572 //# (_pFunc)(&test_rtl_OString_op_cmp, "");
3573 //# (_pFunc)(&test_rtl_OString_op_neq, "");
3574 //# (_pFunc)(&test_rtl_OString_op_g, "");
3575 //# (_pFunc)(&test_rtl_OString_op_l, "");
3576 //# (_pFunc)(&test_rtl_OString_op_ge, "");
3577 //# (_pFunc)(&test_rtl_OString_op_le, "");
3578 //# (_pFunc)(&test_rtl_OString_op_eq, "");
3579 //# (_pFunc)(&test_rtl_OString_op_plus, "");
3580 //# (_pFunc)(&test_rtl_OString_op_peq, "");
3581 //# (_pFunc)(&test_rtl_OString_op_cscs, "");
3582 //# (_pFunc)(&test_rtl_OString_getStr, "");
3583 //# (_pFunc)(&test_rtl_OString_copy, "");
3584 //# (_pFunc)(&test_rtl_OString_concat, "");
3585 //# (_pFunc)(&test_rtl_OString_toAsciiLowerCase, "");
3586 //# (_pFunc)(&test_rtl_OString_toAsciiUpperCase, "");
3587 //# (_pFunc)(&test_rtl_OString_trim, "");
3588 //# (_pFunc)(&test_rtl_OString_valueOf, "");
3589 //# (_pFunc)(&test_rtl_OString_toChar, "");
3590 //# (_pFunc)(&test_rtl_OString_toFloat, "");
3591 //# (_pFunc)(&test_rtl_OString_toDouble, "");
3592 //# (_pFunc)(&test_rtl_OString_toBoolean, "");
3593 //# (_pFunc)(&test_rtl_OString_toInt32, "");
3594 //# (_pFunc)(&test_rtl_OString_toInt64, "");
3595 //# (_pFunc)(&test_rtl_OString_replace, "");
3596 //# (_pFunc)(&test_rtl_OString_replaceAt, "");
3601 D:\local\644\SRX644\sal\qa\rtl_OString.cxx(3559) : error C2664:
3602 'unsigned char (void (__cdecl *)(void *),const char *)'
3603 : cannot convert parameter 1 from
3604 'unsigned char (__cdecl *)(void *)' to 'void (__cdecl *)(void *)'
3606 This conversion requires a reinterpret_cast, a C-style cast or function-