1 package complex
.storages
;
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
;
11 import com
.sun
.star
.embed
.*;
13 import share
.LogWriter
;
14 import complex
.storages
.TestHelper
;
15 import complex
.storages
.StorageTest
;
17 public class Test09
implements StorageTest
{
19 XMultiServiceFactory m_xMSF
;
20 XSingleServiceFactory m_xStorageFactory
;
21 TestHelper m_aTestHelper
;
23 public Test09( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
26 m_xStorageFactory
= xStorageFactory
;
27 m_aTestHelper
= new TestHelper( aLogWriter
, "Test09: " );
35 // create temporary storage based on arbitrary medium
36 // after such a storage is closed it is lost
37 Object oTempStorage
= m_xStorageFactory
.createInstance();
38 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
39 if ( xTempStorage
== null )
41 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
45 String sPass1
= "123";
46 String sPass2
= "321";
47 byte pBytes
[] = { 1, 1, 1, 1, 1 };
49 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
50 // the stream will not be encrypted
51 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "SubStream1", "MediaType1", false, pBytes
, sPass1
) )
54 // create temporary file
55 String sTempFileURL
= m_aTestHelper
.CreateTempFile( m_xMSF
);
56 if ( sTempFileURL
== null || sTempFileURL
== "" )
58 m_aTestHelper
.Error( "No valid temporary file was created!" );
62 // create temporary storage based on a previously created temporary file
63 Object pArgs
[] = new Object
[2];
64 pArgs
[0] = (Object
) sTempFileURL
;
65 pArgs
[1] = new Integer( ElementModes
.WRITE
);
67 Object oTempFileStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
68 XStorage xTempFileStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oTempFileStorage
);
69 if ( xTempFileStorage
== null )
71 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
75 // copy xTempStorage to xTempFileStorage
76 // xTempFileStorage will be automatically commited
77 if ( !m_aTestHelper
.copyStorage( xTempStorage
, xTempFileStorage
) )
80 // change password of the substream of new storage based on file
81 int nResult
= m_aTestHelper
.ChangeStreamPass( xTempFileStorage
, "SubStream1", sPass1
, sPass2
);
83 return false; // test failed
84 else if ( nResult
== -1 )
85 return true; // tested optional feature is not supported
87 if ( !m_aTestHelper
.commitStorage( xTempFileStorage
) )
90 // dispose used storages to free resources
91 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) || !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
94 // ================================================
95 // now check all the written and copied information
96 // ================================================
98 // the temporary file must not be locked any more after storage disposing
99 pArgs
[1] = new Integer( ElementModes
.READ
);
100 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
101 XStorage xResultStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
102 if ( xResultStorage
== null )
104 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
108 if ( !m_aTestHelper
.checkEncrStream( xResultStorage
, "SubStream1", "MediaType1", pBytes
, sPass2
) )
111 // dispose used storages to free resources
112 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
119 m_aTestHelper
.Error( "Exception: " + e
);