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
;
10 import com
.sun
.star
.io
.XStream
;
12 import com
.sun
.star
.embed
.*;
14 import share
.LogWriter
;
15 import complex
.storages
.TestHelper
;
16 import complex
.storages
.StorageTest
;
18 public class RegressionTest_i55821
implements StorageTest
{
20 XMultiServiceFactory m_xMSF
;
21 XSingleServiceFactory m_xStorageFactory
;
22 TestHelper m_aTestHelper
;
24 public RegressionTest_i55821( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
27 m_xStorageFactory
= xStorageFactory
;
28 m_aTestHelper
= new TestHelper( aLogWriter
, "RegressionTest_i55821: " );
35 // ================================================
36 // create a temporary stream and a storage based on it
37 // fill the storage with the data that will be used for testing
38 // ================================================
40 XStream xTempFileStream
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
41 if ( xTempFileStream
== null )
44 // create storage based on the temporary stream
45 Object pArgs
[] = new Object
[2];
46 pArgs
[0] = (Object
) xTempFileStream
;
47 pArgs
[1] = new Integer( ElementModes
.WRITE
);
49 Object oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
50 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
51 if ( xTempStorage
== null )
53 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
57 String sPass
= "12345";
58 byte pBytes
[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
60 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
61 // the stream will not be encrypted
62 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "SubStream1", "MediaType1", false, pBytes
, sPass
) )
65 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
68 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "SubStream2", "MediaType2", false, pBytes
, sPass
) )
71 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
74 // dispose used storages to free resources
75 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
78 // ================================================
79 // reopen the target storage readonly, and check contents
80 // ================================================
82 // the temporary file must not be locked any more after storage disposing
83 pArgs
[1] = new Integer( ElementModes
.READ
);
84 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
85 XStorage xResultStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
86 if ( xResultStorage
== null )
88 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
92 if ( !m_aTestHelper
.checkEncrStream( xResultStorage
, "SubStream1", "MediaType1", pBytes
, sPass
) )
95 if ( !m_aTestHelper
.checkEncrStream( xResultStorage
, "SubStream2", "MediaType2", pBytes
, sPass
) )
98 // dispose used storages to free resources
99 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
106 m_aTestHelper
.Error( "Exception: " + e
);