merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScAnnotationObj.java
blobae0ccf7d0f7526138f0806a7c305464405a227ee
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScAnnotationObj.java,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._sc;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.SOfficeFactory;
41 import com.sun.star.container.XIndexAccess;
42 import com.sun.star.lang.XComponent;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.sheet.XSheetAnnotation;
45 import com.sun.star.sheet.XSheetAnnotationAnchor;
46 import com.sun.star.sheet.XSpreadsheet;
47 import com.sun.star.sheet.XSpreadsheetDocument;
48 import com.sun.star.sheet.XSpreadsheets;
49 import com.sun.star.table.CellAddress;
50 import com.sun.star.table.XCell;
51 import com.sun.star.table.XCellRange;
52 import com.sun.star.uno.AnyConverter;
53 import com.sun.star.uno.Type;
54 import com.sun.star.uno.UnoRuntime;
55 import com.sun.star.uno.XInterface;
57 /**
58 * Test for object which represents some text annotation
59 * anchored to some cell in spreadsheet (implement
60 * <code>com.sun.star.sheet.CellAnnotation</code>).<p>
61 * Object implements the following interfaces :
62 * <ul>
63 * <li> <code>com::sun::star::text::XSimpleText</code></li>
64 * <li> <code>com::sun::star::text::XTextRange</code></li>
65 * <li> <code>com::sun::star::sheet::XSheetAnnotation</code></li>
66 * </ul>
67 * This object test <b> is NOT </b> designed to be run in several
68 * threads concurently.
69 * @see com.sun.star.sheet.CellAnnotation
70 * @see com.sun.star.text.XSimpleText
71 * @see com.sun.star.text.XTextRange
72 * @see com.sun.star.sheet.XSheetAnnotation
73 * @see ifc.text._XSimpleText
74 * @see ifc.text._XTextRange
75 * @see ifc.sheet._XSheetAnnotation
77 public class ScAnnotationObj extends TestCase {
78 static XSpreadsheetDocument xSheetDoc = null;
80 /**
81 * Creates a spreadsheet document.
83 protected void initialize( TestParameters tParam, PrintWriter log ) {
84 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
86 try {
87 log.println( "creating a Spreadsheet document" );
88 xSheetDoc = SOF.createCalcDoc(null);
89 } catch ( com.sun.star.uno.Exception e ) {
90 // Some exception occures.FAILED
91 e.printStackTrace( log );
92 throw new StatusException( "Couldn't create document", e );
97 /**
98 * Disposes a spreadsheet document.
100 protected void cleanup( TestParameters tParam, PrintWriter log ) {
101 log.println( " disposing xSheetDoc " );
102 XComponent oComp = (XComponent) UnoRuntime.queryInterface
103 (XComponent.class, xSheetDoc) ;
104 util.DesktopTools.closeDoc(oComp);
109 * Creating a Testenvironment for the interfaces to be tested.
110 * Retrieves a collection of spreadsheets from a document,
111 * and takes one them. Then a single cell is retrieved, and
112 * using its <code>com.sun.star.sheet.XSheetAnnotationAnchor</code>
113 * interface an annotation is got.
114 * Object relations created :
115 * <ul>
116 * <li> <code>'CELLPOS'</code> for
117 * {@link ifc.sheet._XSheetAnnotation} (of <code>
118 * com.sun.star.table.CellAddress</code> type) which
119 * contains the annotation cell address.</li>
120 * </ul>
122 public synchronized TestEnvironment createTestEnvironment
123 ( TestParameters Param, PrintWriter log )
124 throws StatusException {
126 XInterface oObj = null;
129 // creation of testobject here
130 // first we write what we are intend to do to log file
131 log.println( "Creating a test environment" );
133 CellAddress cellPos = new CellAddress((short)0, 1, 2);
135 log.println("Getting test object ") ;
137 XSpreadsheetDocument xArea = (XSpreadsheetDocument)
138 UnoRuntime.queryInterface(XSpreadsheetDocument.class, xSheetDoc);
139 XSpreadsheets oSheets = (XSpreadsheets) xArea.getSheets();
141 XIndexAccess XAccess = (XIndexAccess)
142 UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
143 XCell oCell = null;
144 try {
145 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
146 new Type(XSpreadsheet.class),XAccess.getByIndex(cellPos.Sheet));
147 XCellRange oCRange = (XCellRange)
148 UnoRuntime.queryInterface(XCellRange.class, oSheet);
149 oCell = oCRange.getCellByPosition(cellPos.Column, cellPos.Row);
150 } catch(com.sun.star.lang.WrappedTargetException e) {
151 e.printStackTrace(log);
152 throw new StatusException(
153 "Error getting test object from spreadsheet document",e);
154 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
155 e.printStackTrace(log);
156 throw new StatusException(
157 "Error getting test object from spreadsheet document",e);
158 } catch(com.sun.star.lang.IllegalArgumentException e) {
159 e.printStackTrace(log);
160 throw new StatusException(
161 "Error getting test object from spreadsheet document",e);
164 XSheetAnnotationAnchor oAnnoA = (XSheetAnnotationAnchor)
165 UnoRuntime.queryInterface(XSheetAnnotationAnchor.class, oCell);
166 XSheetAnnotation oAnno = oAnnoA.getAnnotation();
168 oObj = oAnno;
170 TestEnvironment tEnv = new TestEnvironment( oObj );
172 tEnv.addObjRelation("CELLPOS", cellPos);
174 // Other parameters required for interface tests
176 return tEnv;
179 } // finish class ScAnnotationObj