bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XMultipleOperation.java
blob8aaede910f0bcd5379c6711a251ecadded540172
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 .
18 package ifc.sheet;
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;
31 import lib.Status;
32 import lib.StatusException;
35 public class _XMultipleOperation extends MultiMethodTest {
36 public XMultipleOperation oObj = null;
37 protected XSpreadsheet oSheet = null;
38 boolean both = true;
40 protected void before() {
41 oSheet = (XSpreadsheet) tEnv.getObjRelation("SHEET");
43 if (oSheet == null) {
44 throw new StatusException(Status.failed(
45 "Object relation oSheet is missing"));
48 if (UnoRuntime.queryInterface(XSpreadsheet.class, tEnv.getTestObject()) != null) {
49 log.println("We have a sheet and won't do TableOperationMode.BOTH");
50 both = false;
54 public void _setTableOperation() {
55 boolean res = true;
56 XCellRange cellRange = oSheet.getCellRangeByName("$A$17:$A$17");
57 XCellRangeAddressable CRA = UnoRuntime.queryInterface(
58 XCellRangeAddressable.class,
59 cellRange);
60 XCell cell = null;
61 XCell cell2 = null;
63 try {
64 cell = oSheet.getCellByPosition(0, 16);
65 cell.setFormula("=a15+a16");
66 cell = oSheet.getCellByPosition(0, 14);
67 cell2 = oSheet.getCellByPosition(0, 15);
68 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
69 log.println("Exception while getting Cell " + e.getMessage());
72 XCellAddressable CA = UnoRuntime.queryInterface(
73 XCellAddressable.class, cell);
74 XCellAddressable CA2 = UnoRuntime.queryInterface(
75 XCellAddressable.class, cell2);
76 Point[] cellCoords = new Point[3];
77 double[] cellValues = new double[3];
79 log.println("filling cells");
80 fillCells();
81 log.println("setting TableOperation with parameter ROW");
82 oObj.setTableOperation(CRA.getRangeAddress(), TableOperationMode.ROW,
83 CA.getCellAddress(), CA2.getCellAddress());
84 log.println("checking values");
85 cellCoords = new Point[] {
86 new Point(1, 1), new Point(2, 1), new Point(3, 1)
88 cellValues = new double[] { 5, 10, 15 };
89 res &= checkValues(cellCoords, cellValues);
91 log.println("filling cells");
92 fillCells();
93 log.println("setting TableOperation with parameter COLUMN");
94 oObj.setTableOperation(CRA.getRangeAddress(),
95 TableOperationMode.COLUMN, CA.getCellAddress(),
96 CA2.getCellAddress());
97 log.println("checking values");
98 cellCoords = new Point[] {
99 new Point(1, 1), new Point(1, 2), new Point(1, 3)
101 cellValues = new double[] { 12, 24, 36 };
102 res &= checkValues(cellCoords, cellValues);
104 if (both) {
105 log.println("filling cells");
106 fillCells();
107 log.println("setting TableOperation with parameter BOTH");
108 oObj.setTableOperation(CRA.getRangeAddress(),
109 TableOperationMode.BOTH,
110 CA.getCellAddress(), CA2.getCellAddress());
111 log.println("checking values");
112 cellCoords = new Point[] {
113 new Point(1, 1), new Point(2, 2), new Point(3, 3)
115 cellValues = new double[] { 17, 34, 51 };
116 res &= checkValues(cellCoords, cellValues);
119 tRes.tested("setTableOperation()", res);
122 protected void fillCells() {
123 XCell cell = null;
125 try {
126 for (int k = 1; k < 5; k++) {
127 cell = oSheet.getCellByPosition(0, k);
128 cell.setValue(k * 12);
129 cell = oSheet.getCellByPosition(k, 0);
130 cell.setValue(k * 5);
132 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
133 log.println("Exception while filling Cells " + e.getMessage());
137 protected boolean checkValues(Point[] cellCoords, double[] cellValues) {
138 boolean res = true;
140 for (int i = 0; i < cellValues.length; i++) {
141 try {
142 boolean locres = oSheet.getCellByPosition(cellCoords[i].X,
143 cellCoords[i].Y)
144 .getValue() == cellValues[i];
145 res &= locres;
147 if (!locres) {
148 log.println("Result differs for cell (" +
149 cellCoords[i].X + "," + cellCoords[i].Y +
150 ")");
151 log.println("Expected: " + cellValues[i]);
152 log.println("Getting: " +
153 oSheet.getCellByPosition(cellCoords[i].X,
154 cellCoords[i].Y)
155 .getValue());
157 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
158 log.println("Exception while checking Values " +
159 e.getMessage());
160 res &= false;
164 return res;
168 * Restores initial component text.
170 protected void after() {
171 disposeEnvironment();