xref: /aoo4110/main/sal/qa/rtl/math/test-rtl-math.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_sal.hxx"
25 #include "sal/config.h"
26 
27 #include "cppunit/TestAssert.h"
28 #include "cppunit/TestFixture.h"
29 #include "cppunit/extensions/HelperMacros.h"
30 #include "cppunit/plugin/TestPlugIn.h"
31 #include "rtl/math.hxx"
32 #include "rtl/ustring.h"
33 #include "rtl/ustring.hxx"
34 #include "sal/types.h"
35 
36 namespace {
37 
38 class Test: public CppUnit::TestFixture {
39 public:
test_stringToDouble_good()40     void test_stringToDouble_good() {
41         rtl_math_ConversionStatus status;
42         sal_Int32 end;
43         double res = rtl::math::stringToDouble(
44             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("  +1.E01foo")),
45             sal_Unicode('.'), sal_Unicode(','), &status, &end);
46         CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
47         CPPUNIT_ASSERT_EQUAL(sal_Int32(RTL_CONSTASCII_LENGTH("  +1.E01")), end);
48         CPPUNIT_ASSERT_EQUAL(10.0, res);
49     }
50 
test_stringToDouble_bad()51     void test_stringToDouble_bad() {
52         rtl_math_ConversionStatus status;
53         sal_Int32 end;
54         double res = rtl::math::stringToDouble(
55             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("  +Efoo")),
56             sal_Unicode('.'), sal_Unicode(','), &status, &end);
57         CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
58         CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end);
59         CPPUNIT_ASSERT_EQUAL(0.0, res);
60     }
61 
62     CPPUNIT_TEST_SUITE(Test);
63     CPPUNIT_TEST(test_stringToDouble_good);
64     CPPUNIT_TEST(test_stringToDouble_bad);
65     CPPUNIT_TEST_SUITE_END();
66 };
67 
68 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
69 
70 }
71 
72 CPPUNIT_PLUGIN_IMPLEMENT();
73