1 /* 2 * This file is part of the LibreOffice project. 3 * 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/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 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 . 17 */ 18 package mod._sc; 19 20 import java.io.PrintWriter; 21 22 import lib.TestCase; 23 import lib.TestEnvironment; 24 import lib.TestParameters; 25 import util.SOfficeFactory; 26 27 import com.sun.star.container.XIndexAccess; 28 import com.sun.star.lang.XComponent; 29 import com.sun.star.lang.XMultiServiceFactory; 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.text.XTextContent; 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; 40 41 /** 42 * Test for object that represents a text field (implements 43 * <code>com.sun.star.text.TextField</code>) which inserted in a cell of 44 * the spreadsheet. <p> 45 * Object implements the following interfaces : 46 * <ul> 47 * <li> <code>com::sun::star::lang::XComponent</code></li> 48 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 49 * <li> <code>com::sun::star::text::XTextField</code></li> 50 * <li> <code>com::sun::star::text::XTextContent</code></li> 51 * <li> <code>com::sun::star::text::TextContent</code></li> 52 * </ul> 53 * @see com.sun.star.text.TextField 54 * @see com.sun.star.lang.XComponent 55 * @see com.sun.star.beans.XPropertySet 56 * @see com.sun.star.text.XTextField 57 * @see com.sun.star.text.XTextContent 58 * @see com.sun.star.text.TextContent 59 * @see ifc.lang._XComponent 60 * @see ifc.beans._XPropertySet 61 * @see ifc.text._XTextField 62 * @see ifc.text._XTextContent 63 * @see ifc.text._TextContent 64 */ 65 public class ScCellFieldObj extends TestCase { 66 private XSpreadsheetDocument xSheetDoc = null; 67 68 /** 69 * Creates Spreadsheet document. 70 */ 71 @Override initialize( TestParameters tParam, PrintWriter log )72 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception { 73 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() ); 74 log.println( "creating a Spreadsheet document" ); 75 xSheetDoc = SOF.createCalcDoc(null); 76 } 77 78 /** 79 * Disposes Spreadsheet document. 80 */ 81 @Override cleanup( TestParameters tParam, PrintWriter log )82 protected void cleanup( TestParameters tParam, PrintWriter log ) { 83 log.println( " disposing xSheetDoc " ); 84 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc); 85 util.DesktopTools.closeDoc(oComp); 86 } 87 88 /** 89 * Creating a TestEnvironment for the interfaces to be tested. 90 * Creates an instance of the service 91 * <code>com.sun.star.text.TextField.URL</code>, inserts it to the content 92 * of the cell in the spreadsheet, retrieves a text content 93 * <code>com.sun.star.text.XTextContent</code> from the cell.<p> 94 * Object relations created : 95 * <ul> 96 * <li> <code>'TRO'</code> for 97 * {@link ifc.text._TextContent} </li> 98 * <li> <code>'CONTENT'</code> for 99 * {@link ifc.text._XTextContent} (type of 100 * <code>com.sun.star.text.XTextContent</code> that was queried from 101 * the newly created service <code>com.sun.star.text.TextField.URL</code>)</li> 102 * <li> <code>'TEXT'</code> for 103 * {@link ifc.text._XTextContent} (the text of the cell)</li> 104 * </ul> 105 */ 106 @Override createTestEnvironment( TestParameters Param, PrintWriter log)107 protected TestEnvironment createTestEnvironment( 108 TestParameters Param, PrintWriter log) throws Exception { 109 110 XInterface oObj = null; 111 XText oText = null; 112 XTextContent oContent = null; 113 XInterface aField = null; 114 115 // we want to create an instance of ScCellFieldObj. 116 // to do this we must get an MultiServiceFactory. 117 118 XMultiServiceFactory _oMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xSheetDoc); 119 120 // Now create the instance of com.sun.star.text.TextField. 121 // This object has type ScCellFieldObj. 122 123 oObj = (XInterface) 124 _oMSF.createInstance("com.sun.star.text.TextField.URL"); 125 126 aField = (XInterface) 127 _oMSF.createInstance("com.sun.star.text.TextField.URL"); 128 oContent = UnoRuntime.queryInterface(XTextContent.class, aField); 129 130 XSpreadsheets oSheets = xSheetDoc.getSheets() ; 131 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(XIndexAccess.class, oSheets); 132 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject( 133 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0)); 134 135 XCell oCell = oSheet.getCellByPosition(2,3); 136 oText = UnoRuntime.queryInterface(XText.class, oCell); 137 138 XTextContent oTextContent = UnoRuntime.queryInterface(XTextContent.class, oObj); 139 140 oText.insertTextContent( 141 oText.createTextCursor(), oTextContent, true); 142 143 oCell = oSheet.getCellByPosition(1,4); 144 oText = UnoRuntime.queryInterface(XText.class, oCell); 145 146 TestEnvironment tEnv = new TestEnvironment(oObj) ; 147 148 log.println ("Object created.") ; 149 tEnv.addObjRelation("TRO", Boolean.TRUE); 150 151 tEnv.addObjRelation("CONTENT",oContent); 152 tEnv.addObjRelation("TEXT",oText); 153 154 return tEnv; 155 } 156 157 } // finish class ScCellFieldObj 158 159