bump product version to 6.4.0.3
[LibreOffice.git] / package / qa / storages / RegressionTest_i30400.java
blob39866503b6159936ed40e7a15f3fdd60a0e33368
1 /*
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 )
45 m_xMSF = xMSF;
46 m_xStorageFactory = xStorageFactory;
47 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i30400: " );
50 public boolean test()
52 try
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 )
61 return false;
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!" );
75 return false;
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 ) )
80 return false;
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 ) )
84 return false;
87 // open a new substorage
88 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
89 "SubStorage1",
90 ElementModes.WRITE );
91 if ( xTempSubStorage == null )
93 m_aTestHelper.Error( "Can't create substorage!" );
94 return false;
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 ) )
99 return false;
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 ) )
103 return false;
105 // open a new substorage in the existing substorage
106 XStorage xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
107 "SubSubStorage1",
108 ElementModes.WRITE );
109 if ( xTempSubStorage == null )
111 m_aTestHelper.Error( "Can't create substorage!" );
112 return false;
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 ) )
117 return false;
119 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
120 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubSubStorage,
121 "MediaType6",
122 false,
123 ElementModes.WRITE ) )
124 return false;
127 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
128 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
129 "MediaType7",
130 false,
131 ElementModes.WRITE ) )
132 return false;
134 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
135 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
136 "MediaType8",
137 true,
138 ElementModes.WRITE ) )
139 return false;
142 // check the copying with renaming
145 if ( !TestCopyWithRenaming( xTempStorage, xTempSubStorage, xTempSubSubStorage ) )
146 return false;
149 // commit the storages
152 // commit lowlevel substorage
153 if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) )
154 return false;
156 // commit substorage
157 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
158 return false;
160 // commit the root storage so the contents must be stored now
161 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
162 return false;
165 // dispose the storages
168 // dispose lowerest substorage
169 if ( !m_aTestHelper.disposeStorage( xTempSubSubStorage ) )
170 return false;
172 // dispose substorage
173 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
174 return false;
176 // dispose the temporary storage
177 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
178 return false;
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!" );
190 return false;
193 // open the substorages
195 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
196 "SubStorage1",
197 ElementModes.READ );
198 if ( xTempSubStorage == null )
200 m_aTestHelper.Error( "Can't create substorage!" );
201 return false;
204 // open the lowlevel substorages
206 xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
207 "SubSubStorage1",
208 ElementModes.READ );
209 if ( xTempSubSubStorage == null )
211 m_aTestHelper.Error( "Can't create substorage!" );
212 return false;
215 // test the copying with renaming
216 if ( !TestCopyWithRenaming( xTempStorage, xTempSubStorage, xTempSubSubStorage ) )
217 return false;
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
223 return true;
225 catch( Exception e )
227 m_aTestHelper.Error( "Exception: " + e );
228 return false;
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 )
243 return false;
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!" );
256 return false;
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!" );
266 return false;
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!" );
276 return false;
279 // make a copy with renaming on lowerest level
280 if ( !m_aTestHelper.copyElementTo( xTempSubSubStorage, "SubSubStream1", xTempSubSubStorage2, "SubSubStream1_renamed" ) )
281 return false;
283 // make a copy with renaming on the next level
285 if ( !m_aTestHelper.copyElementTo( xTempSubStorage, "SubStream1", xTempSubStorage2, "SubStream1_renamed" ) )
286 return false;
288 if ( !m_aTestHelper.copyElementTo( xTempSubStorage, "SubEncrStream1", xTempSubStorage2, "SubEncrStream1_renamed" ) )
289 return false;
291 if ( !m_aTestHelper.copyElementTo( xTempSubStorage, "SubSubStorage1", xTempSubStorage2, "SubSubStorage1_renamed" ) )
292 return false;
294 // make a copy with renaming of subelements of the root storage
296 if ( !m_aTestHelper.copyElementTo( xTempStorage, "Stream1", xTempStorage2, "Stream1_renamed" ) )
297 return false;
299 if ( !m_aTestHelper.copyElementTo( xTempStorage, "EncrStream1", xTempStorage2, "EncrStream1_renamed" ) )
300 return false;
302 if ( !m_aTestHelper.copyElementTo( xTempStorage, "SubStorage1", xTempStorage2, "SubStorage1_renamed" ) )
303 return false;
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 ) )
311 return false;
313 // commit substorage to let the renaming take place
314 if ( !m_aTestHelper.commitStorage( xTempSubStorage2 ) )
315 return false;
317 // commit the root storage so the contents must be stored now
318 if ( !m_aTestHelper.commitStorage( xTempStorage2 ) )
319 return false;
322 // dispose the storages
325 // dispose lowerest substorage
326 if ( !m_aTestHelper.disposeStorage( xTempSubSubStorage2 ) )
327 return false;
329 // dispose substorage
330 if ( !m_aTestHelper.disposeStorage( xTempSubStorage2 ) )
331 return false;
333 // dispose the temporary storage
334 if ( !m_aTestHelper.disposeStorage( xTempStorage2 ) )
335 return false;
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!" );
347 return false;
350 // open the substorages
352 XStorage xTempSubStorage2_target = m_aTestHelper.openSubStorage( xTempStorage2,
353 "SubStorage1_target",
354 ElementModes.READ );
355 if ( xTempSubStorage2_target == null )
357 m_aTestHelper.Error( "Can't create substorage!" );
358 return false;
361 XStorage xTempSubStorage2_renamed = m_aTestHelper.openSubStorage( xTempStorage2,
362 "SubStorage1_renamed",
363 ElementModes.READ );
364 if ( xTempSubStorage2_renamed == null )
366 m_aTestHelper.Error( "Can't create substorage!" );
367 return false;
370 // open the lowlevel substorages
372 XStorage xTempSubSubStorage2_inRenamed = m_aTestHelper.openSubStorage( xTempSubStorage2_renamed,
373 "SubSubStorage1",
374 ElementModes.READ );
375 if ( xTempSubSubStorage2_inRenamed == null )
377 m_aTestHelper.Error( "Can't create substorage!" );
378 return false;
381 XStorage xTempSubSubStorage2_renamed = m_aTestHelper.openSubStorage( xTempSubStorage2_target,
382 "SubSubStorage1_renamed",
383 ElementModes.READ );
384 if ( xTempSubSubStorage2_renamed == null )
386 m_aTestHelper.Error( "Can't create substorage!" );
387 return false;
390 XStorage xTempSubSubStorage2_target = m_aTestHelper.openSubStorage( xTempSubStorage2_target,
391 "SubSubStorage1_target",
392 ElementModes.READ );
393 if ( xTempSubSubStorage2_target == null )
395 m_aTestHelper.Error( "Can't create substorage!" );
396 return false;
399 // check the storages
401 if ( !m_aTestHelper.checkStorageProperties( xTempSubSubStorage2_inRenamed, "MediaType6", false, ElementModes.READ ) )
402 return false;
404 if ( !m_aTestHelper.checkStorageProperties( xTempSubSubStorage2_renamed, "MediaType6", false, ElementModes.READ ) )
405 return false;
407 if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage2_renamed, "MediaType7", false, ElementModes.READ ) )
408 return false;
411 // check the streams
414 // sub sub level
416 if ( !m_aTestHelper.checkStream( xTempSubSubStorage2_inRenamed, "SubSubStream1", "MediaType5", true, pBytes1 ) )
417 return false;
419 if ( !m_aTestHelper.checkStream( xTempSubSubStorage2_renamed, "SubSubStream1", "MediaType5", true, pBytes1 ) )
420 return false;
422 if ( !m_aTestHelper.checkStream( xTempSubSubStorage2_target, "SubSubStream1_renamed", "MediaType5", true, pBytes1 ) )
423 return false;
425 // sub level
427 if ( !m_aTestHelper.checkStream( xTempSubStorage2_renamed, "SubStream1", "MediaType3", true, pBytes1 ) )
428 return false;
430 if ( !m_aTestHelper.checkEncrStream( xTempSubStorage2_renamed, "SubEncrStream1", "MediaType4", pBytes1, pPass1 ) )
431 return false;
433 if ( !m_aTestHelper.checkStream( xTempSubStorage2_target, "SubStream1_renamed", "MediaType3", true, pBytes1 ) )
434 return false;
436 if ( !m_aTestHelper.checkEncrStream( xTempSubStorage2_target, "SubEncrStream1_renamed", "MediaType4", pBytes1, pPass1 ) )
437 return false;
439 // root storage level
441 if ( !m_aTestHelper.checkStream( xTempStorage2, "Stream1_renamed", "MediaType1", true, pBytes1 ) )
442 return false;
444 if ( !m_aTestHelper.checkEncrStream( xTempStorage2, "EncrStream1_renamed", "MediaType2", pBytes1, pPass1 ) )
445 return false;
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
450 return true;