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
.lang
.XMultiServiceFactory
;
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
.sheet
.XSubTotalField
;
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
;
46 * Test for object which is represented by service
47 * <code>com.sun.star.sheet.SubTotalField</code>. <p>
48 * Object implements the following interfaces :
50 * <li> <code>com::sun::star::sheet::XSubTotalField</code></li>
52 * @see com.sun.star.sheet.SubTotalField
53 * @see com.sun.star.sheet.XSubTotalField
54 * @see ifc.sheet._XSubTotalField
56 public class ScSubTotalFieldObj
extends TestCase
{
57 private XSpreadsheetDocument xSpreadsheetDoc
;
60 * 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( (XMultiServiceFactory
)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.
82 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
83 log
.println( " disposing xSheetDoc " );
84 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
) ;
85 util
.DesktopTools
.closeDoc(oComp
);
89 * Creating a Testenvironment for the interfaces to be tested.
90 * Retrieves a collection of spreadsheets from the document and takes one of
91 * them. Creates a subtotal descriptor using the interface
92 * <code>XSubTotalCalculatable</code>. Adds a subtotal field definition to
93 * the descriptor. Obtains the subtotal field with index 0 from the
94 * collection. The obtained subtotal field is the instance of the service
95 * <code>com.sun.star.sheet.SubTotalField</code>.
96 * @see com.sun.star.sheet.XSubTotalCalculatable
97 * @see com.sun.star.sheet.SubTotalField
99 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
101 log
.println("getting sheets");
102 XSpreadsheets xSpreadsheets
= xSpreadsheetDoc
.getSheets();
104 log
.println("getting a sheet");
105 XSpreadsheet oSheet
= null;
106 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
108 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
109 new Type (XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
110 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
111 e
.printStackTrace(log
);
112 throw new StatusException( "Couldn't get a spreadsheet", e
);
113 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
114 e
.printStackTrace(log
);
115 throw new StatusException( "Couldn't get a spreadsheet", e
);
116 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
117 e
.printStackTrace(log
);
118 throw new StatusException( "Couldn't get a spreadsheet", e
);
121 XSubTotalCalculatable xSTC
= UnoRuntime
.queryInterface(XSubTotalCalculatable
.class, oSheet
);
123 XSubTotalDescriptor xSTD
= xSTC
.createSubTotalDescriptor(true);
125 SubTotalColumn
[] columns
= new SubTotalColumn
[1];
126 SubTotalColumn column
= new SubTotalColumn();
128 column
.Function
= GeneralFunction
.SUM
;
130 xSTD
.addNew(columns
, 1);
132 XIndexAccess oDescIndex
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSTD
);
134 XInterface oObj
= null;
137 oObj
= ( XSubTotalField
) AnyConverter
.toObject(
138 new Type(XSubTotalField
.class),oDescIndex
.getByIndex(0));
139 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
140 e
.printStackTrace(log
);
141 throw new StatusException("Couldn't get XSubTotalField", e
);
142 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
143 e
.printStackTrace(log
);
144 throw new StatusException("Couldn't get XSubTotalField", e
);
145 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
146 e
.printStackTrace(log
);
147 throw new StatusException("Couldn't get XSubTotalField", e
);
150 TestEnvironment tEnv
= new TestEnvironment(oObj
);
153 } // finish method getTestEnvironment
155 } // finish class ScSubTotalFieldObj