1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScDataPilotTablesObj.java,v $
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 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.container
.XIndexAccess
;
42 import com
.sun
.star
.lang
.XComponent
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.sheet
.XDataPilotDescriptor
;
45 import com
.sun
.star
.sheet
.XDataPilotTables
;
46 import com
.sun
.star
.sheet
.XDataPilotTablesSupplier
;
47 import com
.sun
.star
.sheet
.XSpreadsheet
;
48 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
49 import com
.sun
.star
.sheet
.XSpreadsheets
;
50 import com
.sun
.star
.table
.CellAddress
;
51 import com
.sun
.star
.table
.CellRangeAddress
;
52 import com
.sun
.star
.uno
.AnyConverter
;
53 import com
.sun
.star
.uno
.Type
;
54 import com
.sun
.star
.uno
.UnoRuntime
;
55 import com
.sun
.star
.uno
.XInterface
;
58 * Test for object which is represented by service
59 * <code>com.sun.star.sheet.DataPilotTables</code>. <p>
60 * Object implements the following interfaces :
62 * <li> <code>com::sun::star::sheet::XDataPilotTables</code></li>
63 * <li> <code>com::sun::star::container::XNameAccess</code></li>
64 * <li> <code>com::sun::star::container::XElementAccess</code></li>
66 * @see com.sun.star.sheet.DataPilotTables
67 * @see com.sun.star.sheet.XDataPilotTables
68 * @see com.sun.star.container.XNameAccess
69 * @see com.sun.star.container.XElementAccess
70 * @see ifc.sheet._XDataPilotTables
71 * @see ifc.container._XNameAccess
72 * @see ifc.container._XElementAccess
74 public class ScDataPilotTablesObj
extends TestCase
{
75 static XSpreadsheetDocument xSheetDoc
= null;
78 * Creates Spreadsheet document.
80 protected void initialize( TestParameters tParam
, PrintWriter log
) {
81 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
84 log
.println( "creating a Spreadsheet document" );
85 xSheetDoc
= SOF
.createCalcDoc(null);
86 } catch ( com
.sun
.star
.uno
.Exception e
) {
87 // Some exception occures.FAILED
88 e
.printStackTrace( log
);
89 throw new StatusException( "Couldn't create document", e
);
95 * Disposes Spreadsheet document.
97 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
98 log
.println( " disposing xSheetDoc " );
99 XComponent oComp
= (XComponent
)
100 UnoRuntime
.queryInterface(XComponent
.class, xSheetDoc
) ;
101 util
.DesktopTools
.closeDoc(oComp
);
105 * Creating a Testenvironment for the interfaces to be tested.
106 * Retrieves a collection of spreadsheets from a document
107 * and takes one of them. Fills some table in the spreadsheet.
108 * Obtains the collection of data pilot tables using the interface
109 * <code>XDataPilotTablesSupplier</code>. Creates a data pilot descriptor
110 * for the filled table and inserts new data pilot table with this descriptor
111 * to the collection. The collection of data pilot tables is the instance of
112 * the service <code>com.sun.star.sheet.DataPilotTables</code>.
113 * Object relations created :
115 * <li> <code>'SHEET'</code> for
116 * {@link ifc.sheet._XDataPilotTables}(the spreadsheet which
117 * the collection of data pilot tables was retrieved from) </li>
119 * @see com.sun.star.sheet.DataPilotTable
120 * @see com.sun.star.sheet.XDataPilotTablesSupplier
122 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
124 XInterface oObj
= null;
126 // creation of testobject here
127 // first we write what we are intend to do to log file
128 log
.println( "Creating a test environment" );
130 // create testobject here
132 log
.println("getting sheets");
133 XSpreadsheets xSpreadsheets
= (XSpreadsheets
)xSheetDoc
.getSheets();
135 log
.println("getting a sheet");
136 XSpreadsheet oSheet
= null;
137 XIndexAccess oIndexAccess
= (XIndexAccess
)
138 UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
140 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
141 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
142 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
143 e
.printStackTrace(log
);
144 throw new StatusException( "Couldn't get a spreadsheet", e
);
145 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
146 e
.printStackTrace(log
);
147 throw new StatusException( "Couldn't get a spreadsheet", e
);
148 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
149 e
.printStackTrace(log
);
150 throw new StatusException( "Couldn't get a spreadsheet", e
);
155 log
.println("Filing a table");
156 for (int i
= 1; i
< 4; i
++) {
157 oSheet
.getCellByPosition(i
, 0).setFormula("Col" + i
);
158 oSheet
.getCellByPosition(0, i
).setFormula("Row" + i
);
161 for (int i
= 1; i
< 4; i
++)
162 for (int j
= 1; j
< 4; j
++) {
163 oSheet
.getCellByPosition(i
, j
).setValue(i
* (j
+ 1));
165 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
166 e
.printStackTrace(log
);
167 throw new StatusException("Couldn't fill some cells", e
);
170 XDataPilotTablesSupplier DPTS
= (XDataPilotTablesSupplier
)
171 UnoRuntime
.queryInterface(XDataPilotTablesSupplier
.class, oSheet
);
173 log
.println("Getting test object ") ;
175 XDataPilotTables DPT
= DPTS
.getDataPilotTables();
176 XDataPilotDescriptor DPDsc
= DPT
.createDataPilotDescriptor();
177 DPDsc
.setSourceRange(new CellRangeAddress((short)0, 0, 0, 4, 4));
180 new CellAddress((short)0, 5, 5),
185 log
.println("Creating object - " +
186 ((oObj
== null) ?
"FAILED" : "OK"));
188 TestEnvironment tEnv
= new TestEnvironment( oObj
);
190 // Other parameters required for interface tests
191 tEnv
.addObjRelation("SHEET", oSheet
);