LCOV - code coverage report
Current view: top level - sal/qa/rtl/strings - test_strings_toint.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 36 36 100.0 %
Date: 2014-11-03 Functions: 22 22 100.0 %
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             : 
      10             : #include "sal/config.h"
      11             : 
      12             : #include "cppunit/TestAssert.h"
      13             : #include "cppunit/TestFixture.h"
      14             : #include "cppunit/extensions/HelperMacros.h"
      15             : #include "rtl/string.hxx"
      16             : #include "rtl/ustring.hxx"
      17             : #include "sal/types.h"
      18             : 
      19             : namespace {
      20             : 
      21          48 : template< typename T > class Test: public CppUnit::TestFixture {
      22             : private:
      23           8 :     CPPUNIT_TEST_SUITE(Test);
      24           4 :     CPPUNIT_TEST(testToInt32Overflow);
      25           4 :     CPPUNIT_TEST(testToUInt32Overflow);
      26           4 :     CPPUNIT_TEST(testToInt64Overflow);
      27           4 :     CPPUNIT_TEST(testToUInt64Overflow);
      28           8 :     CPPUNIT_TEST_SUITE_END();
      29             : 
      30           4 :     void testToInt32Overflow() {
      31           4 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(0), T("-2147483649").toInt32());
      32           4 :         CPPUNIT_ASSERT_EQUAL(SAL_MIN_INT32, T("-2147483648").toInt32());
      33           4 :         CPPUNIT_ASSERT_EQUAL(SAL_MIN_INT32 + 1, T("-2147483647").toInt32());
      34           4 :         CPPUNIT_ASSERT_EQUAL(SAL_MAX_INT32 - 1, T("2147483646").toInt32());
      35           4 :         CPPUNIT_ASSERT_EQUAL(SAL_MAX_INT32, T("2147483647").toInt32());
      36           4 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(0), T("2147483648").toInt32());
      37           4 :     }
      38             : 
      39           4 :     void testToUInt32Overflow() {
      40           4 :         CPPUNIT_ASSERT_EQUAL(SAL_MAX_UINT32 - 1, T("4294967294").toUInt32());
      41           4 :         CPPUNIT_ASSERT_EQUAL(SAL_MAX_UINT32, T("4294967295").toUInt32());
      42           4 :         CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), T("4294967296").toUInt32());
      43           4 :     }
      44             : 
      45           4 :     void testToInt64Overflow() {
      46           4 :         CPPUNIT_ASSERT_EQUAL(sal_Int64(0), T("-9223372036854775809").toInt64());
      47           4 :         CPPUNIT_ASSERT_EQUAL(
      48             :             SAL_MIN_INT64, T("-9223372036854775808").toInt64());
      49           4 :         CPPUNIT_ASSERT_EQUAL(
      50             :             SAL_MIN_INT64 + 1, T("-9223372036854775807").toInt64());
      51           4 :         CPPUNIT_ASSERT_EQUAL(
      52             :             SAL_MAX_INT64 - 1, T("9223372036854775806").toInt64());
      53           4 :         CPPUNIT_ASSERT_EQUAL(SAL_MAX_INT64, T("9223372036854775807").toInt64());
      54           4 :         CPPUNIT_ASSERT_EQUAL(sal_Int64(0), T("9223372036854775808").toInt64());
      55           4 :     }
      56             : 
      57           4 :     void testToUInt64Overflow() {
      58           4 :         CPPUNIT_ASSERT_EQUAL(
      59             :             SAL_MAX_UINT64 - 1, T("18446744073709551614").toUInt64());
      60           4 :         CPPUNIT_ASSERT_EQUAL(
      61             :             SAL_MAX_UINT64, T("18446744073709551615").toUInt64());
      62           4 :         CPPUNIT_ASSERT_EQUAL(
      63             :             sal_uInt64(0), T("18446744073709551616").toUInt64());
      64           4 :     }
      65             : };
      66             : 
      67           2 : CPPUNIT_TEST_SUITE_REGISTRATION(Test< rtl::OString >);
      68           2 : CPPUNIT_TEST_SUITE_REGISTRATION(Test< rtl::OUString >);
      69             : 
      70           6 : }
      71             : 
      72             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10