1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package mod._sc; 29 30 import java.io.PrintWriter; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.SOfficeFactory; 37 38 import com.sun.star.container.XIndexAccess; 39 import com.sun.star.lang.XComponent; 40 import com.sun.star.lang.XMultiServiceFactory; 41 import com.sun.star.sheet.GeneralFunction; 42 import com.sun.star.sheet.SubTotalColumn; 43 import com.sun.star.sheet.XSpreadsheet; 44 import com.sun.star.sheet.XSpreadsheetDocument; 45 import com.sun.star.sheet.XSpreadsheets; 46 import com.sun.star.sheet.XSubTotalCalculatable; 47 import com.sun.star.sheet.XSubTotalDescriptor; 48 import com.sun.star.sheet.XSubTotalField; 49 import com.sun.star.uno.AnyConverter; 50 import com.sun.star.uno.Type; 51 import com.sun.star.uno.UnoRuntime; 52 import com.sun.star.uno.XInterface; 53 54 /** 55 * Test for object which is represented by service 56 * <code>com.sun.star.sheet.SubTotalField</code>. <p> 57 * Object implements the following interfaces : 58 * <ul> 59 * <li> <code>com::sun::star::sheet::XSubTotalField</code></li> 60 * </ul> 61 * @see com.sun.star.sheet.SubTotalField 62 * @see com.sun.star.sheet.XSubTotalField 63 * @see ifc.sheet._XSubTotalField 64 */ 65 public class ScSubTotalFieldObj extends TestCase { 66 public static XSpreadsheetDocument xSpreadsheetDoc; 67 68 /** 69 * Creates Spreadsheet document. 70 */ 71 public void initialize( TestParameters Param, PrintWriter log ) { 72 // creation of the testobject here 73 // first we write what we are intend to do to log file 74 log.println("creating a test environment"); 75 76 // get a soffice factory object 77 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 78 79 try { 80 log.println("creating a spreadsheetdocument"); 81 xSpreadsheetDoc = SOF.createCalcDoc(null); 82 } catch (com.sun.star.uno.Exception e) { 83 e.printStackTrace( log ); 84 throw new StatusException( "Couldn't create document ", e ); 85 } 86 } 87 88 /** 89 * Disposes Spreadsheet document. 90 */ 91 protected void cleanup( TestParameters tParam, PrintWriter log ) { 92 log.println( " disposing xSheetDoc " ); 93 XComponent oComp = (XComponent) 94 UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ; 95 util.DesktopTools.closeDoc(oComp); 96 } 97 98 /** 99 * Creating a Testenvironment for the interfaces to be tested. 100 * Retrieves a collection of spreadsheets from the document and takes one of 101 * them. Creates a subtotal descriptor using the interface 102 * <code>XSubTotalCalculatable</code>. Adds a subtotal field definition to 103 * the descriptor. Obtains the subtotal field with index 0 from the 104 * collection. The obtained subtotal field is the instance of the service 105 * <code>com.sun.star.sheet.SubTotalField</code>. 106 * @see com.sun.star.sheet.XSubTotalCalculatable 107 * @see com.sun.star.sheet.SubTotalField 108 */ 109 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 110 111 log.println("getting sheets"); 112 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSpreadsheetDoc.getSheets(); 113 114 log.println("getting a sheet"); 115 XSpreadsheet oSheet = null; 116 XIndexAccess oIndexAccess = (XIndexAccess) 117 UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets); 118 try { 119 oSheet = (XSpreadsheet) AnyConverter.toObject( 120 new Type (XSpreadsheet.class),oIndexAccess.getByIndex(0)); 121 } catch (com.sun.star.lang.WrappedTargetException e) { 122 e.printStackTrace(log); 123 throw new StatusException( "Couldn't get a spreadsheet", e); 124 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 125 e.printStackTrace(log); 126 throw new StatusException( "Couldn't get a spreadsheet", e); 127 } catch (com.sun.star.lang.IllegalArgumentException e) { 128 e.printStackTrace(log); 129 throw new StatusException( "Couldn't get a spreadsheet", e); 130 } 131 132 XSubTotalCalculatable xSTC = (XSubTotalCalculatable) 133 UnoRuntime.queryInterface(XSubTotalCalculatable.class, oSheet); 134 135 XSubTotalDescriptor xSTD = xSTC.createSubTotalDescriptor(true); 136 137 SubTotalColumn[] columns = new SubTotalColumn[1]; 138 SubTotalColumn column = new SubTotalColumn(); 139 column.Column = 5; 140 column.Function = GeneralFunction.SUM; 141 columns[0] = column; 142 xSTD.addNew(columns, 1); 143 144 XIndexAccess oDescIndex = (XIndexAccess) 145 UnoRuntime.queryInterface(XIndexAccess.class, xSTD); 146 147 XInterface oObj = null; 148 149 try { 150 oObj = ( XSubTotalField ) AnyConverter.toObject( 151 new Type(XSubTotalField.class),oDescIndex.getByIndex(0)); 152 } catch (com.sun.star.lang.WrappedTargetException e) { 153 e.printStackTrace(log); 154 throw new StatusException("Couldn't get XSubTotalField", e); 155 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 156 e.printStackTrace(log); 157 throw new StatusException("Couldn't get XSubTotalField", e); 158 } catch (com.sun.star.lang.IllegalArgumentException e) { 159 e.printStackTrace(log); 160 throw new StatusException("Couldn't get XSubTotalField", e); 161 } 162 163 TestEnvironment tEnv = new TestEnvironment(oObj); 164 return tEnv; 165 166 } // finish method getTestEnvironment 167 168 } // finish class ScSubTotalFieldObj 169 170