1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScCellFieldObj.java,v $
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 ************************************************************************/
32 import java
.io
.PrintWriter
;
34 import lib
.StatusException
;
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
.uno
.AnyConverter
;
50 import com
.sun
.star
.uno
.Type
;
51 import com
.sun
.star
.uno
.UnoRuntime
;
52 import com
.sun
.star
.uno
.XInterface
;
55 * Test for object that represents a text field (implements
56 * <code>com.sun.star.text.TextField</code>) which inserted in a cell of
57 * the spreadsheet. <p>
58 * Object implements the following interfaces :
60 * <li> <code>com::sun::star::lang::XComponent</code></li>
61 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
62 * <li> <code>com::sun::star::text::XTextField</code></li>
63 * <li> <code>com::sun::star::text::XTextContent</code></li>
64 * <li> <code>com::sun::star::text::TextContent</code></li>
66 * @see com.sun.star.text.TextField
67 * @see com.sun.star.lang.XComponent
68 * @see com.sun.star.beans.XPropertySet
69 * @see com.sun.star.text.XTextField
70 * @see com.sun.star.text.XTextContent
71 * @see com.sun.star.text.TextContent
72 * @see ifc.lang._XComponent
73 * @see ifc.beans._XPropertySet
74 * @see ifc.text._XTextField
75 * @see ifc.text._XTextContent
76 * @see ifc.text._TextContent
78 public class ScCellFieldObj
extends TestCase
{
79 static XSpreadsheetDocument xSheetDoc
= null;
82 * Creates Spreadsheet document.
84 protected void initialize( TestParameters tParam
, PrintWriter log
) {
85 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
88 log
.println( "creating a Spreadsheet document" );
89 xSheetDoc
= SOF
.createCalcDoc(null);
90 } catch ( com
.sun
.star
.uno
.Exception e
) {
91 // Some exception occures.FAILED
92 e
.printStackTrace( log
);
93 throw new StatusException( "Couldn't create document", e
);
99 * Disposes Spreadsheet document.
101 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
102 log
.println( " disposing xSheetDoc " );
103 XComponent oComp
= (XComponent
)
104 UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
);
105 util
.DesktopTools
.closeDoc(oComp
);
109 * Creating a Testenvironment for the interfaces to be tested.
110 * Creates an instance of the service
111 * <code>com.sun.star.text.TextField.URL</code>, inserts it to the content
112 * of the cell in the spreadsheet, retrieves a text content
113 * <code>com.sun.star.text.XTextContent</code> from the cell.<p>
114 * Object relations created :
116 * <li> <code>'TRO'</code> for
117 * {@link ifc.text._TextContent} </li>
118 * <li> <code>'CONTENT'</code> for
119 * {@link ifc.text._XTextContent} (type of
120 * <code>com.sun.star.text.XTextContent</code> that was queried from
121 * the newly created service <code>com.sun.star.text.TextField.URL</code>)</li>
122 * <li> <code>'TEXT'</code> for
123 * {@link ifc.text._XTextContent} (the text of the cell)</li>
126 protected synchronized TestEnvironment
createTestEnvironment(
127 TestParameters Param
, PrintWriter log
) {
129 XInterface oObj
= null;
131 XTextContent oContent
= null;
132 XInterface aField
= null;
135 // we want to create an instance of ScCellFieldObj.
136 // to do this we must get an MultiServiceFactory.
138 XMultiServiceFactory _oMSF
= (XMultiServiceFactory
)
139 UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xSheetDoc
);
141 // Now create the instance of com.sun.star.text.TextField.
142 // This object has type ScCellFieldObj.
145 _oMSF
.createInstance("com.sun.star.text.TextField.URL");
147 aField
= (XInterface
)
148 _oMSF
.createInstance("com.sun.star.text.TextField.URL");
149 oContent
= (XTextContent
)
150 UnoRuntime
.queryInterface(XTextContent
.class, aField
);
152 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
153 XIndexAccess oIndexSheets
= (XIndexAccess
)
154 UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
155 XSpreadsheet oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
156 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
158 XCell oCell
= oSheet
.getCellByPosition(2,3);
159 oText
= (XText
)UnoRuntime
.queryInterface(XText
.class, oCell
);
161 XTextContent oTextContent
= (XTextContent
)
162 UnoRuntime
.queryInterface(XTextContent
.class, oObj
);
164 oText
.insertTextContent(
165 oText
.createTextCursor(), oTextContent
, true);
167 oCell
= oSheet
.getCellByPosition(1,4);
168 oText
= (XText
)UnoRuntime
.queryInterface(XText
.class, oCell
);
169 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
170 log
.println("Exception occured while creating test Object.");
171 e
.printStackTrace(log
);
172 throw new StatusException("Couldn't create test object", e
);
173 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
174 log
.println("Exception occured while creating test Object.");
175 e
.printStackTrace(log
);
176 throw new StatusException("Couldn't create test object", e
);
177 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
178 log
.println("Exception occured while creating test Object.");
179 e
.printStackTrace(log
);
180 throw new StatusException("Couldn't create test object", e
);
181 } catch (com
.sun
.star
.uno
.Exception e
) {
182 log
.println("Exception occured while creating test Object.");
183 e
.printStackTrace(log
);
184 throw new StatusException("Couldn't create test object", e
);
187 TestEnvironment tEnv
= new TestEnvironment(oObj
) ;
189 log
.println ("Object created.") ;
190 tEnv
.addObjRelation("TRO", new Boolean(true));
192 tEnv
.addObjRelation("CONTENT",oContent
);
193 tEnv
.addObjRelation("TEXT",oText
);
198 } // finish class ScCellFieldObj