2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
20 import java
.io
.PrintWriter
;
22 import lib
.StatusException
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
28 import com
.sun
.star
.container
.XIndexAccess
;
29 import com
.sun
.star
.lang
.XComponent
;
30 import com
.sun
.star
.lang
.XMultiServiceFactory
;
31 import com
.sun
.star
.sheet
.XSpreadsheet
;
32 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
33 import com
.sun
.star
.sheet
.XSpreadsheets
;
34 import com
.sun
.star
.table
.XCell
;
35 import com
.sun
.star
.text
.XText
;
36 import com
.sun
.star
.text
.XTextContent
;
37 import com
.sun
.star
.text
.XTextFieldsSupplier
;
38 import com
.sun
.star
.uno
.AnyConverter
;
39 import com
.sun
.star
.uno
.Type
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
44 * Test for object that represents a collection of text fields
45 * in a cell of a spreadsheet. <p>
47 * Object implements the following interfaces :
49 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
50 * <li> <code>com::sun::star::util::XRefreshable</code></li>
51 * <li> <code>com::sun::star::container::XElementAccess</code></li>
54 * @see com.sun.star.container.XEnumerationAccess
55 * @see com.sun.star.util.XRefreshable
56 * @see com.sun.star.container.XElementAccess
57 * @see ifc.container._XEnumerationAccess
58 * @see ifc.util._XRefreshable
59 * @see ifc.container._XElementAccess
61 public class ScCellFieldsObj
extends TestCase
{
62 private XSpreadsheetDocument xSheetDoc
= null;
65 * Creates Spreadsheet document.
67 protected void initialize( TestParameters tParam
, PrintWriter log
) {
68 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
71 log
.println( "creating a Spreadsheet document" );
72 xSheetDoc
= SOF
.createCalcDoc(null);
73 } catch ( com
.sun
.star
.uno
.Exception e
) {
74 // Some exception occurs.FAILED
75 e
.printStackTrace( log
);
76 throw new StatusException( "Couldn't create document", e
);
82 * Disposes Spreadsheet document.
84 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
85 log
.println( " disposing xSheetDoc " );
86 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
);
87 util
.DesktopTools
.closeDoc(oComp
);
91 * Creating a Testenvironment for the interfaces to be tested.
92 * Creates an instance of the service
93 * <code>com.sun.star.text.TextField.URL</code>, inserts it to the content
94 * of the cell in the spreadsheet. Then the component is obtained
95 * by <code>XTextFieldsSupplier</code> interface of a cell.<p>
97 protected synchronized TestEnvironment
createTestEnvironment(
98 TestParameters Param
, PrintWriter log
) {
100 XInterface oObj
= null;
102 XTextContent oContent
= null;
103 XInterface aField
= null;
106 // we want to create an instance of ScCellFieldObj.
107 // to do this we must get an MultiServiceFactory.
109 XMultiServiceFactory _oMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xSheetDoc
);
111 aField
= (XInterface
)
112 _oMSF
.createInstance("com.sun.star.text.TextField.URL");
113 oContent
= UnoRuntime
.queryInterface(XTextContent
.class, aField
);
115 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
116 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
117 XSpreadsheet oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
118 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
120 XCell oCell
= oSheet
.getCellByPosition(2,3);
121 oText
= UnoRuntime
.queryInterface(XText
.class, oCell
);
123 oText
.insertTextContent(
124 oText
.createTextCursor(), oContent
, true);
126 XTextFieldsSupplier xTextFieldsSupp
= UnoRuntime
.queryInterface(XTextFieldsSupplier
.class, oCell
);
128 oObj
= xTextFieldsSupp
.getTextFields();
129 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
130 log
.println("Exception occurred while creating test Object.");
131 e
.printStackTrace(log
);
132 throw new StatusException("Couldn't create test object", e
);
133 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
134 log
.println("Exception occurred while creating test Object.");
135 e
.printStackTrace(log
);
136 throw new StatusException("Couldn't create test object", e
);
137 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
138 log
.println("Exception occurred while creating test Object.");
139 e
.printStackTrace(log
);
140 throw new StatusException("Couldn't create test object", e
);
141 } catch (com
.sun
.star
.uno
.Exception e
) {
142 log
.println("Exception occurred while creating test Object.");
143 e
.printStackTrace(log
);
144 throw new StatusException("Couldn't create test object", e
);
147 TestEnvironment tEnv
= new TestEnvironment(oObj
) ;