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
;
11 import com
.sun
.star
.embed
.*;
13 import share
.LogWriter
;
14 import complex
.storages
.TestHelper
;
15 import complex
.storages
.StorageTest
;
17 public class Test13
implements StorageTest
{
19 XMultiServiceFactory m_xMSF
;
20 XSingleServiceFactory m_xStorageFactory
;
21 TestHelper m_aTestHelper
;
23 public Test13( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
26 m_xStorageFactory
= xStorageFactory
;
27 m_aTestHelper
= new TestHelper( aLogWriter
, "Test13: " );
32 String aStreamPrefix
= "";
33 for ( int nInd
= 0; nInd
< 4; ++nInd
, aStreamPrefix
+= "SubStorage" + nInd
)
34 if ( !testForPath( aStreamPrefix
) )
40 public boolean testForPath( String aStreamPrefix
)
44 String aSubStream1Path
= aStreamPrefix
+ "SubStream1";
45 String aSubStream2Path
= aStreamPrefix
+ "SubStream2";
46 String aSubStream3Path
= aStreamPrefix
+ "SubStream3";
47 String aBigSubStream1Path
= aStreamPrefix
+ "BigSubStream1";
48 String aBigSubStream2Path
= aStreamPrefix
+ "BigSubStream2";
49 String aBigSubStream3Path
= aStreamPrefix
+ "BigSubStream3";
51 String sTempFileURL
= m_aTestHelper
.CreateTempFile( m_xMSF
);
52 if ( sTempFileURL
== null || sTempFileURL
== "" )
54 m_aTestHelper
.Error( "No valid temporary file was created!" );
58 // create temporary storage based on a previously created temporary file
59 Object pArgs
[] = new Object
[2];
60 pArgs
[0] = (Object
) sTempFileURL
;
61 pArgs
[1] = new Integer( ElementModes
.WRITE
);
63 Object oTempFileStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
64 XStorage xTempFileStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oTempFileStorage
);
65 if ( xTempFileStorage
== null )
67 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
71 byte pBigBytes
[] = new byte[33000];
72 for ( int nInd
= 0; nInd
< 33000; nInd
++ )
73 pBigBytes
[nInd
] = (byte)( nInd
% 128 );
75 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
77 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
79 if ( !m_aTestHelper
.WriteBytesToStreamH( xTempFileStorage
, aSubStream1Path
, "MediaType1", true, pBytes1
, true ) )
81 if ( !m_aTestHelper
.WriteBytesToStreamH( xTempFileStorage
, aBigSubStream1Path
, "MediaType1", true, pBigBytes
, true ) )
84 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
86 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
88 if ( !m_aTestHelper
.WriteBytesToStreamH( xTempFileStorage
, aSubStream2Path
, "MediaType2", false, pBytes2
, true ) )
90 if ( !m_aTestHelper
.WriteBytesToStreamH( xTempFileStorage
, aBigSubStream2Path
, "MediaType2", false, pBigBytes
, true ) )
93 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
95 if ( !m_aTestHelper
.WriteBytesToStreamH( xTempFileStorage
, aSubStream3Path
, "MediaType2", false, pBytes2
, false ) )
97 if ( !m_aTestHelper
.WriteBytesToStreamH( xTempFileStorage
, aBigSubStream3Path
, "MediaType2", false, pBigBytes
, false ) )
100 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
101 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempFileStorage
,
104 ElementModes
.WRITE
) )
107 // commit the root storage so the contents must be stored now
108 if ( !m_aTestHelper
.commitStorage( xTempFileStorage
) )
111 // dispose used storages to free resources
112 if ( !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
115 // ================================================
116 // now reopen the storage,
117 // check all the written and copied information
119 // ================================================
121 // the temporary file must not be locked any more after storage disposing
122 oTempFileStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
123 xTempFileStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oTempFileStorage
);
124 if ( xTempFileStorage
== null )
126 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
130 if ( !m_aTestHelper
.checkStorageProperties( xTempFileStorage
, "MediaType3", true, ElementModes
.WRITE
) )
133 if ( !m_aTestHelper
.checkStreamH( xTempFileStorage
, aSubStream1Path
, "MediaType1", true, pBytes1
) )
136 if ( !m_aTestHelper
.checkStreamH( xTempFileStorage
, aBigSubStream1Path
, "MediaType1", true, pBigBytes
) )
139 if ( !m_aTestHelper
.checkStreamH( xTempFileStorage
, aSubStream2Path
, "MediaType2", false, pBytes2
) )
142 if ( !m_aTestHelper
.checkStreamH( xTempFileStorage
, aBigSubStream2Path
, "MediaType2", false, pBigBytes
) )
145 if ( !m_aTestHelper
.cantOpenStreamH( xTempFileStorage
, aSubStream3Path
, ElementModes
.READ
) )
148 if ( !m_aTestHelper
.cantOpenStreamH( xTempFileStorage
, aBigSubStream3Path
, ElementModes
.READ
) )
151 // open existing substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
153 if ( !m_aTestHelper
.WriteBytesToStreamH( xTempFileStorage
, aSubStream1Path
, "MediaType3", true, pBytes2
, true ) )
155 if ( !m_aTestHelper
.WriteBytesToStreamH( xTempFileStorage
, aBigSubStream1Path
, "MediaType3", true, pBigBytes
, true ) )
159 // open existing substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
161 if ( !m_aTestHelper
.WriteBytesToStreamH( xTempFileStorage
, aSubStream2Path
, "MediaType3", true, pBytes1
, false ) )
163 if ( !m_aTestHelper
.WriteBytesToStreamH( xTempFileStorage
, aBigSubStream2Path
, "MediaType3", true, pBigBytes
, false ) )
166 // commit the root storage so the contents must be stored now
167 if ( !m_aTestHelper
.commitStorage( xTempFileStorage
) )
170 // dispose used storages to free resources
171 if ( !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
174 // ================================================
175 // now reopen the storage,
176 // check all the written information
177 // ================================================
179 // the temporary file must not be locked any more after storage disposing
180 pArgs
[1] = new Integer( ElementModes
.READ
);
181 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
182 XStorage xResultStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
183 if ( xResultStorage
== null )
185 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
189 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
, "MediaType3", true, ElementModes
.READ
) )
192 if ( !m_aTestHelper
.checkStreamH( xResultStorage
, aSubStream1Path
, "MediaType3", true, pBytes2
) )
194 if ( !m_aTestHelper
.checkStreamH( xResultStorage
, aBigSubStream1Path
, "MediaType3", true, pBigBytes
) )
197 // the following stream was not commited last time, so the last change must be lost
198 if ( !m_aTestHelper
.checkStreamH( xResultStorage
, aBigSubStream2Path
, "MediaType2", false, pBigBytes
) )
201 // dispose used storages to free resources
202 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
209 m_aTestHelper
.Error( "Exception: " + e
);