Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScCellTextCursor.java
blobe0e99ecedbe71ffdb03eae832ff9313c5d7677de
1 /*
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 .
18 package mod._sc;
20 import java.io.PrintWriter;
22 import lib.StatusException;
23 import lib.TestCase;
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.sheet.XSpreadsheet;
31 import com.sun.star.sheet.XSpreadsheetDocument;
32 import com.sun.star.sheet.XSpreadsheets;
33 import com.sun.star.table.XCell;
34 import com.sun.star.text.XText;
35 import com.sun.star.uno.AnyConverter;
36 import com.sun.star.uno.Type;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
40 /**
41 * Test for object which is represented by service
42 * <code>com.sun.star.text.TextCursor</code>. <p>
43 * Object implements the following interfaces :
44 * <ul>
45 * <li> <code>com::sun::star::text::XTextCursor</code></li>
46 * <li> <code>com::sun::star::text::XWordCursor</code></li>
47 * <li> <code>com::sun::star::style::CharacterPropertiesComplex</code></li>
48 * <li> <code>com::sun::star::text::XTextRange</code></li>
49 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
50 * <li> <code>com::sun::star::container::XContentEnumerationAccess</code></li>
51 * <li> <code>com::sun::star::beans::XPropertyState</code></li>
52 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
53 * <li> <code>com::sun::star::text::XSentenceCursor</code></li>
54 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
55 * <li> <code>com::sun::star::text::XParagraphCursor</code></li>
56 * <li> <code>com::sun::star::document::XDocumentInsertable</code></li>
57 * <li> <code>com::sun::star::util::XSortable</code></li>
58 * <li> <code>com::sun::star::style::CharacterPropertiesAsian</code></li>
59 * </ul>
60 * @see com.sun.star.text.TextCursor
61 * @see com.sun.star.text.XTextCursor
62 * @see com.sun.star.text.XWordCursor
63 * @see com.sun.star.style.CharacterPropertiesComplex
64 * @see com.sun.star.text.XTextRange
65 * @see com.sun.star.beans.XPropertySet
66 * @see com.sun.star.container.XContentEnumerationAccess
67 * @see com.sun.star.beans.XPropertyState
68 * @see com.sun.star.style.CharacterProperties
69 * @see com.sun.star.text.XSentenceCursor
70 * @see com.sun.star.style.ParagraphProperties
71 * @see com.sun.star.text.XParagraphCursor
72 * @see com.sun.star.document.XDocumentInsertable
73 * @see com.sun.star.util.XSortable
74 * @see com.sun.star.style.CharacterPropertiesAsian
75 * @see ifc.text._XTextCursor
76 * @see ifc.text._XWordCursor
77 * @see ifc.style._CharacterPropertiesComplex
78 * @see ifc.text._XTextRange
79 * @see ifc.beans._XPropertySet
80 * @see ifc.container._XContentEnumerationAccess
81 * @see ifc.beans._XPropertyState
82 * @see ifc.style._CharacterProperties
83 * @see ifc.text._XSentenceCursor
84 * @see ifc.style._ParagraphProperties
85 * @see ifc.text._XParagraphCursor
86 * @see ifc.document._XDocumentInsertable
87 * @see ifc.util._XSortable
88 * @see ifc.style._CharacterPropertiesAsian
90 public class ScCellTextCursor extends TestCase {
91 private XSpreadsheetDocument xSheetDoc = null;
93 /**
94 * Creates Spreadsheet document.
96 @Override
97 protected void initialize( TestParameters tParam, PrintWriter log ) {
98 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
100 try {
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 @Override
115 protected void cleanup( TestParameters tParam, PrintWriter log ) {
116 log.println( " disposing xSheetDoc " );
117 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
118 util.DesktopTools.closeDoc(oComp);
122 * Creating a Testenvironment for the interfaces to be tested.
123 * Retrieves a collection of spreadsheets from a document
124 * and takes one of them. Retrieves the cell from the spreadsheet
125 * and creates text cursor of the cell using the interface
126 * <code>XText</code>. This text cursor is the instance of
127 * the service <code>com.sun.star.text.TextCursor</code>.
128 * Object relations created :
129 * <ul>
130 * <li> <code>'XTEXT'</code> for
131 * {@link ifc.text._XTextRange} (type of
132 * <code>XEnumerationAccess</code> that was retrieved from the
133 * collection of visible cells)</li>
134 * </ul>
135 * @see com.sun.star.text.XText
137 @Override
138 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
140 XInterface oObj = null;
141 XCell aCell = null;
143 // creation of testobject here
144 // first we write what we are intend to do to log file
145 log.println( "Creating a test environment" );
147 // get a soffice factory object
148 try {
149 log.println("Getting spreadsheet") ;
150 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
151 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
152 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
153 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
155 log.println("Getting a cell from sheet") ;
156 aCell = oSheet.getCellByPosition(1,1) ;
158 } catch (com.sun.star.lang.WrappedTargetException e) {
159 e.printStackTrace(log) ;
160 throw new StatusException(
161 "Error getting cell object from spreadsheet document",e) ;
162 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
163 e.printStackTrace(log) ;
164 throw new StatusException(
165 "Error getting cell object from spreadsheet document",e) ;
166 } catch (com.sun.star.lang.IllegalArgumentException e) {
167 e.printStackTrace(log) ;
168 throw new StatusException(
169 "Error getting cell object from spreadsheet document",e) ;
172 XText aText = UnoRuntime.queryInterface(XText.class, aCell);
173 aText.setString("ScCellTextCursor");
174 oObj = aText.createTextCursor();
176 log.println( "creating a new environment for ScCellTextCursor object" );
177 TestEnvironment tEnv = new TestEnvironment( oObj );
179 // Object relations for interface tests
180 tEnv.addObjRelation("XTEXT", aText);
182 return tEnv;
183 } // finish method getTestEnvironment
185 } // finish class ScCellTextCursor