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_i30677
implements StorageTest
{
21 XMultiServiceFactory m_xMSF
;
22 XSingleServiceFactory m_xStorageFactory
;
23 TestHelper m_aTestHelper
;
25 public RegressionTest_i30677( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
28 m_xStorageFactory
= xStorageFactory
;
29 m_aTestHelper
= new TestHelper( aLogWriter
, "RegressionTest_i30677: " );
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 // open a new subsubstorage
64 XStorage xTempSubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
67 if ( xTempSubSubStorage
== null )
69 m_aTestHelper
.Error( "Can't create substorage!" );
73 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
75 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
76 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubSubStorage
, "SubSubStream1", "MediaType1", true, pBytes1
) )
79 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
80 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempStorage
,
83 ElementModes
.WRITE
) )
86 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
87 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubStorage
,
90 ElementModes
.WRITE
) )
93 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
94 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempSubSubStorage
,
97 ElementModes
.WRITE
) )
100 // ================================================
101 // commit the storages
102 // ================================================
104 // commit lowlevel substorage first
105 if ( !m_aTestHelper
.commitStorage( xTempSubSubStorage
) )
109 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
112 // commit substorage to let the renaming take place
113 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
116 // ================================================
117 // dispose the storages
118 // ================================================
120 // dispose lowerest substorage
121 if ( !m_aTestHelper
.disposeStorage( xTempSubSubStorage
) )
124 // dispose substorage
125 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
128 // dispose the temporary storage
129 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
132 // ================================================
133 // reopen the storage and rewrite the stream
134 // ================================================
136 oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
137 xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
138 if ( xTempStorage
== null )
140 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
144 // open the substorages
146 xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
148 ElementModes
.WRITE
);
149 if ( xTempSubStorage
== null )
151 m_aTestHelper
.Error( "Can't create substorage!" );
155 // open the lowlevel substorages
157 xTempSubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
159 ElementModes
.WRITE
);
160 if ( xTempSubSubStorage
== null )
162 m_aTestHelper
.Error( "Can't create substorage!" );
166 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
168 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
169 if ( !m_aTestHelper
.WriteBytesToSubstream( xTempSubSubStorage
, "SubSubStream1", "MediaType1", true, pBytes2
) )
172 // ================================================
173 // commit the storages
174 // ================================================
176 // commit lowlevel substorage first
177 if ( !m_aTestHelper
.commitStorage( xTempSubSubStorage
) )
181 if ( !m_aTestHelper
.commitStorage( xTempSubStorage
) )
184 // commit substorage to let the renaming take place
185 if ( !m_aTestHelper
.commitStorage( xTempStorage
) )
188 // ================================================
189 // dispose the storages
190 // ================================================
192 // dispose lowerest substorage
193 if ( !m_aTestHelper
.disposeStorage( xTempSubSubStorage
) )
196 // dispose substorage
197 if ( !m_aTestHelper
.disposeStorage( xTempSubStorage
) )
200 // dispose the temporary storage
201 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) )
204 // ================================================
205 // reopen the storages and check the contents
206 // ================================================
208 pArgs
[1] = new Integer( ElementModes
.READ
);
209 oTempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
210 xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
211 if ( xTempStorage
== null )
213 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
217 // open the substorages
219 xTempSubStorage
= m_aTestHelper
.openSubStorage( xTempStorage
,
222 if ( xTempSubStorage
== null )
224 m_aTestHelper
.Error( "Can't create substorage!" );
228 // open the lowlevel substorages
230 xTempSubSubStorage
= m_aTestHelper
.openSubStorage( xTempSubStorage
,
233 if ( xTempSubSubStorage
== null )
235 m_aTestHelper
.Error( "Can't create substorage!" );
239 if ( !m_aTestHelper
.checkStorageProperties( xTempSubSubStorage
, "MediaType4", false, ElementModes
.READ
) )
242 if ( !m_aTestHelper
.checkStorageProperties( xTempSubStorage
, "MediaType3", false, ElementModes
.READ
) )
245 if ( !m_aTestHelper
.checkStorageProperties( xTempStorage
, "MediaType2", true, ElementModes
.READ
) )
248 if ( !m_aTestHelper
.checkStream( xTempSubSubStorage
, "SubSubStream1", "MediaType1", true, pBytes2
) )
251 // the root storage is based on the temporary stream so it can be left undisposed, since it does not lock
252 // any resource, later the garbage collector will release the object and it must die by refcount
258 m_aTestHelper
.Error( "Exception: " + e
);