1ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ef39d40dSAndrew Rist * distributed with this work for additional information 6ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10ef39d40dSAndrew Rist * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12ef39d40dSAndrew Rist * 13ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17ef39d40dSAndrew Rist * specific language governing permissions and limitations 18ef39d40dSAndrew Rist * under the License. 19ef39d40dSAndrew Rist * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22ef39d40dSAndrew Rist 23cdf0e10cSrcweir package mod._sc; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import java.io.PrintWriter; 26cdf0e10cSrcweir 27cdf0e10cSrcweir import lib.StatusException; 28cdf0e10cSrcweir import lib.TestCase; 29cdf0e10cSrcweir import lib.TestEnvironment; 30cdf0e10cSrcweir import lib.TestParameters; 31cdf0e10cSrcweir import util.SOfficeFactory; 32cdf0e10cSrcweir 33cdf0e10cSrcweir import com.sun.star.container.XIndexAccess; 34cdf0e10cSrcweir import com.sun.star.lang.XComponent; 35cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 36cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheet; 37cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheetDocument; 38cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheets; 39cdf0e10cSrcweir import com.sun.star.table.XCell; 40cdf0e10cSrcweir import com.sun.star.text.XText; 41cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 42cdf0e10cSrcweir import com.sun.star.uno.Type; 43cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 44cdf0e10cSrcweir import com.sun.star.uno.XInterface; 45cdf0e10cSrcweir 46cdf0e10cSrcweir /** 47cdf0e10cSrcweir * Test for object which is represented by service 48cdf0e10cSrcweir * <code>com.sun.star.text.TextCursor</code>. <p> 49cdf0e10cSrcweir * Object implements the following interfaces : 50cdf0e10cSrcweir * <ul> 51cdf0e10cSrcweir * <li> <code>com::sun::star::text::XTextCursor</code></li> 52cdf0e10cSrcweir * <li> <code>com::sun::star::text::XWordCursor</code></li> 53cdf0e10cSrcweir * <li> <code>com::sun::star::style::CharacterPropertiesComplex</code></li> 54cdf0e10cSrcweir * <li> <code>com::sun::star::text::XTextRange</code></li> 55cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertySet</code></li> 56cdf0e10cSrcweir * <li> <code>com::sun::star::container::XContentEnumerationAccess</code></li> 57cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertyState</code></li> 58cdf0e10cSrcweir * <li> <code>com::sun::star::style::CharacterProperties</code></li> 59cdf0e10cSrcweir * <li> <code>com::sun::star::text::XSentenceCursor</code></li> 60cdf0e10cSrcweir * <li> <code>com::sun::star::style::ParagraphProperties</code></li> 61cdf0e10cSrcweir * <li> <code>com::sun::star::text::XParagraphCursor</code></li> 62cdf0e10cSrcweir * <li> <code>com::sun::star::document::XDocumentInsertable</code></li> 63cdf0e10cSrcweir * <li> <code>com::sun::star::util::XSortable</code></li> 64cdf0e10cSrcweir * <li> <code>com::sun::star::style::CharacterPropertiesAsian</code></li> 65cdf0e10cSrcweir * </ul> 66cdf0e10cSrcweir * @see com.sun.star.text.TextCursor 67cdf0e10cSrcweir * @see com.sun.star.text.XTextCursor 68cdf0e10cSrcweir * @see com.sun.star.text.XWordCursor 69cdf0e10cSrcweir * @see com.sun.star.style.CharacterPropertiesComplex 70cdf0e10cSrcweir * @see com.sun.star.text.XTextRange 71cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet 72cdf0e10cSrcweir * @see com.sun.star.container.XContentEnumerationAccess 73cdf0e10cSrcweir * @see com.sun.star.beans.XPropertyState 74cdf0e10cSrcweir * @see com.sun.star.style.CharacterProperties 75cdf0e10cSrcweir * @see com.sun.star.text.XSentenceCursor 76cdf0e10cSrcweir * @see com.sun.star.style.ParagraphProperties 77cdf0e10cSrcweir * @see com.sun.star.text.XParagraphCursor 78cdf0e10cSrcweir * @see com.sun.star.document.XDocumentInsertable 79cdf0e10cSrcweir * @see com.sun.star.util.XSortable 80cdf0e10cSrcweir * @see com.sun.star.style.CharacterPropertiesAsian 81cdf0e10cSrcweir * @see ifc.text._XTextCursor 82cdf0e10cSrcweir * @see ifc.text._XWordCursor 83cdf0e10cSrcweir * @see ifc.style._CharacterPropertiesComplex 84cdf0e10cSrcweir * @see ifc.text._XTextRange 85cdf0e10cSrcweir * @see ifc.beans._XPropertySet 86cdf0e10cSrcweir * @see ifc.container._XContentEnumerationAccess 87cdf0e10cSrcweir * @see ifc.beans._XPropertyState 88cdf0e10cSrcweir * @see ifc.style._CharacterProperties 89cdf0e10cSrcweir * @see ifc.text._XSentenceCursor 90cdf0e10cSrcweir * @see ifc.style._ParagraphProperties 91cdf0e10cSrcweir * @see ifc.text._XParagraphCursor 92cdf0e10cSrcweir * @see ifc.document._XDocumentInsertable 93cdf0e10cSrcweir * @see ifc.util._XSortable 94cdf0e10cSrcweir * @see ifc.style._CharacterPropertiesAsian 95cdf0e10cSrcweir */ 96cdf0e10cSrcweir public class ScCellTextCursor extends TestCase { 97cdf0e10cSrcweir static XSpreadsheetDocument xSheetDoc = null; 98cdf0e10cSrcweir 99cdf0e10cSrcweir /** 100cdf0e10cSrcweir * Creates Spreadsheet document. 101cdf0e10cSrcweir */ initialize( TestParameters tParam, PrintWriter log )102cdf0e10cSrcweir protected void initialize( TestParameters tParam, PrintWriter log ) { 103cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 104cdf0e10cSrcweir 105cdf0e10cSrcweir try { 106cdf0e10cSrcweir log.println( "creating a Spreadsheet document" ); 107cdf0e10cSrcweir xSheetDoc = SOF.createCalcDoc(null); 108cdf0e10cSrcweir } catch ( com.sun.star.uno.Exception e ) { 109*30acf5e8Spfg // Some exception occured.FAILED 110cdf0e10cSrcweir e.printStackTrace( log ); 111cdf0e10cSrcweir throw new StatusException( "Couldn't create document", e ); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir /** 117cdf0e10cSrcweir * Disposes Spreadsheet document. 118cdf0e10cSrcweir */ cleanup( TestParameters tParam, PrintWriter log )119cdf0e10cSrcweir protected void cleanup( TestParameters tParam, PrintWriter log ) { 120cdf0e10cSrcweir log.println( " disposing xSheetDoc " ); 121cdf0e10cSrcweir XComponent oComp = (XComponent) 122cdf0e10cSrcweir UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ; 123cdf0e10cSrcweir util.DesktopTools.closeDoc(oComp); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir /** 127cdf0e10cSrcweir * Creating a Testenvironment for the interfaces to be tested. 128cdf0e10cSrcweir * Retrieves a collection of spreadsheets from a document 129cdf0e10cSrcweir * and takes one of them. Retrieves the cell from the spreadsheet 130cdf0e10cSrcweir * and creates text cursor of the cell using the interface 131cdf0e10cSrcweir * <code>XText</code>. This text cursor is the instance of 132cdf0e10cSrcweir * the service <code>com.sun.star.text.TextCursor</code>. 133cdf0e10cSrcweir * Object relations created : 134cdf0e10cSrcweir * <ul> 135cdf0e10cSrcweir * <li> <code>'XTEXT'</code> for 136cdf0e10cSrcweir * {@link ifc.text._XTextRange} (type of 137cdf0e10cSrcweir * <code>XEnumerationAccess</code> that was retrieved from the 138cdf0e10cSrcweir * collection of visible cells)</li> 139cdf0e10cSrcweir * </ul> 140cdf0e10cSrcweir * @see com.sun.star.text.XText 141cdf0e10cSrcweir */ createTestEnvironment(TestParameters tParam, PrintWriter log)142cdf0e10cSrcweir protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { 143cdf0e10cSrcweir 144cdf0e10cSrcweir XInterface oObj = null; 145cdf0e10cSrcweir XCell aCell = null; 146cdf0e10cSrcweir 147cdf0e10cSrcweir // creation of testobject here 148cdf0e10cSrcweir // first we write what we are intend to do to log file 149cdf0e10cSrcweir log.println( "Creating a test environment" ); 150cdf0e10cSrcweir 151cdf0e10cSrcweir // get a soffice factory object 152cdf0e10cSrcweir try { 153cdf0e10cSrcweir log.println("Getting spreadsheet") ; 154cdf0e10cSrcweir XSpreadsheets oSheets = xSheetDoc.getSheets() ; 155cdf0e10cSrcweir XIndexAccess oIndexSheets = (XIndexAccess) 156cdf0e10cSrcweir UnoRuntime.queryInterface(XIndexAccess.class, oSheets); 157cdf0e10cSrcweir XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject( 158cdf0e10cSrcweir new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0)); 159cdf0e10cSrcweir 160cdf0e10cSrcweir log.println("Getting a cell from sheet") ; 161cdf0e10cSrcweir aCell = oSheet.getCellByPosition(1,1) ; 162cdf0e10cSrcweir 163cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 164cdf0e10cSrcweir e.printStackTrace(log) ; 165cdf0e10cSrcweir throw new StatusException( 166cdf0e10cSrcweir "Error getting cell object from spreadsheet document",e) ; 167cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 168cdf0e10cSrcweir e.printStackTrace(log) ; 169cdf0e10cSrcweir throw new StatusException( 170cdf0e10cSrcweir "Error getting cell object from spreadsheet document",e) ; 171cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 172cdf0e10cSrcweir e.printStackTrace(log) ; 173cdf0e10cSrcweir throw new StatusException( 174cdf0e10cSrcweir "Error getting cell object from spreadsheet document",e) ; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir XText aText = (XText) UnoRuntime.queryInterface(XText.class, aCell); 178cdf0e10cSrcweir aText.setString("ScCellTextCursor"); 179cdf0e10cSrcweir oObj = aText.createTextCursor(); 180cdf0e10cSrcweir 181cdf0e10cSrcweir log.println( "creating a new environment for ScCellTextCursor object" ); 182cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment( oObj ); 183cdf0e10cSrcweir 184cdf0e10cSrcweir // Object relations for interface tests 185cdf0e10cSrcweir tEnv.addObjRelation("XTEXT", aText); 186cdf0e10cSrcweir 187cdf0e10cSrcweir return tEnv; 188cdf0e10cSrcweir } // finish method getTestEnvironment 189cdf0e10cSrcweir 190cdf0e10cSrcweir } // finish class ScCellTextCursor 191cdf0e10cSrcweir 192