LCOV - code coverage report
Current view: top level - ucb/source/ucp/file - filinpstr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 55 69 79.7 %
Date: 2012-08-25 Functions: 14 18 77.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 33 133 24.8 %

           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 "filinpstr.hxx"
      30                 :            : #include "filerror.hxx"
      31                 :            : #include "shell.hxx"
      32                 :            : #include "prov.hxx"
      33                 :            : 
      34                 :            : 
      35                 :            : using namespace fileaccess;
      36                 :            : using namespace com::sun::star;
      37                 :            : using namespace com::sun::star::ucb;
      38                 :            : 
      39                 :            : 
      40                 :            : 
      41                 :      18511 : XInputStream_impl::XInputStream_impl( shell* pMyShell,const rtl::OUString& aUncPath, sal_Bool bLock )
      42                 :            :     : m_xProvider( pMyShell->m_pProvider ),
      43                 :            :       m_aFile( aUncPath ),
      44                 :            :       m_nErrorCode( TASKHANDLER_NO_ERROR ),
      45 [ +  - ][ +  - ]:      18511 :       m_nMinorErrorCode( TASKHANDLER_NO_ERROR )
                 [ +  - ]
      46                 :            : {
      47                 :      18511 :     sal_uInt32 nFlags = osl_File_OpenFlag_Read;
      48         [ +  + ]:      18511 :     if ( !bLock )
      49                 :        567 :         nFlags |= osl_File_OpenFlag_NoLock;
      50                 :            : 
      51         [ +  - ]:      18511 :     osl::FileBase::RC err = m_aFile.open( nFlags );
      52         [ +  + ]:      18511 :     if( err != osl::FileBase::E_None )
      53                 :            :     {
      54                 :       2184 :         m_nIsOpen = false;
      55         [ +  - ]:       2184 :         m_aFile.close();
      56                 :            : 
      57                 :       2184 :         m_nErrorCode = TASKHANDLING_OPEN_FOR_INPUTSTREAM;
      58                 :       2184 :         m_nMinorErrorCode = err;
      59                 :            :     }
      60                 :            :     else
      61                 :      16327 :         m_nIsOpen = true;
      62                 :      18511 : }
      63                 :            : 
      64                 :            : 
      65         [ +  - ]:      18508 : XInputStream_impl::~XInputStream_impl()
      66                 :            : {
      67                 :            :     try
      68                 :            :     {
      69         [ +  - ]:      18508 :         closeInput();
      70                 :            :     }
      71         [ #  # ]:          0 :     catch (io::IOException const &)
      72                 :            :     {
      73                 :            :         OSL_FAIL("unexpected situation");
      74                 :            :     }
      75         [ #  # ]:          0 :     catch (uno::RuntimeException const &)
      76                 :            :     {
      77                 :            :         OSL_FAIL("unexpected situation");
      78                 :            :     }
      79         [ -  + ]:      37016 : }
              [ #  #  # ]
      80                 :            : 
      81                 :            : 
      82                 :      18511 : sal_Int32 SAL_CALL XInputStream_impl::CtorSuccess()
      83                 :            : {
      84                 :      18511 :     return m_nErrorCode;
      85                 :            : };
      86                 :            : 
      87                 :            : 
      88                 :            : 
      89                 :       2184 : sal_Int32 SAL_CALL XInputStream_impl::getMinorError()
      90                 :            : {
      91                 :       2184 :     return m_nMinorErrorCode;
      92                 :            : }
      93                 :            : 
      94                 :            : 
      95                 :            : //////////////////////////////////////////////////////////////////////////////////////////
      96                 :            : //  XTypeProvider
      97                 :            : //////////////////////////////////////////////////////////////////////////////////////////
      98                 :            : 
      99                 :            : 
     100 [ #  # ][ #  # ]:          0 : XTYPEPROVIDER_IMPL_3( XInputStream_impl,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     101                 :            :                       lang::XTypeProvider,
     102                 :            :                       io::XSeekable,
     103                 :            :                       io::XInputStream )
     104                 :            : 
     105                 :            : 
     106                 :            : 
     107                 :            : uno::Any SAL_CALL
     108                 :      21337 : XInputStream_impl::queryInterface(
     109                 :            :     const uno::Type& rType )
     110                 :            :     throw( uno::RuntimeException)
     111                 :            : {
     112                 :            :     uno::Any aRet = cppu::queryInterface( rType,
     113                 :            :                                           (static_cast< io::XInputStream* >(this)),
     114                 :            :                                           (static_cast< lang::XTypeProvider* >(this)),
     115         [ +  - ]:      21337 :                                           (static_cast< io::XSeekable* >(this)) );
     116 [ +  + ][ +  - ]:      21337 :     return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
     117                 :            : }
     118                 :            : 
     119                 :            : 
     120                 :            : void SAL_CALL
     121                 :     284737 : XInputStream_impl::acquire(
     122                 :            :     void )
     123                 :            :     throw()
     124                 :            : {
     125                 :     284737 :     OWeakObject::acquire();
     126                 :     284737 : }
     127                 :            : 
     128                 :            : 
     129                 :            : void SAL_CALL
     130                 :     284728 : XInputStream_impl::release(
     131                 :            :     void )
     132                 :            :     throw()
     133                 :            : {
     134                 :     284728 :     OWeakObject::release();
     135                 :     284728 : }
     136                 :            : 
     137                 :            : 
     138                 :            : 
     139                 :            : sal_Int32 SAL_CALL
     140                 :     196471 : XInputStream_impl::readBytes(
     141                 :            :                  uno::Sequence< sal_Int8 >& aData,
     142                 :            :                  sal_Int32 nBytesToRead )
     143                 :            :     throw( io::NotConnectedException,
     144                 :            :            io::BufferSizeExceededException,
     145                 :            :            io::IOException,
     146                 :            :            uno::RuntimeException)
     147                 :            : {
     148 [ -  + ][ #  # ]:     196471 :     if( ! m_nIsOpen ) throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
                 [ #  # ]
     149                 :            : 
     150         [ +  - ]:     196471 :     aData.realloc(nBytesToRead);
     151                 :            :         //TODO! translate memory exhaustion (if it were detectable...) into
     152                 :            :         // io::BufferSizeExceededException
     153                 :            : 
     154                 :     196471 :     sal_uInt64 nrc(0);
     155 [ +  - ][ +  - ]:     196471 :     if(m_aFile.read( aData.getArray(),sal_uInt64(nBytesToRead),nrc )
                 [ -  + ]
     156                 :            :        != osl::FileBase::E_None)
     157 [ #  # ][ #  # ]:          0 :         throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
     158                 :            : 
     159                 :            :     // Shrink aData in case we read less than nBytesToRead (XInputStream
     160                 :            :     // documentation does not tell whether this is required, and I do not know
     161                 :            :     // if any code relies on this, so be conservative---SB):
     162         [ +  + ]:     196471 :     if (sal::static_int_cast<sal_Int32>(nrc) != nBytesToRead)
     163         [ +  - ]:      59021 :         aData.realloc(sal_Int32(nrc));
     164                 :     196471 :     return ( sal_Int32 ) nrc;
     165                 :            : }
     166                 :            : 
     167                 :            : sal_Int32 SAL_CALL
     168                 :       7044 : XInputStream_impl::readSomeBytes(
     169                 :            :     uno::Sequence< sal_Int8 >& aData,
     170                 :            :     sal_Int32 nMaxBytesToRead )
     171                 :            :     throw( io::NotConnectedException,
     172                 :            :            io::BufferSizeExceededException,
     173                 :            :            io::IOException,
     174                 :            :            uno::RuntimeException)
     175                 :            : {
     176                 :       7044 :     return readBytes( aData,nMaxBytesToRead );
     177                 :            : }
     178                 :            : 
     179                 :            : 
     180                 :            : void SAL_CALL
     181                 :          0 : XInputStream_impl::skipBytes(
     182                 :            :     sal_Int32 nBytesToSkip )
     183                 :            :     throw( io::NotConnectedException,
     184                 :            :            io::BufferSizeExceededException,
     185                 :            :            io::IOException,
     186                 :            :            uno::RuntimeException)
     187                 :            : {
     188                 :          0 :     m_aFile.setPos( osl_Pos_Current, sal_uInt64( nBytesToSkip ) );
     189                 :          0 : }
     190                 :            : 
     191                 :            : 
     192                 :            : sal_Int32 SAL_CALL
     193                 :          0 : XInputStream_impl::available(
     194                 :            :     void )
     195                 :            :     throw( io::NotConnectedException,
     196                 :            :            io::IOException,
     197                 :            :            uno::RuntimeException)
     198                 :            : {
     199                 :          0 :     return 0;
     200                 :            : }
     201                 :            : 
     202                 :            : 
     203                 :            : void SAL_CALL
     204                 :      19417 : XInputStream_impl::closeInput(
     205                 :            :     void )
     206                 :            :     throw( io::NotConnectedException,
     207                 :            :            io::IOException,
     208                 :            :            uno::RuntimeException )
     209                 :            : {
     210         [ +  + ]:      19417 :     if( m_nIsOpen )
     211                 :            :     {
     212                 :      16324 :         osl::FileBase::RC err = m_aFile.close();
     213         [ -  + ]:      16324 :         if( err != osl::FileBase::E_None )
     214 [ #  # ][ #  # ]:          0 :             throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
     215                 :      16324 :         m_nIsOpen = false;
     216                 :            :     }
     217                 :      19417 : }
     218                 :            : 
     219                 :            : 
     220                 :            : void SAL_CALL
     221                 :      72567 : XInputStream_impl::seek(
     222                 :            :     sal_Int64 location )
     223                 :            :     throw( lang::IllegalArgumentException,
     224                 :            :            io::IOException,
     225                 :            :            uno::RuntimeException )
     226                 :            : {
     227         [ -  + ]:      72567 :     if( location < 0 )
     228 [ #  # ][ #  # ]:          0 :         throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 );
     229         [ -  + ]:      72567 :     if( osl::FileBase::E_None != m_aFile.setPos( osl_Pos_Absolut, sal_uInt64( location ) ) )
     230 [ #  # ][ #  # ]:          0 :         throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
     231                 :      72567 : }
     232                 :            : 
     233                 :            : 
     234                 :            : sal_Int64 SAL_CALL
     235                 :      10491 : XInputStream_impl::getPosition(
     236                 :            :     void )
     237                 :            :     throw( io::IOException,
     238                 :            :            uno::RuntimeException )
     239                 :            : {
     240                 :            :     sal_uInt64 uPos;
     241 [ +  - ][ -  + ]:      10491 :     if( osl::FileBase::E_None != m_aFile.getPos( uPos ) )
     242 [ #  # ][ #  # ]:          0 :         throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
     243                 :      10491 :     return sal_Int64( uPos );
     244                 :            : }
     245                 :            : 
     246                 :            : sal_Int64 SAL_CALL
     247                 :      21774 : XInputStream_impl::getLength(
     248                 :            :     void )
     249                 :            :     throw( io::IOException,
     250                 :            :            uno::RuntimeException )
     251                 :            : {
     252                 :            :     sal_uInt64 uEndPos;
     253 [ +  - ][ -  + ]:      21774 :     if ( m_aFile.getSize(uEndPos) != osl::FileBase::E_None )
     254 [ #  # ][ #  # ]:          0 :         throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
     255                 :            :     else
     256                 :      21774 :         return sal_Int64( uEndPos );
     257                 :            : }
     258                 :            : 
     259                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10