1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package complex
.cellRanges
;
30 import com
.sun
.star
.container
.XIndexAccess
;
31 import complexlib
.ComplexTestCase
;
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
33 import com
.sun
.star
.sheet
.CellFlags
;
34 import com
.sun
.star
.sheet
.XCellRangesQuery
;
35 import com
.sun
.star
.sheet
.XSheetCellRanges
;
36 import com
.sun
.star
.sheet
.XSpreadsheet
;
37 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
38 import com
.sun
.star
.sheet
.XSpreadsheets
;
39 import com
.sun
.star
.table
.CellAddress
;
40 import com
.sun
.star
.table
.XColumnRowRange
;
41 import com
.sun
.star
.table
.XTableColumns
;
42 import com
.sun
.star
.table
.XTableRows
;
43 import com
.sun
.star
.uno
.AnyConverter
;
44 import com
.sun
.star
.uno
.Type
;
45 import com
.sun
.star
.uno
.UnoRuntime
;
46 import com
.sun
.star
.uno
.XInterface
;
47 import java
.io
.PrintWriter
;
48 import util
.SOfficeFactory
;
51 * Check the XCellRangesQuery interface on the SheetCell service. test was
52 * created for bug i20044.
54 public class CheckXCellRangesQuery
extends ComplexTestCase
{
55 XSpreadsheetDocument m_xSheetDoc
= null;
56 XCellRangesQuery m_xCell
= null;
57 XSpreadsheet m_xSpreadSheet
= null;
60 * Get all test methods.
61 * @return The test methods.
63 public String
[] getTestMethodNames() {
64 return new String
[] {"checkEmptyCell", "checkFilledCell"};
68 * Creates Spreadsheet document and the test object,
69 * before the actual test starts.
71 public void before() {
72 // create a calc document
73 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)param
.getMSF() );
76 log
.println( "creating a Spreadsheet document" );
77 m_xSheetDoc
= SOF
.createCalcDoc(null);
78 } catch ( com
.sun
.star
.uno
.Exception e
) {
79 // Some exception occures.FAILED
80 e
.printStackTrace( (PrintWriter
)log
);
81 failed( "Couldn?t create document");
83 XInterface oObj
= null;
86 log
.println("Getting spreadsheet") ;
87 XSpreadsheets oSheets
= m_xSheetDoc
.getSheets() ;
88 XIndexAccess oIndexSheets
= (XIndexAccess
)
89 UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
90 m_xSpreadSheet
= (XSpreadsheet
) AnyConverter
.toObject(
91 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
94 log
.println("Getting a cell from sheet") ;
95 oObj
= m_xSpreadSheet
.getCellByPosition(2, 3);
96 m_xCell
= (XCellRangesQuery
)UnoRuntime
.queryInterface(XCellRangesQuery
.class, oObj
);
98 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
99 e
.printStackTrace((PrintWriter
)log
);
100 failed("Error getting cell object from spreadsheet document");
101 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
102 e
.printStackTrace((PrintWriter
)log
);
103 failed("Error getting cell object from spreadsheet document");
104 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
105 e
.printStackTrace((PrintWriter
)log
);
106 failed("Error getting cell object from spreadsheet document");
109 // set one value for comparison.
111 m_xSpreadSheet
.getCellByPosition(1, 1).setValue(15);
112 m_xSpreadSheet
.getCellByPosition(1, 3).setValue(5);
113 m_xSpreadSheet
.getCellByPosition(2, 1).setFormula("=B2+B4");
114 /* m_xSpreadSheet.getCellByPosition(2, 1).setFormula("=B2+B3");
115 m_xSpreadSheet.getCellByPosition(3, 2).setFormula("");
116 m_xSpreadSheet.getCellByPosition(3, 3).setFormula(""); */
117 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
118 e
.printStackTrace((PrintWriter
)log
);
119 failed("Could not fill cell (1, 1) with a value.");
125 * Perform some tests on an empty cell:
127 * <li>compare an empty cell with a cell with a value in the same column</li>
128 * <li>compare an empty cell with a cell with a value in the same row</li>
129 * <li>query for empty cells</li>
132 public void checkEmptyCell() {
133 log
.println("Checking an empty cell...");
134 // compare an empty cell with a cell with a value
135 assure("\tQuery column differences did not return the correct value.", _queryColumnDifferences("Sheet1.C4"), true);
136 // compare an empty cell with a cell with a value
137 assure("\tQuery column differences did not return the correct value.", _queryRowDifferences("Sheet1.C4"), true);
138 // try to get this cell
139 assure("\tQuery empty cells did not return the correct value.", _queryEmptyCells("Sheet1.C4"), true);
140 log
.println("...done");
144 * Perform some tests on a filled cell:
146 * <li>compare an cell with value 5 with a cell with value 15 in the same column</li>
147 * <li>compare an cell with value 5 with a cell with value 15 in the same row</li>
148 * <li>query for an empty cell.</li>
151 public void checkFilledCell() {
152 log
.println("Checking a filled cell...");
154 // fill the cell with a value
156 m_xSpreadSheet
.getCellByPosition(2, 3).setValue(15);
157 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
158 e
.printStackTrace((PrintWriter
)log
);
159 failed("Could not fill cell (2, 3) with a value.");
162 // compare an cell with value 5 with a cell with value 15
163 assure("\tQuery column differences did not return the correct value.", _queryColumnDifferences("Sheet1.C4"), true);
164 // compare an cell with value 5 with a cell with value 15
165 assure("\tQuery column differences did not return the correct value.", _queryRowDifferences("Sheet1.C4"), true);
166 // try to get nothing
167 assure("\tQuery empty cells did not return the correct value.", _queryEmptyCells(""), true);
168 log
.println("...done");
173 * Query column differences between my cell(2,3) and (1,1).
174 * @param expected The expected outcome value.
175 * @return True, if the result equals the expected result.
177 public boolean _queryColumnDifferences(String expected
) {
178 log
.println("\tQuery column differences");
179 XSheetCellRanges ranges
= m_xCell
.queryColumnDifferences(
180 new CellAddress((short) 0, 1, 1));
181 String getting
= ranges
.getRangeAddressesAsString();
183 if (!getting
.equals(expected
)) {
184 log
.println("\tGetting: " + getting
);
185 log
.println("\tShould have been: " + expected
);
192 * Query for an empty cell.
193 * @param expected The expected outcome value.
194 * @return True, if the result equals the expected result.
196 public boolean _queryEmptyCells(String expected
) {
197 log
.println("\tQuery empty cells");
198 XSheetCellRanges ranges
= m_xCell
.queryEmptyCells();
199 String getting
= ranges
.getRangeAddressesAsString();
201 if (!getting
.equals(expected
)) {
202 log
.println("\tGetting: " + getting
);
203 log
.println("\tShould have been: " + expected
);
210 * Query row differences between my cell(2,3) and (1,1).
211 * @param expected The expected outcome value.
212 * @return True, if the result equals the expected result.
214 public boolean _queryRowDifferences(String expected
) {
215 log
.println("\tQuery row differences");
216 XSheetCellRanges ranges
= m_xCell
.queryRowDifferences(
217 new CellAddress((short) 0, 1, 1));
218 String getting
= ranges
.getRangeAddressesAsString();
220 if (!getting
.equals(expected
)) {
221 log
.println("\tGetting: " + getting
);
222 log
.println("\tShould have been: " + expected
);