2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import com
.sun
.star
.table
.XCellRange
;
22 import lib
.MultiMethodTest
;
24 import com
.sun
.star
.table
.XTableRows
;
26 import lib
.StatusException
;
29 * Testing <code>com.sun.star.table.XTableRows</code>
32 * <li><code> insertByIndex()</code></li>
33 * <li><code> removeByIndex()</code></li>
36 public class _XTableRows
extends MultiMethodTest
{
38 public XTableRows oObj
= null;
39 public XCellRange range
= null;
41 public void before() {
42 range
= (XCellRange
) tEnv
.getObjRelation("XTableRows.XCellRange");
44 throw new StatusException(Status
.failed("ObjectRelation missing"));
47 range
.getCellByPosition(0,0).setValue(17);
48 range
.getCellByPosition(0,1).setValue(15);
49 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
50 log
.println("Couldn't set value for Cell A1");
55 * First a row inserted to valid position, then to invalid. <p>
56 * Has <b> OK </b> status if in the first case number of rows increases
57 * by 1, and in the second an exception is thrown. <p>
59 public void _insertByIndex() {
61 boolean result
= true;
63 requiredMethod("removeByIndex()");
66 log
.println("Inserting row before first row");
67 oObj
.insertByIndex(0,1);
68 result
&= checkCell(1,15);
69 if (checkCell(1,15)) log
.println("... successful");
72 oObj
.insertByIndex(-1,1);
73 log
.println("No Exception occurred while inserting row at -1");
75 } catch (Exception e
) {
76 log
.println("Inserting row at Index -1 ... OK");
80 tRes
.tested( "insertByIndex()", result
);
82 } // end insertByIndex()
85 * First a row removed from valid position, then from invalid. <p>
87 * Has <b> OK </b> status if in the first case number of columns decreases
88 * by 1, and in the second an exception is thrown. <p>
90 public void _removeByIndex() {
92 boolean result
= true;
94 oObj
.removeByIndex(0,1);
95 log
.println("Removing first row");
96 result
&= checkCell(0,15);
97 if (checkCell(0,15)) log
.println("... successful");
100 oObj
.removeByIndex(-1,1);
101 log
.println("No Exception occurred while Removing row at -1");
103 } catch (Exception e
) {
104 log
.println("Removing row at Index -1 ... OK");
108 tRes
.tested( "removeByIndex()", result
);
109 } // end removeByIndex()
111 public boolean checkCell(int row
,double expected
) {
114 getting
= range
.getCellByPosition(0,row
).getValue();
115 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
116 log
.println("Couldn't set value for Cell A1");
119 boolean res
= (getting
==expected
);
121 log
.println("Expected for row "+row
+" was "+expected
);
122 log
.println("Getting for row "+row
+" - "+getting
);
123 log
.println("=> FAILED");
128 } //finish class _XTableRows