bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScSubTotalDescriptorBase.java
blobb331e70ce29e4b0be58e54790a795f1d7b70ac72
1 /*
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 .
19 package mod._sc;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
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.uno.AnyConverter;
40 import com.sun.star.uno.Type;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
45 /**
46 * Test for object which is represented by service
47 * <code>com.sun.star.sheet.SubTotalDescriptor</code>. <p>
48 * Object implements the following interfaces :
49 * <ul>
50 * <li> <code>com::sun::star::sheet::XSubTotalDescriptor</code></li>
51 * <li> <code>com::sun::star::sheet::SubTotalDescriptor</code></li>
52 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
53 * </ul>
54 * @see com.sun.star.sheet.XSubTotalDescriptor
55 * @see com.sun.star.sheet.SubTotalDescriptor
56 * @see com.sun.star.beans.XPropertySet
57 * @see ifc.sheet._XSubTotalDescriptor
58 * @see ifc.sheet._SubTotalDescriptor
59 * @see ifc.beans._XPropertySet
61 public class ScSubTotalDescriptorBase extends TestCase {
62 private XSpreadsheetDocument xSpreadsheetDoc;
64 /**
65 * 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( (XMultiServiceFactory)Param.getMSF());
75 try {
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 );
84 /**
85 * Disposes Spreadsheet document.
87 protected void cleanup( TestParameters tParam, PrintWriter log ) {
88 log.println( " disposing xSheetDoc " );
89 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ;
90 util.DesktopTools.closeDoc(oComp);
93 /**
94 * Creating a Testenvironment for the interfaces to be tested.
95 * Retrieves a collection of spreadsheets from the document and takes one of
96 * them. Creates a subtotal descriptor using the interface
97 * <code>XSubTotalCalculatable</code>. This descriptor is the instance of the
98 * service <code>com.sun.star.sheet.SubTotalDescriptor</code>.
99 * @see com.sun.star.sheet.XSubTotalCalculatable
100 * @see com.sun.star.sheet.SubTotalDescriptor
102 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
104 log.println("getting sheets");
105 XSpreadsheets xSpreadsheets = xSpreadsheetDoc.getSheets();
107 log.println("getting a sheet");
108 XSpreadsheet oSheet = null;
109 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
110 try {
111 oSheet = (XSpreadsheet) AnyConverter.toObject(
112 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
113 } catch (com.sun.star.lang.WrappedTargetException e) {
114 e.printStackTrace(log);
115 throw new StatusException( "Couldn't get a spreadsheet", e);
116 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
117 e.printStackTrace(log);
118 throw new StatusException( "Couldn't get a spreadsheet", e);
119 } catch (com.sun.star.lang.IllegalArgumentException e) {
120 e.printStackTrace(log);
121 throw new StatusException( "Couldn't get a spreadsheet", e);
124 XSubTotalCalculatable xSTC = UnoRuntime.queryInterface(XSubTotalCalculatable.class, oSheet);
126 SubTotalColumn[] columns = new SubTotalColumn[1];
127 SubTotalColumn column = new SubTotalColumn();
128 column.Column = 3;
129 column.Function = GeneralFunction.SUM;
130 columns[0] = column;
132 XSubTotalDescriptor desc = xSTC.createSubTotalDescriptor(true);
133 desc.addNew(columns, 1);
135 XInterface oObj = desc;
137 TestEnvironment tEnv = new TestEnvironment(oObj);
138 return tEnv;
140 } // finish method getTestEnvironment
142 } // finish class ScSubTotalDescriptorBase