2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package complex
.storages
;
21 import com
.sun
.star
.uno
.XInterface
;
22 import com
.sun
.star
.lang
.XMultiServiceFactory
;
23 import com
.sun
.star
.lang
.XSingleServiceFactory
;
25 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
26 import com
.sun
.star
.uno
.UnoRuntime
;
27 import com
.sun
.star
.uno
.XInterface
;
28 import com
.sun
.star
.io
.XStream
;
29 import com
.sun
.star
.io
.XInputStream
;
31 import com
.sun
.star
.embed
.*;
33 import share
.LogWriter
;
34 import complex
.storages
.TestHelper
;
35 import complex
.storages
.StorageTest
;
37 public class RegressionTest_i29169
implements StorageTest
{
39 XMultiServiceFactory m_xMSF
;
40 XSingleServiceFactory m_xStorageFactory
;
41 TestHelper m_aTestHelper
;
43 public RegressionTest_i29169( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
46 m_xStorageFactory
= xStorageFactory
;
47 m_aTestHelper
= new TestHelper( aLogWriter
, "RegressionTest_i29169: " );
54 XStream xTempFileStream
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
55 if ( xTempFileStream
== null )
58 // create storage based on the temporary stream
59 Object pArgs
[] = new Object
[2];
60 pArgs
[0] = (Object
) xTempFileStream
;
61 pArgs
[1] = Integer
.valueOf( ElementModes
.WRITE
);
63 Object oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
64 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
65 if ( xTempStorage
== null )
67 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
71 // open a new substorage
72 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
75 if ( xTempSubStorage
== null )
77 m_aTestHelper
.Error( "Can't create substorage!" );
81 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
83 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
84 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream1", "MediaType1", true, pBytes1
) )
87 // open a new substorage in the existing substorage
88 XStorage xTempSubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
91 if ( xTempSubStorage
== null )
93 m_aTestHelper
.Error( "Can't create substorage!" );
97 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
98 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubSubStorage
, "SubSubStream1", "MediaType2", true, pBytes1
) )
101 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
102 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubSubStorage
,
105 ElementModes
.WRITE
) )
109 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
110 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
113 ElementModes
.WRITE
) )
116 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
117 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
120 ElementModes
.WRITE
) )
124 // commit the storages, and check the renaming in all stages
127 // rename the storage before it is committed
128 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubSubStorage1", "SubSubStorage2" ) )
132 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubStream1", "SubStream2" ) )
135 // commit lowlevel substorage first
136 if ( !m_aTestHelper
.commitStorage( xTempSubSubStorage
) )
139 // rename the storage after it is committed
140 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubSubStorage2", "SubSubStorage3" ) )
143 // rename the stream one more time
144 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubStream2", "SubStream3" ) )
148 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
151 // rename the storage after it's parent is committed
152 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubSubStorage3", "SubSubStorage4" ) )
155 // rename the stream after it's parent is committed
156 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubStream3", "SubStream4" ) )
159 // commit substorage to let the renaming take place
160 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
163 // commit the root storage so the contents must be stored now
164 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
167 // rename the storage after the package is committed
168 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubSubStorage4", "SubSubStorage5" ) )
171 // rename the stream after it's parent is committed
172 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubStream4", "SubStream5" ) )
175 // commit substorage to let the renaming take place
176 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
179 // commit the root storage so the contents must be stored now
180 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
184 // dispose the storages
187 // dispose lowerest substorage
188 if ( !m_aTestHelper
.disposeStorage( xTempSubSubStorage
) )
191 // dispose substorage
192 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
195 // dispose the temporary storage
196 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
200 // create a new storage based on the stream and check the substreams and substorages
203 oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
204 xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
205 if ( xTempStorage
== null )
207 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
211 // open the substorage
212 xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
214 ElementModes
.WRITE
);
215 if ( xTempSubStorage
== null )
217 m_aTestHelper
.Error( "Can't create substorage!" );
221 // open the lowlevel substorage
222 xTempSubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
224 ElementModes
.WRITE
);
225 if ( xTempSubStorage
== null )
227 m_aTestHelper
.Error( "Can't create substorage!" );
231 // check the storages and streams
233 if ( !m_aTestHelper
.checkStorageProperties( xTempSubSubStorage
, "MediaType3", false, ElementModes
.WRITE
) )
236 if ( !m_aTestHelper
.checkStorageProperties( xTempSubStorage
, "MediaType4", false, ElementModes
.WRITE
) )
239 if ( !m_aTestHelper
.checkStorageProperties( xTempStorage
, "MediaType5", true, ElementModes
.WRITE
) )
242 if ( !m_aTestHelper
.checkStream( xTempSubStorage
, "SubStream5", "MediaType1", true, pBytes1
) )
245 if ( !m_aTestHelper
.checkStream( xTempSubSubStorage
, "SubSubStream1", "MediaType2", true, pBytes1
) )
249 // rename the reopened storages and streams
252 // rename the storage before it is committed
253 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubSubStorage5", "SubSubStorage6" ) )
257 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubStream5", "SubStream6" ) )
260 // commit lowlevel substorage first
261 if ( !m_aTestHelper
.commitStorage( xTempSubSubStorage
) )
264 // rename the storage after it is committed
265 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubSubStorage6", "SubSubStorage7" ) )
268 // rename the stream one more time
269 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubStream6", "SubStream7" ) )
273 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
276 // rename the storage after it's parent is committed
277 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubSubStorage7", "SubSubStorage8" ) )
280 // rename the stream after it's parent is committed
281 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubStream7", "SubStream8" ) )
284 // commit substorage to let the renaming take place
285 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
288 // commit the root storage so the contents must be stored now
289 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
292 // rename the storage after the package is committed
293 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubSubStorage8", "SubSubStorage9" ) )
296 // rename the stream after it`s parent is committed
297 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubStream8", "SubStream9" ) )
300 // commit substorage to let the renaming take place
301 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
304 // commit the root storage so the contents must be stored now
305 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
309 // dispose the storages
312 // dispose lowerest substorage
313 if ( !m_aTestHelper
.disposeStorage( xTempSubSubStorage
) )
316 // dispose substorage
317 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
320 // dispose the temporary storage
321 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
326 // create a new readonly storage based on the stream and check the contents
329 pArgs
[1] = Integer
.valueOf( ElementModes
.READ
);
330 oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
331 xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
332 if ( xTempStorage
== null )
334 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
338 // open the substorage
339 xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
342 if ( xTempSubStorage
== null )
344 m_aTestHelper
.Error( "Can't create substorage!" );
348 // open the lowlevel substorage
349 xTempSubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
352 if ( xTempSubStorage
== null )
354 m_aTestHelper
.Error( "Can't create substorage!" );
358 // check the storages and streams
360 if ( !m_aTestHelper
.checkStorageProperties( xTempSubSubStorage
, "MediaType3", false, ElementModes
.READ
) )
363 if ( !m_aTestHelper
.checkStorageProperties( xTempSubStorage
, "MediaType4", false, ElementModes
.READ
) )
366 if ( !m_aTestHelper
.checkStorageProperties( xTempStorage
, "MediaType5", true, ElementModes
.READ
) )
369 if ( !m_aTestHelper
.checkStream( xTempSubStorage
, "SubStream9", "MediaType1", true, pBytes1
) )
372 if ( !m_aTestHelper
.checkStream( xTempSubSubStorage
, "SubSubStream1", "MediaType2", true, pBytes1
) )
375 // the storage is based on the temporary stream so it can be left undisposed, since it does not lock
376 // any resource, later the garbage collector will release the object and it must die by refcount
382 m_aTestHelper
.Error( "Exception: " + e
);