1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sal.hxx"
33 #include <sal/types.h>
36 // #ifndef _RTL_TRES_H_
37 // #include <rtl/tres.h>
40 #include <testshl/tresstatewrapper.hxx>
42 #ifndef _RTL_STRING_HXX_
43 #include <rtl/string.hxx>
46 #ifndef _RTL_STRING_CONST_H_
47 #include <rtl_String_Const.h>
50 #ifndef _RTL_STRING_UTILS_HXX_
51 #include <rtl_String_Utils.hxx>
53 #include <rtl/ustring.h>
57 //------------------------------------------------------------------------
59 //------------------------------------------------------------------------
60 const int MAXBUFLENGTH
= 255;
61 //------------------------------------------------------------------------
63 //------------------------------------------------------------------------
69 (void)input1StrDefault
;
70 (void)input1StrNormal
;
71 (void)input1StrLastDefault
;
72 (void)input1StrLastNormal
;
76 //------------------------------------------------------------------------
77 // testing constructors
78 //------------------------------------------------------------------------
79 static sal_Bool
test_rtl_OString_ctor_001( hTestResult hRtlTestResult
)
82 rtl_String
* pData
= aStr
.pData
;
92 "New OString containing no characters",
98 //------------------------------------------------------------------------
100 static sal_Bool SAL_CALL
test_rtl_OString_ctor_002(
101 hTestResult hRtlTestResult
)
103 ::rtl::OString
aStr(kTestStr1
);
104 rtl_String
* pData
= aStr
.pData
;
111 pData
->refCount
== 1 &&
112 pData
->length
== kTestStr1Len
&&
113 cmpstr( (const sal_Char
*)pData
->buffer
, kTestStr1
, kTestStr1Len
),
114 "New OString from a character buffer array",
119 //------------------------------------------------------------------------
121 static sal_Bool SAL_CALL
test_rtl_OString_ctor_003(
122 hTestResult hRtlTestResult
)
124 ::rtl::OString
aStr(kTestStr2
, kTestStr1Len
);
125 rtl_String
* pData
= aStr
.pData
;
132 pData
->refCount
== 1 &&
133 pData
->length
== kTestStr1Len
&&
134 cmpstr( (const sal_Char
*)pData
->buffer
, kTestStr2
, kTestStr1Len
),
135 "New OString from the first n chars of ascii string",
141 //------------------------------------------------------------------------
143 static sal_Bool SAL_CALL
test_rtl_OString_ctor_004(
144 hTestResult hRtlTestResult
)
146 ::rtl::OString
aStr1(kTestStr1
);
147 ::rtl::OString
aStr2(aStr1
);
148 rtl_String
* pData1
= aStr1
.pData
;
149 rtl_String
* pData2
= aStr2
.pData
;
156 pData1
->refCount
== pData2
->refCount
&&
157 pData1
->length
== kTestStr1Len
&&
158 pData1
->buffer
== pData2
->buffer
,
159 "New OString from an OString",
164 //------------------------------------------------------------------------
166 static sal_Bool
test_rtl_OString_ctor_005( hTestResult hRtlTestResult
)
168 rtl_String
*aStr1
= NULL
;
170 rtl_string_newFromStr( &aStr1
, kTestStr1
);
174 ::rtl::OString
aStr2(aStr1
);
175 rtl_String
* pData2
= aStr2
.pData
;
177 sal_Bool bOK
= c_rtl_tres_state
180 aStr1
->refCount
== pData2
->refCount
&&
181 pData2
->length
== kTestStr1Len
&&
182 aStr1
->buffer
== pData2
->buffer
,
183 "new OString from a RTL String",
187 rtl_string_release( aStr1
);
197 "copying an ascii string to a RTL String!",
203 //------------------------------------------------------------------------
205 static sal_Bool
test_rtl_OString_ctor_006( hTestResult hRtlTestResult
)
208 sal_Unicode aStr1
[kTestStr1Len
+1];
210 if ( AStringToUStringNCopy( aStr1
, kTestStr1
, kTestStr1Len
) )
212 if ( AStringToUStringNCompare( aStr1
, kTestStr1
, kTestStr1Len
) == 0 )
214 // const sal_Char *kTCMessage[2] = { "", "array." };
220 kEncodingRTLTextUSASCII
,
221 kConvertFlagsOUStringToOString
230 "new OString from a unicode character buffer",
234 } /// end if AStringToUStringNCompare
242 "compare ascii string with unicode string!",
246 } /// end if AStringToUStringNCopy
254 "copy ascii string to unicode string!",
259 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_ctors(
260 hTestResult hRtlTestResult
)
263 c_rtl_tres_state_start(hRtlTestResult
, "ctor");
264 sal_Bool bTSState
= test_rtl_OString_ctor_001( hRtlTestResult
);
266 bTSState
&= test_rtl_OString_ctor_002( hRtlTestResult
);
267 bTSState
&= test_rtl_OString_ctor_003( hRtlTestResult
);
268 bTSState
&= test_rtl_OString_ctor_004( hRtlTestResult
);
269 bTSState
&= test_rtl_OString_ctor_005( hRtlTestResult
);
270 bTSState
&= test_rtl_OString_ctor_006( hRtlTestResult
);
272 c_rtl_tres_state_end(hRtlTestResult
, "ctor");
274 // return( bTSState );
279 //------------------------------------------------------------------------
280 // testing the method getLength
281 //------------------------------------------------------------------------
283 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_getLength(
284 hTestResult hRtlTestResult
)
286 sal_Char methName
[MAXBUFLENGTH
];
287 sal_Char
* pMeth
= methName
;
289 c_rtl_tres_state_start(hRtlTestResult
, "getLength");
291 typedef struct TestCase
296 ~TestCase() { delete input
;}
299 TestCase arrTestCase
[]={
301 {"length of ascii string", kTestStr1Len
, new OString(kTestStr1
)},
302 {"length of ascci string of size 1", 1, new OString("1")},
303 {"length of empty string (default constructor)", 0, new OString()},
304 {"length of empty string (empty ascii string arg)",0,new OString("")},
305 {"length of empty string (string arg = '\\0')",0,new OString("\0")}
309 sal_Bool res
= sal_True
;
312 for (i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
314 sal_Int32 length
= arrTestCase
[i
].input
->getLength();
315 sal_Bool lastRes
= (length
== arrTestCase
[i
].expVal
);
320 arrTestCase
[i
].comments
,
321 createName( pMeth
, "getLength", i
)
326 c_rtl_tres_state_end(hRtlTestResult
, "getLength");
332 //------------------------------------------------------------------------
333 // testing the method equals( const OString & aStr )
334 //------------------------------------------------------------------------
335 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_equals(
336 hTestResult hRtlTestResult
)
338 sal_Char methName
[MAXBUFLENGTH
];
339 sal_Char
* pMeth
= methName
;
341 c_rtl_tres_state_start(hRtlTestResult
, "equals");
343 typedef struct TestCase
349 ~TestCase() { delete input1
;delete input2
;}
352 TestCase arrTestCase
[]={
354 {"same size", sal_True
, new OString(kTestStr1
),new OString(kTestStr1
)},
355 {"different size", sal_False
, new OString(kTestStr1
),
356 new OString(kTestStr2
)},
357 {"same size, no case match", sal_False
, new OString(kTestStr1
),
358 new OString(kTestStr3
)},
359 {"two empty strings(def. constructor)", sal_True
, new OString(),
361 {"empty(def.constructor) and non empty", sal_False
, new OString(),
362 new OString(kTestStr2
)},
363 {"non empty and empty(def. constructor)", sal_False
,
364 new OString(kTestStr1
),new OString()},
365 {"two empty strings(string arg = '\\0')", sal_True
,
366 new OString(""),new OString("")},
367 {"empty(string arg = '\\0') and non empty", sal_False
,
368 new OString(""),new OString(kTestStr2
)},
369 {"non empty and empty(string arg = '\\0')", sal_False
,
370 new OString(kTestStr1
),new OString("")}
373 sal_Bool res
= sal_True
;
376 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
379 ( arrTestCase
[i
].input1
->equals(*(arrTestCase
[i
].input2
)) ==
380 arrTestCase
[i
].expVal
);
386 arrTestCase
[i
].comments
,
387 createName( pMeth
, "equals", i
)
392 c_rtl_tres_state_end(hRtlTestResult
, "equals");
396 //------------------------------------------------------------------------
397 // testing the method equalsIgnoreAsciiCase( const OString & aStr )
398 //------------------------------------------------------------------------
400 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_equalsIgnoreAsciiCase(
401 hTestResult hRtlTestResult
)
403 sal_Char methName
[MAXBUFLENGTH
];
404 sal_Char
* pMeth
= methName
;
406 c_rtl_tres_state_start(hRtlTestResult
, "equalsIgnoreAsciiCase");
407 typedef struct TestCase
413 ~TestCase() { delete input1
;delete input2
;}
416 TestCase arrTestCase
[]={
417 {"same strings but different cases",sal_True
,new OString(kTestStr4
),
418 new OString(kTestStr5
)},
419 {"same strings",sal_True
,new OString(kTestStr4
),
420 new OString(kTestStr4
)},
421 {"with equal beginning",sal_False
,new OString(kTestStr2
),
422 new OString(kTestStr4
)},
423 {"empty(def.constructor) and non empty",sal_False
,new OString(),
424 new OString(kTestStr5
)},
425 {"non empty and empty(def.constructor)",sal_False
,
426 new OString(kTestStr4
), new OString()},
427 {"two empty strings(def.constructor)",sal_True
,new OString(),
429 {"different strings with equal length",sal_False
,
430 new OString(kTestStr10
), new OString(kTestStr11
)}
433 sal_Bool res
= sal_True
;
436 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
439 (arrTestCase
[i
].input1
->equalsIgnoreAsciiCase(*arrTestCase
[i
].input2
)
440 == arrTestCase
[i
].expVal
);
446 arrTestCase
[i
].comments
,
447 createName( pMeth
, "equalsIgnoreAsciiCase", i
)
452 c_rtl_tres_state_end(hRtlTestResult
, "equalsIgnoreAsciiCase");
457 static sal_Bool SAL_CALL
test_rtl_OString_compareTo_001(
458 hTestResult hRtlTestResult
)
460 sal_Char methName
[MAXBUFLENGTH
];
461 sal_Char
* pMeth
= methName
;
463 typedef struct TestCase
469 ~TestCase() { delete input1
;delete input2
;}
472 TestCase arrTestCase
[]={
474 {"simple compare, str1 to str5",-1,new OString(kTestStr1
),
475 new OString(kTestStr5
)},
476 {"simple compare, str2 to str5",-1,new OString(kTestStr2
),
477 new OString(kTestStr5
)},
478 {"simple compare, str1 to str9",-1,new OString(kTestStr1
),
479 new OString(kTestStr9
)},
480 {"simple compare, str1 to str2",-1,new OString(kTestStr1
),
481 new OString(kTestStr2
)},
482 {"simple compare, str4 to str5",-1,new OString(kTestStr4
),
483 new OString(kTestStr5
)},
484 {"simple compare, str1 to str3",-1,new OString(kTestStr1
),
485 new OString(kTestStr3
)},
486 {"simple compare, str5 to str1",+1,new OString(kTestStr5
),
487 new OString(kTestStr1
)},
488 {"simple compare, str2 to str1",+1,new OString(kTestStr2
),
489 new OString(kTestStr1
)},
490 {"simple compare, str9 to str5",+1,new OString(kTestStr9
),
491 new OString(kTestStr5
)},
492 {"simple compare, str5 to str4",+1,new OString(kTestStr5
),
493 new OString(kTestStr4
)},
494 {"simple compare, str1 to str1",0,new OString(kTestStr1
),
495 new OString(kTestStr1
)},
496 {"simple compare, nullString to nullString",0,new OString(),
498 {"simple compare, nullString to str2",-1,new OString(),
499 new OString(kTestStr2
)},
500 {"simple compare, str1 to nullString",+1,new OString(kTestStr1
),
504 sal_Bool res
= sal_True
;
507 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
510 arrTestCase
[i
].input1
->compareTo(*arrTestCase
[i
].input2
);
511 cmpRes
= ( cmpRes
== 0 ) ? 0 : ( cmpRes
> 0 ) ? +1 : -1 ;
512 sal_Bool lastRes
= ( cmpRes
== arrTestCase
[i
].expVal
);
518 arrTestCase
[i
].comments
,
519 createName( pMeth
, "compareTo(const OString&)", i
)
529 //------------------------------------------------------------------------
530 // testing the method compareTo( const OString & rObj, sal_Int32 length )
531 //------------------------------------------------------------------------
532 static sal_Bool SAL_CALL
test_rtl_OString_compareTo_002(
533 hTestResult hRtlTestResult
)
535 sal_Char methName
[MAXBUFLENGTH
];
536 sal_Char
* pMeth
= methName
;
538 typedef struct TestCase
545 ~TestCase() { delete input1
;delete input2
;}
548 TestCase arrTestCase
[] =
550 {"compare with maxlength, str1 to str9, 16",-1,16,
551 new OString(kTestStr1
), new OString(kTestStr9
)},
552 {"compare with maxlength, str2 to str9, 32",-1,32,
553 new OString(kTestStr2
), new OString(kTestStr9
)},
554 {"compare with maxlength, str9 to str4, 16",+1,16,
555 new OString(kTestStr9
), new OString(kTestStr4
)},
556 {"compare with maxlength, str9 to str22, 32",+1,32,
557 new OString(kTestStr9
), new OString(kTestStr22
)},
558 {"compare with maxlength, str9 to str5, 16",0,16,
559 new OString(kTestStr9
), new OString(kTestStr5
)},
560 {"compare with maxlength, str9 to str9, 32",0,32,
561 new OString(kTestStr9
), new OString(kTestStr9
)},
562 {"compare with maxlength, str1 to str2, 32",-1,32,
563 new OString(kTestStr1
), new OString(kTestStr2
)},
564 {"compare with maxlength, str1 to str2, 32",-1,32,
565 new OString(kTestStr1
), new OString(kTestStr2
)}
568 sal_Bool res
= sal_True
;
571 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
574 arrTestCase
[i
].input1
->compareTo(*arrTestCase
[i
].input2
,
575 arrTestCase
[i
].maxLength
);
576 cmpRes
= (cmpRes
== 0) ? 0 : (cmpRes
> 0) ? +1 : -1 ;
577 sal_Bool lastRes
= (cmpRes
== arrTestCase
[i
].expVal
);
583 arrTestCase
[i
].comments
,
584 createName( pMeth
, "compareTo(const OString&, sal_Int32)", i
)
593 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_compareTo(
594 hTestResult hRtlTestResult
)
596 c_rtl_tres_state_start(hRtlTestResult
, "compareTo");
597 sal_Bool res
= test_rtl_OString_compareTo_001(hRtlTestResult
);
598 res
&= test_rtl_OString_compareTo_002(hRtlTestResult
);
599 c_rtl_tres_state_end(hRtlTestResult
, "compareTo");
603 //------------------------------------------------------------------------
604 // testing the operator == ( const OString& rStr1, const OString& rStr2 )
605 // testing the operator == ( const OString& rStr1, const sal_Char *rStr2 )
606 // testing the operator == ( const sal_Char *rStr1, const OString& rStr2 )
607 //------------------------------------------------------------------------
608 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_cmp(
609 hTestResult hRtlTestResult
)
611 c_rtl_tres_state_start(hRtlTestResult
, "op_cmp");
612 const sal_Int16 NCASES
= 7;
613 sal_Char methName
[MAXBUFLENGTH
];
614 sal_Char
* pMeth
= methName
;
615 const sal_Char
*arrOStr
[NCASES
][2] =
617 {kTestStr1
, kTestStr1
},
618 {kTestStr1
, kTestStr3
},
619 {kTestStr1
, kTestStr2
},
626 sal_Bool arrExpVal
[NCASES
] =
637 sal_Char
*arrComments
[NCASES
] =
639 "'Sun Microsystems'=='Sun Microsystems'",
640 "!('Sun Microsystems'=='Sun microsystems')",
641 "!('Sun Microsystems'=='Sun Microsystems Java Technology')",
642 "two empty strings(def.constructor)",
643 "!(empty string=='Sun Microsystems Java Technology')",
644 "!('Sun Microsystems Java Technology'==empty string)",
648 sal_Bool res
= sal_True
;
651 for(i
= 0; i
< NCASES
; i
++)
653 OString
*str1
, *str2
;
654 str1
= (arrOStr
[i
][0]) ? new OString(arrOStr
[i
][0]) : new OString() ;
655 str2
= (arrOStr
[i
][1]) ? new OString(arrOStr
[i
][1]) : new OString() ;
657 sal_Bool cmpRes
= (*str1
== *str2
);
658 sal_Bool lastRes
= (cmpRes
== arrExpVal
[i
]);
666 createName( pMeth
, "operator ==(OString&, OString&)", i
)
669 cmpRes
= (*str1
== arrOStr
[i
][1]);
670 lastRes
= (cmpRes
== arrExpVal
[i
]);
677 createName( pMeth
, "operator ==(OString&, sal_Char *)", i
)
680 cmpRes
= (arrOStr
[i
][0] == *str2
);
681 lastRes
= (cmpRes
== arrExpVal
[i
]);
688 createName( pMeth
, "operator ==(sal_Char *, OString&)", i
)
695 c_rtl_tres_state_end(hRtlTestResult
, "op_cmp");
699 //------------------------------------------------------------------------
700 // testing the operator != (const OString& rStr1, const OString& rStr2)
701 // testing the operator != (const OString& rStr1, const sal_Char *rStr2)
702 // testing the operator != (const sal_Char *rStr1, const OString& rStr2)
703 //------------------------------------------------------------------------
704 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_neq(
705 hTestResult hRtlTestResult
)
707 c_rtl_tres_state_start(hRtlTestResult
, "op_neq");
708 const sal_Int16 NCASES
= 6;
709 sal_Char methName
[MAXBUFLENGTH
];
710 sal_Char
* pMeth
= methName
;
712 const sal_Char
*arrOStr
[NCASES
][2] =
714 {kTestStr1
, kTestStr3
},
715 {kTestStr1
, kTestStr2
},
716 {kTestStr1
, kTestStr1
},
722 sal_Bool arrExpVal
[NCASES
] =
732 sal_Char
*arrComments
[NCASES
] =
734 "'Sun Microsystems'!='Sun microsystems'",
735 "'Sun Microsystems'!='Sun Microsystems Java Technology'",
736 "!('Sun Microsystems'!='Sun Microsystems')",
737 "empty string!='Sun Microsystems Java Technology'",
738 "'Sun Microsystems Java Technology'!=empty string", "!(''!='')"
741 sal_Bool res
= sal_True
;
744 for(i
= 0; i
< NCASES
; i
++)
746 OString
*str1
, *str2
;
747 str1
= (arrOStr
[i
][0]) ? new OString(arrOStr
[i
][0]) : new OString() ;
748 str2
= (arrOStr
[i
][1]) ? new OString(arrOStr
[i
][1]) : new OString() ;
750 sal_Bool cmpRes
= (*str1
!= *str2
);
751 sal_Bool lastRes
= (cmpRes
== arrExpVal
[i
]);
758 createName( pMeth
, "operator !=(OString&, OString&)", i
)
761 cmpRes
= (*str1
!= arrOStr
[i
][1]);
762 lastRes
= (cmpRes
== arrExpVal
[i
]);
769 createName( pMeth
, "operator !=(OString&, sal_Char *)", i
)
772 cmpRes
= (arrOStr
[i
][0] != *str2
);
773 lastRes
= (cmpRes
== arrExpVal
[i
]);
780 createName( pMeth
, "operator !=(sal_Char *, OString&)", i
)
787 c_rtl_tres_state_end(hRtlTestResult
, "op_neq");
792 //------------------------------------------------------------------------
793 // testing the operator > (const OString& rStr1, const OString& rStr2)
794 //------------------------------------------------------------------------
795 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_g(
796 hTestResult hRtlTestResult
)
798 sal_Char methName
[MAXBUFLENGTH
];
799 sal_Char
* pMeth
= methName
;
801 c_rtl_tres_state_start(hRtlTestResult
, "op_g");
802 typedef struct TestCase
808 ~TestCase() { delete input1
;delete input2
;}
811 TestCase arrTestCase
[] =
813 { "'Sun microsystems'>'Sun Microsystems'",sal_True
,
814 new OString(kTestStr3
), new OString(kTestStr1
)},
815 {"!('Sun Microsystems'>'Sun microsystems')",sal_False
,
816 new OString(kTestStr1
), new OString(kTestStr3
)},
817 {"'Sun Microsystems Java Technology'>'Sun Microsystems'",sal_True
,
818 new OString(kTestStr2
), new OString(kTestStr1
)},
819 {"!('Sun Microsystems'>'Sun Microsystems Java Technology')",sal_False
,
820 new OString(kTestStr1
), new OString(kTestStr2
)},
821 {"!('Sun Microsystems'>'Sun Microsystems'",sal_False
,
822 new OString(kTestStr1
), new OString(kTestStr1
)},
823 {"'Sun Microsystems'>''",sal_True
,new OString(kTestStr1
),
825 {"!(''>'Sun Microsystems')",sal_False
,new OString(),
826 new OString(kTestStr1
)},
827 {"!(''>'')",sal_False
,new OString(), new OString()}
830 sal_Bool res
= sal_True
;
833 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
835 sal_Bool cmpRes
= (*arrTestCase
[i
].input1
> *arrTestCase
[i
].input2
);
836 sal_Bool lastRes
= (cmpRes
== arrTestCase
[i
].expVal
);
842 arrTestCase
[i
].comments
,
843 createName( pMeth
, "operator >", i
)
850 c_rtl_tres_state_end(hRtlTestResult
, "op_g");
854 //------------------------------------------------------------------------
855 // testing the operator < (const OString& rStr1, const OString& rStr2)
856 //------------------------------------------------------------------------
858 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_l(
859 hTestResult hRtlTestResult
)
861 sal_Char methName
[MAXBUFLENGTH
];
862 sal_Char
* pMeth
= methName
;
864 c_rtl_tres_state_start(hRtlTestResult
, "op_l");
865 typedef struct TestCase
871 ~TestCase() { delete input1
;delete input2
;}
874 TestCase arrTestCase
[] =
876 {"!('Sun microsystems'<'Sun Microsystems')",sal_False
,
877 new OString(kTestStr3
), new OString(kTestStr1
)},
878 {"'Sun Microsystems'<'Sun microsystems'",sal_True
,
879 new OString(kTestStr1
), new OString(kTestStr3
)},
880 {"'Sun Microsystems'<'Sun Microsystems Java Technology'",sal_True
,
881 new OString(kTestStr1
), new OString(kTestStr2
)},
882 {"!('Sun Microsystems Java Technology'<'Sun Microsystems')",sal_False
,
883 new OString(kTestStr2
), new OString(kTestStr1
)},
884 {"!('Sun Microsystems'<'Sun Microsystems'", sal_False
,
885 new OString(kTestStr1
), new OString(kTestStr1
)},
886 {"'Sun Microsystems'<''",sal_False
,new OString(kTestStr1
),
888 {"''<'Sun Microsystems Java Technology'",sal_True
,new OString(),
889 new OString(kTestStr2
)},
890 {"!(''<'')",sal_False
,new OString(), new OString()}
893 sal_Bool res
= sal_True
;
896 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
898 sal_Bool cmpRes
= (*arrTestCase
[i
].input1
< *arrTestCase
[i
].input2
);
899 sal_Bool lastRes
= (cmpRes
== arrTestCase
[i
].expVal
);
905 arrTestCase
[i
].comments
,
906 createName( pMeth
, "operator <", i
)
913 c_rtl_tres_state_end(hRtlTestResult
, "op_l");
917 //------------------------------------------------------------------------
918 // testing the operator >= (const OString& rStr1, const OString& rStr2)
919 //------------------------------------------------------------------------
920 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_ge(
921 hTestResult hRtlTestResult
)
923 sal_Char methName
[MAXBUFLENGTH
];
924 sal_Char
* pMeth
= methName
;
926 c_rtl_tres_state_start(hRtlTestResult
, "op_ge");
927 typedef struct TestCase
933 ~TestCase() { delete input1
;delete input2
;}
936 TestCase arrTestCase
[] =
938 {"'Sun microsystems'>='Sun Microsystems'",sal_True
,
939 new OString(kTestStr3
), new OString(kTestStr1
)},
940 {"!('Sun Microsystems'>='Sun microsystems')",sal_False
,
941 new OString(kTestStr1
), new OString(kTestStr3
)},
942 {"!('Sun Microsystems'>='Sun Microsystems Java Technology')",sal_False
,
943 new OString(kTestStr1
), new OString(kTestStr2
)},
944 {"'Sun Microsystems Java Technology'>='Sun Microsystems'",sal_True
,
945 new OString(kTestStr2
), new OString(kTestStr1
)},
946 {"'Sun Microsystems'>='Sun Microsystems'", sal_True
,
947 new OString(kTestStr1
), new OString(kTestStr1
)},
948 {"'Sun Microsystems'>=''",sal_True
,new OString(kTestStr1
),
950 { "''>='Sun microsystems'",sal_False
,new OString(),
951 new OString(kTestStr3
)},
952 {"''>=''",sal_True
,new OString(), new OString()}
955 sal_Bool res
= sal_True
;
958 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
960 sal_Bool cmpRes
= (*arrTestCase
[i
].input1
>= *arrTestCase
[i
].input2
);
961 sal_Bool lastRes
= (cmpRes
== arrTestCase
[i
].expVal
);
967 arrTestCase
[i
].comments
,
968 createName( pMeth
, "operator >=", i
)
975 c_rtl_tres_state_end(hRtlTestResult
, "op_ge");
979 //------------------------------------------------------------------------
980 // testing the operator <= (const OString& rStr1, const OString& rStr2)
981 //------------------------------------------------------------------------
982 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_le(
983 hTestResult hRtlTestResult
)
985 sal_Char methName
[MAXBUFLENGTH
];
986 sal_Char
* pMeth
= methName
;
988 c_rtl_tres_state_start(hRtlTestResult
, "op_le");
989 typedef struct TestCase
995 ~TestCase() { delete input1
;delete input2
;}
998 TestCase arrTestCase
[] =
1000 {"!('Sun microsystems'<='Sun Microsystems')",sal_False
,
1001 new OString(kTestStr3
), new OString(kTestStr1
)},
1002 {"'Sun Microsystems'<='Sun microsystems'",sal_True
,
1003 new OString(kTestStr1
), new OString(kTestStr3
)},
1004 {"'Sun Microsystems'<='Sun Microsystems Java Technology'",sal_True
,
1005 new OString(kTestStr1
),
1006 new OString(kTestStr2
)},
1007 {"!('Sun Microsystems Java Technology'<='Sun Microsystems')",sal_False
,
1008 new OString(kTestStr2
),
1009 new OString(kTestStr1
)},
1010 {"!('Sun Microsystems'<='Sun Microsystems'", sal_True
,
1011 new OString(kTestStr1
), new OString(kTestStr1
)},
1012 {"'Sun Microsystems'<=''",sal_False
,new OString(kTestStr1
),
1014 {"''<='Sun Microsystems Java Technology'",sal_True
,new OString(),
1015 new OString(kTestStr2
)},
1016 {"!(''<='')",sal_True
,new OString(), new OString()}
1019 sal_Bool res
= sal_True
;
1022 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1024 sal_Bool cmpRes
= (*arrTestCase
[i
].input1
<= *arrTestCase
[i
].input2
);
1025 sal_Bool lastRes
= (cmpRes
== arrTestCase
[i
].expVal
);
1031 arrTestCase
[i
].comments
,
1032 createName( pMeth
, "operator <=", i
)
1039 c_rtl_tres_state_end(hRtlTestResult
, "op_le");
1044 //------------------------------------------------------------------------
1045 // testing the operator =
1046 //------------------------------------------------------------------------
1047 static sal_Bool
test_rtl_OString_op_eq_001( hTestResult hRtlTestResult
)
1049 sal_Char methName
[MAXBUFLENGTH
];
1050 sal_Char
* pMeth
= methName
;
1052 typedef struct TestCase
1058 ~TestCase() { delete input1
;delete input2
;}
1061 TestCase arrTestCase
[] =
1063 {"'' = str1, str1 == str2",sal_True
,new OString(kTestStr1
),
1065 {"str1 = str2, str1 == str2",sal_True
,new OString(kTestStr1
),
1066 new OString(kTestStr6
)},
1067 {"str2 = '', str1 == str2",sal_True
,new OString(),
1068 new OString(kTestStr2
)},
1069 {"'' = '', str1 == str2",sal_True
,new OString(),
1073 sal_Bool res
= sal_True
;
1076 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1078 *(arrTestCase
[i
].input1
) = *(arrTestCase
[i
].input2
);
1081 (*(arrTestCase
[i
].input1
) == *(arrTestCase
[i
].input2
));
1082 sal_Bool lastRes
= (cmpRes
== arrTestCase
[i
].expVal
);
1088 arrTestCase
[i
].comments
,
1089 createName( pMeth
, "operator =", i
)
1098 static sal_Bool
test_rtl_OString_op_eq_002(
1099 hTestResult hRtlTestResult
)
1101 ::rtl::OString aStr
;
1102 aStr
= OString(kTestStr1
);
1110 "str = OString(\"%s\"), str == \"%s\"",
1116 static sal_Bool
test_rtl_OString_op_eq_003(
1117 hTestResult hRtlTestResult
)
1119 sal_Bool bTCState
= false;
1121 ::rtl::OString
aStr1(kTestStr1
);
1122 ::rtl::OString aStr2
;
1123 ::rtl::OString aStr3
;
1125 aStr3
= aStr2
= aStr1
;
1127 bTCState
= ( aStr1
== aStr2
)
1128 && ( aStr1
== aStr3
)
1129 && ( aStr2
== aStr3
);
1135 "str3=str2=str1,(str1 == str2)&&(str1 == str3)&&(str2 == str3)",
1142 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_eq(
1143 hTestResult hRtlTestResult
)
1145 c_rtl_tres_state_start(hRtlTestResult
, "op_eq");
1146 sal_Bool res
= test_rtl_OString_op_eq_001( hRtlTestResult
);
1147 res
&= test_rtl_OString_op_eq_002( hRtlTestResult
);
1148 res
&= test_rtl_OString_op_eq_003( hRtlTestResult
);
1149 c_rtl_tres_state_end(hRtlTestResult
, "op_eq");
1154 //------------------------------------------------------------------------
1155 // testing the operator +
1156 //------------------------------------------------------------------------
1157 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_plus(
1158 hTestResult hRtlTestResult
)
1160 sal_Char methName
[MAXBUFLENGTH
];
1161 sal_Char
* pMeth
= methName
;
1163 c_rtl_tres_state_start(hRtlTestResult
, "op_plus");
1164 typedef struct TestCase
1170 ~TestCase() { delete input1
;delete input2
; delete expVal
;}
1173 TestCase arrTestCase
[] =
1175 {"str1 = str7 + str8",new OString(kTestStr1
),
1176 new OString(kTestStr7
), new OString(kTestStr8
)},
1177 {"str1 = str1 + '' ",new OString(kTestStr1
),
1178 new OString(kTestStr1
), new OString("")},
1179 {"str1 = '' + str1", new OString(kTestStr1
),
1180 new OString(""), new OString(kTestStr1
)},
1181 {" '' = '' + '' ", new OString(""),new OString(""),
1183 {"str1 = str1 + def.constr", new OString(kTestStr1
),
1184 new OString(kTestStr1
), new OString()},
1185 {" str1 = def.constr + str1 ",new OString(kTestStr1
),
1186 new OString(), new OString(kTestStr1
)},
1187 {" def.constr= def.constr + def.constr", new OString(),
1188 new OString(), new OString()}
1191 sal_Bool res
= sal_True
;
1193 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1195 OString str
= (*arrTestCase
[i
].input1
) + (*arrTestCase
[i
].input2
);
1196 sal_Bool lastRes
= (str
== *arrTestCase
[i
].expVal
);
1202 arrTestCase
[i
].comments
,
1203 createName( pMeth
, "operator +", i
)
1210 c_rtl_tres_state_end(hRtlTestResult
, "op_plus");
1214 //------------------------------------------------------------------------
1215 // testing the operator +=
1216 //------------------------------------------------------------------------
1217 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_peq(
1218 hTestResult hRtlTestResult
)
1220 sal_Char methName
[MAXBUFLENGTH
];
1221 sal_Char
* pMeth
= methName
;
1223 c_rtl_tres_state_start(hRtlTestResult
, "op_peq");
1224 typedef struct TestCase
1230 ~TestCase() { delete input1
;delete input2
; delete expVal
;}
1233 TestCase arrTestCase
[] =
1235 {"str1 == (str7 += str8)",new OString(kTestStr1
),
1236 new OString(kTestStr7
), new OString(kTestStr8
)},
1237 {"str1 == (str1 += '')",new OString(kTestStr1
),
1238 new OString(kTestStr1
), new OString("")},
1239 {"str1 == ('' += str1)", new OString(kTestStr1
),
1240 new OString(""), new OString(kTestStr1
)},
1241 {" '' == ('' += '')", new OString(""),
1242 new OString(""), new OString("")},
1243 {"str1 == (str1 += def.constr)", new OString(kTestStr1
),
1244 new OString(kTestStr1
), new OString()},
1245 {" str1 == (def.constr += str1)",new OString(kTestStr1
),
1246 new OString(), new OString(kTestStr1
)},
1247 {" def.constr== (def.constr += def.constr)",
1248 new OString(),new OString(), new OString()}
1251 sal_Bool res
= sal_True
;
1253 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1255 str
+= (*arrTestCase
[i
].input1
); str
+= (*arrTestCase
[i
].input2
);
1256 sal_Bool lastRes
= (str
== *arrTestCase
[i
].expVal
);
1262 arrTestCase
[i
].comments
,
1263 createName( pMeth
, "operator +", i
)
1270 c_rtl_tres_state_end(hRtlTestResult
, "op_peq");
1274 //------------------------------------------------------------------------
1275 // testing the operator const sal_Char * (cscs for short)
1276 //------------------------------------------------------------------------
1277 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_op_cscs(
1278 hTestResult hRtlTestResult
)
1280 sal_Char methName
[MAXBUFLENGTH
];
1281 sal_Char
* pMeth
= methName
;
1283 c_rtl_tres_state_start(hRtlTestResult
, "op_cscs");
1284 typedef struct TestCase
1287 const sal_Char
* expVal
;
1290 ~TestCase() { delete input1
;}
1293 TestCase arrTestCase
[] =
1295 {"test normal string",kTestStr1
,kTestStr1Len
,new OString(kTestStr1
)},
1296 {"test empty string","",1,new OString()}
1299 sal_Bool res
= sal_True
;
1301 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1303 const sal_Char
* pstr
= (*arrTestCase
[i
].input1
);
1305 res
&= c_rtl_tres_state
1308 cmpstr((sal_Char
*)pstr
,(sal_Char
*)arrTestCase
[i
].expVal
,
1309 arrTestCase
[i
].cmpLen
),
1310 arrTestCase
[i
].comments
,
1311 createName( pMeth
, "const sal_Char*", i
)
1314 c_rtl_tres_state_end(hRtlTestResult
, "op_cscs");
1319 //------------------------------------------------------------------------
1320 // testing the method getStr()
1321 //------------------------------------------------------------------------
1324 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_getStr(
1325 hTestResult hRtlTestResult
)
1327 sal_Char methName
[MAXBUFLENGTH
];
1328 sal_Char
* pMeth
= methName
;
1330 c_rtl_tres_state_start(hRtlTestResult
, "getStr");
1331 typedef struct TestCase
1334 const sal_Char
* expVal
;
1337 ~TestCase() { delete input1
;}
1340 TestCase arrTestCase
[] =
1342 {"test normal string",kTestStr1
,kTestStr1Len
,new OString(kTestStr1
)},
1343 {"test empty string","",0,new OString()}
1346 sal_Bool res
= sal_True
;
1348 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1350 const sal_Char
* pstr
= arrTestCase
[i
].input1
->getStr();
1351 res
&= c_rtl_tres_state
1354 cmpstr(pstr
, arrTestCase
[i
].expVal
,
1355 arrTestCase
[i
].cmpLen
),
1356 arrTestCase
[i
].comments
,
1357 createName( pMeth
, "getStr", i
)
1360 c_rtl_tres_state_end(hRtlTestResult
, "getStr");
1366 //------------------------------------------------------------------------
1367 // testing the method copy( sal_Int32 beginIndex )
1368 //------------------------------------------------------------------------
1369 static sal_Bool SAL_CALL
test_rtl_OString_copy_001(
1370 hTestResult hRtlTestResult
)
1372 sal_Char methName
[MAXBUFLENGTH
];
1373 sal_Char
* pMeth
= methName
;
1375 typedef struct TestCase
1378 const sal_Char
* srcStr
;
1379 const sal_Char
* arrExpStr
;
1380 // string for comparing with result
1381 sal_Int32 beginIndex
;
1382 // beginIndex for the method copy
1383 sal_Int32 lengthForCmp
;
1384 // number of symbols for comparing
1385 // (if value is equal to 0 then pointers to buffers must be equal)
1386 sal_Int32 expLength
;
1387 //expected length of the result string
1390 TestCase arrTestCase
[] =
1392 {"beginIndex == 0 ( whole string )", kTestStr2
,kTestStr2
,
1393 0, kTestStr2Len
, kTestStr2Len
},
1394 {"beginIndex == strlen-2 ( last two char )", kTestStr2
,"gy",
1395 kTestStr2Len
-2, 2, 2},
1396 {"beginIndex == strlen-1( last char )", kTestStr2
, "y",
1397 kTestStr2Len
-1, 1, 1}
1400 sal_Bool res
= sal_True
;
1403 for(i
= 0; i
<(sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1405 OString
src(arrTestCase
[i
].srcStr
);
1407 // rtl_String* pDataSrc = src.pData;
1409 dst
= src
.copy(arrTestCase
[i
].beginIndex
);
1411 // rtl_String* pDataDst = dst.pData;
1415 lastRes
= (dst
== arrTestCase
[i
].arrExpStr
);
1422 arrTestCase
[i
].comments
,
1424 "copy_001(beginIndex)(check buffer and length)", i
)
1435 //------------------------------------------------------------------------
1436 // testing the method copy( sal_Int32 beginIndex, sal_Int32 count )
1437 //------------------------------------------------------------------------
1438 static sal_Bool SAL_CALL
test_rtl_OString_copy_002(
1439 hTestResult hRtlTestResult
)
1441 sal_Char methName
[MAXBUFLENGTH
];
1442 sal_Char
* pMeth
= methName
;
1444 typedef struct TestCase
1447 const sal_Char
* arrExpStr
;
1448 sal_Int32 beginIndex
;
1454 TestCase arrTestCase
[] ={
1456 {"copy substring", kTestStr6
, kTestStr11Len
, kTestStr2Len
- kTestStr11Len
,kTestStr6Len
},
1457 /* LLA: it is a bug, beginIndex + count > kTestStr2.getLength() */
1458 /* {"copy normal substring with incorrect count",kTestStr6, kTestStr11Len, 31, 15}, */
1459 {"copy whole string", kTestStr2
, 0, kTestStr2Len
, kTestStr2Len
},
1460 /* {"copy whole string with incorrect count larger than len and index 0", kTestStr2, 0, 40, 32}, */
1461 /* LLA: bug beginIndex + count > kTestStr2 {"copy last character", "y",kTestStr2Len - 1, 31,1}, */
1462 {"copy last character", "y",kTestStr2Len
- 1, 1,1},
1463 /* LLA: bug, beginIndex > kTestStr2 {"beginindex larger than len","",60, 0,0}, */
1464 {"beginindex exact as large as it's length","",kTestStr2Len
, 0,0}
1465 /* LLA: bug, negative count is not allowed. {"count is nagative int","",3, -1,0} */
1467 sal_Bool res
= sal_True
;
1470 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++) {
1471 OString
src(kTestStr2
);
1473 dst
= src
.copy(arrTestCase
[i
].beginIndex
, arrTestCase
[i
].count
);
1474 // rtl_String* pDataSrc = src.pData;
1475 // rtl_String* pDataDst = dst.pData;
1477 sal_Bool lastRes
=sal_True
;
1478 // checks buffer and length
1479 //t_print("this is copy__002 #%d\n", i);
1480 //t_print("dst buffer =%s\n", pDataDst->buffer);
1481 //t_print("expStr =%s\n", arrTestCase[i].arrExpStr);
1482 //t_print("dst length =%d\n", pDataDst->length);
1483 //t_print("count =%d\n", arrTestCase[i].count);
1484 //t_print("expLen =%d\n", arrTestCase[i].expLen);
1486 lastRes
= (dst
.equals(arrTestCase
[i
].arrExpStr
)) ? sal_True
: sal_False
;
1492 arrTestCase
[i
].comments
,
1494 "copy_002(beginIndex,count)(check buffer and length)", i
)
1505 static sal_Bool SAL_CALL
test_rtl_OString_copy_003(
1506 hTestResult hRtlTestResult
)
1508 sal_Bool res
= sal_True
;
1509 char comment
[] = "copy whole short string to long string";
1511 OString
src(kTestStr1
);
1512 // rtl_String* pDataSrc = src.pData;
1513 OString
dst(kTestStr2
);
1516 // rtl_String* pDataDst = dst.pData;
1517 //check buffer and length
1518 sal_Bool lastRes
=(dst
==src
);
1524 "copy_003(beginIndex)(check buffer and length)"
1532 static sal_Bool SAL_CALL
test_rtl_OString_copy_004(
1533 hTestResult hRtlTestResult
)
1535 sal_Bool res
= sal_True
;
1536 sal_Char comment
[] = "copy whole long string to short string";
1538 OString
src(kTestStr2
);
1539 // rtl_String* pDataSrc = src.pData;
1540 OString
dst(kTestStr1
);
1543 // rtl_String* pDataDst = dst.pData;
1544 //check buffer and length
1545 sal_Bool lastRes
=(dst
==src
);
1551 "copy_004(beginIndex)(check buffer and length)"
1558 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_copy(
1559 hTestResult hRtlTestResult
)
1561 c_rtl_tres_state_start(hRtlTestResult
, "copy");
1562 sal_Bool res
= test_rtl_OString_copy_001(hRtlTestResult
);
1563 res
&= test_rtl_OString_copy_002(hRtlTestResult
);
1564 res
&= test_rtl_OString_copy_003(hRtlTestResult
);
1565 res
&= test_rtl_OString_copy_004(hRtlTestResult
);
1566 c_rtl_tres_state_end(hRtlTestResult
, "copy");
1571 //------------------------------------------------------------------------
1572 // testing the method concat( const OString & aStr )
1573 //------------------------------------------------------------------------
1574 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_concat(
1575 hTestResult hRtlTestResult
)
1577 sal_Char methName
[MAXBUFLENGTH
];
1578 sal_Char
* pMeth
=methName
;
1580 c_rtl_tres_state_start(hRtlTestResult
, "concat");
1581 typedef struct TestCase
1587 ~TestCase() { delete input1
;delete input2
; delete expVal
;}
1590 TestCase arrTestCase
[] =
1592 {"concatenates two strings",new OString(kTestStr1
),
1593 new OString(kTestStr7
),
1594 new OString(kTestStr8
)},
1595 {"concatenates empty string",new OString(kTestStr1
),
1596 new OString(kTestStr1
),
1598 {"concatenates to empty string",new OString(kTestStr1
),
1600 new OString(kTestStr1
)},
1601 {"concatenates two empty strings",new OString(""),new OString(""),
1603 {"concatenates string constructed by default constructor",
1604 new OString(kTestStr1
),
1605 new OString(kTestStr1
), new OString()},
1606 {"concatenates to string constructed by default constructor",
1607 new OString(kTestStr1
),
1608 new OString(), new OString(kTestStr1
)},
1609 {"concatenates two strings constructed by default constructor",
1611 new OString(), new OString()}
1614 sal_Bool res
= sal_True
;
1616 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1619 arrTestCase
[i
].input1
->concat(*arrTestCase
[i
].input2
);
1620 sal_Bool lastRes
= (str
== *arrTestCase
[i
].expVal
);
1626 arrTestCase
[i
].comments
,
1627 createName( pMeth
, "concat", i
)
1634 c_rtl_tres_state_end(hRtlTestResult
, "concat");
1639 //------------------------------------------------------------------------
1640 // testing the method toAsciiLowerCase()
1641 //-----------------------------------------------------------------------
1642 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_toAsciiLowerCase(
1643 hTestResult hRtlTestResult
)
1645 sal_Char methName
[MAXBUFLENGTH
];
1646 sal_Char
* pMeth
=methName
;
1648 c_rtl_tres_state_start(hRtlTestResult
, "toAsciiLowerCase");
1649 typedef struct TestCase
1654 ~TestCase() { delete input1
; delete expVal
;}
1657 TestCase arrTestCase
[] =
1660 {"only uppercase",new OString(kTestStr5
),new OString(kTestStr4
)},
1661 {"different cases",new OString(kTestStr5
),new OString(kTestStr1
)},
1662 {"different cases",new OString(kTestStr5
),new OString(kTestStr3
)},
1663 {"only lowercase",new OString(kTestStr5
),new OString(kTestStr5
)},
1664 {"empty string",new OString(""),new OString("")},
1665 {"string constructed by default constructor",
1666 new OString(),new OString()}
1669 sal_Bool res
= sal_True
;
1672 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1674 OString str
= arrTestCase
[i
].input1
->toAsciiLowerCase();
1675 sal_Bool lastRes
= (str
==* arrTestCase
[i
].expVal
);
1681 arrTestCase
[i
].comments
,
1682 createName( pMeth
, "toAsciiLowerCase", i
)
1688 c_rtl_tres_state_end(hRtlTestResult
, "toAsciiLowerCase");
1692 //------------------------------------------------------------------------
1693 // testing the method toAsciiUpperCase()
1694 //------------------------------------------------------------------------
1695 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_toAsciiUpperCase(
1696 hTestResult hRtlTestResult
)
1698 sal_Char methName
[MAXBUFLENGTH
];
1699 sal_Char
* pMeth
=methName
;
1701 c_rtl_tres_state_start(hRtlTestResult
, "toAsciiUpperCase");
1702 typedef struct TestCase
1707 ~TestCase() { delete input1
; delete expVal
;}
1710 TestCase arrTestCase
[] =
1712 {"only lowercase",new OString(kTestStr4
),new OString(kTestStr5
)},
1713 {"mixed cases",new OString(kTestStr4
),new OString(kTestStr3
)},
1714 {"miced cases",new OString(kTestStr4
),new OString(kTestStr1
)},
1715 {"only uppercase",new OString(kTestStr4
),new OString(kTestStr4
)},
1716 {"empty string",new OString(""),new OString("")},
1717 {"string constructed by default constructor",
1718 new OString(),new OString()}
1721 sal_Bool res
= sal_True
;
1724 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1726 OString str
= arrTestCase
[i
].input1
->toAsciiUpperCase();
1727 sal_Bool lastRes
= (str
== *arrTestCase
[i
].expVal
);
1733 arrTestCase
[i
].comments
,
1734 createName( pMeth
, "toAsciiLowerCase", i
)
1739 c_rtl_tres_state_end(hRtlTestResult
, "toAsciiUpperCase");
1745 //------------------------------------------------------------------------
1746 // testing the method trim()
1747 //------------------------------------------------------------------------
1748 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_trim(
1749 hTestResult hRtlTestResult
)
1751 sal_Char methName
[MAXBUFLENGTH
];
1752 sal_Char
* pMeth
=methName
;
1754 c_rtl_tres_state_start(hRtlTestResult
, "trim");
1755 typedef struct TestCase
1760 ~TestCase() { delete input1
; delete expVal
;}
1763 TestCase arrTestCase
[] =
1765 {"removes space from the front",new OString(kTestStr1
),
1766 new OString(kTestStr10
)},
1767 {"removes space from the end",new OString(kTestStr1
),
1768 new OString(kTestStr11
)},
1769 {"removes space from the front and end",new OString(kTestStr1
),
1770 new OString(kTestStr12
)},
1771 {"removes several spaces from the end",new OString(kTestStr1
),
1772 new OString(kTestStr13
)},
1773 {"removes several spaces from the front",new OString(kTestStr1
),
1774 new OString(kTestStr14
)},
1775 {"removes several spaces from the front and one from the end",
1776 new OString(kTestStr1
),
1777 new OString(kTestStr15
)},
1778 {"removes one space from the front and several from the end",
1779 new OString(kTestStr1
),
1780 new OString(kTestStr16
)},
1781 {"removes several spaces from the front and end",
1782 new OString(kTestStr1
),
1783 new OString(kTestStr17
)},
1784 {"removes characters that have codes <= 32",new OString(kTestStr20
),
1785 new OString("\1\3\5\7\11\13\15\17sun\21\23\25\27\31\33\40")},
1786 {"no spaces",new OString(kTestStr8
),new OString(kTestStr8
)}
1789 sal_Bool res
= sal_True
;
1792 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1794 OString strRes
= arrTestCase
[i
].input1
->trim();
1795 sal_Bool lastRes
= (strRes
== *arrTestCase
[i
].expVal
);
1801 arrTestCase
[i
].comments
,
1802 createName( pMeth
, "trim", i
)
1809 c_rtl_tres_state_end(hRtlTestResult
, "trim");
1815 //------------------------------------------------------------------------
1816 // testing the method valueOf( sal_Bool b )
1817 //------------------------------------------------------------------------
1818 sal_Bool SAL_CALL
test_rtl_OString_valueOf_sal_Bool(
1819 hTestResult hRtlTestResult
)
1821 sal_Char methName
[MAXBUFLENGTH
];
1822 sal_Char
* pMeth
=methName
;
1824 typedef struct TestCase
1829 ~TestCase() {delete expVal
;}
1832 TestCase arrTestCase
[] =
1834 {"true",sal_True
,new OString("true")},
1835 {"false",sal_False
, new OString("false")}
1838 sal_Bool res
= sal_True
;
1841 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1843 ::rtl::OString aStr1
;
1844 aStr1
= aStr1
.valueOf( arrTestCase
[i
].input1
);
1845 sal_Bool lastRes
= (arrTestCase
[i
].expVal
->compareTo(aStr1
) == 0);
1851 arrTestCase
[i
].comments
,
1852 createName( pMeth
, "valueof_bool", i
)
1862 sal_Bool SAL_CALL
test_rtl_OString_valueOf_sal_Char(
1863 hTestResult hRtlTestResult
)
1865 sal_Char methName
[MAXBUFLENGTH
];
1866 sal_Char
* pMeth
=methName
;
1868 typedef struct TestCase
1873 ~TestCase() {delete expVal
;}
1876 TestCase arrTestCase
[] =
1878 {"A",'A',new OString("A")},
1879 {"a",'a', new OString("a")},
1880 {"0",'0', new OString("0")},
1881 {"-",'-', new OString("-")},
1882 {"_",'_', new OString("_")},
1883 {"|",'|', new OString("|")},
1884 {"?",'?', new OString("?")},
1885 {"?",'?', new OString("?")},
1886 {"\n",'\n', new OString("\n")},
1887 {"\'",'\'', new OString("\'")},
1888 {"\"",'\"', new OString("\"")}
1892 sal_Bool res
= sal_True
;
1895 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
1897 ::rtl::OString aStr1
;
1898 aStr1
= aStr1
.valueOf( arrTestCase
[i
].input1
);
1899 sal_Bool lastRes
= (arrTestCase
[i
].expVal
->compareTo(aStr1
) == 0);
1905 arrTestCase
[i
].comments
,
1906 createName( pMeth
, "valueof_char", i
)
1917 * Calls the method valueOf(T, radix) and compares
1918 * returned strings with strings that passed in the array resArray.
1920 * @param T, type of argument, passed to valueOf
1921 * @param resArray, array of result strings to compare to
1922 * @param n the number of elements in the array resArray (testcases)
1923 * @param pTestResult the instance of the class TestResult
1924 * @param inArray [optional], array of value that is passed as first argument
1927 * @return true, if all returned strings are equal to corresponding string in
1928 * resArray else, false.
1931 sal_Bool
test_valueOf( const char** resArray
, int n
, sal_Int16 radix
,
1932 hTestResult hRtlTestResult
, const T
*inArray
)
1934 sal_Bool bRes
= sal_True
;
1936 sal_Char methName
[MAXBUFLENGTH
];
1937 sal_Char
* pMeth
= methName
;
1940 for (i
= 0; i
< n
; i
++)
1942 ::rtl::OString aStr1
;
1943 ::rtl::OString
aStr2( resArray
[i
] );
1946 aStr1
= ::rtl::OString::valueOf((T
)i
, radix
);
1949 if ( inArray
[i
] < 0 )
1952 aStr2
+= resArray
[i
];
1954 aStr1
= ::rtl::OString::valueOf((T
)inArray
[i
], radix
);
1957 bRes
&= c_rtl_tres_state
1960 aStr2
.compareTo(aStr1
) == 0,
1961 (sal_Char
*)resArray
[i
],
1962 createName( pMeth
, "valueOf", i
)
1970 #define test_valueOf_Int32 test_valueOf<sal_Int32>
1971 #define test_valueOf_Int64 test_valueOf<sal_Int64>
1972 // LLA: #define test_valueOf_float test_valueOf<float>
1973 // LLA: #define test_valueOf_double test_valueOf<double>
1975 //------------------------------------------------------------------------
1976 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=2 )
1977 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=8 )
1978 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=10 )
1979 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=16 )
1980 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=36 )
1981 //------------------------------------------------------------------------
1982 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int32(
1983 hTestResult hRtlTestResult
)
1985 sal_Bool bRes
= sal_False
;
1987 bRes
= c_rtl_tres_state
1990 test_valueOf_Int32((const char**)kBinaryNumsStr
,
1991 kBinaryNumsCount
, kRadixBinary
, hRtlTestResult
, 0 ),
1993 "valueOf(sal_Int32, radix 2)"
1997 bRes
&= c_rtl_tres_state
2000 test_valueOf_Int32((const char**)kOctolNumsStr
,
2001 kOctolNumsCount
, kRadixOctol
, hRtlTestResult
, 0),
2003 "valueOf(sal_Int32, radix 8)"
2006 bRes
&= c_rtl_tres_state
2009 test_valueOf_Int32((const char**)kDecimalNumsStr
,
2010 kDecimalNumsCount
, kRadixDecimal
, hRtlTestResult
, 0),
2012 "valueOf(sal_Int32, radix 10)"
2015 bRes
&= c_rtl_tres_state
2018 test_valueOf_Int32((const char**)kHexDecimalNumsStr
,
2019 kHexDecimalNumsCount
, kRadixHexdecimal
, hRtlTestResult
, 0),
2021 "valueOf(sal_Int32, radix 16)"
2024 bRes
&= c_rtl_tres_state
2027 test_valueOf_Int32((const char**)kBase36NumsStr
,
2028 kBase36NumsCount
, kRadixBase36
, hRtlTestResult
, 0),
2030 "valueOf(sal_Int32, radix 36)"
2037 //------------------------------------------------------------------------
2038 // testing the method valueOf( sal_Int32 l, sal_Int32 radix=2 )
2039 // where l = large constants
2040 // testing the method valueOf( sal_Int32 l, sal_Int32 radix=8 )
2041 // where l = large constants
2042 // testing the method valueOf( sal_Int32 l, sal_Int32 radix=10 )
2043 // where l = large constants
2044 // testing the method valueOf( sal_Int32 l, sal_Int32 radix=16 )
2045 // where l = large constants
2046 // testing the method valueOf( sal_Int32 l, sal_Int32 radix=36 )
2047 // where l = large constants
2048 //------------------------------------------------------------------------
2049 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int32_Bounderies(
2050 hTestResult hRtlTestResult
)
2052 sal_Bool bRes
= sal_False
;
2054 bRes
= c_rtl_tres_state
2057 test_valueOf_Int32((const char**)kBinaryMaxNumsStr
,
2058 kInt32MaxNumsCount
, kRadixBinary
, hRtlTestResult
,
2061 "valueOf(salInt32, radix 2) Bounderies"
2064 bRes
&= c_rtl_tres_state
2067 test_valueOf_Int32((const char**)kOctolMaxNumsStr
,
2068 kInt32MaxNumsCount
, kRadixOctol
, hRtlTestResult
,
2071 "valueOf(salInt32, radix 8) Bounderies"
2074 bRes
&= c_rtl_tres_state
2077 test_valueOf_Int32((const char**)kDecimalMaxNumsStr
,
2078 kInt32MaxNumsCount
, kRadixDecimal
,
2079 hRtlTestResult
, kInt32MaxNums
),
2081 "valueOf(salInt32, radix 10) Bounderies"
2084 bRes
&= c_rtl_tres_state
2087 test_valueOf_Int32((const char**)kHexDecimalMaxNumsStr
,
2088 kInt32MaxNumsCount
, kRadixHexdecimal
,
2089 hRtlTestResult
, kInt32MaxNums
),
2091 "valueOf(salInt32, radix 16) Bounderies"
2094 bRes
&= c_rtl_tres_state
2097 test_valueOf_Int32((const char**)kBase36MaxNumsStr
,
2098 kInt32MaxNumsCount
, kRadixBase36
,
2099 hRtlTestResult
, kInt32MaxNums
),
2101 "valueOf(salInt32, radix 36) Bounderies"
2107 //------------------------------------------------------------------------
2108 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=2 )
2109 // for negative value
2110 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=8 )
2111 // for negative value
2112 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=10 )
2113 // for negative value
2114 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=16 )
2115 // for negative value
2116 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=36 )
2117 // for negative value
2118 //------------------------------------------------------------------------
2119 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int32_Negative(
2120 hTestResult hRtlTestResult
)
2122 sal_Bool bRes
= sal_False
;
2123 sal_Int32 inArr
[kBase36NumsCount
];
2126 for (i
= 0; i
< kBase36NumsCount
; i
++ )
2129 bRes
= c_rtl_tres_state
2132 test_valueOf_Int32( kBinaryNumsStr
, kBinaryNumsCount
,
2133 kRadixBinary
, hRtlTestResult
, inArr
),
2134 "negative Int32, kRadixBinary",
2135 "valueOf( negative Int32, radix 2 )"
2138 bRes
&= c_rtl_tres_state
2141 test_valueOf_Int32( kOctolNumsStr
, kOctolNumsCount
,
2142 kRadixOctol
, hRtlTestResult
, inArr
),
2143 "negative Int32, kRadixOctol",
2144 "valueOf( negative Int32, radix 8 )"
2148 bRes
&= c_rtl_tres_state
2151 test_valueOf_Int32( kDecimalNumsStr
, kDecimalNumsCount
,
2152 kRadixDecimal
, hRtlTestResult
, inArr
),
2153 "negative Int32, kRadixDecimal",
2154 "valueOf( negative Int32, radix 10 )"
2157 bRes
&= c_rtl_tres_state
2160 test_valueOf_Int32( kHexDecimalNumsStr
, kHexDecimalNumsCount
,
2161 kRadixHexdecimal
, hRtlTestResult
, inArr
),
2162 "negative Int32, kRadixHexdecimal",
2163 "valueOf( negative Int32, radix 16 )"
2167 bRes
&= c_rtl_tres_state
2170 test_valueOf_Int32( kBase36NumsStr
, kBase36NumsCount
,
2171 kRadixBase36
, hRtlTestResult
, inArr
),
2172 "negative Int32, kRadixBase36",
2173 "valueOf( negative Int32, radix 36 )"
2178 //------------------------------------------------------------------------
2179 // testing the method valueOf( sal_Int32 l, sal_Int32 radix ) where radix = -5
2180 //------------------------------------------------------------------------
2181 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int32_WrongRadix(
2182 hTestResult hRtlTestResult
)
2184 sal_Bool bRes
= sal_False
;
2186 sal_Int32 intVal
= 11;
2188 ::rtl::OString aStr1
;
2189 ::rtl::OString
aStr2("11");
2191 aStr1
= aStr1
.valueOf( intVal
, -5 );
2193 bRes
= c_rtl_tres_state
2196 aStr2
.compareTo( aStr1
) == 0,
2197 "if radix not valid then radix must be 10",
2198 "valueOf(sal_Int32, sal_Int32 radix): radix = -5"
2204 //------------------------------------------------------------------------
2205 // testing the method valueOf( sal_Int32 l, sal_Int32 radix )
2206 // where l = -2147483648 (smallest negative value)
2207 //------------------------------------------------------------------------
2208 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int32_SmallestNegativeValue(
2209 hTestResult hRtlTestResult
)
2211 // Standard-conforming way to assign -2147483648 to n:
2213 for (int i
= 1; i
< 32; ++i
)
2215 return c_rtl_tres_state
2218 ::rtl::OString::valueOf(n
) == "-2147483648",
2220 "valueOf(sal_Int32 -2147483648)"
2224 //------------------------------------------------------------------------
2225 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=2 )
2226 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=8 )
2227 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=10 )
2228 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=16 )
2229 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=36 )
2230 //------------------------------------------------------------------------
2231 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int64(
2232 hTestResult hRtlTestResult
)
2234 sal_Bool bRes
= sal_False
;
2236 bRes
= c_rtl_tres_state
2239 test_valueOf_Int64((const char**)kBinaryNumsStr
,
2240 kBinaryNumsCount
, kRadixBinary
, hRtlTestResult
, 0),
2242 "valueOf(sal_Int64, radix 2)_"
2245 bRes
&= c_rtl_tres_state
2248 test_valueOf_Int64((const char**)kOctolNumsStr
,
2249 kOctolNumsCount
, kRadixOctol
, hRtlTestResult
, 0),
2251 "valueOf(sal_Int64, radix 8)_"
2254 bRes
&= c_rtl_tres_state
2257 test_valueOf_Int64((const char**)kDecimalNumsStr
,
2258 kDecimalNumsCount
, kRadixDecimal
, hRtlTestResult
, 0),
2260 "valueOf(sal_Int64, radix 10)_"
2262 bRes
&= c_rtl_tres_state
2265 test_valueOf_Int64((const char**)kHexDecimalNumsStr
,
2266 kHexDecimalNumsCount
, kRadixHexdecimal
, hRtlTestResult
, 0),
2268 "valueOf(sal_Int64, radix 16)_"
2271 bRes
&= c_rtl_tres_state
2274 test_valueOf_Int64((const char**)kBase36NumsStr
,
2275 kBase36NumsCount
, kRadixBase36
, hRtlTestResult
, 0),
2277 "valueOf(sal_Int64, radix 36)_"
2283 //------------------------------------------------------------------------
2284 // testing the method valueOf( sal_Int64 l, sal_Int32 radix=2 )
2285 // where l = large constants
2286 // testing the method valueOf( sal_Int64 l, sal_Int32 radix=8 )
2287 // where l = large constants
2288 // testing the method valueOf( sal_Int64 l, sal_Int32 radix=10 )
2289 // where l = large constants
2290 // testing the method valueOf( sal_Int64 l, sal_Int32 radix=16 )
2291 // where l = large constants
2292 // testing the method valueOf( sal_Int64 l, sal_Int32 radix=36 )
2293 // where l = large constants
2294 //------------------------------------------------------------------------
2295 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int64_Bounderies(
2296 hTestResult hRtlTestResult
)
2298 sal_Bool bRes
= sal_False
;
2300 bRes
= c_rtl_tres_state
2303 test_valueOf_Int64((const char**)kBinaryMaxNumsStr
,
2304 kInt64MaxNumsCount
, kRadixBinary
,
2305 hRtlTestResult
, kInt64MaxNums
),
2307 "valueOf(salInt64, radix 2) Bounderies"
2310 bRes
&= c_rtl_tres_state
2313 test_valueOf_Int64((const char**)kOctolMaxNumsStr
,
2314 kInt64MaxNumsCount
, kRadixOctol
,
2315 hRtlTestResult
, kInt64MaxNums
),
2317 "valueOf(salInt64, radix 8) Bounderies"
2320 bRes
&= c_rtl_tres_state
2323 test_valueOf_Int64((const char**)kDecimalMaxNumsStr
,
2324 kInt64MaxNumsCount
, kRadixDecimal
,
2325 hRtlTestResult
, kInt64MaxNums
),
2327 "valueOf(salInt64, radix 10) Bounderies"
2330 bRes
&= c_rtl_tres_state
2333 test_valueOf_Int64((const char**)kHexDecimalMaxNumsStr
,
2334 kInt64MaxNumsCount
, kRadixHexdecimal
,
2335 hRtlTestResult
, kInt64MaxNums
),
2337 "valueOf(salInt64, radix 16) Bounderies"
2340 bRes
&= c_rtl_tres_state
2343 test_valueOf_Int64((const char**)kBase36MaxNumsStr
,
2344 kInt64MaxNumsCount
, kRadixBase36
,
2345 hRtlTestResult
, kInt64MaxNums
),
2347 "valueOf(salInt64, radix 36) Bounderies"
2353 //------------------------------------------------------------------------
2354 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=2 )
2355 // for negative value
2356 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=8 )
2357 // for negative value
2358 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=10 )
2359 // for negative value
2360 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=16 )
2361 // for negative value
2362 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=36 )
2363 // for negative value
2364 //------------------------------------------------------------------------
2365 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int64_Negative(
2366 hTestResult hRtlTestResult
)
2368 sal_Bool bRes
= sal_False
;
2370 sal_Int64 inArr
[36];
2373 for (i
= 0; i
< 36; i
++) {
2378 bRes
= c_rtl_tres_state
2381 test_valueOf_Int64( kBinaryNumsStr
, kBinaryNumsCount
,
2382 kRadixBinary
, hRtlTestResult
, inArr
),
2383 "negative Int64, kRadixBinary",
2384 "valueOf( negative Int64, radix 2 )"
2387 bRes
&= c_rtl_tres_state
2390 test_valueOf_Int64( kOctolNumsStr
, kOctolNumsCount
,
2391 kRadixOctol
, hRtlTestResult
, inArr
),
2392 "negative Int64, kRadixOctol",
2393 "valueOf( negative Int64, radix 8 )"
2396 bRes
&= c_rtl_tres_state
2399 test_valueOf_Int64( kDecimalNumsStr
, kDecimalNumsCount
,
2400 kRadixDecimal
, hRtlTestResult
, inArr
),
2401 "negative Int64, kRadixDecimal",
2402 "valueOf( negative Int64, radix 10 )"
2405 bRes
&= c_rtl_tres_state
2408 test_valueOf_Int64( kHexDecimalNumsStr
, kHexDecimalNumsCount
,
2409 kRadixHexdecimal
, hRtlTestResult
, inArr
),
2410 "negative Int64, kRadixHexDecimal",
2411 "valueOf( negative Int64, radix 16 )"
2414 bRes
&= c_rtl_tres_state
2417 test_valueOf_Int64( kBase36NumsStr
, kBase36NumsCount
,
2418 kRadixBase36
, hRtlTestResult
, inArr
),
2419 "negative Int64, kRadixBase36",
2420 "valueOf( negative Int64, radix 36 )"
2425 //------------------------------------------------------------------------
2426 // testing the method valueOf( sal_Int64 l, sal_Int32 radix )
2428 //------------------------------------------------------------------------
2429 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int64_WrongRadix(
2430 hTestResult hRtlTestResult
)
2432 sal_Bool bRes
= sal_False
;
2434 sal_Int64 intVal
= 11;
2436 ::rtl::OString aStr1
;
2437 ::rtl::OString
aStr2("11");
2439 aStr1
= aStr1
.valueOf( intVal
, -5 );
2441 bRes
= c_rtl_tres_state
2444 aStr2
.compareTo(aStr1
) == 0,
2445 "if radix not valid then radix must be 10",
2446 "valueOf(sal_Int64, sal_Int32 radix): radix = -5"
2452 //------------------------------------------------------------------------
2453 // testing the method valueOf( sal_Int64 l, sal_Int32 radix )
2454 // where l = -9223372036854775808 (smallest negative value)
2455 //------------------------------------------------------------------------
2456 sal_Bool SAL_CALL
test_rtl_OString_valueOf_Int64_SmallestNegativeValue(
2457 hTestResult hRtlTestResult
)
2459 // Standard-conforming way to assign -9223372036854775808 to n:
2461 for (int i
= 1; i
< 64; ++i
)
2463 return c_rtl_tres_state
2466 ::rtl::OString::valueOf(n
) == "-9223372036854775808",
2467 "-9223372036854775808",
2468 "valueOf(sal_Int64 -9223372036854775808)"
2472 //------------------------------------------------------------------------
2473 // testing the method valueOf( float f )
2474 //------------------------------------------------------------------------
2475 // LLA: sal_Bool SAL_CALL test_rtl_OString_valueOf_float(
2476 // LLA: hTestResult hRtlTestResult )
2478 // LLA: sal_Char methName[MAXBUFLENGTH];
2479 // LLA: sal_Char* pMeth =methName;
2481 // LLA: typedef struct TestCase
2483 // LLA: sal_Char* comments;
2484 // LLA: float input1;
2485 // LLA: OString* expVal;
2487 // LLA: ~TestCase() {delete expVal;}
2490 // LLA: TestCase arrTestCase[] =
2492 // LLA: { "3.0", 3.0, new OString("3.0") },
2493 // LLA: { "3.5", 3.5f, new OString("3.5")},
2494 // LLA: { "3.0625", 3.0625f, new OString("3.0625")},
2495 // LLA: { "3.502525", 3.502525f, new OString("3.502525") },
2496 // LLA: { "3.141592", 3.141592f, new OString("3.141592") },
2497 // LLA: { "3.5025255", 3.5025255f, new OString("3.5025255") },
2498 // LLA: { "3.0039062", 3.00390625f, new OString("3.0039062") }
2501 // LLA: sal_Bool res = sal_True;
2502 // LLA: sal_Int32 i;
2504 // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
2506 // LLA: ::rtl::OString aStr1;
2507 // LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 );
2508 // LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0);
2510 // LLA: c_rtl_tres_state
2512 // LLA: hRtlTestResult,
2514 // LLA: arrTestCase[i].comments,
2515 // LLA: createName( pMeth, "valueof_float", i)
2518 // LLA: res &= lastRes;
2522 // LLA: return ( res );
2528 //------------------------------------------------------------------------
2529 // testing the method valueOf( float f ) for negative value
2530 //------------------------------------------------------------------------
2531 // LLA: sal_Bool SAL_CALL test_rtl_OString_valueOf_Float_Negative(
2532 // LLA: hTestResult hRtlTestResult )
2534 // LLA: sal_Char methName[MAXBUFLENGTH];
2535 // LLA: sal_Char* pMeth =methName;
2537 // LLA: typedef struct TestCase
2539 // LLA: sal_Char* comments;
2540 // LLA: float input1;
2541 // LLA: OString* expVal;
2543 // LLA: ~TestCase() {delete expVal;}
2546 // LLA: TestCase arrTestCase[] =
2548 // LLA: { "-3.0", -3.0, new OString("-3.0") },
2549 // LLA: { "-3.5", -3.5f, new OString("-3.5")},
2550 // LLA: { "-3.0625", -3.0625f, new OString("-3.0625")},
2551 // LLA: { "-3.502525", -3.502525f, new OString("-3.502525") },
2552 // LLA: { "-3.141592", -3.141592f, new OString("-3.141592") },
2553 // LLA: { "-3.5025255", -3.5025255f, new OString("-3.5025255") },
2554 // LLA: { "-3.0039062", -3.00390625f, new OString("-3.0039062") }
2557 // LLA: sal_Bool res = sal_True;
2558 // LLA: sal_Int32 i;
2560 // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
2562 // LLA: ::rtl::OString aStr1;
2563 // LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 );
2564 // LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0);
2566 // LLA: c_rtl_tres_state
2568 // LLA: hRtlTestResult,
2570 // LLA: arrTestCase[i].comments,
2571 // LLA: createName( pMeth, "valueof_negative float", i)
2574 // LLA: res &= lastRes;
2578 // LLA: return ( res );
2581 //------------------------------------------------------------------------
2582 // testing the method valueOf( double f )
2583 //------------------------------------------------------------------------
2584 // LLA: sal_Bool SAL_CALL test_rtl_OString_valueOf_double(
2585 // LLA: hTestResult hRtlTestResult )
2587 // LLA: sal_Char methName[MAXBUFLENGTH];
2588 // LLA: sal_Char* pMeth =methName;
2590 // LLA: typedef struct TestCase
2592 // LLA: sal_Char* comments;
2593 // LLA: double input1;
2594 // LLA: OString* expVal;
2596 // LLA: ~TestCase() {delete expVal;}
2599 // LLA: TestCase arrTestCase[] =
2601 // LLA: {"3.0", 3.0, new OString("3.0")},
2602 // LLA: {"3.5", 3.5, new OString("3.5")},
2603 // LLA: {"3.0625", 3.0625, new OString("3.0625")},
2604 // LLA: {"3.1415926535", 3.1415926535, new OString("3.1415926535")},
2605 // LLA: {"3.1415926535897931", 3.141592653589793,
2606 // LLA: new OString("3.1415926535897931")},
2607 // LLA: {"3.1415926535897931", 3.1415926535897932,
2608 // LLA: new OString("3.1415926535897931")},
2609 // LLA: {"3.1415926535897931", 3.14159265358979323,
2610 // LLA: new OString("3.1415926535897931")},
2611 // LLA: {"3.1415926535897931", 3.141592653589793238462643,
2612 // LLA: new OString("3.1415926535897931")}
2615 // LLA: sal_Bool res = sal_True;
2616 // LLA: sal_Int32 i;
2618 // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
2620 // LLA: ::rtl::OString aStr1;
2621 // LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 );
2622 // LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0);
2624 // LLA: c_rtl_tres_state
2626 // LLA: hRtlTestResult,
2628 // LLA: arrTestCase[i].comments,
2629 // LLA: createName( pMeth, "valueof_double", i)
2632 // LLA: res &= lastRes;
2636 // LLA: return ( res );
2640 //------------------------------------------------------------------------
2641 // testing the method valueOf( double f ) for negative value
2642 //------------------------------------------------------------------------
2643 // LLA: sal_Bool SAL_CALL test_rtl_OString_valueOf_Double_Negative(
2644 // LLA: hTestResult hRtlTestResult )
2646 // LLA: sal_Char methName[MAXBUFLENGTH];
2647 // LLA: sal_Char* pMeth =methName;
2649 // LLA: typedef struct TestCase
2651 // LLA: sal_Char* comments;
2652 // LLA: double input1;
2653 // LLA: OString* expVal;
2655 // LLA: ~TestCase() {delete expVal;}
2658 // LLA: TestCase arrTestCase[] =
2660 // LLA: {"-3.0", -3.0, new OString("-3.0")},
2661 // LLA: {"-3.5", -3.5, new OString("-3.5")},
2662 // LLA: {"-3.0625", -3.0625, new OString("-3.0625")},
2663 // LLA: {"-3.1415926535", -3.1415926535, new OString("-3.1415926535")},
2664 // LLA: {"-3.1415926535897931", -3.141592653589793,
2665 // LLA: new OString("-3.1415926535897931")},
2666 // LLA: {"-3.1415926535897931", -3.1415926535897932,
2667 // LLA: new OString("-3.1415926535897931")},
2668 // LLA: {"-3.1415926535897931", -3.14159265358979323,
2669 // LLA: new OString("-3.1415926535897931")},
2670 // LLA: {"-3.1415926535897931", -3.141592653589793238462643,
2671 // LLA: new OString("-3.1415926535897931")}
2674 // LLA: sal_Bool res = sal_True;
2675 // LLA: sal_Int32 i;
2677 // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
2679 // LLA: ::rtl::OString aStr1;
2680 // LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 );
2681 // LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0);
2683 // LLA: c_rtl_tres_state
2685 // LLA: hRtlTestResult,
2687 // LLA: arrTestCase[i].comments,
2688 // LLA: createName( pMeth, "valueof_nagative double", i)
2691 // LLA: res &= lastRes;
2695 // LLA: return ( res );
2698 //------------------------------------------------------------------------
2699 // testing the method valueOf()
2700 //------------------------------------------------------------------------
2701 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_valueOf(
2702 hTestResult hRtlTestResult
)
2704 c_rtl_tres_state_start(hRtlTestResult
, "valueOf");
2705 sal_Bool bTState
= test_rtl_OString_valueOf_sal_Bool( hRtlTestResult
);
2707 bTState
&= test_rtl_OString_valueOf_sal_Char( hRtlTestResult
);
2709 bTState
&= test_rtl_OString_valueOf_Int32( hRtlTestResult
);
2710 bTState
&= test_rtl_OString_valueOf_Int32_Bounderies( hRtlTestResult
);
2711 bTState
&= test_rtl_OString_valueOf_Int32_Negative( hRtlTestResult
);
2712 bTState
&= test_rtl_OString_valueOf_Int32_WrongRadix( hRtlTestResult
);
2713 bTState
&= test_rtl_OString_valueOf_Int32_SmallestNegativeValue(
2716 bTState
&= test_rtl_OString_valueOf_Int64( hRtlTestResult
);
2717 bTState
&= test_rtl_OString_valueOf_Int64_Bounderies( hRtlTestResult
);
2718 bTState
&= test_rtl_OString_valueOf_Int64_Negative( hRtlTestResult
);
2719 bTState
&= test_rtl_OString_valueOf_Int64_WrongRadix( hRtlTestResult
);
2720 bTState
&= test_rtl_OString_valueOf_Int64_SmallestNegativeValue(
2723 // LLA: the tests for valueOf(float) and valueOf(double) are moved to file
2724 // sal/qa/rtl/ostring/rtl_OString2.cxx
2726 // LLA: bTState &= test_rtl_OString_valueOf_float( hRtlTestResult );
2727 // LLA: bTState &= test_rtl_OString_valueOf_Float_Negative( hRtlTestResult );
2729 // LLA: bTState &= test_rtl_OString_valueOf_double( hRtlTestResult );
2730 // LLA: bTState &= test_rtl_OString_valueOf_Double_Negative( hRtlTestResult );
2732 c_rtl_tres_state_end(hRtlTestResult
, "valueOf");
2733 // return ( bTState );
2737 //------------------------------------------------------------------------
2738 // testing the method toChar()
2739 //------------------------------------------------------------------------
2740 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_toChar(
2741 hTestResult hRtlTestResult
)
2743 sal_Char methName
[MAXBUFLENGTH
];
2744 sal_Char
* pMeth
= methName
;
2746 c_rtl_tres_state_start(hRtlTestResult
, "toChar");
2747 typedef struct TestCase
2752 ~TestCase() {delete input1
;}
2756 TestCase arrTestCase
[] =
2758 {"A", 'A', new OString("A")},
2759 {"a", 'a', new OString("a")},
2760 {"0", '0',new OString("0")},
2761 {"-", '-',new OString("-")},
2762 {"_", '_',new OString("_")},
2764 // TODO: may be UTF-8 values
2765 // {"�0„6", '�0„6',new OString("�0„6")},
2766 // { "�0„7", '�0„7',new OString("�0„7")},
2767 // {"�0‹0", '�0‹0',new OString("�0‹0")},
2768 // {"�0�6", '�0�6',new OString("�0�6")},
2769 {"\n", '\n',new OString("\n")},
2770 {"\'", '\'',new OString("\'")},
2771 {"\"", '\"',new OString("\"")},
2772 {"\0", '\0',new OString("\0")},
2773 {"", '\0',new OString("")},
2774 {"Sun Microsystems", 'S', new OString(kTestStr1
)}
2778 // sal_Bool res = sal_True;
2781 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++ )
2783 sal_Char strRes
= arrTestCase
[i
].input1
->toChar();
2784 sal_Bool lastRes
= ( strRes
== arrTestCase
[i
].expVal
);
2786 char com
[MAXBUFLENGTH
];
2788 cpynstr(com
+ 1, (*arrTestCase
[i
].input1
), MAXBUFLENGTH
);
2789 int length
= AStringLen( (*arrTestCase
[i
].input1
) );
2790 com
[length
+ 1] = '\'';
2791 com
[length
+ 2] = 0;
2798 createName( pMeth
, "toChar", i
)
2803 c_rtl_tres_state_end(hRtlTestResult
, "toChar");
2808 //------------------------------------------------------------------------
2809 // testing the method toFloat()
2810 //------------------------------------------------------------------------
2811 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_toFloat(
2812 hTestResult hRtlTestResult
)
2814 sal_Char methName
[MAXBUFLENGTH
];
2815 sal_Char
* pMeth
= methName
;
2817 c_rtl_tres_state_start(hRtlTestResult
, "toFloat");
2818 typedef struct TestCase
2823 ~TestCase() {delete input1
;}
2827 TestCase arrTestCase
[] =
2829 {3.0f
, new OString("3"), 3e-7f
},
2830 {3.1f
, new OString("3.1"), 3e-7f
},
2831 {3.1415f
, new OString("3.1415"), 3e-7f
},
2832 {3.14159f
, new OString("3.14159"), 3e-7f
},
2833 {3.141592f
, new OString("3.141592"), 3e-7f
},
2834 {3.1415926f
, new OString("3.1415926"), 3e-7f
},
2835 {3.14159265f
, new OString("3.14159265"), 3e-7f
},
2836 {3.141592653589793238462643f
,
2837 new OString("3.141592653589793238462643"), 3e-7f
},
2838 {6.5822e-16f
, new OString("6.5822e-16"), 6e-16f
* 1e-7f
},
2839 {9.1096e-31f
, new OString("9.1096e-31"), 9e-31f
* 1e-7f
},
2840 {2.997925e8f
, new OString("2.997925e8"), 3e8f
* 1e-7f
},
2841 {6.241e18f
, new OString("6.241e18"), 6e18f
* 1e-7f
},
2842 {3.1f
, new OString("03.1"), 3e-7f
},
2843 {3.1f
, new OString(" 3.1"), 3e-7f
},
2844 {-3.1f
, new OString("-3.1"), 3e-7f
},
2845 {3.1f
, new OString("+3.1"), 3e-7f
},
2846 {0.0f
, new OString("-0.0"), 1e-7f
}
2850 // sal_Bool res = sal_True;
2853 t_print("sizeof(float)=%d, sizeof(double)=%d\n", sizeof(float), sizeof(double));
2855 for(i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++ )
2857 float fA
= arrTestCase
[i
].input1
->toFloat();
2858 float fB
= arrTestCase
[i
].expVal
;
2859 float fPrec
= arrTestCase
[i
].m_nPrecision
;
2860 float fResult
= (float) fabs(fA
- fB
);
2861 // t_print("float result: A:(%.9f) B:(%.9f) fabs(A-B):%E\n", fA, fB, fResult);
2862 t_print("float result: A:(%E) B:(%E) fabs(A-B):%E\n", fA
, fB
, (float) fResult
);
2863 sal_Bool lastRes
= ( fResult
<= fPrec
);
2865 char com
[MAXBUFLENGTH
];
2867 cpynstr(com
+ 1, (*arrTestCase
[i
].input1
), MAXBUFLENGTH
);
2868 int length
= AStringLen( (*arrTestCase
[i
].input1
) );
2869 com
[length
+ 1] = '\'';
2870 com
[length
+ 2] = 0;
2877 createName( pMeth
, "toFloat", i
)
2882 c_rtl_tres_state_end(hRtlTestResult
, "toFloat");
2887 //------------------------------------------------------------------------
2888 // testing the method toDouble()
2889 //------------------------------------------------------------------------
2890 // LLA: extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_toDouble(
2891 // LLA: hTestResult hRtlTestResult )
2893 // LLA: sal_Char methName[MAXBUFLENGTH];
2894 // LLA: sal_Char* pMeth = methName;
2896 // LLA: c_rtl_tres_state_start(hRtlTestResult, "toDouble");
2897 // LLA: typedef struct TestCase
2899 // LLA: double expVal;
2900 // LLA: double expDiff;
2901 // LLA: OString* input1;
2902 // LLA: ~TestCase() {delete input1;}
2906 // LLA: TestCase arrTestCase[] =
2908 // LLA: {3.0, 1e-35, new OString("3")},
2909 // LLA: {3.1, 1e-2, new OString("3.1")},
2910 // LLA: {3.1415, 1e-5, new OString("3.1415")},
2911 // LLA: {3.1415926535, 1e-11, new OString("3.1415926535")},
2912 // LLA: {3.141592653589793, 1e-15,
2913 // LLA: new OString("3.141592653589793")},
2914 // LLA: {3.1415926535897932, 1e-16,
2915 // LLA: new OString("3.1415926535897932")},
2916 // LLA: {3.14159265358979323, 1e-15,
2917 // LLA: new OString("3.14159265358979323")},
2918 // LLA: {3.141592653589793238462643, 1e-15,
2919 // LLA: new OString("3.141592653589793238462643")},
2920 // LLA: {6.5822e-16, 1e-20, new OString("6.5822e-16")},
2921 // LLA: {9.1096e-31, 1e-35, new OString("9.1096e-31")},
2922 // LLA: {2.997925e8, 10, new OString("2.997925e8")},
2923 // LLA: {6.241e18, 100, new OString("6.241e18")},
2924 // LLA: {1.7e-308, 1e-35, new OString("1.7e-308")},
2925 // LLA: {1.7e+308, 100, new OString("1.7e+308")},
2926 // LLA: {3.1, 1e-2, new OString("03.1")},
2927 // LLA: {3.1, 1e-2, new OString(" 3.1")},
2928 // LLA: {-3.1, 1e-2, new OString("-3.1")},
2929 // LLA: {3.1, 1e-2, new OString("+3.1")},
2930 // LLA: {0.0, 1e-2, new OString("-0.0")}
2933 // LLA: sal_Bool res = sal_True;
2934 // LLA: sal_Int32 i;
2936 // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++ )
2938 // LLA: double dRes = arrTestCase[i].input1->toDouble();
2939 // LLA: double dErg = dRes - arrTestCase[i].expVal ;
2940 // LLA: double dComp = fabs( dErg );
2941 // LLA: sal_Bool lastRes = ( dComp <= arrTestCase[i].expDiff );
2943 // LLA: char com[MAXBUFLENGTH];
2944 // LLA: com[0] = '\'';
2945 // LLA: cpynstr(com + 1, (*arrTestCase[i].input1), MAXBUFLENGTH);
2946 // LLA: int length = AStringLen( (*arrTestCase[i].input1) );
2947 // LLA: com[length + 1] = '\'';
2948 // LLA: com[length + 2] = 0;
2950 // LLA: c_rtl_tres_state
2952 // LLA: hRtlTestResult,
2955 // LLA: createName( pMeth, "toDouble", i )
2960 // LLA: c_rtl_tres_state_end(hRtlTestResult, "toDouble");
2961 // LLA: // return (res);
2964 //------------------------------------------------------------------------
2965 // testing the method toBoolean()
2966 //------------------------------------------------------------------------
2968 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_toBoolean(
2969 hTestResult hRtlTestResult
)
2971 sal_Char methName
[MAXBUFLENGTH
];
2972 sal_Char
* pMeth
= methName
;
2974 c_rtl_tres_state_start(hRtlTestResult
, "toBoolean");
2975 typedef struct TestCase
2983 TestCase arrTestCase
[]={
2985 {"expected true", sal_True
, new OString("True")},
2986 {"expected false", sal_False
, new OString("False")},
2987 {"expected true", sal_True
, new OString("1")}
2991 sal_Bool res
= sal_True
;
2994 for (i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
2996 sal_Bool bRes
= arrTestCase
[i
].input
->toBoolean();
2997 sal_Bool lastRes
= (bRes
== arrTestCase
[i
].expVal
);
3002 arrTestCase
[i
].comments
,
3003 createName( pMeth
, "toBoolean", i
)
3008 c_rtl_tres_state_end(hRtlTestResult
, "toBoolean");
3014 //------------------------------------------------------------------------
3015 // testing the method toInt32( sal_Int16 radix = 2,8,10,16,36 )
3016 //------------------------------------------------------------------------
3017 sal_Bool
test_toInt32( int num
, const sal_Char
** in
,
3018 const sal_Int32
*expVal
,sal_Int16 radix
, hTestResult hRtlTestResult
)
3020 sal_Bool res
= sal_True
;
3021 sal_Char methName
[MAXBUFLENGTH
];
3022 sal_Char
* pMeth
= methName
;
3025 for( i
= 0; i
< num
; i
++ )
3028 sal_Int32 intRes
= str
.toInt32(radix
);
3029 sal_Bool lastRes
= (intRes
== expVal
[i
]);
3031 char buf
[MAXBUFLENGTH
];
3033 cpynstr( buf
+ 1, in
[i
], MAXBUFLENGTH
);
3034 int length
= AStringLen( in
[i
] );
3035 buf
[length
+ 1] = '\'';
3036 buf
[length
+ 2] = 0;
3043 createName( pMeth
,"toInt32", i
)
3052 sal_Bool SAL_CALL
test_rtl_OString_toInt32_wrongRadix(
3053 hTestResult hRtlTestResult
)
3055 ::rtl::OString
str("0");
3057 sal_Int32 iRes
= str
.toInt32(-1);
3066 "toInt32( 0, wrong radix -1 )"
3071 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_toInt32(
3072 hTestResult hRtlTestResult
)
3074 sal_Int32 expValues
[kBase36NumsCount
];
3077 c_rtl_tres_state_start(hRtlTestResult
, "toInt32");
3078 for ( i
= 0; i
< kBase36NumsCount
; i
++ )
3081 sal_Bool res
= c_rtl_tres_state
3084 test_toInt32( kBinaryNumsCount
, kBinaryNumsStr
,
3085 expValues
, kRadixBinary
, hRtlTestResult
),
3087 "toInt32( radix 2 )"
3089 res
&= c_rtl_tres_state
3092 test_toInt32( kInt32MaxNumsCount
, kBinaryMaxNumsStr
,
3093 kInt32MaxNums
, kRadixBinary
, hRtlTestResult
),
3094 "kBinaryMaxNumsStr",
3095 "toInt32_Boundaries( radix 2 )"
3098 res
&= c_rtl_tres_state
3101 test_toInt32( kOctolNumsCount
, kOctolNumsStr
,
3102 expValues
, kRadixOctol
, hRtlTestResult
),
3104 "toInt32( radix 8 )"
3107 res
&= c_rtl_tres_state
3110 test_toInt32( kInt32MaxNumsCount
, kOctolMaxNumsStr
,
3111 (sal_Int32
*)kInt32MaxNums
, kRadixOctol
, hRtlTestResult
),
3113 "toInt32_Boundaries( radix 8 )"
3116 res
&= c_rtl_tres_state
3119 test_toInt32( kDecimalNumsCount
, kDecimalNumsStr
, expValues
,
3120 kRadixDecimal
, hRtlTestResult
),
3122 "toInt32( radix 10 )"
3125 res
&= c_rtl_tres_state
3128 test_toInt32( kInt32MaxNumsCount
, kDecimalMaxNumsStr
,
3129 (sal_Int32
*)kInt32MaxNums
, kRadixDecimal
, hRtlTestResult
),
3130 "kDecimalMaxNumsStr",
3131 "toInt32_Boundaries( radix 10 )"
3134 res
&= c_rtl_tres_state
3137 test_toInt32( kHexDecimalNumsCount
, kHexDecimalNumsStr
, expValues
,
3138 kRadixHexdecimal
, hRtlTestResult
),
3139 "kHexDecimalNumsStr",
3140 "toInt32( radix 16 )"
3143 res
&= c_rtl_tres_state
3146 test_toInt32( kInt32MaxNumsCount
, kHexDecimalMaxNumsStr
,
3147 (sal_Int32
*)kInt32MaxNums
, kRadixHexdecimal
, hRtlTestResult
),
3148 "kHexDecimalMaxNumsStr",
3149 "toInt32_Boundaries( radix 16 )"
3152 res
&= c_rtl_tres_state
3155 test_toInt32( kBase36NumsCount
, kBase36NumsStr
, expValues
,
3156 kRadixBase36
, hRtlTestResult
),
3158 "toInt32( radix 36 )"
3161 res
&= c_rtl_tres_state
3164 test_toInt32( kInt32MaxNumsCount
, kBase36MaxNumsStr
,
3165 (sal_Int32
*)kInt32MaxNums
, kRadixBase36
, hRtlTestResult
),
3166 "kBase36MaxNumsStr",
3167 "toInt32_Boundaries( radix 36 )"
3170 const sal_Int16 nSpecCases
= 5;
3171 static const sal_Char
*spString
[nSpecCases
] =
3180 sal_Int32 expSpecVal
[nSpecCases
] =
3189 res
&= c_rtl_tres_state
3192 test_toInt32( nSpecCases
, spString
, expSpecVal
,
3193 kRadixDecimal
, hRtlTestResult
),
3195 "toInt32( specialcases )"
3198 res
&= test_rtl_OString_toInt32_wrongRadix( hRtlTestResult
);
3200 c_rtl_tres_state_end(hRtlTestResult
, "toInt32");
3204 //------------------------------------------------------------------------
3205 // testing the method toInt64( sal_Int16 radix = 2,8,10,16,36 )
3206 //------------------------------------------------------------------------
3207 sal_Bool
test_toInt64( int num
, const sal_Char
** in
,
3208 const sal_Int64
*expVal
,sal_Int16 radix
, hTestResult hRtlTestResult
)
3210 sal_Bool res
= sal_True
;
3211 sal_Char methName
[MAXBUFLENGTH
];
3212 sal_Char
* pMeth
= methName
;
3215 for( i
= 0; i
< num
; i
++ )
3217 OString
str( in
[i
] );
3218 sal_Int64 intRes
= str
.toInt64( radix
);
3219 sal_Bool lastRes
= ( intRes
== expVal
[i
] );
3221 char buf
[MAXBUFLENGTH
];
3223 cpynstr( buf
+ 1, in
[i
], MAXBUFLENGTH
);
3224 int length
= AStringLen(in
[i
]);
3225 buf
[length
+ 1] = '\'';
3226 buf
[length
+ 2] = 0;
3233 createName( pMeth
, "toInt64", i
)
3241 sal_Bool SAL_CALL
test_rtl_OString_toInt64_wrongRadix(
3242 hTestResult hRtlTestResult
)
3244 ::rtl::OString
str("0");
3246 sal_Int64 iRes
= str
.toInt64(-1);
3254 "toInt64( wrong radix -1)"
3259 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_toInt64(
3260 hTestResult hRtlTestResult
)
3262 sal_Int64 expValues
[kBase36NumsCount
];
3265 c_rtl_tres_state_start(hRtlTestResult
, "toInt64");
3266 for (i
= 0; i
< kBase36NumsCount
; expValues
[i
] = i
, i
++);
3268 sal_Bool res
= c_rtl_tres_state
3271 test_toInt64( kBinaryNumsCount
, kBinaryNumsStr
, expValues
,
3272 kRadixBinary
, hRtlTestResult
),
3274 "toInt64( radix 2 )"
3277 res
&= c_rtl_tres_state
3280 test_toInt64( kInt32MaxNumsCount
, kBinaryMaxNumsStr
,
3281 (sal_Int64
*)kInt64MaxNums
, kRadixBinary
, hRtlTestResult
),
3282 "kBinaryMaxNumsStr",
3283 "toInt64_Boundaries( radix 2 )"
3286 res
&= c_rtl_tres_state
3289 test_toInt64( kOctolNumsCount
, kOctolNumsStr
, expValues
,
3290 kRadixOctol
, hRtlTestResult
),
3292 "toInt64( radix 8 )"
3295 res
&= c_rtl_tres_state
3298 test_toInt64( kInt32MaxNumsCount
, kOctolMaxNumsStr
,
3299 (sal_Int64
*)kInt64MaxNums
, kRadixOctol
, hRtlTestResult
),
3301 "toInt64_Boundaries( radix 8 )"
3304 res
&= c_rtl_tres_state
3307 test_toInt64( kDecimalNumsCount
, kDecimalNumsStr
, expValues
,
3308 kRadixDecimal
, hRtlTestResult
),
3310 "toInt64( radix 10 )"
3313 res
&= c_rtl_tres_state
3316 test_toInt64( kInt32MaxNumsCount
, kDecimalMaxNumsStr
,
3317 (sal_Int64
*)kInt64MaxNums
, kRadixDecimal
, hRtlTestResult
),
3318 "kDecimalMaxNumsStr",
3319 "toInt64_Boundaries( radix 10 )"
3322 res
&= c_rtl_tres_state
3325 test_toInt64( kHexDecimalNumsCount
, kHexDecimalNumsStr
, expValues
,
3326 kRadixHexdecimal
, hRtlTestResult
),
3327 "kHexDecimalNumsStr",
3328 "toInt64( radix 16 )"
3331 res
&= c_rtl_tres_state
3334 test_toInt64( kInt32MaxNumsCount
, kHexDecimalMaxNumsStr
,
3335 (sal_Int64
*)kInt64MaxNums
, kRadixHexdecimal
, hRtlTestResult
),
3336 "kHexDecimalMaxNumsStr",
3337 "toInt64_Boundaries( radix 16 )"
3340 res
&= c_rtl_tres_state
3343 test_toInt64( kBase36NumsCount
, kBase36NumsStr
, expValues
,
3344 kRadixBase36
, hRtlTestResult
),
3346 "toInt64( radix 36 )"
3349 res
&= c_rtl_tres_state
3352 test_toInt64( kInt32MaxNumsCount
, kBase36MaxNumsStr
,
3353 (sal_Int64
*)kInt64MaxNums
, kRadixBase36
, hRtlTestResult
),
3354 "kBase36MaxNumsStr",
3355 "toInt64_Boundaries( radix 36 )"
3360 const sal_Int16 nSpecCases
= 5;
3361 static const sal_Char
*spString
[nSpecCases
] =
3370 sal_Int64 expSpecVal
[nSpecCases
] =
3379 res
&= c_rtl_tres_state
3382 test_toInt64( nSpecCases
, spString
, expSpecVal
,
3383 kRadixDecimal
, hRtlTestResult
),
3385 "toInt64( specialcases )"
3388 res
&= test_rtl_OString_toInt64_wrongRadix( hRtlTestResult
);
3390 c_rtl_tres_state_end(hRtlTestResult
, "toInt64");
3394 //------------------------------------------------------------------------
3395 // testing the method replace( sal_Char oldChar, sal_Char newChar )
3396 //------------------------------------------------------------------------
3397 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_replace(
3398 hTestResult hRtlTestResult
)
3400 sal_Char methName
[MAXBUFLENGTH
];
3401 sal_Char
* pMeth
= methName
;
3403 c_rtl_tres_state_start(hRtlTestResult
, "replace");
3404 typedef struct TestCase
3412 ~TestCase() { delete input
; delete expVal
;}
3415 TestCase arrTestCase
[]={
3417 {"string differs", new OString(kTestStr18
),
3418 new OString(kTestStr4
),'S','s'},
3419 {"string differs", new OString(kTestStr19
),
3420 new OString(kTestStr17
),(sal_Char
)' ',(sal_Char
)'-'},
3421 {"same string, no replace ", new OString(kTestStr22
),
3422 new OString(kTestStr22
),'*','8'}
3426 sal_Bool res
= sal_True
;
3429 for (i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
3431 ::rtl::OString aStr1
;
3432 aStr1
= arrTestCase
[i
].input
->replace(arrTestCase
[i
].oldChar
,
3433 arrTestCase
[i
].newChar
);
3435 res
&= c_rtl_tres_state
3438 (arrTestCase
[i
].expVal
->compareTo(aStr1
) == 0),
3439 arrTestCase
[i
].comments
,
3440 createName( pMeth
, "replace", i
)
3444 c_rtl_tres_state_end(hRtlTestResult
, "replace");
3450 //------------------------------------------------------------------------
3451 // testing the method replaceAt( sal_Int32 index, sal_Int32 count,
3452 // const OString& newStr )
3453 //------------------------------------------------------------------------
3454 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString_replaceAt(
3455 hTestResult hRtlTestResult
)
3457 sal_Char methName
[MAXBUFLENGTH
];
3458 sal_Char
* pMeth
= methName
;
3460 c_rtl_tres_state_start(hRtlTestResult
, "replaceAt");
3461 typedef struct TestCase
3470 ~TestCase() { delete input
; delete expVal
; delete newStr
;}
3473 TestCase arrTestCase
[]=
3476 { "string differs", new OString(kTestStr2
), new OString(kTestStr22
),
3477 new OString(kTestStr2
), 0, kTestStr22Len
},
3479 { "larger index", new OString(kTestStr1
), new OString(kTestStr7
),
3480 new OString(kTestStr8
), 64, kTestStr8Len
},
3482 { "larger count", new OString(kTestStr2
), new OString(kTestStr22
),
3483 new OString(kTestStr2
),0, 64 },
3485 { "navigate index", new OString(kTestStr2
), new OString(kTestStr22
),
3486 new OString(kTestStr2
), -64, 64 },
3488 { "null string", new OString(""),
3489 new OString(kTestStr14
),new OString(""), 0, kTestStr14Len
}
3492 sal_Bool res
= sal_True
;
3495 for (i
= 0; i
< (sizeof (arrTestCase
))/(sizeof (TestCase
)); i
++)
3497 ::rtl::OString aStr1
;
3498 aStr1
= arrTestCase
[i
].input
->replaceAt( arrTestCase
[i
].index
,
3499 arrTestCase
[i
].count
, *arrTestCase
[i
].newStr
);
3501 sal_Bool lastRes
= ( arrTestCase
[i
].expVal
->compareTo(aStr1
) == 0 );
3507 arrTestCase
[i
].comments
,
3508 createName( pMeth
, "replaceAt", i
)
3513 c_rtl_tres_state_end(hRtlTestResult
, "replaceAt");
3517 extern "C" void /* sal_Bool */ SAL_CALL
test_rtl_OString( hTestResult hRtlTestResult
)
3520 c_rtl_tres_state_start(hRtlTestResult
, "rtl_OString" );
3522 test_rtl_OString_ctors( hRtlTestResult
);
3523 test_rtl_OString_getLength( hRtlTestResult
);
3524 test_rtl_OString_equals( hRtlTestResult
);
3525 test_rtl_OString_equalsIgnoreAsciiCase( hRtlTestResult
);
3526 test_rtl_OString_compareTo( hRtlTestResult
);
3527 test_rtl_OString_op_cmp( hRtlTestResult
);
3528 test_rtl_OString_op_neq( hRtlTestResult
);
3529 test_rtl_OString_op_g( hRtlTestResult
);
3530 test_rtl_OString_op_l( hRtlTestResult
);
3531 test_rtl_OString_op_ge( hRtlTestResult
);
3532 test_rtl_OString_op_le( hRtlTestResult
);
3533 test_rtl_OString_op_eq( hRtlTestResult
);
3534 test_rtl_OString_op_plus( hRtlTestResult
);
3535 test_rtl_OString_op_peq( hRtlTestResult
);
3536 test_rtl_OString_op_cscs( hRtlTestResult
);
3537 test_rtl_OString_getStr( hRtlTestResult
);
3538 test_rtl_OString_copy( hRtlTestResult
);
3539 test_rtl_OString_concat( hRtlTestResult
);
3540 test_rtl_OString_toAsciiLowerCase( hRtlTestResult
);
3541 test_rtl_OString_toAsciiUpperCase( hRtlTestResult
);
3542 test_rtl_OString_trim( hRtlTestResult
);
3543 test_rtl_OString_valueOf( hRtlTestResult
);
3544 test_rtl_OString_toChar( hRtlTestResult
);
3545 test_rtl_OString_toFloat( hRtlTestResult
);
3546 // LLA: test_rtl_OString_toDouble( hRtlTestResult );
3547 test_rtl_OString_toBoolean( hRtlTestResult
);
3548 test_rtl_OString_toInt32( hRtlTestResult
);
3549 test_rtl_OString_toInt64( hRtlTestResult
);
3550 test_rtl_OString_replace( hRtlTestResult
);
3551 test_rtl_OString_replaceAt( hRtlTestResult
);
3553 c_rtl_tres_state_end(hRtlTestResult
, "rtl_OString");
3557 // -----------------------------------------------------------------------------
3558 void RegisterAdditionalFunctions(FktRegFuncPtr _pFunc
)
3562 (_pFunc
)(&test_rtl_OString
, "");
3564 //# (_pFunc)(&test_rtl_OString_ctors, "");
3565 //# (_pFunc)(&test_rtl_OString_getLength, "");
3566 //# (_pFunc)(&test_rtl_OString_equals, "");
3567 //# (_pFunc)(&test_rtl_OString_equalsIgnoreAsciiCase, "");
3568 //# (_pFunc)(&test_rtl_OString_compareTo, "");
3569 //# (_pFunc)(&test_rtl_OString_op_cmp, "");
3570 //# (_pFunc)(&test_rtl_OString_op_neq, "");
3571 //# (_pFunc)(&test_rtl_OString_op_g, "");
3572 //# (_pFunc)(&test_rtl_OString_op_l, "");
3573 //# (_pFunc)(&test_rtl_OString_op_ge, "");
3574 //# (_pFunc)(&test_rtl_OString_op_le, "");
3575 //# (_pFunc)(&test_rtl_OString_op_eq, "");
3576 //# (_pFunc)(&test_rtl_OString_op_plus, "");
3577 //# (_pFunc)(&test_rtl_OString_op_peq, "");
3578 //# (_pFunc)(&test_rtl_OString_op_cscs, "");
3579 //# (_pFunc)(&test_rtl_OString_getStr, "");
3580 //# (_pFunc)(&test_rtl_OString_copy, "");
3581 //# (_pFunc)(&test_rtl_OString_concat, "");
3582 //# (_pFunc)(&test_rtl_OString_toAsciiLowerCase, "");
3583 //# (_pFunc)(&test_rtl_OString_toAsciiUpperCase, "");
3584 //# (_pFunc)(&test_rtl_OString_trim, "");
3585 //# (_pFunc)(&test_rtl_OString_valueOf, "");
3586 //# (_pFunc)(&test_rtl_OString_toChar, "");
3587 //# (_pFunc)(&test_rtl_OString_toFloat, "");
3588 //# (_pFunc)(&test_rtl_OString_toDouble, "");
3589 //# (_pFunc)(&test_rtl_OString_toBoolean, "");
3590 //# (_pFunc)(&test_rtl_OString_toInt32, "");
3591 //# (_pFunc)(&test_rtl_OString_toInt64, "");
3592 //# (_pFunc)(&test_rtl_OString_replace, "");
3593 //# (_pFunc)(&test_rtl_OString_replaceAt, "");
3598 D:\local\644\SRX644\sal\qa\rtl_OString.cxx(3559) : error C2664:
3599 'unsigned char (void (__cdecl *)(void *),const char *)'
3600 : cannot convert parameter 1 from
3601 'unsigned char (__cdecl *)(void *)' to 'void (__cdecl *)(void *)'
3603 This conversion requires a reinterpret_cast, a C-style cast or function-