2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.container
.XIndexAccess
;
30 import com
.sun
.star
.lang
.XComponent
;
31 import com
.sun
.star
.sheet
.XDataPilotDescriptor
;
32 import com
.sun
.star
.sheet
.XDataPilotTables
;
33 import com
.sun
.star
.sheet
.XDataPilotTablesSupplier
;
34 import com
.sun
.star
.sheet
.XSpreadsheet
;
35 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
36 import com
.sun
.star
.sheet
.XSpreadsheets
;
37 import com
.sun
.star
.table
.CellAddress
;
38 import com
.sun
.star
.table
.CellRangeAddress
;
39 import com
.sun
.star
.uno
.AnyConverter
;
40 import com
.sun
.star
.uno
.Type
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
45 * Test for object which is represented by service
46 * <code>com.sun.star.sheet.DataPilotFields</code>. <p>
47 * Object implements the following interfaces :
49 * <li> <code>com::sun::star::container::XNameAccess</code></li>
50 * <li> <code>com::sun::star::container::XElementAccess</code></li>
52 * @see com.sun.star.sheet.DataPilotFields
53 * @see com.sun.star.container.XNameAccess
54 * @see com.sun.star.container.XElementAccess
55 * @see ifc.container._XNameAccess
56 * @see ifc.container._XElementAccess
58 public class ScDataPilotFieldsObj
extends TestCase
{
59 private XSpreadsheetDocument xSheetDoc
= null;
62 * Creates Spreadsheet document.
65 protected void initialize( TestParameters tParam
, PrintWriter log
) {
66 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
69 log
.println( "creating a Spreadsheet document" );
70 xSheetDoc
= SOF
.createCalcDoc(null);
71 } catch ( com
.sun
.star
.uno
.Exception e
) {
72 // Some exception occurs.FAILED
73 e
.printStackTrace( log
);
74 throw new StatusException( "Couldn't create document", e
);
80 * Disposes Spreadsheet document.
83 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
84 log
.println( " disposing xSheetDoc " );
85 XComponent oComp
= UnoRuntime
.queryInterface(XComponent
.class, xSheetDoc
) ;
86 util
.DesktopTools
.closeDoc(oComp
);
90 * Creating a Testenvironment for the interfaces to be tested.
91 * Retrieves a collection of spreadsheets from a document
92 * and takes one of them. Fills some table in the spreadsheet.
93 * Obtains the collection of data pilot tables using the interface
94 * <code>XDataPilotTablesSupplier</code>. Creates a data pilot descriptor
95 * for the filled table and inserts new data pilot table with this descriptor
96 * to the collection. Obtains the collection of all the data pilot fields
97 * using the interface <code>XDataPilotDescriptor</code>. This collection
98 * is the instance of the service <code>com.sun.star.sheet.DataPilotFields</code>.
99 * @see com.sun.star.sheet.DataPilotFields
100 * @see com.sun.star.sheet.XDataPilotTablesSupplier
101 * @see com.sun.star.sheet.XDataPilotDescriptor
104 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
106 XInterface oObj
= null;
108 // creation of testobject here
109 // first we write what we are intend to do to log file
110 log
.println( "Creating a test environment" );
112 // create testobject here
114 log
.println("getting sheets");
115 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets();
117 log
.println("getting a sheet");
118 XSpreadsheet oSheet
= null;
119 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
121 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
122 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
123 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
124 e
.printStackTrace(log
);
125 throw new StatusException( "Couldn't get a spreadsheet", e
);
126 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
127 e
.printStackTrace(log
);
128 throw new StatusException( "Couldn't get a spreadsheet", e
);
129 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
130 e
.printStackTrace(log
);
131 throw new StatusException( "Couldn't get a spreadsheet", e
);
135 log
.println("Filing a table");
136 for (int i
= 1; i
< 4; i
++) {
137 oSheet
.getCellByPosition(i
, 0).setFormula("Col" + i
);
138 oSheet
.getCellByPosition(0, i
).setFormula("Row" + i
);
141 for (int i
= 1; i
< 4; i
++)
142 for (int j
= 1; j
< 4; j
++) {
143 oSheet
.getCellByPosition(i
, j
).setValue(i
* (j
+ 1));
145 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
146 e
.printStackTrace(log
);
147 throw new StatusException("Couldn't fill some cells", e
);
150 XDataPilotTablesSupplier DPTS
= UnoRuntime
.queryInterface(XDataPilotTablesSupplier
.class, oSheet
);
152 log
.println("Getting test object ") ;
154 XDataPilotTables DPT
= DPTS
.getDataPilotTables();
155 XDataPilotDescriptor DPDsc
= DPT
.createDataPilotDescriptor();
156 DPDsc
.setSourceRange(new CellRangeAddress((short)0, 0, 0, 4, 4));
159 new CellAddress((short)0, 5, 5),
162 oObj
= DPDsc
.getDataPilotFields();
163 log
.println("Creating object - " +
164 ((oObj
== null) ?
"FAILED" : "OK"));
166 TestEnvironment tEnv
= new TestEnvironment( oObj
);
168 // Other parameters required for interface tests