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