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
)
28 m_xStorageFactory
= xStorageFactory
;
29 m_aTestHelper
= new TestHelper( aLogWriter
, "Test05: " );
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" ) }
56 String sTempFileURL
= m_aTestHelper
.CreateTempFile( m_xMSF
);
57 if ( sTempFileURL
== null || sTempFileURL
== "" )
59 m_aTestHelper
.Error( "No valid temporary file was created!" );
63 // create temporary storage based on a previously created temporary file
64 XStorage xTempFileStorage
= m_aTestHelper
.createStorageFromURL( m_xStorageFactory
,
67 if ( xTempFileStorage
== null )
69 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
73 // open a new substorage
74 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempFileStorage
,
77 if ( xTempSubStorage
== null )
79 m_aTestHelper
.Error( "Can't create substorage!" );
83 // open a new substorage
84 XStorage xSubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
87 if ( xSubSubStorage
== null )
89 m_aTestHelper
.Error( "Can't create substorage!" );
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
,
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
,
116 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
117 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempFileStorage
,
123 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
124 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
130 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
131 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xSubSubStorage
,
138 // commit all the storages
139 if ( !m_aTestHelper
.commitStorage( xSubSubStorage
) )
142 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
145 if ( !m_aTestHelper
.commitStorage( xTempFileStorage
) )
148 // try to open an opened substorage, open call must fail
149 if ( !m_aTestHelper
.cantOpenStorage( xTempFileStorage
, "SubStorage1" ) )
153 // reopen created streams
154 XStream xSubStream1
= m_aTestHelper
.OpenStream( xSubSubStorage
,
156 ElementModes
.WRITE
| ElementModes
.NOCREATE
);
157 XStream xSubStream2
= m_aTestHelper
.OpenStream( xSubSubStorage
,
159 ElementModes
.READ
| ElementModes
.NOCREATE
);
160 if ( xSubStream1
== null || xSubStream2
== null )
163 // it should be possible to have more then one copy of stream for reading
164 XStream xSubStream2clone
= m_aTestHelper
.OpenStream( xSubSubStorage
,
166 ElementModes
.READ
| ElementModes
.NOCREATE
);
167 if ( xSubStream2
== null )
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
) )
176 // the second stream can not be open for writing
177 if ( !m_aTestHelper
.cantOpenStream( xSubSubStorage
, "SubStream2", ElementModes
.WRITE
) )
181 // dispose xTestSubStorage, all the subtree must be disposed
182 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
185 // check that subtree was disposed correctly
188 xSubSubStorage
.isStreamElement( "SubStream1" );
189 m_aTestHelper
.Error( "Substorage was not disposed!" );
192 catch ( com
.sun
.star
.lang
.DisposedException de
)
194 catch ( Exception e
)
196 m_aTestHelper
.Error( "Wrong exception is thrown by disposed storage: " + e
);
202 xSubStream1
.getInputStream();
203 m_aTestHelper
.Error( "Writeable substream was not disposed!" );
206 catch ( com
.sun
.star
.lang
.DisposedException de
)
208 catch ( Exception e
)
210 m_aTestHelper
.Error( "Wrong exception is thrown by disposed stream: " + e
);
216 xSubStream2
.getInputStream();
217 m_aTestHelper
.Error( "Readonly substream was not disposed!" );
220 catch ( com
.sun
.star
.lang
.DisposedException de
)
222 catch ( Exception e
)
224 m_aTestHelper
.Error( "Wrong exception is thrown by disposed stream: " + e
);
229 // dispose root storage
230 if ( !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
234 // ================================================
235 // now check all the written and copied information
236 // ================================================
238 XStorage xResultStorage
= m_aTestHelper
.createStorageFromURL( m_xStorageFactory
,
241 if ( xResultStorage
== null )
243 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
247 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
,
253 // open existing substorage
254 XStorage xResSubStorage
= m_aTestHelper
.openSubStorage( xResultStorage
,
257 if ( xResSubStorage
== null )
259 m_aTestHelper
.Error( "Can't open existing substorage 'SubSubStorage'!" );
263 if ( !m_aTestHelper
.checkStorageProperties( xResSubStorage
,
269 // open existing substorage
270 XStorage xResSubSubStorage
= m_aTestHelper
.openSubStorage( xResSubStorage
,
273 if ( xResSubSubStorage
== null )
275 m_aTestHelper
.Error( "Can't open existing substorage 'SubSubStorage'!" );
279 if ( !m_aTestHelper
.checkStorageProperties( xResSubSubStorage
,
286 if ( !m_aTestHelper
.checkStream( xResSubSubStorage
,
293 if ( !m_aTestHelper
.checkStream( xResSubSubStorage
,
300 // dispose used storages to free resources
301 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
308 m_aTestHelper
.Error( "Exception: " + e
);