Update ooo320-m1
[ooovba.git] / package / qa / ofopxmlstorages / Test05.java
blob971c0338b40bfa138f9f075e82d1dbd7193465f6
1 package complex.ofopxmlstorages;
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;
12 import com.sun.star.embed.*;
13 import com.sun.star.beans.StringPair;
15 import share.LogWriter;
16 import complex.ofopxmlstorages.TestHelper;
17 import complex.ofopxmlstorages.StorageTest;
19 public class Test05 implements StorageTest {
21 XMultiServiceFactory m_xMSF;
22 XSingleServiceFactory m_xStorageFactory;
23 TestHelper m_aTestHelper;
25 public Test05( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
27 m_xMSF = xMSF;
28 m_xStorageFactory = xStorageFactory;
29 m_aTestHelper = new TestHelper( aLogWriter, "Test05: " );
32 public boolean test()
34 StringPair[][] aRelations1 =
35 { { new StringPair( "Id", "Num1" ) },
36 { new StringPair( "Target", "TargetURLValue1" ), new StringPair( "Id", "Num6" ) },
37 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
38 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
39 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
40 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
41 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value1" ) }
44 StringPair[][] aRelations2 =
45 { { new StringPair( "Id", "Num1" ) },
46 { new StringPair( "Target", "TargetURLValue2" ), new StringPair( "Id", "Num6" ) },
47 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
48 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
49 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
50 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
51 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }
54 try
56 String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
57 if ( sTempFileURL == null || sTempFileURL == "" )
59 m_aTestHelper.Error( "No valid temporary file was created!" );
60 return false;
63 // create temporary storage based on a previously created temporary file
64 XStorage xTempFileStorage = m_aTestHelper.createStorageFromURL( m_xStorageFactory,
65 sTempFileURL,
66 ElementModes.WRITE );
67 if ( xTempFileStorage == null )
69 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
70 return false;
73 // open a new substorage
74 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempFileStorage,
75 "SubStorage1",
76 ElementModes.WRITE );
77 if ( xTempSubStorage == null )
79 m_aTestHelper.Error( "Can't create substorage!" );
80 return false;
83 // open a new substorage
84 XStorage xSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage,
85 "SubSubStorage1",
86 ElementModes.WRITE );
87 if ( xSubSubStorage == null )
89 m_aTestHelper.Error( "Can't create substorage!" );
90 return false;
94 byte pBytes1[] = { 1, 1, 1, 1, 1 };
96 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
97 if ( !m_aTestHelper.WriteBytesToSubstream( xSubSubStorage,
98 "SubStream1",
99 "MediaType1",
100 true,
101 pBytes1,
102 aRelations1 ) )
103 return false;
105 byte pBytes2[] = { 2, 2, 2, 2, 2 };
107 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
108 if ( !m_aTestHelper.WriteBytesToSubstream( xSubSubStorage,
109 "SubStream2",
110 "MediaType2",
111 false,
112 pBytes2,
113 aRelations2 ) )
114 return false;
116 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
117 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempFileStorage,
118 true,
119 ElementModes.WRITE,
120 aRelations2 ) )
121 return false;
123 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
124 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
125 false,
126 ElementModes.WRITE,
127 aRelations2 ) )
128 return false;
130 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
131 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xSubSubStorage,
132 false,
133 ElementModes.WRITE,
134 aRelations2 ) )
135 return false;
138 // commit all the storages
139 if ( !m_aTestHelper.commitStorage( xSubSubStorage ) )
140 return false;
142 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
143 return false;
145 if ( !m_aTestHelper.commitStorage( xTempFileStorage ) )
146 return false;
148 // try to open an opened substorage, open call must fail
149 if ( !m_aTestHelper.cantOpenStorage( xTempFileStorage, "SubStorage1" ) )
150 return false;
153 // reopen created streams
154 XStream xSubStream1 = m_aTestHelper.OpenStream( xSubSubStorage,
155 "SubStream1",
156 ElementModes.WRITE | ElementModes.NOCREATE );
157 XStream xSubStream2 = m_aTestHelper.OpenStream( xSubSubStorage,
158 "SubStream2",
159 ElementModes.READ | ElementModes.NOCREATE );
160 if ( xSubStream1 == null || xSubStream2 == null )
161 return false;
163 // it should be possible to have more then one copy of stream for reading
164 XStream xSubStream2clone = m_aTestHelper.OpenStream( xSubSubStorage,
165 "SubStream2",
166 ElementModes.READ | ElementModes.NOCREATE );
167 if ( xSubStream2 == null )
168 return false;
171 // so now the first stream can not be open neither for reading nor for writing
172 if ( !m_aTestHelper.cantOpenStream( xSubSubStorage, "SubStream1", ElementModes.WRITE )
173 || !m_aTestHelper.cantOpenStream( xSubSubStorage, "SubStream1", ElementModes.READ ) )
174 return false;
176 // the second stream can not be open for writing
177 if ( !m_aTestHelper.cantOpenStream( xSubSubStorage, "SubStream2", ElementModes.WRITE ) )
178 return false;
181 // dispose xTestSubStorage, all the subtree must be disposed
182 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
183 return false;
185 // check that subtree was disposed correctly
188 xSubSubStorage.isStreamElement( "SubStream1" );
189 m_aTestHelper.Error( "Substorage was not disposed!" );
190 return false;
192 catch ( com.sun.star.lang.DisposedException de )
194 catch ( Exception e )
196 m_aTestHelper.Error( "Wrong exception is thrown by disposed storage: " + e );
197 return false;
202 xSubStream1.getInputStream();
203 m_aTestHelper.Error( "Writeable substream was not disposed!" );
204 return false;
206 catch ( com.sun.star.lang.DisposedException de )
208 catch ( Exception e )
210 m_aTestHelper.Error( "Wrong exception is thrown by disposed stream: " + e );
211 return false;
216 xSubStream2.getInputStream();
217 m_aTestHelper.Error( "Readonly substream was not disposed!" );
218 return false;
220 catch ( com.sun.star.lang.DisposedException de )
222 catch ( Exception e )
224 m_aTestHelper.Error( "Wrong exception is thrown by disposed stream: " + e );
225 return false;
229 // dispose root storage
230 if ( !m_aTestHelper.disposeStorage( xTempFileStorage ) )
231 return false;
234 // ================================================
235 // now check all the written and copied information
236 // ================================================
238 XStorage xResultStorage = m_aTestHelper.createStorageFromURL( m_xStorageFactory,
239 sTempFileURL,
240 ElementModes.READ );
241 if ( xResultStorage == null )
243 m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
244 return false;
247 if ( !m_aTestHelper.checkStorageProperties( xResultStorage,
248 true,
249 ElementModes.READ,
250 aRelations2 ) )
251 return false;
253 // open existing substorage
254 XStorage xResSubStorage = m_aTestHelper.openSubStorage( xResultStorage,
255 "SubStorage1",
256 ElementModes.READ );
257 if ( xResSubStorage == null )
259 m_aTestHelper.Error( "Can't open existing substorage 'SubSubStorage'!" );
260 return false;
263 if ( !m_aTestHelper.checkStorageProperties( xResSubStorage,
264 false,
265 ElementModes.READ,
266 aRelations2 ) )
267 return false;
269 // open existing substorage
270 XStorage xResSubSubStorage = m_aTestHelper.openSubStorage( xResSubStorage,
271 "SubSubStorage1",
272 ElementModes.READ );
273 if ( xResSubSubStorage == null )
275 m_aTestHelper.Error( "Can't open existing substorage 'SubSubStorage'!" );
276 return false;
279 if ( !m_aTestHelper.checkStorageProperties( xResSubSubStorage,
280 false,
281 ElementModes.READ,
282 aRelations2 ) )
283 return false;
285 // check substreams
286 if ( !m_aTestHelper.checkStream( xResSubSubStorage,
287 "SubStream1",
288 "MediaType1",
289 pBytes1,
290 aRelations1 ) )
291 return false;
293 if ( !m_aTestHelper.checkStream( xResSubSubStorage,
294 "SubStream2",
295 "MediaType2",
296 pBytes2,
297 aRelations2 ) )
298 return false;
300 // dispose used storages to free resources
301 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
302 return false;
304 return true;
306 catch( Exception e )
308 m_aTestHelper.Error( "Exception: " + e );
309 return false;