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
;
6 import com
.sun
.star
.lang
.DisposedException
;
8 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
9 import com
.sun
.star
.uno
.UnoRuntime
;
10 import com
.sun
.star
.uno
.XInterface
;
12 import com
.sun
.star
.container
.XNameAccess
;
14 import com
.sun
.star
.embed
.*;
15 import com
.sun
.star
.beans
.StringPair
;
17 import share
.LogWriter
;
18 import complex
.ofopxmlstorages
.TestHelper
;
19 import complex
.ofopxmlstorages
.StorageTest
;
21 public class Test04
implements StorageTest
{
23 XMultiServiceFactory m_xMSF
;
24 XSingleServiceFactory m_xStorageFactory
;
25 TestHelper m_aTestHelper
;
27 public Test04( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
30 m_xStorageFactory
= xStorageFactory
;
31 m_aTestHelper
= new TestHelper( aLogWriter
, "Test04: " );
36 StringPair
[][] aRelations1
=
37 { { new StringPair( "Id", "Num1" ) },
38 { new StringPair( "Target", "TargetURLValue1" ), new StringPair( "Id", "Num6" ) },
39 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
40 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
41 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
42 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) },
43 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value1" ) }
46 StringPair
[][] aRelations2
=
47 { { new StringPair( "Id", "Num1" ) },
48 { new StringPair( "Target", "TargetURLValue2" ), new StringPair( "Id", "Num6" ) },
49 { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) },
50 { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
51 { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) },
52 { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) },
53 { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }
58 String sTempFileURL
= m_aTestHelper
.CreateTempFile( m_xMSF
);
59 if ( sTempFileURL
== null || sTempFileURL
== "" )
61 m_aTestHelper
.Error( "No valid temporary file was created!" );
65 // create temporary storage based on arbitrary medium
66 // after such a storage is closed it is lost
67 XStorage xTempStorage
= m_aTestHelper
.createTempStorage( m_xMSF
, m_xStorageFactory
);
68 if ( xTempStorage
== null )
70 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
74 // open substorages and create streams there
76 // first substorage of the root storage
77 XStorage xTempSubStorage1
= m_aTestHelper
.openSubStorage( xTempStorage
,
80 if ( xTempSubStorage1
== null )
82 m_aTestHelper
.Error( "Can't create substorage!" );
86 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
88 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
89 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage1
,
97 // second substorage of the root storage
98 XStorage xTempSubStorage2
= m_aTestHelper
.openSubStorage( xTempStorage
,
100 ElementModes
.WRITE
);
101 if ( xTempSubStorage2
== null )
103 m_aTestHelper
.Error( "Can't create substorage!" );
107 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
109 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
110 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage2
,
118 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
119 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
125 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
126 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage1
,
132 // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly
133 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage2
,
139 // create temporary storage based on a previously created temporary file
140 XStorage xTempFileStorage
= m_aTestHelper
.createStorageFromURL( m_xStorageFactory
,
142 ElementModes
.WRITE
);
143 if ( xTempFileStorage
== null )
145 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
149 if ( !m_aTestHelper
.copyElementTo( xTempStorage
, "SubStorage1", xTempFileStorage
) )
152 // if storage is not commited before disposing all the changes will be lost
153 if ( !m_aTestHelper
.commitStorage( xTempSubStorage2
) )
156 // a storage must be disposed before moving/removing otherwise the access will be denied
157 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage2
) )
160 if ( !m_aTestHelper
.moveElementTo( xTempStorage
, "SubStorage2", xTempFileStorage
) )
163 // SubStorage2 must be removed and disposed now
166 xTempSubStorage2
.isStreamElement( "SubStream2" );
167 m_aTestHelper
.Error( "SubStorage2 must be disposed already!" );
170 catch( com
.sun
.star
.lang
.DisposedException de
)
175 m_aTestHelper
.Error( "Wrong exception in case of disposed storage, exception: " + e
);
179 if ( !m_aTestHelper
.copyElementTo( xTempSubStorage1
, "SubStream1", xTempFileStorage
) )
182 if ( !m_aTestHelper
.renameElement( xTempFileStorage
, "SubStream1", "SubStream1_copy" ) )
185 if ( !m_aTestHelper
.moveElementTo( xTempSubStorage1
, "SubStream1", xTempFileStorage
) )
188 if ( !m_aTestHelper
.commitStorage( xTempFileStorage
) )
191 // dispose used storages to free resources
192 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) || !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
195 // ================================================
196 // now check all the written and copied information
197 // ================================================
199 // the temporary file must not be locked any more after storage disposing
200 XStorage xResStorage
= m_aTestHelper
.createStorageFromURL( m_xStorageFactory
,
202 ElementModes
.WRITE
);
204 if ( xResStorage
== null )
206 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
210 // open and check SubStorage1
211 XStorage xResSubStorage1
= m_aTestHelper
.openSubStorage( xResStorage
,
214 if ( xResSubStorage1
== null )
216 m_aTestHelper
.Error( "Can't open existing substorage!" );
220 if ( !m_aTestHelper
.checkStorageProperties( xResSubStorage1
,
227 // open and check SubStorage2
228 XStorage xResSubStorage2
= m_aTestHelper
.openSubStorage( xResStorage
,
231 if ( xResSubStorage2
== null )
233 m_aTestHelper
.Error( "Can't open existing substorage!" );
237 if ( !m_aTestHelper
.checkStorageProperties( xResSubStorage2
,
244 // check all the result streams
246 if ( !m_aTestHelper
.checkStream( xResStorage
, "SubStream1", "MediaType1", pBytes1
, aRelations1
) )
249 if ( !m_aTestHelper
.checkStream( xResStorage
, "SubStream1_copy", "MediaType1", pBytes1
, aRelations1
) )
252 if ( !m_aTestHelper
.checkStream( xResSubStorage1
, "SubStream1", "MediaType1", pBytes1
, aRelations1
) )
255 if ( !m_aTestHelper
.checkStream( xResSubStorage2
, "SubStream2", "MediaType2", pBytes2
, aRelations2
) )
258 // the storage must be disposed before removing
259 if ( !m_aTestHelper
.disposeStorage( xResSubStorage2
) )
262 // remove element and check that it was removed completelly
263 if ( !m_aTestHelper
.removeElement( xResStorage
, "SubStorage2" ) )
268 XNameAccess xResAccess
= (XNameAccess
) UnoRuntime
.queryInterface( XNameAccess
.class, xResStorage
);
269 if ( xResAccess
.hasByName( "SubStorage2" ) )
270 m_aTestHelper
.Error( "SubStorage2 must be removed already!" );
274 m_aTestHelper
.Error( "Can't get access to root storage, exception: " + e
);
280 xResSubStorage2
.isStreamElement( "SubStream2" );
282 m_aTestHelper
.Error( "SubStorage2 must be disposed already!" );
285 catch( com
.sun
.star
.lang
.DisposedException de
)
290 m_aTestHelper
.Error( "Wrong exception in case of disposed storage, exception: " + e
);
294 // dispose used storages to free resources
295 if ( !m_aTestHelper
.disposeStorage( xResStorage
) )
302 m_aTestHelper
.Error( "Exception: " + e
);