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
;
12 import com
.sun
.star
.beans
.XPropertySet
;
13 import com
.sun
.star
.uno
.AnyConverter
;
15 import com
.sun
.star
.embed
.*;
17 import share
.LogWriter
;
18 import complex
.storages
.TestHelper
;
19 import complex
.storages
.StorageTest
;
21 ///////////////////////////////////
22 // Tests also fix for i51352
23 ///////////////////////////////////
25 public class RegressionTest_i27773
implements StorageTest
{
27 XMultiServiceFactory m_xMSF
;
28 XSingleServiceFactory m_xStorageFactory
;
29 TestHelper m_aTestHelper
;
31 public RegressionTest_i27773( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
34 m_xStorageFactory
= xStorageFactory
;
35 m_aTestHelper
= new TestHelper( aLogWriter
, "RegressionTest_i27773: " );
42 XStream xTempFileStream
= m_aTestHelper
.CreateTempFileStream( m_xMSF
);
43 if ( xTempFileStream
== null )
48 // for debugging proposes
50 XPropertySet xPropSet
= (XPropertySet
) UnoRuntime
.queryInterface( XPropertySet
.class, xTempFileStream
);
51 if ( xPropSet
!= null )
55 String sTempURL
= AnyConverter
.toString( xPropSet
.getPropertyValue( "Uri" ) );
56 // m_aTestHelper.Message( "URL: " + sTempURL );
57 xPropSet
.setPropertyValue( "RemoveFile", new Boolean( false ) );
65 // create storage based on the temporary stream
66 Object pArgs
[] = new Object
[2];
67 pArgs
[0] = (Object
) xTempFileStream
;
68 pArgs
[1] = new Integer( ElementModes
.WRITE
);
70 Object oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
71 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
72 if ( xTempStorage
== null )
74 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
78 // open a new substorage
79 XStorage xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
82 if ( xTempSubStorage
== null )
84 m_aTestHelper
.Error( "Can't create substorage!" );
88 // open an empty substorage
89 XStorage xEmptySubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
92 if ( xEmptySubStorage
== null )
94 m_aTestHelper
.Error( "Can't create substorage!" );
98 // open an empty substorage
99 XStorage xEmptySubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
100 "EmptySubSubStorage1",
101 ElementModes
.WRITE
);
102 if ( xEmptySubSubStorage
== null )
104 m_aTestHelper
.Error( "Can't create substorage!" );
109 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
111 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
112 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubStorage
, "SubStream1", "MediaType1", true, pBytes1
) )
115 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
116 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
119 ElementModes
.WRITE
) )
122 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
123 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xEmptySubStorage
,
126 ElementModes
.WRITE
) )
129 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
130 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
133 ElementModes
.WRITE
) )
136 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
137 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xEmptySubSubStorage
,
140 ElementModes
.WRITE
) )
144 // make a copy of substorage
146 if ( !m_aTestHelper
.copyElementTo( xTempStorage
, "SubStorage1", xTempStorage
, "SubStorage1_copy" ) )
149 if ( !m_aTestHelper
.copyElementTo( xTempStorage
, "EmptySubStorage1", xTempStorage
, "EmptySubStorage1_copy" ) )
152 // ================================================
153 // copy all the changed and noncommited substorages
155 // ================================================
157 if ( !m_aTestHelper
.commitStorage( xEmptySubSubStorage
) )
160 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
163 if ( !m_aTestHelper
.commitStorage( xEmptySubStorage
) )
166 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
169 // dispose substorages
171 if ( !m_aTestHelper
.disposeStorage( xEmptySubSubStorage
) )
174 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
177 if ( !m_aTestHelper
.disposeStorage( xEmptySubStorage
) )
180 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
183 // ================================================
184 // reopen the storage in readonly mode an check contents
185 // ================================================
187 pArgs
[1] = new Integer( ElementModes
.READ
);
189 oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
190 xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
191 if ( xTempStorage
== null )
193 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
197 // open original substorage
198 xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
201 if ( xTempSubStorage
== null )
203 m_aTestHelper
.Error( "Can't create substorage!" );
207 // open copy of the original substorage
208 XStorage xTempSubStorage_copy
= m_aTestHelper
.openSubStorage( xTempStorage
,
211 if ( xTempSubStorage_copy
== null )
213 m_aTestHelper
.Error( "Can't create substorage!" );
217 // open empty substorage
218 xEmptySubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
221 if ( xEmptySubStorage
== null )
223 m_aTestHelper
.Error( "Can't create substorage!" );
227 // open copy of empty substorage
228 XStorage xEmptySubStorage_copy
= m_aTestHelper
.openSubStorage( xTempStorage
,
229 "EmptySubStorage1_copy",
231 if ( xEmptySubStorage_copy
== null )
233 m_aTestHelper
.Error( "Can't create substorage!" );
237 // open an empty substorage of the substorage
238 xEmptySubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
239 "EmptySubSubStorage1",
241 if ( xEmptySubSubStorage
== null )
243 m_aTestHelper
.Error( "Can't create substorage!" );
247 // open an empty substorage of the substorage copy
248 XStorage xEmptySubSubStorage_inCopy
= m_aTestHelper
.openSubStorage( xTempSubStorage_copy
,
249 "EmptySubSubStorage1",
251 if ( xEmptySubSubStorage_inCopy
== null )
253 m_aTestHelper
.Error( "Can't create substorage!" );
260 if ( !m_aTestHelper
.checkStorageProperties( xEmptySubSubStorage
, "MediaType5", false, ElementModes
.READ
) )
263 if ( !m_aTestHelper
.checkStorageProperties( xEmptySubSubStorage_inCopy
, "MediaType5", false, ElementModes
.READ
) )
266 if ( !m_aTestHelper
.checkStorageProperties( xTempSubStorage
, "MediaType4", false, ElementModes
.READ
) )
269 if ( !m_aTestHelper
.checkStorageProperties( xTempSubStorage_copy
, "MediaType4", false, ElementModes
.READ
) )
272 if ( !m_aTestHelper
.checkStorageProperties( xEmptySubStorage
, "MediaType3", false, ElementModes
.READ
) )
275 if ( !m_aTestHelper
.checkStorageProperties( xEmptySubStorage_copy
, "MediaType3", false, ElementModes
.READ
) )
278 if ( !m_aTestHelper
.checkStorageProperties( xTempStorage
, "MediaType2", true, ElementModes
.READ
) )
281 if ( !m_aTestHelper
.checkStream( xTempSubStorage
, "SubStream1", "MediaType1", true, pBytes1
) )
284 if ( !m_aTestHelper
.checkStream( xTempSubStorage_copy
, "SubStream1", "MediaType1", true, pBytes1
) )
287 // the root storage is based on the temporary stream so it can be left undisposed, since it does not lock
288 // any resource, later the garbage collector will release the object and it must die by refcount
294 m_aTestHelper
.Error( "Exception: " + e
);