1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScSubTotalFieldObj.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.container
.XIndexAccess
;
42 import com
.sun
.star
.lang
.XComponent
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.sheet
.GeneralFunction
;
45 import com
.sun
.star
.sheet
.SubTotalColumn
;
46 import com
.sun
.star
.sheet
.XSpreadsheet
;
47 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
48 import com
.sun
.star
.sheet
.XSpreadsheets
;
49 import com
.sun
.star
.sheet
.XSubTotalCalculatable
;
50 import com
.sun
.star
.sheet
.XSubTotalDescriptor
;
51 import com
.sun
.star
.sheet
.XSubTotalField
;
52 import com
.sun
.star
.uno
.AnyConverter
;
53 import com
.sun
.star
.uno
.Type
;
54 import com
.sun
.star
.uno
.UnoRuntime
;
55 import com
.sun
.star
.uno
.XInterface
;
58 * Test for object which is represented by service
59 * <code>com.sun.star.sheet.SubTotalField</code>. <p>
60 * Object implements the following interfaces :
62 * <li> <code>com::sun::star::sheet::XSubTotalField</code></li>
64 * @see com.sun.star.sheet.SubTotalField
65 * @see com.sun.star.sheet.XSubTotalField
66 * @see ifc.sheet._XSubTotalField
68 public class ScSubTotalFieldObj
extends TestCase
{
69 public static XSpreadsheetDocument xSpreadsheetDoc
;
72 * Creates Spreadsheet document.
74 public void initialize( TestParameters Param
, PrintWriter log
) {
75 // creation of the testobject here
76 // first we write what we are intend to do to log file
77 log
.println("creating a test environment");
79 // get a soffice factory object
80 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)Param
.getMSF());
83 log
.println("creating a spreadsheetdocument");
84 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
85 } catch (com
.sun
.star
.uno
.Exception e
) {
86 e
.printStackTrace( log
);
87 throw new StatusException( "Couldn't create document ", e
);
92 * Disposes Spreadsheet document.
94 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
95 log
.println( " disposing xSheetDoc " );
96 XComponent oComp
= (XComponent
)
97 UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
) ;
98 util
.DesktopTools
.closeDoc(oComp
);
102 * Creating a Testenvironment for the interfaces to be tested.
103 * Retrieves a collection of spreadsheets from the document and takes one of
104 * them. Creates a subtotal descriptor using the interface
105 * <code>XSubTotalCalculatable</code>. Adds a subtotal field definition to
106 * the descriptor. Obtains the subtotal field with index 0 from the
107 * collection. The obtained subtotal field is the instance of the service
108 * <code>com.sun.star.sheet.SubTotalField</code>.
109 * @see com.sun.star.sheet.XSubTotalCalculatable
110 * @see com.sun.star.sheet.SubTotalField
112 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
114 log
.println("getting sheets");
115 XSpreadsheets xSpreadsheets
= (XSpreadsheets
)xSpreadsheetDoc
.getSheets();
117 log
.println("getting a sheet");
118 XSpreadsheet oSheet
= null;
119 XIndexAccess oIndexAccess
= (XIndexAccess
)
120 UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
122 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
123 new Type (XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
124 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
125 e
.printStackTrace(log
);
126 throw new StatusException( "Couldn't get a spreadsheet", e
);
127 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
128 e
.printStackTrace(log
);
129 throw new StatusException( "Couldn't get a spreadsheet", e
);
130 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
131 e
.printStackTrace(log
);
132 throw new StatusException( "Couldn't get a spreadsheet", e
);
135 XSubTotalCalculatable xSTC
= (XSubTotalCalculatable
)
136 UnoRuntime
.queryInterface(XSubTotalCalculatable
.class, oSheet
);
138 XSubTotalDescriptor xSTD
= xSTC
.createSubTotalDescriptor(true);
140 SubTotalColumn
[] columns
= new SubTotalColumn
[1];
141 SubTotalColumn column
= new SubTotalColumn();
143 column
.Function
= GeneralFunction
.SUM
;
145 xSTD
.addNew(columns
, 1);
147 XIndexAccess oDescIndex
= (XIndexAccess
)
148 UnoRuntime
.queryInterface(XIndexAccess
.class, xSTD
);
150 XInterface oObj
= null;
153 oObj
= ( XSubTotalField
) AnyConverter
.toObject(
154 new Type(XSubTotalField
.class),oDescIndex
.getByIndex(0));
155 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
156 e
.printStackTrace(log
);
157 throw new StatusException("Couldn't get XSubTotalField", e
);
158 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
159 e
.printStackTrace(log
);
160 throw new StatusException("Couldn't get XSubTotalField", e
);
161 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
162 e
.printStackTrace(log
);
163 throw new StatusException("Couldn't get XSubTotalField", e
);
166 TestEnvironment tEnv
= new TestEnvironment(oObj
);
169 } // finish method getTestEnvironment
171 } // finish class ScSubTotalFieldObj