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 Test07
implements StorageTest
{
19 XMultiServiceFactory m_xMSF
;
20 XSingleServiceFactory m_xStorageFactory
;
21 TestHelper m_aTestHelper
;
23 public Test07( XMultiServiceFactory xMSF
, XSingleServiceFactory xStorageFactory
, LogWriter aLogWriter
)
26 m_xStorageFactory
= xStorageFactory
;
27 m_aTestHelper
= new TestHelper( aLogWriter
, "Test07: " );
34 String sTempFileURL
= m_aTestHelper
.CreateTempFile( m_xMSF
);
35 if ( sTempFileURL
== null || sTempFileURL
== "" )
37 m_aTestHelper
.Error( "No valid temporary file was created!" );
41 // create temporary storage based on arbitrary medium
42 // after such a storage is closed it is lost
43 Object oTempStorage
= m_xStorageFactory
.createInstance();
44 XStorage xTempStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oTempStorage
);
45 if ( xTempStorage
== null )
47 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
51 byte pBigBytes
[] = new byte[33000];
52 for ( int nInd
= 0; nInd
< 33000; nInd
++ )
53 pBigBytes
[nInd
] = (byte)( nInd
% 128 );
55 byte pBytes1
[] = { 1, 1, 1, 1, 1 };
56 String sPass1
= "12345";
58 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
59 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "BigSubStream1", "MediaType1", true, pBigBytes
, sPass1
) )
62 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
63 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "SubStream1", "MediaType1", true, pBytes1
, sPass1
) )
66 byte pBytes2
[] = { 2, 2, 2, 2, 2 };
67 String sPass2
= "54321";
69 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
70 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "BigSubStream2", "MediaType2", false, pBigBytes
, sPass2
) )
73 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
74 if ( !m_aTestHelper
.WriteBytesToEncrSubstream( xTempStorage
, "SubStream2", "MediaType2", false, pBytes2
, sPass2
) )
77 // create temporary storage based on a previously created temporary file
78 Object pArgs
[] = new Object
[2];
79 pArgs
[0] = (Object
) sTempFileURL
;
80 pArgs
[1] = new Integer( ElementModes
.WRITE
);
82 Object oTempFileStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
83 XStorage xTempFileStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oTempFileStorage
);
84 if ( xTempFileStorage
== null )
86 m_aTestHelper
.Error( "Can't create storage based on temporary file!" );
90 // copy xTempStorage to xTempFileStorage
91 // xTempFileStorage will be automatically commited
92 if ( !m_aTestHelper
.copyStorage( xTempStorage
, xTempFileStorage
) )
95 // dispose used storages to free resources
96 if ( !m_aTestHelper
.disposeStorage( xTempStorage
) || !m_aTestHelper
.disposeStorage( xTempFileStorage
) )
99 // ================================================
100 // now check all the written and copied information
101 // ================================================
103 // the temporary file must not be locked any more after storage disposing
104 pArgs
[1] = new Integer( ElementModes
.WRITE
);
105 Object oResultStorage
= m_xStorageFactory
.createInstanceWithArguments( pArgs
);
106 XStorage xResultStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, oResultStorage
);
107 if ( xResultStorage
== null )
109 m_aTestHelper
.Error( "Can't reopen storage based on temporary file!" );
113 Object o2CopyStorage
= m_xStorageFactory
.createInstance();
114 XStorage x2CopyStorage
= (XStorage
) UnoRuntime
.queryInterface( XStorage
.class, o2CopyStorage
);
115 if ( x2CopyStorage
== null )
117 m_aTestHelper
.Error( "Can't create temporary storage representation!" );
121 if ( !m_aTestHelper
.copyStorage( xResultStorage
, x2CopyStorage
) )
124 if ( !m_aTestHelper
.checkEncrStream( xResultStorage
, "SubStream1", "MediaType1", pBytes1
, sPass1
) )
127 if ( !m_aTestHelper
.checkEncrStream( xResultStorage
, "BigSubStream1", "MediaType1", pBigBytes
, sPass1
) )
130 if ( !m_aTestHelper
.checkEncrStream( xResultStorage
, "SubStream2", "MediaType2", pBytes2
, sPass2
) )
133 if ( !m_aTestHelper
.checkEncrStream( xResultStorage
, "BigSubStream2", "MediaType2", pBigBytes
, sPass2
) )
136 if ( !m_aTestHelper
.checkEncrStream( x2CopyStorage
, "SubStream1", "MediaType1", pBytes1
, sPass1
) )
139 if ( !m_aTestHelper
.checkEncrStream( x2CopyStorage
, "BigSubStream1", "MediaType1", pBigBytes
, sPass1
) )
142 if ( !m_aTestHelper
.checkEncrStream( x2CopyStorage
, "SubStream2", "MediaType2", pBytes2
, sPass2
) )
145 if ( !m_aTestHelper
.checkEncrStream( x2CopyStorage
, "BigSubStream2", "MediaType2", pBigBytes
, sPass2
) )
148 // dispose used storages to free resources
149 if ( !m_aTestHelper
.disposeStorage( xResultStorage
) )
156 m_aTestHelper
.Error( "Exception: " + e
);