1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package mod._sc; 25 26 import java.io.PrintWriter; 27 28 import lib.StatusException; 29 import lib.TestCase; 30 import lib.TestEnvironment; 31 import lib.TestParameters; 32 import util.SOfficeFactory; 33 34 import com.sun.star.container.XIndexAccess; 35 import com.sun.star.lang.XComponent; 36 import com.sun.star.lang.XMultiServiceFactory; 37 import com.sun.star.sheet.XSpreadsheet; 38 import com.sun.star.sheet.XSpreadsheetDocument; 39 import com.sun.star.sheet.XSpreadsheets; 40 import com.sun.star.table.XCell; 41 import com.sun.star.text.XText; 42 import com.sun.star.text.XTextContent; 43 import com.sun.star.text.XTextFieldsSupplier; 44 import com.sun.star.uno.AnyConverter; 45 import com.sun.star.uno.Type; 46 import com.sun.star.uno.UnoRuntime; 47 import com.sun.star.uno.XInterface; 48 49 /** 50 * Test for object that represents enumeration of a colection 51 * of text fields in a cell of a spreadsheet. <p> 52 * 53 * Object implements the following interfaces : 54 * <ul> 55 * <li> <code>com::sun::star::container::XEnumeration</code></li> 56 * </ul> <p> 57 * 58 * @see com.sun.star.container.XEnumeration 59 * @see ifc.container._XEnumeration 60 */ 61 public class ScIndexEnumeration_TextFieldEnumeration extends TestCase { 62 static XSpreadsheetDocument xSheetDoc = null; 63 64 /** 65 * Creates Spreadsheet document. 66 */ initialize( TestParameters tParam, PrintWriter log )67 protected void initialize( TestParameters tParam, PrintWriter log ) { 68 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 69 70 try { 71 log.println( "creating a Spreadsheet document" ); 72 xSheetDoc = SOF.createCalcDoc(null); 73 } catch ( com.sun.star.uno.Exception e ) { 74 // Some exception occures.FAILED 75 e.printStackTrace( log ); 76 throw new StatusException( "Couldn't create document", e ); 77 } 78 79 } 80 81 /** 82 * Disposes Spreadsheet document. 83 */ cleanup( TestParameters tParam, PrintWriter log )84 protected void cleanup( TestParameters tParam, PrintWriter log ) { 85 log.println( " disposing xSheetDoc " ); 86 XComponent oComp = (XComponent) 87 UnoRuntime.queryInterface (XComponent.class, xSheetDoc); 88 util.DesktopTools.closeDoc(oComp); 89 } 90 91 /** 92 * Creating a Testenvironment for the interfaces to be tested. 93 * Creates an instance of the service 94 * <code>com.sun.star.text.TextField.URL</code>, inserts it to the content 95 * of the cell in the spreadsheet. Then the component is obtained 96 * by <code>XTextFieldsSupplier</code> interface of a cell 97 * and <code>XEnumerationSupplier</code> interface .<p> 98 */ createTestEnvironment( TestParameters Param, PrintWriter log)99 protected synchronized TestEnvironment createTestEnvironment( 100 TestParameters Param, PrintWriter log) { 101 102 XInterface oObj = null; 103 XText oText = null; 104 XTextContent oContent = null; 105 XInterface aField = null; 106 XTextFieldsSupplier xTextFieldsSupp = null; 107 108 try { 109 // we want to create an instance of ScCellFieldObj. 110 // to do this we must get an MultiServiceFactory. 111 112 XMultiServiceFactory _oMSF = (XMultiServiceFactory) 113 UnoRuntime.queryInterface(XMultiServiceFactory.class, xSheetDoc); 114 115 aField = (XInterface) 116 _oMSF.createInstance("com.sun.star.text.TextField.URL"); 117 oContent = (XTextContent) 118 UnoRuntime.queryInterface(XTextContent.class, aField); 119 120 XSpreadsheets oSheets = xSheetDoc.getSheets() ; 121 XIndexAccess oIndexSheets = (XIndexAccess) 122 UnoRuntime.queryInterface(XIndexAccess.class, oSheets); 123 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject( 124 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0)); 125 126 XCell oCell = oSheet.getCellByPosition(2,3); 127 oText = (XText)UnoRuntime.queryInterface(XText.class, oCell); 128 129 oText.insertTextContent( 130 oText.createTextCursor(), oContent, true); 131 132 xTextFieldsSupp = (XTextFieldsSupplier) 133 UnoRuntime.queryInterface(XTextFieldsSupplier.class, oCell); 134 135 oObj = xTextFieldsSupp.getTextFields().createEnumeration(); 136 } catch (com.sun.star.lang.WrappedTargetException e) { 137 log.println("Exception occured while creating test Object."); 138 e.printStackTrace(log); 139 throw new StatusException("Couldn't create test object", e); 140 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 141 log.println("Exception occured while creating test Object."); 142 e.printStackTrace(log); 143 throw new StatusException("Couldn't create test object", e); 144 } catch (com.sun.star.lang.IllegalArgumentException e) { 145 log.println("Exception occured while creating test Object."); 146 e.printStackTrace(log); 147 throw new StatusException("Couldn't create test object", e); 148 } catch (com.sun.star.uno.Exception e) { 149 log.println("Exception occured while creating test Object."); 150 e.printStackTrace(log); 151 throw new StatusException("Couldn't create test object", e); 152 } 153 154 TestEnvironment tEnv = new TestEnvironment(oObj) ; 155 156 tEnv.addObjRelation("ENUM", xTextFieldsSupp.getTextFields()); 157 158 return tEnv; 159 } 160 161 } 162 163