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 28 package ifc.table; 29 30 import lib.MultiMethodTest; 31 32 import com.sun.star.table.XCell; 33 import com.sun.star.table.XCellRange; 34 35 /** 36 * Testing <code>com.sun.star.table.XCellRange</code> 37 * interface methods : 38 * <ul> 39 * <li><code> getCellByPosition()</code></li> 40 * <li><code> getCellRangeByPosition()</code></li> 41 * <li><code> getCellRangeByName()</code></li> 42 * </ul> <p> 43 * This test needs the following object relations : 44 * <ul> 45 * <li> <code>'ValidRange'</code> (of type <code>String</code>): 46 * cell range that can be defined by the object test instead of 47 * definition at this test ("<code>A1:A1</code>")</li> 48 * </ul> <p> 49 * Test is <b> NOT </b> multithread compilant. <p> 50 * @see com.sun.star.table.XCellRange 51 */ 52 public class _XCellRange extends MultiMethodTest { 53 public XCellRange oObj = null; 54 55 /** 56 * First a cell get from valid position, second - from invalid. <p> 57 * Has <b> OK </b> status if in the first case not null value is 58 * returned and no exceptions are thrown, and in the second 59 * case <code>IndexOutOfBoundsException</code> is thrown. <p> 60 */ 61 public void _getCellByPosition() { 62 63 boolean result = false; 64 65 try { 66 XCell cell = oObj.getCellByPosition(0,0); 67 result = cell != null ; 68 log.println("Getting cell by position with a valid position ... OK"); 69 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 70 log.println("Exception occurred while getting cell by position with a valid position"); 71 e.printStackTrace(log); 72 result = false; 73 } 74 75 try { 76 oObj.getCellByPosition(-1,1); 77 log.println("No Exception occurred while getting cell by position with invalid position"); 78 result &= false; 79 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 80 log.println("Getting cell by position with a invalid position ... OK"); 81 result &= true; 82 } 83 84 tRes.tested( "getCellByPosition()", result ); 85 86 } // end getCellByPosition() 87 88 /** 89 * A range is tried to obtain with valid name. <p> 90 * Has <b> OK </b> status if not null range is 91 * returned. <p> 92 */ 93 public void _getCellRangeByName() { 94 95 boolean result = false; 96 97 String valid = (String) tEnv.getObjRelation("ValidRange"); 98 if (valid == null ) valid = "A1:A1"; 99 XCellRange range = oObj.getCellRangeByName(valid); 100 result = range != null ; 101 log.println("Getting cellrange by name with a valid name ... OK"); 102 103 tRes.tested( "getCellRangeByName()", result ); 104 105 106 } // end getCellRangeByName() 107 108 /** 109 * First a range is tried to obtain with valid bounds, 110 * second - with invalid. <p> 111 * Has <b> OK </b> status if in the first case not null range is 112 * returned and no exceptions are thrown, and in the second 113 * case <code>IndexOutOfBoundsException</code> is thrown. <p> 114 */ 115 public void _getCellRangeByPosition() { 116 117 boolean result = false; 118 119 try { 120 XCellRange range = oObj.getCellRangeByPosition(0,0,0,0); 121 result = range != null; 122 log.println("Getting cellrange by Position with a valid position ... OK"); 123 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 124 log.println("Exception occurred while getting cellrange by position with a valid position"); 125 e.printStackTrace(log); 126 result = false; 127 } 128 129 try { 130 oObj.getCellRangeByPosition(-1,0,-1,1); 131 log.println("No Exception occurred while getting cellrange by position with invalid position"); 132 result &= false; 133 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 134 log.println("Getting cellrange by position with a invalid position ... OK"); 135 result &= true; 136 } 137 138 tRes.tested( "getCellRangeByPosition()", result ); 139 140 141 } // end getCellRangeByPosition() 142 143 /** 144 * Forces environment recreation. 145 */ 146 protected void after() { 147 disposeEnvironment(); 148 } 149 150 } // finish class _XCellRange 151 152