1*cdf0e10cSrcweir package complex.ofopxmlstorages; 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 11*cdf0e10cSrcweir import com.sun.star.lang.IllegalArgumentException; 12*cdf0e10cSrcweir import com.sun.star.container.NoSuchElementException; 13*cdf0e10cSrcweir import com.sun.star.container.ElementExistException; 14*cdf0e10cSrcweir 15*cdf0e10cSrcweir import com.sun.star.embed.*; 16*cdf0e10cSrcweir 17*cdf0e10cSrcweir import share.LogWriter; 18*cdf0e10cSrcweir import complex.ofopxmlstorages.TestHelper; 19*cdf0e10cSrcweir import complex.ofopxmlstorages.StorageTest; 20*cdf0e10cSrcweir 21*cdf0e10cSrcweir public class Test06 implements StorageTest { 22*cdf0e10cSrcweir 23*cdf0e10cSrcweir XMultiServiceFactory m_xMSF; 24*cdf0e10cSrcweir XSingleServiceFactory m_xStorageFactory; 25*cdf0e10cSrcweir TestHelper m_aTestHelper; 26*cdf0e10cSrcweir 27*cdf0e10cSrcweir public Test06( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) 28*cdf0e10cSrcweir { 29*cdf0e10cSrcweir m_xMSF = xMSF; 30*cdf0e10cSrcweir m_xStorageFactory = xStorageFactory; 31*cdf0e10cSrcweir m_aTestHelper = new TestHelper( aLogWriter, "Test06: " ); 32*cdf0e10cSrcweir } 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir public boolean test() 35*cdf0e10cSrcweir { 36*cdf0e10cSrcweir try 37*cdf0e10cSrcweir { 38*cdf0e10cSrcweir // create temporary storage based on arbitrary medium 39*cdf0e10cSrcweir // after such a storage is closed it is lost 40*cdf0e10cSrcweir XStorage xTempStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory ); 41*cdf0e10cSrcweir if ( xTempStorage == null ) 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create temporary storage representation!" ); 44*cdf0e10cSrcweir return false; 45*cdf0e10cSrcweir } 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir try 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir xTempStorage.copyToStorage( null ); 50*cdf0e10cSrcweir m_aTestHelper.Error( "The method must throw an exception because of illegal parameter!" ); 51*cdf0e10cSrcweir return false; 52*cdf0e10cSrcweir } 53*cdf0e10cSrcweir catch( com.sun.star.lang.IllegalArgumentException iae ) 54*cdf0e10cSrcweir {} 55*cdf0e10cSrcweir catch( com.sun.star.uno.Exception ue ) 56*cdf0e10cSrcweir {} 57*cdf0e10cSrcweir catch( Exception e ) 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir m_aTestHelper.Error( "Unexpected excepion because of illegal parameter : " + e ); 60*cdf0e10cSrcweir return false; 61*cdf0e10cSrcweir } 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir // open new substorages 64*cdf0e10cSrcweir XStorage xTempSubStorage1 = m_aTestHelper.openSubStorage( xTempStorage, 65*cdf0e10cSrcweir "SubStorage1", 66*cdf0e10cSrcweir ElementModes.WRITE ); 67*cdf0e10cSrcweir XStorage xTempSubStorage2 = m_aTestHelper.openSubStorage( xTempStorage, 68*cdf0e10cSrcweir "SubStorage2", 69*cdf0e10cSrcweir ElementModes.WRITE ); 70*cdf0e10cSrcweir if ( xTempSubStorage1 == null || xTempSubStorage2 == null ) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 73*cdf0e10cSrcweir return false; 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir // in case stream is open for reading it must exist 77*cdf0e10cSrcweir try 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir xTempSubStorage1.openStreamElement( "NonExistingStream", ElementModes.READ ); 80*cdf0e10cSrcweir m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent stream for reading!" ); 81*cdf0e10cSrcweir return false; 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir catch( com.sun.star.uno.Exception ue ) 84*cdf0e10cSrcweir {} 85*cdf0e10cSrcweir catch( Exception e ) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir m_aTestHelper.Error( "Unexpected excepion in case of try to open nonexistent stream for reading : " + e ); 88*cdf0e10cSrcweir return false; 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir // in case a storage is open for reading it must exist 92*cdf0e10cSrcweir try 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir xTempSubStorage1.openStreamElement( "NonExistingStorage", ElementModes.READ ); 95*cdf0e10cSrcweir m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent storage for reading!" ); 96*cdf0e10cSrcweir return false; 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir catch( com.sun.star.uno.Exception ue ) 99*cdf0e10cSrcweir {} 100*cdf0e10cSrcweir catch( Exception e ) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir m_aTestHelper.Error( "Unexpected excepion in case of try to open nonexistent storage for reading : " + e ); 103*cdf0e10cSrcweir return false; 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir // in case of removing nonexistent element an exception must be thrown 107*cdf0e10cSrcweir try 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir xTempSubStorage1.removeElement( "NonExistingElement" ); 110*cdf0e10cSrcweir m_aTestHelper.Error( "An exception must be thrown in case of removing nonexistent element!" ); 111*cdf0e10cSrcweir return false; 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir catch( com.sun.star.container.NoSuchElementException ne ) 114*cdf0e10cSrcweir {} 115*cdf0e10cSrcweir catch( Exception e ) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir m_aTestHelper.Error( "Unexpected excepion in case of try to remove nonexistent element : " + e ); 118*cdf0e10cSrcweir return false; 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir // in case of renaming of nonexistent element an exception must be thrown 122*cdf0e10cSrcweir try 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir xTempSubStorage1.renameElement( "NonExistingElement", "NewName" ); 125*cdf0e10cSrcweir m_aTestHelper.Error( "An exception must be thrown in case of renaming nonexistent element!" ); 126*cdf0e10cSrcweir return false; 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir catch( com.sun.star.container.NoSuchElementException ne ) 129*cdf0e10cSrcweir {} 130*cdf0e10cSrcweir catch( Exception e ) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir m_aTestHelper.Error( "Unexpected excepion in case of try to rename nonexistent element : " + e ); 133*cdf0e10cSrcweir return false; 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir // in case of renaming to a name of existent element an exception must be thrown 137*cdf0e10cSrcweir try 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir xTempStorage.renameElement( "SubStorage1", "SubStorage2" ); 140*cdf0e10cSrcweir m_aTestHelper.Error( "An exception must be thrown in case of renaming to the name of existent element!" ); 141*cdf0e10cSrcweir return false; 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir catch( com.sun.star.container.ElementExistException ee ) 144*cdf0e10cSrcweir {} 145*cdf0e10cSrcweir catch( Exception e ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir m_aTestHelper.Error( "Unexpected excepion in case of try to rename to the name of existent element : " + e ); 148*cdf0e10cSrcweir return false; 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir // in case of copying target storage must be provided 152*cdf0e10cSrcweir try 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir xTempStorage.copyElementTo( "SubStorage1", null, "SubStorage1" ); 155*cdf0e10cSrcweir m_aTestHelper.Error( "An exception must be thrown in case empty reference is provided as target for copying!" ); 156*cdf0e10cSrcweir return false; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir catch( com.sun.star.lang.IllegalArgumentException iae ) 159*cdf0e10cSrcweir {} 160*cdf0e10cSrcweir catch( com.sun.star.uno.Exception ue ) 161*cdf0e10cSrcweir {} 162*cdf0e10cSrcweir catch( Exception e ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir m_aTestHelper.Error( "Unexpected excepion in case empty reference is provieded as target for copying : " + e ); 165*cdf0e10cSrcweir return false; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir // in case of moving target storage must be provided 169*cdf0e10cSrcweir try 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir xTempStorage.moveElementTo( "SubStorage1", null, "SubStorage1" ); 172*cdf0e10cSrcweir m_aTestHelper.Error( "An exception must be thrown in case empty reference is provided as target for moving!" ); 173*cdf0e10cSrcweir return false; 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir catch( com.sun.star.lang.IllegalArgumentException iae ) 176*cdf0e10cSrcweir {} 177*cdf0e10cSrcweir catch( com.sun.star.uno.Exception ue ) 178*cdf0e10cSrcweir {} 179*cdf0e10cSrcweir catch( Exception e ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir m_aTestHelper.Error( "Unexpected excepion in case empty reference is provieded as target for moving : " + e ); 182*cdf0e10cSrcweir return false; 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir // prepare target for further testings 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir // create new temporary storage based on arbitrary medium 189*cdf0e10cSrcweir XStorage xTargetStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory ); 190*cdf0e10cSrcweir if ( xTargetStorage == null ) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create temporary storage representation!" ); 193*cdf0e10cSrcweir return false; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir // open a new substorage 197*cdf0e10cSrcweir XStorage xTargetSubStorage = m_aTestHelper.openSubStorage( xTargetStorage, 198*cdf0e10cSrcweir "SubStorage1", 199*cdf0e10cSrcweir ElementModes.WRITE ); 200*cdf0e10cSrcweir if ( xTargetSubStorage == null ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 203*cdf0e10cSrcweir return false; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir // in case of copying of nonexistent element an exception must be thrown 207*cdf0e10cSrcweir try 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir xTempStorage.copyElementTo( "Nonexistent element", xTargetStorage, "Target" ); 210*cdf0e10cSrcweir m_aTestHelper.Error( "An exception must be thrown in case of copying of nonexisting element!" ); 211*cdf0e10cSrcweir return false; 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir catch( com.sun.star.container.NoSuchElementException ne ) 214*cdf0e10cSrcweir {} 215*cdf0e10cSrcweir catch( Exception e ) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir m_aTestHelper.Error( "Unexpected excepion in case of copying of nonexistent element: " + e ); 218*cdf0e10cSrcweir return false; 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir // in case of moving of nonexistent element an exception must be thrown 222*cdf0e10cSrcweir try 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir xTempStorage.moveElementTo( "Nonexistent element", xTargetStorage, "Target" ); 225*cdf0e10cSrcweir m_aTestHelper.Error( "An exception must be thrown in case of moving of nonexisting element!" ); 226*cdf0e10cSrcweir return false; 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir catch( com.sun.star.container.NoSuchElementException ne ) 229*cdf0e10cSrcweir {} 230*cdf0e10cSrcweir catch( Exception e ) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir m_aTestHelper.Error( "Unexpected excepion in case of moving of nonexistent element: " + e ); 233*cdf0e10cSrcweir return false; 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir // in case target for copying already exists an exception must be thrown 237*cdf0e10cSrcweir try 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir xTempStorage.copyElementTo( "SubStorage1", xTargetStorage, "SubStorage1" ); 240*cdf0e10cSrcweir m_aTestHelper.Error( "An exception must be thrown in case target for copying already exists!" ); 241*cdf0e10cSrcweir return false; 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir catch( com.sun.star.container.ElementExistException ee ) 244*cdf0e10cSrcweir {} 245*cdf0e10cSrcweir catch( Exception e ) 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir m_aTestHelper.Error( "Unexpected excepion in case target for copying already exists: " + e ); 248*cdf0e10cSrcweir return false; 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir // in case target for moving already exists an exception must be thrown 252*cdf0e10cSrcweir try 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir xTempStorage.moveElementTo( "SubStorage1", xTargetStorage, "SubStorage1" ); 255*cdf0e10cSrcweir m_aTestHelper.Error( "An exception must be thrown in case target for moving already exists!" ); 256*cdf0e10cSrcweir return false; 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir catch( com.sun.star.container.ElementExistException ee ) 259*cdf0e10cSrcweir {} 260*cdf0e10cSrcweir catch( Exception e ) 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir m_aTestHelper.Error( "Unexpected excepion in case target for moving already exists: " + e ); 263*cdf0e10cSrcweir return false; 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir return true; 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir catch( Exception e ) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir m_aTestHelper.Error( "Exception: " + e ); 272*cdf0e10cSrcweir return false; 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278