xref: /aoo42x/main/sal/qa/rtl/ostring/rtl_OString2.cxx (revision b3f397bd)
187d2adbcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
387d2adbcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
487d2adbcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
587d2adbcSAndrew Rist  * distributed with this work for additional information
687d2adbcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
787d2adbcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
887d2adbcSAndrew Rist  * "License"); you may not use this file except in compliance
987d2adbcSAndrew Rist  * with the License.  You may obtain a copy of the License at
1087d2adbcSAndrew Rist  *
1187d2adbcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1287d2adbcSAndrew Rist  *
1387d2adbcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1487d2adbcSAndrew Rist  * software distributed under the License is distributed on an
1587d2adbcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1687d2adbcSAndrew Rist  * KIND, either express or implied.  See the License for the
1787d2adbcSAndrew Rist  * specific language governing permissions and limitations
1887d2adbcSAndrew Rist  * under the License.
1987d2adbcSAndrew Rist  *
2087d2adbcSAndrew Rist  *************************************************************/
2187d2adbcSAndrew Rist 
2287d2adbcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir 
25cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
26cdf0e10cSrcweir #include "precompiled_sal.hxx"
27cdf0e10cSrcweir // autogenerated file with codegen.pl
28cdf0e10cSrcweir // There exist some more test code in sal/qa/rtl_strings/rtl_OString.cxx
29*b3f397bdSDamjan Jovanovic #include <rtl/string.hxx>
30cdf0e10cSrcweir 
31*b3f397bdSDamjan Jovanovic #include "gtest/gtest.h"
32cdf0e10cSrcweir #include "valueequal.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace rtl_OString
35cdf0e10cSrcweir {
36cdf0e10cSrcweir 
37*b3f397bdSDamjan Jovanovic class valueOf : public ::testing::Test
38cdf0e10cSrcweir {
39*b3f397bdSDamjan Jovanovic protected:
valueOf_float_test_impl(float _nValue)40cdf0e10cSrcweir     void valueOf_float_test_impl(float _nValue)
41cdf0e10cSrcweir         {
42cdf0e10cSrcweir             rtl::OString sValue;
43cdf0e10cSrcweir             sValue = rtl::OString::valueOf( _nValue );
44*b3f397bdSDamjan Jovanovic             printf("nFloat := %.9f  sValue := %s\n", _nValue, sValue.getStr());
45cdf0e10cSrcweir 
46cdf0e10cSrcweir             float nValueATOF = static_cast<float>(atof( sValue.getStr() ));
47cdf0e10cSrcweir 
48cdf0e10cSrcweir             bool bEqualResult = is_float_equal(_nValue, nValueATOF);
49*b3f397bdSDamjan Jovanovic             ASSERT_TRUE(bEqualResult == true) << "Values are not equal.";
50cdf0e10cSrcweir         }
51cdf0e10cSrcweir 
valueOf_float_test(float _nValue)52cdf0e10cSrcweir     void valueOf_float_test(float _nValue)
53cdf0e10cSrcweir         {
54cdf0e10cSrcweir             valueOf_float_test_impl(_nValue);
55cdf0e10cSrcweir 
56cdf0e10cSrcweir             // test also the negative part.
57cdf0e10cSrcweir             float nNegativeValue = -_nValue;
58cdf0e10cSrcweir             valueOf_float_test_impl(nNegativeValue);
59cdf0e10cSrcweir         }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir public:
62cdf0e10cSrcweir     // initialise your test code values here.
SetUp()63*b3f397bdSDamjan Jovanovic     void SetUp()
64cdf0e10cSrcweir     {
65cdf0e10cSrcweir     }
66cdf0e10cSrcweir 
TearDown()67*b3f397bdSDamjan Jovanovic     void TearDown()
68cdf0e10cSrcweir     {
69cdf0e10cSrcweir     }
70cdf0e10cSrcweir 
71*b3f397bdSDamjan Jovanovic protected:
72cdf0e10cSrcweir 
valueOf_double_test_impl(double _nValue)73cdf0e10cSrcweir     void valueOf_double_test_impl(double _nValue)
74cdf0e10cSrcweir         {
75cdf0e10cSrcweir             rtl::OString sValue;
76cdf0e10cSrcweir             sValue = rtl::OString::valueOf( _nValue );
77*b3f397bdSDamjan Jovanovic             printf("nDouble := %.20f  sValue := %s\n", _nValue, sValue.getStr());
78cdf0e10cSrcweir 
79cdf0e10cSrcweir             double nValueATOF = atof( sValue.getStr() );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir             bool bEqualResult = is_double_equal(_nValue, nValueATOF);
82*b3f397bdSDamjan Jovanovic             ASSERT_TRUE(bEqualResult == true) << "Values are not equal.";
83cdf0e10cSrcweir         }
84cdf0e10cSrcweir 
valueOf_double_test(double _nValue)85cdf0e10cSrcweir     void valueOf_double_test(double _nValue)
86cdf0e10cSrcweir         {
87cdf0e10cSrcweir             valueOf_double_test_impl(_nValue);
88cdf0e10cSrcweir 
89cdf0e10cSrcweir             // test also the negative part.
90cdf0e10cSrcweir             double nNegativeValue = -_nValue;
91cdf0e10cSrcweir             valueOf_double_test_impl(nNegativeValue);
92cdf0e10cSrcweir         }
93*b3f397bdSDamjan Jovanovic }; // class valueOf
94cdf0e10cSrcweir 
TEST_F(valueOf,valueOf_float_test_001)95*b3f397bdSDamjan Jovanovic TEST_F(valueOf, valueOf_float_test_001)
96*b3f397bdSDamjan Jovanovic {
97*b3f397bdSDamjan Jovanovic     // this is demonstration code
98*b3f397bdSDamjan Jovanovic     // ASSERT_TRUE(1 == 1) << "a message";
99*b3f397bdSDamjan Jovanovic     float nValue = 3.0f;
100*b3f397bdSDamjan Jovanovic     valueOf_float_test(nValue);
101*b3f397bdSDamjan Jovanovic }
102cdf0e10cSrcweir 
TEST_F(valueOf,valueOf_float_test_002)103*b3f397bdSDamjan Jovanovic TEST_F(valueOf, valueOf_float_test_002)
104*b3f397bdSDamjan Jovanovic {
105*b3f397bdSDamjan Jovanovic     float nValue = 3.5f;
106*b3f397bdSDamjan Jovanovic     valueOf_float_test(nValue);
107*b3f397bdSDamjan Jovanovic }
108*b3f397bdSDamjan Jovanovic 
TEST_F(valueOf,valueOf_float_test_003)109*b3f397bdSDamjan Jovanovic TEST_F(valueOf, valueOf_float_test_003)
110*b3f397bdSDamjan Jovanovic {
111*b3f397bdSDamjan Jovanovic     float nValue = 3.0625f;
112*b3f397bdSDamjan Jovanovic     valueOf_float_test(nValue);
113*b3f397bdSDamjan Jovanovic }
114*b3f397bdSDamjan Jovanovic 
TEST_F(valueOf,valueOf_float_test_004)115*b3f397bdSDamjan Jovanovic TEST_F(valueOf, valueOf_float_test_004)
116*b3f397bdSDamjan Jovanovic {
117*b3f397bdSDamjan Jovanovic     float nValue = 3.502525f;
118*b3f397bdSDamjan Jovanovic     valueOf_float_test(nValue);
119*b3f397bdSDamjan Jovanovic }
120*b3f397bdSDamjan Jovanovic 
TEST_F(valueOf,valueOf_float_test_005)121*b3f397bdSDamjan Jovanovic TEST_F(valueOf, valueOf_float_test_005)
122*b3f397bdSDamjan Jovanovic {
123*b3f397bdSDamjan Jovanovic     float nValue = 3.141592f;
124*b3f397bdSDamjan Jovanovic     valueOf_float_test(nValue);
125*b3f397bdSDamjan Jovanovic }
126*b3f397bdSDamjan Jovanovic 
TEST_F(valueOf,valueOf_float_test_006)127*b3f397bdSDamjan Jovanovic TEST_F(valueOf, valueOf_float_test_006)
128*b3f397bdSDamjan Jovanovic {
129*b3f397bdSDamjan Jovanovic     float nValue = 3.5025255f;
130*b3f397bdSDamjan Jovanovic     valueOf_float_test(nValue);
131*b3f397bdSDamjan Jovanovic }
132*b3f397bdSDamjan Jovanovic 
TEST_F(valueOf,valueOf_float_test_007)133*b3f397bdSDamjan Jovanovic TEST_F(valueOf, valueOf_float_test_007)
134*b3f397bdSDamjan Jovanovic {
135*b3f397bdSDamjan Jovanovic     float nValue = 3.0039062f;
136*b3f397bdSDamjan Jovanovic     valueOf_float_test(nValue);
137*b3f397bdSDamjan Jovanovic }
138*b3f397bdSDamjan Jovanovic 
TEST_F(valueOf,valueOf_double_test_001)139*b3f397bdSDamjan Jovanovic TEST_F(valueOf, valueOf_double_test_001)
140*b3f397bdSDamjan Jovanovic {
141*b3f397bdSDamjan Jovanovic     double nValue = 3.0;
142*b3f397bdSDamjan Jovanovic     valueOf_double_test(nValue);
143*b3f397bdSDamjan Jovanovic }
TEST_F(valueOf,valueOf_double_test_002)144*b3f397bdSDamjan Jovanovic TEST_F(valueOf, valueOf_double_test_002)
145*b3f397bdSDamjan Jovanovic {
146*b3f397bdSDamjan Jovanovic     double nValue = 3.5;
147*b3f397bdSDamjan Jovanovic     valueOf_double_test(nValue);
148*b3f397bdSDamjan Jovanovic }
TEST_F(valueOf,valueOf_double_test_003)149*b3f397bdSDamjan Jovanovic TEST_F(valueOf, valueOf_double_test_003)
150*b3f397bdSDamjan Jovanovic {
151*b3f397bdSDamjan Jovanovic     double nValue = 3.0625;
152*b3f397bdSDamjan Jovanovic     valueOf_double_test(nValue);
153*b3f397bdSDamjan Jovanovic }
TEST_F(valueOf,valueOf_double_test_004)154*b3f397bdSDamjan Jovanovic TEST_F(valueOf, valueOf_double_test_004)
155*b3f397bdSDamjan Jovanovic {
156*b3f397bdSDamjan Jovanovic     double nValue = 3.1415926535;
157*b3f397bdSDamjan Jovanovic     valueOf_double_test(nValue);
158*b3f397bdSDamjan Jovanovic }
TEST_F(valueOf,valueOf_double_test_005)159*b3f397bdSDamjan Jovanovic TEST_F(valueOf, valueOf_double_test_005)
160*b3f397bdSDamjan Jovanovic {
161*b3f397bdSDamjan Jovanovic     double nValue = 3.141592653589793;
162*b3f397bdSDamjan Jovanovic     valueOf_double_test(nValue);
163*b3f397bdSDamjan Jovanovic }
TEST_F(valueOf,valueOf_double_test_006)164*b3f397bdSDamjan Jovanovic TEST_F(valueOf, valueOf_double_test_006)
165*b3f397bdSDamjan Jovanovic {
166*b3f397bdSDamjan Jovanovic     double nValue = 3.1415926535897932;
167*b3f397bdSDamjan Jovanovic     valueOf_double_test(nValue);
168*b3f397bdSDamjan Jovanovic }
TEST_F(valueOf,valueOf_double_test_007)169*b3f397bdSDamjan Jovanovic TEST_F(valueOf, valueOf_double_test_007)
170*b3f397bdSDamjan Jovanovic {
171*b3f397bdSDamjan Jovanovic     double nValue = 3.14159265358979323;
172*b3f397bdSDamjan Jovanovic     valueOf_double_test(nValue);
173*b3f397bdSDamjan Jovanovic }
TEST_F(valueOf,valueOf_double_test_008)174*b3f397bdSDamjan Jovanovic TEST_F(valueOf, valueOf_double_test_008)
175*b3f397bdSDamjan Jovanovic {
176*b3f397bdSDamjan Jovanovic     double nValue = 3.141592653589793238462643;
177*b3f397bdSDamjan Jovanovic     valueOf_double_test(nValue);
178*b3f397bdSDamjan Jovanovic }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 
181cdf0e10cSrcweir // -----------------------------------------------------------------------------
182cdf0e10cSrcweir // - toDouble (tests)
183cdf0e10cSrcweir // -----------------------------------------------------------------------------
184*b3f397bdSDamjan Jovanovic class toDouble : public ::testing::Test
185cdf0e10cSrcweir {
186cdf0e10cSrcweir 
187cdf0e10cSrcweir public:
188cdf0e10cSrcweir 
toDouble()189cdf0e10cSrcweir     toDouble()
190cdf0e10cSrcweir         {
191cdf0e10cSrcweir             // testPrecision a;
192cdf0e10cSrcweir         }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     // initialise your test code values here.
SetUp()197*b3f397bdSDamjan Jovanovic     void SetUp()
198cdf0e10cSrcweir         {
199cdf0e10cSrcweir         }
200cdf0e10cSrcweir 
TearDown()201*b3f397bdSDamjan Jovanovic     void TearDown()
202*b3f397bdSDamjan Jovanovic 	{
203*b3f397bdSDamjan Jovanovic 	}
204cdf0e10cSrcweir 
toDouble_test_impl(rtl::OString const & _sValue)205cdf0e10cSrcweir     void toDouble_test_impl(rtl::OString const& _sValue)
206cdf0e10cSrcweir         {
207cdf0e10cSrcweir             double nValueATOF = atof( _sValue.getStr() );
208cdf0e10cSrcweir 
209cdf0e10cSrcweir             // rtl::OUString suValue = rtl::OUString::createFromAscii( _sValue.getStr() );
210cdf0e10cSrcweir             double nValueToDouble = _sValue.toDouble();
211cdf0e10cSrcweir 
212cdf0e10cSrcweir             bool bEqualResult = is_double_equal(nValueToDouble, nValueATOF);
213*b3f397bdSDamjan Jovanovic             ASSERT_TRUE(bEqualResult == true) << "Values are not equal.";
214cdf0e10cSrcweir         }
215cdf0e10cSrcweir 
toDouble_test(rtl::OString const & _sValue)216cdf0e10cSrcweir     void toDouble_test(rtl::OString const& _sValue)
217cdf0e10cSrcweir         {
218cdf0e10cSrcweir             toDouble_test_impl(_sValue);
219cdf0e10cSrcweir 
220cdf0e10cSrcweir             // test also the negativ part.
221cdf0e10cSrcweir             rtl::OString sNegativValue("-");
222cdf0e10cSrcweir             sNegativValue += _sValue;
223cdf0e10cSrcweir             toDouble_test_impl(sNegativValue);
224cdf0e10cSrcweir         }
225*b3f397bdSDamjan Jovanovic }; // class toDouble
226cdf0e10cSrcweir 
TEST_F(toDouble,toDouble_selftest)227*b3f397bdSDamjan Jovanovic TEST_F(toDouble, toDouble_selftest)
228*b3f397bdSDamjan Jovanovic {
229*b3f397bdSDamjan Jovanovic     printf("Start selftest:\n");
230*b3f397bdSDamjan Jovanovic     ASSERT_TRUE (is_double_equal(1.0, 1.01) == false);
231*b3f397bdSDamjan Jovanovic     ASSERT_TRUE (is_double_equal(1.0, 1.001) == false);
232*b3f397bdSDamjan Jovanovic     ASSERT_TRUE (is_double_equal(1.0, 1.0001) == false);
233*b3f397bdSDamjan Jovanovic     ASSERT_TRUE (is_double_equal(1.0, 1.00001) == false);
234*b3f397bdSDamjan Jovanovic     ASSERT_TRUE (is_double_equal(1.0, 1.000001) == false);
235*b3f397bdSDamjan Jovanovic     ASSERT_TRUE (is_double_equal(1.0, 1.0000001) == false);
236*b3f397bdSDamjan Jovanovic     ASSERT_TRUE (is_double_equal(1.0, 1.00000001) == false);
237*b3f397bdSDamjan Jovanovic     ASSERT_TRUE (is_double_equal(1.0, 1.000000001) == false);
238*b3f397bdSDamjan Jovanovic     ASSERT_TRUE (is_double_equal(1.0, 1.0000000001) == false);
239*b3f397bdSDamjan Jovanovic     ASSERT_TRUE (is_double_equal(1.0, 1.00000000001) == false);
240*b3f397bdSDamjan Jovanovic     ASSERT_TRUE (is_double_equal(1.0, 1.000000000001) == false);
241*b3f397bdSDamjan Jovanovic     ASSERT_TRUE (is_double_equal(1.0, 1.0000000000001) == false);
242*b3f397bdSDamjan Jovanovic     // we check til 14 values after comma
243*b3f397bdSDamjan Jovanovic     ASSERT_TRUE (is_double_equal(1.0, 1.00000000000001) == true);
244*b3f397bdSDamjan Jovanovic     ASSERT_TRUE (is_double_equal(1.0, 1.000000000000001) == true);
245*b3f397bdSDamjan Jovanovic     ASSERT_TRUE (is_double_equal(1.0, 1.0000000000000001) == true);
246*b3f397bdSDamjan Jovanovic     printf("Selftest done.\n");
247*b3f397bdSDamjan Jovanovic }
248*b3f397bdSDamjan Jovanovic 
TEST_F(toDouble,toDouble_test_3)249*b3f397bdSDamjan Jovanovic TEST_F(toDouble, toDouble_test_3)
250*b3f397bdSDamjan Jovanovic {
251*b3f397bdSDamjan Jovanovic     rtl::OString sValue("3");
252*b3f397bdSDamjan Jovanovic     toDouble_test(sValue);
253*b3f397bdSDamjan Jovanovic }
TEST_F(toDouble,toDouble_test_3_5)254*b3f397bdSDamjan Jovanovic TEST_F(toDouble, toDouble_test_3_5)
255*b3f397bdSDamjan Jovanovic {
256*b3f397bdSDamjan Jovanovic     rtl::OString sValue("3.5");
257*b3f397bdSDamjan Jovanovic     toDouble_test(sValue);
258*b3f397bdSDamjan Jovanovic }
TEST_F(toDouble,toDouble_test_3_0625)259*b3f397bdSDamjan Jovanovic TEST_F(toDouble, toDouble_test_3_0625)
260*b3f397bdSDamjan Jovanovic {
261*b3f397bdSDamjan Jovanovic     rtl::OString sValue("3.0625");
262*b3f397bdSDamjan Jovanovic     toDouble_test(sValue);
263*b3f397bdSDamjan Jovanovic }
TEST_F(toDouble,toDouble_test_pi)264*b3f397bdSDamjan Jovanovic TEST_F(toDouble, toDouble_test_pi)
265*b3f397bdSDamjan Jovanovic {
266*b3f397bdSDamjan Jovanovic     // value from http://www.angio.net/pi/digits/50.txt
267*b3f397bdSDamjan Jovanovic     rtl::OString sValue("3.141592653589793238462643383279502884197169399375");
268*b3f397bdSDamjan Jovanovic     toDouble_test(sValue);
269*b3f397bdSDamjan Jovanovic }
270cdf0e10cSrcweir 
TEST_F(toDouble,toDouble_test_1)271*b3f397bdSDamjan Jovanovic TEST_F(toDouble, toDouble_test_1)
272*b3f397bdSDamjan Jovanovic {
273*b3f397bdSDamjan Jovanovic     rtl::OString sValue("1");
274*b3f397bdSDamjan Jovanovic     toDouble_test(sValue);
275*b3f397bdSDamjan Jovanovic }
TEST_F(toDouble,toDouble_test_10)276*b3f397bdSDamjan Jovanovic TEST_F(toDouble, toDouble_test_10)
277*b3f397bdSDamjan Jovanovic {
278*b3f397bdSDamjan Jovanovic     rtl::OString sValue("10");
279*b3f397bdSDamjan Jovanovic     toDouble_test(sValue);
280*b3f397bdSDamjan Jovanovic }
TEST_F(toDouble,toDouble_test_100)281*b3f397bdSDamjan Jovanovic TEST_F(toDouble, toDouble_test_100)
282*b3f397bdSDamjan Jovanovic {
283*b3f397bdSDamjan Jovanovic     rtl::OString sValue("100");
284*b3f397bdSDamjan Jovanovic     toDouble_test(sValue);
285*b3f397bdSDamjan Jovanovic }
TEST_F(toDouble,toDouble_test_1000)286*b3f397bdSDamjan Jovanovic TEST_F(toDouble, toDouble_test_1000)
287*b3f397bdSDamjan Jovanovic {
288*b3f397bdSDamjan Jovanovic     rtl::OString sValue("1000");
289*b3f397bdSDamjan Jovanovic     toDouble_test(sValue);
290*b3f397bdSDamjan Jovanovic }
TEST_F(toDouble,toDouble_test_10000)291*b3f397bdSDamjan Jovanovic TEST_F(toDouble, toDouble_test_10000)
292*b3f397bdSDamjan Jovanovic {
293*b3f397bdSDamjan Jovanovic     rtl::OString sValue("10000");
294*b3f397bdSDamjan Jovanovic     toDouble_test(sValue);
295*b3f397bdSDamjan Jovanovic }
TEST_F(toDouble,toDouble_test_1e99)296*b3f397bdSDamjan Jovanovic TEST_F(toDouble, toDouble_test_1e99)
297*b3f397bdSDamjan Jovanovic {
298*b3f397bdSDamjan Jovanovic     rtl::OString sValue("1e99");
299*b3f397bdSDamjan Jovanovic     toDouble_test(sValue);
300*b3f397bdSDamjan Jovanovic }
TEST_F(toDouble,toDouble_test_1e_n99)301*b3f397bdSDamjan Jovanovic TEST_F(toDouble, toDouble_test_1e_n99)
302*b3f397bdSDamjan Jovanovic {
303*b3f397bdSDamjan Jovanovic     rtl::OString sValue("1e-99");
304*b3f397bdSDamjan Jovanovic     toDouble_test(sValue);
305*b3f397bdSDamjan Jovanovic }
TEST_F(toDouble,toDouble_test_1e308)306*b3f397bdSDamjan Jovanovic TEST_F(toDouble, toDouble_test_1e308)
307*b3f397bdSDamjan Jovanovic {
308*b3f397bdSDamjan Jovanovic     rtl::OString sValue("1e308");
309*b3f397bdSDamjan Jovanovic     toDouble_test(sValue);
310*b3f397bdSDamjan Jovanovic }
311cdf0e10cSrcweir 
312cdf0e10cSrcweir // -----------------------------------------------------------------------------
313cdf0e10cSrcweir // - getToken (tests)
314cdf0e10cSrcweir // -----------------------------------------------------------------------------
315*b3f397bdSDamjan Jovanovic class getToken : public ::testing::Test
316cdf0e10cSrcweir {
317cdf0e10cSrcweir 
318cdf0e10cSrcweir public:
319cdf0e10cSrcweir 
320cdf0e10cSrcweir     // initialise your test code values here.
SetUp()321*b3f397bdSDamjan Jovanovic     void SetUp()
322cdf0e10cSrcweir         {
323cdf0e10cSrcweir         }
324cdf0e10cSrcweir 
TearDown()325*b3f397bdSDamjan Jovanovic     void TearDown()
326cdf0e10cSrcweir         {
327cdf0e10cSrcweir         }
328*b3f397bdSDamjan Jovanovic }; // class getToken
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 
TEST_F(getToken,getToken_000)331*b3f397bdSDamjan Jovanovic TEST_F(getToken, getToken_000)
332*b3f397bdSDamjan Jovanovic {
333*b3f397bdSDamjan Jovanovic     rtl::OString sTokenStr;
334cdf0e10cSrcweir 
335*b3f397bdSDamjan Jovanovic     sal_Int32 nIndex = 0;
336*b3f397bdSDamjan Jovanovic     do
337*b3f397bdSDamjan Jovanovic     {
338*b3f397bdSDamjan Jovanovic         rtl::OString sToken = sTokenStr.getToken( 0, ';', nIndex );
339*b3f397bdSDamjan Jovanovic     }
340*b3f397bdSDamjan Jovanovic     while ( nIndex >= 0 );
341*b3f397bdSDamjan Jovanovic     // printf("Index %d\n", nIndex);
342*b3f397bdSDamjan Jovanovic     // should not GPF
343*b3f397bdSDamjan Jovanovic }
344cdf0e10cSrcweir 
TEST_F(getToken,getToken_001)345*b3f397bdSDamjan Jovanovic TEST_F(getToken, getToken_001)
346*b3f397bdSDamjan Jovanovic {
347*b3f397bdSDamjan Jovanovic     rtl::OString sTokenStr = "a;b";
348cdf0e10cSrcweir 
349*b3f397bdSDamjan Jovanovic     sal_Int32 nIndex = 0;
350cdf0e10cSrcweir 
351*b3f397bdSDamjan Jovanovic     rtl::OString sToken = sTokenStr.getToken( 0, ';', nIndex );
352*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(sToken.equals("a") == sal_True) << "Token should be a 'a'";
353cdf0e10cSrcweir 
354*b3f397bdSDamjan Jovanovic     /* rtl::OString */ sToken = sTokenStr.getToken( 0, ';', nIndex );
355*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(sToken.equals("b") == sal_True) << "Token should be a 'b'";
356*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(nIndex == -1) << "index should be negative";
357*b3f397bdSDamjan Jovanovic }
358cdf0e10cSrcweir 
TEST_F(getToken,getToken_002)359*b3f397bdSDamjan Jovanovic TEST_F(getToken, getToken_002)
360*b3f397bdSDamjan Jovanovic {
361*b3f397bdSDamjan Jovanovic     rtl::OString sTokenStr = "a;b.c";
362cdf0e10cSrcweir 
363*b3f397bdSDamjan Jovanovic     sal_Int32 nIndex = 0;
364cdf0e10cSrcweir 
365*b3f397bdSDamjan Jovanovic     rtl::OString sToken = sTokenStr.getToken( 0, ';', nIndex );
366*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(sToken.equals("a") == sal_True) << "Token should be a 'a'";
367cdf0e10cSrcweir 
368*b3f397bdSDamjan Jovanovic     /* rtl::OString */ sToken = sTokenStr.getToken( 0, '.', nIndex );
369*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(sToken.equals("b") == sal_True) << "Token should be a 'b'";
370cdf0e10cSrcweir 
371*b3f397bdSDamjan Jovanovic     /* rtl::OString */ sToken = sTokenStr.getToken( 0, '.', nIndex );
372*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(sToken.equals("c") == sal_True) << "Token should be a 'c'";
373*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(nIndex == -1) << "index should be negative";
374*b3f397bdSDamjan Jovanovic }
375cdf0e10cSrcweir 
TEST_F(getToken,getToken_003)376*b3f397bdSDamjan Jovanovic TEST_F(getToken, getToken_003)
377*b3f397bdSDamjan Jovanovic {
378*b3f397bdSDamjan Jovanovic     rtl::OString sTokenStr = "a;;b";
379cdf0e10cSrcweir 
380*b3f397bdSDamjan Jovanovic     sal_Int32 nIndex = 0;
381cdf0e10cSrcweir 
382*b3f397bdSDamjan Jovanovic     rtl::OString sToken = sTokenStr.getToken( 0, ';', nIndex );
383*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(sToken.equals("a") == sal_True) << "Token should be a 'a'";
384cdf0e10cSrcweir 
385*b3f397bdSDamjan Jovanovic     /* rtl::OString */ sToken = sTokenStr.getToken( 0, ';', nIndex );
386*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(sToken.getLength() == 0) << "Token should be empty";
387cdf0e10cSrcweir 
388*b3f397bdSDamjan Jovanovic     /* rtl::OString */ sToken = sTokenStr.getToken( 0, ';', nIndex );
389*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(sToken.equals("b") == sal_True) << "Token should be a 'b'";
390*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(nIndex == -1) << "index should be negative";
391*b3f397bdSDamjan Jovanovic }
392cdf0e10cSrcweir 
TEST_F(getToken,getToken_004)393*b3f397bdSDamjan Jovanovic TEST_F(getToken, getToken_004)
394*b3f397bdSDamjan Jovanovic {
395*b3f397bdSDamjan Jovanovic     rtl::OString sTokenStr = "longer.then.ever.";
396cdf0e10cSrcweir 
397*b3f397bdSDamjan Jovanovic     sal_Int32 nIndex = 0;
398cdf0e10cSrcweir 
399*b3f397bdSDamjan Jovanovic     rtl::OString sToken = sTokenStr.getToken( 0, '.', nIndex );
400*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(sToken.equals("longer") == sal_True) << "Token should be 'longer'";
401cdf0e10cSrcweir 
402*b3f397bdSDamjan Jovanovic     /* rtl::OString */ sToken = sTokenStr.getToken( 0, '.', nIndex );
403*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(sToken.equals("then") == sal_True) << "Token should be 'then'";
404cdf0e10cSrcweir 
405*b3f397bdSDamjan Jovanovic     /* rtl::OString */ sToken = sTokenStr.getToken( 0, '.', nIndex );
406*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(sToken.equals("ever") == sal_True) << "Token should be 'ever'";
407cdf0e10cSrcweir 
408*b3f397bdSDamjan Jovanovic     /* rtl::OString */ sToken = sTokenStr.getToken( 0, '.', nIndex );
409*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(sToken.getLength() == 0) << "Token should be empty";
410cdf0e10cSrcweir 
411*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(nIndex == -1) << "index should be negative";
412*b3f397bdSDamjan Jovanovic }
413cdf0e10cSrcweir 
414cdf0e10cSrcweir // -----------------------------------------------------------------------------
415cdf0e10cSrcweir // testing the method replaceAt( sal_Int32 index, sal_Int32 count,
416cdf0e10cSrcweir // const OString& newStr )
417cdf0e10cSrcweir // -----------------------------------------------------------------------------
418cdf0e10cSrcweir 
419cdf0e10cSrcweir // Developer note: Mindy Liu, 2004-04-23
420cdf0e10cSrcweir // stollen from sal/qa/rtl_strings/rtl_OString.cxx
421cdf0e10cSrcweir 
422*b3f397bdSDamjan Jovanovic class replaceAt : public ::testing::Test
423cdf0e10cSrcweir {
424cdf0e10cSrcweir 
425cdf0e10cSrcweir public:
426cdf0e10cSrcweir     // initialise your test code values here.
SetUp()427*b3f397bdSDamjan Jovanovic     void SetUp()
428cdf0e10cSrcweir         {
429cdf0e10cSrcweir         }
430cdf0e10cSrcweir 
TearDown()431*b3f397bdSDamjan Jovanovic     void TearDown()
432cdf0e10cSrcweir         {
433cdf0e10cSrcweir         }
check_replaceAt(const rtl::OString * expVal,const rtl::OString * input,const rtl::OString * newStr,sal_Int32 index,sal_Int32 count)434cdf0e10cSrcweir     sal_Bool check_replaceAt( const rtl::OString* expVal, const rtl::OString* input,
435cdf0e10cSrcweir         const rtl::OString* newStr, sal_Int32  index, sal_Int32 count)
436cdf0e10cSrcweir     {
437cdf0e10cSrcweir     	 ::rtl::OString aStr1;
438cdf0e10cSrcweir         aStr1= input->replaceAt( index, count, *newStr );
439cdf0e10cSrcweir 
440*b3f397bdSDamjan Jovanovic         printf("the result OString is %s#\n", aStr1.getStr() );
441cdf0e10cSrcweir 
442cdf0e10cSrcweir         sal_Bool bRes = ( expVal->compareTo(aStr1) == 0 );
443cdf0e10cSrcweir         return bRes;
444cdf0e10cSrcweir     }
445*b3f397bdSDamjan Jovanovic }; // class replaceAt
446cdf0e10cSrcweir 
TEST_F(replaceAt,replaceAt_001)447*b3f397bdSDamjan Jovanovic TEST_F(replaceAt, replaceAt_001)
448*b3f397bdSDamjan Jovanovic {
449*b3f397bdSDamjan Jovanovic     sal_Bool bRes = check_replaceAt(new rtl::OString("Java@Sun"),
450*b3f397bdSDamjan Jovanovic 		new rtl::OString("Sun java"), new rtl::OString("Java@Sun"), 0, 8 );
451*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(bRes == sal_True) << "string differs, replace whole string";
452*b3f397bdSDamjan Jovanovic }
453cdf0e10cSrcweir 
TEST_F(replaceAt,replaceAt_002)454*b3f397bdSDamjan Jovanovic TEST_F(replaceAt, replaceAt_002)
455*b3f397bdSDamjan Jovanovic {
456*b3f397bdSDamjan Jovanovic     sal_Bool bRes = check_replaceAt(new rtl::OString("Sun Java desktop system"),
457*b3f397bdSDamjan Jovanovic 		new rtl::OString("Sun "), new rtl::OString("Java desktop system"), 10, 8 );
458*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(bRes == sal_True) << "index > length of input string";
459*b3f397bdSDamjan Jovanovic }
460cdf0e10cSrcweir 
TEST_F(replaceAt,replaceAt_003)461*b3f397bdSDamjan Jovanovic TEST_F(replaceAt, replaceAt_003)
462*b3f397bdSDamjan Jovanovic {
463*b3f397bdSDamjan Jovanovic     sal_Bool bRes = check_replaceAt(new rtl::OString("SuJava desktop system"),
464*b3f397bdSDamjan Jovanovic 		new rtl::OString("Sun "), new rtl::OString("Java desktop system"), 2, 64 );
465*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(bRes == sal_True) << "larger count";
466*b3f397bdSDamjan Jovanovic }
467cdf0e10cSrcweir 
TEST_F(replaceAt,replaceAt_004)468*b3f397bdSDamjan Jovanovic TEST_F(replaceAt, replaceAt_004)
469*b3f397bdSDamjan Jovanovic {
470cdf0e10cSrcweir 
471*b3f397bdSDamjan Jovanovic     sal_Bool bRes = check_replaceAt(new rtl::OString("Java desktop system"),
472*b3f397bdSDamjan Jovanovic 		new rtl::OString("Sun "), new rtl::OString("Java desktop system"), -4, 8 );
473*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(bRes == sal_True) << "navigate index";
474*b3f397bdSDamjan Jovanovic }
TEST_F(replaceAt,replaceAt_005)475*b3f397bdSDamjan Jovanovic TEST_F(replaceAt, replaceAt_005)
476*b3f397bdSDamjan Jovanovic {
477cdf0e10cSrcweir 
478*b3f397bdSDamjan Jovanovic     sal_Bool bRes = check_replaceAt(new rtl::OString("Sun Jesktop System"),
479*b3f397bdSDamjan Jovanovic 		new rtl::OString("Sun Java Desktop System"), new rtl::OString(""), 5, 5 );
480*b3f397bdSDamjan Jovanovic     ASSERT_TRUE(bRes == sal_True) << "replace with null string";
481*b3f397bdSDamjan Jovanovic }
482cdf0e10cSrcweir 
483cdf0e10cSrcweir 
484cdf0e10cSrcweir } // namespace rtl_OString
485cdf0e10cSrcweir 
486cdf0e10cSrcweir 
main(int argc,char ** argv)487*b3f397bdSDamjan Jovanovic int main(int argc, char **argv)
488*b3f397bdSDamjan Jovanovic {
489*b3f397bdSDamjan Jovanovic     ::testing::InitGoogleTest(&argc, argv);
490*b3f397bdSDamjan Jovanovic     return RUN_ALL_TESTS();
491*b3f397bdSDamjan Jovanovic }
492