merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScCellFieldsObj.java
blob99eb846c14ded22fb07176d704d1d27e97add125
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScCellFieldsObj.java,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package mod._sc;
32 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
38 import util.SOfficeFactory;
40 import com.sun.star.container.XIndexAccess;
41 import com.sun.star.lang.XComponent;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import com.sun.star.sheet.XSpreadsheet;
44 import com.sun.star.sheet.XSpreadsheetDocument;
45 import com.sun.star.sheet.XSpreadsheets;
46 import com.sun.star.table.XCell;
47 import com.sun.star.text.XText;
48 import com.sun.star.text.XTextContent;
49 import com.sun.star.text.XTextFieldsSupplier;
50 import com.sun.star.uno.AnyConverter;
51 import com.sun.star.uno.Type;
52 import com.sun.star.uno.UnoRuntime;
53 import com.sun.star.uno.XInterface;
55 /**
56 * Test for object that represents a colection of text fields
57 * in a cell of a spreadsheet. <p>
59 * Object implements the following interfaces :
60 * <ul>
61 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
62 * <li> <code>com::sun::star::util::XRefreshable</code></li>
63 * <li> <code>com::sun::star::container::XElementAccess</code></li>
64 * </ul> <p>
66 * @see com.sun.star.container.XEnumerationAccess
67 * @see com.sun.star.util.XRefreshable
68 * @see com.sun.star.container.XElementAccess
69 * @see ifc.container._XEnumerationAccess
70 * @see ifc.util._XRefreshable
71 * @see ifc.container._XElementAccess
73 public class ScCellFieldsObj extends TestCase {
74 static XSpreadsheetDocument xSheetDoc = null;
76 /**
77 * Creates Spreadsheet document.
79 protected void initialize( TestParameters tParam, PrintWriter log ) {
80 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
82 try {
83 log.println( "creating a Spreadsheet document" );
84 xSheetDoc = SOF.createCalcDoc(null);
85 } catch ( com.sun.star.uno.Exception e ) {
86 // Some exception occures.FAILED
87 e.printStackTrace( log );
88 throw new StatusException( "Couldn't create document", e );
93 /**
94 * Disposes Spreadsheet document.
96 protected void cleanup( TestParameters tParam, PrintWriter log ) {
97 log.println( " disposing xSheetDoc " );
98 XComponent oComp = (XComponent)
99 UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
100 util.DesktopTools.closeDoc(oComp);
104 * Creating a Testenvironment for the interfaces to be tested.
105 * Creates an instance of the service
106 * <code>com.sun.star.text.TextField.URL</code>, inserts it to the content
107 * of the cell in the spreadsheet. Then the component is obtained
108 * by <code>XTextFieldsSupplier</code> interface of a cell.<p>
110 protected synchronized TestEnvironment createTestEnvironment(
111 TestParameters Param, PrintWriter log) {
113 XInterface oObj = null;
114 XText oText = null;
115 XTextContent oContent = null;
116 XInterface aField = null;
118 try {
119 // we want to create an instance of ScCellFieldObj.
120 // to do this we must get an MultiServiceFactory.
122 XMultiServiceFactory _oMSF = (XMultiServiceFactory)
123 UnoRuntime.queryInterface(XMultiServiceFactory.class, xSheetDoc);
125 aField = (XInterface)
126 _oMSF.createInstance("com.sun.star.text.TextField.URL");
127 oContent = (XTextContent)
128 UnoRuntime.queryInterface(XTextContent.class, aField);
130 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
131 XIndexAccess oIndexSheets = (XIndexAccess)
132 UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
133 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
134 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
136 XCell oCell = oSheet.getCellByPosition(2,3);
137 oText = (XText)UnoRuntime.queryInterface(XText.class, oCell);
139 oText.insertTextContent(
140 oText.createTextCursor(), oContent, true);
142 XTextFieldsSupplier xTextFieldsSupp = (XTextFieldsSupplier)
143 UnoRuntime.queryInterface(XTextFieldsSupplier.class, oCell);
145 oObj = xTextFieldsSupp.getTextFields();
146 } catch (com.sun.star.lang.WrappedTargetException e) {
147 log.println("Exception occured while creating test Object.");
148 e.printStackTrace(log);
149 throw new StatusException("Couldn't create test object", e);
150 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
151 log.println("Exception occured while creating test Object.");
152 e.printStackTrace(log);
153 throw new StatusException("Couldn't create test object", e);
154 } catch (com.sun.star.lang.IllegalArgumentException e) {
155 log.println("Exception occured while creating test Object.");
156 e.printStackTrace(log);
157 throw new StatusException("Couldn't create test object", e);
158 } catch (com.sun.star.uno.Exception e) {
159 log.println("Exception occured while creating test Object.");
160 e.printStackTrace(log);
161 throw new StatusException("Couldn't create test object", e);
164 TestEnvironment tEnv = new TestEnvironment(oObj) ;
166 return tEnv;