bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScDataPilotTablesObj.java
blob60823b792cfee3fe36202e7259716bd068377274
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.XDataPilotDescriptor;
33 import com.sun.star.sheet.XDataPilotTables;
34 import com.sun.star.sheet.XDataPilotTablesSupplier;
35 import com.sun.star.sheet.XSpreadsheet;
36 import com.sun.star.sheet.XSpreadsheetDocument;
37 import com.sun.star.sheet.XSpreadsheets;
38 import com.sun.star.table.CellAddress;
39 import com.sun.star.table.CellRangeAddress;
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;
45 /**
46 * Test for object which is represented by service
47 * <code>com.sun.star.sheet.DataPilotTables</code>. <p>
48 * Object implements the following interfaces :
49 * <ul>
50 * <li> <code>com::sun::star::sheet::XDataPilotTables</code></li>
51 * <li> <code>com::sun::star::container::XNameAccess</code></li>
52 * <li> <code>com::sun::star::container::XElementAccess</code></li>
53 * </ul>
54 * @see com.sun.star.sheet.DataPilotTables
55 * @see com.sun.star.sheet.XDataPilotTables
56 * @see com.sun.star.container.XNameAccess
57 * @see com.sun.star.container.XElementAccess
58 * @see ifc.sheet._XDataPilotTables
59 * @see ifc.container._XNameAccess
60 * @see ifc.container._XElementAccess
62 public class ScDataPilotTablesObj extends TestCase {
63 private XSpreadsheetDocument xSheetDoc = null;
65 /**
66 * Creates Spreadsheet document.
68 protected void initialize( TestParameters tParam, PrintWriter log ) {
69 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
71 try {
72 log.println( "creating a Spreadsheet document" );
73 xSheetDoc = SOF.createCalcDoc(null);
74 } catch ( com.sun.star.uno.Exception e ) {
75 // Some exception occurs.FAILED
76 e.printStackTrace( log );
77 throw new StatusException( "Couldn't create document", e );
82 /**
83 * Disposes Spreadsheet document.
85 protected void cleanup( TestParameters tParam, PrintWriter log ) {
86 log.println( " disposing xSheetDoc " );
87 XComponent oComp = UnoRuntime.queryInterface(XComponent.class, xSheetDoc) ;
88 util.DesktopTools.closeDoc(oComp);
91 /**
92 * Creating a Testenvironment for the interfaces to be tested.
93 * Retrieves a collection of spreadsheets from a document
94 * and takes one of them. Fills some table in the spreadsheet.
95 * Obtains the collection of data pilot tables using the interface
96 * <code>XDataPilotTablesSupplier</code>. Creates a data pilot descriptor
97 * for the filled table and inserts new data pilot table with this descriptor
98 * to the collection. The collection of data pilot tables is the instance of
99 * the service <code>com.sun.star.sheet.DataPilotTables</code>.
100 * Object relations created :
101 * <ul>
102 * <li> <code>'SHEET'</code> for
103 * {@link ifc.sheet._XDataPilotTables}(the spreadsheet which
104 * the collection of data pilot tables was retrieved from) </li>
105 * </ul>
106 * @see com.sun.star.sheet.DataPilotTable
107 * @see com.sun.star.sheet.XDataPilotTablesSupplier
109 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
111 XInterface oObj = null;
113 // creation of testobject here
114 // first we write what we are intend to do to log file
115 log.println( "Creating a test environment" );
117 // create testobject here
119 log.println("getting sheets");
120 XSpreadsheets xSpreadsheets = xSheetDoc.getSheets();
122 log.println("getting a sheet");
123 XSpreadsheet oSheet = null;
124 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
125 try {
126 oSheet = (XSpreadsheet) AnyConverter.toObject(
127 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
128 } catch (com.sun.star.lang.WrappedTargetException e) {
129 e.printStackTrace(log);
130 throw new StatusException( "Couldn't get a spreadsheet", e);
131 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
132 e.printStackTrace(log);
133 throw new StatusException( "Couldn't get a spreadsheet", e);
134 } catch (com.sun.star.lang.IllegalArgumentException e) {
135 e.printStackTrace(log);
136 throw new StatusException( "Couldn't get a spreadsheet", e);
140 try {
141 log.println("Filing a table");
142 for (int i = 1; i < 4; i++) {
143 oSheet.getCellByPosition(i, 0).setFormula("Col" + i);
144 oSheet.getCellByPosition(0, i).setFormula("Row" + i);
147 for (int i = 1; i < 4; i++)
148 for (int j = 1; j < 4; j++) {
149 oSheet.getCellByPosition(i, j).setValue(i * (j + 1));
151 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
152 e.printStackTrace(log);
153 throw new StatusException("Couldn't fill some cells", e);
156 XDataPilotTablesSupplier DPTS = UnoRuntime.queryInterface(XDataPilotTablesSupplier.class, oSheet);
158 log.println("Getting test object ") ;
160 XDataPilotTables DPT = DPTS.getDataPilotTables();
161 XDataPilotDescriptor DPDsc = DPT.createDataPilotDescriptor();
162 DPDsc.setSourceRange(new CellRangeAddress((short)0, 0, 0, 4, 4));
163 DPT.insertNewByName(
164 "DataPilotTable",
165 new CellAddress((short)0, 5, 5),
166 DPDsc );
168 oObj = DPT;
170 log.println("Creating object - " +
171 ((oObj == null) ? "FAILED" : "OK"));
173 TestEnvironment tEnv = new TestEnvironment( oObj );
175 // Other parameters required for interface tests
176 tEnv.addObjRelation("SHEET", oSheet);
178 return tEnv;