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
;
11 import com
.sun
.star
.io
.XInputStream
;
13 import com
.sun
.star
.embed
.*;
15 import share
.LogWriter
;
16 import complex
.storages
.TestHelper
;
17 import complex
.storages
.StorageTest
;
19 public class RegressionTest_i84234
implements StorageTest
{
21 XMultiServiceFactory m_xMSF
;
22 XSingleServiceFactory m_xStorageFactory
;
23 TestHelper m_aTestHelper
;
25 public RegressionTest_i84234( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
28 m_xStorageFactory
= xStorageFactory
;
29 m_aTestHelper
= new TestHelper( aLogWriter
, "RegressionTest_i84234: " );
36 XStream xTempFileStream
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
37 if ( xTempFileStream
== null )
40 // create storage based on the temporary stream
41 Object pArgs
[] = new Object
[2];
42 pArgs
[0] = (Object
) xTempFileStream
;
43 pArgs
[1] = new Integer( ElementModes
.WRITE
);
45 Object oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
46 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
47 if ( xTempStorage
== null )
49 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
53 // open a new substorage
54 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
57 if ( xTempSubStorage
== null )
59 m_aTestHelper
.Error( "Can't create substorage!" );
63 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
65 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
66 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempStorage
, "SubStream1", "text/xml", false, pBytes1
) )
69 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
70 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream2", "text/xml", false, pBytes1
) )
74 // ================================================
75 // commit the storages and dispose them
76 // ================================================
79 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
83 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
87 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
91 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
94 // ================================================
95 // reopen the storages in readwrite mode and check Compressed flag
96 // ================================================
98 oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
99 xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
100 if ( xTempStorage
== null )
102 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
106 // open a new substorage
107 xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
109 ElementModes
.WRITE
);
110 if ( xTempSubStorage
== null )
112 m_aTestHelper
.Error( "Can't create substorage!" );
116 if ( !m_aTestHelper
.checkStream( xTempStorage
, "SubStream1", "text/xml", false, pBytes1
) )
119 if ( !m_aTestHelper
.checkStream( xTempSubStorage
, "SubStream2", "text/xml", false, pBytes1
) )
122 // the root storage is based on the temporary stream so it can be left undisposed, since it does not lock
123 // any resource, later the garbage collector will release the object and it must die by refcount
129 m_aTestHelper
.Error( "Exception: " + e
);