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 ************************************************************************/
29 import com
.sun
.star
.awt
.Point
;
30 import com
.sun
.star
.sheet
.TableOperationMode
;
31 import com
.sun
.star
.sheet
.XCellAddressable
;
32 import com
.sun
.star
.sheet
.XCellRangeAddressable
;
33 import com
.sun
.star
.sheet
.XMultipleOperation
;
34 import com
.sun
.star
.sheet
.XSpreadsheet
;
35 import com
.sun
.star
.table
.XCell
;
36 import com
.sun
.star
.table
.XCellRange
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
39 import lib
.MultiMethodTest
;
41 import lib
.StatusException
;
44 public class _XMultipleOperation
extends MultiMethodTest
{
45 public XMultipleOperation oObj
= null;
46 protected XSpreadsheet oSheet
= null;
49 protected void before() {
50 oSheet
= (XSpreadsheet
) tEnv
.getObjRelation("SHEET");
53 throw new StatusException(Status
.failed(
54 "Object relation oSheet is missing"));
57 if (UnoRuntime
.queryInterface(XSpreadsheet
.class, tEnv
.getTestObject()) != null) {
58 log
.println("We have a sheet and won't do TableOperationMode.BOTH");
63 public void _setTableOperation() {
65 XCellRange cellRange
= oSheet
.getCellRangeByName("$A$17:$A$17");
66 XCellRangeAddressable CRA
= (XCellRangeAddressable
) UnoRuntime
.queryInterface(
67 XCellRangeAddressable
.class,
73 cell
= oSheet
.getCellByPosition(0, 16);
74 cell
.setFormula("=a15+a16");
75 cell
= oSheet
.getCellByPosition(0, 14);
76 cell2
= oSheet
.getCellByPosition(0, 15);
77 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
78 log
.println("Exception while getting Cell " + e
.getMessage());
81 XCellAddressable CA
= (XCellAddressable
) UnoRuntime
.queryInterface(
82 XCellAddressable
.class, cell
);
83 XCellAddressable CA2
= (XCellAddressable
) UnoRuntime
.queryInterface(
84 XCellAddressable
.class, cell2
);
85 Point
[] cellCoords
= new Point
[3];
86 double[] cellValues
= new double[3];
88 log
.println("filling cells");
90 log
.println("setting TableOperation with parameter ROW");
91 oObj
.setTableOperation(CRA
.getRangeAddress(), TableOperationMode
.ROW
,
92 CA
.getCellAddress(), CA2
.getCellAddress());
93 log
.println("checking values");
94 cellCoords
= new Point
[] {
95 new Point(1, 1), new Point(2, 1), new Point(3, 1)
97 cellValues
= new double[] { 5, 10, 15 };
98 res
&= checkValues(cellCoords
, cellValues
);
100 log
.println("filling cells");
102 log
.println("setting TableOperation with parameter COLUMN");
103 oObj
.setTableOperation(CRA
.getRangeAddress(),
104 TableOperationMode
.COLUMN
, CA
.getCellAddress(),
105 CA2
.getCellAddress());
106 log
.println("checking values");
107 cellCoords
= new Point
[] {
108 new Point(1, 1), new Point(1, 2), new Point(1, 3)
110 cellValues
= new double[] { 12, 24, 36 };
111 res
&= checkValues(cellCoords
, cellValues
);
114 log
.println("filling cells");
116 log
.println("setting TableOperation with parameter BOTH");
117 oObj
.setTableOperation(CRA
.getRangeAddress(),
118 TableOperationMode
.BOTH
,
119 CA
.getCellAddress(), CA2
.getCellAddress());
120 log
.println("checking values");
121 cellCoords
= new Point
[] {
122 new Point(1, 1), new Point(2, 2), new Point(3, 3)
124 cellValues
= new double[] { 17, 34, 51 };
125 res
&= checkValues(cellCoords
, cellValues
);
128 tRes
.tested("setTableOperation()", res
);
131 protected void fillCells() {
135 for (int k
= 1; k
< 5; k
++) {
136 cell
= oSheet
.getCellByPosition(0, k
);
137 cell
.setValue(k
* 12);
138 cell
= oSheet
.getCellByPosition(k
, 0);
139 cell
.setValue(k
* 5);
141 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
142 log
.println("Exception while filling Cells " + e
.getMessage());
146 protected boolean checkValues(Point
[] cellCoords
, double[] cellValues
) {
149 for (int i
= 0; i
< cellValues
.length
; i
++) {
151 boolean locres
= oSheet
.getCellByPosition(cellCoords
[i
].X
,
153 .getValue() == cellValues
[i
];
157 log
.println("Result differs for cell (" +
158 cellCoords
[i
].X
+ "," + cellCoords
[i
].Y
+
160 log
.println("Expected: " + cellValues
[i
]);
161 log
.println("Getting: " +
162 oSheet
.getCellByPosition(cellCoords
[i
].X
,
166 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
167 log
.println("Exception while checking Values " +
177 * Restores initial component text.
179 protected void after() {
180 disposeEnvironment();