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: ScDataPilotFieldsObj.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.DataPilotFields</code>. <p>
60 * Object implements the following interfaces :
62 * <li> <code>com::sun::star::container::XNameAccess</code></li>
63 * <li> <code>com::sun::star::container::XElementAccess</code></li>
65 * @see com.sun.star.sheet.DataPilotFields
66 * @see com.sun.star.container.XNameAccess
67 * @see com.sun.star.container.XElementAccess
68 * @see ifc.container._XNameAccess
69 * @see ifc.container._XElementAccess
71 public class ScDataPilotFieldsObj
extends TestCase
{
72 static XSpreadsheetDocument xSheetDoc
= null;
75 * Creates Spreadsheet document.
77 protected void initialize( TestParameters tParam
, PrintWriter log
) {
78 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
81 log
.println( "creating a Spreadsheet document" );
82 xSheetDoc
= SOF
.createCalcDoc(null);
83 } catch ( com
.sun
.star
.uno
.Exception e
) {
84 // Some exception occures.FAILED
85 e
.printStackTrace( log
);
86 throw new StatusException( "Couldn't create document", e
);
92 * Disposes Spreadsheet document.
94 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
95 log
.println( " disposing xSheetDoc " );
96 XComponent oComp
= (XComponent
)
97 UnoRuntime
.queryInterface(XComponent
.class, xSheetDoc
) ;
98 util
.DesktopTools
.closeDoc(oComp
);
102 * Creating a Testenvironment for the interfaces to be tested.
103 * Retrieves a collection of spreadsheets from a document
104 * and takes one of them. Fills some table in the spreadsheet.
105 * Obtains the collection of data pilot tables using the interface
106 * <code>XDataPilotTablesSupplier</code>. Creates a data pilot descriptor
107 * for the filled table and inserts new data pilot table with this descriptor
108 * to the collection. Obtains the collection of all the data pilot fields
109 * using the interface <code>XDataPilotDescriptor</code>. This collection
110 * is the instance of the service <code>com.sun.star.sheet.DataPilotFields</code>.
111 * @see com.sun.star.sheet.DataPilotFields
112 * @see com.sun.star.sheet.XDataPilotTablesSupplier
113 * @see com.sun.star.sheet.XDataPilotDescriptor
115 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
117 XInterface oObj
= null;
119 // creation of testobject here
120 // first we write what we are intend to do to log file
121 log
.println( "Creating a test environment" );
123 // create testobject here
125 log
.println("getting sheets");
126 XSpreadsheets xSpreadsheets
= (XSpreadsheets
)xSheetDoc
.getSheets();
128 log
.println("getting a sheet");
129 XSpreadsheet oSheet
= null;
130 XIndexAccess oIndexAccess
= (XIndexAccess
)
131 UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
133 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
134 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
135 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
136 e
.printStackTrace(log
);
137 throw new StatusException( "Couldn't get a spreadsheet", e
);
138 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
139 e
.printStackTrace(log
);
140 throw new StatusException( "Couldn't get a spreadsheet", e
);
141 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
142 e
.printStackTrace(log
);
143 throw new StatusException( "Couldn't get a spreadsheet", e
);
147 log
.println("Filing a table");
148 for (int i
= 1; i
< 4; i
++) {
149 oSheet
.getCellByPosition(i
, 0).setFormula("Col" + i
);
150 oSheet
.getCellByPosition(0, i
).setFormula("Row" + i
);
153 for (int i
= 1; i
< 4; i
++)
154 for (int j
= 1; j
< 4; j
++) {
155 oSheet
.getCellByPosition(i
, j
).setValue(i
* (j
+ 1));
157 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
158 e
.printStackTrace(log
);
159 throw new StatusException("Couldn't fill some cells", e
);
162 XDataPilotTablesSupplier DPTS
= (XDataPilotTablesSupplier
)
163 UnoRuntime
.queryInterface(XDataPilotTablesSupplier
.class, oSheet
);
165 log
.println("Getting test object ") ;
167 XDataPilotTables DPT
= DPTS
.getDataPilotTables();
168 XDataPilotDescriptor DPDsc
= DPT
.createDataPilotDescriptor();
169 DPDsc
.setSourceRange(new CellRangeAddress((short)0, 0, 0, 4, 4));
172 new CellAddress((short)0, 5, 5),
175 oObj
= DPDsc
.getDataPilotFields();
176 log
.println("Creating object - " +
177 ((oObj
== null) ?
"FAILED" : "OK"));
179 TestEnvironment tEnv
= new TestEnvironment( oObj
);
181 // Other parameters required for interface tests