bump product version to 4.1.6.2
[LibreOffice.git] / sot / qa / cppunit / test_sot.cxx
blobc88bcacb784202698fa666a1aada4d14354f1afc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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;
20 namespace
22 class SotTest
23 : public test::FiltersTest
24 , public test::BootstrapFixtureBase
26 public:
27 SotTest() {}
29 bool checkStream( const SotStorageRef &xObjStor,
30 const String &rStreamName,
31 sal_uLong nSize );
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);
38 void test();
40 CPPUNIT_TEST_SUITE(SotTest);
41 CPPUNIT_TEST(test);
42 CPPUNIT_TEST_SUITE_END();
45 bool SotTest::checkStream( const SotStorageRef &xObjStor,
46 const String &rStreamName,
47 sal_uLong nSize )
49 unsigned char *pData = (unsigned char*)malloc( nSize );
50 sal_uLong nReadableSize = 0;
51 if( !pData )
52 return true;
54 { // Read the data in one block
55 SotStorageStreamRef xStream( xObjStor->OpenSotStream( rStreamName ) );
56 xStream->Seek(0);
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() );
71 unsigned char c;
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",
76 pData[i - 1] == c );
80 return true;
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() );
100 return true;
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())
110 return false;
112 CPPUNIT_ASSERT_MESSAGE("sot storage is not valid", xObjStor->Validate());
113 return checkStorage (xObjStor);
116 void SotTest::test()
118 testDir(OUString(),
119 getURLFromSrc("/sot/qa/cppunit/data/"),
120 OUString());
123 CPPUNIT_TEST_SUITE_REGISTRATION(SotTest);
126 CPPUNIT_PLUGIN_IMPLEMENT();
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */