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