1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 package ifc.sheet; 28 29 import lib.MultiMethodTest; 30 import lib.Status; 31 import lib.StatusException; 32 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; 38 39 40 public class _XSubTotalCalculatable extends MultiMethodTest { 41 public XSubTotalCalculatable oObj; 42 protected XSubTotalDescriptor desc; 43 protected XSpreadsheet oSheet; 44 45 protected void before() { 46 oSheet = (XSpreadsheet) tEnv.getObjRelation("SHEET"); 47 48 if (oSheet == null) { 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()); 53 54 if (oSheet == null) { 55 throw new StatusException(Status.failed( 56 "Object relation oSheet is missing")); 57 } 58 } 59 } 60 61 public void _applySubTotals() { 62 requiredMethod("createSubTotalDescriptor()"); 63 64 boolean res = true; 65 66 try { 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); 75 76 String formula = oSheet.getCellByPosition(0, 3).getFormula(); 77 String expected = "=SUBTOTAL(9;$A$2:$A$3)"; 78 res = formula.equals(expected); 79 80 if (!res) { 81 log.println("getting: " + formula); 82 log.println("expected: " + expected); 83 } 84 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 85 log.println("Couldn't fill cells" + e.getLocalizedMessage()); 86 res = false; 87 } 88 89 tRes.tested("applySubTotals()", res); 90 } 91 92 public void _createSubTotalDescriptor() { 93 desc = oObj.createSubTotalDescriptor(true); 94 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); 101 } 102 103 public void _removeSubTotals() { 104 requiredMethod("applySubTotals()"); 105 106 boolean res = true; 107 108 try { 109 oObj.removeSubTotals(); 110 111 String formula = oSheet.getCellByPosition(0, 3).getFormula(); 112 String expected = ""; 113 res = formula.equals(expected); 114 115 if (!res) { 116 log.println("getting: " + formula); 117 log.println("expected: " + expected); 118 } 119 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 120 log.println("Couldn't get cell" + e.getLocalizedMessage()); 121 } 122 123 tRes.tested("removeSubTotals()", res); 124 } 125 }