bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScCellFieldObj.java
blob4258bafb1f8e44bebedff9cb4cae532916cdcdbf
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 @Override
73 protected void initialize( TestParameters tParam, PrintWriter log ) {
74 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
76 try {
77 log.println( "creating a Spreadsheet document" );
78 xSheetDoc = SOF.createCalcDoc(null);
79 } catch ( com.sun.star.uno.Exception e ) {
80 // Some exception occurs.FAILED
81 e.printStackTrace( log );
82 throw new StatusException( "Couldn't create document", e );
87 /**
88 * Disposes Spreadsheet document.
90 @Override
91 protected void cleanup( TestParameters tParam, PrintWriter log ) {
92 log.println( " disposing xSheetDoc " );
93 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
94 util.DesktopTools.closeDoc(oComp);
97 /**
98 * Creating a Testenvironment for the interfaces to be tested.
99 * Creates an instance of the service
100 * <code>com.sun.star.text.TextField.URL</code>, inserts it to the content
101 * of the cell in the spreadsheet, retrieves a text content
102 * <code>com.sun.star.text.XTextContent</code> from the cell.<p>
103 * Object relations created :
104 * <ul>
105 * <li> <code>'TRO'</code> for
106 * {@link ifc.text._TextContent} </li>
107 * <li> <code>'CONTENT'</code> for
108 * {@link ifc.text._XTextContent} (type of
109 * <code>com.sun.star.text.XTextContent</code> that was queried from
110 * the newly created service <code>com.sun.star.text.TextField.URL</code>)</li>
111 * <li> <code>'TEXT'</code> for
112 * {@link ifc.text._XTextContent} (the text of the cell)</li>
113 * </ul>
115 @Override
116 protected synchronized TestEnvironment createTestEnvironment(
117 TestParameters Param, PrintWriter log) {
119 XInterface oObj = null;
120 XText oText = null;
121 XTextContent oContent = null;
122 XInterface aField = null;
124 try {
125 // we want to create an instance of ScCellFieldObj.
126 // to do this we must get an MultiServiceFactory.
128 XMultiServiceFactory _oMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xSheetDoc);
130 // Now create the instance of com.sun.star.text.TextField.
131 // This object has type ScCellFieldObj.
133 oObj = (XInterface)
134 _oMSF.createInstance("com.sun.star.text.TextField.URL");
136 aField = (XInterface)
137 _oMSF.createInstance("com.sun.star.text.TextField.URL");
138 oContent = UnoRuntime.queryInterface(XTextContent.class, aField);
140 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
141 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
142 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
143 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
145 XCell oCell = oSheet.getCellByPosition(2,3);
146 oText = UnoRuntime.queryInterface(XText.class, oCell);
148 XTextContent oTextContent = UnoRuntime.queryInterface(XTextContent.class, oObj);
150 oText.insertTextContent(
151 oText.createTextCursor(), oTextContent, true);
153 oCell = oSheet.getCellByPosition(1,4);
154 oText = UnoRuntime.queryInterface(XText.class, oCell);
155 } catch (com.sun.star.lang.WrappedTargetException e) {
156 log.println("Exception occurred while creating test Object.");
157 e.printStackTrace(log);
158 throw new StatusException("Couldn't create test object", e);
159 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
160 log.println("Exception occurred while creating test Object.");
161 e.printStackTrace(log);
162 throw new StatusException("Couldn't create test object", e);
163 } catch (com.sun.star.lang.IllegalArgumentException e) {
164 log.println("Exception occurred while creating test Object.");
165 e.printStackTrace(log);
166 throw new StatusException("Couldn't create test object", e);
167 } catch (com.sun.star.uno.Exception e) {
168 log.println("Exception occurred while creating test Object.");
169 e.printStackTrace(log);
170 throw new StatusException("Couldn't create test object", e);
173 TestEnvironment tEnv = new TestEnvironment(oObj) ;
175 log.println ("Object created.") ;
176 tEnv.addObjRelation("TRO", Boolean.TRUE);
178 tEnv.addObjRelation("CONTENT",oContent);
179 tEnv.addObjRelation("TEXT",oText);
181 return tEnv;
184 } // finish class ScCellFieldObj