merge the formfield patch from ooo-build
[ooovba.git] / package / qa / storages / RegressionTest_i30677.java
blob87d28939f3611862ff158812827444101e469749
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_i30677 implements StorageTest {
21 XMultiServiceFactory m_xMSF;
22 XSingleServiceFactory m_xStorageFactory;
23 TestHelper m_aTestHelper;
25 public RegressionTest_i30677( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
27 m_xMSF = xMSF;
28 m_xStorageFactory = xStorageFactory;
29 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i30677: " );
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 // open a new subsubstorage
64 XStorage xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
65 "SubSubStorage1",
66 ElementModes.WRITE );
67 if ( xTempSubSubStorage == null )
69 m_aTestHelper.Error( "Can't create substorage!" );
70 return false;
73 byte pBytes1[] = { 1, 1, 1, 1, 1 };
75 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
76 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubSubStorage, "SubSubStream1", "MediaType1", true, pBytes1 ) )
77 return false;
79 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
80 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
81 "MediaType2",
82 true,
83 ElementModes.WRITE ) )
84 return false;
86 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
87 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
88 "MediaType3",
89 false,
90 ElementModes.WRITE ) )
91 return false;
93 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
94 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubSubStorage,
95 "MediaType4",
96 false,
97 ElementModes.WRITE ) )
98 return false;
100 // ================================================
101 // commit the storages
102 // ================================================
104 // commit lowlevel substorage first
105 if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) )
106 return false;
108 // commit substorage
109 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
110 return false;
112 // commit substorage to let the renaming take place
113 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
114 return false;
116 // ================================================
117 // dispose the storages
118 // ================================================
120 // dispose lowerest substorage
121 if ( !m_aTestHelper.disposeStorage( xTempSubSubStorage ) )
122 return false;
124 // dispose substorage
125 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
126 return false;
128 // dispose the temporary storage
129 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
130 return false;
132 // ================================================
133 // reopen the storage and rewrite the stream
134 // ================================================
136 oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
137 xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
138 if ( xTempStorage == null )
140 m_aTestHelper.Error( "Can't create temporary storage representation!" );
141 return false;
144 // open the substorages
146 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
147 "SubStorage1",
148 ElementModes.WRITE );
149 if ( xTempSubStorage == null )
151 m_aTestHelper.Error( "Can't create substorage!" );
152 return false;
155 // open the lowlevel substorages
157 xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
158 "SubSubStorage1",
159 ElementModes.WRITE );
160 if ( xTempSubSubStorage == null )
162 m_aTestHelper.Error( "Can't create substorage!" );
163 return false;
166 byte pBytes2[] = { 2, 2, 2, 2, 2 };
168 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
169 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubSubStorage, "SubSubStream1", "MediaType1", true, pBytes2 ) )
170 return false;
172 // ================================================
173 // commit the storages
174 // ================================================
176 // commit lowlevel substorage first
177 if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) )
178 return false;
180 // commit substorage
181 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
182 return false;
184 // commit substorage to let the renaming take place
185 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
186 return false;
188 // ================================================
189 // dispose the storages
190 // ================================================
192 // dispose lowerest substorage
193 if ( !m_aTestHelper.disposeStorage( xTempSubSubStorage ) )
194 return false;
196 // dispose substorage
197 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
198 return false;
200 // dispose the temporary storage
201 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
202 return false;
204 // ================================================
205 // reopen the storages and check the contents
206 // ================================================
208 pArgs[1] = new Integer( ElementModes.READ );
209 oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
210 xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
211 if ( xTempStorage == null )
213 m_aTestHelper.Error( "Can't create temporary storage representation!" );
214 return false;
217 // open the substorages
219 xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
220 "SubStorage1",
221 ElementModes.READ );
222 if ( xTempSubStorage == null )
224 m_aTestHelper.Error( "Can't create substorage!" );
225 return false;
228 // open the lowlevel substorages
230 xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
231 "SubSubStorage1",
232 ElementModes.READ );
233 if ( xTempSubSubStorage == null )
235 m_aTestHelper.Error( "Can't create substorage!" );
236 return false;
239 if ( !m_aTestHelper.checkStorageProperties( xTempSubSubStorage, "MediaType4", false, ElementModes.READ ) )
240 return false;
242 if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage, "MediaType3", false, ElementModes.READ ) )
243 return false;
245 if ( !m_aTestHelper.checkStorageProperties( xTempStorage, "MediaType2", true, ElementModes.READ ) )
246 return false;
248 if ( !m_aTestHelper.checkStream( xTempSubSubStorage, "SubSubStream1", "MediaType1", true, pBytes2 ) )
249 return false;
251 // the root storage is based on the temporary stream so it can be left undisposed, since it does not lock
252 // any resource, later the garbage collector will release the object and it must die by refcount
254 return true;
256 catch( Exception e )
258 m_aTestHelper.Error( "Exception: " + e );
259 return false;