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 import com.sun.star.beans.XPropertySet; 13*cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 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 21*cdf0e10cSrcweir /////////////////////////////////// 22*cdf0e10cSrcweir // Tests also fix for i51352 23*cdf0e10cSrcweir /////////////////////////////////// 24*cdf0e10cSrcweir 25*cdf0e10cSrcweir public class RegressionTest_i27773 implements StorageTest { 26*cdf0e10cSrcweir 27*cdf0e10cSrcweir XMultiServiceFactory m_xMSF; 28*cdf0e10cSrcweir XSingleServiceFactory m_xStorageFactory; 29*cdf0e10cSrcweir TestHelper m_aTestHelper; 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir public RegressionTest_i27773( 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_i27773: " ); 36*cdf0e10cSrcweir } 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir public boolean test() 39*cdf0e10cSrcweir { 40*cdf0e10cSrcweir try 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF ); 43*cdf0e10cSrcweir if ( xTempFileStream == null ) 44*cdf0e10cSrcweir return false; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir if ( true ) 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir // for debugging proposes 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xTempFileStream ); 51*cdf0e10cSrcweir if ( xPropSet != null ) 52*cdf0e10cSrcweir { 53*cdf0e10cSrcweir try 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir String sTempURL = AnyConverter.toString( xPropSet.getPropertyValue( "Uri" ) ); 56*cdf0e10cSrcweir // m_aTestHelper.Message( "URL: " + sTempURL ); 57*cdf0e10cSrcweir xPropSet.setPropertyValue( "RemoveFile", new Boolean( false ) ); 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir catch ( Exception e ) 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir } 62*cdf0e10cSrcweir } 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) xTempFileStream; 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 // open a new substorage 79*cdf0e10cSrcweir XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, 80*cdf0e10cSrcweir "SubStorage1", 81*cdf0e10cSrcweir ElementModes.WRITE ); 82*cdf0e10cSrcweir if ( xTempSubStorage == null ) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 85*cdf0e10cSrcweir return false; 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir // open an empty substorage 89*cdf0e10cSrcweir XStorage xEmptySubStorage = m_aTestHelper.openSubStorage( xTempStorage, 90*cdf0e10cSrcweir "EmptySubStorage1", 91*cdf0e10cSrcweir ElementModes.WRITE ); 92*cdf0e10cSrcweir if ( xEmptySubStorage == null ) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 95*cdf0e10cSrcweir return false; 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir // open an empty substorage 99*cdf0e10cSrcweir XStorage xEmptySubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage, 100*cdf0e10cSrcweir "EmptySubSubStorage1", 101*cdf0e10cSrcweir ElementModes.WRITE ); 102*cdf0e10cSrcweir if ( xEmptySubSubStorage == null ) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 105*cdf0e10cSrcweir return false; 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir byte pBytes1[] = { 1, 1, 1, 1, 1 }; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes 112*cdf0e10cSrcweir if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) ) 113*cdf0e10cSrcweir return false; 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly 116*cdf0e10cSrcweir if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage, 117*cdf0e10cSrcweir "MediaType2", 118*cdf0e10cSrcweir true, 119*cdf0e10cSrcweir ElementModes.WRITE ) ) 120*cdf0e10cSrcweir return false; 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly 123*cdf0e10cSrcweir if ( !m_aTestHelper.setStorageTypeAndCheckProps( xEmptySubStorage, 124*cdf0e10cSrcweir "MediaType3", 125*cdf0e10cSrcweir false, 126*cdf0e10cSrcweir ElementModes.WRITE ) ) 127*cdf0e10cSrcweir return false; 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly 130*cdf0e10cSrcweir if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage, 131*cdf0e10cSrcweir "MediaType4", 132*cdf0e10cSrcweir false, 133*cdf0e10cSrcweir ElementModes.WRITE ) ) 134*cdf0e10cSrcweir return false; 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir // set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly 137*cdf0e10cSrcweir if ( !m_aTestHelper.setStorageTypeAndCheckProps( xEmptySubSubStorage, 138*cdf0e10cSrcweir "MediaType5", 139*cdf0e10cSrcweir false, 140*cdf0e10cSrcweir ElementModes.WRITE ) ) 141*cdf0e10cSrcweir return false; 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir // make a copy of substorage 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir if ( !m_aTestHelper.copyElementTo( xTempStorage, "SubStorage1", xTempStorage, "SubStorage1_copy" ) ) 147*cdf0e10cSrcweir return false; 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir if ( !m_aTestHelper.copyElementTo( xTempStorage, "EmptySubStorage1", xTempStorage, "EmptySubStorage1_copy" ) ) 150*cdf0e10cSrcweir return false; 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir // ================================================ 153*cdf0e10cSrcweir // copy all the changed and noncommited substorages 154*cdf0e10cSrcweir // and dispose them 155*cdf0e10cSrcweir // ================================================ 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xEmptySubSubStorage ) ) 158*cdf0e10cSrcweir return false; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) 161*cdf0e10cSrcweir return false; 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xEmptySubStorage ) ) 164*cdf0e10cSrcweir return false; 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xTempStorage ) ) 167*cdf0e10cSrcweir return false; 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir // dispose substorages 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xEmptySubSubStorage ) ) 172*cdf0e10cSrcweir return false; 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) ) 175*cdf0e10cSrcweir return false; 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xEmptySubStorage ) ) 178*cdf0e10cSrcweir return false; 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) 181*cdf0e10cSrcweir return false; 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir // ================================================ 184*cdf0e10cSrcweir // reopen the storage in readonly mode an check contents 185*cdf0e10cSrcweir // ================================================ 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir pArgs[1] = new Integer( ElementModes.READ ); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); 190*cdf0e10cSrcweir xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); 191*cdf0e10cSrcweir if ( xTempStorage == null ) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create temporary storage representation!" ); 194*cdf0e10cSrcweir return false; 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir // open original substorage 198*cdf0e10cSrcweir xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, 199*cdf0e10cSrcweir "SubStorage1", 200*cdf0e10cSrcweir ElementModes.READ ); 201*cdf0e10cSrcweir if ( xTempSubStorage == null ) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 204*cdf0e10cSrcweir return false; 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir // open copy of the original substorage 208*cdf0e10cSrcweir XStorage xTempSubStorage_copy = m_aTestHelper.openSubStorage( xTempStorage, 209*cdf0e10cSrcweir "SubStorage1_copy", 210*cdf0e10cSrcweir ElementModes.READ ); 211*cdf0e10cSrcweir if ( xTempSubStorage_copy == null ) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 214*cdf0e10cSrcweir return false; 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir // open empty substorage 218*cdf0e10cSrcweir xEmptySubStorage = m_aTestHelper.openSubStorage( xTempStorage, 219*cdf0e10cSrcweir "EmptySubStorage1", 220*cdf0e10cSrcweir ElementModes.READ ); 221*cdf0e10cSrcweir if ( xEmptySubStorage == null ) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 224*cdf0e10cSrcweir return false; 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir // open copy of empty substorage 228*cdf0e10cSrcweir XStorage xEmptySubStorage_copy = m_aTestHelper.openSubStorage( xTempStorage, 229*cdf0e10cSrcweir "EmptySubStorage1_copy", 230*cdf0e10cSrcweir ElementModes.READ ); 231*cdf0e10cSrcweir if ( xEmptySubStorage_copy == null ) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 234*cdf0e10cSrcweir return false; 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir // open an empty substorage of the substorage 238*cdf0e10cSrcweir xEmptySubSubStorage = m_aTestHelper.openSubStorage( xTempSubStorage, 239*cdf0e10cSrcweir "EmptySubSubStorage1", 240*cdf0e10cSrcweir ElementModes.READ ); 241*cdf0e10cSrcweir if ( xEmptySubSubStorage == null ) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 244*cdf0e10cSrcweir return false; 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir // open an empty substorage of the substorage copy 248*cdf0e10cSrcweir XStorage xEmptySubSubStorage_inCopy = m_aTestHelper.openSubStorage( xTempSubStorage_copy, 249*cdf0e10cSrcweir "EmptySubSubStorage1", 250*cdf0e10cSrcweir ElementModes.READ ); 251*cdf0e10cSrcweir if ( xEmptySubSubStorage_inCopy == null ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 254*cdf0e10cSrcweir return false; 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir // check contents 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir if ( !m_aTestHelper.checkStorageProperties( xEmptySubSubStorage, "MediaType5", false, ElementModes.READ ) ) 261*cdf0e10cSrcweir return false; 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir if ( !m_aTestHelper.checkStorageProperties( xEmptySubSubStorage_inCopy, "MediaType5", false, ElementModes.READ ) ) 264*cdf0e10cSrcweir return false; 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage, "MediaType4", false, ElementModes.READ ) ) 267*cdf0e10cSrcweir return false; 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir if ( !m_aTestHelper.checkStorageProperties( xTempSubStorage_copy, "MediaType4", false, ElementModes.READ ) ) 270*cdf0e10cSrcweir return false; 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir if ( !m_aTestHelper.checkStorageProperties( xEmptySubStorage, "MediaType3", false, ElementModes.READ ) ) 273*cdf0e10cSrcweir return false; 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir if ( !m_aTestHelper.checkStorageProperties( xEmptySubStorage_copy, "MediaType3", false, ElementModes.READ ) ) 276*cdf0e10cSrcweir return false; 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir if ( !m_aTestHelper.checkStorageProperties( xTempStorage, "MediaType2", true, ElementModes.READ ) ) 279*cdf0e10cSrcweir return false; 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir if ( !m_aTestHelper.checkStream( xTempSubStorage, "SubStream1", "MediaType1", true, pBytes1 ) ) 282*cdf0e10cSrcweir return false; 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir if ( !m_aTestHelper.checkStream( xTempSubStorage_copy, "SubStream1", "MediaType1", true, pBytes1 ) ) 285*cdf0e10cSrcweir return false; 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir // the root storage is based on the temporary stream so it can be left undisposed, since it does not lock 288*cdf0e10cSrcweir // any resource, later the garbage collector will release the object and it must die by refcount 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir return true; 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir catch( Exception e ) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir m_aTestHelper.Error( "Exception: " + e ); 295*cdf0e10cSrcweir return false; 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir 300