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
.uno
.AnyConverter
;
39 import com
.sun
.star
.uno
.Type
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
45 * Test for object which is represented by service
46 * <code>com.sun.star.sheet.SubTotalDescriptor</code>. <p>
47 * Object implements the following interfaces :
49 * <li> <code>com::sun::star::sheet::XSubTotalDescriptor</code></li>
50 * <li> <code>com::sun::star::sheet::SubTotalDescriptor</code></li>
51 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
53 * @see com.sun.star.sheet.XSubTotalDescriptor
54 * @see com.sun.star.sheet.SubTotalDescriptor
55 * @see com.sun.star.beans.XPropertySet
56 * @see ifc.sheet._XSubTotalDescriptor
57 * @see ifc.sheet._SubTotalDescriptor
58 * @see ifc.beans._XPropertySet
60 public class ScSubTotalDescriptorBase
extends TestCase
{
61 private XSpreadsheetDocument xSpreadsheetDoc
;
64 * Creates Spreadsheet document.
67 public void initialize( TestParameters Param
, PrintWriter log
) {
68 // creation of the testobject here
69 // first we write what we are intend to do to log file
70 log
.println("creating a test environment");
72 // get a soffice factory object
73 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
76 log
.println("creating a spreadsheetdocument");
77 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
78 } catch (com
.sun
.star
.uno
.Exception e
) {
79 e
.printStackTrace( log
);
80 throw new StatusException( "Couldn't create document ", e
);
85 * Disposes Spreadsheet document.
88 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
89 log
.println( " disposing xSheetDoc " );
90 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
) ;
91 util
.DesktopTools
.closeDoc(oComp
);
95 * Creating a Testenvironment for the interfaces to be tested.
96 * Retrieves a collection of spreadsheets from the document and takes one of
97 * them. Creates a subtotal descriptor using the interface
98 * <code>XSubTotalCalculatable</code>. This descriptor is the instance of the
99 * service <code>com.sun.star.sheet.SubTotalDescriptor</code>.
100 * @see com.sun.star.sheet.XSubTotalCalculatable
101 * @see com.sun.star.sheet.SubTotalDescriptor
104 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
106 log
.println("getting sheets");
107 XSpreadsheets xSpreadsheets
= xSpreadsheetDoc
.getSheets();
109 log
.println("getting a sheet");
110 XSpreadsheet oSheet
= null;
111 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
113 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
114 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
115 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
116 e
.printStackTrace(log
);
117 throw new StatusException( "Couldn't get a spreadsheet", e
);
118 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
119 e
.printStackTrace(log
);
120 throw new StatusException( "Couldn't get a spreadsheet", e
);
121 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
122 e
.printStackTrace(log
);
123 throw new StatusException( "Couldn't get a spreadsheet", e
);
126 XSubTotalCalculatable xSTC
= UnoRuntime
.queryInterface(XSubTotalCalculatable
.class, oSheet
);
128 SubTotalColumn
[] columns
= new SubTotalColumn
[1];
129 SubTotalColumn column
= new SubTotalColumn();
131 column
.Function
= GeneralFunction
.SUM
;
134 XSubTotalDescriptor desc
= xSTC
.createSubTotalDescriptor(true);
135 desc
.addNew(columns
, 1);
137 XInterface oObj
= desc
;
139 TestEnvironment tEnv
= new TestEnvironment(oObj
);
142 } // finish method getTestEnvironment
144 } // finish class ScSubTotalDescriptorBase