merge the formfield patch from ooo-build
[ooovba.git] / package / qa / storages / RegressionTest_i27773.java
blob6753541508fde5a59f272358d4f4c24bd73c8f83
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;
12 import com.sun.star.beans.XPropertySet;
13 import com.sun.star.uno.AnyConverter;
15 import com.sun.star.embed.*;
17 import share.LogWriter;
18 import complex.storages.TestHelper;
19 import complex.storages.StorageTest;
21 ///////////////////////////////////
22 // Tests also fix for i51352
23 ///////////////////////////////////
25 public class RegressionTest_i27773 implements StorageTest {
27 XMultiServiceFactory m_xMSF;
28 XSingleServiceFactory m_xStorageFactory;
29 TestHelper m_aTestHelper;
31 public RegressionTest_i27773( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
33 m_xMSF = xMSF;
34 m_xStorageFactory = xStorageFactory;
35 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i27773: " );
38 public boolean test()
40 try
42 XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF );
43 if ( xTempFileStream == null )
44 return false;
46 if ( true )
48 // for debugging proposes
50 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xTempFileStream );
51 if ( xPropSet != null )
53 try
55 String sTempURL = AnyConverter.toString( xPropSet.getPropertyValue( "Uri" ) );
56 // m_aTestHelper.Message( "URL: " + sTempURL );
57 xPropSet.setPropertyValue( "RemoveFile", new Boolean( false ) );
59 catch ( Exception e )
65 // create storage based on the temporary stream
66 Object pArgs[] = new Object[2];
67 pArgs[0] = (Object) xTempFileStream;
68 pArgs[1] = new Integer( ElementModes.WRITE );
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 substorage
79 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
80 "SubStorage1",
81 ElementModes.WRITE );
82 if ( xTempSubStorage == null )
84 m_aTestHelper.Error( "Can't create substorage!" );
85 return false;
88 // open an empty substorage
89 XStorage xEmptySubStorage = m_aTestHelper.openSubStorage( xTempStorage,
90 "EmptySubStorage1",
91 ElementModes.WRITE );
92 if ( xEmptySubStorage == null )
94 m_aTestHelper.Error( "Can't create substorage!" );
95 return false;
98 // open an empty substorage
99 XStorage xEmptySubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
100 "EmptySubSubStorage1",
101 ElementModes.WRITE );
102 if ( xEmptySubSubStorage == null )
104 m_aTestHelper.Error( "Can't create substorage!" );
105 return false;
109 byte pBytes1[] = { 1, 1, 1, 1, 1 };
111 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
112 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
113 return false;
115 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
116 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
117 "MediaType2",
118 true,
119 ElementModes.WRITE ) )
120 return false;
122 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
123 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xEmptySubStorage,
124 "MediaType3",
125 false,
126 ElementModes.WRITE ) )
127 return false;
129 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
130 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
131 "MediaType4",
132 false,
133 ElementModes.WRITE ) )
134 return false;
136 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
137 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xEmptySubSubStorage,
138 "MediaType5",
139 false,
140 ElementModes.WRITE ) )
141 return false;
144 // make a copy of substorage
146 if ( !m_aTestHelper.copyElementTo( xTempStorage, "SubStorage1", xTempStorage, "SubStorage1_copy" ) )
147 return false;
149 if ( !m_aTestHelper.copyElementTo( xTempStorage, "EmptySubStorage1", xTempStorage, "EmptySubStorage1_copy" ) )
150 return false;
152 // ================================================
153 // copy all the changed and noncommited substorages
154 // and dispose them
155 // ================================================
157 if ( !m_aTestHelper.commitStorage( xEmptySubSubStorage ) )
158 return false;
160 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
161 return false;
163 if ( !m_aTestHelper.commitStorage( xEmptySubStorage ) )
164 return false;
166 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
167 return false;
169 // dispose substorages
171 if ( !m_aTestHelper.disposeStorage( xEmptySubSubStorage ) )
172 return false;
174 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
175 return false;
177 if ( !m_aTestHelper.disposeStorage( xEmptySubStorage ) )
178 return false;
180 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
181 return false;
183 // ================================================
184 // reopen the storage in readonly mode an check contents
185 // ================================================
187 pArgs[1] = new Integer( ElementModes.READ );
189 oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
190 xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
191 if ( xTempStorage == null )
193 m_aTestHelper.Error( "Can't create temporary storage representation!" );
194 return false;
197 // open original substorage
198 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
199 "SubStorage1",
200 ElementModes.READ );
201 if ( xTempSubStorage == null )
203 m_aTestHelper.Error( "Can't create substorage!" );
204 return false;
207 // open copy of the original substorage
208 XStorage xTempSubStorage_copy = m_aTestHelper.openSubStorage( xTempStorage,
209 "SubStorage1_copy",
210 ElementModes.READ );
211 if ( xTempSubStorage_copy == null )
213 m_aTestHelper.Error( "Can't create substorage!" );
214 return false;
217 // open empty substorage
218 xEmptySubStorage = m_aTestHelper.openSubStorage( xTempStorage,
219 "EmptySubStorage1",
220 ElementModes.READ );
221 if ( xEmptySubStorage == null )
223 m_aTestHelper.Error( "Can't create substorage!" );
224 return false;
227 // open copy of empty substorage
228 XStorage xEmptySubStorage_copy = m_aTestHelper.openSubStorage( xTempStorage,
229 "EmptySubStorage1_copy",
230 ElementModes.READ );
231 if ( xEmptySubStorage_copy == null )
233 m_aTestHelper.Error( "Can't create substorage!" );
234 return false;
237 // open an empty substorage of the substorage
238 xEmptySubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
239 "EmptySubSubStorage1",
240 ElementModes.READ );
241 if ( xEmptySubSubStorage == null )
243 m_aTestHelper.Error( "Can't create substorage!" );
244 return false;
247 // open an empty substorage of the substorage copy
248 XStorage xEmptySubSubStorage_inCopy = m_aTestHelper.openSubStorage( xTempSubStorage_copy,
249 "EmptySubSubStorage1",
250 ElementModes.READ );
251 if ( xEmptySubSubStorage_inCopy == null )
253 m_aTestHelper.Error( "Can't create substorage!" );
254 return false;
258 // check contents
260 if ( !m_aTestHelper.checkStorageProperties( xEmptySubSubStorage, "MediaType5", false, ElementModes.READ ) )
261 return false;
263 if ( !m_aTestHelper.checkStorageProperties( xEmptySubSubStorage_inCopy, "MediaType5", false, ElementModes.READ ) )
264 return false;
266 if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage, "MediaType4", false, ElementModes.READ ) )
267 return false;
269 if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage_copy, "MediaType4", false, ElementModes.READ ) )
270 return false;
272 if ( !m_aTestHelper.checkStorageProperties( xEmptySubStorage, "MediaType3", false, ElementModes.READ ) )
273 return false;
275 if ( !m_aTestHelper.checkStorageProperties( xEmptySubStorage_copy, "MediaType3", false, ElementModes.READ ) )
276 return false;
278 if ( !m_aTestHelper.checkStorageProperties( xTempStorage, "MediaType2", true, ElementModes.READ ) )
279 return false;
281 if ( !m_aTestHelper.checkStream( xTempSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) )
282 return false;
284 if ( !m_aTestHelper.checkStream( xTempSubStorage_copy, "SubStream1", "MediaType1", true, pBytes1 ) )
285 return false;
287 // the root storage is based on the temporary stream so it can be left undisposed, since it does not lock
288 // any resource, later the garbage collector will release the object and it must die by refcount
290 return true;
292 catch( Exception e )
294 m_aTestHelper.Error( "Exception: " + e );
295 return false;