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