merge the formfield patch from ooo-build
[ooovba.git] / package / qa / storages / RegressionTest_i29169.java
blob137d84fa21de71607ad22db395ae308ce743a0f1
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_i29169 implements StorageTest {
21 XMultiServiceFactory m_xMSF;
22 XSingleServiceFactory m_xStorageFactory;
23 TestHelper m_aTestHelper;
25 public RegressionTest_i29169( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
27 m_xMSF = xMSF;
28 m_xStorageFactory = xStorageFactory;
29 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i29169: " );
32 public boolean test()
34 try
36 XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF );
37 if ( xTempFileStream == null )
38 return false;
40 // create storage based on the temporary stream
41 Object pArgs[] = new Object[2];
42 pArgs[0] = (Object) xTempFileStream;
43 pArgs[1] = new Integer( ElementModes.WRITE );
45 Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
46 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
47 if ( xTempStorage == null )
49 m_aTestHelper.Error( "Can't create temporary storage representation!" );
50 return false;
53 // open a new substorage
54 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
55 "SubStorage1",
56 ElementModes.WRITE );
57 if ( xTempSubStorage == null )
59 m_aTestHelper.Error( "Can't create substorage!" );
60 return false;
63 byte pBytes1[] = { 1, 1, 1, 1, 1 };
65 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
66 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
67 return false;
69 // open a new substorage in the existing substorage
70 XStorage xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
71 "SubSubStorage1",
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( xTempSubSubStorage, "SubSubStream1", "MediaType2", true, pBytes1 ) )
81 return false;
83 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
84 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubSubStorage,
85 "MediaType3",
86 false,
87 ElementModes.WRITE ) )
88 return false;
91 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
92 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
93 "MediaType4",
94 false,
95 ElementModes.WRITE ) )
96 return false;
98 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
99 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
100 "MediaType5",
101 true,
102 ElementModes.WRITE ) )
103 return false;
105 // ================================================
106 // commit the storages, and check the renaming in all stages
107 // ================================================
109 // rename the storage before it is commited
110 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubSubStorage1", "SubSubStorage2" ) )
111 return false;
113 // rename the stream
114 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubStream1", "SubStream2" ) )
115 return false;
117 // commit lowlevel substorage first
118 if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) )
119 return false;
121 // rename the storage after it is commited
122 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubSubStorage2", "SubSubStorage3" ) )
123 return false;
125 // rename the stream one more time
126 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubStream2", "SubStream3" ) )
127 return false;
129 // commit substorage
130 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
131 return false;
133 // rename the storage after it`s parent is commited
134 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubSubStorage3", "SubSubStorage4" ) )
135 return false;
137 // rename the stream after it`s parent is commited
138 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubStream3", "SubStream4" ) )
139 return false;
141 // commit substorage to let the renaming take place
142 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
143 return false;
145 // commit the root storage so the contents must be stored now
146 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
147 return false;
149 // rename the storage after the package is commited
150 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubSubStorage4", "SubSubStorage5" ) )
151 return false;
153 // rename the stream after it`s parent is commited
154 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubStream4", "SubStream5" ) )
155 return false;
157 // commit substorage to let the renaming take place
158 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
159 return false;
161 // commit the root storage so the contents must be stored now
162 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
163 return false;
165 // ================================================
166 // dispose the storages
167 // ================================================
169 // dispose lowerest substorage
170 if ( !m_aTestHelper.disposeStorage( xTempSubSubStorage ) )
171 return false;
173 // dispose substorage
174 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
175 return false;
177 // dispose the temporary storage
178 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
179 return false;
181 // ================================================
182 // create a new storage based on the stream and check the substreams and substorages
183 // ================================================
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 substorage
194 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
195 "SubStorage1",
196 ElementModes.WRITE );
197 if ( xTempSubStorage == null )
199 m_aTestHelper.Error( "Can't create substorage!" );
200 return false;
203 // open the lowlevel substorage
204 xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
205 "SubSubStorage5",
206 ElementModes.WRITE );
207 if ( xTempSubStorage == null )
209 m_aTestHelper.Error( "Can't create substorage!" );
210 return false;
213 // check the storages and streams
215 if ( !m_aTestHelper.checkStorageProperties( xTempSubSubStorage, "MediaType3", false, ElementModes.WRITE ) )
216 return false;
218 if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage, "MediaType4", false, ElementModes.WRITE ) )
219 return false;
221 if ( !m_aTestHelper.checkStorageProperties( xTempStorage, "MediaType5", true, ElementModes.WRITE ) )
222 return false;
224 if ( !m_aTestHelper.checkStream( xTempSubStorage, "SubStream5", "MediaType1", true, pBytes1 ) )
225 return false;
227 if ( !m_aTestHelper.checkStream( xTempSubSubStorage, "SubSubStream1", "MediaType2", true, pBytes1 ) )
228 return false;
230 // ================================================
231 // rename the reopened storages and streams
232 // ================================================
234 // rename the storage before it is commited
235 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubSubStorage5", "SubSubStorage6" ) )
236 return false;
238 // rename the stream
239 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubStream5", "SubStream6" ) )
240 return false;
242 // commit lowlevel substorage first
243 if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) )
244 return false;
246 // rename the storage after it is commited
247 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubSubStorage6", "SubSubStorage7" ) )
248 return false;
250 // rename the stream one more time
251 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubStream6", "SubStream7" ) )
252 return false;
254 // commit substorage
255 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
256 return false;
258 // rename the storage after it`s parent is commited
259 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubSubStorage7", "SubSubStorage8" ) )
260 return false;
262 // rename the stream after it`s parent is commited
263 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubStream7", "SubStream8" ) )
264 return false;
266 // commit substorage to let the renaming take place
267 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
268 return false;
270 // commit the root storage so the contents must be stored now
271 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
272 return false;
274 // rename the storage after the package is commited
275 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubSubStorage8", "SubSubStorage9" ) )
276 return false;
278 // rename the stream after it`s parent is commited
279 if ( !m_aTestHelper.renameElement( xTempSubStorage, "SubStream8", "SubStream9" ) )
280 return false;
282 // commit substorage to let the renaming take place
283 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
284 return false;
286 // commit the root storage so the contents must be stored now
287 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
288 return false;
290 // ================================================
291 // dispose the storages
292 // ================================================
294 // dispose lowerest substorage
295 if ( !m_aTestHelper.disposeStorage( xTempSubSubStorage ) )
296 return false;
298 // dispose substorage
299 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
300 return false;
302 // dispose the temporary storage
303 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
304 return false;
307 // ================================================
308 // create a new readonly storage based on the stream and check the contents
309 // ================================================
311 pArgs[1] = new Integer( ElementModes.READ );
312 oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
313 xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
314 if ( xTempStorage == null )
316 m_aTestHelper.Error( "Can't create temporary storage representation!" );
317 return false;
320 // open the substorage
321 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
322 "SubStorage1",
323 ElementModes.READ );
324 if ( xTempSubStorage == null )
326 m_aTestHelper.Error( "Can't create substorage!" );
327 return false;
330 // open the lowlevel substorage
331 xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
332 "SubSubStorage9",
333 ElementModes.READ );
334 if ( xTempSubStorage == null )
336 m_aTestHelper.Error( "Can't create substorage!" );
337 return false;
340 // check the storages and streams
342 if ( !m_aTestHelper.checkStorageProperties( xTempSubSubStorage, "MediaType3", false, ElementModes.READ ) )
343 return false;
345 if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage, "MediaType4", false, ElementModes.READ ) )
346 return false;
348 if ( !m_aTestHelper.checkStorageProperties( xTempStorage, "MediaType5", true, ElementModes.READ ) )
349 return false;
351 if ( !m_aTestHelper.checkStream( xTempSubStorage, "SubStream9", "MediaType1", true, pBytes1 ) )
352 return false;
354 if ( !m_aTestHelper.checkStream( xTempSubSubStorage, "SubSubStream1", "MediaType2", true, pBytes1 ) )
355 return false;
357 // the storage is based on the temporary stream so it can be left undisposed, since it does not lock
358 // any resource, later the garbage collector will release the object and it must die by refcount
360 return true;
362 catch( Exception e )
364 m_aTestHelper.Error( "Exception: " + e );
365 return false;