Update ooo320-m1
[ooovba.git] / package / qa / storages / RegressionTest_i59886.java
blobce39e39df10937d868ed10c96df2034a23434c17
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_i59886 implements StorageTest {
21 XMultiServiceFactory m_xMSF;
22 XSingleServiceFactory m_xStorageFactory;
23 TestHelper m_aTestHelper;
25 public RegressionTest_i59886( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
27 m_xMSF = xMSF;
28 m_xStorageFactory = xStorageFactory;
29 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i59886: " );
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 byte pBytes[] = new byte[36000];
54 for ( int nInd = 0; nInd < 36000; nInd++ )
55 pBytes[nInd] = (byte)( nInd % 128 );
57 String sPass = "12345";
59 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
60 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "SubStream1", "MediaType1", true, pBytes, sPass ) )
61 return false;
63 // open a new substorage
64 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
65 "SubStorage1",
66 ElementModes.WRITE );
67 if ( xTempSubStorage == null )
69 m_aTestHelper.Error( "Can't create substorage!" );
70 return false;
73 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
74 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempSubStorage, "SubStream2", "MediaType2", false, pBytes, sPass ) )
75 return false;
77 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
78 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
79 "MediaType3",
80 true,
81 ElementModes.WRITE ) )
82 return false;
84 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
85 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
86 "MediaType4",
87 false,
88 ElementModes.WRITE ) )
89 return false;
91 // commit substorage first
92 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
93 return false;
95 // commit the root storage so the contents must be stored now
96 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
97 return false;
99 // dispose used storage to free resources
100 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
101 return false;
103 // ================================================
104 // now reopen the storage, set the common storage key
105 // and copy the storage
106 // ================================================
108 Object oStep2TempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
109 XStorage xStep2TempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oStep2TempStorage );
110 if ( xStep2TempStorage == null )
112 m_aTestHelper.Error( "Can't create temporary storage representation!" );
113 return false;
117 XStorage xStep2TempSubStorage = m_aTestHelper.openSubStorage( xStep2TempStorage,
118 "SubStorage1",
119 ElementModes.WRITE );
120 if ( xStep2TempSubStorage == null )
122 m_aTestHelper.Error( "Can't create substorage!" );
123 return false;
126 // set the common storage password
127 XEncryptionProtectedSource xEncr = (XEncryptionProtectedSource) UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xStep2TempStorage );
128 if ( xEncr == null )
130 m_aTestHelper.Error( "The storage does not support encryption access!" );
131 return false;
135 xEncr.setEncryptionPassword( sPass );
137 catch( Exception e )
139 m_aTestHelper.Error( "Can not set the common storage password!" );
140 return false;
143 // open the stream for writing and read them so that the cache is created, but do not change
144 byte pDummyData[][] = new byte[1][3];
145 XStream xTempStream1 = m_aTestHelper.OpenStream( xStep2TempStorage, "SubStream1", ElementModes.WRITE );
146 XStream xTempStream2 = m_aTestHelper.OpenStream( xStep2TempSubStorage, "SubStream2", ElementModes.WRITE );
147 if ( xTempStream1 == null || xTempStream2 == null )
148 return false;
150 XInputStream xTempInStream1 = xTempStream1.getInputStream();
151 XInputStream xTempInStream2 = xTempStream2.getInputStream();
152 if ( xTempInStream1 == null || xTempInStream2 == null )
154 m_aTestHelper.Error( "No input stream is available!" );
155 return false;
158 xTempInStream1.readBytes( pDummyData, 3 );
159 xTempInStream2.readBytes( pDummyData, 3 );
162 // create temporary storage, it will be checked later
163 Object oTargetStorage = m_xStorageFactory.createInstance();
164 XStorage xTargetStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTargetStorage );
165 if ( xTargetStorage == null )
167 m_aTestHelper.Error( "Can't create temporary storage representation!" );
168 return false;
171 // copy the current storage to the target
174 xStep2TempStorage.copyToStorage( xTargetStorage );
176 catch( Exception e )
178 m_aTestHelper.Error( "Can not copy the storage with common storage password!" );
179 return false;
182 // dispose used storage to free resources
183 if ( !m_aTestHelper.disposeStorage( xStep2TempStorage ) )
184 return false;
186 // ================================================
187 // now check all the information in the copy
188 // ================================================
190 if ( !m_aTestHelper.checkStorageProperties( xTargetStorage, "MediaType3", true, ElementModes.WRITE ) )
191 return false;
193 // open existing substorage
194 XStorage xTargetSubStorage = m_aTestHelper.openSubStorage( xTargetStorage,
195 "SubStorage1",
196 ElementModes.WRITE );
197 if ( xTargetSubStorage == null )
199 m_aTestHelper.Error( "Can't open existing substorage!" );
200 return false;
203 if ( !m_aTestHelper.checkStorageProperties( xTargetSubStorage, "MediaType4", false, ElementModes.WRITE ) )
204 return false;
206 // set the common storage password
207 XEncryptionProtectedSource xTargetEncr = (XEncryptionProtectedSource) UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xTargetStorage );
208 if ( xTargetEncr == null )
210 m_aTestHelper.Error( "The storage does not support encryption access!" );
211 return false;
215 xTargetEncr.setEncryptionPassword( sPass );
217 catch( Exception e )
219 m_aTestHelper.Error( "Can not set the common storage password!" );
220 return false;
223 // check the streams
224 if ( !m_aTestHelper.checkStream( xTargetStorage, "SubStream1", "MediaType1", true, pBytes ) )
225 return false;
226 if ( !m_aTestHelper.checkStream( xTargetSubStorage, "SubStream2", "MediaType2", true, pBytes ) )
227 return false;
230 // dispose used storages to free resources
231 if ( !m_aTestHelper.disposeStorage( xTargetStorage ) )
232 return false;
234 return true;
236 catch( Exception e )
238 m_aTestHelper.Error( "Exception: " + e );
239 return false;