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 com.sun.star.table.XCellRange; 27cdf0e10cSrcweir import lib.MultiMethodTest; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.table.XTableRows; 30cdf0e10cSrcweir import lib.Status; 31cdf0e10cSrcweir import lib.StatusException; 32cdf0e10cSrcweir 33cdf0e10cSrcweir /** 34cdf0e10cSrcweir * Testing <code>com.sun.star.table.XTableRows</code> 35cdf0e10cSrcweir * interface methods : 36cdf0e10cSrcweir * <ul> 37cdf0e10cSrcweir * <li><code> insertByIndex()</code></li> 38cdf0e10cSrcweir * <li><code> removeByIndex()</code></li> 39cdf0e10cSrcweir * </ul> 40cdf0e10cSrcweir */ 41cdf0e10cSrcweir public class _XTableRows extends MultiMethodTest { 42cdf0e10cSrcweir 43cdf0e10cSrcweir public XTableRows oObj = null; 44cdf0e10cSrcweir public XCellRange range = null; 45cdf0e10cSrcweir before()46cdf0e10cSrcweir public void before() { 47cdf0e10cSrcweir range = (XCellRange) tEnv.getObjRelation("XTableRows.XCellRange"); 48cdf0e10cSrcweir if (range==null) { 49cdf0e10cSrcweir throw new StatusException(Status.failed("ObjectRelation missing")); 50cdf0e10cSrcweir } 51cdf0e10cSrcweir try { 52cdf0e10cSrcweir range.getCellByPosition(0,0).setValue(17); 53cdf0e10cSrcweir range.getCellByPosition(0,1).setValue(15); 54cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 55cdf0e10cSrcweir log.println("Couldn't set value for Cell A1"); 56cdf0e10cSrcweir } 57cdf0e10cSrcweir } 58cdf0e10cSrcweir 59cdf0e10cSrcweir /** 60cdf0e10cSrcweir * First a row inserted to valid position, then to invalid. <p> 61cdf0e10cSrcweir * Has <b> OK </b> status if in the first case number of rows increases 62cdf0e10cSrcweir * by 1, and in the second an exception is thrown. <p> 63cdf0e10cSrcweir */ _insertByIndex()64cdf0e10cSrcweir public void _insertByIndex() { 65cdf0e10cSrcweir 66cdf0e10cSrcweir boolean result = true; 67cdf0e10cSrcweir 68cdf0e10cSrcweir requiredMethod("removeByIndex()"); 69cdf0e10cSrcweir 70cdf0e10cSrcweir int origCnt = oObj.getCount(); 71cdf0e10cSrcweir log.println("Inserting row before first row"); 72cdf0e10cSrcweir oObj.insertByIndex(0,1); 73cdf0e10cSrcweir result &= checkCell(1,15); 74cdf0e10cSrcweir if (checkCell(1,15)) log.println("... successful"); 75cdf0e10cSrcweir 76cdf0e10cSrcweir try { 77cdf0e10cSrcweir oObj.insertByIndex(-1,1); 78cdf0e10cSrcweir log.println("No Exception occurred while inserting row at -1"); 79cdf0e10cSrcweir result &= false; 80cdf0e10cSrcweir } catch (Exception e) { 81cdf0e10cSrcweir log.println("Inserting row at Index -1 ... OK"); 82cdf0e10cSrcweir result &= true; 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir tRes.tested( "insertByIndex()", result ); 86cdf0e10cSrcweir 87cdf0e10cSrcweir } // end insertByIndex() 88cdf0e10cSrcweir 89cdf0e10cSrcweir /** 90cdf0e10cSrcweir * First a row removed from valid position, then from invalid. <p> 91cdf0e10cSrcweir * 92cdf0e10cSrcweir * Has <b> OK </b> status if in the first case number of columns decreases 93cdf0e10cSrcweir * by 1, and in the second an exception is thrown. <p> 94cdf0e10cSrcweir */ _removeByIndex()95cdf0e10cSrcweir public void _removeByIndex() { 96cdf0e10cSrcweir 97cdf0e10cSrcweir boolean result = true; 98cdf0e10cSrcweir 99cdf0e10cSrcweir oObj.removeByIndex(0,1); 100cdf0e10cSrcweir log.println("Removing first row"); 101cdf0e10cSrcweir result &= checkCell(0,15); 102cdf0e10cSrcweir if (checkCell(0,15)) log.println("... successful"); 103cdf0e10cSrcweir 104cdf0e10cSrcweir try { 105cdf0e10cSrcweir oObj.removeByIndex(-1,1); 106cdf0e10cSrcweir log.println("No Exception occurred while Removing row at -1"); 107cdf0e10cSrcweir result &= false; 108cdf0e10cSrcweir } catch (Exception e) { 109cdf0e10cSrcweir log.println("Removing row at Index -1 ... OK"); 110cdf0e10cSrcweir result &= true; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir tRes.tested( "removeByIndex()", result ); 114cdf0e10cSrcweir } // end removeByIndex() 115cdf0e10cSrcweir checkCell(int row,double expected)116cdf0e10cSrcweir public boolean checkCell(int row,double expected) { 117cdf0e10cSrcweir double getting=0; 118cdf0e10cSrcweir try { 119cdf0e10cSrcweir getting = range.getCellByPosition(0,row).getValue(); 120cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 121cdf0e10cSrcweir log.println("Couldn't set value for Cell A1"); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir boolean res = (getting==expected); 125cdf0e10cSrcweir if (!res) { 126cdf0e10cSrcweir log.println("Expected for row "+row+" was "+expected); 127cdf0e10cSrcweir log.println("Getting for row "+row+" - "+getting); 128cdf0e10cSrcweir log.println("=> FAILED"); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir return res; 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir } //finish class _XTableRows 134cdf0e10cSrcweir 135