1 package complex
.storages
;
3 import com
.sun
.star
.uno
.XInterface
;
4 import com
.sun
.star
.lang
.XMultiServiceFactory
;
5 import com
.sun
.star
.lang
.XSingleServiceFactory
;
7 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
8 import com
.sun
.star
.uno
.UnoRuntime
;
9 import com
.sun
.star
.uno
.XInterface
;
10 import com
.sun
.star
.io
.XStream
;
11 import com
.sun
.star
.io
.XInputStream
;
13 import com
.sun
.star
.embed
.*;
15 import share
.LogWriter
;
16 import complex
.storages
.TestHelper
;
17 import complex
.storages
.StorageTest
;
19 public class RegressionTest_i29169
implements StorageTest
{
21 XMultiServiceFactory m_xMSF
;
22 XSingleServiceFactory m_xStorageFactory
;
23 TestHelper m_aTestHelper
;
25 public RegressionTest_i29169( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
28 m_xStorageFactory
= xStorageFactory
;
29 m_aTestHelper
= new TestHelper( aLogWriter
, "RegressionTest_i29169: " );
36 XStream xTempFileStream
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
37 if ( xTempFileStream
== null )
40 // create storage based on the temporary stream
41 Object pArgs
[] = new Object
[2];
42 pArgs
[0] = (Object
) xTempFileStream
;
43 pArgs
[1] = new Integer( ElementModes
.WRITE
);
45 Object oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
46 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
47 if ( xTempStorage
== null )
49 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
53 // open a new substorage
54 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
57 if ( xTempSubStorage
== null )
59 m_aTestHelper
.Error( "Can't create substorage!" );
63 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
65 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
66 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream1", "MediaType1", true, pBytes1
) )
69 // open a new substorage in the existing substorage
70 XStorage xTempSubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
73 if ( xTempSubStorage
== null )
75 m_aTestHelper
.Error( "Can't create substorage!" );
79 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
80 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubSubStorage
, "SubSubStream1", "MediaType2", true, pBytes1
) )
83 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
84 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubSubStorage
,
87 ElementModes
.WRITE
) )
91 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
92 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
95 ElementModes
.WRITE
) )
98 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
99 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
102 ElementModes
.WRITE
) )
105 // ================================================
106 // commit the storages, and check the renaming in all stages
107 // ================================================
109 // rename the storage before it is commited
110 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubSubStorage1", "SubSubStorage2" ) )
114 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubStream1", "SubStream2" ) )
117 // commit lowlevel substorage first
118 if ( !m_aTestHelper
.commitStorage( xTempSubSubStorage
) )
121 // rename the storage after it is commited
122 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubSubStorage2", "SubSubStorage3" ) )
125 // rename the stream one more time
126 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubStream2", "SubStream3" ) )
130 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
133 // rename the storage after it`s parent is commited
134 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubSubStorage3", "SubSubStorage4" ) )
137 // rename the stream after it`s parent is commited
138 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubStream3", "SubStream4" ) )
141 // commit substorage to let the renaming take place
142 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
145 // commit the root storage so the contents must be stored now
146 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
149 // rename the storage after the package is commited
150 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubSubStorage4", "SubSubStorage5" ) )
153 // rename the stream after it`s parent is commited
154 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubStream4", "SubStream5" ) )
157 // commit substorage to let the renaming take place
158 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
161 // commit the root storage so the contents must be stored now
162 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
165 // ================================================
166 // dispose the storages
167 // ================================================
169 // dispose lowerest substorage
170 if ( !m_aTestHelper
.disposeStorage( xTempSubSubStorage
) )
173 // dispose substorage
174 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
177 // dispose the temporary storage
178 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
181 // ================================================
182 // create a new storage based on the stream and check the substreams and substorages
183 // ================================================
185 oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
186 xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
187 if ( xTempStorage
== null )
189 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
193 // open the substorage
194 xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
196 ElementModes
.WRITE
);
197 if ( xTempSubStorage
== null )
199 m_aTestHelper
.Error( "Can't create substorage!" );
203 // open the lowlevel substorage
204 xTempSubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
206 ElementModes
.WRITE
);
207 if ( xTempSubStorage
== null )
209 m_aTestHelper
.Error( "Can't create substorage!" );
213 // check the storages and streams
215 if ( !m_aTestHelper
.checkStorageProperties( xTempSubSubStorage
, "MediaType3", false, ElementModes
.WRITE
) )
218 if ( !m_aTestHelper
.checkStorageProperties( xTempSubStorage
, "MediaType4", false, ElementModes
.WRITE
) )
221 if ( !m_aTestHelper
.checkStorageProperties( xTempStorage
, "MediaType5", true, ElementModes
.WRITE
) )
224 if ( !m_aTestHelper
.checkStream( xTempSubStorage
, "SubStream5", "MediaType1", true, pBytes1
) )
227 if ( !m_aTestHelper
.checkStream( xTempSubSubStorage
, "SubSubStream1", "MediaType2", true, pBytes1
) )
230 // ================================================
231 // rename the reopened storages and streams
232 // ================================================
234 // rename the storage before it is commited
235 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubSubStorage5", "SubSubStorage6" ) )
239 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubStream5", "SubStream6" ) )
242 // commit lowlevel substorage first
243 if ( !m_aTestHelper
.commitStorage( xTempSubSubStorage
) )
246 // rename the storage after it is commited
247 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubSubStorage6", "SubSubStorage7" ) )
250 // rename the stream one more time
251 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubStream6", "SubStream7" ) )
255 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
258 // rename the storage after it`s parent is commited
259 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubSubStorage7", "SubSubStorage8" ) )
262 // rename the stream after it`s parent is commited
263 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubStream7", "SubStream8" ) )
266 // commit substorage to let the renaming take place
267 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
270 // commit the root storage so the contents must be stored now
271 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
274 // rename the storage after the package is commited
275 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubSubStorage8", "SubSubStorage9" ) )
278 // rename the stream after it`s parent is commited
279 if ( !m_aTestHelper
.renameElement( xTempSubStorage
, "SubStream8", "SubStream9" ) )
282 // commit substorage to let the renaming take place
283 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
286 // commit the root storage so the contents must be stored now
287 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
290 // ================================================
291 // dispose the storages
292 // ================================================
294 // dispose lowerest substorage
295 if ( !m_aTestHelper
.disposeStorage( xTempSubSubStorage
) )
298 // dispose substorage
299 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
302 // dispose the temporary storage
303 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
307 // ================================================
308 // create a new readonly storage based on the stream and check the contents
309 // ================================================
311 pArgs
[1] = new Integer( ElementModes
.READ
);
312 oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
313 xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
314 if ( xTempStorage
== null )
316 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
320 // open the substorage
321 xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
324 if ( xTempSubStorage
== null )
326 m_aTestHelper
.Error( "Can't create substorage!" );
330 // open the lowlevel substorage
331 xTempSubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
334 if ( xTempSubStorage
== null )
336 m_aTestHelper
.Error( "Can't create substorage!" );
340 // check the storages and streams
342 if ( !m_aTestHelper
.checkStorageProperties( xTempSubSubStorage
, "MediaType3", false, ElementModes
.READ
) )
345 if ( !m_aTestHelper
.checkStorageProperties( xTempSubStorage
, "MediaType4", false, ElementModes
.READ
) )
348 if ( !m_aTestHelper
.checkStorageProperties( xTempStorage
, "MediaType5", true, ElementModes
.READ
) )
351 if ( !m_aTestHelper
.checkStream( xTempSubStorage
, "SubStream9", "MediaType1", true, pBytes1
) )
354 if ( !m_aTestHelper
.checkStream( xTempSubSubStorage
, "SubSubStream1", "MediaType2", true, pBytes1
) )
357 // the storage is based on the temporary stream so it can be left undisposed, since it does not lock
358 // any resource, later the garbage collector will release the object and it must die by refcount
364 m_aTestHelper
.Error( "Exception: " + e
);