Update ooo320-m1
[ooovba.git] / package / qa / storages / Test13.java
blob6e8c8a4e9037976e942587e0e2c67ef5b7cc1660
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;
11 import com.sun.star.embed.*;
13 import share.LogWriter;
14 import complex.storages.TestHelper;
15 import complex.storages.StorageTest;
17 public class Test13 implements StorageTest {
19 XMultiServiceFactory m_xMSF;
20 XSingleServiceFactory m_xStorageFactory;
21 TestHelper m_aTestHelper;
23 public Test13( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
25 m_xMSF = xMSF;
26 m_xStorageFactory = xStorageFactory;
27 m_aTestHelper = new TestHelper( aLogWriter, "Test13: " );
30 public boolean test()
32 String aStreamPrefix = "";
33 for ( int nInd = 0; nInd < 4; ++nInd, aStreamPrefix += "SubStorage" + nInd )
34 if ( !testForPath( aStreamPrefix ) )
35 return false;
37 return true;
40 public boolean testForPath( String aStreamPrefix )
42 try
44 String aSubStream1Path = aStreamPrefix + "SubStream1";
45 String aSubStream2Path = aStreamPrefix + "SubStream2";
46 String aSubStream3Path = aStreamPrefix + "SubStream3";
47 String aBigSubStream1Path = aStreamPrefix + "BigSubStream1";
48 String aBigSubStream2Path = aStreamPrefix + "BigSubStream2";
49 String aBigSubStream3Path = aStreamPrefix + "BigSubStream3";
51 String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
52 if ( sTempFileURL == null || sTempFileURL == "" )
54 m_aTestHelper.Error( "No valid temporary file was created!" );
55 return false;
58 // create temporary storage based on a previously created temporary file
59 Object pArgs[] = new Object[2];
60 pArgs[0] = (Object) sTempFileURL;
61 pArgs[1] = new Integer( ElementModes.WRITE );
63 Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
64 XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
65 if ( xTempFileStorage == null )
67 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
68 return false;
71 byte pBigBytes[] = new byte[33000];
72 for ( int nInd = 0; nInd < 33000; nInd++ )
73 pBigBytes[nInd] = (byte)( nInd % 128 );
75 byte pBytes1[] = { 1, 1, 1, 1, 1 };
77 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
78 // and commit
79 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aSubStream1Path, "MediaType1", true, pBytes1, true ) )
80 return false;
81 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aBigSubStream1Path, "MediaType1", true, pBigBytes, true ) )
82 return false;
84 byte pBytes2[] = { 2, 2, 2, 2, 2 };
86 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
87 // and commit
88 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aSubStream2Path, "MediaType2", false, pBytes2, true ) )
89 return false;
90 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aBigSubStream2Path, "MediaType2", false, pBigBytes, true ) )
91 return false;
93 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
94 // and don't commit
95 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aSubStream3Path, "MediaType2", false, pBytes2, false ) )
96 return false;
97 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aBigSubStream3Path, "MediaType2", false, pBigBytes, false ) )
98 return false;
100 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
101 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempFileStorage,
102 "MediaType3",
103 true,
104 ElementModes.WRITE ) )
105 return false;
107 // commit the root storage so the contents must be stored now
108 if ( !m_aTestHelper.commitStorage( xTempFileStorage ) )
109 return false;
111 // dispose used storages to free resources
112 if ( !m_aTestHelper.disposeStorage( xTempFileStorage ) )
113 return false;
115 // ================================================
116 // now reopen the storage,
117 // check all the written and copied information
118 // and change it
119 // ================================================
121 // the temporary file must not be locked any more after storage disposing
122 oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
123 xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
124 if ( xTempFileStorage == null )
126 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
127 return false;
130 if ( !m_aTestHelper.checkStorageProperties( xTempFileStorage, "MediaType3", true, ElementModes.WRITE ) )
131 return false;
133 if ( !m_aTestHelper.checkStreamH( xTempFileStorage, aSubStream1Path, "MediaType1", true, pBytes1 ) )
134 return false;
136 if ( !m_aTestHelper.checkStreamH( xTempFileStorage, aBigSubStream1Path, "MediaType1", true, pBigBytes ) )
137 return false;
139 if ( !m_aTestHelper.checkStreamH( xTempFileStorage, aSubStream2Path, "MediaType2", false, pBytes2 ) )
140 return false;
142 if ( !m_aTestHelper.checkStreamH( xTempFileStorage, aBigSubStream2Path, "MediaType2", false, pBigBytes ) )
143 return false;
145 if ( !m_aTestHelper.cantOpenStreamH( xTempFileStorage, aSubStream3Path, ElementModes.READ ) )
146 return false;
148 if ( !m_aTestHelper.cantOpenStreamH( xTempFileStorage, aBigSubStream3Path, ElementModes.READ ) )
149 return false;
151 // open existing substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
152 // and commit
153 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aSubStream1Path, "MediaType3", true, pBytes2, true ) )
154 return false;
155 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aBigSubStream1Path, "MediaType3", true, pBigBytes, true ) )
156 return false;
159 // open existing substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
160 // and don't commit
161 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aSubStream2Path, "MediaType3", true, pBytes1, false ) )
162 return false;
163 if ( !m_aTestHelper.WriteBytesToStreamH( xTempFileStorage, aBigSubStream2Path, "MediaType3", true, pBigBytes, false ) )
164 return false;
166 // commit the root storage so the contents must be stored now
167 if ( !m_aTestHelper.commitStorage( xTempFileStorage ) )
168 return false;
170 // dispose used storages to free resources
171 if ( !m_aTestHelper.disposeStorage( xTempFileStorage ) )
172 return false;
174 // ================================================
175 // now reopen the storage,
176 // check all the written information
177 // ================================================
179 // the temporary file must not be locked any more after storage disposing
180 pArgs[1] = new Integer( ElementModes.READ );
181 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
182 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
183 if ( xResultStorage == null )
185 m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
186 return false;
189 if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType3", true, ElementModes.READ ) )
190 return false;
192 if ( !m_aTestHelper.checkStreamH( xResultStorage, aSubStream1Path, "MediaType3", true, pBytes2 ) )
193 return false;
194 if ( !m_aTestHelper.checkStreamH( xResultStorage, aBigSubStream1Path, "MediaType3", true, pBigBytes ) )
195 return false;
197 // the following stream was not commited last time, so the last change must be lost
198 if ( !m_aTestHelper.checkStreamH( xResultStorage, aBigSubStream2Path, "MediaType2", false, pBigBytes ) )
199 return false;
201 // dispose used storages to free resources
202 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
203 return false;
205 return true;
207 catch( Exception e )
209 m_aTestHelper.Error( "Exception: " + e );
210 return false;