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";
48 String sTempFileURL
= m_aTestHelper
.CreateTempFile( m_xMSF
);
49 if ( sTempFileURL
== null || sTempFileURL
== "" )
51 m_aTestHelper
.Error( "No valid temporary file was created!" );
55 // create temporary storage based on a previously created temporary file
56 Object pArgs
[] = new Object
[2];
57 pArgs
[0] = (Object
) sTempFileURL
;
58 pArgs
[1] = new Integer( ElementModes
.WRITE
);
60 Object oTempFileStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
61 XStorage xTempFileStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oTempFileStorage
);
62 if ( xTempFileStorage
== null )
64 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
68 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
70 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
72 if ( !m_aTestHelper
.WriteBytesToStreamH( xTempFileStorage
, aSubStream1Path
, "MediaType1", true, pBytes1
, true ) )
75 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
77 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
79 if ( !m_aTestHelper
.WriteBytesToStreamH( xTempFileStorage
, aSubStream2Path
, "MediaType2", false, pBytes2
, true ) )
82 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
84 if ( !m_aTestHelper
.WriteBytesToStreamH( xTempFileStorage
, aSubStream3Path
, "MediaType2", false, pBytes2
, false ) )
87 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
88 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempFileStorage
,
91 ElementModes
.WRITE
) )
94 // commit the root storage so the contents must be stored now
95 if ( !m_aTestHelper
.commitStorage( xTempFileStorage
) )
98 // dispose used storages to free resources
99 if ( !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
102 // ================================================
103 // now reopen the storage,
104 // check all the written and copied information
106 // ================================================
108 // the temporary file must not be locked any more after storage disposing
109 oTempFileStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
110 xTempFileStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oTempFileStorage
);
111 if ( xTempFileStorage
== null )
113 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
117 if ( !m_aTestHelper
.checkStorageProperties( xTempFileStorage
, "MediaType3", true, ElementModes
.WRITE
) )
120 if ( !m_aTestHelper
.checkStreamH( xTempFileStorage
, aSubStream1Path
, "MediaType1", true, pBytes1
) )
123 if ( !m_aTestHelper
.checkStreamH( xTempFileStorage
, aSubStream2Path
, "MediaType2", false, pBytes2
) )
126 if ( !m_aTestHelper
.cantOpenStreamH( xTempFileStorage
, aSubStream3Path
, ElementModes
.READ
) )
129 // open existing substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
131 if ( !m_aTestHelper
.WriteBytesToStreamH( xTempFileStorage
, aSubStream1Path
, "MediaType3", true, pBytes2
, true ) )
134 // open existing substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
136 if ( !m_aTestHelper
.WriteBytesToStreamH( xTempFileStorage
, aSubStream2Path
, "MediaType3", true, pBytes1
, false ) )
139 // commit the root storage so the contents must be stored now
140 if ( !m_aTestHelper
.commitStorage( xTempFileStorage
) )
143 // dispose used storages to free resources
144 if ( !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
147 // ================================================
148 // now reopen the storage,
149 // check all the written information
150 // ================================================
152 // the temporary file must not be locked any more after storage disposing
153 pArgs
[1] = new Integer( ElementModes
.READ
);
154 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
155 XStorage xResultStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
156 if ( xResultStorage
== null )
158 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
162 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
, "MediaType3", true, ElementModes
.READ
) )
165 if ( !m_aTestHelper
.checkStreamH( xResultStorage
, aSubStream1Path
, "MediaType3", true, pBytes2
) )
168 // the following stream was not commited last time, so the last change must be lost
169 if ( !m_aTestHelper
.checkStreamH( xResultStorage
, aSubStream2Path
, "MediaType2", false, pBytes2
) )
172 // dispose used storages to free resources
173 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
180 m_aTestHelper
.Error( "Exception: " + e
);