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_i30400
implements StorageTest
{
39 XMultiServiceFactory m_xMSF
;
40 XSingleServiceFactory m_xStorageFactory
;
41 TestHelper m_aTestHelper
;
43 public RegressionTest_i30400( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
46 m_xStorageFactory
= xStorageFactory
;
47 m_aTestHelper
= new TestHelper( aLogWriter
, "RegressionTest_i30400: " );
55 // create a temporary stream and a storage based on it
56 // fill the storage with the data that will be used for testing
59 XStream xTempFileStream
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
60 if ( xTempFileStream
== null )
63 // create storage based on the temporary stream
64 Object pArgs
[] = new Object
[2];
65 pArgs
[0] = (Object
) xTempFileStream
;
66 pArgs
[1] = Integer
.valueOf( ElementModes
.WRITE
);
67 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
68 String pPass1
= "1, 2, 3, 4, 5";
70 Object oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
71 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
72 if ( xTempStorage
== null )
74 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
78 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
79 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
, "Stream1", "MediaType1", true, pBytes1
) )
82 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
83 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "EncrStream1", "MediaType2", true, pBytes1
, pPass1
) )
87 // open a new substorage
88 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
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( xTempSubStorage
, "SubStream1", "MediaType3", true, pBytes1
) )
101 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
102 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempSubStorage
, "SubEncrStream1", "MediaType4", true, pBytes1
, pPass1
) )
105 // open a new substorage in the existing substorage
106 XStorage xTempSubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
108 ElementModes
.WRITE
);
109 if ( xTempSubStorage
== null )
111 m_aTestHelper
.Error( "Can't create substorage!" );
115 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
116 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubSubStorage
, "SubSubStream1", "MediaType5", true, pBytes1
) )
119 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
120 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubSubStorage
,
123 ElementModes
.WRITE
) )
127 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
128 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
131 ElementModes
.WRITE
) )
134 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
135 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
138 ElementModes
.WRITE
) )
142 // check the copying with renaming
145 if ( !TestCopyWithRenaming( xTempStorage
, xTempSubStorage
, xTempSubSubStorage
) )
149 // commit the storages
152 // commit lowlevel substorage
153 if ( !m_aTestHelper
.commitStorage( xTempSubSubStorage
) )
157 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
160 // commit the root storage so the contents must be stored now
161 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
165 // dispose the storages
168 // dispose lowerest substorage
169 if ( !m_aTestHelper
.disposeStorage( xTempSubSubStorage
) )
172 // dispose substorage
173 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
176 // dispose the temporary storage
177 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
181 // reopen the target storage readonly, and check the copying with renaming
184 pArgs
[1] = Integer
.valueOf( ElementModes
.READ
);
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 substorages
195 xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
198 if ( xTempSubStorage
== null )
200 m_aTestHelper
.Error( "Can't create substorage!" );
204 // open the lowlevel substorages
206 xTempSubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
209 if ( xTempSubSubStorage
== null )
211 m_aTestHelper
.Error( "Can't create substorage!" );
215 // test the copying with renaming
216 if ( !TestCopyWithRenaming( xTempStorage
, xTempSubStorage
, xTempSubSubStorage
) )
220 // the storage is based on the temporary stream so it can be left undisposed, since it does not lock
221 // any resource, later the garbage collector will release the object and it must die by refcount
227 m_aTestHelper
.Error( "Exception: " + e
);
233 public boolean TestCopyWithRenaming( XStorage xTempStorage
, XStorage xTempSubStorage
, XStorage xTempSubSubStorage
)
234 throws com
.sun
.star
.uno
.Exception
237 // create a second temporary stream and copy all the staff there
238 // with renaming, check the success
241 XStream xTempFileStream2
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
242 if ( xTempFileStream2
== null )
245 Object pArgs
[] = new Object
[2];
246 pArgs
[0] = (Object
) xTempFileStream2
;
247 pArgs
[1] = Integer
.valueOf( ElementModes
.WRITE
);
248 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
249 String pPass1
= "1, 2, 3, 4, 5";
251 Object oTempStorage2
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
252 XStorage xTempStorage2
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage2
);
253 if ( xTempStorage2
== null )
255 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
259 // open a new substorage
260 XStorage xTempSubStorage2
= m_aTestHelper
.openSubStorage( xTempStorage2
,
261 "SubStorage1_target",
262 ElementModes
.WRITE
);
263 if ( xTempSubStorage2
== null )
265 m_aTestHelper
.Error( "Can't create substorage!" );
269 // open a new substorage in the existing substorage
270 XStorage xTempSubSubStorage2
= m_aTestHelper
.openSubStorage( xTempSubStorage2
,
271 "SubSubStorage1_target",
272 ElementModes
.WRITE
);
273 if ( xTempSubSubStorage2
== null )
275 m_aTestHelper
.Error( "Can't create substorage!" );
279 // make a copy with renaming on lowerest level
280 if ( !m_aTestHelper
.copyElementTo( xTempSubSubStorage
, "SubSubStream1", xTempSubSubStorage2
, "SubSubStream1_renamed" ) )
283 // make a copy with renaming on the next level
285 if ( !m_aTestHelper
.copyElementTo( xTempSubStorage
, "SubStream1", xTempSubStorage2
, "SubStream1_renamed" ) )
288 if ( !m_aTestHelper
.copyElementTo( xTempSubStorage
, "SubEncrStream1", xTempSubStorage2
, "SubEncrStream1_renamed" ) )
291 if ( !m_aTestHelper
.copyElementTo( xTempSubStorage
, "SubSubStorage1", xTempSubStorage2
, "SubSubStorage1_renamed" ) )
294 // make a copy with renaming of subelements of the root storage
296 if ( !m_aTestHelper
.copyElementTo( xTempStorage
, "Stream1", xTempStorage2
, "Stream1_renamed" ) )
299 if ( !m_aTestHelper
.copyElementTo( xTempStorage
, "EncrStream1", xTempStorage2
, "EncrStream1_renamed" ) )
302 if ( !m_aTestHelper
.copyElementTo( xTempStorage
, "SubStorage1", xTempStorage2
, "SubStorage1_renamed" ) )
306 // commit the storages, and check the renaming in all stages
309 // commit substorage to let the renaming take place
310 if ( !m_aTestHelper
.commitStorage( xTempSubSubStorage2
) )
313 // commit substorage to let the renaming take place
314 if ( !m_aTestHelper
.commitStorage( xTempSubStorage2
) )
317 // commit the root storage so the contents must be stored now
318 if ( !m_aTestHelper
.commitStorage( xTempStorage2
) )
322 // dispose the storages
325 // dispose lowerest substorage
326 if ( !m_aTestHelper
.disposeStorage( xTempSubSubStorage2
) )
329 // dispose substorage
330 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage2
) )
333 // dispose the temporary storage
334 if ( !m_aTestHelper
.disposeStorage( xTempStorage2
) )
338 // reopen the target storage readonly, and check the contents
341 pArgs
[1] = Integer
.valueOf( ElementModes
.READ
);
342 oTempStorage2
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
343 xTempStorage2
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage2
);
344 if ( xTempStorage2
== null )
346 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
350 // open the substorages
352 XStorage xTempSubStorage2_target
= m_aTestHelper
.openSubStorage( xTempStorage2
,
353 "SubStorage1_target",
355 if ( xTempSubStorage2_target
== null )
357 m_aTestHelper
.Error( "Can't create substorage!" );
361 XStorage xTempSubStorage2_renamed
= m_aTestHelper
.openSubStorage( xTempStorage2
,
362 "SubStorage1_renamed",
364 if ( xTempSubStorage2_renamed
== null )
366 m_aTestHelper
.Error( "Can't create substorage!" );
370 // open the lowlevel substorages
372 XStorage xTempSubSubStorage2_inRenamed
= m_aTestHelper
.openSubStorage( xTempSubStorage2_renamed
,
375 if ( xTempSubSubStorage2_inRenamed
== null )
377 m_aTestHelper
.Error( "Can't create substorage!" );
381 XStorage xTempSubSubStorage2_renamed
= m_aTestHelper
.openSubStorage( xTempSubStorage2_target
,
382 "SubSubStorage1_renamed",
384 if ( xTempSubSubStorage2_renamed
== null )
386 m_aTestHelper
.Error( "Can't create substorage!" );
390 XStorage xTempSubSubStorage2_target
= m_aTestHelper
.openSubStorage( xTempSubStorage2_target
,
391 "SubSubStorage1_target",
393 if ( xTempSubSubStorage2_target
== null )
395 m_aTestHelper
.Error( "Can't create substorage!" );
399 // check the storages
401 if ( !m_aTestHelper
.checkStorageProperties( xTempSubSubStorage2_inRenamed
, "MediaType6", false, ElementModes
.READ
) )
404 if ( !m_aTestHelper
.checkStorageProperties( xTempSubSubStorage2_renamed
, "MediaType6", false, ElementModes
.READ
) )
407 if ( !m_aTestHelper
.checkStorageProperties( xTempSubStorage2_renamed
, "MediaType7", false, ElementModes
.READ
) )
416 if ( !m_aTestHelper
.checkStream( xTempSubSubStorage2_inRenamed
, "SubSubStream1", "MediaType5", true, pBytes1
) )
419 if ( !m_aTestHelper
.checkStream( xTempSubSubStorage2_renamed
, "SubSubStream1", "MediaType5", true, pBytes1
) )
422 if ( !m_aTestHelper
.checkStream( xTempSubSubStorage2_target
, "SubSubStream1_renamed", "MediaType5", true, pBytes1
) )
427 if ( !m_aTestHelper
.checkStream( xTempSubStorage2_renamed
, "SubStream1", "MediaType3", true, pBytes1
) )
430 if ( !m_aTestHelper
.checkEncrStream( xTempSubStorage2_renamed
, "SubEncrStream1", "MediaType4", pBytes1
, pPass1
) )
433 if ( !m_aTestHelper
.checkStream( xTempSubStorage2_target
, "SubStream1_renamed", "MediaType3", true, pBytes1
) )
436 if ( !m_aTestHelper
.checkEncrStream( xTempSubStorage2_target
, "SubEncrStream1_renamed", "MediaType4", pBytes1
, pPass1
) )
439 // root storage level
441 if ( !m_aTestHelper
.checkStream( xTempStorage2
, "Stream1_renamed", "MediaType1", true, pBytes1
) )
444 if ( !m_aTestHelper
.checkEncrStream( xTempStorage2
, "EncrStream1_renamed", "MediaType2", pBytes1
, pPass1
) )
447 // the storage is based on the temporary stream so it can be left undisposed, since it does not lock
448 // any resource, later the garbage collector will release the object and it must die by refcount