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
.GeneralFunction
;
32 import com
.sun
.star
.sheet
.SubTotalColumn
;
33 import com
.sun
.star
.sheet
.XSpreadsheet
;
34 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
35 import com
.sun
.star
.sheet
.XSpreadsheets
;
36 import com
.sun
.star
.sheet
.XSubTotalCalculatable
;
37 import com
.sun
.star
.sheet
.XSubTotalDescriptor
;
38 import com
.sun
.star
.sheet
.XSubTotalField
;
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.SubTotalField</code>. <p>
47 * Object implements the following interfaces :
49 * <li> <code>com::sun::star::sheet::XSubTotalField</code></li>
51 * @see com.sun.star.sheet.SubTotalField
52 * @see com.sun.star.sheet.XSubTotalField
53 * @see ifc.sheet._XSubTotalField
55 public class ScSubTotalFieldObj
extends TestCase
{
56 private XSpreadsheetDocument xSpreadsheetDoc
;
59 * Creates Spreadsheet document.
62 public void initialize( TestParameters Param
, PrintWriter log
) {
63 // creation of the testobject here
64 // first we write what we are intend to do to log file
65 log
.println("creating a test environment");
67 // get a soffice factory object
68 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
71 log
.println("creating a spreadsheetdocument");
72 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
73 } catch (com
.sun
.star
.uno
.Exception e
) {
74 e
.printStackTrace( log
);
75 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, xSpreadsheetDoc
) ;
86 util
.DesktopTools
.closeDoc(oComp
);
90 * Creating a Testenvironment for the interfaces to be tested.
91 * Retrieves a collection of spreadsheets from the document and takes one of
92 * them. Creates a subtotal descriptor using the interface
93 * <code>XSubTotalCalculatable</code>. Adds a subtotal field definition to
94 * the descriptor. Obtains the subtotal field with index 0 from the
95 * collection. The obtained subtotal field is the instance of the service
96 * <code>com.sun.star.sheet.SubTotalField</code>.
97 * @see com.sun.star.sheet.XSubTotalCalculatable
98 * @see com.sun.star.sheet.SubTotalField
101 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
103 log
.println("getting sheets");
104 XSpreadsheets xSpreadsheets
= xSpreadsheetDoc
.getSheets();
106 log
.println("getting a sheet");
107 XSpreadsheet oSheet
= null;
108 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
110 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
111 new Type (XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
112 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
113 e
.printStackTrace(log
);
114 throw new StatusException( "Couldn't get a spreadsheet", e
);
115 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
116 e
.printStackTrace(log
);
117 throw new StatusException( "Couldn't get a spreadsheet", e
);
118 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
119 e
.printStackTrace(log
);
120 throw new StatusException( "Couldn't get a spreadsheet", e
);
123 XSubTotalCalculatable xSTC
= UnoRuntime
.queryInterface(XSubTotalCalculatable
.class, oSheet
);
125 XSubTotalDescriptor xSTD
= xSTC
.createSubTotalDescriptor(true);
127 SubTotalColumn
[] columns
= new SubTotalColumn
[1];
128 SubTotalColumn column
= new SubTotalColumn();
130 column
.Function
= GeneralFunction
.SUM
;
132 xSTD
.addNew(columns
, 1);
134 XIndexAccess oDescIndex
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSTD
);
136 XInterface oObj
= null;
139 oObj
= ( XSubTotalField
) AnyConverter
.toObject(
140 new Type(XSubTotalField
.class),oDescIndex
.getByIndex(0));
141 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
142 e
.printStackTrace(log
);
143 throw new StatusException("Couldn't get XSubTotalField", e
);
144 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
145 e
.printStackTrace(log
);
146 throw new StatusException("Couldn't get XSubTotalField", e
);
147 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
148 e
.printStackTrace(log
);
149 throw new StatusException("Couldn't get XSubTotalField", e
);
152 TestEnvironment tEnv
= new TestEnvironment(oObj
);
155 } // finish method getTestEnvironment
157 } // finish class ScSubTotalFieldObj