2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import java
.io
.PrintWriter
;
22 import lib
.StatusException
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
28 import com
.sun
.star
.container
.XIndexAccess
;
29 import com
.sun
.star
.lang
.XComponent
;
30 import com
.sun
.star
.lang
.XMultiServiceFactory
;
31 import com
.sun
.star
.sheet
.XSpreadsheet
;
32 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
33 import com
.sun
.star
.sheet
.XSpreadsheets
;
34 import com
.sun
.star
.table
.XCell
;
35 import com
.sun
.star
.text
.XText
;
36 import com
.sun
.star
.uno
.AnyConverter
;
37 import com
.sun
.star
.uno
.Type
;
38 import com
.sun
.star
.uno
.UnoRuntime
;
39 import com
.sun
.star
.uno
.XInterface
;
42 * Test for object which is represented by service
43 * <code>com.sun.star.text.TextCursor</code>. <p>
44 * Object implements the following interfaces :
46 * <li> <code>com::sun::star::text::XTextCursor</code></li>
47 * <li> <code>com::sun::star::text::XWordCursor</code></li>
48 * <li> <code>com::sun::star::style::CharacterPropertiesComplex</code></li>
49 * <li> <code>com::sun::star::text::XTextRange</code></li>
50 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
51 * <li> <code>com::sun::star::container::XContentEnumerationAccess</code></li>
52 * <li> <code>com::sun::star::beans::XPropertyState</code></li>
53 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
54 * <li> <code>com::sun::star::text::XSentenceCursor</code></li>
55 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
56 * <li> <code>com::sun::star::text::XParagraphCursor</code></li>
57 * <li> <code>com::sun::star::document::XDocumentInsertable</code></li>
58 * <li> <code>com::sun::star::util::XSortable</code></li>
59 * <li> <code>com::sun::star::style::CharacterPropertiesAsian</code></li>
61 * @see com.sun.star.text.TextCursor
62 * @see com.sun.star.text.XTextCursor
63 * @see com.sun.star.text.XWordCursor
64 * @see com.sun.star.style.CharacterPropertiesComplex
65 * @see com.sun.star.text.XTextRange
66 * @see com.sun.star.beans.XPropertySet
67 * @see com.sun.star.container.XContentEnumerationAccess
68 * @see com.sun.star.beans.XPropertyState
69 * @see com.sun.star.style.CharacterProperties
70 * @see com.sun.star.text.XSentenceCursor
71 * @see com.sun.star.style.ParagraphProperties
72 * @see com.sun.star.text.XParagraphCursor
73 * @see com.sun.star.document.XDocumentInsertable
74 * @see com.sun.star.util.XSortable
75 * @see com.sun.star.style.CharacterPropertiesAsian
76 * @see ifc.text._XTextCursor
77 * @see ifc.text._XWordCursor
78 * @see ifc.style._CharacterPropertiesComplex
79 * @see ifc.text._XTextRange
80 * @see ifc.beans._XPropertySet
81 * @see ifc.container._XContentEnumerationAccess
82 * @see ifc.beans._XPropertyState
83 * @see ifc.style._CharacterProperties
84 * @see ifc.text._XSentenceCursor
85 * @see ifc.style._ParagraphProperties
86 * @see ifc.text._XParagraphCursor
87 * @see ifc.document._XDocumentInsertable
88 * @see ifc.util._XSortable
89 * @see ifc.style._CharacterPropertiesAsian
91 public class ScCellTextCursor
extends TestCase
{
92 private XSpreadsheetDocument xSheetDoc
= null;
95 * Creates Spreadsheet document.
97 protected void initialize( TestParameters tParam
, PrintWriter log
) {
98 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
101 log
.println( "creating a Spreadsheet document" );
102 xSheetDoc
= SOF
.createCalcDoc(null);
103 } catch ( com
.sun
.star
.uno
.Exception e
) {
104 // Some exception occurs.FAILED
105 e
.printStackTrace( log
);
106 throw new StatusException( "Couldn't create document", e
);
112 * Disposes Spreadsheet document.
114 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
115 log
.println( " disposing xSheetDoc " );
116 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
) ;
117 util
.DesktopTools
.closeDoc(oComp
);
121 * Creating a Testenvironment for the interfaces to be tested.
122 * Retrieves a collection of spreadsheets from a document
123 * and takes one of them. Retrieves the cell from the spreadsheet
124 * and creates text cursor of the cell using the interface
125 * <code>XText</code>. This text cursor is the instance of
126 * the service <code>com.sun.star.text.TextCursor</code>.
127 * Object relations created :
129 * <li> <code>'XTEXT'</code> for
130 * {@link ifc.text._XTextRange} (type of
131 * <code>XEnumerationAccess</code> that was retrieved from the
132 * collection of visible cells)</li>
134 * @see com.sun.star.text.XText
136 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
138 XInterface oObj
= null;
141 // creation of testobject here
142 // first we write what we are intend to do to log file
143 log
.println( "Creating a test environment" );
145 // get a soffice factory object
147 log
.println("Getting spreadsheet") ;
148 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
149 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
150 XSpreadsheet oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
151 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
153 log
.println("Getting a cell from sheet") ;
154 aCell
= oSheet
.getCellByPosition(1,1) ;
156 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
157 e
.printStackTrace(log
) ;
158 throw new StatusException(
159 "Error getting cell object from spreadsheet document",e
) ;
160 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
161 e
.printStackTrace(log
) ;
162 throw new StatusException(
163 "Error getting cell object from spreadsheet document",e
) ;
164 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
165 e
.printStackTrace(log
) ;
166 throw new StatusException(
167 "Error getting cell object from spreadsheet document",e
) ;
170 XText aText
= UnoRuntime
.queryInterface(XText
.class, aCell
);
171 aText
.setString("ScCellTextCursor");
172 oObj
= aText
.createTextCursor();
174 log
.println( "creating a new environment for ScCellTextCursor object" );
175 TestEnvironment tEnv
= new TestEnvironment( oObj
);
177 // Object relations for interface tests
178 tEnv
.addObjRelation("XTEXT", aText
);
181 } // finish method getTestEnvironment
183 } // finish class ScCellTextCursor