merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / table / _XTableRows.java
blobaff6fc9b5101d6f31ed033ae95e4e453992e4ff4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XTableRows.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.table;
33 import com.sun.star.table.XCellRange;
34 import lib.MultiMethodTest;
36 import com.sun.star.table.XTableRows;
37 import lib.Status;
38 import lib.StatusException;
40 /**
41 * Testing <code>com.sun.star.table.XTableRows</code>
42 * interface methods :
43 * <ul>
44 * <li><code> insertByIndex()</code></li>
45 * <li><code> removeByIndex()</code></li>
46 * </ul>
48 public class _XTableRows extends MultiMethodTest {
50 public XTableRows oObj = null;
51 public XCellRange range = null;
53 public void before() {
54 range = (XCellRange) tEnv.getObjRelation("XTableRows.XCellRange");
55 if (range==null) {
56 throw new StatusException(Status.failed("ObjectRelation missing"));
58 try {
59 range.getCellByPosition(0,0).setValue(17);
60 range.getCellByPosition(0,1).setValue(15);
61 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
62 log.println("Couldn't set value for Cell A1");
66 /**
67 * First a row inserted to valid position, then to invalid. <p>
68 * Has <b> OK </b> status if in the first case number of rows increases
69 * by 1, and in the second an exception is thrown. <p>
71 public void _insertByIndex() {
73 boolean result = true;
75 requiredMethod("removeByIndex()");
77 int origCnt = oObj.getCount();
78 log.println("Inserting row before first row");
79 oObj.insertByIndex(0,1);
80 result &= checkCell(1,15);
81 if (checkCell(1,15)) log.println("... successful");
83 try {
84 oObj.insertByIndex(-1,1);
85 log.println("No Exception occurred while inserting row at -1");
86 result &= false;
87 } catch (Exception e) {
88 log.println("Inserting row at Index -1 ... OK");
89 result &= true;
92 tRes.tested( "insertByIndex()", result );
94 } // end insertByIndex()
96 /**
97 * First a row removed from valid position, then from invalid. <p>
99 * Has <b> OK </b> status if in the first case number of columns decreases
100 * by 1, and in the second an exception is thrown. <p>
102 public void _removeByIndex() {
104 boolean result = true;
106 oObj.removeByIndex(0,1);
107 log.println("Removing first row");
108 result &= checkCell(0,15);
109 if (checkCell(0,15)) log.println("... successful");
111 try {
112 oObj.removeByIndex(-1,1);
113 log.println("No Exception occurred while Removing row at -1");
114 result &= false;
115 } catch (Exception e) {
116 log.println("Removing row at Index -1 ... OK");
117 result &= true;
120 tRes.tested( "removeByIndex()", result );
121 } // end removeByIndex()
123 public boolean checkCell(int row,double expected) {
124 double getting=0;
125 try {
126 getting = range.getCellByPosition(0,row).getValue();
127 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
128 log.println("Couldn't set value for Cell A1");
131 boolean res = (getting==expected);
132 if (!res) {
133 log.println("Expected for row "+row+" was "+expected);
134 log.println("Getting for row "+row+" - "+getting);
135 log.println("=> FAILED");
137 return res;
140 } //finish class _XTableRows