xref: /aoo42x/main/sal/qa/rtl/math/test-rtl-math.cxx (revision cdf0e10c)
1 /*************************************************************************
2 *
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
6 *
7 * OpenOffice.org - a multi-platform office productivity suite
8 *
9 * This file is part of OpenOffice.org.
10 *
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.
14 *
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).
20 *
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.
25 *
26 ************************************************************************/
27 
28 #include "precompiled_sal.hxx"
29 #include "sal/config.h"
30 
31 #include "cppunit/TestAssert.h"
32 #include "cppunit/TestFixture.h"
33 #include "cppunit/extensions/HelperMacros.h"
34 #include "cppunit/plugin/TestPlugIn.h"
35 #include "rtl/math.hxx"
36 #include "rtl/ustring.h"
37 #include "rtl/ustring.hxx"
38 #include "sal/types.h"
39 
40 namespace {
41 
42 class Test: public CppUnit::TestFixture {
43 public:
44     void test_stringToDouble_good() {
45         rtl_math_ConversionStatus status;
46         sal_Int32 end;
47         double res = rtl::math::stringToDouble(
48             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("  +1.E01foo")),
49             sal_Unicode('.'), sal_Unicode(','), &status, &end);
50         CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
51         CPPUNIT_ASSERT_EQUAL(sal_Int32(RTL_CONSTASCII_LENGTH("  +1.E01")), end);
52         CPPUNIT_ASSERT_EQUAL(10.0, res);
53     }
54 
55     void test_stringToDouble_bad() {
56         rtl_math_ConversionStatus status;
57         sal_Int32 end;
58         double res = rtl::math::stringToDouble(
59             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("  +Efoo")),
60             sal_Unicode('.'), sal_Unicode(','), &status, &end);
61         CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
62         CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end);
63         CPPUNIT_ASSERT_EQUAL(0.0, res);
64     }
65 
66     CPPUNIT_TEST_SUITE(Test);
67     CPPUNIT_TEST(test_stringToDouble_good);
68     CPPUNIT_TEST(test_stringToDouble_bad);
69     CPPUNIT_TEST_SUITE_END();
70 };
71 
72 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
73 
74 }
75 
76 CPPUNIT_PLUGIN_IMPLEMENT();
77