1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package mod._sc; 29 30 import java.io.PrintWriter; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.SOfficeFactory; 37 38 import com.sun.star.beans.XPropertySet; 39 import com.sun.star.lang.XComponent; 40 import com.sun.star.lang.XMultiServiceFactory; 41 import com.sun.star.sheet.XAreaLinks; 42 import com.sun.star.sheet.XSpreadsheetDocument; 43 import com.sun.star.table.CellAddress; 44 import com.sun.star.uno.AnyConverter; 45 import com.sun.star.uno.Type; 46 import com.sun.star.uno.UnoRuntime; 47 import com.sun.star.uno.XInterface; 48 49 /** 50 * Test for object which is represented by service 51 * <code>com.sun.star.sheet.CellAreaLink</code>. 52 * This object reflects some cell range (this range 53 * can also be from another saved document) in 54 * any range (of the same size) of the current 55 * document.<p> 56 * Object implements the following interfaces : 57 * <ul> 58 * <li> <code>com::sun::star::sheet::XAreaLink</code></li> 59 * <li> <code>com::sun::star::util::XRefreshable</code></li> 60 * <li> <code>com::sun::star::sheet::CellAreaLink</code></li> 61 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 62 * </ul> 63 * This object test <b> is NOT </b> designed to be run in several 64 * threads concurently. 65 * @see com.sun.star.sheet.XAreaLink 66 * @see com.sun.star.util.XRefreshable 67 * @see com.sun.star.sheet.CellAreaLink 68 * @see com.sun.star.beans.XPropertySet 69 * @see ifc.sheet._XAreaLink 70 * @see ifc.util._XRefreshable 71 * @see ifc.sheet._CellAreaLink 72 * @see ifc.beans._XPropertySet 73 */ 74 public class ScAreaLinkObj extends TestCase { 75 static XSpreadsheetDocument xSheetDoc = null; 76 77 /** 78 * Creates Spreadsheet document. 79 */ 80 protected void initialize( TestParameters tParam, PrintWriter log ) { 81 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 82 83 try { 84 log.println( "creating a Spreadsheet document" ); 85 xSheetDoc = SOF.createCalcDoc(null); 86 } catch ( com.sun.star.uno.Exception e ) { 87 // Some exception occures.FAILED 88 e.printStackTrace( log ); 89 throw new StatusException( "Couldn't create document", e ); 90 } 91 92 } 93 94 /** 95 * Disposes Spreadsheet document. 96 */ 97 protected void cleanup( TestParameters tParam, PrintWriter log ) { 98 log.println( " disposing xSheetDoc " ); 99 XComponent oComp = (XComponent) UnoRuntime.queryInterface 100 (XComponent.class, xSheetDoc) ; 101 util.DesktopTools.closeDoc(oComp); 102 } 103 104 105 /** 106 * Creating a Testenvironment for the interfaces to be tested. 107 * Retrieves a collection of Area Links using the 'AreaLinks' 108 * property of the Spreadsheet document. Adds a new link to this 109 * collection, which has a source in the same document. This 110 * link is passed as a tested object. 111 */ 112 public synchronized TestEnvironment createTestEnvironment 113 ( TestParameters Param, PrintWriter log ) throws StatusException { 114 115 XInterface oObj = null; 116 117 try { 118 119 // creation of testobject here 120 XPropertySet props = (XPropertySet) UnoRuntime.queryInterface 121 (XPropertySet.class, xSheetDoc); 122 XAreaLinks links = (XAreaLinks) AnyConverter.toObject( 123 new Type(XAreaLinks.class),props.getPropertyValue("AreaLinks")) ; 124 CellAddress addr = new CellAddress ((short) 1,2,3) ; 125 String aSourceArea = util.utils.getFullTestURL("calcshapes.sxc"); 126 links.insertAtPosition (addr, aSourceArea, "a2:b5", "", "") ; 127 128 oObj = (XInterface) AnyConverter.toObject( 129 new Type(XInterface.class), links.getByIndex(0)) ; 130 } catch (com.sun.star.beans.UnknownPropertyException 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.WrappedTargetException 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.IndexOutOfBoundsException 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 } catch (com.sun.star.lang.IllegalArgumentException e) { 143 log.println ("Exception occured while creating test Object.") ; 144 e.printStackTrace(log) ; 145 throw new StatusException("Couldn't create test object", e); 146 } 147 148 TestEnvironment tEnv = new TestEnvironment(oObj) ; 149 150 return tEnv; 151 } 152 } 153