merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScAnnotationsObj.java
blob26ba2fb03b82b804b0fa305ccd75f13381365be8
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: ScAnnotationsObj.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.XNameAccess;
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.XSheetAnnotationsSupplier;
47 import com.sun.star.sheet.XSpreadsheet;
48 import com.sun.star.sheet.XSpreadsheetDocument;
49 import com.sun.star.sheet.XSpreadsheets;
50 import com.sun.star.table.XCell;
51 import com.sun.star.table.XCellRange;
52 import com.sun.star.text.XSimpleText;
53 import com.sun.star.uno.AnyConverter;
54 import com.sun.star.uno.Type;
55 import com.sun.star.uno.UnoRuntime;
56 import com.sun.star.uno.XInterface;
58 /**
59 * Test for object which represents a collection of annotations
60 * for a spreadsheet document (implements
61 * <code>com.sun.star.sheet.CellAnnotations</code>). <p>
62 * Object implements the following interfaces :
63 * <ul>
64 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
65 * <li> <code>com::sun::star::container::XElementAccess</code></li>
66 * <li> <code>com::sun::star::sheet::XSheetAnnotations</code></li>
67 * </ul> <p>
68 * This object test <b> is NOT </b> designed to be run in several
69 * threads concurently.
70 * @see com.sun.star.sheet.CellAnnotations
71 * @see com.sun.star.container.XIndexAccess
72 * @see com.sun.star.container.XElementAccess
73 * @see com.sun.star.sheet.XSheetAnnotations
74 * @see ifc.container._XIndexAccess
75 * @see ifc.container._XElementAccess
76 * @see ifc.sheet._XSheetAnnotations
78 public class ScAnnotationsObj extends TestCase {
79 static XSpreadsheetDocument xSheetDoc = null;
81 /**
82 * Creates Spreadsheet document.
84 protected void initialize( TestParameters tParam, PrintWriter log ) {
85 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
87 try {
88 log.println( "creating a Spreadsheet document" );
89 xSheetDoc = SOF.createCalcDoc(null);
90 } catch ( com.sun.star.uno.Exception e ) {
91 // Some exception occures.FAILED
92 e.printStackTrace( log );
93 throw new StatusException( "Couldn't create document", e );
98 /**
99 * Disposes Spreadsheet document.
101 protected void cleanup( TestParameters tParam, PrintWriter log ) {
102 log.println( " disposing xSheetDoc " );
103 XComponent oComp = (XComponent)
104 UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
105 util.DesktopTools.closeDoc(oComp);
109 * Creating a Testenvironment for the interfaces to be tested.
110 * From a document collection of spreadsheets a single one is
111 * retrieved and one annotation is added to it. Then a collection
112 * of annotations is retrieved using spreadsheet's
113 * <code>com.sun.star.sheet.XSheetAnnotationsSupplier</code> interface.
115 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
117 XInterface oObj = null;
119 // creation of testobject here
120 // first we write what we are intend to do to log file
121 log.println( "Creating a test environment" );
123 log.println("Getting test object ") ;
125 XSpreadsheetDocument xSpreadsheetDoc = (XSpreadsheetDocument)
126 UnoRuntime.queryInterface(XSpreadsheetDocument.class, xSheetDoc);
127 XSpreadsheets sheets = (XSpreadsheets) xSpreadsheetDoc.getSheets();
129 XNameAccess oNames = (XNameAccess)
130 UnoRuntime.queryInterface( XNameAccess.class, sheets );
131 XCell oCell = null;
132 XSpreadsheet oSheet = null;
133 try {
134 oSheet = (XSpreadsheet) AnyConverter.toObject(
135 new Type(XSpreadsheet.class),
136 oNames.getByName(oNames.getElementNames()[0]));
137 // adding an annotation...
138 XCellRange oCRange = (XCellRange)
139 UnoRuntime.queryInterface(XCellRange.class, oSheet);
140 oCell = oCRange.getCellByPosition(10,10);
141 } catch (com.sun.star.lang.WrappedTargetException e) {
142 e.printStackTrace(log);
143 throw new StatusException(
144 "Error getting test object from spreadsheet document",e);
145 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
146 e.printStackTrace(log) ;
147 throw new StatusException(
148 "Error getting test object from spreadsheet document",e) ;
149 } catch (com.sun.star.container.NoSuchElementException e) {
150 e.printStackTrace(log) ;
151 throw new StatusException(
152 "Error getting test object from spreadsheet document",e) ;
153 } catch (com.sun.star.lang.IllegalArgumentException e) {
154 e.printStackTrace(log) ;
155 throw new StatusException(
156 "Error getting test object from spreadsheet document",e) ;
159 XSheetAnnotationAnchor oAnnoA = (XSheetAnnotationAnchor)
160 UnoRuntime.queryInterface(XSheetAnnotationAnchor.class, oCell);
161 XSheetAnnotation oAnno = oAnnoA.getAnnotation();
162 XSimpleText sText = ((XSimpleText)
163 UnoRuntime.queryInterface(XSimpleText.class, oAnno));
164 sText.setString("ScAnnotationsObj");
166 XSheetAnnotationsSupplier supp = (XSheetAnnotationsSupplier)
167 UnoRuntime.queryInterface(
168 XSheetAnnotationsSupplier.class, oSheet);
169 oObj = supp.getAnnotations();
171 TestEnvironment tEnv = new TestEnvironment( oObj );
173 return tEnv;
176 } // finish class ScAnnotationsObj