1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XMultipleOperation.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import com
.sun
.star
.awt
.Point
;
33 import com
.sun
.star
.sheet
.TableOperationMode
;
34 import com
.sun
.star
.sheet
.XCellAddressable
;
35 import com
.sun
.star
.sheet
.XCellRangeAddressable
;
36 import com
.sun
.star
.sheet
.XMultipleOperation
;
37 import com
.sun
.star
.sheet
.XSpreadsheet
;
38 import com
.sun
.star
.table
.XCell
;
39 import com
.sun
.star
.table
.XCellRange
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
42 import lib
.MultiMethodTest
;
44 import lib
.StatusException
;
47 public class _XMultipleOperation
extends MultiMethodTest
{
48 public XMultipleOperation oObj
= null;
49 protected XSpreadsheet oSheet
= null;
52 protected void before() {
53 oSheet
= (XSpreadsheet
) tEnv
.getObjRelation("SHEET");
56 throw new StatusException(Status
.failed(
57 "Object relation oSheet is missing"));
60 if (UnoRuntime
.queryInterface(XSpreadsheet
.class, tEnv
.getTestObject()) != null) {
61 log
.println("We have a sheet and won't do TableOperationMode.BOTH");
66 public void _setTableOperation() {
68 XCellRange cellRange
= oSheet
.getCellRangeByName("$A$17:$A$17");
69 XCellRangeAddressable CRA
= (XCellRangeAddressable
) UnoRuntime
.queryInterface(
70 XCellRangeAddressable
.class,
76 cell
= oSheet
.getCellByPosition(0, 16);
77 cell
.setFormula("=a15+a16");
78 cell
= oSheet
.getCellByPosition(0, 14);
79 cell2
= oSheet
.getCellByPosition(0, 15);
80 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
81 log
.println("Exception while getting Cell " + e
.getMessage());
84 XCellAddressable CA
= (XCellAddressable
) UnoRuntime
.queryInterface(
85 XCellAddressable
.class, cell
);
86 XCellAddressable CA2
= (XCellAddressable
) UnoRuntime
.queryInterface(
87 XCellAddressable
.class, cell2
);
88 Point
[] cellCoords
= new Point
[3];
89 double[] cellValues
= new double[3];
91 log
.println("filling cells");
93 log
.println("setting TableOperation with parameter ROW");
94 oObj
.setTableOperation(CRA
.getRangeAddress(), TableOperationMode
.ROW
,
95 CA
.getCellAddress(), CA2
.getCellAddress());
96 log
.println("checking values");
97 cellCoords
= new Point
[] {
98 new Point(1, 1), new Point(2, 1), new Point(3, 1)
100 cellValues
= new double[] { 5, 10, 15 };
101 res
&= checkValues(cellCoords
, cellValues
);
103 log
.println("filling cells");
105 log
.println("setting TableOperation with parameter COLUMN");
106 oObj
.setTableOperation(CRA
.getRangeAddress(),
107 TableOperationMode
.COLUMN
, CA
.getCellAddress(),
108 CA2
.getCellAddress());
109 log
.println("checking values");
110 cellCoords
= new Point
[] {
111 new Point(1, 1), new Point(1, 2), new Point(1, 3)
113 cellValues
= new double[] { 12, 24, 36 };
114 res
&= checkValues(cellCoords
, cellValues
);
117 log
.println("filling cells");
119 log
.println("setting TableOperation with parameter BOTH");
120 oObj
.setTableOperation(CRA
.getRangeAddress(),
121 TableOperationMode
.BOTH
,
122 CA
.getCellAddress(), CA2
.getCellAddress());
123 log
.println("checking values");
124 cellCoords
= new Point
[] {
125 new Point(1, 1), new Point(2, 2), new Point(3, 3)
127 cellValues
= new double[] { 17, 34, 51 };
128 res
&= checkValues(cellCoords
, cellValues
);
131 tRes
.tested("setTableOperation()", res
);
134 protected void fillCells() {
138 for (int k
= 1; k
< 5; k
++) {
139 cell
= oSheet
.getCellByPosition(0, k
);
140 cell
.setValue(k
* 12);
141 cell
= oSheet
.getCellByPosition(k
, 0);
142 cell
.setValue(k
* 5);
144 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
145 log
.println("Exception while filling Cells " + e
.getMessage());
149 protected boolean checkValues(Point
[] cellCoords
, double[] cellValues
) {
152 for (int i
= 0; i
< cellValues
.length
; i
++) {
154 boolean locres
= oSheet
.getCellByPosition(cellCoords
[i
].X
,
156 .getValue() == cellValues
[i
];
160 log
.println("Result differs for cell (" +
161 cellCoords
[i
].X
+ "," + cellCoords
[i
].Y
+
163 log
.println("Expected: " + cellValues
[i
]);
164 log
.println("Getting: " +
165 oSheet
.getCellByPosition(cellCoords
[i
].X
,
169 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
170 log
.println("Exception while checking Values " +
180 * Restores initial component text.
182 protected void after() {
183 disposeEnvironment();