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_i35095
implements StorageTest
{
21 XMultiServiceFactory m_xMSF
;
22 XSingleServiceFactory m_xStorageFactory
;
23 TestHelper m_aTestHelper
;
25 public RegressionTest_i35095( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
28 m_xStorageFactory
= xStorageFactory
;
29 m_aTestHelper
= new TestHelper( aLogWriter
, "RegressionTest_i35095: " );
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 byte pBytes
[] = new byte[36000];
54 for ( int nInd
= 0; nInd
< 36000; nInd
++ )
55 pBytes
[nInd
] = (byte)( nInd
% 128 );
57 String sPass
= "12345";
59 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
60 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "SubStream1", "MediaType1", true, pBytes
, sPass
) )
63 // open a new substorage
64 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
67 if ( xTempSubStorage
== null )
69 m_aTestHelper
.Error( "Can't create substorage!" );
73 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
74 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempSubStorage
, "SubStream2", "MediaType2", false, pBytes
, sPass
) )
77 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
78 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
81 ElementModes
.WRITE
) )
84 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
85 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
88 ElementModes
.WRITE
) )
91 // commit substorage first
92 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
95 // commit the root storage so the contents must be stored now
96 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
99 // dispose used storage to free resources
100 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
103 // ================================================
104 // now check all the written information
105 // and the raw stream contents
106 // ================================================
108 // close the output part of the temporary stream
109 // the output part must present since we already wrote to the stream
110 if ( !m_aTestHelper
.closeOutput( xTempFileStream
) )
113 XInputStream xTempInStream
= m_aTestHelper
.getInputStream( xTempFileStream
);
114 if ( xTempInStream
== null )
118 // since no mode is provided the result storage must be opened readonly
119 Object pOneArg
[] = new Object
[1];
120 pOneArg
[0] = (Object
) xTempInStream
;
122 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pOneArg
);
123 XStorage xResultStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
124 if ( xResultStorage
== null )
126 m_aTestHelper
.Error( "Can't open storage based on input stream!" );
130 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
, "MediaType3", true, ElementModes
.READ
) )
133 // open existing substorage
134 XStorage xResultSubStorage
= m_aTestHelper
.openSubStorage( xResultStorage
,
137 if ( xResultSubStorage
== null )
139 m_aTestHelper
.Error( "Can't open existing substorage!" );
143 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
, "MediaType4", false, ElementModes
.READ
) )
146 if ( !m_aTestHelper
.compareRawMethodsOnEncrStream( xResultStorage
, "SubStream1" ) )
149 if ( !m_aTestHelper
.compareRawMethodsOnEncrStream( xResultSubStorage
, "SubStream2" ) )
152 // dispose used storages to free resources
153 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
160 m_aTestHelper
.Error( "Exception: " + e
);