1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package ifc.table; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import lib.MultiMethodTest; 27cdf0e10cSrcweir 28cdf0e10cSrcweir import com.sun.star.table.XCell; 29cdf0e10cSrcweir import com.sun.star.table.XCellRange; 30cdf0e10cSrcweir 31cdf0e10cSrcweir /** 32cdf0e10cSrcweir * Testing <code>com.sun.star.table.XCellRange</code> 33cdf0e10cSrcweir * interface methods : 34cdf0e10cSrcweir * <ul> 35cdf0e10cSrcweir * <li><code> getCellByPosition()</code></li> 36cdf0e10cSrcweir * <li><code> getCellRangeByPosition()</code></li> 37cdf0e10cSrcweir * <li><code> getCellRangeByName()</code></li> 38cdf0e10cSrcweir * </ul> <p> 39cdf0e10cSrcweir * This test needs the following object relations : 40cdf0e10cSrcweir * <ul> 41cdf0e10cSrcweir * <li> <code>'ValidRange'</code> (of type <code>String</code>): 42cdf0e10cSrcweir * cell range that can be defined by the object test instead of 43cdf0e10cSrcweir * definition at this test ("<code>A1:A1</code>")</li> 44cdf0e10cSrcweir * </ul> <p> 45cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 46cdf0e10cSrcweir * @see com.sun.star.table.XCellRange 47cdf0e10cSrcweir */ 48cdf0e10cSrcweir public class _XCellRange extends MultiMethodTest { 49cdf0e10cSrcweir public XCellRange oObj = null; 50cdf0e10cSrcweir 51cdf0e10cSrcweir /** 52cdf0e10cSrcweir * First a cell get from valid position, second - from invalid. <p> 53cdf0e10cSrcweir * Has <b> OK </b> status if in the first case not null value is 54cdf0e10cSrcweir * returned and no exceptions are thrown, and in the second 55cdf0e10cSrcweir * case <code>IndexOutOfBoundsException</code> is thrown. <p> 56cdf0e10cSrcweir */ _getCellByPosition()57cdf0e10cSrcweir public void _getCellByPosition() { 58cdf0e10cSrcweir 59cdf0e10cSrcweir boolean result = false; 60cdf0e10cSrcweir 61cdf0e10cSrcweir try { 62cdf0e10cSrcweir XCell cell = oObj.getCellByPosition(0,0); 63cdf0e10cSrcweir result = cell != null ; 64cdf0e10cSrcweir log.println("Getting cell by position with a valid position ... OK"); 65cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 66cdf0e10cSrcweir log.println("Exception occurred while getting cell by position with a valid position"); 67cdf0e10cSrcweir e.printStackTrace(log); 68cdf0e10cSrcweir result = false; 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir try { 72cdf0e10cSrcweir oObj.getCellByPosition(-1,1); 73cdf0e10cSrcweir log.println("No Exception occurred while getting cell by position with invalid position"); 74cdf0e10cSrcweir result &= false; 75cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 76cdf0e10cSrcweir log.println("Getting cell by position with a invalid position ... OK"); 77cdf0e10cSrcweir result &= true; 78cdf0e10cSrcweir } 79cdf0e10cSrcweir 80cdf0e10cSrcweir tRes.tested( "getCellByPosition()", result ); 81cdf0e10cSrcweir 82cdf0e10cSrcweir } // end getCellByPosition() 83cdf0e10cSrcweir 84cdf0e10cSrcweir /** 85cdf0e10cSrcweir * A range is tried to obtain with valid name. <p> 86cdf0e10cSrcweir * Has <b> OK </b> status if not null range is 87cdf0e10cSrcweir * returned. <p> 88cdf0e10cSrcweir */ _getCellRangeByName()89cdf0e10cSrcweir public void _getCellRangeByName() { 90cdf0e10cSrcweir 91cdf0e10cSrcweir boolean result = false; 92cdf0e10cSrcweir 93cdf0e10cSrcweir String valid = (String) tEnv.getObjRelation("ValidRange"); 94cdf0e10cSrcweir if (valid == null ) valid = "A1:A1"; 95cdf0e10cSrcweir XCellRange range = oObj.getCellRangeByName(valid); 96cdf0e10cSrcweir result = range != null ; 97cdf0e10cSrcweir log.println("Getting cellrange by name with a valid name ... OK"); 98cdf0e10cSrcweir 99cdf0e10cSrcweir tRes.tested( "getCellRangeByName()", result ); 100cdf0e10cSrcweir 101cdf0e10cSrcweir 102cdf0e10cSrcweir } // end getCellRangeByName() 103cdf0e10cSrcweir 104cdf0e10cSrcweir /** 105cdf0e10cSrcweir * First a range is tried to obtain with valid bounds, 106cdf0e10cSrcweir * second - with invalid. <p> 107cdf0e10cSrcweir * Has <b> OK </b> status if in the first case not null range is 108cdf0e10cSrcweir * returned and no exceptions are thrown, and in the second 109cdf0e10cSrcweir * case <code>IndexOutOfBoundsException</code> is thrown. <p> 110cdf0e10cSrcweir */ _getCellRangeByPosition()111cdf0e10cSrcweir public void _getCellRangeByPosition() { 112cdf0e10cSrcweir 113cdf0e10cSrcweir boolean result = false; 114cdf0e10cSrcweir 115cdf0e10cSrcweir try { 116cdf0e10cSrcweir XCellRange range = oObj.getCellRangeByPosition(0,0,0,0); 117cdf0e10cSrcweir result = range != null; 118cdf0e10cSrcweir log.println("Getting cellrange by Position with a valid position ... OK"); 119cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 120cdf0e10cSrcweir log.println("Exception occurred while getting cellrange by position with a valid position"); 121cdf0e10cSrcweir e.printStackTrace(log); 122cdf0e10cSrcweir result = false; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir try { 126cdf0e10cSrcweir oObj.getCellRangeByPosition(-1,0,-1,1); 127cdf0e10cSrcweir log.println("No Exception occurred while getting cellrange by position with invalid position"); 128cdf0e10cSrcweir result &= false; 129cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 130cdf0e10cSrcweir log.println("Getting cellrange by position with a invalid position ... OK"); 131cdf0e10cSrcweir result &= true; 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir tRes.tested( "getCellRangeByPosition()", result ); 135cdf0e10cSrcweir 136cdf0e10cSrcweir 137cdf0e10cSrcweir } // end getCellRangeByPosition() 138cdf0e10cSrcweir 139cdf0e10cSrcweir /** 140cdf0e10cSrcweir * Forces environment recreation. 141cdf0e10cSrcweir */ after()142cdf0e10cSrcweir protected void after() { 143cdf0e10cSrcweir disposeEnvironment(); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir } // finish class _XCellRange 147cdf0e10cSrcweir 148