1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir package mod._sc; 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir import com.sun.star.container.XIndexAccess; 30*cdf0e10cSrcweir import com.sun.star.lang.XComponent; 31*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 32*cdf0e10cSrcweir import com.sun.star.sheet.XSheetAnnotation; 33*cdf0e10cSrcweir import com.sun.star.sheet.XSheetAnnotationAnchor; 34*cdf0e10cSrcweir import com.sun.star.sheet.XSheetAnnotationShapeSupplier; 35*cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheet; 36*cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheetDocument; 37*cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheets; 38*cdf0e10cSrcweir import com.sun.star.table.CellAddress; 39*cdf0e10cSrcweir import com.sun.star.table.XCell; 40*cdf0e10cSrcweir import com.sun.star.table.XCellRange; 41*cdf0e10cSrcweir import com.sun.star.text.XSimpleText; 42*cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 43*cdf0e10cSrcweir import com.sun.star.uno.Type; 44*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 45*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir import lib.StatusException; 48*cdf0e10cSrcweir import lib.TestCase; 49*cdf0e10cSrcweir import lib.TestEnvironment; 50*cdf0e10cSrcweir import lib.TestParameters; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir import util.SOfficeFactory; 53*cdf0e10cSrcweir import util.utils; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir import java.io.PrintWriter; 56*cdf0e10cSrcweir import util.DefaultDsc; 57*cdf0e10cSrcweir import util.InstCreator; 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir /** 61*cdf0e10cSrcweir * Test for object which represents some text annotation 62*cdf0e10cSrcweir * anchored to some cell in spreadsheet (implement 63*cdf0e10cSrcweir * <code>com.sun.star.sheet.CellAnnotation</code>).<p> 64*cdf0e10cSrcweir * Object implements the following interfaces : 65*cdf0e10cSrcweir * <ul> 66*cdf0e10cSrcweir * <li> <code>com::sun::star::text::XSimpleText</code></li> 67*cdf0e10cSrcweir * <li> <code>com::sun::star::text::XTextRange</code></li> 68*cdf0e10cSrcweir * <li> <code>com::sun::star::sheet::XSheetAnnotation</code></li> 69*cdf0e10cSrcweir * </ul> 70*cdf0e10cSrcweir * This object test <b> is NOT </b> designed to be run in several 71*cdf0e10cSrcweir * threads concurently. 72*cdf0e10cSrcweir * @see com.sun.star.sheet.CellAnnotation 73*cdf0e10cSrcweir * @see com.sun.star.text.XSimpleText 74*cdf0e10cSrcweir * @see com.sun.star.text.XTextRange 75*cdf0e10cSrcweir * @see com.sun.star.sheet.XSheetAnnotation 76*cdf0e10cSrcweir * @see ifc.text._XSimpleText 77*cdf0e10cSrcweir * @see ifc.text._XTextRange 78*cdf0e10cSrcweir * @see ifc.sheet._XSheetAnnotation 79*cdf0e10cSrcweir */ 80*cdf0e10cSrcweir public class ScAnnotationShapeObj extends TestCase { 81*cdf0e10cSrcweir static XSpreadsheetDocument xSheetDoc = null; 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir /** 84*cdf0e10cSrcweir * Creates a spreadsheet document. 85*cdf0e10cSrcweir */ 86*cdf0e10cSrcweir protected void initialize(TestParameters tParam, PrintWriter log) { 87*cdf0e10cSrcweir SOfficeFactory SOF = 88*cdf0e10cSrcweir SOfficeFactory.getFactory((XMultiServiceFactory) tParam 89*cdf0e10cSrcweir .getMSF()); 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir try { 92*cdf0e10cSrcweir log.println("creating a Spreadsheet document"); 93*cdf0e10cSrcweir log.println("Loading: "+utils.getFullTestURL( 94*cdf0e10cSrcweir "ScAnnotationShapeObj.sxc")); 95*cdf0e10cSrcweir xSheetDoc = 96*cdf0e10cSrcweir (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, 97*cdf0e10cSrcweir SOF.loadDocument(utils.getFullTestURL( 98*cdf0e10cSrcweir "ScAnnotationShapeObj.sxc"))); 99*cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 100*cdf0e10cSrcweir // Some exception occures.FAILED 101*cdf0e10cSrcweir e.printStackTrace(log); 102*cdf0e10cSrcweir throw new StatusException("Couldn't create document", e); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir /** 107*cdf0e10cSrcweir * Disposes a spreadsheet document. 108*cdf0e10cSrcweir */ 109*cdf0e10cSrcweir protected void cleanup(TestParameters tParam, PrintWriter log) { 110*cdf0e10cSrcweir log.println(" disposing xSheetDoc "); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir XComponent oComp = 113*cdf0e10cSrcweir (XComponent) UnoRuntime.queryInterface(XComponent.class, 114*cdf0e10cSrcweir xSheetDoc); 115*cdf0e10cSrcweir util.DesktopTools.closeDoc(oComp); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir /** 119*cdf0e10cSrcweir * Creating a Testenvironment for the interfaces to be tested. 120*cdf0e10cSrcweir * Retrieves a collection of spreadsheets from a document, 121*cdf0e10cSrcweir * and takes one them. Then a single cell is retrieved, and 122*cdf0e10cSrcweir * using its <code>com.sun.star.sheet.XSheetAnnotationAnchor</code> 123*cdf0e10cSrcweir * interface an annotation is got. 124*cdf0e10cSrcweir * Object relations created : 125*cdf0e10cSrcweir * <ul> 126*cdf0e10cSrcweir * <li> <code>'CELLPOS'</code> for 127*cdf0e10cSrcweir * {@link ifc.sheet._XSheetAnnotation} (of <code> 128*cdf0e10cSrcweir * com.sun.star.table.CellAddress</code> type) which 129*cdf0e10cSrcweir * contains the annotation cell address.</li> 130*cdf0e10cSrcweir * </ul> 131*cdf0e10cSrcweir */ 132*cdf0e10cSrcweir public synchronized TestEnvironment createTestEnvironment( 133*cdf0e10cSrcweir TestParameters Param, PrintWriter log) throws StatusException { 134*cdf0e10cSrcweir XInterface oObj = null; 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir // creation of testobject here 137*cdf0e10cSrcweir // first we write what we are intend to do to log file 138*cdf0e10cSrcweir log.println("Creating a test environment"); 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir CellAddress cellPos = new CellAddress((short) 0, 1, 2); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir log.println("Getting test object "); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir XSpreadsheetDocument xArea = 145*cdf0e10cSrcweir (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, 146*cdf0e10cSrcweir xSheetDoc); 147*cdf0e10cSrcweir XSpreadsheets oSheets = (XSpreadsheets) xArea.getSheets(); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir XIndexAccess XAccess = 150*cdf0e10cSrcweir (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, 151*cdf0e10cSrcweir oSheets); 152*cdf0e10cSrcweir XCell oCell = null; 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir try { 155*cdf0e10cSrcweir XSpreadsheet oSheet = 156*cdf0e10cSrcweir (XSpreadsheet) AnyConverter.toObject(new Type( 157*cdf0e10cSrcweir XSpreadsheet.class), 158*cdf0e10cSrcweir XAccess.getByIndex(cellPos.Sheet)); 159*cdf0e10cSrcweir XCellRange oCRange = 160*cdf0e10cSrcweir (XCellRange) UnoRuntime.queryInterface(XCellRange.class, 161*cdf0e10cSrcweir oSheet); 162*cdf0e10cSrcweir oCell = 163*cdf0e10cSrcweir oCRange.getCellByPosition(cellPos.Column, cellPos.Row); 164*cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 165*cdf0e10cSrcweir e.printStackTrace(log); 166*cdf0e10cSrcweir throw new StatusException("Error getting test object from spreadsheet document", 167*cdf0e10cSrcweir e); 168*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 169*cdf0e10cSrcweir e.printStackTrace(log); 170*cdf0e10cSrcweir throw new StatusException("Error getting test object from spreadsheet document", 171*cdf0e10cSrcweir e); 172*cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 173*cdf0e10cSrcweir e.printStackTrace(log); 174*cdf0e10cSrcweir throw new StatusException("Error getting test object from spreadsheet document", 175*cdf0e10cSrcweir e); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir XSheetAnnotationAnchor oAnnoA = 179*cdf0e10cSrcweir (XSheetAnnotationAnchor) UnoRuntime.queryInterface(XSheetAnnotationAnchor.class, 180*cdf0e10cSrcweir oCell); 181*cdf0e10cSrcweir XSheetAnnotation oAnno = oAnnoA.getAnnotation(); 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir XSimpleText xAnnoText = 184*cdf0e10cSrcweir (XSimpleText) UnoRuntime.queryInterface(XSimpleText.class, 185*cdf0e10cSrcweir oAnno); 186*cdf0e10cSrcweir xAnnoText.setString("ScAnnotationShapeObj"); 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir XSheetAnnotationShapeSupplier xSheetAnnotationShapeSupplier = 189*cdf0e10cSrcweir (XSheetAnnotationShapeSupplier) UnoRuntime.queryInterface(XSheetAnnotationShapeSupplier.class, 190*cdf0e10cSrcweir oAnno); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir oObj = xSheetAnnotationShapeSupplier.getAnnotationShape(); 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir log.println("ImplementationName: " 195*cdf0e10cSrcweir + util.utils.getImplName(oObj)); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment(oObj); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir //adding ObjRelation for RotationDescriptor 200*cdf0e10cSrcweir tEnv.addObjRelation("NoShear", Boolean.TRUE); 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir //adding ObjRelation for XText 203*cdf0e10cSrcweir DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent", 204*cdf0e10cSrcweir "com.sun.star.text.TextField.DateTime"); 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir log.println( "adding InstCreator object" ); 207*cdf0e10cSrcweir tEnv.addObjRelation( 208*cdf0e10cSrcweir "XTEXTINFO", new InstCreator( xSheetDoc, tDsc ) ); 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir return tEnv; 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir // finish class ScAnnotationShapeObj 214