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
.lang
.XMultiServiceFactory
;
33 import com
.sun
.star
.sheet
.XDataPilotDescriptor
;
34 import com
.sun
.star
.sheet
.XDataPilotTables
;
35 import com
.sun
.star
.sheet
.XDataPilotTablesSupplier
;
36 import com
.sun
.star
.sheet
.XSpreadsheet
;
37 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
38 import com
.sun
.star
.sheet
.XSpreadsheets
;
39 import com
.sun
.star
.table
.CellAddress
;
40 import com
.sun
.star
.table
.CellRangeAddress
;
41 import com
.sun
.star
.uno
.AnyConverter
;
42 import com
.sun
.star
.uno
.Type
;
43 import com
.sun
.star
.uno
.UnoRuntime
;
44 import com
.sun
.star
.uno
.XInterface
;
46 public class ScIndexEnumeration_DataPilotFieldsEnumeration
extends TestCase
{
47 private XSpreadsheetDocument xSheetDoc
= null;
50 * Creates Spreadsheet document.
52 protected void initialize( TestParameters tParam
, PrintWriter log
) {
53 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)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.
69 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
70 log
.println( " disposing xSheetDoc " );
71 XComponent oComp
= UnoRuntime
.queryInterface(XComponent
.class, xSheetDoc
) ;
72 util
.DesktopTools
.closeDoc(oComp
);
75 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
77 XInterface oObj
= null;
79 // creation of testobject here
80 // first we write what we are intend to do to log file
81 log
.println( "Creating a test environment" );
83 // create testobject here
85 log
.println("getting sheets");
86 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets();
88 log
.println("getting a sheet");
89 XSpreadsheet oSheet
= null;
90 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
92 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
93 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
94 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
95 e
.printStackTrace(log
);
96 throw new StatusException( "Couldn't get a spreadsheet", e
);
97 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
98 e
.printStackTrace(log
);
99 throw new StatusException( "Couldn't get a spreadsheet", e
);
100 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
101 e
.printStackTrace(log
);
102 throw new StatusException( "Couldn't get a spreadsheet", e
);
106 log
.println("Filing a table");
107 for (int i
= 1; i
< 4; i
++) {
108 oSheet
.getCellByPosition(i
, 0).setFormula("Col" + i
);
109 oSheet
.getCellByPosition(0, i
).setFormula("Row" + i
);
112 for (int i
= 1; i
< 4; i
++)
113 for (int j
= 1; j
< 4; j
++) {
114 oSheet
.getCellByPosition(i
, j
).setValue(i
* (j
+ 1));
116 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
117 e
.printStackTrace(log
);
118 throw new StatusException("Couldn't fill some cells", e
);
121 XDataPilotTablesSupplier DPTS
= UnoRuntime
.queryInterface(XDataPilotTablesSupplier
.class, oSheet
);
123 log
.println("Getting test object ") ;
125 XDataPilotTables DPT
= DPTS
.getDataPilotTables();
126 XDataPilotDescriptor DPDsc
= DPT
.createDataPilotDescriptor();
127 DPDsc
.setSourceRange(new CellRangeAddress((short)0, 0, 0, 4, 4));
130 new CellAddress((short)0, 5, 5),
133 oObj
= DPDsc
.getDataPilotFields();
134 log
.println("Creating object - " +
135 ((oObj
== null) ?
"FAILED" : "OK"));
137 XEnumerationAccess ea
= UnoRuntime
.queryInterface(XEnumerationAccess
.class,oObj
);
139 oObj
= ea
.createEnumeration();
141 log
.println("ImplementationName: "+util
.utils
.getImplName(oObj
));
142 // creating test environment
143 TestEnvironment tEnv
= new TestEnvironment( oObj
);
145 tEnv
.addObjRelation("ENUM",ea
);