LCOV - code coverage report
Current view: top level - sot/source/sdstor - stgole.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 90 102 88.2 %
Date: 2012-08-25 Functions: 12 14 85.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 54 118 45.8 %

           Branch data     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                 :            : 
      21                 :            : #include "rtl/string.h"
      22                 :            : #include "rtl/string.h"
      23                 :            : #include "stgole.hxx"
      24                 :            : #include "sot/storinfo.hxx"     // Read/WriteClipboardFormat()
      25                 :            : 
      26                 :            : #if defined(_MSC_VER) && (_MSC_VER>=1400)
      27                 :            : #pragma warning(disable: 4342)
      28                 :            : #endif
      29                 :            : ///////////////////////// class StgInternalStream ////////////////////////
      30                 :            : 
      31                 :        105 : StgInternalStream::StgInternalStream
      32                 :        105 :     ( BaseStorage& rStg, const String& rName, sal_Bool bWr )
      33                 :            : {
      34                 :        105 :     bIsWritable = sal_True;
      35                 :            :     sal_uInt16 nMode = bWr
      36                 :            :                  ? STREAM_WRITE | STREAM_SHARE_DENYALL
      37         [ +  + ]:        105 :                  : STREAM_READ | STREAM_SHARE_DENYWRITE | STREAM_NOCREATE;
      38         [ +  - ]:        105 :     pStrm = rStg.OpenStream( rName, nMode );
      39                 :            : 
      40                 :            :     // set the error code right here in the stream
      41 [ +  - ][ +  - ]:        105 :     SetError( rStg.GetError() );
      42         [ +  - ]:        105 :     SetBufferSize( 1024 );
      43                 :        105 : }
      44                 :            : 
      45                 :        105 : StgInternalStream::~StgInternalStream()
      46                 :            : {
      47 [ +  - ][ +  - ]:        105 :     delete pStrm;
      48         [ -  + ]:        105 : }
      49                 :            : 
      50                 :         81 : sal_uLong StgInternalStream::GetData( void* pData, sal_uLong nSize )
      51                 :            : {
      52         [ +  - ]:         81 :     if( pStrm )
      53                 :            :     {
      54                 :         81 :         nSize = pStrm->Read( pData, nSize );
      55                 :         81 :         SetError( pStrm->GetError() );
      56                 :         81 :         return nSize;
      57                 :            :     }
      58                 :            :     else
      59                 :         81 :         return 0;
      60                 :            : }
      61                 :            : 
      62                 :         24 : sal_uLong StgInternalStream::PutData( const void* pData, sal_uLong nSize )
      63                 :            : {
      64         [ +  - ]:         24 :     if( pStrm )
      65                 :            :     {
      66                 :         24 :         nSize = pStrm->Write( pData, nSize );
      67                 :         24 :         SetError( pStrm->GetError() );
      68                 :         24 :         return nSize;
      69                 :            :     }
      70                 :            :     else
      71                 :         24 :         return 0;
      72                 :            : }
      73                 :            : 
      74                 :        186 : sal_uLong StgInternalStream::SeekPos( sal_uLong nPos )
      75                 :            : {
      76         [ +  - ]:        186 :     return pStrm ? pStrm->Seek( nPos ) : 0;
      77                 :            : }
      78                 :            : 
      79                 :         24 : void StgInternalStream::FlushData()
      80                 :            : {
      81         [ +  - ]:         24 :     if( pStrm )
      82                 :            :     {
      83                 :         24 :         pStrm->Flush();
      84                 :         24 :         SetError( pStrm->GetError() );
      85                 :            :     }
      86                 :         24 : }
      87                 :            : 
      88                 :         24 : void StgInternalStream::Commit()
      89                 :            : {
      90                 :         24 :     Flush();
      91                 :         24 :     pStrm->Commit();
      92                 :         24 : }
      93                 :            : 
      94                 :            : ///////////////////////// class StgCompObjStream /////////////////////////
      95                 :            : 
      96                 :         93 : StgCompObjStream::StgCompObjStream( BaseStorage& rStg, sal_Bool bWr )
      97 [ +  - ][ +  - ]:         93 :             : StgInternalStream( rStg, rtl::OUString("\1CompObj"), bWr )
         [ +  - ][ +  - ]
      98                 :            : {
      99                 :         93 :     memset( &aClsId, 0, sizeof( ClsId ) );
     100                 :         93 :     nCbFormat = 0;
     101                 :         93 : }
     102                 :            : 
     103                 :         81 : sal_Bool StgCompObjStream::Load()
     104                 :            : {
     105                 :         81 :     memset( &aClsId, 0, sizeof( ClsId ) );
     106                 :         81 :     nCbFormat = 0;
     107         [ +  - ]:         81 :     aUserName.Erase();
     108         [ -  + ]:         81 :     if( GetError() != SVSTREAM_OK )
     109                 :          0 :         return sal_False;
     110         [ +  - ]:         81 :     Seek( 8L );     // skip the first part
     111                 :         81 :     sal_Int32 nMarker = 0;
     112         [ +  - ]:         81 :     *this >> nMarker;
     113         [ +  - ]:         81 :     if( nMarker == -1L )
     114                 :            :     {
     115         [ +  - ]:         81 :         *this >> aClsId;
     116                 :         81 :         sal_Int32 nLen1 = 0;
     117         [ +  - ]:         81 :         *this >> nLen1;
     118         [ +  - ]:         81 :         if ( nLen1 > 0 )
     119                 :            :         {
     120                 :            :             // higher bits are ignored
     121         [ +  - ]:         81 :             sal_uLong nStrLen = ::std::min( nLen1, (sal_Int32)0xFFFE );
     122                 :            : 
     123         [ +  - ]:         81 :             sal_Char* p = new sal_Char[ nStrLen+1 ];
     124                 :         81 :             p[nStrLen] = 0;
     125 [ +  - ][ +  - ]:         81 :             if( Read( p, nStrLen ) == nStrLen )
     126                 :            :             {
     127                 :            :                 //The encoding here is "ANSI", which is pretty useless seeing as
     128                 :            :                 //the actual codepage used doesn't seem to be specified/stored
     129                 :            :                 //anywhere :-(. Might as well pick 1252 and be consistent on
     130                 :            :                 //all platforms and envs
     131                 :            :                 //http://www.openoffice.org/nonav/issues/showattachment.cgi/68668/Orginal%20Document.doc
     132                 :            :                 //for a good edge-case example
     133 [ +  - ][ +  - ]:         81 :                 aUserName = nStrLen ? String( p, RTL_TEXTENCODING_MS_1252 ) : String();
         [ #  # ][ +  - ]
                 [ +  - ]
     134         [ +  - ]:         81 :                 nCbFormat = ReadClipboardFormat( *this );
     135                 :            :             }
     136                 :            :             else
     137         [ #  # ]:          0 :                 SetError( SVSTREAM_GENERALERROR );
     138         [ +  - ]:         81 :             delete [] p;
     139                 :            :         }
     140                 :            :     }
     141                 :         81 :     return sal_Bool( GetError() == SVSTREAM_OK );
     142                 :            : }
     143                 :            : 
     144                 :         12 : sal_Bool StgCompObjStream::Store()
     145                 :            : {
     146         [ -  + ]:         12 :     if( GetError() != SVSTREAM_OK )
     147                 :          0 :         return sal_False;
     148         [ +  - ]:         12 :     Seek( 0L );
     149 [ +  - ][ +  - ]:         12 :     rtl::OString aAsciiUserName(rtl::OUStringToOString(aUserName, RTL_TEXTENCODING_MS_1252));
     150         [ +  - ]:         12 :     *this << (sal_Int16) 1          // Version?
     151         [ +  - ]:         12 :               << (sal_Int16) -2                     // 0xFFFE = Byte Order Indicator
     152         [ +  - ]:         12 :               << (sal_Int32) 0x0A03         // Windows 3.10
     153         [ +  - ]:         12 :               << (sal_Int32) -1L
     154         [ +  - ]:         12 :               << aClsId             // Class ID
     155         [ +  - ]:         24 :               << (sal_Int32) (aAsciiUserName.getLength() + 1)
     156         [ +  - ]:         24 :               << (const char *)aAsciiUserName.getStr()
     157         [ +  - ]:         12 :               << (sal_uInt8) 0;             // string terminator
     158         [ +  - ]:         12 :     WriteClipboardFormat( *this, nCbFormat );
     159         [ +  - ]:         12 :     *this << (sal_Int32) 0;             // terminator
     160         [ +  - ]:         12 :     Commit();
     161                 :         12 :     return sal_Bool( GetError() == SVSTREAM_OK );
     162                 :            : }
     163                 :            : 
     164                 :            : /////////////////////////// class StgOleStream ///////////////////////////
     165                 :            : 
     166                 :         12 : StgOleStream::StgOleStream( BaseStorage& rStg, sal_Bool bWr )
     167 [ +  - ][ +  - ]:         12 :             : StgInternalStream( rStg, rtl::OUString("\1Ole"), bWr )
                 [ +  - ]
     168                 :            : {
     169                 :         12 :     nFlags = 0;
     170                 :         12 : }
     171                 :            : 
     172                 :          0 : sal_Bool StgOleStream::Load()
     173                 :            : {
     174                 :          0 :     nFlags = 0;
     175         [ #  # ]:          0 :     if( GetError() != SVSTREAM_OK )
     176                 :          0 :         return sal_False;
     177                 :          0 :     sal_Int32 version = 0;
     178         [ #  # ]:          0 :     Seek( 0L );
     179 [ #  # ][ #  # ]:          0 :     *this >> version >> nFlags;
     180                 :          0 :     return sal_Bool( GetError() == SVSTREAM_OK );
     181                 :            : }
     182                 :            : 
     183                 :         12 : sal_Bool StgOleStream::Store()
     184                 :            : {
     185         [ -  + ]:         12 :     if( GetError() != SVSTREAM_OK )
     186                 :          0 :         return sal_False;
     187                 :         12 :     Seek( 0L );
     188                 :         12 :     *this << (sal_Int32) 0x02000001         // OLE version, format
     189                 :         12 :           << (sal_Int32) nFlags             // Object flags
     190                 :         12 :           << (sal_Int32) 0                  // Update Options
     191                 :         12 :           << (sal_Int32) 0                  // reserved
     192                 :         12 :           << (sal_Int32) 0;                 // Moniker 1
     193                 :         12 :     Commit();
     194                 :         12 :     return sal_Bool( GetError() == SVSTREAM_OK );
     195                 :            : }
     196                 :            : 
     197                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10