Update ooo320-m1
[ooovba.git] / package / qa / storages / RegressionTest_i49755.java
blobc1b597828d0d12fc17ba5ba4eb114426000d0823
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_i49755 implements StorageTest {
21 XMultiServiceFactory m_xMSF;
22 XSingleServiceFactory m_xStorageFactory;
23 TestHelper m_aTestHelper;
25 public RegressionTest_i49755( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
27 m_xMSF = xMSF;
28 m_xStorageFactory = xStorageFactory;
29 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i49755: " );
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 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
54 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
55 "MediaType1",
56 true,
57 ElementModes.WRITE ) )
58 return false;
61 byte pBytes[] = new byte[36000];
62 for ( int nInd = 0; nInd < 36000; nInd++ )
63 pBytes[nInd] = (byte)( nInd % 128 );
65 // open a new substorage
66 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
67 "SubStorage1",
68 ElementModes.WRITE );
69 if ( xTempSubStorage == null )
71 m_aTestHelper.Error( "Can't create substorage!" );
72 return false;
75 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
76 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
77 "MediaType2",
78 false,
79 ElementModes.WRITE ) )
80 return false;
82 // open a new substorage
83 XStorage xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
84 "SubStorage2",
85 ElementModes.WRITE );
86 if ( xTempSubStorage == null )
88 m_aTestHelper.Error( "Can't create substorage!" );
89 return false;
92 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
93 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubSubStorage,
94 "MediaType3",
95 false,
96 ElementModes.WRITE ) )
97 return false;
99 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
100 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubSubStorage, "SubStream1", "MediaType4", true, pBytes ) )
101 return false;
103 // open a new substorage
104 XStorage xTempSubStorage1 = m_aTestHelper.openSubStorage( xTempStorage,
105 "SubStorage3",
106 ElementModes.WRITE );
107 if ( xTempSubStorage1 == null )
109 m_aTestHelper.Error( "Can't create substorage!" );
110 return false;
113 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
114 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage1,
115 "MediaType5",
116 false,
117 ElementModes.WRITE ) )
118 return false;
120 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
121 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage1, "SubStream2", "MediaType4", false, pBytes ) )
122 return false;
125 // commit substorages first
126 if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) )
127 return false;
129 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
130 return false;
132 if ( !m_aTestHelper.commitStorage( xTempSubStorage1 ) )
133 return false;
135 // commit the root storage so the contents must be stored now
136 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
137 return false;
139 // dispose used storage to free resources
140 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
141 return false;
143 // ================================================
144 // now change the contents of the second substorage
145 // without changing of the contents of the first substorage
146 // ================================================
148 Object oStep2TempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
149 XStorage xStep2TempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oStep2TempStorage );
150 if ( xStep2TempStorage == null )
152 m_aTestHelper.Error( "Can't create temporary storage representation!" );
153 return false;
156 XStorage xStep2TempSubStorage1 = m_aTestHelper.openSubStorage( xStep2TempStorage,
157 "SubStorage3",
158 ElementModes.WRITE );
159 if ( xStep2TempSubStorage1 == null )
161 m_aTestHelper.Error( "Can't create substorage!" );
162 return false;
165 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
166 if ( !m_aTestHelper.WriteBytesToSubstream( xStep2TempSubStorage1, "SubStream2", "MediaType4", false, pBytes ) )
167 return false;
169 if ( !m_aTestHelper.commitStorage( xStep2TempSubStorage1 ) )
170 return false;
172 // commit the root storage so the contents must be stored now
173 if ( !m_aTestHelper.commitStorage( xStep2TempStorage ) )
174 return false;
176 // dispose used storage to free resources
177 if ( !m_aTestHelper.disposeStorage( xStep2TempStorage ) )
178 return false;
181 // ================================================
182 // now check all the written information
183 // and the raw stream contents
184 // ================================================
186 // close the output part of the temporary stream
187 // the output part must present since we already wrote to the stream
188 if ( !m_aTestHelper.closeOutput( xTempFileStream ) )
189 return false;
191 XInputStream xTempInStream = m_aTestHelper.getInputStream( xTempFileStream );
192 if ( xTempInStream == null )
193 return false;
195 // open input stream
196 // since no mode is provided the result storage must be opened readonly
197 Object pOneArg[] = new Object[1];
198 pOneArg[0] = (Object) xTempInStream;
200 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pOneArg );
201 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
202 if ( xResultStorage == null )
204 m_aTestHelper.Error( "Can't open storage based on input stream!" );
205 return false;
208 if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType1", true, ElementModes.READ ) )
209 return false;
211 // open existing substorage
212 XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
213 "SubStorage1",
214 ElementModes.READ );
215 if ( xResultSubStorage == null )
217 m_aTestHelper.Error( "Can't open existing substorage!" );
218 return false;
221 if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType2", false, ElementModes.READ ) )
222 return false;
224 // open existing substorage
225 XStorage xResultSubSubStorage = m_aTestHelper.openSubStorage( xResultSubStorage,
226 "SubStorage2",
227 ElementModes.READ );
228 if ( xResultSubSubStorage == null )
230 m_aTestHelper.Error( "Can't open existing substorage!" );
231 return false;
234 if ( !m_aTestHelper.checkStorageProperties( xResultSubSubStorage, "MediaType3", false, ElementModes.READ ) )
235 return false;
237 if ( !m_aTestHelper.checkStream( xResultSubSubStorage, "SubStream1", "MediaType4", true, pBytes ) )
238 return false;
242 XStorage xResultSubStorage1 = m_aTestHelper.openSubStorage( xResultStorage,
243 "SubStorage3",
244 ElementModes.READ );
245 if ( xResultSubStorage1 == null )
247 m_aTestHelper.Error( "Can't open existing substorage!" );
248 return false;
251 if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage1, "MediaType5", false, ElementModes.READ ) )
252 return false;
254 if ( !m_aTestHelper.checkStream( xResultSubStorage1, "SubStream2", "MediaType4", false, pBytes ) )
255 return false;
258 // dispose used storages to free resources
259 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
260 return false;
262 return true;
264 catch( Exception e )
266 m_aTestHelper.Error( "Exception: " + e );
267 return false;