Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScIndexEnumeration_TextFieldEnumeration.java
blob63975f4612d3f07f73a80a33675ce3b8523964b6
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 @Override
63 protected void initialize( TestParameters tParam, PrintWriter log ) {
64 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
66 try {
67 log.println( "creating a Spreadsheet document" );
68 xSheetDoc = SOF.createCalcDoc(null);
69 } catch ( com.sun.star.uno.Exception e ) {
70 // Some exception occurs.FAILED
71 e.printStackTrace( log );
72 throw new StatusException( "Couldn't create document", e );
77 /**
78 * Disposes Spreadsheet document.
80 @Override
81 protected void cleanup( TestParameters tParam, PrintWriter log ) {
82 log.println( " disposing xSheetDoc " );
83 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
84 util.DesktopTools.closeDoc(oComp);
87 /**
88 * Creating a Testenvironment for the interfaces to be tested.
89 * Creates an instance of the service
90 * <code>com.sun.star.text.TextField.URL</code>, inserts it to the content
91 * of the cell in the spreadsheet. Then the component is obtained
92 * by <code>XTextFieldsSupplier</code> interface of a cell
93 * and <code>XEnumerationSupplier</code> interface .<p>
95 @Override
96 protected synchronized TestEnvironment createTestEnvironment(
97 TestParameters Param, PrintWriter log) {
99 XInterface oObj = null;
100 XText oText = null;
101 XTextContent oContent = null;
102 XInterface aField = null;
103 XTextFieldsSupplier xTextFieldsSupp = null;
105 try {
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 xTextFieldsSupp = UnoRuntime.queryInterface(XTextFieldsSupplier.class, oCell);
128 oObj = xTextFieldsSupp.getTextFields().createEnumeration();
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) ;
149 tEnv.addObjRelation("ENUM", xTextFieldsSupp.getTextFields());
151 return tEnv;