1*cdf0e10cSrcweir package storagetesting; 2*cdf0e10cSrcweir 3*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 4*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 5*cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 6*cdf0e10cSrcweir 7*cdf0e10cSrcweir import com.sun.star.lang.*; 8*cdf0e10cSrcweir import com.sun.star.embed.*; 9*cdf0e10cSrcweir import com.sun.star.packages.*; 10*cdf0e10cSrcweir import com.sun.star.io.*; 11*cdf0e10cSrcweir import com.sun.star.beans.*; 12*cdf0e10cSrcweir 13*cdf0e10cSrcweir public class TestHelper { 14*cdf0e10cSrcweir 15*cdf0e10cSrcweir String m_sTestPrefix; 16*cdf0e10cSrcweir 17*cdf0e10cSrcweir public TestHelper( String sTestPrefix ) 18*cdf0e10cSrcweir { 19*cdf0e10cSrcweir m_sTestPrefix = sTestPrefix; 20*cdf0e10cSrcweir } 21*cdf0e10cSrcweir 22*cdf0e10cSrcweir public boolean WriteBytesToStream( XStream xStream, 23*cdf0e10cSrcweir String sStreamName, 24*cdf0e10cSrcweir String sMediaType, 25*cdf0e10cSrcweir boolean bCompressed, 26*cdf0e10cSrcweir byte[] pBytes ) 27*cdf0e10cSrcweir { 28*cdf0e10cSrcweir // get output stream of substream 29*cdf0e10cSrcweir XOutputStream xOutput = xStream.getOutputStream(); 30*cdf0e10cSrcweir if ( xOutput == null ) 31*cdf0e10cSrcweir { 32*cdf0e10cSrcweir Error( "Can't get XOutputStream implementation from substream '" + sStreamName + "'!" ); 33*cdf0e10cSrcweir return false; 34*cdf0e10cSrcweir } 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir // get XTrucate implementation from output stream 37*cdf0e10cSrcweir XTruncate xTruncate = (XTruncate) UnoRuntime.queryInterface( XTruncate.class, xOutput ); 38*cdf0e10cSrcweir if ( xTruncate == null ) 39*cdf0e10cSrcweir { 40*cdf0e10cSrcweir Error( "Can't get XTruncate implementation from substream '" + sStreamName + "'!" ); 41*cdf0e10cSrcweir return false; 42*cdf0e10cSrcweir } 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir // write requested byte sequence 45*cdf0e10cSrcweir try 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir xTruncate.truncate(); 48*cdf0e10cSrcweir xOutput.writeBytes( pBytes ); 49*cdf0e10cSrcweir } 50*cdf0e10cSrcweir catch( Exception e ) 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir Error( "Can't write to stream '" + sStreamName + "', exception: " + e ); 53*cdf0e10cSrcweir return false; 54*cdf0e10cSrcweir } 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir // get access to the XPropertySet interface 57*cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStream ); 58*cdf0e10cSrcweir if ( xPropSet == null ) 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir Error( "Can't get XPropertySet implementation from substream '" + sStreamName + "'!" ); 61*cdf0e10cSrcweir return false; 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir // set properties to the stream 65*cdf0e10cSrcweir try 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir xPropSet.setPropertyValue( "MediaType", sMediaType ); 68*cdf0e10cSrcweir xPropSet.setPropertyValue( "Compressed", new Boolean( bCompressed ) ); 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir catch( Exception e ) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir Error( "Can't set properties to substream '" + sStreamName + "', exception: " + e ); 73*cdf0e10cSrcweir return false; 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir // check size property of the stream 77*cdf0e10cSrcweir try 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir int nSize = AnyConverter.toInt( xPropSet.getPropertyValue( "Size" ) ); 80*cdf0e10cSrcweir if ( nSize != pBytes.length ) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir Error( "The 'Size' property of substream '" + sStreamName + "' contains wrong value!" ); 83*cdf0e10cSrcweir return false; 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir catch( Exception e ) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir Error( "Can't get 'Size' property from substream '" + sStreamName + "', exception: " + e ); 89*cdf0e10cSrcweir return false; 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir // free the stream resources, garbage collector may remove the object too late 93*cdf0e10cSrcweir XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xStream ); 94*cdf0e10cSrcweir if ( xComponent == null ) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir Error( "Can't get XComponent implementation from substream '" + sStreamName + "'!" ); 97*cdf0e10cSrcweir return false; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir xComponent.dispose(); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir return true; 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir public boolean WriteBytesToSubstream( XStorage xStorage, 106*cdf0e10cSrcweir String sStreamName, 107*cdf0e10cSrcweir String sMediaType, 108*cdf0e10cSrcweir boolean bCompressed, 109*cdf0e10cSrcweir byte[] pBytes ) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir // open substream element 112*cdf0e10cSrcweir XStream xSubStream = null; 113*cdf0e10cSrcweir try 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir Object oSubStream = xStorage.openStreamElement( sStreamName, ElementModes.ELEMENT_WRITE ); 116*cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 117*cdf0e10cSrcweir if ( xSubStream == null ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "'!" ); 120*cdf0e10cSrcweir return false; 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir catch( Exception e ) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" ); 126*cdf0e10cSrcweir return false; 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir return WriteBytesToStream( xSubStream, sStreamName, sMediaType, bCompressed, pBytes ); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir public boolean WriteBytesToEncrSubstream( XStorage xStorage, 133*cdf0e10cSrcweir String sStreamName, 134*cdf0e10cSrcweir String sMediaType, 135*cdf0e10cSrcweir boolean bCompressed, 136*cdf0e10cSrcweir byte[] pBytes, 137*cdf0e10cSrcweir byte[] pPass ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir // open substream element 140*cdf0e10cSrcweir XStream xSubStream = null; 141*cdf0e10cSrcweir try 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir Object oSubStream = xStorage.openEncryptedStreamElement( sStreamName, ElementModes.ELEMENT_WRITE, pPass ); 144*cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 145*cdf0e10cSrcweir if ( xSubStream == null ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "'!" ); 148*cdf0e10cSrcweir return false; 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir catch( Exception e ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" ); 154*cdf0e10cSrcweir return false; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir return WriteBytesToStream( xSubStream, sStreamName, sMediaType, bCompressed, pBytes ); 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir public boolean WBToSubstrOfEncr( XStorage xStorage, 161*cdf0e10cSrcweir String sStreamName, 162*cdf0e10cSrcweir String sMediaType, 163*cdf0e10cSrcweir boolean bCompressed, 164*cdf0e10cSrcweir byte[] pBytes, 165*cdf0e10cSrcweir boolean bEncrypted ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir // open substream element 168*cdf0e10cSrcweir XStream xSubStream = null; 169*cdf0e10cSrcweir try 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir Object oSubStream = xStorage.openStreamElement( sStreamName, ElementModes.ELEMENT_WRITE ); 172*cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 173*cdf0e10cSrcweir if ( xSubStream == null ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "'!" ); 176*cdf0e10cSrcweir return false; 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir catch( Exception e ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" ); 182*cdf0e10cSrcweir return false; 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir // get access to the XPropertySet interface 186*cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xSubStream ); 187*cdf0e10cSrcweir if ( xPropSet == null ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir Error( "Can't get XPropertySet implementation from substream '" + sStreamName + "'!" ); 190*cdf0e10cSrcweir return false; 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir // set properties to the stream 194*cdf0e10cSrcweir try 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir xPropSet.setPropertyValue( "Encrypted", new Boolean( bEncrypted ) ); 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir catch( Exception e ) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir Error( "Can't set 'Encrypted' property to substream '" + sStreamName + "', exception: " + e ); 201*cdf0e10cSrcweir return false; 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir return WriteBytesToStream( xSubStream, sStreamName, sMediaType, bCompressed, pBytes ); 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir public int ChangeStreamPass( XStorage xStorage, 208*cdf0e10cSrcweir String sStreamName, 209*cdf0e10cSrcweir byte[] pOldPass, 210*cdf0e10cSrcweir byte[] pNewPass ) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir // open substream element 213*cdf0e10cSrcweir XStream xSubStream = null; 214*cdf0e10cSrcweir try 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir Object oSubStream = xStorage.openEncryptedStreamElement( sStreamName, ElementModes.ELEMENT_WRITE, pOldPass ); 217*cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 218*cdf0e10cSrcweir if ( xSubStream == null ) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir Error( "Can't open substream '" + sStreamName + "'!" ); 221*cdf0e10cSrcweir return 0; 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir catch( Exception e ) 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir Error( "Can't open substream '" + sStreamName + "', exception : " + e + "!" ); 227*cdf0e10cSrcweir return 0; 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir // change the password for the stream 232*cdf0e10cSrcweir XEncryptionProtectedSource xStreamEncryption = 233*cdf0e10cSrcweir (XEncryptionProtectedSource) UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xSubStream ); 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir if ( xStreamEncryption == null ) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir Message( "Optional interface XEncryptionProtectedSource is not implemented, feature can not be tested!" ); 238*cdf0e10cSrcweir return -1; 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir try { 242*cdf0e10cSrcweir xStreamEncryption.setEncryptionKey( pNewPass ); 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir catch( Exception e ) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir Error( "Can't change encryption key of the substream '" + sStreamName + "', exception:" + e ); 247*cdf0e10cSrcweir return 0; 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir // free the stream resources, garbage collector may remove the object too late 251*cdf0e10cSrcweir XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xSubStream ); 252*cdf0e10cSrcweir if ( xComponent == null ) 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir Error( "Can't get XComponent implementation from substream '" + sStreamName + "'!" ); 255*cdf0e10cSrcweir return 0; 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir xComponent.dispose(); 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir return 1; 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir public boolean setStorageTypeAndCheckProps( XStorage xStorage, String sMediaType, boolean bIsRoot, int nMode ) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir boolean bOk = false; 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir // get access to the XPropertySet interface 267*cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStorage ); 268*cdf0e10cSrcweir if ( xPropSet != null ) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir try 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir // set "MediaType" property to the stream 273*cdf0e10cSrcweir xPropSet.setPropertyValue( "MediaType", sMediaType ); 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir // get "IsRoot" and "OpenMode" properties and control there values 276*cdf0e10cSrcweir boolean bPropIsRoot = AnyConverter.toBoolean( xPropSet.getPropertyValue( "IsRoot" ) ); 277*cdf0e10cSrcweir int nPropMode = AnyConverter.toInt( xPropSet.getPropertyValue( "OpenMode" ) ); 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir bOk = true; 280*cdf0e10cSrcweir if ( bPropIsRoot != bIsRoot ) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir Error( "'IsRoot' property contains wrong value!" ); 283*cdf0e10cSrcweir bOk = false; 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir if ( ( bIsRoot && ( nPropMode | ElementModes.ELEMENT_READ ) != ( nMode | ElementModes.ELEMENT_READ ) ) 287*cdf0e10cSrcweir || ( !bIsRoot && ( nPropMode & nMode ) != nMode ) ) 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir Error( "'OpenMode' property contains wrong value!" ); 290*cdf0e10cSrcweir bOk = false; 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir catch( Exception e ) 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir Error( "Can't control properties of substorage, exception: " + e ); 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir else 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir Error( "Can't get XPropertySet implementation from storage!" ); 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir return bOk; 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir public boolean checkStorageProperties( XStorage xStorage, String sMediaType, boolean bIsRoot, int nMode ) 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir boolean bOk = false; 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir // get access to the XPropertySet interface 311*cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStorage ); 312*cdf0e10cSrcweir if ( xPropSet != null ) 313*cdf0e10cSrcweir { 314*cdf0e10cSrcweir try 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir // get "MediaType", "IsRoot" and "OpenMode" properties and control there values 317*cdf0e10cSrcweir String sPropMediaType = AnyConverter.toString( xPropSet.getPropertyValue( "MediaType" ) ); 318*cdf0e10cSrcweir boolean bPropIsRoot = AnyConverter.toBoolean( xPropSet.getPropertyValue( "IsRoot" ) ); 319*cdf0e10cSrcweir int nPropMode = AnyConverter.toInt( xPropSet.getPropertyValue( "OpenMode" ) ); 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir bOk = true; 322*cdf0e10cSrcweir if ( !sPropMediaType.equals( sMediaType ) ) 323*cdf0e10cSrcweir { 324*cdf0e10cSrcweir Error( "'MediaType' property contains wrong value, expected '" 325*cdf0e10cSrcweir + sMediaType + "', set '" + sPropMediaType + "' !" ); 326*cdf0e10cSrcweir bOk = false; 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir if ( bPropIsRoot != bIsRoot ) 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir Error( "'IsRoot' property contains wrong value!" ); 332*cdf0e10cSrcweir bOk = false; 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir if ( ( bIsRoot && ( nPropMode | ElementModes.ELEMENT_READ ) != ( nMode | ElementModes.ELEMENT_READ ) ) 336*cdf0e10cSrcweir || ( !bIsRoot && ( nPropMode & nMode ) != nMode ) ) 337*cdf0e10cSrcweir { 338*cdf0e10cSrcweir Error( "'OpenMode' property contains wrong value!" ); 339*cdf0e10cSrcweir bOk = false; 340*cdf0e10cSrcweir } 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir catch( Exception e ) 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir Error( "Can't get properties of substorage, exception: " + e ); 345*cdf0e10cSrcweir } 346*cdf0e10cSrcweir } 347*cdf0e10cSrcweir else 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir Error( "Can't get XPropertySet implementation from storage!" ); 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir return bOk; 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir public boolean InternalCheckStream( XStream xStream, 356*cdf0e10cSrcweir String sName, 357*cdf0e10cSrcweir String sMediaType, 358*cdf0e10cSrcweir byte[] pBytes ) 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir // get input stream of substream 361*cdf0e10cSrcweir XInputStream xInput = xStream.getInputStream(); 362*cdf0e10cSrcweir if ( xInput == null ) 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir Error( "Can't get XInputStream implementation from substream '" + sName + "'!" ); 365*cdf0e10cSrcweir return false; 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir byte pContents[][] = new byte[1][]; // ??? 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir // read contents 371*cdf0e10cSrcweir try 372*cdf0e10cSrcweir { 373*cdf0e10cSrcweir xInput.readBytes( pContents, pBytes.length + 1 ); 374*cdf0e10cSrcweir } 375*cdf0e10cSrcweir catch( Exception e ) 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir Error( "Can't read from stream '" + sName + "', exception: " + e ); 378*cdf0e10cSrcweir return false; 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir // check size of stream data 382*cdf0e10cSrcweir if ( pContents.length == 0 ) 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir Error( "SubStream '" + sName + "' reading produced disaster!" ); 385*cdf0e10cSrcweir return false; 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir if ( pBytes.length != pContents[0].length ) 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir Error( "SubStream '" + sName + "' contains wrong amount of data! (" + pContents[0].length + "/" + pBytes.length + ")" ); 391*cdf0e10cSrcweir return false; 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir // check stream data 395*cdf0e10cSrcweir for ( int ind = 0; ind < pBytes.length; ind++ ) 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir if ( pBytes[ind] != pContents[0][ind] ) 398*cdf0e10cSrcweir { 399*cdf0e10cSrcweir Error( "SubStream '" + sName + "' contains wrong data!" ); 400*cdf0e10cSrcweir return false; 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir // check properties 406*cdf0e10cSrcweir boolean bOk = false; 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir // get access to the XPropertySet interface 409*cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStream ); 410*cdf0e10cSrcweir if ( xPropSet != null ) 411*cdf0e10cSrcweir { 412*cdf0e10cSrcweir try 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir // get "MediaType" and "Size" properties and control there values 415*cdf0e10cSrcweir String sPropMediaType = AnyConverter.toString( xPropSet.getPropertyValue( "MediaType" ) ); 416*cdf0e10cSrcweir int nPropSize = AnyConverter.toInt( xPropSet.getPropertyValue( "Size" ) ); 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir bOk = true; 419*cdf0e10cSrcweir if ( !sPropMediaType.equals( sMediaType ) ) 420*cdf0e10cSrcweir { 421*cdf0e10cSrcweir Error( "'MediaType' property contains wrong value for stream '" + sName + "',\nexpected: '" 422*cdf0e10cSrcweir + sMediaType + "', set: '" + sPropMediaType + "'!" ); 423*cdf0e10cSrcweir bOk = false; 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir if ( nPropSize != pBytes.length ) 427*cdf0e10cSrcweir { 428*cdf0e10cSrcweir Error( "'Size' property contains wrong value for stream'" + sName + "'!" ); 429*cdf0e10cSrcweir bOk = false; 430*cdf0e10cSrcweir } 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir catch( Exception e ) 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir Error( "Can't get properties of substream '" + sName + "', exception: " + e ); 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir } 437*cdf0e10cSrcweir else 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir Error( "Can't get XPropertySet implementation from stream '" + sName + "'!" ); 440*cdf0e10cSrcweir } 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir return bOk; 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir 445*cdf0e10cSrcweir public boolean checkStream( XStorage xParentStorage, 446*cdf0e10cSrcweir String sName, 447*cdf0e10cSrcweir String sMediaType, 448*cdf0e10cSrcweir byte[] pBytes ) 449*cdf0e10cSrcweir { 450*cdf0e10cSrcweir // open substream element first 451*cdf0e10cSrcweir XStream xSubStream = null; 452*cdf0e10cSrcweir try 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir Object oSubStream = xParentStorage.openStreamElement( sName, ElementModes.ELEMENT_READ ); 455*cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 456*cdf0e10cSrcweir if ( xSubStream == null ) 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir Error( "Can't open substream '" + sName + "'!" ); 459*cdf0e10cSrcweir return false; 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir } 462*cdf0e10cSrcweir catch( Exception e ) 463*cdf0e10cSrcweir { 464*cdf0e10cSrcweir Error( "Can't open substream '" + sName + "', exception : " + e + "!" ); 465*cdf0e10cSrcweir return false; 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir return InternalCheckStream( xSubStream, sName, sMediaType, pBytes ); 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir public boolean checkEncrStream( XStorage xParentStorage, 472*cdf0e10cSrcweir String sName, 473*cdf0e10cSrcweir String sMediaType, 474*cdf0e10cSrcweir byte[] pBytes, 475*cdf0e10cSrcweir byte[] pPass ) 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir // Important: a common password for any of parent storage should not be set or 478*cdf0e10cSrcweir // should be different from pPass 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir if ( pPass.length == 0 ) 481*cdf0e10cSrcweir { 482*cdf0e10cSrcweir Error( "Wrong password is used in the test!" ); 483*cdf0e10cSrcweir return false; 484*cdf0e10cSrcweir } 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir try 487*cdf0e10cSrcweir { 488*cdf0e10cSrcweir Object oSubStream = xParentStorage.openStreamElement( sName, ElementModes.ELEMENT_READ ); 489*cdf0e10cSrcweir Error( "Encrypted stream '" + sName + "' was opened without password!" ); 490*cdf0e10cSrcweir return false; 491*cdf0e10cSrcweir } 492*cdf0e10cSrcweir catch( WrongPasswordException wpe ) 493*cdf0e10cSrcweir {} 494*cdf0e10cSrcweir catch( Exception e ) 495*cdf0e10cSrcweir { 496*cdf0e10cSrcweir Error( "Unexpected exception in case of opening of encrypted stream '" + sName + "' without password: " + e + "!" ); 497*cdf0e10cSrcweir return false; 498*cdf0e10cSrcweir } 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir byte pWrongPass[] = { 1, 1 }; 501*cdf0e10cSrcweir pWrongPass[0] += pPass[0]; 502*cdf0e10cSrcweir try 503*cdf0e10cSrcweir { 504*cdf0e10cSrcweir Object oSubStream = xParentStorage.openEncryptedStreamElement( sName, ElementModes.ELEMENT_READ, pWrongPass ); 505*cdf0e10cSrcweir Error( "Encrypted stream '" + sName + "' was opened with wrong password!" ); 506*cdf0e10cSrcweir return false; 507*cdf0e10cSrcweir } 508*cdf0e10cSrcweir catch( WrongPasswordException wpe ) 509*cdf0e10cSrcweir {} 510*cdf0e10cSrcweir catch( Exception e ) 511*cdf0e10cSrcweir { 512*cdf0e10cSrcweir Error( "Unexpected exception in case of opening of encrypted stream '" + sName + "' with wrong password: " + e + "!" ); 513*cdf0e10cSrcweir return false; 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir XStream xSubStream = null; 517*cdf0e10cSrcweir try 518*cdf0e10cSrcweir { 519*cdf0e10cSrcweir Object oSubStream = xParentStorage.openEncryptedStreamElement( sName, ElementModes.ELEMENT_READ, pPass ); 520*cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 521*cdf0e10cSrcweir if ( xSubStream == null ) 522*cdf0e10cSrcweir { 523*cdf0e10cSrcweir Error( "Can't open encrypted substream '" + sName + "'!" ); 524*cdf0e10cSrcweir return false; 525*cdf0e10cSrcweir } 526*cdf0e10cSrcweir } 527*cdf0e10cSrcweir catch( Exception e ) 528*cdf0e10cSrcweir { 529*cdf0e10cSrcweir Error( "Can't open encrypted substream '" + sName + "', exception : " + e + "!" ); 530*cdf0e10cSrcweir return false; 531*cdf0e10cSrcweir } 532*cdf0e10cSrcweir 533*cdf0e10cSrcweir return InternalCheckStream( xSubStream, sName, sMediaType, pBytes ); 534*cdf0e10cSrcweir } 535*cdf0e10cSrcweir 536*cdf0e10cSrcweir public boolean copyStorage( XStorage xSourceStorage, XStorage xDestStorage ) 537*cdf0e10cSrcweir { 538*cdf0e10cSrcweir // copy xSourceStorage to xDestStorage 539*cdf0e10cSrcweir try 540*cdf0e10cSrcweir { 541*cdf0e10cSrcweir xSourceStorage.copyToStorage( xDestStorage ); 542*cdf0e10cSrcweir } 543*cdf0e10cSrcweir catch( Exception e ) 544*cdf0e10cSrcweir { 545*cdf0e10cSrcweir Error( "Storage copying failed, exception: " + e ); 546*cdf0e10cSrcweir return false; 547*cdf0e10cSrcweir } 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir return true; 550*cdf0e10cSrcweir } 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir public boolean commitStorage( XStorage xStorage ) 553*cdf0e10cSrcweir { 554*cdf0e10cSrcweir // XTransactedObject must be supported by storages 555*cdf0e10cSrcweir XTransactedObject xTransact = (XTransactedObject) UnoRuntime.queryInterface( XTransactedObject.class, xStorage ); 556*cdf0e10cSrcweir if ( xTransact == null ) 557*cdf0e10cSrcweir { 558*cdf0e10cSrcweir Error( "Storage doesn't implement transacted access!" ); 559*cdf0e10cSrcweir return false; 560*cdf0e10cSrcweir } 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir try 563*cdf0e10cSrcweir { 564*cdf0e10cSrcweir xTransact.commit(); 565*cdf0e10cSrcweir } 566*cdf0e10cSrcweir catch( Exception e ) 567*cdf0e10cSrcweir { 568*cdf0e10cSrcweir Error( "Storage commit failed, exception:" + e ); 569*cdf0e10cSrcweir return false; 570*cdf0e10cSrcweir } 571*cdf0e10cSrcweir 572*cdf0e10cSrcweir return true; 573*cdf0e10cSrcweir } 574*cdf0e10cSrcweir 575*cdf0e10cSrcweir public boolean disposeStorage( XStorage xStorage ) 576*cdf0e10cSrcweir { 577*cdf0e10cSrcweir // dispose the storage 578*cdf0e10cSrcweir XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xStorage ); 579*cdf0e10cSrcweir if ( xComponent == null ) 580*cdf0e10cSrcweir { 581*cdf0e10cSrcweir Error( "Can't retrieve XComponent implementation from storage!" ); 582*cdf0e10cSrcweir return false; 583*cdf0e10cSrcweir } 584*cdf0e10cSrcweir 585*cdf0e10cSrcweir try 586*cdf0e10cSrcweir { 587*cdf0e10cSrcweir xComponent.dispose(); 588*cdf0e10cSrcweir } 589*cdf0e10cSrcweir catch( Exception e ) 590*cdf0e10cSrcweir { 591*cdf0e10cSrcweir Error( "Storage disposing failed!" ); 592*cdf0e10cSrcweir return false; 593*cdf0e10cSrcweir } 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir return true; 596*cdf0e10cSrcweir } 597*cdf0e10cSrcweir 598*cdf0e10cSrcweir public XInputStream getInputStream( XStream xStream ) 599*cdf0e10cSrcweir { 600*cdf0e10cSrcweir XInputStream xInTemp = null; 601*cdf0e10cSrcweir try 602*cdf0e10cSrcweir { 603*cdf0e10cSrcweir xInTemp = xStream.getInputStream(); 604*cdf0e10cSrcweir if ( xInTemp == null ) 605*cdf0e10cSrcweir Error( "Can't get the input part of a stream!" ); 606*cdf0e10cSrcweir } 607*cdf0e10cSrcweir catch ( Exception e ) 608*cdf0e10cSrcweir { 609*cdf0e10cSrcweir Error( "Can't get the input part of a stream, exception :" + e ); 610*cdf0e10cSrcweir } 611*cdf0e10cSrcweir 612*cdf0e10cSrcweir return xInTemp; 613*cdf0e10cSrcweir } 614*cdf0e10cSrcweir 615*cdf0e10cSrcweir public boolean closeOutput( XStream xStream ) 616*cdf0e10cSrcweir { 617*cdf0e10cSrcweir XOutputStream xOutTemp = null; 618*cdf0e10cSrcweir try 619*cdf0e10cSrcweir { 620*cdf0e10cSrcweir xOutTemp = xStream.getOutputStream(); 621*cdf0e10cSrcweir if ( xOutTemp == null ) 622*cdf0e10cSrcweir { 623*cdf0e10cSrcweir Error( "Can't get the output part of a stream!" ); 624*cdf0e10cSrcweir return false; 625*cdf0e10cSrcweir } 626*cdf0e10cSrcweir } 627*cdf0e10cSrcweir catch ( Exception e ) 628*cdf0e10cSrcweir { 629*cdf0e10cSrcweir Error( "Can't get the output part of a stream, exception :" + e ); 630*cdf0e10cSrcweir return false; 631*cdf0e10cSrcweir } 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir try 634*cdf0e10cSrcweir { 635*cdf0e10cSrcweir xOutTemp.closeOutput(); 636*cdf0e10cSrcweir } 637*cdf0e10cSrcweir catch ( Exception e ) 638*cdf0e10cSrcweir { 639*cdf0e10cSrcweir Error( "Can't close output part of a stream, exception :" + e ); 640*cdf0e10cSrcweir return false; 641*cdf0e10cSrcweir } 642*cdf0e10cSrcweir 643*cdf0e10cSrcweir return true; 644*cdf0e10cSrcweir } 645*cdf0e10cSrcweir 646*cdf0e10cSrcweir public XStorage openSubStorage( XStorage xStorage, String sName, int nMode ) 647*cdf0e10cSrcweir { 648*cdf0e10cSrcweir // open existing substorage 649*cdf0e10cSrcweir try 650*cdf0e10cSrcweir { 651*cdf0e10cSrcweir Object oSubStorage = xStorage.openStorageElement( sName, nMode ); 652*cdf0e10cSrcweir XStorage xSubStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oSubStorage ); 653*cdf0e10cSrcweir return xSubStorage; 654*cdf0e10cSrcweir } 655*cdf0e10cSrcweir catch( Exception e ) 656*cdf0e10cSrcweir { 657*cdf0e10cSrcweir Error( "Can't open substorage '" + sName + "', exception: " + e ); 658*cdf0e10cSrcweir } 659*cdf0e10cSrcweir 660*cdf0e10cSrcweir return null; 661*cdf0e10cSrcweir } 662*cdf0e10cSrcweir 663*cdf0e10cSrcweir public XStream CreateTempFileStream( XMultiServiceFactory xMSF ) 664*cdf0e10cSrcweir { 665*cdf0e10cSrcweir // try to get temporary file representation 666*cdf0e10cSrcweir XStream xTempFileStream = null; 667*cdf0e10cSrcweir try 668*cdf0e10cSrcweir { 669*cdf0e10cSrcweir Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" ); 670*cdf0e10cSrcweir xTempFileStream = (XStream)UnoRuntime.queryInterface( XStream.class, oTempFile ); 671*cdf0e10cSrcweir } 672*cdf0e10cSrcweir catch( Exception e ) 673*cdf0e10cSrcweir {} 674*cdf0e10cSrcweir 675*cdf0e10cSrcweir if ( xTempFileStream == null ) 676*cdf0e10cSrcweir Error( "Can't create temporary file!" ); 677*cdf0e10cSrcweir 678*cdf0e10cSrcweir return xTempFileStream; 679*cdf0e10cSrcweir } 680*cdf0e10cSrcweir 681*cdf0e10cSrcweir public String CreateTempFile( XMultiServiceFactory xMSF ) 682*cdf0e10cSrcweir { 683*cdf0e10cSrcweir String sResult = null; 684*cdf0e10cSrcweir 685*cdf0e10cSrcweir // try to get temporary file representation 686*cdf0e10cSrcweir XPropertySet xTempFileProps = null; 687*cdf0e10cSrcweir try 688*cdf0e10cSrcweir { 689*cdf0e10cSrcweir Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" ); 690*cdf0e10cSrcweir xTempFileProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, oTempFile ); 691*cdf0e10cSrcweir } 692*cdf0e10cSrcweir catch( Exception e ) 693*cdf0e10cSrcweir {} 694*cdf0e10cSrcweir 695*cdf0e10cSrcweir if ( xTempFileProps != null ) 696*cdf0e10cSrcweir { 697*cdf0e10cSrcweir try 698*cdf0e10cSrcweir { 699*cdf0e10cSrcweir xTempFileProps.setPropertyValue( "RemoveFile", new Boolean( false ) ); 700*cdf0e10cSrcweir sResult = AnyConverter.toString( xTempFileProps.getPropertyValue( "Uri" ) ); 701*cdf0e10cSrcweir } 702*cdf0e10cSrcweir catch( Exception e ) 703*cdf0e10cSrcweir { 704*cdf0e10cSrcweir Error( "Can't control TempFile properties, exception: " + e ); 705*cdf0e10cSrcweir } 706*cdf0e10cSrcweir } 707*cdf0e10cSrcweir else 708*cdf0e10cSrcweir { 709*cdf0e10cSrcweir Error( "Can't create temporary file representation!" ); 710*cdf0e10cSrcweir } 711*cdf0e10cSrcweir 712*cdf0e10cSrcweir // close temporary file explicitly 713*cdf0e10cSrcweir try 714*cdf0e10cSrcweir { 715*cdf0e10cSrcweir XStream xStream = (XStream)UnoRuntime.queryInterface( XStream.class, xTempFileProps ); 716*cdf0e10cSrcweir if ( xStream != null ) 717*cdf0e10cSrcweir { 718*cdf0e10cSrcweir XOutputStream xOut = xStream.getOutputStream(); 719*cdf0e10cSrcweir if ( xOut != null ) 720*cdf0e10cSrcweir xOut.closeOutput(); 721*cdf0e10cSrcweir 722*cdf0e10cSrcweir XInputStream xIn = xStream.getInputStream(); 723*cdf0e10cSrcweir if ( xIn != null ) 724*cdf0e10cSrcweir xIn.closeInput(); 725*cdf0e10cSrcweir } 726*cdf0e10cSrcweir else 727*cdf0e10cSrcweir Error( "Can't close TempFile!" ); 728*cdf0e10cSrcweir } 729*cdf0e10cSrcweir catch( Exception e ) 730*cdf0e10cSrcweir { 731*cdf0e10cSrcweir Error( "Can't close TempFile, exception: " + e ); 732*cdf0e10cSrcweir } 733*cdf0e10cSrcweir 734*cdf0e10cSrcweir return sResult; 735*cdf0e10cSrcweir } 736*cdf0e10cSrcweir 737*cdf0e10cSrcweir public boolean copyElementTo( XStorage xSource, String sName, XStorage xDest ) 738*cdf0e10cSrcweir { 739*cdf0e10cSrcweir // copy element with name sName from xSource to xDest 740*cdf0e10cSrcweir try 741*cdf0e10cSrcweir { 742*cdf0e10cSrcweir xSource.copyElementTo( sName, xDest, sName ); 743*cdf0e10cSrcweir } 744*cdf0e10cSrcweir catch( Exception e ) 745*cdf0e10cSrcweir { 746*cdf0e10cSrcweir Error( "Element copying failed, exception: " + e ); 747*cdf0e10cSrcweir return false; 748*cdf0e10cSrcweir } 749*cdf0e10cSrcweir 750*cdf0e10cSrcweir return true; 751*cdf0e10cSrcweir } 752*cdf0e10cSrcweir 753*cdf0e10cSrcweir public boolean moveElementTo( XStorage xSource, String sName, XStorage xDest ) 754*cdf0e10cSrcweir { 755*cdf0e10cSrcweir // move element with name sName from xSource to xDest 756*cdf0e10cSrcweir try 757*cdf0e10cSrcweir { 758*cdf0e10cSrcweir xSource.moveElementTo( sName, xDest, sName ); 759*cdf0e10cSrcweir } 760*cdf0e10cSrcweir catch( Exception e ) 761*cdf0e10cSrcweir { 762*cdf0e10cSrcweir Error( "Element moving failed, exception: " + e ); 763*cdf0e10cSrcweir return false; 764*cdf0e10cSrcweir } 765*cdf0e10cSrcweir 766*cdf0e10cSrcweir return true; 767*cdf0e10cSrcweir } 768*cdf0e10cSrcweir 769*cdf0e10cSrcweir public boolean renameElement( XStorage xStorage, String sOldName, String sNewName ) 770*cdf0e10cSrcweir { 771*cdf0e10cSrcweir // rename element with name sOldName to sNewName 772*cdf0e10cSrcweir try 773*cdf0e10cSrcweir { 774*cdf0e10cSrcweir xStorage.renameElement( sOldName, sNewName ); 775*cdf0e10cSrcweir } 776*cdf0e10cSrcweir catch( Exception e ) 777*cdf0e10cSrcweir { 778*cdf0e10cSrcweir Error( "Element renaming failed, exception: " + e ); 779*cdf0e10cSrcweir return false; 780*cdf0e10cSrcweir } 781*cdf0e10cSrcweir 782*cdf0e10cSrcweir return true; 783*cdf0e10cSrcweir } 784*cdf0e10cSrcweir 785*cdf0e10cSrcweir public boolean removeElement( XStorage xStorage, String sName ) 786*cdf0e10cSrcweir { 787*cdf0e10cSrcweir // remove element with name sName 788*cdf0e10cSrcweir try 789*cdf0e10cSrcweir { 790*cdf0e10cSrcweir xStorage.removeElement( sName ); 791*cdf0e10cSrcweir } 792*cdf0e10cSrcweir catch( Exception e ) 793*cdf0e10cSrcweir { 794*cdf0e10cSrcweir Error( "Element removing failed, exception: " + e ); 795*cdf0e10cSrcweir return false; 796*cdf0e10cSrcweir } 797*cdf0e10cSrcweir 798*cdf0e10cSrcweir return true; 799*cdf0e10cSrcweir } 800*cdf0e10cSrcweir 801*cdf0e10cSrcweir public XStream OpenStream( XStorage xStorage, 802*cdf0e10cSrcweir String sStreamName, 803*cdf0e10cSrcweir int nMode ) 804*cdf0e10cSrcweir { 805*cdf0e10cSrcweir // open substream element 806*cdf0e10cSrcweir XStream xSubStream = null; 807*cdf0e10cSrcweir try 808*cdf0e10cSrcweir { 809*cdf0e10cSrcweir Object oSubStream = xStorage.openStreamElement( sStreamName, nMode ); 810*cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 811*cdf0e10cSrcweir if ( xSubStream == null ) 812*cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "'!" ); 813*cdf0e10cSrcweir } 814*cdf0e10cSrcweir catch( Exception e ) 815*cdf0e10cSrcweir { 816*cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" ); 817*cdf0e10cSrcweir } 818*cdf0e10cSrcweir 819*cdf0e10cSrcweir return xSubStream; 820*cdf0e10cSrcweir } 821*cdf0e10cSrcweir 822*cdf0e10cSrcweir public boolean cantOpenStorage( XStorage xStorage, String sName ) 823*cdf0e10cSrcweir { 824*cdf0e10cSrcweir // try to open an opened substorage, open call must fail 825*cdf0e10cSrcweir try 826*cdf0e10cSrcweir { 827*cdf0e10cSrcweir Object oDummyStorage = xStorage.openStorageElement( sName, ElementModes.ELEMENT_READ ); 828*cdf0e10cSrcweir Error( "The trying to reopen opened substorage '" + sName + "' must fail!" ); 829*cdf0e10cSrcweir } 830*cdf0e10cSrcweir catch( Exception e ) 831*cdf0e10cSrcweir { 832*cdf0e10cSrcweir return true; 833*cdf0e10cSrcweir } 834*cdf0e10cSrcweir 835*cdf0e10cSrcweir return false; 836*cdf0e10cSrcweir } 837*cdf0e10cSrcweir 838*cdf0e10cSrcweir public boolean cantOpenStream( XStorage xStorage, String sName, int nMode ) 839*cdf0e10cSrcweir { 840*cdf0e10cSrcweir // try to open the substream with specified mode must fail 841*cdf0e10cSrcweir try 842*cdf0e10cSrcweir { 843*cdf0e10cSrcweir Object oDummyStream = xStorage.openStreamElement( sName, nMode ); 844*cdf0e10cSrcweir Error( "The trying to open substoream '" + sName + "' must fail!" ); 845*cdf0e10cSrcweir } 846*cdf0e10cSrcweir catch( Exception e ) 847*cdf0e10cSrcweir { 848*cdf0e10cSrcweir return true; 849*cdf0e10cSrcweir } 850*cdf0e10cSrcweir 851*cdf0e10cSrcweir return false; 852*cdf0e10cSrcweir } 853*cdf0e10cSrcweir 854*cdf0e10cSrcweir public void Error( String sError ) 855*cdf0e10cSrcweir { 856*cdf0e10cSrcweir System.out.println( m_sTestPrefix + "Error: " + sError ); 857*cdf0e10cSrcweir } 858*cdf0e10cSrcweir 859*cdf0e10cSrcweir public void Message( String sError ) 860*cdf0e10cSrcweir { 861*cdf0e10cSrcweir System.out.println( m_sTestPrefix + sError ); 862*cdf0e10cSrcweir } 863*cdf0e10cSrcweir } 864*cdf0e10cSrcweir 865