bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScCellFieldObj.java
blobf47206410c5909162b75ffad3e0fc53a2476b437
1 /*
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 .
18 package mod._sc;
20 import java.io.PrintWriter;
22 import lib.StatusException;
23 import lib.TestCase;
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.uno.AnyConverter;
38 import com.sun.star.uno.Type;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
42 /**
43 * Test for object that represents a text field (implements
44 * <code>com.sun.star.text.TextField</code>) which inserted in a cell of
45 * the spreadsheet. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>com::sun::star::lang::XComponent</code></li>
49 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
50 * <li> <code>com::sun::star::text::XTextField</code></li>
51 * <li> <code>com::sun::star::text::XTextContent</code></li>
52 * <li> <code>com::sun::star::text::TextContent</code></li>
53 * </ul>
54 * @see com.sun.star.text.TextField
55 * @see com.sun.star.lang.XComponent
56 * @see com.sun.star.beans.XPropertySet
57 * @see com.sun.star.text.XTextField
58 * @see com.sun.star.text.XTextContent
59 * @see com.sun.star.text.TextContent
60 * @see ifc.lang._XComponent
61 * @see ifc.beans._XPropertySet
62 * @see ifc.text._XTextField
63 * @see ifc.text._XTextContent
64 * @see ifc.text._TextContent
66 public class ScCellFieldObj extends TestCase {
67 private XSpreadsheetDocument xSheetDoc = null;
69 /**
70 * Creates Spreadsheet document.
72 protected void initialize( TestParameters tParam, PrintWriter log ) {
73 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
75 try {
76 log.println( "creating a Spreadsheet document" );
77 xSheetDoc = SOF.createCalcDoc(null);
78 } catch ( com.sun.star.uno.Exception e ) {
79 // Some exception occurs.FAILED
80 e.printStackTrace( log );
81 throw new StatusException( "Couldn't create document", e );
86 /**
87 * Disposes Spreadsheet document.
89 protected void cleanup( TestParameters tParam, PrintWriter log ) {
90 log.println( " disposing xSheetDoc " );
91 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
92 util.DesktopTools.closeDoc(oComp);
95 /**
96 * Creating a Testenvironment for the interfaces to be tested.
97 * Creates an instance of the service
98 * <code>com.sun.star.text.TextField.URL</code>, inserts it to the content
99 * of the cell in the spreadsheet, retrieves a text content
100 * <code>com.sun.star.text.XTextContent</code> from the cell.<p>
101 * Object relations created :
102 * <ul>
103 * <li> <code>'TRO'</code> for
104 * {@link ifc.text._TextContent} </li>
105 * <li> <code>'CONTENT'</code> for
106 * {@link ifc.text._XTextContent} (type of
107 * <code>com.sun.star.text.XTextContent</code> that was queried from
108 * the newly created service <code>com.sun.star.text.TextField.URL</code>)</li>
109 * <li> <code>'TEXT'</code> for
110 * {@link ifc.text._XTextContent} (the text of the cell)</li>
111 * </ul>
113 protected synchronized TestEnvironment createTestEnvironment(
114 TestParameters Param, PrintWriter log) {
116 XInterface oObj = null;
117 XText oText = null;
118 XTextContent oContent = null;
119 XInterface aField = null;
121 try {
122 // we want to create an instance of ScCellFieldObj.
123 // to do this we must get an MultiServiceFactory.
125 XMultiServiceFactory _oMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xSheetDoc);
127 // Now create the instance of com.sun.star.text.TextField.
128 // This object has type ScCellFieldObj.
130 oObj = (XInterface)
131 _oMSF.createInstance("com.sun.star.text.TextField.URL");
133 aField = (XInterface)
134 _oMSF.createInstance("com.sun.star.text.TextField.URL");
135 oContent = UnoRuntime.queryInterface(XTextContent.class, aField);
137 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
138 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
139 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
140 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
142 XCell oCell = oSheet.getCellByPosition(2,3);
143 oText = UnoRuntime.queryInterface(XText.class, oCell);
145 XTextContent oTextContent = UnoRuntime.queryInterface(XTextContent.class, oObj);
147 oText.insertTextContent(
148 oText.createTextCursor(), oTextContent, true);
150 oCell = oSheet.getCellByPosition(1,4);
151 oText = UnoRuntime.queryInterface(XText.class, oCell);
152 } catch (com.sun.star.lang.WrappedTargetException e) {
153 log.println("Exception occurred while creating test Object.");
154 e.printStackTrace(log);
155 throw new StatusException("Couldn't create test object", e);
156 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
157 log.println("Exception occurred while creating test Object.");
158 e.printStackTrace(log);
159 throw new StatusException("Couldn't create test object", e);
160 } catch (com.sun.star.lang.IllegalArgumentException e) {
161 log.println("Exception occurred while creating test Object.");
162 e.printStackTrace(log);
163 throw new StatusException("Couldn't create test object", e);
164 } catch (com.sun.star.uno.Exception e) {
165 log.println("Exception occurred while creating test Object.");
166 e.printStackTrace(log);
167 throw new StatusException("Couldn't create test object", e);
170 TestEnvironment tEnv = new TestEnvironment(oObj) ;
172 log.println ("Object created.") ;
173 tEnv.addObjRelation("TRO", new Boolean(true));
175 tEnv.addObjRelation("CONTENT",oContent);
176 tEnv.addObjRelation("TEXT",oText);
178 return tEnv;
181 } // finish class ScCellFieldObj