1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package mod._sc; 25 26 import java.io.PrintWriter; 27 28 import lib.StatusException; 29 import lib.TestCase; 30 import lib.TestEnvironment; 31 import lib.TestParameters; 32 import util.SOfficeFactory; 33 34 import com.sun.star.beans.XPropertySet; 35 import com.sun.star.container.XEnumerationAccess; 36 import com.sun.star.lang.XComponent; 37 import com.sun.star.lang.XMultiServiceFactory; 38 import com.sun.star.sheet.XAreaLinks; 39 import com.sun.star.sheet.XSpreadsheetDocument; 40 import com.sun.star.table.CellAddress; 41 import com.sun.star.uno.AnyConverter; 42 import com.sun.star.uno.Type; 43 import com.sun.star.uno.UnoRuntime; 44 import com.sun.star.uno.XInterface; 45 46 public class ScIndexEnumeration_CellAreaLinksEnumeration extends TestCase { 47 static XSpreadsheetDocument xSheetDoc = null; 48 49 /** 50 * Creates Spreadsheet document. 51 */ initialize( TestParameters tParam, PrintWriter log )52 protected void initialize( TestParameters tParam, PrintWriter log ) { 53 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 54 55 try { 56 log.println( "creating a Spreadsheet document" ); 57 xSheetDoc = SOF.createCalcDoc(null); 58 } catch ( com.sun.star.uno.Exception e ) { 59 // Some exception occures.FAILED 60 e.printStackTrace( log ); 61 throw new StatusException( "Couldn't create document", e ); 62 } 63 64 } 65 66 /** 67 * Disposes Spreadsheet document. 68 */ cleanup( TestParameters tParam, PrintWriter log )69 protected void cleanup( TestParameters tParam, PrintWriter log ) { 70 log.println( " disposing xSheetDoc " ); 71 XComponent oComp = (XComponent) UnoRuntime.queryInterface 72 (XComponent.class, xSheetDoc) ; 73 util.DesktopTools.closeDoc(oComp); 74 } 75 76 createTestEnvironment(TestParameters Param, PrintWriter log)77 public synchronized TestEnvironment createTestEnvironment 78 (TestParameters Param, PrintWriter log){ 79 80 XInterface oObj = null; 81 TestEnvironment tEnv = null ; 82 83 try { 84 85 // creation of testobject here 86 XPropertySet props = (XPropertySet)UnoRuntime.queryInterface 87 (XPropertySet.class, xSheetDoc); 88 oObj = (XInterface) AnyConverter.toObject( 89 new Type(XInterface.class),props.getPropertyValue("AreaLinks")) ; 90 XAreaLinks links = null ; 91 92 // adding one link into collection (for best testing) 93 links = (XAreaLinks) UnoRuntime.queryInterface(XAreaLinks.class, oObj) ; 94 CellAddress addr = new CellAddress ((short) 1,2,3) ; 95 String aSourceArea = util.utils.getFullTestURL("calcshapes.sxc"); 96 links.insertAtPosition (addr, aSourceArea, "a2:b5", "", "") ; 97 98 XEnumerationAccess ea = (XEnumerationAccess) 99 UnoRuntime.queryInterface(XEnumerationAccess.class,oObj); 100 101 oObj = ea.createEnumeration(); 102 103 log.println("ImplementationName: "+util.utils.getImplName(oObj)); 104 // creating test environment 105 tEnv = new TestEnvironment(oObj); 106 107 tEnv.addObjRelation("ENUM",ea); 108 109 } catch (com.sun.star.beans.UnknownPropertyException e) { 110 log.println ("Exception occured while creating test Object.") ; 111 e.printStackTrace(log) ; 112 throw new StatusException("Couldn't create test object", e); 113 } catch (com.sun.star.lang.WrappedTargetException e) { 114 log.println ("Exception occured while creating test Object.") ; 115 e.printStackTrace(log) ; 116 throw new StatusException("Couldn't create test object", e); 117 } catch (com.sun.star.lang.IllegalArgumentException e) { 118 log.println ("Exception occured while creating test Object.") ; 119 e.printStackTrace(log) ; 120 throw new StatusException("Couldn't create test object", e); 121 } 122 123 return tEnv ; 124 } 125 126 } 127 128