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_i49755
implements StorageTest
{
21 XMultiServiceFactory m_xMSF
;
22 XSingleServiceFactory m_xStorageFactory
;
23 TestHelper m_aTestHelper
;
25 public RegressionTest_i49755( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
28 m_xStorageFactory
= xStorageFactory
;
29 m_aTestHelper
= new TestHelper( aLogWriter
, "RegressionTest_i49755: " );
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 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
54 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
57 ElementModes
.WRITE
) )
61 byte pBytes
[] = new byte[36000];
62 for ( int nInd
= 0; nInd
< 36000; nInd
++ )
63 pBytes
[nInd
] = (byte)( nInd
% 128 );
65 // open a new substorage
66 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
69 if ( xTempSubStorage
== null )
71 m_aTestHelper
.Error( "Can't create substorage!" );
75 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
76 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
79 ElementModes
.WRITE
) )
82 // open a new substorage
83 XStorage xTempSubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
86 if ( xTempSubStorage
== null )
88 m_aTestHelper
.Error( "Can't create substorage!" );
92 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
93 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubSubStorage
,
96 ElementModes
.WRITE
) )
99 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
100 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubSubStorage
, "SubStream1", "MediaType4", true, pBytes
) )
103 // open a new substorage
104 XStorage xTempSubStorage1
= m_aTestHelper
.openSubStorage( xTempStorage
,
106 ElementModes
.WRITE
);
107 if ( xTempSubStorage1
== null )
109 m_aTestHelper
.Error( "Can't create substorage!" );
113 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
114 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage1
,
117 ElementModes
.WRITE
) )
120 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
121 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage1
, "SubStream2", "MediaType4", false, pBytes
) )
125 // commit substorages first
126 if ( !m_aTestHelper
.commitStorage( xTempSubSubStorage
) )
129 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
132 if ( !m_aTestHelper
.commitStorage( xTempSubStorage1
) )
135 // commit the root storage so the contents must be stored now
136 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
139 // dispose used storage to free resources
140 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
143 // ================================================
144 // now change the contents of the second substorage
145 // without changing of the contents of the first substorage
146 // ================================================
148 Object oStep2TempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
149 XStorage xStep2TempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oStep2TempStorage
);
150 if ( xStep2TempStorage
== null )
152 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
156 XStorage xStep2TempSubStorage1
= m_aTestHelper
.openSubStorage( xStep2TempStorage
,
158 ElementModes
.WRITE
);
159 if ( xStep2TempSubStorage1
== null )
161 m_aTestHelper
.Error( "Can't create substorage!" );
165 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
166 if ( !m_aTestHelper
.WriteBytesToSubstream( xStep2TempSubStorage1
, "SubStream2", "MediaType4", false, pBytes
) )
169 if ( !m_aTestHelper
.commitStorage( xStep2TempSubStorage1
) )
172 // commit the root storage so the contents must be stored now
173 if ( !m_aTestHelper
.commitStorage( xStep2TempStorage
) )
176 // dispose used storage to free resources
177 if ( !m_aTestHelper
.disposeStorage( xStep2TempStorage
) )
181 // ================================================
182 // now check all the written information
183 // and the raw stream contents
184 // ================================================
186 // close the output part of the temporary stream
187 // the output part must present since we already wrote to the stream
188 if ( !m_aTestHelper
.closeOutput( xTempFileStream
) )
191 XInputStream xTempInStream
= m_aTestHelper
.getInputStream( xTempFileStream
);
192 if ( xTempInStream
== null )
196 // since no mode is provided the result storage must be opened readonly
197 Object pOneArg
[] = new Object
[1];
198 pOneArg
[0] = (Object
) xTempInStream
;
200 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pOneArg
);
201 XStorage xResultStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
202 if ( xResultStorage
== null )
204 m_aTestHelper
.Error( "Can't open storage based on input stream!" );
208 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
, "MediaType1", true, ElementModes
.READ
) )
211 // open existing substorage
212 XStorage xResultSubStorage
= m_aTestHelper
.openSubStorage( xResultStorage
,
215 if ( xResultSubStorage
== null )
217 m_aTestHelper
.Error( "Can't open existing substorage!" );
221 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage
, "MediaType2", false, ElementModes
.READ
) )
224 // open existing substorage
225 XStorage xResultSubSubStorage
= m_aTestHelper
.openSubStorage( xResultSubStorage
,
228 if ( xResultSubSubStorage
== null )
230 m_aTestHelper
.Error( "Can't open existing substorage!" );
234 if ( !m_aTestHelper
.checkStorageProperties( xResultSubSubStorage
, "MediaType3", false, ElementModes
.READ
) )
237 if ( !m_aTestHelper
.checkStream( xResultSubSubStorage
, "SubStream1", "MediaType4", true, pBytes
) )
242 XStorage xResultSubStorage1
= m_aTestHelper
.openSubStorage( xResultStorage
,
245 if ( xResultSubStorage1
== null )
247 m_aTestHelper
.Error( "Can't open existing substorage!" );
251 if ( !m_aTestHelper
.checkStorageProperties( xResultSubStorage1
, "MediaType5", false, ElementModes
.READ
) )
254 if ( !m_aTestHelper
.checkStream( xResultSubStorage1
, "SubStream2", "MediaType4", false, pBytes
) )
258 // dispose used storages to free resources
259 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
266 m_aTestHelper
.Error( "Exception: " + e
);