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 lib
.MultiMethodTest
;
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
;
37 protected void before() {
38 oSheet
= (XSpreadsheet
) tEnv
.getObjRelation("SHEET");
41 log
.println("Object relation oSheet is missing");
42 log
.println("Trying to query the needed Interface");
43 oSheet
= UnoRuntime
.queryInterface(
44 XSpreadsheet
.class, tEnv
.getTestObject());
47 throw new StatusException(Status
.failed(
48 "Object relation oSheet is missing"));
53 public void _applySubTotals() {
54 requiredMethod("createSubTotalDescriptor()");
59 oSheet
.getCellByPosition(0, 0).setFormula("first");
60 oSheet
.getCellByPosition(1, 0).setFormula("second");
61 oSheet
.getCellByPosition(0, 3).setFormula("");
62 oSheet
.getCellByPosition(0, 1).setValue(5);
63 oSheet
.getCellByPosition(0, 2).setValue(5);
64 oSheet
.getCellByPosition(1, 1).setValue(17);
65 oSheet
.getCellByPosition(1, 2).setValue(25);
66 oObj
.applySubTotals(desc
, true);
68 String formula
= oSheet
.getCellByPosition(0, 3).getFormula();
69 String expected
= "=SUBTOTAL(9;$A$2:$A$3)";
70 res
= formula
.equals(expected
);
73 log
.println("getting: " + formula
);
74 log
.println("expected: " + expected
);
76 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
77 log
.println("Couldn't fill cells" + e
.getLocalizedMessage());
81 tRes
.tested("applySubTotals()", res
);
84 public void _createSubTotalDescriptor() {
85 desc
= oObj
.createSubTotalDescriptor(true);
87 SubTotalColumn
[] columns
= new SubTotalColumn
[1];
88 columns
[0] = new SubTotalColumn();
89 columns
[0].Column
= 0;
90 columns
[0].Function
= com
.sun
.star
.sheet
.GeneralFunction
.SUM
;
91 desc
.addNew(columns
, 0);
92 tRes
.tested("createSubTotalDescriptor()", true);
95 public void _removeSubTotals() {
96 requiredMethod("applySubTotals()");
101 oObj
.removeSubTotals();
103 String formula
= oSheet
.getCellByPosition(0, 3).getFormula();
104 String expected
= "";
105 res
= formula
.equals(expected
);
108 log
.println("getting: " + formula
);
109 log
.println("expected: " + expected
);
111 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
112 log
.println("Couldn't get cell" + e
.getLocalizedMessage());
115 tRes
.tested("removeSubTotals()", res
);