Update ooo320-m1
[ooovba.git] / package / qa / storages / RegressionTest_i30400.java
blob8294b6814b9d29f2e769616222df633529f5c914
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 )
27 m_xMSF = xMSF;
28 m_xStorageFactory = xStorageFactory;
29 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i30400: " );
32 public boolean test()
34 try
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 )
43 return false;
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!" );
57 return false;
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 ) )
62 return false;
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 ) )
66 return false;
69 // open a new substorage
70 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
71 "SubStorage1",
72 ElementModes.WRITE );
73 if ( xTempSubStorage == null )
75 m_aTestHelper.Error( "Can't create substorage!" );
76 return false;
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 ) )
81 return false;
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 ) )
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", "MediaType5", 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 "MediaType6",
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 "MediaType7",
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 "MediaType8",
119 true,
120 ElementModes.WRITE ) )
121 return false;
123 // ================================================
124 // check the copying with renaming
125 // ================================================
127 if ( !TestCopyWithRenaming( xTempStorage, xTempSubStorage, xTempSubSubStorage ) )
128 return false;
130 // ================================================
131 // commit the storages
132 // ================================================
134 // commit lowlevel substorage
135 if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) )
136 return false;
138 // commit substorage
139 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
140 return false;
142 // commit the root storage so the contents must be stored now
143 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
144 return false;
146 // ================================================
147 // dispose the storages
148 // ================================================
150 // dispose lowerest substorage
151 if ( !m_aTestHelper.disposeStorage( xTempSubSubStorage ) )
152 return false;
154 // dispose substorage
155 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
156 return false;
158 // dispose the temporary storage
159 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
160 return false;
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!" );
172 return false;
175 // open the substorages
177 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
178 "SubStorage1",
179 ElementModes.READ );
180 if ( xTempSubStorage == null )
182 m_aTestHelper.Error( "Can't create substorage!" );
183 return false;
186 // open the lowlevel substorages
188 xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
189 "SubSubStorage1",
190 ElementModes.READ );
191 if ( xTempSubSubStorage == null )
193 m_aTestHelper.Error( "Can't create substorage!" );
194 return false;
197 // test the copying with renaming
198 if ( !TestCopyWithRenaming( xTempStorage, xTempSubStorage, xTempSubSubStorage ) )
199 return false;
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
205 return true;
207 catch( Exception e )
209 m_aTestHelper.Error( "Exception: " + e );
210 return false;
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 )
225 return false;
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!" );
238 return false;
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!" );
248 return false;
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!" );
258 return false;
261 // make a copy with renaming on lowerest level
262 if ( !m_aTestHelper.copyElementTo( xTempSubSubStorage, "SubSubStream1", xTempSubSubStorage2, "SubSubStream1_renamed" ) )
263 return false;
265 // make a copy with renaming on the next level
267 if ( !m_aTestHelper.copyElementTo( xTempSubStorage, "SubStream1", xTempSubStorage2, "SubStream1_renamed" ) )
268 return false;
270 if ( !m_aTestHelper.copyElementTo( xTempSubStorage, "SubEncrStream1", xTempSubStorage2, "SubEncrStream1_renamed" ) )
271 return false;
273 if ( !m_aTestHelper.copyElementTo( xTempSubStorage, "SubSubStorage1", xTempSubStorage2, "SubSubStorage1_renamed" ) )
274 return false;
276 // make a copy with renaming of subelements of the root storage
278 if ( !m_aTestHelper.copyElementTo( xTempStorage, "Stream1", xTempStorage2, "Stream1_renamed" ) )
279 return false;
281 if ( !m_aTestHelper.copyElementTo( xTempStorage, "EncrStream1", xTempStorage2, "EncrStream1_renamed" ) )
282 return false;
284 if ( !m_aTestHelper.copyElementTo( xTempStorage, "SubStorage1", xTempStorage2, "SubStorage1_renamed" ) )
285 return false;
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 ) )
293 return false;
295 // commit substorage to let the renaming take place
296 if ( !m_aTestHelper.commitStorage( xTempSubStorage2 ) )
297 return false;
299 // commit the root storage so the contents must be stored now
300 if ( !m_aTestHelper.commitStorage( xTempStorage2 ) )
301 return false;
303 // ================================================
304 // dispose the storages
305 // ================================================
307 // dispose lowerest substorage
308 if ( !m_aTestHelper.disposeStorage( xTempSubSubStorage2 ) )
309 return false;
311 // dispose substorage
312 if ( !m_aTestHelper.disposeStorage( xTempSubStorage2 ) )
313 return false;
315 // dispose the temporary storage
316 if ( !m_aTestHelper.disposeStorage( xTempStorage2 ) )
317 return false;
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!" );
329 return false;
332 // open the substorages
334 XStorage xTempSubStorage2_target = m_aTestHelper.openSubStorage( xTempStorage2,
335 "SubStorage1_target",
336 ElementModes.READ );
337 if ( xTempSubStorage2_target == null )
339 m_aTestHelper.Error( "Can't create substorage!" );
340 return false;
343 XStorage xTempSubStorage2_renamed = m_aTestHelper.openSubStorage( xTempStorage2,
344 "SubStorage1_renamed",
345 ElementModes.READ );
346 if ( xTempSubStorage2_renamed == null )
348 m_aTestHelper.Error( "Can't create substorage!" );
349 return false;
352 // open the lowlevel substorages
354 XStorage xTempSubSubStorage2_inRenamed = m_aTestHelper.openSubStorage( xTempSubStorage2_renamed,
355 "SubSubStorage1",
356 ElementModes.READ );
357 if ( xTempSubSubStorage2_inRenamed == null )
359 m_aTestHelper.Error( "Can't create substorage!" );
360 return false;
363 XStorage xTempSubSubStorage2_renamed = m_aTestHelper.openSubStorage( xTempSubStorage2_target,
364 "SubSubStorage1_renamed",
365 ElementModes.READ );
366 if ( xTempSubSubStorage2_renamed == null )
368 m_aTestHelper.Error( "Can't create substorage!" );
369 return false;
372 XStorage xTempSubSubStorage2_target = m_aTestHelper.openSubStorage( xTempSubStorage2_target,
373 "SubSubStorage1_target",
374 ElementModes.READ );
375 if ( xTempSubSubStorage2_target == null )
377 m_aTestHelper.Error( "Can't create substorage!" );
378 return false;
381 // check the storages
383 if ( !m_aTestHelper.checkStorageProperties( xTempSubSubStorage2_inRenamed, "MediaType6", false, ElementModes.READ ) )
384 return false;
386 if ( !m_aTestHelper.checkStorageProperties( xTempSubSubStorage2_renamed, "MediaType6", false, ElementModes.READ ) )
387 return false;
389 if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage2_renamed, "MediaType7", false, ElementModes.READ ) )
390 return false;
393 // check the streams
396 // sub sub level
398 if ( !m_aTestHelper.checkStream( xTempSubSubStorage2_inRenamed, "SubSubStream1", "MediaType5", true, pBytes1 ) )
399 return false;
401 if ( !m_aTestHelper.checkStream( xTempSubSubStorage2_renamed, "SubSubStream1", "MediaType5", true, pBytes1 ) )
402 return false;
404 if ( !m_aTestHelper.checkStream( xTempSubSubStorage2_target, "SubSubStream1_renamed", "MediaType5", true, pBytes1 ) )
405 return false;
407 // sub level
409 if ( !m_aTestHelper.checkStream( xTempSubStorage2_renamed, "SubStream1", "MediaType3", true, pBytes1 ) )
410 return false;
412 if ( !m_aTestHelper.checkEncrStream( xTempSubStorage2_renamed, "SubEncrStream1", "MediaType4", pBytes1, pPass1 ) )
413 return false;
415 if ( !m_aTestHelper.checkStream( xTempSubStorage2_target, "SubStream1_renamed", "MediaType3", true, pBytes1 ) )
416 return false;
418 if ( !m_aTestHelper.checkEncrStream( xTempSubStorage2_target, "SubEncrStream1_renamed", "MediaType4", pBytes1, pPass1 ) )
419 return false;
421 // root storage level
423 if ( !m_aTestHelper.checkStream( xTempStorage2, "Stream1_renamed", "MediaType1", true, pBytes1 ) )
424 return false;
426 if ( !m_aTestHelper.checkEncrStream( xTempStorage2, "EncrStream1_renamed", "MediaType2", pBytes1, pPass1 ) )
427 return false;
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
432 return true;