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 lib
.MultiMethodTest
;
31 import lib
.StatusException
;
33 import com
.sun
.star
.sheet
.SubTotalColumn
;
34 import com
.sun
.star
.sheet
.XSpreadsheet
;
35 import com
.sun
.star
.sheet
.XSubTotalCalculatable
;
36 import com
.sun
.star
.sheet
.XSubTotalDescriptor
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
40 public class _XSubTotalCalculatable
extends MultiMethodTest
{
41 public XSubTotalCalculatable oObj
;
42 protected XSubTotalDescriptor desc
;
43 protected XSpreadsheet oSheet
;
45 protected void before() {
46 oSheet
= (XSpreadsheet
) tEnv
.getObjRelation("SHEET");
49 log
.println("Object relation oSheet is missing");
50 log
.println("Trying to query the needed Interface");
51 oSheet
= (XSpreadsheet
) UnoRuntime
.queryInterface(
52 XSpreadsheet
.class, tEnv
.getTestObject());
55 throw new StatusException(Status
.failed(
56 "Object relation oSheet is missing"));
61 public void _applySubTotals() {
62 requiredMethod("createSubTotalDescriptor()");
67 oSheet
.getCellByPosition(0, 0).setFormula("first");
68 oSheet
.getCellByPosition(1, 0).setFormula("second");
69 oSheet
.getCellByPosition(0, 3).setFormula("");
70 oSheet
.getCellByPosition(0, 1).setValue(5);
71 oSheet
.getCellByPosition(0, 2).setValue(5);
72 oSheet
.getCellByPosition(1, 1).setValue(17);
73 oSheet
.getCellByPosition(1, 2).setValue(25);
74 oObj
.applySubTotals(desc
, true);
76 String formula
= oSheet
.getCellByPosition(0, 3).getFormula();
77 String expected
= "=SUBTOTAL(9;$A$2:$A$3)";
78 res
= formula
.equals(expected
);
81 log
.println("getting: " + formula
);
82 log
.println("expected: " + expected
);
84 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
85 log
.println("Couldn't fill cells" + e
.getLocalizedMessage());
89 tRes
.tested("applySubTotals()", res
);
92 public void _createSubTotalDescriptor() {
93 desc
= oObj
.createSubTotalDescriptor(true);
95 SubTotalColumn
[] columns
= new SubTotalColumn
[1];
96 columns
[0] = new SubTotalColumn();
97 columns
[0].Column
= 0;
98 columns
[0].Function
= com
.sun
.star
.sheet
.GeneralFunction
.SUM
;
99 desc
.addNew(columns
, 0);
100 tRes
.tested("createSubTotalDescriptor()", true);
103 public void _removeSubTotals() {
104 requiredMethod("applySubTotals()");
109 oObj
.removeSubTotals();
111 String formula
= oSheet
.getCellByPosition(0, 3).getFormula();
112 String expected
= "";
113 res
= formula
.equals(expected
);
116 log
.println("getting: " + formula
);
117 log
.println("expected: " + expected
);
119 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
120 log
.println("Couldn't get cell" + e
.getLocalizedMessage());
123 tRes
.tested("removeSubTotals()", res
);