merge the formfield patch from ooo-build
[ooovba.git] / package / qa / storages / Test07.java
blobb0edaa5db9983c400e24447ce33c4cea230f5502
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 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 ) )
60 return false;
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 ) )
64 return false;
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 ) )
71 return false;
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 ) )
75 return false;
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!" );
87 return false;
90 // copy xTempStorage to xTempFileStorage
91 // xTempFileStorage will be automatically commited
92 if ( !m_aTestHelper.copyStorage( xTempStorage, xTempFileStorage ) )
93 return false;
95 // dispose used storages to free resources
96 if ( !m_aTestHelper.disposeStorage( xTempStorage ) || !m_aTestHelper.disposeStorage( xTempFileStorage ) )
97 return false;
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!" );
110 return false;
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!" );
118 return false;
121 if ( !m_aTestHelper.copyStorage( xResultStorage, x2CopyStorage ) )
122 return false;
124 if ( !m_aTestHelper.checkEncrStream( xResultStorage, "SubStream1", "MediaType1", pBytes1, sPass1 ) )
125 return false;
127 if ( !m_aTestHelper.checkEncrStream( xResultStorage, "BigSubStream1", "MediaType1", pBigBytes, sPass1 ) )
128 return false;
130 if ( !m_aTestHelper.checkEncrStream( xResultStorage, "SubStream2", "MediaType2", pBytes2, sPass2 ) )
131 return false;
133 if ( !m_aTestHelper.checkEncrStream( xResultStorage, "BigSubStream2", "MediaType2", pBigBytes, sPass2 ) )
134 return false;
136 if ( !m_aTestHelper.checkEncrStream( x2CopyStorage, "SubStream1", "MediaType1", pBytes1, sPass1 ) )
137 return false;
139 if ( !m_aTestHelper.checkEncrStream( x2CopyStorage, "BigSubStream1", "MediaType1", pBigBytes, sPass1 ) )
140 return false;
142 if ( !m_aTestHelper.checkEncrStream( x2CopyStorage, "SubStream2", "MediaType2", pBytes2, sPass2 ) )
143 return false;
145 if ( !m_aTestHelper.checkEncrStream( x2CopyStorage, "BigSubStream2", "MediaType2", pBigBytes, sPass2 ) )
146 return false;
148 // dispose used storages to free resources
149 if ( !m_aTestHelper.disposeStorage( xResultStorage ) )
150 return false;
152 return true;
154 catch( Exception e )
156 m_aTestHelper.Error( "Exception: " + e );
157 return false;