xref: /AOO41X/main/qadevOOo/tests/java/ifc/sheet/_XSubTotalCalculatable.java (revision ef39d40d3f5e66cf3f035b3e93783012b340500d)
1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package ifc.sheet;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import lib.MultiMethodTest;
26cdf0e10cSrcweir import lib.Status;
27cdf0e10cSrcweir import lib.StatusException;
28cdf0e10cSrcweir 
29cdf0e10cSrcweir import com.sun.star.sheet.SubTotalColumn;
30cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheet;
31cdf0e10cSrcweir import com.sun.star.sheet.XSubTotalCalculatable;
32cdf0e10cSrcweir import com.sun.star.sheet.XSubTotalDescriptor;
33cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 
36cdf0e10cSrcweir public class _XSubTotalCalculatable extends MultiMethodTest {
37cdf0e10cSrcweir     public XSubTotalCalculatable oObj;
38cdf0e10cSrcweir     protected XSubTotalDescriptor desc;
39cdf0e10cSrcweir     protected XSpreadsheet oSheet;
40cdf0e10cSrcweir 
before()41cdf0e10cSrcweir     protected void before() {
42cdf0e10cSrcweir         oSheet = (XSpreadsheet) tEnv.getObjRelation("SHEET");
43cdf0e10cSrcweir 
44cdf0e10cSrcweir         if (oSheet == null) {
45cdf0e10cSrcweir             log.println("Object relation oSheet is missing");
46cdf0e10cSrcweir             log.println("Trying to query the needed Interface");
47cdf0e10cSrcweir             oSheet = (XSpreadsheet) UnoRuntime.queryInterface(
48cdf0e10cSrcweir                              XSpreadsheet.class, tEnv.getTestObject());
49cdf0e10cSrcweir 
50cdf0e10cSrcweir             if (oSheet == null) {
51cdf0e10cSrcweir                 throw new StatusException(Status.failed(
52cdf0e10cSrcweir                                                   "Object relation oSheet is missing"));
53cdf0e10cSrcweir             }
54cdf0e10cSrcweir         }
55cdf0e10cSrcweir     }
56cdf0e10cSrcweir 
_applySubTotals()57cdf0e10cSrcweir     public void _applySubTotals() {
58cdf0e10cSrcweir         requiredMethod("createSubTotalDescriptor()");
59cdf0e10cSrcweir 
60cdf0e10cSrcweir         boolean res = true;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir         try {
63cdf0e10cSrcweir             oSheet.getCellByPosition(0, 0).setFormula("first");
64cdf0e10cSrcweir             oSheet.getCellByPosition(1, 0).setFormula("second");
65cdf0e10cSrcweir             oSheet.getCellByPosition(0, 3).setFormula("");
66cdf0e10cSrcweir             oSheet.getCellByPosition(0, 1).setValue(5);
67cdf0e10cSrcweir             oSheet.getCellByPosition(0, 2).setValue(5);
68cdf0e10cSrcweir             oSheet.getCellByPosition(1, 1).setValue(17);
69cdf0e10cSrcweir             oSheet.getCellByPosition(1, 2).setValue(25);
70cdf0e10cSrcweir             oObj.applySubTotals(desc, true);
71cdf0e10cSrcweir 
72cdf0e10cSrcweir             String formula = oSheet.getCellByPosition(0, 3).getFormula();
73cdf0e10cSrcweir             String expected = "=SUBTOTAL(9;$A$2:$A$3)";
74cdf0e10cSrcweir             res = formula.equals(expected);
75cdf0e10cSrcweir 
76cdf0e10cSrcweir             if (!res) {
77cdf0e10cSrcweir                 log.println("getting: " + formula);
78cdf0e10cSrcweir                 log.println("expected: " + expected);
79cdf0e10cSrcweir             }
80cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
81cdf0e10cSrcweir             log.println("Couldn't fill cells" + e.getLocalizedMessage());
82cdf0e10cSrcweir             res = false;
83cdf0e10cSrcweir         }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         tRes.tested("applySubTotals()", res);
86cdf0e10cSrcweir     }
87cdf0e10cSrcweir 
_createSubTotalDescriptor()88cdf0e10cSrcweir     public void _createSubTotalDescriptor() {
89cdf0e10cSrcweir         desc = oObj.createSubTotalDescriptor(true);
90cdf0e10cSrcweir 
91cdf0e10cSrcweir         SubTotalColumn[] columns = new SubTotalColumn[1];
92cdf0e10cSrcweir         columns[0] = new SubTotalColumn();
93cdf0e10cSrcweir         columns[0].Column = 0;
94cdf0e10cSrcweir         columns[0].Function = com.sun.star.sheet.GeneralFunction.SUM;
95cdf0e10cSrcweir         desc.addNew(columns, 0);
96cdf0e10cSrcweir         tRes.tested("createSubTotalDescriptor()", true);
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir 
_removeSubTotals()99cdf0e10cSrcweir     public void _removeSubTotals() {
100cdf0e10cSrcweir         requiredMethod("applySubTotals()");
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         boolean res = true;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir         try {
105cdf0e10cSrcweir             oObj.removeSubTotals();
106cdf0e10cSrcweir 
107cdf0e10cSrcweir             String formula = oSheet.getCellByPosition(0, 3).getFormula();
108cdf0e10cSrcweir             String expected = "";
109cdf0e10cSrcweir             res = formula.equals(expected);
110cdf0e10cSrcweir 
111cdf0e10cSrcweir             if (!res) {
112cdf0e10cSrcweir                 log.println("getting: " + formula);
113cdf0e10cSrcweir                 log.println("expected: " + expected);
114cdf0e10cSrcweir             }
115cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
116cdf0e10cSrcweir             log.println("Couldn't get cell" + e.getLocalizedMessage());
117cdf0e10cSrcweir         }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         tRes.tested("removeSubTotals()", res);
120cdf0e10cSrcweir     }
121cdf0e10cSrcweir }