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