xref: /AOO41X/main/qadevOOo/tests/java/mod/_sc/ScCellTextCursor.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package mod._sc;
28 
29 import java.io.PrintWriter;
30 
31 import lib.StatusException;
32 import lib.TestCase;
33 import lib.TestEnvironment;
34 import lib.TestParameters;
35 import util.SOfficeFactory;
36 
37 import com.sun.star.container.XIndexAccess;
38 import com.sun.star.lang.XComponent;
39 import com.sun.star.lang.XMultiServiceFactory;
40 import com.sun.star.sheet.XSpreadsheet;
41 import com.sun.star.sheet.XSpreadsheetDocument;
42 import com.sun.star.sheet.XSpreadsheets;
43 import com.sun.star.table.XCell;
44 import com.sun.star.text.XText;
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 is represented by service
52 * <code>com.sun.star.text.TextCursor</code>. <p>
53 * Object implements the following interfaces :
54 * <ul>
55 *  <li> <code>com::sun::star::text::XTextCursor</code></li>
56 *  <li> <code>com::sun::star::text::XWordCursor</code></li>
57 *  <li> <code>com::sun::star::style::CharacterPropertiesComplex</code></li>
58 *  <li> <code>com::sun::star::text::XTextRange</code></li>
59 *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
60 *  <li> <code>com::sun::star::container::XContentEnumerationAccess</code></li>
61 *  <li> <code>com::sun::star::beans::XPropertyState</code></li>
62 *  <li> <code>com::sun::star::style::CharacterProperties</code></li>
63 *  <li> <code>com::sun::star::text::XSentenceCursor</code></li>
64 *  <li> <code>com::sun::star::style::ParagraphProperties</code></li>
65 *  <li> <code>com::sun::star::text::XParagraphCursor</code></li>
66 *  <li> <code>com::sun::star::document::XDocumentInsertable</code></li>
67 *  <li> <code>com::sun::star::util::XSortable</code></li>
68 *  <li> <code>com::sun::star::style::CharacterPropertiesAsian</code></li>
69 * </ul>
70 * @see com.sun.star.text.TextCursor
71 * @see com.sun.star.text.XTextCursor
72 * @see com.sun.star.text.XWordCursor
73 * @see com.sun.star.style.CharacterPropertiesComplex
74 * @see com.sun.star.text.XTextRange
75 * @see com.sun.star.beans.XPropertySet
76 * @see com.sun.star.container.XContentEnumerationAccess
77 * @see com.sun.star.beans.XPropertyState
78 * @see com.sun.star.style.CharacterProperties
79 * @see com.sun.star.text.XSentenceCursor
80 * @see com.sun.star.style.ParagraphProperties
81 * @see com.sun.star.text.XParagraphCursor
82 * @see com.sun.star.document.XDocumentInsertable
83 * @see com.sun.star.util.XSortable
84 * @see com.sun.star.style.CharacterPropertiesAsian
85 * @see ifc.text._XTextCursor
86 * @see ifc.text._XWordCursor
87 * @see ifc.style._CharacterPropertiesComplex
88 * @see ifc.text._XTextRange
89 * @see ifc.beans._XPropertySet
90 * @see ifc.container._XContentEnumerationAccess
91 * @see ifc.beans._XPropertyState
92 * @see ifc.style._CharacterProperties
93 * @see ifc.text._XSentenceCursor
94 * @see ifc.style._ParagraphProperties
95 * @see ifc.text._XParagraphCursor
96 * @see ifc.document._XDocumentInsertable
97 * @see ifc.util._XSortable
98 * @see ifc.style._CharacterPropertiesAsian
99 */
100 public class ScCellTextCursor extends TestCase {
101     static XSpreadsheetDocument xSheetDoc = null;
102 
103     /**
104     * Creates Spreadsheet document.
105     */
106     protected void initialize( TestParameters tParam, PrintWriter log ) {
107         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
108 
109         try {
110             log.println( "creating a Spreadsheet document" );
111             xSheetDoc = SOF.createCalcDoc(null);
112         } catch ( com.sun.star.uno.Exception e ) {
113             // Some exception occures.FAILED
114             e.printStackTrace( log );
115             throw new StatusException( "Couldn't create document", e );
116         }
117 
118     }
119 
120     /**
121     * Disposes Spreadsheet document.
122     */
123     protected void cleanup( TestParameters tParam, PrintWriter log ) {
124         log.println( "    disposing xSheetDoc " );
125         XComponent oComp = (XComponent)
126             UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
127         util.DesktopTools.closeDoc(oComp);
128     }
129 
130     /**
131     * Creating a Testenvironment for the interfaces to be tested.
132     * Retrieves a collection of spreadsheets from a document
133     * and takes one of them. Retrieves the cell from the spreadsheet
134     * and creates text cursor of the cell using the interface
135     * <code>XText</code>. This text cursor is the instance of
136     * the service <code>com.sun.star.text.TextCursor</code>.
137     * Object relations created :
138     * <ul>
139     *  <li> <code>'XTEXT'</code> for
140     *      {@link ifc.text._XTextRange} (type of
141     *      <code>XEnumerationAccess</code> that was retrieved from the
142     *      collection of visible cells)</li>
143     * </ul>
144     * @see com.sun.star.text.XText
145     */
146     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
147 
148         XInterface oObj = null;
149         XCell aCell = null;
150 
151         // creation of testobject here
152         // first we write what we are intend to do to log file
153         log.println( "Creating a test environment" );
154 
155         // get a soffice factory object
156         try {
157             log.println("Getting spreadsheet") ;
158             XSpreadsheets oSheets = xSheetDoc.getSheets() ;
159             XIndexAccess oIndexSheets = (XIndexAccess)
160                 UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
161             XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
162                     new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
163 
164             log.println("Getting a cell from sheet") ;
165             aCell = oSheet.getCellByPosition(1,1) ;
166 
167         } catch (com.sun.star.lang.WrappedTargetException e) {
168             e.printStackTrace(log) ;
169             throw new StatusException(
170                 "Error getting cell object from spreadsheet document",e) ;
171         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
172             e.printStackTrace(log) ;
173             throw new StatusException(
174                 "Error getting cell object from spreadsheet document",e) ;
175         } catch (com.sun.star.lang.IllegalArgumentException e) {
176             e.printStackTrace(log) ;
177             throw new StatusException(
178                 "Error getting cell object from spreadsheet document",e) ;
179         }
180 
181         XText aText = (XText) UnoRuntime.queryInterface(XText.class, aCell);
182         aText.setString("ScCellTextCursor");
183         oObj = aText.createTextCursor();
184 
185         log.println( "creating a new environment for ScCellTextCursor object" );
186         TestEnvironment tEnv = new TestEnvironment( oObj );
187 
188         // Object relations for interface tests
189         tEnv.addObjRelation("XTEXT", aText);
190 
191         return tEnv;
192     } // finish method getTestEnvironment
193 
194 }    // finish class ScCellTextCursor
195 
196