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: ScIndexEnumeration_TextFieldEnumeration.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 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.container
.XIndexAccess
;
42 import com
.sun
.star
.lang
.XComponent
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.sheet
.XSpreadsheet
;
45 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
46 import com
.sun
.star
.sheet
.XSpreadsheets
;
47 import com
.sun
.star
.table
.XCell
;
48 import com
.sun
.star
.text
.XText
;
49 import com
.sun
.star
.text
.XTextContent
;
50 import com
.sun
.star
.text
.XTextFieldsSupplier
;
51 import com
.sun
.star
.uno
.AnyConverter
;
52 import com
.sun
.star
.uno
.Type
;
53 import com
.sun
.star
.uno
.UnoRuntime
;
54 import com
.sun
.star
.uno
.XInterface
;
57 * Test for object that represents enumeration of a colection
58 * of text fields in a cell of a spreadsheet. <p>
60 * Object implements the following interfaces :
62 * <li> <code>com::sun::star::container::XEnumeration</code></li>
65 * @see com.sun.star.container.XEnumeration
66 * @see ifc.container._XEnumeration
68 public class ScIndexEnumeration_TextFieldEnumeration
extends TestCase
{
69 static XSpreadsheetDocument xSheetDoc
= null;
72 * Creates Spreadsheet document.
74 protected void initialize( TestParameters tParam
, PrintWriter log
) {
75 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
78 log
.println( "creating a Spreadsheet document" );
79 xSheetDoc
= SOF
.createCalcDoc(null);
80 } catch ( com
.sun
.star
.uno
.Exception e
) {
81 // Some exception occures.FAILED
82 e
.printStackTrace( log
);
83 throw new StatusException( "Couldn't create document", e
);
89 * Disposes Spreadsheet document.
91 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
92 log
.println( " disposing xSheetDoc " );
93 XComponent oComp
= (XComponent
)
94 UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
);
95 util
.DesktopTools
.closeDoc(oComp
);
99 * Creating a Testenvironment for the interfaces to be tested.
100 * Creates an instance of the service
101 * <code>com.sun.star.text.TextField.URL</code>, inserts it to the content
102 * of the cell in the spreadsheet. Then the component is obtained
103 * by <code>XTextFieldsSupplier</code> interface of a cell
104 * and <code>XEnumerationSupplier</code> interface .<p>
106 protected synchronized TestEnvironment
createTestEnvironment(
107 TestParameters Param
, PrintWriter log
) {
109 XInterface oObj
= null;
111 XTextContent oContent
= null;
112 XInterface aField
= null;
113 XTextFieldsSupplier xTextFieldsSupp
= null;
116 // we want to create an instance of ScCellFieldObj.
117 // to do this we must get an MultiServiceFactory.
119 XMultiServiceFactory _oMSF
= (XMultiServiceFactory
)
120 UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xSheetDoc
);
122 aField
= (XInterface
)
123 _oMSF
.createInstance("com.sun.star.text.TextField.URL");
124 oContent
= (XTextContent
)
125 UnoRuntime
.queryInterface(XTextContent
.class, aField
);
127 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
128 XIndexAccess oIndexSheets
= (XIndexAccess
)
129 UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
130 XSpreadsheet oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
131 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
133 XCell oCell
= oSheet
.getCellByPosition(2,3);
134 oText
= (XText
)UnoRuntime
.queryInterface(XText
.class, oCell
);
136 oText
.insertTextContent(
137 oText
.createTextCursor(), oContent
, true);
139 xTextFieldsSupp
= (XTextFieldsSupplier
)
140 UnoRuntime
.queryInterface(XTextFieldsSupplier
.class, oCell
);
142 oObj
= xTextFieldsSupp
.getTextFields().createEnumeration();
143 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
144 log
.println("Exception occured while creating test Object.");
145 e
.printStackTrace(log
);
146 throw new StatusException("Couldn't create test object", e
);
147 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
148 log
.println("Exception occured while creating test Object.");
149 e
.printStackTrace(log
);
150 throw new StatusException("Couldn't create test object", e
);
151 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
152 log
.println("Exception occured while creating test Object.");
153 e
.printStackTrace(log
);
154 throw new StatusException("Couldn't create test object", e
);
155 } catch (com
.sun
.star
.uno
.Exception e
) {
156 log
.println("Exception occured while creating test Object.");
157 e
.printStackTrace(log
);
158 throw new StatusException("Couldn't create test object", e
);
161 TestEnvironment tEnv
= new TestEnvironment(oObj
) ;
163 tEnv
.addObjRelation("ENUM", xTextFieldsSupp
.getTextFields());