Update ooo320-m1
[ooovba.git] / package / qa / ofopxmlstorages / Test08.java
blobab7f9b14bf440d88555e80ae8c41bccee13353f2
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;
11 import com.sun.star.io.XInputStream;
13 import com.sun.star.embed.*;
14 import com.sun.star.beans.StringPair;
16 import share.LogWriter;
17 import complex.ofopxmlstorages.TestHelper;
18 import complex.ofopxmlstorages.StorageTest;
20 public class Test08 implements StorageTest {
22 XMultiServiceFactory m_xMSF;
23 XSingleServiceFactory m_xStorageFactory;
24 TestHelper m_aTestHelper;
26 public Test08( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
28 m_xMSF = xMSF;
29 m_xStorageFactory = xStorageFactory;
30 m_aTestHelper = new TestHelper( aLogWriter, "Test08: " );
33 public boolean test()
35 StringPair[][] aRelations1 =
36 { { new StringPair( "Id", "Num1" ) },
37 { new StringPair( "Target", "TargetURLValue1" ), new StringPair( "Id", "Num6" ) },
38 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
39 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
40 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
41 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
42 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value1" ) }
45 try
47 XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF );
48 if ( xTempFileStream == null )
49 return false;
51 // create storage based on the temporary stream
52 XStorage xTempStorage = m_aTestHelper.createStorageFromStream( m_xStorageFactory,
53 xTempFileStream,
54 ElementModes.WRITE );
55 if ( xTempStorage == null )
57 m_aTestHelper.Error( "Can't create temporary storage representation!" );
58 return false;
61 // open a new substorage
62 XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage,
63 "SubStorage1",
64 ElementModes.WRITE );
65 if ( xTempSubStorage == null )
67 m_aTestHelper.Error( "Can't create substorage!" );
68 return false;
71 byte pBytes1[] = { 1, 1, 1, 1, 1 };
73 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
74 if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage,
75 "SubStream1",
76 "MediaType1",
77 true,
78 pBytes1,
79 aRelations1 ) )
80 return false;
82 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
83 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage,
84 true,
85 ElementModes.WRITE,
86 aRelations1 ) )
87 return false;
89 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
90 if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage,
91 false,
92 ElementModes.WRITE,
93 aRelations1 ) )
94 return false;
96 // commit substorage first
97 if ( !m_aTestHelper.commitStorage( xTempSubStorage ) )
98 return false;
100 // commit the root storage so the contents must be stored now
101 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
102 return false;
104 // dispose substorage
105 if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) )
106 return false;
108 // ================================================
109 // check substorage
110 // ================================================
112 if ( !checkSubStorages( xTempStorage, pBytes1, aRelations1 ) )
113 return false;
115 // dispose used storage to free resources
116 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
117 return false;
119 // ================================================
120 // now check all the written information with readwrite access
121 // ================================================
123 XStorage xResWriteStorage = m_aTestHelper.createStorageFromStream( m_xStorageFactory,
124 xTempFileStream,
125 ElementModes.WRITE );
126 if ( xResWriteStorage == null )
128 m_aTestHelper.Error( "Can't open storage based on input stream!" );
129 return false;
132 if ( !m_aTestHelper.checkStorageProperties( xResWriteStorage,
133 true,
134 ElementModes.WRITE,
135 aRelations1 ) )
136 return false;
138 if( !checkSubStorages( xResWriteStorage, pBytes1, aRelations1 ) )
139 return false;
141 // try to open for writing after opening for reading
142 XStorage xResWSubStorage = m_aTestHelper.openSubStorage( xResWriteStorage,
143 "SubStorage1",
144 ElementModes.WRITE );
145 if ( xResWSubStorage == null )
147 m_aTestHelper.Error( "Can't open substorage for writing after it was opened for reading!" );
148 return false;
151 if ( !m_aTestHelper.checkStorageProperties( xResWSubStorage,
152 false,
153 ElementModes.WRITE,
154 aRelations1 ) )
155 return false;
157 if ( !m_aTestHelper.checkStream( xResWSubStorage,
158 "SubStream1",
159 "MediaType1",
160 pBytes1,
161 aRelations1 ) )
162 return false;
164 // dispose used storage to free resources
165 if ( !m_aTestHelper.disposeStorage( xResWriteStorage ) )
166 return false;
169 // ================================================
170 // now check all the written information with readonly access
171 // ================================================
173 // close the output part of the temporary stream
174 // the output part must present since we already wrote to the stream
175 if ( !m_aTestHelper.closeOutput( xTempFileStream ) )
176 return false;
178 XInputStream xTempInStream = m_aTestHelper.getInputStream( xTempFileStream );
179 if ( xTempInStream == null )
180 return false;
182 // open input stream
183 // since no mode is provided the result storage must be opened readonly
184 XStorage xResultStorage = m_aTestHelper.createStorageFromInputStream( m_xStorageFactory,
185 xTempInStream );
186 if ( xResultStorage == null )
188 m_aTestHelper.Error( "Can't open storage based on input stream!" );
189 return false;
192 if ( !m_aTestHelper.checkStorageProperties( xResultStorage,
193 true,
194 ElementModes.READ,
195 aRelations1 ) )
196 return false;
198 if( !checkSubStorages( xResultStorage, pBytes1, aRelations1 ) )
199 return false;
201 return true;
203 catch( Exception e )
205 m_aTestHelper.Error( "Exception: " + e );
206 return false;
210 private boolean checkSubStorages( XStorage xStorage, byte[] pBytes1, StringPair[][] aRelations )
212 XStorage xReadSubStorage1 = m_aTestHelper.openSubStorage( xStorage,
213 "SubStorage1",
214 ElementModes.READ );
216 XStorage xReadSubStorage2 = m_aTestHelper.openSubStorage( xStorage,
217 "SubStorage1",
218 ElementModes.READ );
220 if ( xReadSubStorage1 == null || xReadSubStorage2 == null )
222 m_aTestHelper.Error( "Can't open substorage for reading!" );
223 return false;
226 if ( !m_aTestHelper.checkStorageProperties( xReadSubStorage1,
227 false,
228 ElementModes.READ,
229 aRelations ) )
230 return false;
232 if ( !m_aTestHelper.checkStorageProperties( xReadSubStorage2,
233 false,
234 ElementModes.READ,
235 aRelations ) )
236 return false;
238 if ( !m_aTestHelper.checkStream( xReadSubStorage1,
239 "SubStream1",
240 "MediaType1",
241 pBytes1,
242 aRelations ) )
243 return false;
245 if ( !m_aTestHelper.checkStream( xReadSubStorage2,
246 "SubStream1",
247 "MediaType1",
248 pBytes1,
249 aRelations ) )
250 return false;
252 if ( !m_aTestHelper.disposeStorage( xReadSubStorage1 ) )
253 return false;
255 if ( !m_aTestHelper.disposeStorage( xReadSubStorage2 ) )
256 return false;
258 return true;