bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XSubTotalCalculatable.java
blobd34f89f4403f6ad86d3f2a54af859e09bd712ca3
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 lib.MultiMethodTest;
21 import lib.Status;
22 import lib.StatusException;
24 import com.sun.star.sheet.SubTotalColumn;
25 import com.sun.star.sheet.XSpreadsheet;
26 import com.sun.star.sheet.XSubTotalCalculatable;
27 import com.sun.star.sheet.XSubTotalDescriptor;
28 import com.sun.star.uno.UnoRuntime;
31 public class _XSubTotalCalculatable extends MultiMethodTest {
32 public XSubTotalCalculatable oObj;
33 protected XSubTotalDescriptor desc;
34 protected XSpreadsheet oSheet;
36 protected void before() {
37 oSheet = (XSpreadsheet) tEnv.getObjRelation("SHEET");
39 if (oSheet == null) {
40 log.println("Object relation oSheet is missing");
41 log.println("Trying to query the needed Interface");
42 oSheet = UnoRuntime.queryInterface(
43 XSpreadsheet.class, tEnv.getTestObject());
45 if (oSheet == null) {
46 throw new StatusException(Status.failed(
47 "Object relation oSheet is missing"));
52 public void _applySubTotals() {
53 requiredMethod("createSubTotalDescriptor()");
55 boolean res = true;
57 try {
58 oSheet.getCellByPosition(0, 0).setFormula("first");
59 oSheet.getCellByPosition(1, 0).setFormula("second");
60 oSheet.getCellByPosition(0, 3).setFormula("");
61 oSheet.getCellByPosition(0, 1).setValue(5);
62 oSheet.getCellByPosition(0, 2).setValue(5);
63 oSheet.getCellByPosition(1, 1).setValue(17);
64 oSheet.getCellByPosition(1, 2).setValue(25);
65 oObj.applySubTotals(desc, true);
67 String formula = oSheet.getCellByPosition(0, 3).getFormula();
68 String expected = "=SUBTOTAL(9;$A$2:$A$3)";
69 res = formula.equals(expected);
71 if (!res) {
72 log.println("getting: " + formula);
73 log.println("expected: " + expected);
75 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
76 log.println("Couldn't fill cells" + e.getLocalizedMessage());
77 res = false;
80 tRes.tested("applySubTotals()", res);
83 public void _createSubTotalDescriptor() {
84 desc = oObj.createSubTotalDescriptor(true);
86 SubTotalColumn[] columns = new SubTotalColumn[1];
87 columns[0] = new SubTotalColumn();
88 columns[0].Column = 0;
89 columns[0].Function = com.sun.star.sheet.GeneralFunction.SUM;
90 desc.addNew(columns, 0);
91 tRes.tested("createSubTotalDescriptor()", true);
94 public void _removeSubTotals() {
95 requiredMethod("applySubTotals()");
97 boolean res = true;
99 try {
100 oObj.removeSubTotals();
102 String formula = oSheet.getCellByPosition(0, 3).getFormula();
103 String expected = "";
104 res = formula.equals(expected);
106 if (!res) {
107 log.println("getting: " + formula);
108 log.println("expected: " + expected);
110 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
111 log.println("Couldn't get cell" + e.getLocalizedMessage());
114 tRes.tested("removeSubTotals()", res);