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_i30677 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_i30677( 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_i30677: " ); 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 // open a new substorage 54*cdf0e10cSrcweir XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, 55*cdf0e10cSrcweir "SubStorage1", 56*cdf0e10cSrcweir ElementModes.WRITE ); 57*cdf0e10cSrcweir if ( xTempSubStorage == null ) 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 60*cdf0e10cSrcweir return false; 61*cdf0e10cSrcweir } 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir // open a new subsubstorage 64*cdf0e10cSrcweir XStorage xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage, 65*cdf0e10cSrcweir "SubSubStorage1", 66*cdf0e10cSrcweir ElementModes.WRITE ); 67*cdf0e10cSrcweir if ( xTempSubSubStorage == null ) 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 70*cdf0e10cSrcweir return false; 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir byte pBytes1[] = { 1, 1, 1, 1, 1 }; 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes 76*cdf0e10cSrcweir if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubSubStorage, "SubSubStream1", "MediaType1", true, pBytes1 ) ) 77*cdf0e10cSrcweir return false; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly 80*cdf0e10cSrcweir if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage, 81*cdf0e10cSrcweir "MediaType2", 82*cdf0e10cSrcweir true, 83*cdf0e10cSrcweir ElementModes.WRITE ) ) 84*cdf0e10cSrcweir return false; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly 87*cdf0e10cSrcweir if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage, 88*cdf0e10cSrcweir "MediaType3", 89*cdf0e10cSrcweir false, 90*cdf0e10cSrcweir ElementModes.WRITE ) ) 91*cdf0e10cSrcweir return false; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly 94*cdf0e10cSrcweir if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubSubStorage, 95*cdf0e10cSrcweir "MediaType4", 96*cdf0e10cSrcweir false, 97*cdf0e10cSrcweir ElementModes.WRITE ) ) 98*cdf0e10cSrcweir return false; 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir // ================================================ 101*cdf0e10cSrcweir // commit the storages 102*cdf0e10cSrcweir // ================================================ 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir // commit lowlevel substorage first 105*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) ) 106*cdf0e10cSrcweir return false; 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir // commit substorage 109*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) 110*cdf0e10cSrcweir return false; 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir // commit substorage to let the renaming take place 113*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xTempStorage ) ) 114*cdf0e10cSrcweir return false; 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir // ================================================ 117*cdf0e10cSrcweir // dispose the storages 118*cdf0e10cSrcweir // ================================================ 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir // dispose lowerest substorage 121*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xTempSubSubStorage ) ) 122*cdf0e10cSrcweir return false; 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir // dispose substorage 125*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) ) 126*cdf0e10cSrcweir return false; 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir // dispose the temporary storage 129*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) 130*cdf0e10cSrcweir return false; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir // ================================================ 133*cdf0e10cSrcweir // reopen the storage and rewrite the stream 134*cdf0e10cSrcweir // ================================================ 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); 137*cdf0e10cSrcweir xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); 138*cdf0e10cSrcweir if ( xTempStorage == null ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create temporary storage representation!" ); 141*cdf0e10cSrcweir return false; 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir // open the substorages 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, 147*cdf0e10cSrcweir "SubStorage1", 148*cdf0e10cSrcweir ElementModes.WRITE ); 149*cdf0e10cSrcweir if ( xTempSubStorage == null ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 152*cdf0e10cSrcweir return false; 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir // open the lowlevel substorages 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage, 158*cdf0e10cSrcweir "SubSubStorage1", 159*cdf0e10cSrcweir ElementModes.WRITE ); 160*cdf0e10cSrcweir if ( xTempSubSubStorage == null ) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 163*cdf0e10cSrcweir return false; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir byte pBytes2[] = { 2, 2, 2, 2, 2 }; 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes 169*cdf0e10cSrcweir if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubSubStorage, "SubSubStream1", "MediaType1", true, pBytes2 ) ) 170*cdf0e10cSrcweir return false; 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir // ================================================ 173*cdf0e10cSrcweir // commit the storages 174*cdf0e10cSrcweir // ================================================ 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir // commit lowlevel substorage first 177*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xTempSubSubStorage ) ) 178*cdf0e10cSrcweir return false; 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir // commit substorage 181*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) 182*cdf0e10cSrcweir return false; 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir // commit substorage to let the renaming take place 185*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xTempStorage ) ) 186*cdf0e10cSrcweir return false; 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir // ================================================ 189*cdf0e10cSrcweir // dispose the storages 190*cdf0e10cSrcweir // ================================================ 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir // dispose lowerest substorage 193*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xTempSubSubStorage ) ) 194*cdf0e10cSrcweir return false; 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir // dispose substorage 197*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) ) 198*cdf0e10cSrcweir return false; 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir // dispose the temporary storage 201*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) 202*cdf0e10cSrcweir return false; 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir // ================================================ 205*cdf0e10cSrcweir // reopen the storages and check the contents 206*cdf0e10cSrcweir // ================================================ 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir pArgs[1] = new Integer( ElementModes.READ ); 209*cdf0e10cSrcweir oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); 210*cdf0e10cSrcweir xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); 211*cdf0e10cSrcweir if ( xTempStorage == null ) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create temporary storage representation!" ); 214*cdf0e10cSrcweir return false; 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir // open the substorages 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, 220*cdf0e10cSrcweir "SubStorage1", 221*cdf0e10cSrcweir ElementModes.READ ); 222*cdf0e10cSrcweir if ( xTempSubStorage == null ) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 225*cdf0e10cSrcweir return false; 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir // open the lowlevel substorages 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir xTempSubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage, 231*cdf0e10cSrcweir "SubSubStorage1", 232*cdf0e10cSrcweir ElementModes.READ ); 233*cdf0e10cSrcweir if ( xTempSubSubStorage == null ) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 236*cdf0e10cSrcweir return false; 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir if ( !m_aTestHelper.checkStorageProperties( xTempSubSubStorage, "MediaType4", false, ElementModes.READ ) ) 240*cdf0e10cSrcweir return false; 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage, "MediaType3", false, ElementModes.READ ) ) 243*cdf0e10cSrcweir return false; 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir if ( !m_aTestHelper.checkStorageProperties( xTempStorage, "MediaType2", true, ElementModes.READ ) ) 246*cdf0e10cSrcweir return false; 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir if ( !m_aTestHelper.checkStream( xTempSubSubStorage, "SubSubStream1", "MediaType1", true, pBytes2 ) ) 249*cdf0e10cSrcweir return false; 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir // the root storage is based on the temporary stream so it can be left undisposed, since it does not lock 252*cdf0e10cSrcweir // any resource, later the garbage collector will release the object and it must die by refcount 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir return true; 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir catch( Exception e ) 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir m_aTestHelper.Error( "Exception: " + e ); 259*cdf0e10cSrcweir return false; 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264