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
.GeneralFunction
;
33 import com
.sun
.star
.sheet
.SubTotalColumn
;
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
.sheet
.XSubTotalCalculatable
;
38 import com
.sun
.star
.sheet
.XSubTotalDescriptor
;
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
;
44 public class ScIndexEnumeration_SubTotalFieldsEnumeration
extends TestCase
{
45 private XSpreadsheetDocument xSpreadsheetDoc
;
48 * Creates Spreadsheet document.
51 public void initialize( TestParameters Param
, PrintWriter log
) {
52 // creation of the testobject here
53 // first we write what we are intend to do to log file
54 log
.println("creating a test environment");
56 // get a soffice factory object
57 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
60 log
.println("creating a spreadsheetdocument");
61 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
62 } catch (com
.sun
.star
.uno
.Exception e
) {
63 e
.printStackTrace( log
);
64 throw new StatusException( "Couldn't create document ", e
);
69 * Disposes Spreadsheet document.
72 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
73 log
.println( " disposing xSheetDoc " );
74 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
) ;
75 util
.DesktopTools
.closeDoc(oComp
);
79 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
81 log
.println("getting sheets");
82 XSpreadsheets xSpreadsheets
= xSpreadsheetDoc
.getSheets();
84 log
.println("getting a sheet");
85 XSpreadsheet oSheet
= null;
86 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
88 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
89 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
90 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
91 e
.printStackTrace(log
);
92 throw new StatusException( "Couldn't get a spreadsheet", e
);
93 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
94 e
.printStackTrace(log
);
95 throw new StatusException( "Couldn't get a spreadsheet", e
);
96 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
97 e
.printStackTrace(log
);
98 throw new StatusException( "Couldn't get a spreadsheet", e
);
101 XSubTotalCalculatable xSTC
= UnoRuntime
.queryInterface(XSubTotalCalculatable
.class, oSheet
);
103 XSubTotalDescriptor xSTD
= xSTC
.createSubTotalDescriptor(true);
105 SubTotalColumn
[] columns
= new SubTotalColumn
[1];
106 SubTotalColumn column
= new SubTotalColumn();
108 column
.Function
= GeneralFunction
.SUM
;
110 xSTD
.addNew(columns
, 1);
112 XIndexAccess oDescIndex
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSTD
);
114 XInterface oObj
= null;
116 XEnumerationAccess ea
= UnoRuntime
.queryInterface(XEnumerationAccess
.class,oDescIndex
);
118 oObj
= ea
.createEnumeration();
120 log
.println("ImplementationName: "+util
.utils
.getImplName(oObj
));
121 // creating test environment
122 TestEnvironment tEnv
= new TestEnvironment( oObj
);
124 tEnv
.addObjRelation("ENUM",ea
);
128 } // finish method getTestEnvironment