Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
5 : : * The contents of this file are subject to the Mozilla Public License Version
6 : : * 1.1 (the "License"); you may not use this file except in compliance with
7 : : * the License or as specified alternatively below. You may obtain a copy of
8 : : * the License at http://www.mozilla.org/MPL/
9 : : *
10 : : * Software distributed under the License is distributed on an "AS IS" basis,
11 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : : * for the specific language governing rights and limitations under the
13 : : * License.
14 : : *
15 : : * Major Contributor(s):
16 : : * Copyright (C) 2011 Red Hat, Inc., Stephan Bergmann <sbergman@redhat.com>
17 : : * (initial developer)
18 : : *
19 : : * All Rights Reserved.
20 : : *
21 : : * For minor contributions see the git repository.
22 : : *
23 : : * Alternatively, the contents of this file may be used under the terms of
24 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
25 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
26 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
27 : : * instead of those above.
28 : : */
29 : :
30 : : #include <unotest/filters-test.hxx>
31 : : #include <unotest/bootstrapfixturebase.hxx>
32 : :
33 : : #include <osl/file.hxx>
34 : : #include <osl/process.h>
35 : : #include <sot/storage.hxx>
36 : : #include <sot/storinfo.hxx>
37 : :
38 : : using namespace ::com::sun::star;
39 : :
40 : : namespace
41 : : {
42 [ + - ][ - + ]: 6 : class SotTest
43 : : : public test::FiltersTest
44 : : , public test::BootstrapFixtureBase
45 : : {
46 : : public:
47 [ + - ]: 3 : SotTest() {}
48 : :
49 : : bool checkStream( const SotStorageRef &xObjStor,
50 : : const String &rStreamName,
51 : : sal_uLong nSize );
52 : : bool checkStorage( const SotStorageRef &xObjStor );
53 : :
54 : : virtual bool load(const rtl::OUString &,
55 : : const rtl::OUString &rURL, const rtl::OUString &);
56 : :
57 : : void test();
58 : :
59 [ + - ][ + - ]: 6 : CPPUNIT_TEST_SUITE(SotTest);
[ + - ][ + - ]
[ # # ]
60 [ + - ][ + - ]: 3 : CPPUNIT_TEST(test);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
61 [ + - ][ + - ]: 6 : CPPUNIT_TEST_SUITE_END();
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
62 : : };
63 : :
64 : 150 : bool SotTest::checkStream( const SotStorageRef &xObjStor,
65 : : const String &rStreamName,
66 : : sal_uLong nSize )
67 : : {
68 : 150 : unsigned char *pData = (unsigned char*)malloc( nSize );
69 : 150 : sal_uLong nReadableSize = 0;
70 [ - + ]: 150 : if( !pData )
71 : 0 : return true;
72 : :
73 : : { // Read the data in one block
74 [ + - ]: 150 : SotStorageStreamRef xStream( xObjStor->OpenSotStream( rStreamName ) );
75 [ + - ]: 150 : xStream->Seek(0);
76 [ + - ]: 150 : sal_uLong nRemaining = xStream->GetSize() - xStream->Tell();
77 : :
78 [ + - ][ + - ]: 150 : CPPUNIT_ASSERT_MESSAGE( "check size", nRemaining == nSize );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
79 [ + - ][ + - ]: 150 : CPPUNIT_ASSERT_MESSAGE( "check size #2", xStream->remainingSize() == nSize );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
80 : :
81 : : // Read as much as we can, a corrupted FAT chain can cause real grief here
82 [ + - ][ + - ]: 150 : nReadableSize = xStream->Read( (void *)pData, nSize );
83 : : // fprintf(stderr, "readable size %d vs size %d remaining %d\n", nReadableSize, nSize, nReadableSize);
84 : : }
85 : : { // Read the data backwards as well
86 [ + - ]: 150 : SotStorageStreamRef xStream( xObjStor->OpenSotStream( rStreamName ) );
87 [ + + ]: 1930746 : for( sal_uLong i = nReadableSize; i > 0; i-- )
88 : : {
89 [ + - ][ + - ]: 1930596 : CPPUNIT_ASSERT_MESSAGE( "sot reading error", !xStream->GetError() );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
90 : : unsigned char c;
91 [ + - ]: 1930596 : xStream->Seek( i - 1 );
92 [ + - ][ + - ]: 3861192 : CPPUNIT_ASSERT_MESSAGE( "sot storage reading byte",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
93 [ + - ]: 1930596 : xStream->Read( &c, 1 ) == 1);
94 [ + - ][ + - ]: 3861192 : CPPUNIT_ASSERT_MESSAGE( "mismatching data storage reading byte",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
95 [ + - ]: 1930596 : pData[i - 1] == c );
96 [ + - ]: 150 : }
97 : : }
98 : :
99 : 150 : return true;
100 : : }
101 : :
102 : 30 : bool SotTest::checkStorage( const SotStorageRef &xObjStor )
103 : : {
104 [ + - ]: 30 : SvStorageInfoList aInfoList;
105 [ + - ]: 30 : xObjStor->FillInfoList( &aInfoList );
106 : :
107 [ + - ][ + + ]: 414 : for( SvStorageInfoList::iterator aIt = aInfoList.begin();
108 : 207 : aIt != aInfoList.end(); ++aIt )
109 : : {
110 : : // fprintf( stderr, "Stream '%s' size %ld\n",
111 : : // rtl::OUStringToOString( aIt->GetName(), RTL_TEXTENCODING_UTF8 ).getStr(),
112 : : // (long)aIt->GetSize() );
113 [ + + ]: 177 : if( aIt->IsStorage() )
114 : : {
115 [ + - ]: 24 : SotStorageRef xChild( xObjStor->OpenSotStorage( aIt->GetName() ) );
116 [ + - ][ + - ]: 24 : checkStorage( xChild );
117 : : }
118 [ + + ]: 153 : else if( aIt->IsStream() )
119 [ + - ]: 150 : checkStream( xObjStor, aIt->GetName(), aIt->GetSize() );
120 : : }
121 : :
122 : 30 : return true;
123 : : }
124 : :
125 : 6 : bool SotTest::load(const rtl::OUString &,
126 : : const rtl::OUString &rURL, const rtl::OUString &)
127 : : {
128 [ + - ][ + - ]: 6 : SvFileStream aStream(rURL, STREAM_READ);
[ + - ]
129 [ + - ][ + - ]: 6 : SotStorageRef xObjStor = new SotStorage(aStream);
130 [ - + ][ - + ]: 6 : if (!xObjStor.Is() || xObjStor->GetError())
[ + - ]
131 : 0 : return false;
132 : :
133 [ + - ][ + - ]: 6 : CPPUNIT_ASSERT_MESSAGE("sot storage is not valid", xObjStor->Validate());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
134 [ + - ][ + - ]: 6 : return checkStorage (xObjStor);
[ + - ]
135 : : }
136 : :
137 : 3 : void SotTest::test()
138 : : {
139 : : testDir(rtl::OUString(),
140 : : getURLFromSrc("/sot/qa/cppunit/data/"),
141 [ + - ][ + - ]: 3 : rtl::OUString());
142 : 3 : }
143 : :
144 : 3 : CPPUNIT_TEST_SUITE_REGISTRATION(SotTest);
145 : : }
146 : :
147 [ + - ][ + - ]: 12 : CPPUNIT_PLUGIN_IMPLEMENT();
[ + - ][ + - ]
[ + - ][ # # ]
148 : :
149 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|