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_i30400
implements StorageTest
{
21 XMultiServiceFactory m_xMSF
;
22 XSingleServiceFactory m_xStorageFactory
;
23 TestHelper m_aTestHelper
;
25 public RegressionTest_i30400( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
28 m_xStorageFactory
= xStorageFactory
;
29 m_aTestHelper
= new TestHelper( aLogWriter
, "RegressionTest_i30400: " );
36 // ================================================
37 // create a temporary stream and a storage based on it
38 // fill the storage with the data that will be used for testing
39 // ================================================
41 XStream xTempFileStream
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
42 if ( xTempFileStream
== null )
45 // create storage based on the temporary stream
46 Object pArgs
[] = new Object
[2];
47 pArgs
[0] = (Object
) xTempFileStream
;
48 pArgs
[1] = new Integer( ElementModes
.WRITE
);
49 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
50 String pPass1
= "1, 2, 3, 4, 5";
52 Object oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
53 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
54 if ( xTempStorage
== null )
56 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
60 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
61 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
, "Stream1", "MediaType1", true, pBytes1
) )
64 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
65 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "EncrStream1", "MediaType2", true, pBytes1
, pPass1
) )
69 // open a new substorage
70 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
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( xTempSubStorage
, "SubStream1", "MediaType3", true, pBytes1
) )
83 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
84 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempSubStorage
, "SubEncrStream1", "MediaType4", true, pBytes1
, pPass1
) )
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", "MediaType5", 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
) )
123 // ================================================
124 // check the copying with renaming
125 // ================================================
127 if ( !TestCopyWithRenaming( xTempStorage
, xTempSubStorage
, xTempSubSubStorage
) )
130 // ================================================
131 // commit the storages
132 // ================================================
134 // commit lowlevel substorage
135 if ( !m_aTestHelper
.commitStorage( xTempSubSubStorage
) )
139 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
142 // commit the root storage so the contents must be stored now
143 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
146 // ================================================
147 // dispose the storages
148 // ================================================
150 // dispose lowerest substorage
151 if ( !m_aTestHelper
.disposeStorage( xTempSubSubStorage
) )
154 // dispose substorage
155 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
158 // dispose the temporary storage
159 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
162 // ================================================
163 // reopen the target storage readonly, and check the copying with renaming
164 // ================================================
166 pArgs
[1] = new Integer( ElementModes
.READ
);
167 oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
168 xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
169 if ( xTempStorage
== null )
171 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
175 // open the substorages
177 xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
180 if ( xTempSubStorage
== null )
182 m_aTestHelper
.Error( "Can't create substorage!" );
186 // open the lowlevel substorages
188 xTempSubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
191 if ( xTempSubSubStorage
== null )
193 m_aTestHelper
.Error( "Can't create substorage!" );
197 // test the copying with renaming
198 if ( !TestCopyWithRenaming( xTempStorage
, xTempSubStorage
, xTempSubSubStorage
) )
202 // the storage is based on the temporary stream so it can be left undisposed, since it does not lock
203 // any resource, later the garbage collector will release the object and it must die by refcount
209 m_aTestHelper
.Error( "Exception: " + e
);
215 public boolean TestCopyWithRenaming( XStorage xTempStorage
, XStorage xTempSubStorage
, XStorage xTempSubSubStorage
)
216 throws com
.sun
.star
.uno
.Exception
218 // ================================================
219 // create a second temporary stream and copy all the staff there
220 // with renaming, check the success
221 // ================================================
223 XStream xTempFileStream2
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
224 if ( xTempFileStream2
== null )
227 Object pArgs
[] = new Object
[2];
228 pArgs
[0] = (Object
) xTempFileStream2
;
229 pArgs
[1] = new Integer( ElementModes
.WRITE
);
230 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
231 String pPass1
= "1, 2, 3, 4, 5";
233 Object oTempStorage2
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
234 XStorage xTempStorage2
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage2
);
235 if ( xTempStorage2
== null )
237 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
241 // open a new substorage
242 XStorage xTempSubStorage2
= m_aTestHelper
.openSubStorage( xTempStorage2
,
243 "SubStorage1_target",
244 ElementModes
.WRITE
);
245 if ( xTempSubStorage2
== null )
247 m_aTestHelper
.Error( "Can't create substorage!" );
251 // open a new substorage in the existing substorage
252 XStorage xTempSubSubStorage2
= m_aTestHelper
.openSubStorage( xTempSubStorage2
,
253 "SubSubStorage1_target",
254 ElementModes
.WRITE
);
255 if ( xTempSubSubStorage2
== null )
257 m_aTestHelper
.Error( "Can't create substorage!" );
261 // make a copy with renaming on lowerest level
262 if ( !m_aTestHelper
.copyElementTo( xTempSubSubStorage
, "SubSubStream1", xTempSubSubStorage2
, "SubSubStream1_renamed" ) )
265 // make a copy with renaming on the next level
267 if ( !m_aTestHelper
.copyElementTo( xTempSubStorage
, "SubStream1", xTempSubStorage2
, "SubStream1_renamed" ) )
270 if ( !m_aTestHelper
.copyElementTo( xTempSubStorage
, "SubEncrStream1", xTempSubStorage2
, "SubEncrStream1_renamed" ) )
273 if ( !m_aTestHelper
.copyElementTo( xTempSubStorage
, "SubSubStorage1", xTempSubStorage2
, "SubSubStorage1_renamed" ) )
276 // make a copy with renaming of subelements of the root storage
278 if ( !m_aTestHelper
.copyElementTo( xTempStorage
, "Stream1", xTempStorage2
, "Stream1_renamed" ) )
281 if ( !m_aTestHelper
.copyElementTo( xTempStorage
, "EncrStream1", xTempStorage2
, "EncrStream1_renamed" ) )
284 if ( !m_aTestHelper
.copyElementTo( xTempStorage
, "SubStorage1", xTempStorage2
, "SubStorage1_renamed" ) )
287 // ================================================
288 // commit the storages, and check the renaming in all stages
289 // ================================================
291 // commit substorage to let the renaming take place
292 if ( !m_aTestHelper
.commitStorage( xTempSubSubStorage2
) )
295 // commit substorage to let the renaming take place
296 if ( !m_aTestHelper
.commitStorage( xTempSubStorage2
) )
299 // commit the root storage so the contents must be stored now
300 if ( !m_aTestHelper
.commitStorage( xTempStorage2
) )
303 // ================================================
304 // dispose the storages
305 // ================================================
307 // dispose lowerest substorage
308 if ( !m_aTestHelper
.disposeStorage( xTempSubSubStorage2
) )
311 // dispose substorage
312 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage2
) )
315 // dispose the temporary storage
316 if ( !m_aTestHelper
.disposeStorage( xTempStorage2
) )
319 // ================================================
320 // reopen the target storage readonly, and check the contents
321 // ================================================
323 pArgs
[1] = new Integer( ElementModes
.READ
);
324 oTempStorage2
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
325 xTempStorage2
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage2
);
326 if ( xTempStorage2
== null )
328 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
332 // open the substorages
334 XStorage xTempSubStorage2_target
= m_aTestHelper
.openSubStorage( xTempStorage2
,
335 "SubStorage1_target",
337 if ( xTempSubStorage2_target
== null )
339 m_aTestHelper
.Error( "Can't create substorage!" );
343 XStorage xTempSubStorage2_renamed
= m_aTestHelper
.openSubStorage( xTempStorage2
,
344 "SubStorage1_renamed",
346 if ( xTempSubStorage2_renamed
== null )
348 m_aTestHelper
.Error( "Can't create substorage!" );
352 // open the lowlevel substorages
354 XStorage xTempSubSubStorage2_inRenamed
= m_aTestHelper
.openSubStorage( xTempSubStorage2_renamed
,
357 if ( xTempSubSubStorage2_inRenamed
== null )
359 m_aTestHelper
.Error( "Can't create substorage!" );
363 XStorage xTempSubSubStorage2_renamed
= m_aTestHelper
.openSubStorage( xTempSubStorage2_target
,
364 "SubSubStorage1_renamed",
366 if ( xTempSubSubStorage2_renamed
== null )
368 m_aTestHelper
.Error( "Can't create substorage!" );
372 XStorage xTempSubSubStorage2_target
= m_aTestHelper
.openSubStorage( xTempSubStorage2_target
,
373 "SubSubStorage1_target",
375 if ( xTempSubSubStorage2_target
== null )
377 m_aTestHelper
.Error( "Can't create substorage!" );
381 // check the storages
383 if ( !m_aTestHelper
.checkStorageProperties( xTempSubSubStorage2_inRenamed
, "MediaType6", false, ElementModes
.READ
) )
386 if ( !m_aTestHelper
.checkStorageProperties( xTempSubSubStorage2_renamed
, "MediaType6", false, ElementModes
.READ
) )
389 if ( !m_aTestHelper
.checkStorageProperties( xTempSubStorage2_renamed
, "MediaType7", false, ElementModes
.READ
) )
398 if ( !m_aTestHelper
.checkStream( xTempSubSubStorage2_inRenamed
, "SubSubStream1", "MediaType5", true, pBytes1
) )
401 if ( !m_aTestHelper
.checkStream( xTempSubSubStorage2_renamed
, "SubSubStream1", "MediaType5", true, pBytes1
) )
404 if ( !m_aTestHelper
.checkStream( xTempSubSubStorage2_target
, "SubSubStream1_renamed", "MediaType5", true, pBytes1
) )
409 if ( !m_aTestHelper
.checkStream( xTempSubStorage2_renamed
, "SubStream1", "MediaType3", true, pBytes1
) )
412 if ( !m_aTestHelper
.checkEncrStream( xTempSubStorage2_renamed
, "SubEncrStream1", "MediaType4", pBytes1
, pPass1
) )
415 if ( !m_aTestHelper
.checkStream( xTempSubStorage2_target
, "SubStream1_renamed", "MediaType3", true, pBytes1
) )
418 if ( !m_aTestHelper
.checkEncrStream( xTempSubStorage2_target
, "SubEncrStream1_renamed", "MediaType4", pBytes1
, pPass1
) )
421 // root storage level
423 if ( !m_aTestHelper
.checkStream( xTempStorage2
, "Stream1_renamed", "MediaType1", true, pBytes1
) )
426 if ( !m_aTestHelper
.checkEncrStream( xTempStorage2
, "EncrStream1_renamed", "MediaType2", pBytes1
, pPass1
) )
429 // the storage is based on the temporary stream so it can be left undisposed, since it does not lock
430 // any resource, later the garbage collector will release the object and it must die by refcount