bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScCellFieldsObj.java
blob9ad004d868ec7d2884f690df15f85719170bbc97
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.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;
43 /**
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 :
48 * <ul>
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>
52 * </ul> <p>
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;
64 /**
65 * Creates Spreadsheet document.
67 @Override
68 protected void initialize( TestParameters tParam, PrintWriter log ) {
69 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
71 try {
72 log.println( "creating a Spreadsheet document" );
73 xSheetDoc = SOF.createCalcDoc(null);
74 } catch ( com.sun.star.uno.Exception e ) {
75 // Some exception occurs.FAILED
76 e.printStackTrace( log );
77 throw new StatusException( "Couldn't create document", e );
82 /**
83 * Disposes Spreadsheet document.
85 @Override
86 protected void cleanup( TestParameters tParam, PrintWriter log ) {
87 log.println( " disposing xSheetDoc " );
88 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
89 util.DesktopTools.closeDoc(oComp);
92 /**
93 * Creating a Testenvironment for the interfaces to be tested.
94 * Creates an instance of the service
95 * <code>com.sun.star.text.TextField.URL</code>, inserts it to the content
96 * of the cell in the spreadsheet. Then the component is obtained
97 * by <code>XTextFieldsSupplier</code> interface of a cell.<p>
99 @Override
100 protected synchronized TestEnvironment createTestEnvironment(
101 TestParameters Param, PrintWriter log) {
103 XInterface oObj = null;
104 XText oText = null;
105 XTextContent oContent = null;
106 XInterface aField = null;
108 try {
109 // we want to create an instance of ScCellFieldObj.
110 // to do this we must get an MultiServiceFactory.
112 XMultiServiceFactory _oMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xSheetDoc);
114 aField = (XInterface)
115 _oMSF.createInstance("com.sun.star.text.TextField.URL");
116 oContent = UnoRuntime.queryInterface(XTextContent.class, aField);
118 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
119 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
120 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
121 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
123 XCell oCell = oSheet.getCellByPosition(2,3);
124 oText = UnoRuntime.queryInterface(XText.class, oCell);
126 oText.insertTextContent(
127 oText.createTextCursor(), oContent, true);
129 XTextFieldsSupplier xTextFieldsSupp = UnoRuntime.queryInterface(XTextFieldsSupplier.class, oCell);
131 oObj = xTextFieldsSupp.getTextFields();
132 } catch (com.sun.star.lang.WrappedTargetException e) {
133 log.println("Exception occurred while creating test Object.");
134 e.printStackTrace(log);
135 throw new StatusException("Couldn't create test object", e);
136 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
137 log.println("Exception occurred while creating test Object.");
138 e.printStackTrace(log);
139 throw new StatusException("Couldn't create test object", e);
140 } catch (com.sun.star.lang.IllegalArgumentException e) {
141 log.println("Exception occurred while creating test Object.");
142 e.printStackTrace(log);
143 throw new StatusException("Couldn't create test object", e);
144 } catch (com.sun.star.uno.Exception e) {
145 log.println("Exception occurred while creating test Object.");
146 e.printStackTrace(log);
147 throw new StatusException("Couldn't create test object", e);
150 TestEnvironment tEnv = new TestEnvironment(oObj) ;
152 return tEnv;