merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScIndexEnumeration_DataPilotFieldsEnumeration.java
blobe3e448579d4b5c88271797308dd4355e3677817e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScIndexEnumeration_DataPilotFieldsEnumeration.java,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._sc;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.SOfficeFactory;
41 import com.sun.star.container.XEnumerationAccess;
42 import com.sun.star.container.XIndexAccess;
43 import com.sun.star.lang.XComponent;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.sheet.XDataPilotDescriptor;
46 import com.sun.star.sheet.XDataPilotTables;
47 import com.sun.star.sheet.XDataPilotTablesSupplier;
48 import com.sun.star.sheet.XSpreadsheet;
49 import com.sun.star.sheet.XSpreadsheetDocument;
50 import com.sun.star.sheet.XSpreadsheets;
51 import com.sun.star.table.CellAddress;
52 import com.sun.star.table.CellRangeAddress;
53 import com.sun.star.uno.AnyConverter;
54 import com.sun.star.uno.Type;
55 import com.sun.star.uno.UnoRuntime;
56 import com.sun.star.uno.XInterface;
58 public class ScIndexEnumeration_DataPilotFieldsEnumeration extends TestCase {
59 static XSpreadsheetDocument xSheetDoc = null;
61 /**
62 * Creates Spreadsheet document.
64 protected void initialize( TestParameters tParam, PrintWriter log ) {
65 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
67 try {
68 log.println( "creating a Spreadsheet document" );
69 xSheetDoc = SOF.createCalcDoc(null);
70 } catch ( com.sun.star.uno.Exception e ) {
71 // Some exception occures.FAILED
72 e.printStackTrace( log );
73 throw new StatusException( "Couldn't create document", e );
78 /**
79 * Disposes Spreadsheet document.
81 protected void cleanup( TestParameters tParam, PrintWriter log ) {
82 log.println( " disposing xSheetDoc " );
83 XComponent oComp = (XComponent)
84 UnoRuntime.queryInterface(XComponent.class, xSheetDoc) ;
85 util.DesktopTools.closeDoc(oComp);
88 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
90 XInterface oObj = null;
92 // creation of testobject here
93 // first we write what we are intend to do to log file
94 log.println( "Creating a test environment" );
96 // create testobject here
98 log.println("getting sheets");
99 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSheetDoc.getSheets();
101 log.println("getting a sheet");
102 XSpreadsheet oSheet = null;
103 XIndexAccess oIndexAccess = (XIndexAccess)
104 UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
105 try {
106 oSheet = (XSpreadsheet) AnyConverter.toObject(
107 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
108 } catch (com.sun.star.lang.WrappedTargetException e) {
109 e.printStackTrace(log);
110 throw new StatusException( "Couldn't get a spreadsheet", e);
111 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
112 e.printStackTrace(log);
113 throw new StatusException( "Couldn't get a spreadsheet", e);
114 } catch (com.sun.star.lang.IllegalArgumentException e) {
115 e.printStackTrace(log);
116 throw new StatusException( "Couldn't get a spreadsheet", e);
119 try {
120 log.println("Filing a table");
121 for (int i = 1; i < 4; i++) {
122 oSheet.getCellByPosition(i, 0).setFormula("Col" + i);
123 oSheet.getCellByPosition(0, i).setFormula("Row" + i);
126 for (int i = 1; i < 4; i++)
127 for (int j = 1; j < 4; j++) {
128 oSheet.getCellByPosition(i, j).setValue(i * (j + 1));
130 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
131 e.printStackTrace(log);
132 throw new StatusException("Couldn't fill some cells", e);
135 XDataPilotTablesSupplier DPTS = (XDataPilotTablesSupplier)
136 UnoRuntime.queryInterface(XDataPilotTablesSupplier.class, oSheet);
138 log.println("Getting test object ") ;
140 XDataPilotTables DPT = DPTS.getDataPilotTables();
141 XDataPilotDescriptor DPDsc = DPT.createDataPilotDescriptor();
142 DPDsc.setSourceRange(new CellRangeAddress((short)0, 0, 0, 4, 4));
143 DPT.insertNewByName(
144 "DataPilotTable",
145 new CellAddress((short)0, 5, 5),
146 DPDsc);
148 oObj = DPDsc.getDataPilotFields();
149 log.println("Creating object - " +
150 ((oObj == null) ? "FAILED" : "OK"));
152 XEnumerationAccess ea = (XEnumerationAccess)
153 UnoRuntime.queryInterface(XEnumerationAccess.class,oObj);
155 oObj = ea.createEnumeration();
157 log.println("ImplementationName: "+util.utils.getImplName(oObj));
158 // creating test environment
159 TestEnvironment tEnv = new TestEnvironment( oObj );
161 tEnv.addObjRelation("ENUM",ea);
163 return tEnv;