bump product version to 6.4.0.3
[LibreOffice.git] / package / qa / storages / RegressionTest_i29169.java
blob12286e7589cdb08a2671a37f997d4e11e98eee99
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_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 )
45 m_xMSF = xMSF;
46 m_xStorageFactory = xStorageFactory;
47 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i29169: " );
50 public boolean test()
52 try
54 XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF );
55 if ( xTempFileStream == null )
56 return false;
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!" );
68 return false;
71 // open a new substorage
72 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
73 "SubStorage1",
74 ElementModes.WRITE );
75 if ( xTempSubStorage == null )
77 m_aTestHelper.Error( "Can't create substorage!" );
78 return false;
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 ) )
85 return false;
87 // open a new substorage in the existing substorage
88 XStorage xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
89 "SubSubStorage1",
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( xTempSubSubStorage, "SubSubStream1", "MediaType2", true, pBytes1 ) )
99 return false;
101 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
102 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubSubStorage,
103 "MediaType3",
104 false,
105 ElementModes.WRITE ) )
106 return false;
109 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
110 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
111 "MediaType4",
112 false,
113 ElementModes.WRITE ) )
114 return false;
116 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
117 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
118 "MediaType5",
119 true,
120 ElementModes.WRITE ) )
121 return false;
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" ) )
129 return false;
131 // rename the stream
132 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubStream1", "SubStream2" ) )
133 return false;
135 // commit lowlevel substorage first
136 if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) )
137 return false;
139 // rename the storage after it is committed
140 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubSubStorage2", "SubSubStorage3" ) )
141 return false;
143 // rename the stream one more time
144 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubStream2", "SubStream3" ) )
145 return false;
147 // commit substorage
148 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
149 return false;
151 // rename the storage after it's parent is committed
152 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubSubStorage3", "SubSubStorage4" ) )
153 return false;
155 // rename the stream after it's parent is committed
156 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubStream3", "SubStream4" ) )
157 return false;
159 // commit substorage to let the renaming take place
160 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
161 return false;
163 // commit the root storage so the contents must be stored now
164 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
165 return false;
167 // rename the storage after the package is committed
168 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubSubStorage4", "SubSubStorage5" ) )
169 return false;
171 // rename the stream after it's parent is committed
172 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubStream4", "SubStream5" ) )
173 return false;
175 // commit substorage to let the renaming take place
176 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
177 return false;
179 // commit the root storage so the contents must be stored now
180 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
181 return false;
184 // dispose the storages
187 // dispose lowerest substorage
188 if ( !m_aTestHelper.disposeStorage( xTempSubSubStorage ) )
189 return false;
191 // dispose substorage
192 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
193 return false;
195 // dispose the temporary storage
196 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
197 return false;
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!" );
208 return false;
211 // open the substorage
212 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
213 "SubStorage1",
214 ElementModes.WRITE );
215 if ( xTempSubStorage == null )
217 m_aTestHelper.Error( "Can't create substorage!" );
218 return false;
221 // open the lowlevel substorage
222 xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
223 "SubSubStorage5",
224 ElementModes.WRITE );
225 if ( xTempSubStorage == null )
227 m_aTestHelper.Error( "Can't create substorage!" );
228 return false;
231 // check the storages and streams
233 if ( !m_aTestHelper.checkStorageProperties( xTempSubSubStorage, "MediaType3", false, ElementModes.WRITE ) )
234 return false;
236 if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage, "MediaType4", false, ElementModes.WRITE ) )
237 return false;
239 if ( !m_aTestHelper.checkStorageProperties( xTempStorage, "MediaType5", true, ElementModes.WRITE ) )
240 return false;
242 if ( !m_aTestHelper.checkStream( xTempSubStorage, "SubStream5", "MediaType1", true, pBytes1 ) )
243 return false;
245 if ( !m_aTestHelper.checkStream( xTempSubSubStorage, "SubSubStream1", "MediaType2", true, pBytes1 ) )
246 return false;
249 // rename the reopened storages and streams
252 // rename the storage before it is committed
253 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubSubStorage5", "SubSubStorage6" ) )
254 return false;
256 // rename the stream
257 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubStream5", "SubStream6" ) )
258 return false;
260 // commit lowlevel substorage first
261 if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) )
262 return false;
264 // rename the storage after it is committed
265 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubSubStorage6", "SubSubStorage7" ) )
266 return false;
268 // rename the stream one more time
269 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubStream6", "SubStream7" ) )
270 return false;
272 // commit substorage
273 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
274 return false;
276 // rename the storage after it's parent is committed
277 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubSubStorage7", "SubSubStorage8" ) )
278 return false;
280 // rename the stream after it's parent is committed
281 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubStream7", "SubStream8" ) )
282 return false;
284 // commit substorage to let the renaming take place
285 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
286 return false;
288 // commit the root storage so the contents must be stored now
289 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
290 return false;
292 // rename the storage after the package is committed
293 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubSubStorage8", "SubSubStorage9" ) )
294 return false;
296 // rename the stream after it`s parent is committed
297 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubStream8", "SubStream9" ) )
298 return false;
300 // commit substorage to let the renaming take place
301 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
302 return false;
304 // commit the root storage so the contents must be stored now
305 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
306 return false;
309 // dispose the storages
312 // dispose lowerest substorage
313 if ( !m_aTestHelper.disposeStorage( xTempSubSubStorage ) )
314 return false;
316 // dispose substorage
317 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
318 return false;
320 // dispose the temporary storage
321 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
322 return false;
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!" );
335 return false;
338 // open the substorage
339 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
340 "SubStorage1",
341 ElementModes.READ );
342 if ( xTempSubStorage == null )
344 m_aTestHelper.Error( "Can't create substorage!" );
345 return false;
348 // open the lowlevel substorage
349 xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
350 "SubSubStorage9",
351 ElementModes.READ );
352 if ( xTempSubStorage == null )
354 m_aTestHelper.Error( "Can't create substorage!" );
355 return false;
358 // check the storages and streams
360 if ( !m_aTestHelper.checkStorageProperties( xTempSubSubStorage, "MediaType3", false, ElementModes.READ ) )
361 return false;
363 if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage, "MediaType4", false, ElementModes.READ ) )
364 return false;
366 if ( !m_aTestHelper.checkStorageProperties( xTempStorage, "MediaType5", true, ElementModes.READ ) )
367 return false;
369 if ( !m_aTestHelper.checkStream( xTempSubStorage, "SubStream9", "MediaType1", true, pBytes1 ) )
370 return false;
372 if ( !m_aTestHelper.checkStream( xTempSubSubStorage, "SubSubStream1", "MediaType2", true, pBytes1 ) )
373 return false;
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
378 return true;
380 catch( Exception e )
382 m_aTestHelper.Error( "Exception: " + e );
383 return false;