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_i59886
implements StorageTest
{
21 XMultiServiceFactory m_xMSF
;
22 XSingleServiceFactory m_xStorageFactory
;
23 TestHelper m_aTestHelper
;
25 public RegressionTest_i59886( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
28 m_xStorageFactory
= xStorageFactory
;
29 m_aTestHelper
= new TestHelper( aLogWriter
, "RegressionTest_i59886: " );
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 reopen the storage, set the common storage key
105 // and copy the storage
106 // ================================================
108 Object oStep2TempStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
109 XStorage xStep2TempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oStep2TempStorage
);
110 if ( xStep2TempStorage
== null )
112 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
117 XStorage xStep2TempSubStorage
= m_aTestHelper
.openSubStorage( xStep2TempStorage
,
119 ElementModes
.WRITE
);
120 if ( xStep2TempSubStorage
== null )
122 m_aTestHelper
.Error( "Can't create substorage!" );
126 // set the common storage password
127 XEncryptionProtectedSource xEncr
= (XEncryptionProtectedSource
) UnoRuntime
.queryInterface( XEncryptionProtectedSource
.class, xStep2TempStorage
);
130 m_aTestHelper
.Error( "The storage does not support encryption access!" );
135 xEncr
.setEncryptionPassword( sPass
);
139 m_aTestHelper
.Error( "Can not set the common storage password!" );
143 // open the stream for writing and read them so that the cache is created, but do not change
144 byte pDummyData
[][] = new byte[1][3];
145 XStream xTempStream1
= m_aTestHelper
.OpenStream( xStep2TempStorage
, "SubStream1", ElementModes
.WRITE
);
146 XStream xTempStream2
= m_aTestHelper
.OpenStream( xStep2TempSubStorage
, "SubStream2", ElementModes
.WRITE
);
147 if ( xTempStream1
== null || xTempStream2
== null )
150 XInputStream xTempInStream1
= xTempStream1
.getInputStream();
151 XInputStream xTempInStream2
= xTempStream2
.getInputStream();
152 if ( xTempInStream1
== null || xTempInStream2
== null )
154 m_aTestHelper
.Error( "No input stream is available!" );
158 xTempInStream1
.readBytes( pDummyData
, 3 );
159 xTempInStream2
.readBytes( pDummyData
, 3 );
162 // create temporary storage, it will be checked later
163 Object oTargetStorage
= m_xStorageFactory
.createInstance();
164 XStorage xTargetStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTargetStorage
);
165 if ( xTargetStorage
== null )
167 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
171 // copy the current storage to the target
174 xStep2TempStorage
.copyToStorage( xTargetStorage
);
178 m_aTestHelper
.Error( "Can not copy the storage with common storage password!" );
182 // dispose used storage to free resources
183 if ( !m_aTestHelper
.disposeStorage( xStep2TempStorage
) )
186 // ================================================
187 // now check all the information in the copy
188 // ================================================
190 if ( !m_aTestHelper
.checkStorageProperties( xTargetStorage
, "MediaType3", true, ElementModes
.WRITE
) )
193 // open existing substorage
194 XStorage xTargetSubStorage
= m_aTestHelper
.openSubStorage( xTargetStorage
,
196 ElementModes
.WRITE
);
197 if ( xTargetSubStorage
== null )
199 m_aTestHelper
.Error( "Can't open existing substorage!" );
203 if ( !m_aTestHelper
.checkStorageProperties( xTargetSubStorage
, "MediaType4", false, ElementModes
.WRITE
) )
206 // set the common storage password
207 XEncryptionProtectedSource xTargetEncr
= (XEncryptionProtectedSource
) UnoRuntime
.queryInterface( XEncryptionProtectedSource
.class, xTargetStorage
);
208 if ( xTargetEncr
== null )
210 m_aTestHelper
.Error( "The storage does not support encryption access!" );
215 xTargetEncr
.setEncryptionPassword( sPass
);
219 m_aTestHelper
.Error( "Can not set the common storage password!" );
224 if ( !m_aTestHelper
.checkStream( xTargetStorage
, "SubStream1", "MediaType1", true, pBytes
) )
226 if ( !m_aTestHelper
.checkStream( xTargetSubStorage
, "SubStream2", "MediaType2", true, pBytes
) )
230 // dispose used storages to free resources
231 if ( !m_aTestHelper
.disposeStorage( xTargetStorage
) )
238 m_aTestHelper
.Error( "Exception: " + e
);