1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include <unotest/filters-test.hxx>
11 #include <unotest/bootstrapfixturebase.hxx>
13 #include <osl/file.hxx>
14 #include <osl/process.h>
15 #include <sot/storage.hxx>
16 #include <sot/storinfo.hxx>
18 using namespace ::com::sun::star
;
23 : public test::FiltersTest
24 , public test::BootstrapFixtureBase
29 bool checkStream( const SotStorageRef
&xObjStor
,
30 const String
&rStreamName
,
32 bool checkStorage( const SotStorageRef
&xObjStor
);
34 virtual bool load(const OUString
&,
35 const OUString
&rURL
, const OUString
&,
36 unsigned int, unsigned int, unsigned int);
40 CPPUNIT_TEST_SUITE(SotTest
);
42 CPPUNIT_TEST_SUITE_END();
45 bool SotTest::checkStream( const SotStorageRef
&xObjStor
,
46 const String
&rStreamName
,
49 unsigned char *pData
= (unsigned char*)malloc( nSize
);
50 sal_uLong nReadableSize
= 0;
54 { // Read the data in one block
55 SotStorageStreamRef
xStream( xObjStor
->OpenSotStream( rStreamName
) );
57 sal_uLong nRemaining
= xStream
->GetSize() - xStream
->Tell();
59 CPPUNIT_ASSERT_MESSAGE( "check size", nRemaining
== nSize
);
60 CPPUNIT_ASSERT_MESSAGE( "check size #2", xStream
->remainingSize() == nSize
);
62 // Read as much as we can, a corrupted FAT chain can cause real grief here
63 nReadableSize
= xStream
->Read( (void *)pData
, nSize
);
64 // fprintf(stderr, "readable size %d vs size %d remaining %d\n", nReadableSize, nSize, nReadableSize);
66 { // Read the data backwards as well
67 SotStorageStreamRef
xStream( xObjStor
->OpenSotStream( rStreamName
) );
68 for( sal_uLong i
= nReadableSize
; i
> 0; i
-- )
70 CPPUNIT_ASSERT_MESSAGE( "sot reading error", !xStream
->GetError() );
72 xStream
->Seek( i
- 1 );
73 CPPUNIT_ASSERT_MESSAGE( "sot storage reading byte",
74 xStream
->Read( &c
, 1 ) == 1);
75 CPPUNIT_ASSERT_MESSAGE( "mismatching data storage reading byte",
83 bool SotTest::checkStorage( const SotStorageRef
&xObjStor
)
85 SvStorageInfoList aInfoList
;
86 xObjStor
->FillInfoList( &aInfoList
);
88 for( SvStorageInfoList::iterator aIt
= aInfoList
.begin();
89 aIt
!= aInfoList
.end(); ++aIt
)
91 if( aIt
->IsStorage() )
93 SotStorageRef
xChild( xObjStor
->OpenSotStorage( aIt
->GetName() ) );
94 checkStorage( xChild
);
96 else if( aIt
->IsStream() )
97 checkStream( xObjStor
, aIt
->GetName(), aIt
->GetSize() );
103 bool SotTest::load(const OUString
&,
104 const OUString
&rURL
, const OUString
&,
105 unsigned int, unsigned int, unsigned int)
107 SvFileStream
aStream(rURL
, STREAM_READ
);
108 SotStorageRef xObjStor
= new SotStorage(aStream
);
109 if (!xObjStor
.Is() || xObjStor
->GetError())
112 CPPUNIT_ASSERT_MESSAGE("sot storage is not valid", xObjStor
->Validate());
113 return checkStorage (xObjStor
);
119 getURLFromSrc("/sot/qa/cppunit/data/"),
123 CPPUNIT_TEST_SUITE_REGISTRATION(SotTest
);
126 CPPUNIT_PLUGIN_IMPLEMENT();
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */