1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski package complex.storages; 23*b1cdbd2cSJim Jagielski 24*b1cdbd2cSJim Jagielski import com.sun.star.uno.XInterface; 25*b1cdbd2cSJim Jagielski import com.sun.star.lang.XMultiServiceFactory; 26*b1cdbd2cSJim Jagielski import com.sun.star.lang.XSingleServiceFactory; 27*b1cdbd2cSJim Jagielski 28*b1cdbd2cSJim Jagielski import com.sun.star.bridge.XUnoUrlResolver; 29*b1cdbd2cSJim Jagielski import com.sun.star.uno.UnoRuntime; 30*b1cdbd2cSJim Jagielski import com.sun.star.uno.XInterface; 31*b1cdbd2cSJim Jagielski 32*b1cdbd2cSJim Jagielski import com.sun.star.lang.IllegalArgumentException; 33*b1cdbd2cSJim Jagielski import com.sun.star.container.NoSuchElementException; 34*b1cdbd2cSJim Jagielski import com.sun.star.container.ElementExistException; 35*b1cdbd2cSJim Jagielski 36*b1cdbd2cSJim Jagielski import com.sun.star.embed.*; 37*b1cdbd2cSJim Jagielski 38*b1cdbd2cSJim Jagielski import share.LogWriter; 39*b1cdbd2cSJim Jagielski import complex.storages.TestHelper; 40*b1cdbd2cSJim Jagielski import complex.storages.StorageTest; 41*b1cdbd2cSJim Jagielski 42*b1cdbd2cSJim Jagielski public class Test06 implements StorageTest { 43*b1cdbd2cSJim Jagielski 44*b1cdbd2cSJim Jagielski XMultiServiceFactory m_xMSF; 45*b1cdbd2cSJim Jagielski XSingleServiceFactory m_xStorageFactory; 46*b1cdbd2cSJim Jagielski TestHelper m_aTestHelper; 47*b1cdbd2cSJim Jagielski Test06( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter )48*b1cdbd2cSJim Jagielski public Test06( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) 49*b1cdbd2cSJim Jagielski { 50*b1cdbd2cSJim Jagielski m_xMSF = xMSF; 51*b1cdbd2cSJim Jagielski m_xStorageFactory = xStorageFactory; 52*b1cdbd2cSJim Jagielski m_aTestHelper = new TestHelper( aLogWriter, "Test06: " ); 53*b1cdbd2cSJim Jagielski } 54*b1cdbd2cSJim Jagielski test()55*b1cdbd2cSJim Jagielski public boolean test() 56*b1cdbd2cSJim Jagielski { 57*b1cdbd2cSJim Jagielski try 58*b1cdbd2cSJim Jagielski { 59*b1cdbd2cSJim Jagielski // create temporary storage based on arbitrary medium 60*b1cdbd2cSJim Jagielski // after such a storage is closed it is lost 61*b1cdbd2cSJim Jagielski Object oTempStorage = m_xStorageFactory.createInstance(); 62*b1cdbd2cSJim Jagielski XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); 63*b1cdbd2cSJim Jagielski if ( xTempStorage == null ) 64*b1cdbd2cSJim Jagielski { 65*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "Can't create temporary storage representation!" ); 66*b1cdbd2cSJim Jagielski return false; 67*b1cdbd2cSJim Jagielski } 68*b1cdbd2cSJim Jagielski 69*b1cdbd2cSJim Jagielski try 70*b1cdbd2cSJim Jagielski { 71*b1cdbd2cSJim Jagielski xTempStorage.copyToStorage( null ); 72*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "The method must throw an exception because of illegal parameter!" ); 73*b1cdbd2cSJim Jagielski return false; 74*b1cdbd2cSJim Jagielski } 75*b1cdbd2cSJim Jagielski catch( com.sun.star.lang.IllegalArgumentException iae ) 76*b1cdbd2cSJim Jagielski {} 77*b1cdbd2cSJim Jagielski catch( com.sun.star.uno.Exception ue ) 78*b1cdbd2cSJim Jagielski {} 79*b1cdbd2cSJim Jagielski catch( Exception e ) 80*b1cdbd2cSJim Jagielski { 81*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "Unexpected excepion because of illegal parameter : " + e ); 82*b1cdbd2cSJim Jagielski return false; 83*b1cdbd2cSJim Jagielski } 84*b1cdbd2cSJim Jagielski 85*b1cdbd2cSJim Jagielski // open new substorages 86*b1cdbd2cSJim Jagielski XStorage xTempSubStorage1 = m_aTestHelper.openSubStorage( xTempStorage, 87*b1cdbd2cSJim Jagielski "SubStorage1", 88*b1cdbd2cSJim Jagielski ElementModes.WRITE ); 89*b1cdbd2cSJim Jagielski XStorage xTempSubStorage2 = m_aTestHelper.openSubStorage( xTempStorage, 90*b1cdbd2cSJim Jagielski "SubStorage2", 91*b1cdbd2cSJim Jagielski ElementModes.WRITE ); 92*b1cdbd2cSJim Jagielski if ( xTempSubStorage1 == null || xTempSubStorage2 == null ) 93*b1cdbd2cSJim Jagielski { 94*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "Can't create substorage!" ); 95*b1cdbd2cSJim Jagielski return false; 96*b1cdbd2cSJim Jagielski } 97*b1cdbd2cSJim Jagielski 98*b1cdbd2cSJim Jagielski // in case stream is open for reading it must exist 99*b1cdbd2cSJim Jagielski try 100*b1cdbd2cSJim Jagielski { 101*b1cdbd2cSJim Jagielski xTempSubStorage1.openStreamElement( "NonExistingStream", ElementModes.READ ); 102*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent stream for reading!" ); 103*b1cdbd2cSJim Jagielski return false; 104*b1cdbd2cSJim Jagielski } 105*b1cdbd2cSJim Jagielski catch( com.sun.star.uno.Exception ue ) 106*b1cdbd2cSJim Jagielski {} 107*b1cdbd2cSJim Jagielski catch( Exception e ) 108*b1cdbd2cSJim Jagielski { 109*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "Unexpected excepion in case of try to open nonexistent stream for reading : " + e ); 110*b1cdbd2cSJim Jagielski return false; 111*b1cdbd2cSJim Jagielski } 112*b1cdbd2cSJim Jagielski 113*b1cdbd2cSJim Jagielski // in case a storage is open for reading it must exist 114*b1cdbd2cSJim Jagielski try 115*b1cdbd2cSJim Jagielski { 116*b1cdbd2cSJim Jagielski xTempSubStorage1.openStreamElement( "NonExistingStorage", ElementModes.READ ); 117*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent storage for reading!" ); 118*b1cdbd2cSJim Jagielski return false; 119*b1cdbd2cSJim Jagielski } 120*b1cdbd2cSJim Jagielski catch( com.sun.star.uno.Exception ue ) 121*b1cdbd2cSJim Jagielski {} 122*b1cdbd2cSJim Jagielski catch( Exception e ) 123*b1cdbd2cSJim Jagielski { 124*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "Unexpected excepion in case of try to open nonexistent storage for reading : " + e ); 125*b1cdbd2cSJim Jagielski return false; 126*b1cdbd2cSJim Jagielski } 127*b1cdbd2cSJim Jagielski 128*b1cdbd2cSJim Jagielski // in case of removing nonexistent element an exception must be thrown 129*b1cdbd2cSJim Jagielski try 130*b1cdbd2cSJim Jagielski { 131*b1cdbd2cSJim Jagielski xTempSubStorage1.removeElement( "NonExistingElement" ); 132*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "An exception must be thrown in case of removing nonexistent element!" ); 133*b1cdbd2cSJim Jagielski return false; 134*b1cdbd2cSJim Jagielski } 135*b1cdbd2cSJim Jagielski catch( com.sun.star.container.NoSuchElementException ne ) 136*b1cdbd2cSJim Jagielski {} 137*b1cdbd2cSJim Jagielski catch( Exception e ) 138*b1cdbd2cSJim Jagielski { 139*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "Unexpected excepion in case of try to remove nonexistent element : " + e ); 140*b1cdbd2cSJim Jagielski return false; 141*b1cdbd2cSJim Jagielski } 142*b1cdbd2cSJim Jagielski 143*b1cdbd2cSJim Jagielski // in case of renaming of nonexistent element an exception must be thrown 144*b1cdbd2cSJim Jagielski try 145*b1cdbd2cSJim Jagielski { 146*b1cdbd2cSJim Jagielski xTempSubStorage1.renameElement( "NonExistingElement", "NewName" ); 147*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "An exception must be thrown in case of renaming nonexistent element!" ); 148*b1cdbd2cSJim Jagielski return false; 149*b1cdbd2cSJim Jagielski } 150*b1cdbd2cSJim Jagielski catch( com.sun.star.container.NoSuchElementException ne ) 151*b1cdbd2cSJim Jagielski {} 152*b1cdbd2cSJim Jagielski catch( Exception e ) 153*b1cdbd2cSJim Jagielski { 154*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "Unexpected excepion in case of try to rename nonexistent element : " + e ); 155*b1cdbd2cSJim Jagielski return false; 156*b1cdbd2cSJim Jagielski } 157*b1cdbd2cSJim Jagielski 158*b1cdbd2cSJim Jagielski // in case of renaming to a name of existent element an exception must be thrown 159*b1cdbd2cSJim Jagielski try 160*b1cdbd2cSJim Jagielski { 161*b1cdbd2cSJim Jagielski xTempStorage.renameElement( "SubStorage1", "SubStorage2" ); 162*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "An exception must be thrown in case of renaming to the name of existent element!" ); 163*b1cdbd2cSJim Jagielski return false; 164*b1cdbd2cSJim Jagielski } 165*b1cdbd2cSJim Jagielski catch( com.sun.star.container.ElementExistException ee ) 166*b1cdbd2cSJim Jagielski {} 167*b1cdbd2cSJim Jagielski catch( Exception e ) 168*b1cdbd2cSJim Jagielski { 169*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "Unexpected excepion in case of try to rename to the name of existent element : " + e ); 170*b1cdbd2cSJim Jagielski return false; 171*b1cdbd2cSJim Jagielski } 172*b1cdbd2cSJim Jagielski 173*b1cdbd2cSJim Jagielski // in case of copying target storage must be provided 174*b1cdbd2cSJim Jagielski try 175*b1cdbd2cSJim Jagielski { 176*b1cdbd2cSJim Jagielski xTempStorage.copyElementTo( "SubStorage1", null, "SubStorage1" ); 177*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "An exception must be thrown in case empty reference is provided as target for copying!" ); 178*b1cdbd2cSJim Jagielski return false; 179*b1cdbd2cSJim Jagielski } 180*b1cdbd2cSJim Jagielski catch( com.sun.star.lang.IllegalArgumentException iae ) 181*b1cdbd2cSJim Jagielski {} 182*b1cdbd2cSJim Jagielski catch( com.sun.star.uno.Exception ue ) 183*b1cdbd2cSJim Jagielski {} 184*b1cdbd2cSJim Jagielski catch( Exception e ) 185*b1cdbd2cSJim Jagielski { 186*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "Unexpected excepion in case empty reference is provieded as target for copying : " + e ); 187*b1cdbd2cSJim Jagielski return false; 188*b1cdbd2cSJim Jagielski } 189*b1cdbd2cSJim Jagielski 190*b1cdbd2cSJim Jagielski // in case of moving target storage must be provided 191*b1cdbd2cSJim Jagielski try 192*b1cdbd2cSJim Jagielski { 193*b1cdbd2cSJim Jagielski xTempStorage.moveElementTo( "SubStorage1", null, "SubStorage1" ); 194*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "An exception must be thrown in case empty reference is provided as target for moving!" ); 195*b1cdbd2cSJim Jagielski return false; 196*b1cdbd2cSJim Jagielski } 197*b1cdbd2cSJim Jagielski catch( com.sun.star.lang.IllegalArgumentException iae ) 198*b1cdbd2cSJim Jagielski {} 199*b1cdbd2cSJim Jagielski catch( com.sun.star.uno.Exception ue ) 200*b1cdbd2cSJim Jagielski {} 201*b1cdbd2cSJim Jagielski catch( Exception e ) 202*b1cdbd2cSJim Jagielski { 203*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "Unexpected excepion in case empty reference is provieded as target for moving : " + e ); 204*b1cdbd2cSJim Jagielski return false; 205*b1cdbd2cSJim Jagielski } 206*b1cdbd2cSJim Jagielski 207*b1cdbd2cSJim Jagielski 208*b1cdbd2cSJim Jagielski // prepare target for further testings 209*b1cdbd2cSJim Jagielski 210*b1cdbd2cSJim Jagielski // create new temporary storage based on arbitrary medium 211*b1cdbd2cSJim Jagielski Object oTargetStorage = m_xStorageFactory.createInstance(); 212*b1cdbd2cSJim Jagielski XStorage xTargetStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTargetStorage ); 213*b1cdbd2cSJim Jagielski if ( xTargetStorage == null ) 214*b1cdbd2cSJim Jagielski { 215*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "Can't create temporary storage representation!" ); 216*b1cdbd2cSJim Jagielski return false; 217*b1cdbd2cSJim Jagielski } 218*b1cdbd2cSJim Jagielski 219*b1cdbd2cSJim Jagielski // open a new substorage 220*b1cdbd2cSJim Jagielski XStorage xTargetSubStorage = m_aTestHelper.openSubStorage( xTargetStorage, 221*b1cdbd2cSJim Jagielski "SubStorage1", 222*b1cdbd2cSJim Jagielski ElementModes.WRITE ); 223*b1cdbd2cSJim Jagielski if ( xTargetSubStorage == null ) 224*b1cdbd2cSJim Jagielski { 225*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "Can't create substorage!" ); 226*b1cdbd2cSJim Jagielski return false; 227*b1cdbd2cSJim Jagielski } 228*b1cdbd2cSJim Jagielski 229*b1cdbd2cSJim Jagielski // in case of copying of nonexistent element an exception must be thrown 230*b1cdbd2cSJim Jagielski try 231*b1cdbd2cSJim Jagielski { 232*b1cdbd2cSJim Jagielski xTempStorage.copyElementTo( "Nonexistent element", xTargetStorage, "Target" ); 233*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "An exception must be thrown in case of copying of nonexisting element!" ); 234*b1cdbd2cSJim Jagielski return false; 235*b1cdbd2cSJim Jagielski } 236*b1cdbd2cSJim Jagielski catch( com.sun.star.container.NoSuchElementException ne ) 237*b1cdbd2cSJim Jagielski {} 238*b1cdbd2cSJim Jagielski catch( Exception e ) 239*b1cdbd2cSJim Jagielski { 240*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "Unexpected excepion in case of copying of nonexistent element: " + e ); 241*b1cdbd2cSJim Jagielski return false; 242*b1cdbd2cSJim Jagielski } 243*b1cdbd2cSJim Jagielski 244*b1cdbd2cSJim Jagielski // in case of moving of nonexistent element an exception must be thrown 245*b1cdbd2cSJim Jagielski try 246*b1cdbd2cSJim Jagielski { 247*b1cdbd2cSJim Jagielski xTempStorage.moveElementTo( "Nonexistent element", xTargetStorage, "Target" ); 248*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "An exception must be thrown in case of moving of nonexisting element!" ); 249*b1cdbd2cSJim Jagielski return false; 250*b1cdbd2cSJim Jagielski } 251*b1cdbd2cSJim Jagielski catch( com.sun.star.container.NoSuchElementException ne ) 252*b1cdbd2cSJim Jagielski {} 253*b1cdbd2cSJim Jagielski catch( Exception e ) 254*b1cdbd2cSJim Jagielski { 255*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "Unexpected excepion in case of moving of nonexistent element: " + e ); 256*b1cdbd2cSJim Jagielski return false; 257*b1cdbd2cSJim Jagielski } 258*b1cdbd2cSJim Jagielski 259*b1cdbd2cSJim Jagielski // in case target for copying already exists an exception must be thrown 260*b1cdbd2cSJim Jagielski try 261*b1cdbd2cSJim Jagielski { 262*b1cdbd2cSJim Jagielski xTempStorage.copyElementTo( "SubStorage1", xTargetStorage, "SubStorage1" ); 263*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "An exception must be thrown in case target for copying already exists!" ); 264*b1cdbd2cSJim Jagielski return false; 265*b1cdbd2cSJim Jagielski } 266*b1cdbd2cSJim Jagielski catch( com.sun.star.container.ElementExistException ee ) 267*b1cdbd2cSJim Jagielski {} 268*b1cdbd2cSJim Jagielski catch( Exception e ) 269*b1cdbd2cSJim Jagielski { 270*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "Unexpected excepion in case target for copying already exists: " + e ); 271*b1cdbd2cSJim Jagielski return false; 272*b1cdbd2cSJim Jagielski } 273*b1cdbd2cSJim Jagielski 274*b1cdbd2cSJim Jagielski // in case target for moving already exists an exception must be thrown 275*b1cdbd2cSJim Jagielski try 276*b1cdbd2cSJim Jagielski { 277*b1cdbd2cSJim Jagielski xTempStorage.moveElementTo( "SubStorage1", xTargetStorage, "SubStorage1" ); 278*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "An exception must be thrown in case target for moving already exists!" ); 279*b1cdbd2cSJim Jagielski return false; 280*b1cdbd2cSJim Jagielski } 281*b1cdbd2cSJim Jagielski catch( com.sun.star.container.ElementExistException ee ) 282*b1cdbd2cSJim Jagielski {} 283*b1cdbd2cSJim Jagielski catch( Exception e ) 284*b1cdbd2cSJim Jagielski { 285*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "Unexpected excepion in case target for moving already exists: " + e ); 286*b1cdbd2cSJim Jagielski return false; 287*b1cdbd2cSJim Jagielski } 288*b1cdbd2cSJim Jagielski 289*b1cdbd2cSJim Jagielski 290*b1cdbd2cSJim Jagielski return true; 291*b1cdbd2cSJim Jagielski } 292*b1cdbd2cSJim Jagielski catch( Exception e ) 293*b1cdbd2cSJim Jagielski { 294*b1cdbd2cSJim Jagielski m_aTestHelper.Error( "Exception: " + e ); 295*b1cdbd2cSJim Jagielski return false; 296*b1cdbd2cSJim Jagielski } 297*b1cdbd2cSJim Jagielski } 298*b1cdbd2cSJim Jagielski 299*b1cdbd2cSJim Jagielski } 300*b1cdbd2cSJim Jagielski 301