fix toolbar import
[ooovba.git] / package / qa / storages / Test07.java
blob1480602785a436c406125fdaf1c29f16ea0a334d
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 )
25 m_xMSF = xMSF;
26 m_xStorageFactory = xStorageFactory;
27 m_aTestHelper = new TestHelper( aLogWriter, "Test07: " );
30 public boolean test()
32 try
34 String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF );
35 if ( sTempFileURL == null || sTempFileURL == "" )
37 m_aTestHelper.Error( "No valid temporary file was created!" );
38 return false;
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!" );
48 return false;
51 byte pBytes1[] = { 1, 1, 1, 1, 1 };
52 String sPass1 = "12345";
54 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
55 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "SubStream1", "MediaType1", true, pBytes1, sPass1 ) )
56 return false;
58 byte pBytes2[] = { 2, 2, 2, 2, 2 };
59 String sPass2 = "54321";
61 // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes
62 if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "SubStream2", "MediaType2", false, pBytes2, sPass2 ) )
63 return false;
65 // create temporary storage based on a previously created temporary file
66 Object pArgs[] = new Object[2];
67 pArgs[0] = (Object) sTempFileURL;
68 pArgs[1] = new Integer( ElementModes.WRITE );
70 Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
71 XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage );
72 if ( xTempFileStorage == null )
74 m_aTestHelper.Error( "Can't create storage based on temporary file!" );
75 return false;
78 // copy xTempStorage to xTempFileStorage
79 // xTempFileStorage will be automatically commited
80 if ( !m_aTestHelper.copyStorage( xTempStorage, xTempFileStorage ) )
81 return false;
83 // dispose used storages to free resources
84 if ( !m_aTestHelper.disposeStorage( xTempStorage ) || !m_aTestHelper.disposeStorage( xTempFileStorage ) )
85 return false;
87 // ================================================
88 // now check all the written and copied information
89 // ================================================
91 // the temporary file must not be locked any more after storage disposing
92 pArgs[1] = new Integer( ElementModes.WRITE );
93 Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
94 XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage );
95 if ( xResultStorage == null )
97 m_aTestHelper.Error( "Can't reopen storage based on temporary file!" );
98 return false;
101 Object o2CopyStorage = m_xStorageFactory.createInstance();
102 XStorage x2CopyStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, o2CopyStorage );
103 if ( x2CopyStorage == null )
105 m_aTestHelper.Error( "Can't create temporary storage representation!" );
106 return false;
109 if ( !m_aTestHelper.copyStorage( xResultStorage, x2CopyStorage ) )
110 return false;
112 if ( !m_aTestHelper.checkEncrStream( xResultStorage, "SubStream1", "MediaType1", pBytes1, sPass1 ) )
113 return false;
115 if ( !m_aTestHelper.checkEncrStream( xResultStorage, "SubStream2", "MediaType2", pBytes2, sPass2 ) )
116 return false;
118 if ( !m_aTestHelper.checkEncrStream( x2CopyStorage, "SubStream1", "MediaType1", pBytes1, sPass1 ) )
119 return false;
121 if ( !m_aTestHelper.checkEncrStream( x2CopyStorage, "SubStream2", "MediaType2", pBytes2, sPass2 ) )
122 return false;
124 // dispose used storages to free resources
125 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
126 return false;
128 return true;
130 catch( Exception e )
132 m_aTestHelper.Error( "Exception: " + e );
133 return false;