1*cdf0e10cSrcweir package complex.storages; 2*cdf0e10cSrcweir 3*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 4*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 5*cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory; 6*cdf0e10cSrcweir 7*cdf0e10cSrcweir import com.sun.star.bridge.XUnoUrlResolver; 8*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 9*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 10*cdf0e10cSrcweir import com.sun.star.io.XStream; 11*cdf0e10cSrcweir 12*cdf0e10cSrcweir import com.sun.star.embed.*; 13*cdf0e10cSrcweir 14*cdf0e10cSrcweir import share.LogWriter; 15*cdf0e10cSrcweir import complex.storages.TestHelper; 16*cdf0e10cSrcweir import complex.storages.StorageTest; 17*cdf0e10cSrcweir 18*cdf0e10cSrcweir public class RegressionTest_i55821 implements StorageTest { 19*cdf0e10cSrcweir 20*cdf0e10cSrcweir XMultiServiceFactory m_xMSF; 21*cdf0e10cSrcweir XSingleServiceFactory m_xStorageFactory; 22*cdf0e10cSrcweir TestHelper m_aTestHelper; 23*cdf0e10cSrcweir 24*cdf0e10cSrcweir public RegressionTest_i55821( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) 25*cdf0e10cSrcweir { 26*cdf0e10cSrcweir m_xMSF = xMSF; 27*cdf0e10cSrcweir m_xStorageFactory = xStorageFactory; 28*cdf0e10cSrcweir m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_i55821: " ); 29*cdf0e10cSrcweir } 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir public boolean test() 32*cdf0e10cSrcweir { 33*cdf0e10cSrcweir try 34*cdf0e10cSrcweir { 35*cdf0e10cSrcweir // ================================================ 36*cdf0e10cSrcweir // create a temporary stream and a storage based on it 37*cdf0e10cSrcweir // fill the storage with the data that will be used for testing 38*cdf0e10cSrcweir // ================================================ 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF ); 41*cdf0e10cSrcweir if ( xTempFileStream == null ) 42*cdf0e10cSrcweir return false; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir // create storage based on the temporary stream 45*cdf0e10cSrcweir Object pArgs[] = new Object[2]; 46*cdf0e10cSrcweir pArgs[0] = (Object) xTempFileStream; 47*cdf0e10cSrcweir pArgs[1] = new Integer( ElementModes.WRITE ); 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); 50*cdf0e10cSrcweir XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); 51*cdf0e10cSrcweir if ( xTempStorage == null ) 52*cdf0e10cSrcweir { 53*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create temporary storage representation!" ); 54*cdf0e10cSrcweir return false; 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir String sPass = "12345"; 58*cdf0e10cSrcweir 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 }; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes 61*cdf0e10cSrcweir // the stream will not be encrypted 62*cdf0e10cSrcweir if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "SubStream1", "MediaType1", false, pBytes, sPass ) ) 63*cdf0e10cSrcweir return false; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xTempStorage ) ) 66*cdf0e10cSrcweir return false; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "SubStream2", "MediaType2", false, pBytes, sPass ) ) 69*cdf0e10cSrcweir return false; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xTempStorage ) ) 72*cdf0e10cSrcweir return false; 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir // dispose used storages to free resources 75*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) 76*cdf0e10cSrcweir return false; 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir // ================================================ 79*cdf0e10cSrcweir // reopen the target storage readonly, and check contents 80*cdf0e10cSrcweir // ================================================ 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir // the temporary file must not be locked any more after storage disposing 83*cdf0e10cSrcweir pArgs[1] = new Integer( ElementModes.READ ); 84*cdf0e10cSrcweir Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); 85*cdf0e10cSrcweir XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage ); 86*cdf0e10cSrcweir if ( xResultStorage == null ) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir m_aTestHelper.Error( "Can't reopen storage based on temporary file!" ); 89*cdf0e10cSrcweir return false; 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir if ( !m_aTestHelper.checkEncrStream( xResultStorage, "SubStream1", "MediaType1", pBytes, sPass ) ) 93*cdf0e10cSrcweir return false; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir if ( !m_aTestHelper.checkEncrStream( xResultStorage, "SubStream2", "MediaType2", pBytes, sPass ) ) 96*cdf0e10cSrcweir return false; 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir // dispose used storages to free resources 99*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xResultStorage ) ) 100*cdf0e10cSrcweir return false; 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir return true; 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir catch( Exception e ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir m_aTestHelper.Error( "Exception: " + e ); 107*cdf0e10cSrcweir return false; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112