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
.XEnumerationAccess
;
30 import com
.sun
.star
.container
.XIndexAccess
;
31 import com
.sun
.star
.lang
.XComponent
;
32 import com
.sun
.star
.sheet
.XDataPilotDescriptor
;
33 import com
.sun
.star
.sheet
.XDataPilotTables
;
34 import com
.sun
.star
.sheet
.XDataPilotTablesSupplier
;
35 import com
.sun
.star
.sheet
.XSpreadsheet
;
36 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
37 import com
.sun
.star
.sheet
.XSpreadsheets
;
38 import com
.sun
.star
.table
.CellAddress
;
39 import com
.sun
.star
.table
.CellRangeAddress
;
40 import com
.sun
.star
.uno
.AnyConverter
;
41 import com
.sun
.star
.uno
.Type
;
42 import com
.sun
.star
.uno
.UnoRuntime
;
43 import com
.sun
.star
.uno
.XInterface
;
45 public class ScIndexEnumeration_DataPilotFieldsEnumeration
extends TestCase
{
46 private XSpreadsheetDocument xSheetDoc
= null;
49 * Creates Spreadsheet document.
52 protected void initialize( TestParameters tParam
, PrintWriter log
) {
53 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
56 log
.println( "creating a Spreadsheet document" );
57 xSheetDoc
= SOF
.createCalcDoc(null);
58 } catch ( com
.sun
.star
.uno
.Exception e
) {
59 // Some exception occurs.FAILED
60 e
.printStackTrace( log
);
61 throw new StatusException( "Couldn't create document", e
);
67 * Disposes Spreadsheet document.
70 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
71 log
.println( " disposing xSheetDoc " );
72 XComponent oComp
= UnoRuntime
.queryInterface(XComponent
.class, xSheetDoc
) ;
73 util
.DesktopTools
.closeDoc(oComp
);
77 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
79 XInterface oObj
= null;
81 // creation of testobject here
82 // first we write what we are intend to do to log file
83 log
.println( "Creating a test environment" );
85 // create testobject here
87 log
.println("getting sheets");
88 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets();
90 log
.println("getting a sheet");
91 XSpreadsheet oSheet
= null;
92 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
94 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
95 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
96 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
97 e
.printStackTrace(log
);
98 throw new StatusException( "Couldn't get a spreadsheet", e
);
99 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
100 e
.printStackTrace(log
);
101 throw new StatusException( "Couldn't get a spreadsheet", e
);
102 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
103 e
.printStackTrace(log
);
104 throw new StatusException( "Couldn't get a spreadsheet", e
);
108 log
.println("Filing a table");
109 for (int i
= 1; i
< 4; i
++) {
110 oSheet
.getCellByPosition(i
, 0).setFormula("Col" + i
);
111 oSheet
.getCellByPosition(0, i
).setFormula("Row" + i
);
114 for (int i
= 1; i
< 4; i
++)
115 for (int j
= 1; j
< 4; j
++) {
116 oSheet
.getCellByPosition(i
, j
).setValue(i
* (j
+ 1));
118 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
119 e
.printStackTrace(log
);
120 throw new StatusException("Couldn't fill some cells", e
);
123 XDataPilotTablesSupplier DPTS
= UnoRuntime
.queryInterface(XDataPilotTablesSupplier
.class, oSheet
);
125 log
.println("Getting test object ") ;
127 XDataPilotTables DPT
= DPTS
.getDataPilotTables();
128 XDataPilotDescriptor DPDsc
= DPT
.createDataPilotDescriptor();
129 DPDsc
.setSourceRange(new CellRangeAddress((short)0, 0, 0, 4, 4));
132 new CellAddress((short)0, 5, 5),
135 oObj
= DPDsc
.getDataPilotFields();
136 log
.println("Creating object - " +
137 ((oObj
== null) ?
"FAILED" : "OK"));
139 XEnumerationAccess ea
= UnoRuntime
.queryInterface(XEnumerationAccess
.class,oObj
);
141 oObj
= ea
.createEnumeration();
143 log
.println("ImplementationName: "+util
.utils
.getImplName(oObj
));
144 // creating test environment
145 TestEnvironment tEnv
= new TestEnvironment( oObj
);
147 tEnv
.addObjRelation("ENUM",ea
);