LCOV - code coverage report
Current view: top level - sal/qa/rtl/strings - test_strings_valuex.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 59 59 100.0 %
Date: 2015-06-13 12:38:46 Functions: 23 23 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/types.h>
      11             : #include <cppunit/TestFixture.h>
      12             : #include <cppunit/extensions/HelperMacros.h>
      13             : #include "rtl/ustring.hxx"
      14             : #include <iostream>
      15             : 
      16             : namespace test { namespace strings {
      17             : 
      18          18 : class valueX : public CppUnit::TestFixture {
      19             : public:
      20             :     void testOBoolean();
      21             :     void testOUBoolean();
      22             :     void testOUInt();
      23             :     void testOInt();
      24             :     void testOUFloat();
      25             :     void testOFloat();
      26             : 
      27           2 :     CPPUNIT_TEST_SUITE(valueX);
      28           1 :     CPPUNIT_TEST(testOBoolean);
      29           1 :     CPPUNIT_TEST(testOUBoolean);
      30           1 :     CPPUNIT_TEST(testOUInt);
      31           1 :     CPPUNIT_TEST(testOInt);
      32           1 :     CPPUNIT_TEST(testOUFloat);
      33           1 :     CPPUNIT_TEST(testOFloat);
      34           5 :     CPPUNIT_TEST_SUITE_END();
      35             : };
      36             : 
      37             : } }
      38             : 
      39           1 : CPPUNIT_TEST_SUITE_REGISTRATION(test::strings::valueX);
      40             : 
      41             : namespace {
      42             : 
      43             : template< typename T >
      44           2 : void testBoolean() {
      45           2 :     CPPUNIT_ASSERT_EQUAL( T( "false" ), T::boolean( false ) );
      46           2 :     CPPUNIT_ASSERT_EQUAL( T( "false" ), T::boolean( sal_False ) );
      47           2 :     CPPUNIT_ASSERT_EQUAL( T( "true" ), T::boolean( true ) );
      48           2 :     CPPUNIT_ASSERT_EQUAL( T( "true" ), T::boolean( sal_True ) );
      49           2 : }
      50             : 
      51             : }
      52             : 
      53           1 : void test::strings::valueX::testOBoolean() {
      54           1 :     testBoolean<rtl::OString>();
      55           1 : }
      56             : 
      57           1 : void test::strings::valueX::testOUBoolean() {
      58           1 :     testBoolean<rtl::OUString>();
      59           1 : }
      60             : 
      61             : template< typename T >
      62           2 : void testInt() {
      63           2 :     CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( 30039062 ));
      64             : 
      65             :     // test the overloading resolution
      66             : 
      67           2 :     CPPUNIT_ASSERT_EQUAL( T( "30" ), T::number( static_cast< signed char >( 30 )));
      68           2 :     CPPUNIT_ASSERT_EQUAL( T( "30" ), T::number( static_cast< unsigned char >( 30 )));
      69           2 :     CPPUNIT_ASSERT_EQUAL( T( "30039" ), T::number( static_cast< short >( 30039 )));
      70           2 :     CPPUNIT_ASSERT_EQUAL( T( "30039" ), T::number( static_cast< unsigned short >( 30039 )));
      71           2 :     CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< int >( 30039062 )));
      72           2 :     CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< unsigned int >( 30039062 )));
      73           2 :     CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< long >( 30039062 )));
      74           2 :     CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< unsigned long >( 30039062 )));
      75           2 :     CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< long long >( 30039062 )));
      76             :     // The highest bit set in unsigned long long may not actually work.
      77           2 :     CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< unsigned long long >( 30039062 )));
      78             : 
      79           2 :     CPPUNIT_ASSERT_EQUAL( T( "30" ), T::number( static_cast< sal_Int8 >( 30 )));
      80           2 :     CPPUNIT_ASSERT_EQUAL( T( "30" ), T::number( static_cast< sal_uInt8 >( 30 )));
      81           2 :     CPPUNIT_ASSERT_EQUAL( T( "30039" ), T::number( static_cast< sal_Int16 >( 30039 )));
      82           2 :     CPPUNIT_ASSERT_EQUAL( T( "30039" ), T::number( static_cast< sal_uInt16 >( 30039 )));
      83           2 :     CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< sal_Int32 >( 30039062 )));
      84           2 :     CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< sal_uInt32 >( 30039062 )));
      85           2 :     CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< sal_Int64 >( 30039062 )));
      86           2 :     CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( static_cast< sal_uInt64 >( 30039062 )));
      87             : 
      88             :     // The implementation internally uses sal_Int64 etc. types, so check ranges.
      89             :     assert( sizeof( int ) <= sizeof( sal_Int32 ));
      90             :     assert( sizeof( long ) <= sizeof( sal_Int64 ));
      91             :     assert( sizeof( long long ) <= sizeof( sal_Int64 ));
      92             :     assert( sizeof( unsigned int ) < sizeof( sal_Int64 ));
      93           2 : }
      94             : 
      95           1 : void test::strings::valueX::testOUInt() {
      96           1 :     testInt<rtl::OUString>();
      97           1 : }
      98             : 
      99           1 : void test::strings::valueX::testOInt() {
     100           1 :     testInt<rtl::OString>();
     101           1 : }
     102             : 
     103             : template< typename T >
     104           2 : void testFloat() {
     105           2 :     CPPUNIT_ASSERT_EQUAL( T( "39062.2" ), T::number( 39062.2f ));
     106           2 :     CPPUNIT_ASSERT_EQUAL( T( "30039062.2" ), T::number( 30039062.2 ));
     107             :     // long double not supported
     108           2 : }
     109             : 
     110           1 : void test::strings::valueX::testOUFloat() {
     111           1 :     testFloat<rtl::OUString>();
     112           1 : }
     113             : 
     114           1 : void test::strings::valueX::testOFloat() {
     115           1 :     testFloat<rtl::OString>();
     116           4 : }
     117             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11