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 Test07
implements StorageTest
{
18 XMultiServiceFactory m_xMSF
;
19 XSingleServiceFactory m_xStorageFactory
;
20 TestHelper m_aTestHelper
;
22 public Test07( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
)
25 m_xStorageFactory
= xStorageFactory
;
26 m_aTestHelper
= new TestHelper( "Test07: " );
33 String sTempFileURL
= m_aTestHelper
.CreateTempFile( m_xMSF
);
34 if ( sTempFileURL
== null || sTempFileURL
== "" )
36 m_aTestHelper
.Error( "No valid temporary file was created!" );
40 // create temporary storage based on arbitrary medium
41 // after such a storage is closed it is lost
42 Object oTempStorage
= m_xStorageFactory
.createInstance();
43 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
44 if ( xTempStorage
== null )
46 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
50 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
51 byte pPass1
[] = { 1, 2, 3, 4, 5 };
53 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
54 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "SubStream1", "MediaType1", true, pBytes1
, pPass1
) )
57 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
58 byte pPass2
[] = { 5, 4, 3, 2, 1 };
60 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
61 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "SubStream2", "MediaType2", false, pBytes2
, pPass2
) )
64 // create temporary storage based on a previously created temporary file
65 Object pArgs
[] = new Object
[2];
66 pArgs
[0] = (Object
) sTempFileURL
;
67 pArgs
[1] = new Integer( ElementModes
.ELEMENT_WRITE
);
69 Object oTempFileStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
70 XStorage xTempFileStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oTempFileStorage
);
71 if ( xTempFileStorage
== null )
73 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
77 // copy xTempStorage to xTempFileStorage
78 // xTempFileStorage will be automatically commited
79 if ( !m_aTestHelper
.copyStorage( xTempStorage
, xTempFileStorage
) )
82 // dispose used storages to free resources
83 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) || !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
86 // ================================================
87 // now check all the written and copied information
88 // ================================================
90 // the temporary file must not be locked any more after storage disposing
91 pArgs
[1] = new Integer( ElementModes
.ELEMENT_READWRITE
);
92 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
93 XStorage xResultStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
94 if ( xResultStorage
== null )
96 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
100 Object o2CopyStorage
= m_xStorageFactory
.createInstance();
101 XStorage x2CopyStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, o2CopyStorage
);
102 if ( x2CopyStorage
== null )
104 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
108 if ( !m_aTestHelper
.copyStorage( xResultStorage
, x2CopyStorage
) )
111 if ( !m_aTestHelper
.checkEncrStream( xResultStorage
, "SubStream1", "MediaType1", pBytes1
, pPass1
) )
114 if ( !m_aTestHelper
.checkEncrStream( xResultStorage
, "SubStream2", "MediaType2", pBytes2
, pPass2
) )
117 if ( !m_aTestHelper
.checkEncrStream( x2CopyStorage
, "SubStream1", "MediaType1", pBytes1
, pPass1
) )
120 if ( !m_aTestHelper
.checkEncrStream( x2CopyStorage
, "SubStream2", "MediaType2", pBytes2
, pPass2
) )
123 // dispose used storages to free resources
124 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
131 m_aTestHelper
.Error( "Exception: " + e
);