1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package ifc.sheet; 25 26 import lib.MultiMethodTest; 27 import lib.Status; 28 import lib.StatusException; 29 30 import com.sun.star.sheet.XDataPilotDescriptor; 31 import com.sun.star.sheet.XDataPilotTables; 32 import com.sun.star.sheet.XSpreadsheet; 33 import com.sun.star.table.CellAddress; 34 35 /** 36 * Testing <code>com.sun.star.sheet.XDataPilotTables</code> 37 * interface methods : 38 * <ul> 39 * <li><code> createDataPilotDescriptor()</code></li> 40 * <li><code> insertNewByName()</code></li> 41 * <li><code> removeByName()</code></li> 42 * </ul> <p> 43 * This test needs the following object relations : 44 * <ul> 45 * <li> <code>'SHEET'</code> (of type <code>XSpreadsheet</code>): 46 * to have a spreadsheet document for document content checking</li> 47 * <ul> <p> 48 * @see com.sun.star.sheet.XDataPilotTables 49 */ 50 public class _XDataPilotTables extends MultiMethodTest { 51 52 public XDataPilotTables oObj = null; 53 XDataPilotDescriptor DPDscr = null; 54 String name = "XDataPilotTables"; 55 CellAddress CA = new CellAddress((short)0, 9, 8); 56 XSpreadsheet oSheet = null; 57 58 /** 59 * Retrieves object relations. 60 * @throws StatusException If one of relations not found. 61 */ before()62 protected void before() { 63 oSheet = (XSpreadsheet)tEnv.getObjRelation("SHEET"); 64 if (oSheet == null) throw new StatusException(Status.failed 65 ("Relation 'SHEET' not found")); 66 } 67 68 /** 69 * Test calls the method, stores returned value and checks returned value. 70 * <p>Has <b> OK </b> status if returned value isn't null. <p> 71 */ _createDataPilotDescriptor()72 public void _createDataPilotDescriptor(){ 73 DPDscr = oObj.createDataPilotDescriptor(); 74 tRes.tested("createDataPilotDescriptor()", DPDscr != null); 75 } 76 77 /** 78 * Test calls the method inserting new table with new name and then calls 79 * the method inserting table with existent name. <p> 80 * Has <b> OK </b> status if the cell content where table was inserted is 81 * equal to 'Filter' after first call and exception was thrown during 82 * second call. <p> 83 * The following method tests are to be completed successfully before : 84 * <ul> 85 * <li> <code> createDataPilotDescriptor() </code> : to have 86 * <code>XDataPilotDescriptor</code> created by this method</li> 87 * </ul> 88 */ _insertNewByName()89 public void _insertNewByName(){ 90 requiredMethod("createDataPilotDescriptor()"); 91 boolean bResult = true; 92 log.println("Inserting new Table \"" + name + "\""); 93 try { 94 oObj.insertNewByName(name, CA, DPDscr); 95 bResult &= oSheet.getCellByPosition 96 (CA.Column, CA.Row).getFormula().equals("Filter"); 97 } catch (com.sun.star.uno.Exception e) { 98 log.println("Exception occurred! " + e); 99 bResult = false; 100 } 101 102 log.println(bResult ? "OK" : "FAILED"); 103 log.println("Trying to insert element with existent name"); 104 105 try { 106 oObj.insertNewByName(name,new CellAddress((short)0, 7, 7), DPDscr); 107 log.println("No exception! - FAILED"); 108 bResult = false; 109 } catch (com.sun.star.uno.RuntimeException e) { 110 log.println("Expected exception - OK " + e); 111 } 112 113 log.println("Inserting new table " + (bResult ? "OK" : "FAILED")); 114 tRes.tested("insertNewByName()", bResult); 115 } 116 117 /** 118 * Test calls the method for existent table and for unexistent table. <p> 119 * Has <b> OK </b> status if the cell where table was removed from is empty 120 * after first call and exception was thrown during second call. <p> 121 * The following method tests are to be completed successfully before : 122 * <ul> 123 * <li> <code>insertNewByName()</code>: to have name of existent table</li> 124 * </ul> 125 */ _removeByName()126 public void _removeByName(){ 127 requiredMethod("insertNewByName()"); 128 boolean bResult = true; 129 log.println("Remove table with name " + name); 130 try { 131 oObj.removeByName(name); 132 bResult &= oSheet.getCellByPosition 133 (CA.Column, CA.Row).getFormula().equals(""); 134 } catch (com.sun.star.uno.Exception e) { 135 log.println("Exception occurred ! " + e); 136 bResult = false; 137 } 138 log.println(bResult ? "OK" : "FAILED"); 139 log.println("Removing unexistent element"); 140 try { 141 oObj.removeByName(name); 142 log.println("No exception! - FAILED"); 143 bResult = false; 144 } catch (com.sun.star.uno.RuntimeException e) { 145 log.println("Expected exception - OK " + e); 146 } 147 148 log.println("Removing a table " + (bResult ? "OK" : "FAILED")); 149 tRes.tested("removeByName()", bResult); 150 } 151 152 } 153 154