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.XEnumerationAccess; 39 import com.sun.star.container.XIndexAccess; 40 import com.sun.star.lang.XComponent; 41 import com.sun.star.lang.XMultiServiceFactory; 42 import com.sun.star.sheet.XDataPilotDescriptor; 43 import com.sun.star.sheet.XDataPilotTables; 44 import com.sun.star.sheet.XDataPilotTablesSupplier; 45 import com.sun.star.sheet.XSpreadsheet; 46 import com.sun.star.sheet.XSpreadsheetDocument; 47 import com.sun.star.sheet.XSpreadsheets; 48 import com.sun.star.table.CellAddress; 49 import com.sun.star.table.CellRangeAddress; 50 import com.sun.star.uno.AnyConverter; 51 import com.sun.star.uno.Type; 52 import com.sun.star.uno.UnoRuntime; 53 import com.sun.star.uno.XInterface; 54 55 public class ScIndexEnumeration_DataPilotFieldsEnumeration extends TestCase { 56 static XSpreadsheetDocument xSheetDoc = null; 57 58 /** 59 * Creates Spreadsheet document. 60 */ 61 protected void initialize( TestParameters tParam, PrintWriter log ) { 62 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 63 64 try { 65 log.println( "creating a Spreadsheet document" ); 66 xSheetDoc = SOF.createCalcDoc(null); 67 } catch ( com.sun.star.uno.Exception e ) { 68 // Some exception occures.FAILED 69 e.printStackTrace( log ); 70 throw new StatusException( "Couldn't create document", e ); 71 } 72 73 } 74 75 /** 76 * Disposes Spreadsheet document. 77 */ 78 protected void cleanup( TestParameters tParam, PrintWriter log ) { 79 log.println( " disposing xSheetDoc " ); 80 XComponent oComp = (XComponent) 81 UnoRuntime.queryInterface(XComponent.class, xSheetDoc) ; 82 util.DesktopTools.closeDoc(oComp); 83 } 84 85 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 86 87 XInterface oObj = null; 88 89 // creation of testobject here 90 // first we write what we are intend to do to log file 91 log.println( "Creating a test environment" ); 92 93 // create testobject here 94 95 log.println("getting sheets"); 96 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSheetDoc.getSheets(); 97 98 log.println("getting a sheet"); 99 XSpreadsheet oSheet = null; 100 XIndexAccess oIndexAccess = (XIndexAccess) 101 UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets); 102 try { 103 oSheet = (XSpreadsheet) AnyConverter.toObject( 104 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0)); 105 } catch (com.sun.star.lang.WrappedTargetException e) { 106 e.printStackTrace(log); 107 throw new StatusException( "Couldn't get a spreadsheet", e); 108 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 109 e.printStackTrace(log); 110 throw new StatusException( "Couldn't get a spreadsheet", e); 111 } catch (com.sun.star.lang.IllegalArgumentException e) { 112 e.printStackTrace(log); 113 throw new StatusException( "Couldn't get a spreadsheet", e); 114 } 115 116 try { 117 log.println("Filing a table"); 118 for (int i = 1; i < 4; i++) { 119 oSheet.getCellByPosition(i, 0).setFormula("Col" + i); 120 oSheet.getCellByPosition(0, i).setFormula("Row" + i); 121 } 122 123 for (int i = 1; i < 4; i++) 124 for (int j = 1; j < 4; j++) { 125 oSheet.getCellByPosition(i, j).setValue(i * (j + 1)); 126 } 127 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 128 e.printStackTrace(log); 129 throw new StatusException("Couldn't fill some cells", e); 130 } 131 132 XDataPilotTablesSupplier DPTS = (XDataPilotTablesSupplier) 133 UnoRuntime.queryInterface(XDataPilotTablesSupplier.class, oSheet); 134 135 log.println("Getting test object ") ; 136 137 XDataPilotTables DPT = DPTS.getDataPilotTables(); 138 XDataPilotDescriptor DPDsc = DPT.createDataPilotDescriptor(); 139 DPDsc.setSourceRange(new CellRangeAddress((short)0, 0, 0, 4, 4)); 140 DPT.insertNewByName( 141 "DataPilotTable", 142 new CellAddress((short)0, 5, 5), 143 DPDsc); 144 145 oObj = DPDsc.getDataPilotFields(); 146 log.println("Creating object - " + 147 ((oObj == null) ? "FAILED" : "OK")); 148 149 XEnumerationAccess ea = (XEnumerationAccess) 150 UnoRuntime.queryInterface(XEnumerationAccess.class,oObj); 151 152 oObj = ea.createEnumeration(); 153 154 log.println("ImplementationName: "+util.utils.getImplName(oObj)); 155 // creating test environment 156 TestEnvironment tEnv = new TestEnvironment( oObj ); 157 158 tEnv.addObjRelation("ENUM",ea); 159 160 return tEnv; 161 } 162 163 } 164 165 166