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 .
20 import com
.sun
.star
.awt
.Point
;
21 import com
.sun
.star
.sheet
.TableOperationMode
;
22 import com
.sun
.star
.sheet
.XCellAddressable
;
23 import com
.sun
.star
.sheet
.XCellRangeAddressable
;
24 import com
.sun
.star
.sheet
.XMultipleOperation
;
25 import com
.sun
.star
.sheet
.XSpreadsheet
;
26 import com
.sun
.star
.table
.XCell
;
27 import com
.sun
.star
.table
.XCellRange
;
28 import com
.sun
.star
.uno
.UnoRuntime
;
30 import lib
.MultiMethodTest
;
32 import lib
.StatusException
;
35 public class _XMultipleOperation
extends MultiMethodTest
{
36 public XMultipleOperation oObj
= null;
37 protected XSpreadsheet oSheet
= null;
41 protected void before() {
42 oSheet
= (XSpreadsheet
) tEnv
.getObjRelation("SHEET");
45 throw new StatusException(Status
.failed(
46 "Object relation oSheet is missing"));
49 if (UnoRuntime
.queryInterface(XSpreadsheet
.class, tEnv
.getTestObject()) != null) {
50 log
.println("We have a sheet and won't do TableOperationMode.BOTH");
55 public void _setTableOperation() {
57 XCellRange cellRange
= oSheet
.getCellRangeByName("$A$17:$A$17");
58 XCellRangeAddressable CRA
= UnoRuntime
.queryInterface(
59 XCellRangeAddressable
.class,
65 cell
= oSheet
.getCellByPosition(0, 16);
66 cell
.setFormula("=a15+a16");
67 cell
= oSheet
.getCellByPosition(0, 14);
68 cell2
= oSheet
.getCellByPosition(0, 15);
69 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
70 log
.println("Exception while getting Cell " + e
.getMessage());
73 XCellAddressable CA
= UnoRuntime
.queryInterface(
74 XCellAddressable
.class, cell
);
75 XCellAddressable CA2
= UnoRuntime
.queryInterface(
76 XCellAddressable
.class, cell2
);
77 Point
[] cellCoords
= new Point
[3];
78 double[] cellValues
= new double[3];
80 log
.println("filling cells");
82 log
.println("setting TableOperation with parameter ROW");
83 oObj
.setTableOperation(CRA
.getRangeAddress(), TableOperationMode
.ROW
,
84 CA
.getCellAddress(), CA2
.getCellAddress());
85 log
.println("checking values");
86 cellCoords
= new Point
[] {
87 new Point(1, 1), new Point(2, 1), new Point(3, 1)
89 cellValues
= new double[] { 5, 10, 15 };
90 res
&= checkValues(cellCoords
, cellValues
);
92 log
.println("filling cells");
94 log
.println("setting TableOperation with parameter COLUMN");
95 oObj
.setTableOperation(CRA
.getRangeAddress(),
96 TableOperationMode
.COLUMN
, CA
.getCellAddress(),
97 CA2
.getCellAddress());
98 log
.println("checking values");
99 cellCoords
= new Point
[] {
100 new Point(1, 1), new Point(1, 2), new Point(1, 3)
102 cellValues
= new double[] { 12, 24, 36 };
103 res
&= checkValues(cellCoords
, cellValues
);
106 log
.println("filling cells");
108 log
.println("setting TableOperation with parameter BOTH");
109 oObj
.setTableOperation(CRA
.getRangeAddress(),
110 TableOperationMode
.BOTH
,
111 CA
.getCellAddress(), CA2
.getCellAddress());
112 log
.println("checking values");
113 cellCoords
= new Point
[] {
114 new Point(1, 1), new Point(2, 2), new Point(3, 3)
116 cellValues
= new double[] { 17, 34, 51 };
117 res
&= checkValues(cellCoords
, cellValues
);
120 tRes
.tested("setTableOperation()", res
);
123 protected void fillCells() {
127 for (int k
= 1; k
< 5; k
++) {
128 cell
= oSheet
.getCellByPosition(0, k
);
129 cell
.setValue(k
* 12);
130 cell
= oSheet
.getCellByPosition(k
, 0);
131 cell
.setValue(k
* 5);
133 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
134 log
.println("Exception while filling Cells " + e
.getMessage());
138 protected boolean checkValues(Point
[] cellCoords
, double[] cellValues
) {
141 for (int i
= 0; i
< cellValues
.length
; i
++) {
143 boolean locres
= oSheet
.getCellByPosition(cellCoords
[i
].X
,
145 .getValue() == cellValues
[i
];
149 log
.println("Result differs for cell (" +
150 cellCoords
[i
].X
+ "," + cellCoords
[i
].Y
+
152 log
.println("Expected: " + cellValues
[i
]);
153 log
.println("Getting: " +
154 oSheet
.getCellByPosition(cellCoords
[i
].X
,
158 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
159 log
.println("Exception while checking Values " +
169 * Restores initial component text.
172 protected void after() {
173 disposeEnvironment();