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
)
29 m_xStorageFactory
= xStorageFactory
;
30 m_aTestHelper
= new TestHelper( aLogWriter
, "Test08: " );
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" ) }
47 XStream xTempFileStream
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
48 if ( xTempFileStream
== null )
51 // create storage based on the temporary stream
52 XStorage xTempStorage
= m_aTestHelper
.createStorageFromStream( m_xStorageFactory
,
55 if ( xTempStorage
== null )
57 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
61 // open a new substorage
62 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
65 if ( xTempSubStorage
== null )
67 m_aTestHelper
.Error( "Can't create substorage!" );
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
,
82 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
83 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
89 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
90 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
96 // commit substorage first
97 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
100 // commit the root storage so the contents must be stored now
101 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
104 // dispose substorage
105 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
108 // ================================================
110 // ================================================
112 if ( !checkSubStorages( xTempStorage
, pBytes1
, aRelations1
) )
115 // dispose used storage to free resources
116 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
119 // ================================================
120 // now check all the written information with readwrite access
121 // ================================================
123 XStorage xResWriteStorage
= m_aTestHelper
.createStorageFromStream( m_xStorageFactory
,
125 ElementModes
.WRITE
);
126 if ( xResWriteStorage
== null )
128 m_aTestHelper
.Error( "Can't open storage based on input stream!" );
132 if ( !m_aTestHelper
.checkStorageProperties( xResWriteStorage
,
138 if( !checkSubStorages( xResWriteStorage
, pBytes1
, aRelations1
) )
141 // try to open for writing after opening for reading
142 XStorage xResWSubStorage
= m_aTestHelper
.openSubStorage( xResWriteStorage
,
144 ElementModes
.WRITE
);
145 if ( xResWSubStorage
== null )
147 m_aTestHelper
.Error( "Can't open substorage for writing after it was opened for reading!" );
151 if ( !m_aTestHelper
.checkStorageProperties( xResWSubStorage
,
157 if ( !m_aTestHelper
.checkStream( xResWSubStorage
,
164 // dispose used storage to free resources
165 if ( !m_aTestHelper
.disposeStorage( xResWriteStorage
) )
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
) )
178 XInputStream xTempInStream
= m_aTestHelper
.getInputStream( xTempFileStream
);
179 if ( xTempInStream
== null )
183 // since no mode is provided the result storage must be opened readonly
184 XStorage xResultStorage
= m_aTestHelper
.createStorageFromInputStream( m_xStorageFactory
,
186 if ( xResultStorage
== null )
188 m_aTestHelper
.Error( "Can't open storage based on input stream!" );
192 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
,
198 if( !checkSubStorages( xResultStorage
, pBytes1
, aRelations1
) )
205 m_aTestHelper
.Error( "Exception: " + e
);
210 private boolean checkSubStorages( XStorage xStorage
, byte[] pBytes1
, StringPair
[][] aRelations
)
212 XStorage xReadSubStorage1
= m_aTestHelper
.openSubStorage( xStorage
,
216 XStorage xReadSubStorage2
= m_aTestHelper
.openSubStorage( xStorage
,
220 if ( xReadSubStorage1
== null || xReadSubStorage2
== null )
222 m_aTestHelper
.Error( "Can't open substorage for reading!" );
226 if ( !m_aTestHelper
.checkStorageProperties( xReadSubStorage1
,
232 if ( !m_aTestHelper
.checkStorageProperties( xReadSubStorage2
,
238 if ( !m_aTestHelper
.checkStream( xReadSubStorage1
,
245 if ( !m_aTestHelper
.checkStream( xReadSubStorage2
,
252 if ( !m_aTestHelper
.disposeStorage( xReadSubStorage1
) )
255 if ( !m_aTestHelper
.disposeStorage( xReadSubStorage2
) )