fix toolbar import
[ooovba.git] / package / qa / storages / RegressionTest_i55821.java
blobaabeda14c4e30fc2879e37c8a5737074dd3de791
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;
12 import com.sun.star.embed.*;
14 import share.LogWriter;
15 import complex.storages.TestHelper;
16 import complex.storages.StorageTest;
18 public class RegressionTest_i55821 implements StorageTest {
20 XMultiServiceFactory m_xMSF;
21 XSingleServiceFactory m_xStorageFactory;
22 TestHelper m_aTestHelper;
24 public RegressionTest_i55821( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )
26 m_xMSF = xMSF;
27 m_xStorageFactory = xStorageFactory;
28 m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i55821: " );
31 public boolean test()
33 try
35 // ================================================
36 // create a temporary stream and a storage based on it
37 // fill the storage with the data that will be used for testing
38 // ================================================
40 XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF );
41 if ( xTempFileStream == null )
42 return false;
44 // create storage based on the temporary stream
45 Object pArgs[] = new Object[2];
46 pArgs[0] = (Object) xTempFileStream;
47 pArgs[1] = new Integer( ElementModes.WRITE );
49 Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
50 XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
51 if ( xTempStorage == null )
53 m_aTestHelper.Error( "Can't create temporary storage representation!" );
54 return false;
57 String sPass = "12345";
58 byte pBytes[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
60 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
61 // the stream will not be encrypted
62 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "SubStream1", "MediaType1", false, pBytes, sPass ) )
63 return false;
65 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
66 return false;
68 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "SubStream2", "MediaType2", false, pBytes, sPass ) )
69 return false;
71 if ( !m_aTestHelper.commitStorage( xTempStorage ) )
72 return false;
74 // dispose used storages to free resources
75 if ( !m_aTestHelper.disposeStorage( xTempStorage ) )
76 return false;
78 // ================================================
79 // reopen the target storage readonly, and check contents
80 // ================================================
82 // the temporary file must not be locked any more after storage disposing
83 pArgs[1] = new Integer( ElementModes.READ );
84 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
85 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
86 if ( xResultStorage == null )
88 m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
89 return false;
92 if ( !m_aTestHelper.checkEncrStream( xResultStorage, "SubStream1", "MediaType1", pBytes, sPass ) )
93 return false;
95 if ( !m_aTestHelper.checkEncrStream( xResultStorage, "SubStream2", "MediaType2", pBytes, sPass ) )
96 return false;
98 // dispose used storages to free resources
99 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
100 return false;
102 return true;
104 catch( Exception e )
106 m_aTestHelper.Error( "Exception: " + e );
107 return false;