bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScDataPilotFieldsObj.java
blobb114991b3f3e144219622e490a62342f6e4a306d
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.DataPilotFields</code>. <p>
48 * Object implements the following interfaces :
49 * <ul>
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.DataPilotFields
54 * @see com.sun.star.container.XNameAccess
55 * @see com.sun.star.container.XElementAccess
56 * @see ifc.container._XNameAccess
57 * @see ifc.container._XElementAccess
59 public class ScDataPilotFieldsObj extends TestCase {
60 private XSpreadsheetDocument xSheetDoc = null;
62 /**
63 * Creates Spreadsheet document.
65 protected void initialize( TestParameters tParam, PrintWriter log ) {
66 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
68 try {
69 log.println( "creating a Spreadsheet document" );
70 xSheetDoc = SOF.createCalcDoc(null);
71 } catch ( com.sun.star.uno.Exception e ) {
72 // Some exception occurs.FAILED
73 e.printStackTrace( log );
74 throw new StatusException( "Couldn't create document", e );
79 /**
80 * Disposes Spreadsheet document.
82 protected void cleanup( TestParameters tParam, PrintWriter log ) {
83 log.println( " disposing xSheetDoc " );
84 XComponent oComp = UnoRuntime.queryInterface(XComponent.class, xSheetDoc) ;
85 util.DesktopTools.closeDoc(oComp);
88 /**
89 * Creating a Testenvironment for the interfaces to be tested.
90 * Retrieves a collection of spreadsheets from a document
91 * and takes one of them. Fills some table in the spreadsheet.
92 * Obtains the collection of data pilot tables using the interface
93 * <code>XDataPilotTablesSupplier</code>. Creates a data pilot descriptor
94 * for the filled table and inserts new data pilot table with this descriptor
95 * to the collection. Obtains the collection of all the data pilot fields
96 * using the interface <code>XDataPilotDescriptor</code>. This collection
97 * is the instance of the service <code>com.sun.star.sheet.DataPilotFields</code>.
98 * @see com.sun.star.sheet.DataPilotFields
99 * @see com.sun.star.sheet.XDataPilotTablesSupplier
100 * @see com.sun.star.sheet.XDataPilotDescriptor
102 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
104 XInterface oObj = null;
106 // creation of testobject here
107 // first we write what we are intend to do to log file
108 log.println( "Creating a test environment" );
110 // create testobject here
112 log.println("getting sheets");
113 XSpreadsheets xSpreadsheets = xSheetDoc.getSheets();
115 log.println("getting a sheet");
116 XSpreadsheet oSheet = null;
117 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
118 try {
119 oSheet = (XSpreadsheet) AnyConverter.toObject(
120 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
121 } catch (com.sun.star.lang.WrappedTargetException e) {
122 e.printStackTrace(log);
123 throw new StatusException( "Couldn't get a spreadsheet", e);
124 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
125 e.printStackTrace(log);
126 throw new StatusException( "Couldn't get a spreadsheet", e);
127 } catch (com.sun.star.lang.IllegalArgumentException e) {
128 e.printStackTrace(log);
129 throw new StatusException( "Couldn't get a spreadsheet", e);
132 try {
133 log.println("Filing a table");
134 for (int i = 1; i < 4; i++) {
135 oSheet.getCellByPosition(i, 0).setFormula("Col" + i);
136 oSheet.getCellByPosition(0, i).setFormula("Row" + i);
139 for (int i = 1; i < 4; i++)
140 for (int j = 1; j < 4; j++) {
141 oSheet.getCellByPosition(i, j).setValue(i * (j + 1));
143 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
144 e.printStackTrace(log);
145 throw new StatusException("Couldn't fill some cells", e);
148 XDataPilotTablesSupplier DPTS = UnoRuntime.queryInterface(XDataPilotTablesSupplier.class, oSheet);
150 log.println("Getting test object ") ;
152 XDataPilotTables DPT = DPTS.getDataPilotTables();
153 XDataPilotDescriptor DPDsc = DPT.createDataPilotDescriptor();
154 DPDsc.setSourceRange(new CellRangeAddress((short)0, 0, 0, 4, 4));
155 DPT.insertNewByName(
156 "DataPilotTable",
157 new CellAddress((short)0, 5, 5),
158 DPDsc);
160 oObj = DPDsc.getDataPilotFields();
161 log.println("Creating object - " +
162 ((oObj == null) ? "FAILED" : "OK"));
164 TestEnvironment tEnv = new TestEnvironment( oObj );
166 // Other parameters required for interface tests
168 return tEnv;