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.lang.XComponent; 36 import com.sun.star.lang.XMultiServiceFactory; 37 import com.sun.star.sheet.XAreaLinks; 38 import com.sun.star.sheet.XSpreadsheetDocument; 39 import com.sun.star.table.CellAddress; 40 import com.sun.star.uno.AnyConverter; 41 import com.sun.star.uno.Type; 42 import com.sun.star.uno.UnoRuntime; 43 import com.sun.star.uno.XInterface; 44 45 /** 46 * Test for object which is represented by service 47 * <code>com.sun.star.sheet.CellAreaLink</code>. 48 * This object reflects some cell range (this range 49 * can also be from another saved document) in 50 * any range (of the same size) of the current 51 * document.<p> 52 * Object implements the following interfaces : 53 * <ul> 54 * <li> <code>com::sun::star::sheet::XAreaLink</code></li> 55 * <li> <code>com::sun::star::util::XRefreshable</code></li> 56 * <li> <code>com::sun::star::sheet::CellAreaLink</code></li> 57 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 58 * </ul> 59 * This object test <b> is NOT </b> designed to be run in several 60 * threads concurently. 61 * @see com.sun.star.sheet.XAreaLink 62 * @see com.sun.star.util.XRefreshable 63 * @see com.sun.star.sheet.CellAreaLink 64 * @see com.sun.star.beans.XPropertySet 65 * @see ifc.sheet._XAreaLink 66 * @see ifc.util._XRefreshable 67 * @see ifc.sheet._CellAreaLink 68 * @see ifc.beans._XPropertySet 69 */ 70 public class ScAreaLinkObj extends TestCase { 71 static XSpreadsheetDocument xSheetDoc = null; 72 73 /** 74 * Creates Spreadsheet document. 75 */ initialize( TestParameters tParam, PrintWriter log )76 protected void initialize( TestParameters tParam, PrintWriter log ) { 77 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 78 79 try { 80 log.println( "creating a Spreadsheet document" ); 81 xSheetDoc = SOF.createCalcDoc(null); 82 } catch ( com.sun.star.uno.Exception e ) { 83 // Some exception occures.FAILED 84 e.printStackTrace( log ); 85 throw new StatusException( "Couldn't create document", e ); 86 } 87 88 } 89 90 /** 91 * Disposes Spreadsheet document. 92 */ cleanup( TestParameters tParam, PrintWriter log )93 protected void cleanup( TestParameters tParam, PrintWriter log ) { 94 log.println( " disposing xSheetDoc " ); 95 XComponent oComp = (XComponent) UnoRuntime.queryInterface 96 (XComponent.class, xSheetDoc) ; 97 util.DesktopTools.closeDoc(oComp); 98 } 99 100 101 /** 102 * Creating a Testenvironment for the interfaces to be tested. 103 * Retrieves a collection of Area Links using the 'AreaLinks' 104 * property of the Spreadsheet document. Adds a new link to this 105 * collection, which has a source in the same document. This 106 * link is passed as a tested object. 107 */ createTestEnvironment( TestParameters Param, PrintWriter log )108 public synchronized TestEnvironment createTestEnvironment 109 ( TestParameters Param, PrintWriter log ) throws StatusException { 110 111 XInterface oObj = null; 112 113 try { 114 115 // creation of testobject here 116 XPropertySet props = (XPropertySet) UnoRuntime.queryInterface 117 (XPropertySet.class, xSheetDoc); 118 XAreaLinks links = (XAreaLinks) AnyConverter.toObject( 119 new Type(XAreaLinks.class),props.getPropertyValue("AreaLinks")) ; 120 CellAddress addr = new CellAddress ((short) 1,2,3) ; 121 String aSourceArea = util.utils.getFullTestURL("calcshapes.sxc"); 122 links.insertAtPosition (addr, aSourceArea, "a2:b5", "", "") ; 123 124 oObj = (XInterface) AnyConverter.toObject( 125 new Type(XInterface.class), links.getByIndex(0)) ; 126 } catch (com.sun.star.beans.UnknownPropertyException e) { 127 log.println ("Exception occured while creating test Object.") ; 128 e.printStackTrace(log) ; 129 throw new StatusException("Couldn't create test object", e); 130 } catch (com.sun.star.lang.WrappedTargetException e) { 131 log.println ("Exception occured while creating test Object.") ; 132 e.printStackTrace(log) ; 133 throw new StatusException("Couldn't create test object", e); 134 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 135 log.println ("Exception occured while creating test Object.") ; 136 e.printStackTrace(log) ; 137 throw new StatusException("Couldn't create test object", e); 138 } catch (com.sun.star.lang.IllegalArgumentException e) { 139 log.println ("Exception occured while creating test Object.") ; 140 e.printStackTrace(log) ; 141 throw new StatusException("Couldn't create test object", e); 142 } 143 144 TestEnvironment tEnv = new TestEnvironment(oObj) ; 145 146 return tEnv; 147 } 148 } 149