merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScCellTextCursor.java
blob56801d8e630ffae2be3e6314b3d75f606bbe25fe
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: ScCellTextCursor.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 ************************************************************************/
30 package mod._sc;
32 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
38 import util.SOfficeFactory;
40 import com.sun.star.container.XIndexAccess;
41 import com.sun.star.lang.XComponent;
42 import com.sun.star.lang.XMultiServiceFactory;
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.XCell;
47 import com.sun.star.text.XText;
48 import com.sun.star.uno.AnyConverter;
49 import com.sun.star.uno.Type;
50 import com.sun.star.uno.UnoRuntime;
51 import com.sun.star.uno.XInterface;
53 /**
54 * Test for object which is represented by service
55 * <code>com.sun.star.text.TextCursor</code>. <p>
56 * Object implements the following interfaces :
57 * <ul>
58 * <li> <code>com::sun::star::text::XTextCursor</code></li>
59 * <li> <code>com::sun::star::text::XWordCursor</code></li>
60 * <li> <code>com::sun::star::style::CharacterPropertiesComplex</code></li>
61 * <li> <code>com::sun::star::text::XTextRange</code></li>
62 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
63 * <li> <code>com::sun::star::container::XContentEnumerationAccess</code></li>
64 * <li> <code>com::sun::star::beans::XPropertyState</code></li>
65 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
66 * <li> <code>com::sun::star::text::XSentenceCursor</code></li>
67 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
68 * <li> <code>com::sun::star::text::XParagraphCursor</code></li>
69 * <li> <code>com::sun::star::document::XDocumentInsertable</code></li>
70 * <li> <code>com::sun::star::util::XSortable</code></li>
71 * <li> <code>com::sun::star::style::CharacterPropertiesAsian</code></li>
72 * </ul>
73 * @see com.sun.star.text.TextCursor
74 * @see com.sun.star.text.XTextCursor
75 * @see com.sun.star.text.XWordCursor
76 * @see com.sun.star.style.CharacterPropertiesComplex
77 * @see com.sun.star.text.XTextRange
78 * @see com.sun.star.beans.XPropertySet
79 * @see com.sun.star.container.XContentEnumerationAccess
80 * @see com.sun.star.beans.XPropertyState
81 * @see com.sun.star.style.CharacterProperties
82 * @see com.sun.star.text.XSentenceCursor
83 * @see com.sun.star.style.ParagraphProperties
84 * @see com.sun.star.text.XParagraphCursor
85 * @see com.sun.star.document.XDocumentInsertable
86 * @see com.sun.star.util.XSortable
87 * @see com.sun.star.style.CharacterPropertiesAsian
88 * @see ifc.text._XTextCursor
89 * @see ifc.text._XWordCursor
90 * @see ifc.style._CharacterPropertiesComplex
91 * @see ifc.text._XTextRange
92 * @see ifc.beans._XPropertySet
93 * @see ifc.container._XContentEnumerationAccess
94 * @see ifc.beans._XPropertyState
95 * @see ifc.style._CharacterProperties
96 * @see ifc.text._XSentenceCursor
97 * @see ifc.style._ParagraphProperties
98 * @see ifc.text._XParagraphCursor
99 * @see ifc.document._XDocumentInsertable
100 * @see ifc.util._XSortable
101 * @see ifc.style._CharacterPropertiesAsian
103 public class ScCellTextCursor extends TestCase {
104 static XSpreadsheetDocument xSheetDoc = null;
107 * Creates Spreadsheet document.
109 protected void initialize( TestParameters tParam, PrintWriter log ) {
110 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
112 try {
113 log.println( "creating a Spreadsheet document" );
114 xSheetDoc = SOF.createCalcDoc(null);
115 } catch ( com.sun.star.uno.Exception e ) {
116 // Some exception occures.FAILED
117 e.printStackTrace( log );
118 throw new StatusException( "Couldn't create document", e );
124 * Disposes Spreadsheet document.
126 protected void cleanup( TestParameters tParam, PrintWriter log ) {
127 log.println( " disposing xSheetDoc " );
128 XComponent oComp = (XComponent)
129 UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
130 util.DesktopTools.closeDoc(oComp);
134 * Creating a Testenvironment for the interfaces to be tested.
135 * Retrieves a collection of spreadsheets from a document
136 * and takes one of them. Retrieves the cell from the spreadsheet
137 * and creates text cursor of the cell using the interface
138 * <code>XText</code>. This text cursor is the instance of
139 * the service <code>com.sun.star.text.TextCursor</code>.
140 * Object relations created :
141 * <ul>
142 * <li> <code>'XTEXT'</code> for
143 * {@link ifc.text._XTextRange} (type of
144 * <code>XEnumerationAccess</code> that was retrieved from the
145 * collection of visible cells)</li>
146 * </ul>
147 * @see com.sun.star.text.XText
149 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
151 XInterface oObj = null;
152 XCell aCell = null;
154 // creation of testobject here
155 // first we write what we are intend to do to log file
156 log.println( "Creating a test environment" );
158 // get a soffice factory object
159 try {
160 log.println("Getting spreadsheet") ;
161 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
162 XIndexAccess oIndexSheets = (XIndexAccess)
163 UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
164 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
165 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
167 log.println("Getting a cell from sheet") ;
168 aCell = oSheet.getCellByPosition(1,1) ;
170 } catch (com.sun.star.lang.WrappedTargetException e) {
171 e.printStackTrace(log) ;
172 throw new StatusException(
173 "Error getting cell object from spreadsheet document",e) ;
174 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
175 e.printStackTrace(log) ;
176 throw new StatusException(
177 "Error getting cell object from spreadsheet document",e) ;
178 } catch (com.sun.star.lang.IllegalArgumentException e) {
179 e.printStackTrace(log) ;
180 throw new StatusException(
181 "Error getting cell object from spreadsheet document",e) ;
184 XText aText = (XText) UnoRuntime.queryInterface(XText.class, aCell);
185 aText.setString("ScCellTextCursor");
186 oObj = aText.createTextCursor();
188 log.println( "creating a new environment for ScCellTextCursor object" );
189 TestEnvironment tEnv = new TestEnvironment( oObj );
191 // Object relations for interface tests
192 tEnv.addObjRelation("XTEXT", aText);
194 return tEnv;
195 } // finish method getTestEnvironment
197 } // finish class ScCellTextCursor