1 package storagetesting
;
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 storagetesting
.TestHelper
;
14 import storagetesting
.StorageTest
;
16 public class Test09
implements StorageTest
{
18 XMultiServiceFactory m_xMSF
;
19 XSingleServiceFactory m_xStorageFactory
;
20 TestHelper m_aTestHelper
;
22 public Test09( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
)
25 m_xStorageFactory
= xStorageFactory
;
26 m_aTestHelper
= new TestHelper( "Test09: " );
34 // create temporary storage based on arbitrary medium
35 // after such a storage is closed it is lost
36 Object oTempStorage
= m_xStorageFactory
.createInstance();
37 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
38 if ( xTempStorage
== null )
40 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
44 byte pPass1
[] = { 1, 2, 3 };
45 byte pPass2
[] = { 3, 2, 1 };
46 byte pBytes
[] = { 1, 1, 1, 1, 1 };
48 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
49 // the stream will not be encrypted
50 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "SubStream1", "MediaType1", false, pBytes
, pPass1
) )
53 // create temporary file
54 String sTempFileURL
= m_aTestHelper
.CreateTempFile( m_xMSF
);
55 if ( sTempFileURL
== null || sTempFileURL
== "" )
57 m_aTestHelper
.Error( "No valid temporary file was created!" );
61 // create temporary storage based on a previously created temporary file
62 Object pArgs
[] = new Object
[2];
63 pArgs
[0] = (Object
) sTempFileURL
;
64 pArgs
[1] = new Integer( ElementModes
.ELEMENT_WRITE
);
66 Object oTempFileStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
67 XStorage xTempFileStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oTempFileStorage
);
68 if ( xTempFileStorage
== null )
70 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
74 // copy xTempStorage to xTempFileStorage
75 // xTempFileStorage will be automatically commited
76 if ( !m_aTestHelper
.copyStorage( xTempStorage
, xTempFileStorage
) )
79 // change password of the substream of new storage based on file
80 int nResult
= m_aTestHelper
.ChangeStreamPass( xTempFileStorage
, "SubStream1", pPass1
, pPass2
);
82 return false; // test failed
83 else if ( nResult
== -1 )
84 return true; // tested optional feature is not supported
86 if ( !m_aTestHelper
.commitStorage( xTempFileStorage
) )
89 // dispose used storages to free resources
90 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) || !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
93 // ================================================
94 // now check all the written and copied information
95 // ================================================
97 // the temporary file must not be locked any more after storage disposing
98 pArgs
[1] = new Integer( ElementModes
.ELEMENT_READ
);
99 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
100 XStorage xResultStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
101 if ( xResultStorage
== null )
103 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
107 if ( !m_aTestHelper
.checkEncrStream( xResultStorage
, "SubStream1", "MediaType1", pBytes
, pPass2
) )
110 // dispose used storages to free resources
111 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
118 m_aTestHelper
.Error( "Exception: " + e
);