LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sot/qa/cppunit - test_sot.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 47 49 95.9 %
Date: 2013-07-09 Functions: 13 14 92.9 %
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 <unotest/filters-test.hxx>
      11             : #include <unotest/bootstrapfixturebase.hxx>
      12             : 
      13             : #include <osl/file.hxx>
      14             : #include <osl/process.h>
      15             : #include <sot/storage.hxx>
      16             : #include <sot/storinfo.hxx>
      17             : 
      18             : using namespace ::com::sun::star;
      19             : 
      20             : namespace
      21             : {
      22           2 :     class SotTest
      23             :         : public test::FiltersTest
      24             :         , public test::BootstrapFixtureBase
      25             :     {
      26             :     public:
      27           1 :         SotTest() {}
      28             : 
      29             :         bool checkStream( const SotStorageRef &xObjStor,
      30             :                           const OUString &rStreamName,
      31             :                           sal_uLong nSize );
      32             :         bool checkStorage( const SotStorageRef &xObjStor );
      33             : 
      34             :         virtual bool load(const OUString &,
      35             :             const OUString &rURL, const OUString &,
      36             :             unsigned int, unsigned int, unsigned int);
      37             : 
      38             :         void test();
      39             : 
      40           2 :         CPPUNIT_TEST_SUITE(SotTest);
      41           1 :         CPPUNIT_TEST(test);
      42           2 :         CPPUNIT_TEST_SUITE_END();
      43             :     };
      44             : 
      45          61 :     bool SotTest::checkStream( const SotStorageRef &xObjStor,
      46             :                                const OUString &rStreamName,
      47             :                                sal_uLong nSize )
      48             :     {
      49          61 :         unsigned char *pData = (unsigned char*)malloc( nSize );
      50          61 :         sal_uLong nReadableSize = 0;
      51          61 :         if( !pData )
      52           0 :             return true;
      53             : 
      54             :         {   // Read the data in one block
      55          61 :             SotStorageStreamRef xStream( xObjStor->OpenSotStream( rStreamName ) );
      56          61 :             xStream->Seek(0);
      57          61 :             sal_uLong nRemaining = xStream->GetSize() - xStream->Tell();
      58             : 
      59          61 :             CPPUNIT_ASSERT_MESSAGE( "check size", nRemaining == nSize );
      60          61 :             CPPUNIT_ASSERT_MESSAGE( "check size #2", xStream->remainingSize() == nSize );
      61             : 
      62             :             // Read as much as we can, a corrupted FAT chain can cause real grief here
      63          61 :             nReadableSize = xStream->Read( (void *)pData, nSize );
      64             : //            fprintf(stderr, "readable size %d vs size %d remaining %d\n", nReadableSize, nSize, nReadableSize);
      65             :         }
      66             :         {   // Read the data backwards as well
      67          61 :             SotStorageStreamRef xStream( xObjStor->OpenSotStream( rStreamName ) );
      68      683602 :             for( sal_uLong i = nReadableSize; i > 0; i-- )
      69             :             {
      70      683541 :                 CPPUNIT_ASSERT_MESSAGE( "sot reading error", !xStream->GetError() );
      71             :                 unsigned char c;
      72      683541 :                 xStream->Seek( i - 1 );
      73     1367082 :                 CPPUNIT_ASSERT_MESSAGE( "sot storage reading byte",
      74      683541 :                                         xStream->Read( &c, 1 ) == 1);
      75     1367082 :                 CPPUNIT_ASSERT_MESSAGE( "mismatching data storage reading byte",
      76      683541 :                                         pData[i - 1] == c );
      77          61 :             }
      78             :         }
      79             : 
      80          61 :         return true;
      81             :     }
      82             : 
      83          14 :     bool SotTest::checkStorage( const SotStorageRef &xObjStor )
      84             :     {
      85          14 :         SvStorageInfoList aInfoList;
      86          14 :         xObjStor->FillInfoList( &aInfoList );
      87             : 
      88         258 :         for( SvStorageInfoList::iterator aIt = aInfoList.begin();
      89         172 :              aIt != aInfoList.end(); ++aIt )
      90             :         {
      91          72 :             if( aIt->IsStorage() )
      92             :             {
      93          10 :                 SotStorageRef xChild( xObjStor->OpenSotStorage( aIt->GetName() ) );
      94          10 :                 checkStorage( xChild );
      95             :             }
      96          62 :             else if( aIt->IsStream() )
      97          61 :                 checkStream( xObjStor, aIt->GetName(), aIt->GetSize() );
      98             :         }
      99             : 
     100          14 :         return true;
     101             :     }
     102             : 
     103           4 :     bool SotTest::load(const OUString &,
     104             :         const OUString &rURL, const OUString &,
     105             :         unsigned int, unsigned int, unsigned int)
     106             :     {
     107           4 :         SvFileStream aStream(rURL, STREAM_READ);
     108           8 :         SotStorageRef xObjStor = new SotStorage(aStream);
     109           4 :         if (!xObjStor.Is() || xObjStor->GetError())
     110           0 :             return false;
     111             : 
     112           4 :         CPPUNIT_ASSERT_MESSAGE("sot storage is not valid", xObjStor->Validate());
     113           8 :         return checkStorage (xObjStor);
     114             :     }
     115             : 
     116           1 :     void SotTest::test()
     117             :     {
     118             :         testDir(OUString(),
     119             :             getURLFromSrc("/sot/qa/cppunit/data/"),
     120           1 :             OUString());
     121           1 :     }
     122             : 
     123           1 :     CPPUNIT_TEST_SUITE_REGISTRATION(SotTest);
     124             : }
     125             : 
     126           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     127             : 
     128             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10