bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScIndexEnumeration_TextFieldEnumeration.java
blob10a42cc24039a1462544eccadc9969326079107b
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 .
19 package mod._sc;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.container.XIndexAccess;
30 import com.sun.star.lang.XComponent;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.sheet.XSpreadsheet;
33 import com.sun.star.sheet.XSpreadsheetDocument;
34 import com.sun.star.sheet.XSpreadsheets;
35 import com.sun.star.table.XCell;
36 import com.sun.star.text.XText;
37 import com.sun.star.text.XTextContent;
38 import com.sun.star.text.XTextFieldsSupplier;
39 import com.sun.star.uno.AnyConverter;
40 import com.sun.star.uno.Type;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
44 /**
45 * Test for object that represents enumeration of a collection
46 * of text fields in a cell of a spreadsheet. <p>
48 * Object implements the following interfaces :
49 * <ul>
50 * <li> <code>com::sun::star::container::XEnumeration</code></li>
51 * </ul> <p>
53 * @see com.sun.star.container.XEnumeration
54 * @see ifc.container._XEnumeration
56 public class ScIndexEnumeration_TextFieldEnumeration extends TestCase {
57 private XSpreadsheetDocument xSheetDoc = null;
59 /**
60 * Creates Spreadsheet document.
62 protected void initialize( TestParameters tParam, PrintWriter log ) {
63 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
65 try {
66 log.println( "creating a Spreadsheet document" );
67 xSheetDoc = SOF.createCalcDoc(null);
68 } catch ( com.sun.star.uno.Exception e ) {
69 // Some exception occurs.FAILED
70 e.printStackTrace( log );
71 throw new StatusException( "Couldn't create document", e );
76 /**
77 * Disposes Spreadsheet document.
79 protected void cleanup( TestParameters tParam, PrintWriter log ) {
80 log.println( " disposing xSheetDoc " );
81 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
82 util.DesktopTools.closeDoc(oComp);
85 /**
86 * Creating a Testenvironment for the interfaces to be tested.
87 * Creates an instance of the service
88 * <code>com.sun.star.text.TextField.URL</code>, inserts it to the content
89 * of the cell in the spreadsheet. Then the component is obtained
90 * by <code>XTextFieldsSupplier</code> interface of a cell
91 * and <code>XEnumerationSupplier</code> interface .<p>
93 protected synchronized TestEnvironment createTestEnvironment(
94 TestParameters Param, PrintWriter log) {
96 XInterface oObj = null;
97 XText oText = null;
98 XTextContent oContent = null;
99 XInterface aField = null;
100 XTextFieldsSupplier xTextFieldsSupp = null;
102 try {
103 // we want to create an instance of ScCellFieldObj.
104 // to do this we must get an MultiServiceFactory.
106 XMultiServiceFactory _oMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xSheetDoc);
108 aField = (XInterface)
109 _oMSF.createInstance("com.sun.star.text.TextField.URL");
110 oContent = UnoRuntime.queryInterface(XTextContent.class, aField);
112 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
113 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
114 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
115 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
117 XCell oCell = oSheet.getCellByPosition(2,3);
118 oText = UnoRuntime.queryInterface(XText.class, oCell);
120 oText.insertTextContent(
121 oText.createTextCursor(), oContent, true);
123 xTextFieldsSupp = UnoRuntime.queryInterface(XTextFieldsSupplier.class, oCell);
125 oObj = xTextFieldsSupp.getTextFields().createEnumeration();
126 } catch (com.sun.star.lang.WrappedTargetException e) {
127 log.println("Exception occurred while creating test Object.");
128 e.printStackTrace(log);
129 throw new StatusException("Couldn't create test object", e);
130 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
131 log.println("Exception occurred while creating test Object.");
132 e.printStackTrace(log);
133 throw new StatusException("Couldn't create test object", e);
134 } catch (com.sun.star.lang.IllegalArgumentException e) {
135 log.println("Exception occurred while creating test Object.");
136 e.printStackTrace(log);
137 throw new StatusException("Couldn't create test object", e);
138 } catch (com.sun.star.uno.Exception e) {
139 log.println("Exception occurred while creating test Object.");
140 e.printStackTrace(log);
141 throw new StatusException("Couldn't create test object", e);
144 TestEnvironment tEnv = new TestEnvironment(oObj) ;
146 tEnv.addObjRelation("ENUM", xTextFieldsSupp.getTextFields());
148 return tEnv;