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.container.XIndexAccess; 39 import com.sun.star.lang.XComponent; 40 import com.sun.star.lang.XMultiServiceFactory; 41 import com.sun.star.sheet.XSheetAnnotation; 42 import com.sun.star.sheet.XSheetAnnotationAnchor; 43 import com.sun.star.sheet.XSpreadsheet; 44 import com.sun.star.sheet.XSpreadsheetDocument; 45 import com.sun.star.sheet.XSpreadsheets; 46 import com.sun.star.table.CellAddress; 47 import com.sun.star.table.XCell; 48 import com.sun.star.table.XCellRange; 49 import com.sun.star.uno.AnyConverter; 50 import com.sun.star.uno.Type; 51 import com.sun.star.uno.UnoRuntime; 52 import com.sun.star.uno.XInterface; 53 54 /** 55 * Test for object which represents some text annotation 56 * anchored to some cell in spreadsheet (implement 57 * <code>com.sun.star.sheet.CellAnnotation</code>).<p> 58 * Object implements the following interfaces : 59 * <ul> 60 * <li> <code>com::sun::star::text::XSimpleText</code></li> 61 * <li> <code>com::sun::star::text::XTextRange</code></li> 62 * <li> <code>com::sun::star::sheet::XSheetAnnotation</code></li> 63 * </ul> 64 * This object test <b> is NOT </b> designed to be run in several 65 * threads concurently. 66 * @see com.sun.star.sheet.CellAnnotation 67 * @see com.sun.star.text.XSimpleText 68 * @see com.sun.star.text.XTextRange 69 * @see com.sun.star.sheet.XSheetAnnotation 70 * @see ifc.text._XSimpleText 71 * @see ifc.text._XTextRange 72 * @see ifc.sheet._XSheetAnnotation 73 */ 74 public class ScAnnotationObj extends TestCase { 75 static XSpreadsheetDocument xSheetDoc = null; 76 77 /** 78 * Creates a 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 a 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 spreadsheets from a document, 108 * and takes one them. Then a single cell is retrieved, and 109 * using its <code>com.sun.star.sheet.XSheetAnnotationAnchor</code> 110 * interface an annotation is got. 111 * Object relations created : 112 * <ul> 113 * <li> <code>'CELLPOS'</code> for 114 * {@link ifc.sheet._XSheetAnnotation} (of <code> 115 * com.sun.star.table.CellAddress</code> type) which 116 * contains the annotation cell address.</li> 117 * </ul> 118 */ 119 public synchronized TestEnvironment createTestEnvironment 120 ( TestParameters Param, PrintWriter log ) 121 throws StatusException { 122 123 XInterface oObj = null; 124 125 126 // creation of testobject here 127 // first we write what we are intend to do to log file 128 log.println( "Creating a test environment" ); 129 130 CellAddress cellPos = new CellAddress((short)0, 1, 2); 131 132 log.println("Getting test object ") ; 133 134 XSpreadsheetDocument xArea = (XSpreadsheetDocument) 135 UnoRuntime.queryInterface(XSpreadsheetDocument.class, xSheetDoc); 136 XSpreadsheets oSheets = (XSpreadsheets) xArea.getSheets(); 137 138 XIndexAccess XAccess = (XIndexAccess) 139 UnoRuntime.queryInterface(XIndexAccess.class, oSheets); 140 XCell oCell = null; 141 try { 142 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject( 143 new Type(XSpreadsheet.class),XAccess.getByIndex(cellPos.Sheet)); 144 XCellRange oCRange = (XCellRange) 145 UnoRuntime.queryInterface(XCellRange.class, oSheet); 146 oCell = oCRange.getCellByPosition(cellPos.Column, cellPos.Row); 147 } catch(com.sun.star.lang.WrappedTargetException e) { 148 e.printStackTrace(log); 149 throw new StatusException( 150 "Error getting test object from spreadsheet document",e); 151 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 152 e.printStackTrace(log); 153 throw new StatusException( 154 "Error getting test object from spreadsheet document",e); 155 } catch(com.sun.star.lang.IllegalArgumentException e) { 156 e.printStackTrace(log); 157 throw new StatusException( 158 "Error getting test object from spreadsheet document",e); 159 } 160 161 XSheetAnnotationAnchor oAnnoA = (XSheetAnnotationAnchor) 162 UnoRuntime.queryInterface(XSheetAnnotationAnchor.class, oCell); 163 XSheetAnnotation oAnno = oAnnoA.getAnnotation(); 164 165 oObj = oAnno; 166 167 TestEnvironment tEnv = new TestEnvironment( oObj ); 168 169 tEnv.addObjRelation("CELLPOS", cellPos); 170 171 // Other parameters required for interface tests 172 173 return tEnv; 174 } 175 176 } // finish class ScAnnotationObj 177 178 179