LCOV - code coverage report
Current view: top level - sal/qa/rtl/math - test-rtl-math.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 21 25 84.0 %
Date: 2012-08-25 Functions: 12 14 85.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 63 138 45.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            : *
       4                 :            : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            : *
       6                 :            : * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            : *
       8                 :            : * OpenOffice.org - a multi-platform office productivity suite
       9                 :            : *
      10                 :            : * This file is part of OpenOffice.org.
      11                 :            : *
      12                 :            : * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            : * it under the terms of the GNU Lesser General Public License version 3
      14                 :            : * only, as published by the Free Software Foundation.
      15                 :            : *
      16                 :            : * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            : * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            : * GNU Lesser General Public License version 3 for more details
      20                 :            : * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            : *
      22                 :            : * You should have received a copy of the GNU Lesser General Public License
      23                 :            : * version 3 along with OpenOffice.org.  If not, see
      24                 :            : * <http://www.openoffice.org/license.html>
      25                 :            : * for a copy of the LGPLv3 License.
      26                 :            : *
      27                 :            : ************************************************************************/
      28                 :            : 
      29                 :            : #include <sal/types.h>
      30                 :            : #include "cppunit/TestAssert.h"
      31                 :            : #include "cppunit/TestFixture.h"
      32                 :            : #include "cppunit/extensions/HelperMacros.h"
      33                 :            : #include "cppunit/plugin/TestPlugIn.h"
      34                 :            : #include "rtl/math.hxx"
      35                 :            : #include "rtl/ustring.h"
      36                 :            : #include "rtl/ustring.hxx"
      37                 :            : #include "sal/types.h"
      38                 :            : 
      39                 :            : CPPUNIT_NS_BEGIN
      40                 :            : 
      41                 :            : template<> struct assertion_traits<rtl_math_ConversionStatus>
      42                 :            : {
      43                 :         10 :     static bool equal( const rtl_math_ConversionStatus& x, const rtl_math_ConversionStatus& y )
      44                 :            :     {
      45                 :         10 :         return x == y;
      46                 :            :     }
      47                 :            : 
      48                 :          0 :     static std::string toString( const rtl_math_ConversionStatus& x )
      49                 :            :     {
      50         [ #  # ]:          0 :         OStringStream ost;
      51         [ #  # ]:          0 :         ost << static_cast<unsigned int>(x);
      52 [ #  # ][ #  # ]:          0 :         return ost.str();
      53                 :            :     }
      54                 :            : };
      55                 :            : 
      56                 :            : CPPUNIT_NS_END
      57                 :            : 
      58                 :            : namespace {
      59                 :            : 
      60         [ -  + ]:         30 : class Test: public CppUnit::TestFixture {
      61                 :            : public:
      62                 :          5 :     void test_stringToDouble_good() {
      63                 :            :         rtl_math_ConversionStatus status;
      64                 :            :         sal_Int32 end;
      65                 :            :         double res = rtl::math::stringToDouble(
      66                 :            :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("  +1.E01foo")),
      67         [ +  - ]:          5 :             sal_Unicode('.'), sal_Unicode(','), &status, &end);
      68 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
         [ +  - ][ +  - ]
                 [ +  - ]
      69 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(RTL_CONSTASCII_LENGTH("  +1.E01")), end);
         [ +  - ][ +  - ]
                 [ +  - ]
      70 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_EQUAL(10.0, res);
         [ +  - ][ +  - ]
                 [ +  - ]
      71                 :          5 :     }
      72                 :            : 
      73                 :          5 :     void test_stringToDouble_bad() {
      74                 :            :         rtl_math_ConversionStatus status;
      75                 :            :         sal_Int32 end;
      76                 :            :         double res = rtl::math::stringToDouble(
      77                 :            :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("  +Efoo")),
      78         [ +  - ]:          5 :             sal_Unicode('.'), sal_Unicode(','), &status, &end);
      79 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
         [ +  - ][ +  - ]
                 [ +  - ]
      80 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end);
         [ +  - ][ +  - ]
                 [ +  - ]
      81 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_EQUAL(0.0, res);
         [ +  - ][ +  - ]
                 [ +  - ]
      82                 :          5 :     }
      83                 :            : 
      84 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE(Test);
         [ +  - ][ +  - ]
                 [ #  # ]
      85 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(test_stringToDouble_good);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      86 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(test_stringToDouble_bad);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      87 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE_END();
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      88                 :            : };
      89                 :            : 
      90                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
      91                 :            : 
      92                 :            : }
      93                 :            : 
      94 [ +  - ][ +  - ]:         20 : CPPUNIT_PLUGIN_IMPLEMENT();
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
      95                 :            : 
      96                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10