1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XTableRows.java,v $
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 ************************************************************************/
33 import com
.sun
.star
.table
.XCellRange
;
34 import lib
.MultiMethodTest
;
36 import com
.sun
.star
.table
.XTableRows
;
38 import lib
.StatusException
;
41 * Testing <code>com.sun.star.table.XTableRows</code>
44 * <li><code> insertByIndex()</code></li>
45 * <li><code> removeByIndex()</code></li>
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");
56 throw new StatusException(Status
.failed("ObjectRelation missing"));
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");
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");
84 oObj
.insertByIndex(-1,1);
85 log
.println("No Exception occurred while inserting row at -1");
87 } catch (Exception e
) {
88 log
.println("Inserting row at Index -1 ... OK");
92 tRes
.tested( "insertByIndex()", result
);
94 } // end insertByIndex()
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");
112 oObj
.removeByIndex(-1,1);
113 log
.println("No Exception occurred while Removing row at -1");
115 } catch (Exception e
) {
116 log
.println("Removing row at Index -1 ... OK");
120 tRes
.tested( "removeByIndex()", result
);
121 } // end removeByIndex()
123 public boolean checkCell(int row
,double expected
) {
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
);
133 log
.println("Expected for row "+row
+" was "+expected
);
134 log
.println("Getting for row "+row
+" - "+getting
);
135 log
.println("=> FAILED");
140 } //finish class _XTableRows