1*cdf0e10cSrcweir package complex.storages; 2*cdf0e10cSrcweir 3*cdf0e10cSrcweir import java.lang.Integer; 4*cdf0e10cSrcweir 5*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 6*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 7*cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory; 8*cdf0e10cSrcweir 9*cdf0e10cSrcweir import com.sun.star.bridge.XUnoUrlResolver; 10*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 11*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 12*cdf0e10cSrcweir import com.sun.star.io.XStream; 13*cdf0e10cSrcweir import com.sun.star.io.XInputStream; 14*cdf0e10cSrcweir 15*cdf0e10cSrcweir import com.sun.star.embed.*; 16*cdf0e10cSrcweir 17*cdf0e10cSrcweir import share.LogWriter; 18*cdf0e10cSrcweir import complex.storages.TestHelper; 19*cdf0e10cSrcweir import complex.storages.StorageTest; 20*cdf0e10cSrcweir import complex.storages.BorderedStream; 21*cdf0e10cSrcweir 22*cdf0e10cSrcweir public class RegressionTest_125919 implements StorageTest { 23*cdf0e10cSrcweir 24*cdf0e10cSrcweir XMultiServiceFactory m_xMSF; 25*cdf0e10cSrcweir XSingleServiceFactory m_xStorageFactory; 26*cdf0e10cSrcweir TestHelper m_aTestHelper; 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir int nMinTestLen = 0; 29*cdf0e10cSrcweir int nMaxTestLen = 60000; 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir public RegressionTest_125919( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) 32*cdf0e10cSrcweir { 33*cdf0e10cSrcweir m_xMSF = xMSF; 34*cdf0e10cSrcweir m_xStorageFactory = xStorageFactory; 35*cdf0e10cSrcweir m_aTestHelper = new TestHelper( aLogWriter, "RegressionTest_125919: " ); 36*cdf0e10cSrcweir } 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir public boolean test() 39*cdf0e10cSrcweir { 40*cdf0e10cSrcweir try 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir byte[] pBytes0 = new byte[0]; 43*cdf0e10cSrcweir byte[] pBytes18 = new byte[18000]; 44*cdf0e10cSrcweir byte[] pBytes36 = new byte[36000]; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir for ( int nInitInd = 0; nInitInd < 36000; nInitInd++ ) 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir pBytes36[nInitInd] = ( new Integer( nInitInd >> ( ( nInitInd % 2 ) * 8 ) ) ).byteValue(); 49*cdf0e10cSrcweir if ( nInitInd < 18000 ) 50*cdf0e10cSrcweir pBytes18[nInitInd] = ( new Integer( 256 - pBytes36[nInitInd] ) ).byteValue(); 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir System.out.println( "This test can take up to some hours. The file size currently is about 50000." ); 54*cdf0e10cSrcweir System.out.println( "Progress: " ); 55*cdf0e10cSrcweir for ( int nAvailableBytes = nMinTestLen; nAvailableBytes < nMaxTestLen; nAvailableBytes++ ) 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir Object oBStream = new BorderedStream( nAvailableBytes ); 58*cdf0e10cSrcweir XStream xBorderedStream = (XStream)UnoRuntime.queryInterface( XStream.class, oBStream ); 59*cdf0e10cSrcweir if ( xBorderedStream == null ) 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create bordered stream!" ); 62*cdf0e10cSrcweir return false; 63*cdf0e10cSrcweir } 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir // create storage based on the temporary stream 66*cdf0e10cSrcweir Object pArgs[] = new Object[2]; 67*cdf0e10cSrcweir pArgs[0] = (Object) xBorderedStream; 68*cdf0e10cSrcweir pArgs[1] = new Integer( ElementModes.WRITE ); 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); 71*cdf0e10cSrcweir XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); 72*cdf0e10cSrcweir if ( xTempStorage == null ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create temporary storage representation!" ); 75*cdf0e10cSrcweir return false; 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir XTransactedObject xTransact = (XTransactedObject) UnoRuntime.queryInterface( XTransactedObject.class, xTempStorage ); 79*cdf0e10cSrcweir if ( xTransact == null ) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir m_aTestHelper.Error( "This test is designed for storages in transacted mode!" ); 82*cdf0e10cSrcweir return false; 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "SubStream" + 0, "MediaType1", true, pBytes0 ) ) 87*cdf0e10cSrcweir return false; 88*cdf0e10cSrcweir if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "SubStream" + 18, "MediaType2", true, pBytes18 ) ) 89*cdf0e10cSrcweir return false; 90*cdf0e10cSrcweir if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, "SubStream" + 36, "MediaType3", true, pBytes36 ) ) 91*cdf0e10cSrcweir return false; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir if ( nAvailableBytes > 0 && nAvailableBytes % 100 == 0 ) 94*cdf0e10cSrcweir System.out.println( " " + nAvailableBytes ); 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir if ( nAvailableBytes > 0 && nAvailableBytes % 2 == 1 ) 97*cdf0e10cSrcweir System.out.print( "#" ); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir try 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir xTransact.commit(); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir System.out.println( "" ); 104*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) 105*cdf0e10cSrcweir return false; 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir // SUCCESS 108*cdf0e10cSrcweir return true; 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir catch( UseBackupException aExc ) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir // when there is not enough place in the target location and the target file is empty 113*cdf0e10cSrcweir // the direct writing will fail and must throw this exception with empty URL 114*cdf0e10cSrcweir if ( aExc.TemporaryFileURL.length() != 0 ) 115*cdf0e10cSrcweir return false; 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir catch( Exception e ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir System.out.println( "" ); 120*cdf0e10cSrcweir m_aTestHelper.Error( "Unexpected exception: " + e + "\nnAvailableBytes = " + nAvailableBytes ); 121*cdf0e10cSrcweir return false; 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir return false; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir catch( Exception e ) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir m_aTestHelper.Error( "Exception: " + e ); 130*cdf0e10cSrcweir return false; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135