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.XEnumerationAccess; 35 import com.sun.star.container.XIndexAccess; 36 import com.sun.star.lang.XComponent; 37 import com.sun.star.lang.XMultiServiceFactory; 38 import com.sun.star.sheet.GeneralFunction; 39 import com.sun.star.sheet.SubTotalColumn; 40 import com.sun.star.sheet.XSpreadsheet; 41 import com.sun.star.sheet.XSpreadsheetDocument; 42 import com.sun.star.sheet.XSpreadsheets; 43 import com.sun.star.sheet.XSubTotalCalculatable; 44 import com.sun.star.sheet.XSubTotalDescriptor; 45 import com.sun.star.uno.AnyConverter; 46 import com.sun.star.uno.Type; 47 import com.sun.star.uno.UnoRuntime; 48 import com.sun.star.uno.XInterface; 49 50 public class ScIndexEnumeration_SubTotalFieldsEnumeration extends TestCase { 51 public static XSpreadsheetDocument xSpreadsheetDoc; 52 53 /** 54 * Creates Spreadsheet document. 55 */ initialize( TestParameters Param, PrintWriter log )56 public void initialize( TestParameters Param, PrintWriter log ) { 57 // creation of the testobject here 58 // first we write what we are intend to do to log file 59 log.println("creating a test environment"); 60 61 // get a soffice factory object 62 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 63 64 try { 65 log.println("creating a spreadsheetdocument"); 66 xSpreadsheetDoc = SOF.createCalcDoc(null); 67 } catch (com.sun.star.uno.Exception e) { 68 e.printStackTrace( log ); 69 throw new StatusException( "Couldn't create document ", e ); 70 } 71 } 72 73 /** 74 * Disposes Spreadsheet document. 75 */ cleanup( TestParameters tParam, PrintWriter log )76 protected void cleanup( TestParameters tParam, PrintWriter log ) { 77 log.println( " disposing xSheetDoc " ); 78 XComponent oComp = (XComponent) 79 UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ; 80 util.DesktopTools.closeDoc(oComp); 81 } 82 createTestEnvironment(TestParameters Param, PrintWriter log)83 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 84 85 log.println("getting sheets"); 86 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSpreadsheetDoc.getSheets(); 87 88 log.println("getting a sheet"); 89 XSpreadsheet oSheet = null; 90 XIndexAccess oIndexAccess = (XIndexAccess) 91 UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets); 92 try { 93 oSheet = (XSpreadsheet) AnyConverter.toObject( 94 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0)); 95 } catch (com.sun.star.lang.WrappedTargetException e) { 96 e.printStackTrace(log); 97 throw new StatusException( "Couldn't get a spreadsheet", e); 98 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 99 e.printStackTrace(log); 100 throw new StatusException( "Couldn't get a spreadsheet", e); 101 } catch (com.sun.star.lang.IllegalArgumentException e) { 102 e.printStackTrace(log); 103 throw new StatusException( "Couldn't get a spreadsheet", e); 104 } 105 106 XSubTotalCalculatable xSTC = (XSubTotalCalculatable) 107 UnoRuntime.queryInterface(XSubTotalCalculatable.class, oSheet); 108 109 XSubTotalDescriptor xSTD = xSTC.createSubTotalDescriptor(true); 110 111 SubTotalColumn[] columns = new SubTotalColumn[1]; 112 SubTotalColumn column = new SubTotalColumn(); 113 column.Column = 5; 114 column.Function = GeneralFunction.SUM; 115 columns[0] = column; 116 xSTD.addNew(columns, 1); 117 118 XIndexAccess oDescIndex = (XIndexAccess) 119 UnoRuntime.queryInterface(XIndexAccess.class, xSTD); 120 121 XInterface oObj = null; 122 123 XEnumerationAccess ea = (XEnumerationAccess) 124 UnoRuntime.queryInterface(XEnumerationAccess.class,oDescIndex); 125 126 oObj = ea.createEnumeration(); 127 128 log.println("ImplementationName: "+util.utils.getImplName(oObj)); 129 // creating test environment 130 TestEnvironment tEnv = new TestEnvironment( oObj ); 131 132 tEnv.addObjRelation("ENUM",ea); 133 134 return tEnv; 135 136 } // finish method getTestEnvironment 137 } 138