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 import com.sun.star.io.XInputStream; 12*cdf0e10cSrcweir 13*cdf0e10cSrcweir import com.sun.star.embed.*; 14*cdf0e10cSrcweir 15*cdf0e10cSrcweir import share.LogWriter; 16*cdf0e10cSrcweir import complex.storages.TestHelper; 17*cdf0e10cSrcweir import complex.storages.StorageTest; 18*cdf0e10cSrcweir 19*cdf0e10cSrcweir public class Test17 implements StorageTest { 20*cdf0e10cSrcweir 21*cdf0e10cSrcweir XMultiServiceFactory m_xMSF; 22*cdf0e10cSrcweir XSingleServiceFactory m_xStorageFactory; 23*cdf0e10cSrcweir TestHelper m_aTestHelper; 24*cdf0e10cSrcweir 25*cdf0e10cSrcweir public Test17( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) 26*cdf0e10cSrcweir { 27*cdf0e10cSrcweir m_xMSF = xMSF; 28*cdf0e10cSrcweir m_xStorageFactory = xStorageFactory; 29*cdf0e10cSrcweir m_aTestHelper = new TestHelper( aLogWriter, "Test17: " ); 30*cdf0e10cSrcweir } 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir public boolean test() 33*cdf0e10cSrcweir { 34*cdf0e10cSrcweir try 35*cdf0e10cSrcweir { 36*cdf0e10cSrcweir XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF ); 37*cdf0e10cSrcweir if ( xTempFileStream == null ) 38*cdf0e10cSrcweir return false; 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir // create storage based on the temporary stream 41*cdf0e10cSrcweir Object pArgs[] = new Object[2]; 42*cdf0e10cSrcweir pArgs[0] = (Object) xTempFileStream; 43*cdf0e10cSrcweir pArgs[1] = new Integer( ElementModes.WRITE ); 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); 46*cdf0e10cSrcweir XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); 47*cdf0e10cSrcweir if ( xTempStorage == null ) 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create temporary storage representation!" ); 50*cdf0e10cSrcweir return false; 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir byte pBytes1[] = { 1, 1, 1, 1, 1 }; 55*cdf0e10cSrcweir String pNames[] = { "SubStream1", "SubStream2", "SubStream3", "SubStream4", "SubStream5", "SubStream6", "SubStream7" }; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir for ( int nInd = 0; nInd < pNames.length; nInd++ ) 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir // open a new substorage 60*cdf0e10cSrcweir XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, 61*cdf0e10cSrcweir "SubStorage1", 62*cdf0e10cSrcweir ElementModes.WRITE ); 63*cdf0e10cSrcweir if ( xTempSubStorage == null ) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 66*cdf0e10cSrcweir return false; 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes 70*cdf0e10cSrcweir if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, pNames[nInd], "MediaType1", true, pBytes1 ) ) 71*cdf0e10cSrcweir return false; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir // commit substorage first 74*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) 75*cdf0e10cSrcweir return false; 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir // dispose used storage to free resources 78*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) ) 79*cdf0e10cSrcweir return false; 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir // commit the root storage so the contents must be stored now 83*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xTempStorage ) ) 84*cdf0e10cSrcweir return false; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir // dispose used storage to free resources 87*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) 88*cdf0e10cSrcweir return false; 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir // ================================================ 92*cdf0e10cSrcweir // now check all the written information 93*cdf0e10cSrcweir // ================================================ 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir // close the output part of the temporary stream 96*cdf0e10cSrcweir // the output part must present since we already wrote to the stream 97*cdf0e10cSrcweir if ( !m_aTestHelper.closeOutput( xTempFileStream ) ) 98*cdf0e10cSrcweir return false; 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir XInputStream xTempInStream = m_aTestHelper.getInputStream( xTempFileStream ); 101*cdf0e10cSrcweir if ( xTempInStream == null ) 102*cdf0e10cSrcweir return false; 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir // open input stream 106*cdf0e10cSrcweir // since no mode is provided the result storage must be opened readonly 107*cdf0e10cSrcweir Object pOneArg[] = new Object[1]; 108*cdf0e10cSrcweir pOneArg[0] = (Object) xTempInStream; 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pOneArg ); 111*cdf0e10cSrcweir XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage ); 112*cdf0e10cSrcweir if ( xResultStorage == null ) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir m_aTestHelper.Error( "Can't open storage based on input stream!" ); 115*cdf0e10cSrcweir return false; 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir // open existing substorage 119*cdf0e10cSrcweir XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage, 120*cdf0e10cSrcweir "SubStorage1", 121*cdf0e10cSrcweir ElementModes.READ ); 122*cdf0e10cSrcweir if ( xResultSubStorage == null ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir m_aTestHelper.Error( "Can't open existing substorage!" ); 125*cdf0e10cSrcweir return false; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir for ( int nInd = 0; nInd < pNames.length; nInd++ ) 129*cdf0e10cSrcweir if ( !m_aTestHelper.checkStream( xResultSubStorage, pNames[nInd], "MediaType1", true, pBytes1 ) ) 130*cdf0e10cSrcweir return false; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir return true; 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir catch( Exception e ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir m_aTestHelper.Error( "Exception: " + e ); 137*cdf0e10cSrcweir return false; 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir 143