LCOV - code coverage report
Current view: top level - libreoffice/sal/qa/rtl/math - test-rtl-math.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 21 25 84.0 %
Date: 2012-12-27 Functions: 12 14 85.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sal/types.h>
      21             : #include "cppunit/TestAssert.h"
      22             : #include "cppunit/TestFixture.h"
      23             : #include "cppunit/extensions/HelperMacros.h"
      24             : #include "cppunit/plugin/TestPlugIn.h"
      25             : #include "rtl/math.hxx"
      26             : #include "rtl/ustring.h"
      27             : #include "rtl/ustring.hxx"
      28             : #include "sal/types.h"
      29             : 
      30             : CPPUNIT_NS_BEGIN
      31             : 
      32             : template<> struct assertion_traits<rtl_math_ConversionStatus>
      33             : {
      34           2 :     static bool equal( const rtl_math_ConversionStatus& x, const rtl_math_ConversionStatus& y )
      35             :     {
      36           2 :         return x == y;
      37             :     }
      38             : 
      39           0 :     static std::string toString( const rtl_math_ConversionStatus& x )
      40             :     {
      41           0 :         OStringStream ost;
      42           0 :         ost << static_cast<unsigned int>(x);
      43           0 :         return ost.str();
      44             :     }
      45             : };
      46             : 
      47             : CPPUNIT_NS_END
      48             : 
      49             : namespace {
      50             : 
      51           6 : class Test: public CppUnit::TestFixture {
      52             : public:
      53           1 :     void test_stringToDouble_good() {
      54             :         rtl_math_ConversionStatus status;
      55             :         sal_Int32 end;
      56             :         double res = rtl::math::stringToDouble(
      57             :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("  +1.E01foo")),
      58           1 :             sal_Unicode('.'), sal_Unicode(','), &status, &end);
      59           1 :         CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
      60           1 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(RTL_CONSTASCII_LENGTH("  +1.E01")), end);
      61           1 :         CPPUNIT_ASSERT_EQUAL(10.0, res);
      62           1 :     }
      63             : 
      64           1 :     void test_stringToDouble_bad() {
      65             :         rtl_math_ConversionStatus status;
      66             :         sal_Int32 end;
      67             :         double res = rtl::math::stringToDouble(
      68             :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("  +Efoo")),
      69           1 :             sal_Unicode('.'), sal_Unicode(','), &status, &end);
      70           1 :         CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
      71           1 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end);
      72           1 :         CPPUNIT_ASSERT_EQUAL(0.0, res);
      73           1 :     }
      74             : 
      75           2 :     CPPUNIT_TEST_SUITE(Test);
      76           1 :     CPPUNIT_TEST(test_stringToDouble_good);
      77           1 :     CPPUNIT_TEST(test_stringToDouble_bad);
      78           2 :     CPPUNIT_TEST_SUITE_END();
      79             : };
      80             : 
      81           1 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
      82             : 
      83             : }
      84             : 
      85           4 : CPPUNIT_PLUGIN_IMPLEMENT();
      86             : 
      87             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10