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 Test14
implements StorageTest
{
19 XMultiServiceFactory m_xMSF
;
20 XSingleServiceFactory m_xStorageFactory
;
21 TestHelper m_aTestHelper
;
23 public Test14( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
26 m_xStorageFactory
= xStorageFactory
;
27 m_aTestHelper
= new TestHelper( aLogWriter
, "Test14: " );
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 };
69 String sPass1
= "12345";
71 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
73 if ( !m_aTestHelper
.WriteBytesToEncrStreamH( xTempFileStorage
, aSubStream1Path
, "MediaType1", true, pBytes1
, sPass1
, true ) )
76 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
77 String sPass2
= "54321";
79 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
81 if ( !m_aTestHelper
.WriteBytesToEncrStreamH( xTempFileStorage
, aSubStream2Path
, "MediaType2", false, pBytes2
, sPass2
, true ) )
84 // open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
86 if ( !m_aTestHelper
.WriteBytesToEncrStreamH( xTempFileStorage
, aSubStream3Path
, "MediaType2", false, pBytes2
, sPass2
, false ) )
89 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly
90 if ( !m_aTestHelper
.setStorageTypeAndCheckProps( xTempFileStorage
,
93 ElementModes
.WRITE
) )
96 // commit the root storage so the contents must be stored now
97 if ( !m_aTestHelper
.commitStorage( xTempFileStorage
) )
100 // dispose used storages to free resources
101 if ( !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
104 // ================================================
105 // now reopen the storage,
106 // check all the written and copied information
108 // ================================================
110 // the temporary file must not be locked any more after storage disposing
111 oTempFileStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
112 xTempFileStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oTempFileStorage
);
113 if ( xTempFileStorage
== null )
115 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
119 if ( !m_aTestHelper
.checkStorageProperties( xTempFileStorage
, "MediaType3", true, ElementModes
.WRITE
) )
122 if ( !m_aTestHelper
.checkEncrStreamH( xTempFileStorage
, aSubStream1Path
, "MediaType1", pBytes1
, sPass1
) )
125 if ( !m_aTestHelper
.checkEncrStreamH( xTempFileStorage
, aSubStream2Path
, "MediaType2", pBytes2
, sPass2
) )
128 if ( !m_aTestHelper
.cantOpenEncrStreamH( xTempFileStorage
, aSubStream3Path
, ElementModes
.READ
, sPass2
) )
131 // open existing substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
133 if ( !m_aTestHelper
.WriteBytesToEncrStreamH( xTempFileStorage
, aSubStream1Path
, "MediaType3", true, pBytes2
, sPass1
, true ) )
136 // open existing substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes
138 if ( !m_aTestHelper
.WriteBytesToEncrStreamH( xTempFileStorage
, aSubStream2Path
, "MediaType3", true, pBytes1
, sPass2
, false ) )
141 // commit the root storage so the contents must be stored now
142 if ( !m_aTestHelper
.commitStorage( xTempFileStorage
) )
145 // dispose used storages to free resources
146 if ( !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
149 // ================================================
150 // now reopen the storage,
151 // check all the written information
152 // ================================================
154 // the temporary file must not be locked any more after storage disposing
155 pArgs
[1] = new Integer( ElementModes
.READ
);
156 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
157 XStorage xResultStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
158 if ( xResultStorage
== null )
160 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
164 if ( !m_aTestHelper
.checkStorageProperties( xResultStorage
, "MediaType3", true, ElementModes
.READ
) )
167 if ( !m_aTestHelper
.checkEncrStreamH( xResultStorage
, aSubStream1Path
, "MediaType3", pBytes2
, sPass1
) )
170 // the following stream was not commited last time, so the last change must be lost
171 if ( !m_aTestHelper
.checkEncrStreamH( xResultStorage
, aSubStream2Path
, "MediaType2", pBytes2
, sPass2
) )
174 // dispose used storages to free resources
175 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
182 m_aTestHelper
.Error( "Exception: " + e
);