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 RegressionTest_i49755 implements StorageTest { 20*cdf0e10cSrcweir 21*cdf0e10cSrcweir XMultiServiceFactory m_xMSF; 22*cdf0e10cSrcweir XSingleServiceFactory m_xStorageFactory; 23*cdf0e10cSrcweir TestHelper m_aTestHelper; 24*cdf0e10cSrcweir 25*cdf0e10cSrcweir public RegressionTest_i49755( 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, "RegressionTest_i49755: " ); 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 // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly 54*cdf0e10cSrcweir if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage, 55*cdf0e10cSrcweir "MediaType1", 56*cdf0e10cSrcweir true, 57*cdf0e10cSrcweir ElementModes.WRITE ) ) 58*cdf0e10cSrcweir return false; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir byte pBytes[] = new byte[36000]; 62*cdf0e10cSrcweir for ( int nInd = 0; nInd < 36000; nInd++ ) 63*cdf0e10cSrcweir pBytes[nInd] = (byte)( nInd % 128 ); 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir // open a new substorage 66*cdf0e10cSrcweir XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, 67*cdf0e10cSrcweir "SubStorage1", 68*cdf0e10cSrcweir ElementModes.WRITE ); 69*cdf0e10cSrcweir if ( xTempSubStorage == null ) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 72*cdf0e10cSrcweir return false; 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly 76*cdf0e10cSrcweir if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage, 77*cdf0e10cSrcweir "MediaType2", 78*cdf0e10cSrcweir false, 79*cdf0e10cSrcweir ElementModes.WRITE ) ) 80*cdf0e10cSrcweir return false; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir // open a new substorage 83*cdf0e10cSrcweir XStorage xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage, 84*cdf0e10cSrcweir "SubStorage2", 85*cdf0e10cSrcweir ElementModes.WRITE ); 86*cdf0e10cSrcweir if ( xTempSubStorage == null ) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 89*cdf0e10cSrcweir return false; 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly 93*cdf0e10cSrcweir if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubSubStorage, 94*cdf0e10cSrcweir "MediaType3", 95*cdf0e10cSrcweir false, 96*cdf0e10cSrcweir ElementModes.WRITE ) ) 97*cdf0e10cSrcweir return false; 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes 100*cdf0e10cSrcweir if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubSubStorage, "SubStream1", "MediaType4", true, pBytes ) ) 101*cdf0e10cSrcweir return false; 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir // open a new substorage 104*cdf0e10cSrcweir XStorage xTempSubStorage1 = m_aTestHelper.openSubStorage( xTempStorage, 105*cdf0e10cSrcweir "SubStorage3", 106*cdf0e10cSrcweir ElementModes.WRITE ); 107*cdf0e10cSrcweir if ( xTempSubStorage1 == null ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 110*cdf0e10cSrcweir return false; 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly 114*cdf0e10cSrcweir if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage1, 115*cdf0e10cSrcweir "MediaType5", 116*cdf0e10cSrcweir false, 117*cdf0e10cSrcweir ElementModes.WRITE ) ) 118*cdf0e10cSrcweir return false; 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes 121*cdf0e10cSrcweir if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage1, "SubStream2", "MediaType4", false, pBytes ) ) 122*cdf0e10cSrcweir return false; 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir // commit substorages first 126*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) ) 127*cdf0e10cSrcweir return false; 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) 130*cdf0e10cSrcweir return false; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xTempSubStorage1 ) ) 133*cdf0e10cSrcweir return false; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir // commit the root storage so the contents must be stored now 136*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xTempStorage ) ) 137*cdf0e10cSrcweir return false; 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir // dispose used storage to free resources 140*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) 141*cdf0e10cSrcweir return false; 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir // ================================================ 144*cdf0e10cSrcweir // now change the contents of the second substorage 145*cdf0e10cSrcweir // without changing of the contents of the first substorage 146*cdf0e10cSrcweir // ================================================ 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir Object oStep2TempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); 149*cdf0e10cSrcweir XStorage xStep2TempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oStep2TempStorage ); 150*cdf0e10cSrcweir if ( xStep2TempStorage == null ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create temporary storage representation!" ); 153*cdf0e10cSrcweir return false; 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir XStorage xStep2TempSubStorage1 = m_aTestHelper.openSubStorage( xStep2TempStorage, 157*cdf0e10cSrcweir "SubStorage3", 158*cdf0e10cSrcweir ElementModes.WRITE ); 159*cdf0e10cSrcweir if ( xStep2TempSubStorage1 == null ) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 162*cdf0e10cSrcweir return false; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes 166*cdf0e10cSrcweir if ( !m_aTestHelper.WriteBytesToSubstream( xStep2TempSubStorage1, "SubStream2", "MediaType4", false, pBytes ) ) 167*cdf0e10cSrcweir return false; 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xStep2TempSubStorage1 ) ) 170*cdf0e10cSrcweir return false; 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir // commit the root storage so the contents must be stored now 173*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xStep2TempStorage ) ) 174*cdf0e10cSrcweir return false; 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir // dispose used storage to free resources 177*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xStep2TempStorage ) ) 178*cdf0e10cSrcweir return false; 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir // ================================================ 182*cdf0e10cSrcweir // now check all the written information 183*cdf0e10cSrcweir // and the raw stream contents 184*cdf0e10cSrcweir // ================================================ 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir // close the output part of the temporary stream 187*cdf0e10cSrcweir // the output part must present since we already wrote to the stream 188*cdf0e10cSrcweir if ( !m_aTestHelper.closeOutput( xTempFileStream ) ) 189*cdf0e10cSrcweir return false; 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir XInputStream xTempInStream = m_aTestHelper.getInputStream( xTempFileStream ); 192*cdf0e10cSrcweir if ( xTempInStream == null ) 193*cdf0e10cSrcweir return false; 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir // open input stream 196*cdf0e10cSrcweir // since no mode is provided the result storage must be opened readonly 197*cdf0e10cSrcweir Object pOneArg[] = new Object[1]; 198*cdf0e10cSrcweir pOneArg[0] = (Object) xTempInStream; 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pOneArg ); 201*cdf0e10cSrcweir XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage ); 202*cdf0e10cSrcweir if ( xResultStorage == null ) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir m_aTestHelper.Error( "Can't open storage based on input stream!" ); 205*cdf0e10cSrcweir return false; 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType1", true, ElementModes.READ ) ) 209*cdf0e10cSrcweir return false; 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir // open existing substorage 212*cdf0e10cSrcweir XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage, 213*cdf0e10cSrcweir "SubStorage1", 214*cdf0e10cSrcweir ElementModes.READ ); 215*cdf0e10cSrcweir if ( xResultSubStorage == null ) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir m_aTestHelper.Error( "Can't open existing substorage!" ); 218*cdf0e10cSrcweir return false; 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType2", false, ElementModes.READ ) ) 222*cdf0e10cSrcweir return false; 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir // open existing substorage 225*cdf0e10cSrcweir XStorage xResultSubSubStorage = m_aTestHelper.openSubStorage( xResultSubStorage, 226*cdf0e10cSrcweir "SubStorage2", 227*cdf0e10cSrcweir ElementModes.READ ); 228*cdf0e10cSrcweir if ( xResultSubSubStorage == null ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir m_aTestHelper.Error( "Can't open existing substorage!" ); 231*cdf0e10cSrcweir return false; 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir if ( !m_aTestHelper.checkStorageProperties( xResultSubSubStorage, "MediaType3", false, ElementModes.READ ) ) 235*cdf0e10cSrcweir return false; 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir if ( !m_aTestHelper.checkStream( xResultSubSubStorage, "SubStream1", "MediaType4", true, pBytes ) ) 238*cdf0e10cSrcweir return false; 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir XStorage xResultSubStorage1 = m_aTestHelper.openSubStorage( xResultStorage, 243*cdf0e10cSrcweir "SubStorage3", 244*cdf0e10cSrcweir ElementModes.READ ); 245*cdf0e10cSrcweir if ( xResultSubStorage1 == null ) 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir m_aTestHelper.Error( "Can't open existing substorage!" ); 248*cdf0e10cSrcweir return false; 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage1, "MediaType5", false, ElementModes.READ ) ) 252*cdf0e10cSrcweir return false; 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir if ( !m_aTestHelper.checkStream( xResultSubStorage1, "SubStream2", "MediaType4", false, pBytes ) ) 255*cdf0e10cSrcweir return false; 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir // dispose used storages to free resources 259*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xResultStorage ) ) 260*cdf0e10cSrcweir return false; 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir return true; 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir catch( Exception e ) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir m_aTestHelper.Error( "Exception: " + e ); 267*cdf0e10cSrcweir return false; 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir 273