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;
42 public void before() {
43 range
= (XCellRange
) tEnv
.getObjRelation("XTableRows.XCellRange");
45 throw new StatusException(Status
.failed("ObjectRelation missing"));
48 range
.getCellByPosition(0,0).setValue(17);
49 range
.getCellByPosition(0,1).setValue(15);
50 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
51 log
.println("Couldn't set value for Cell A1");
56 * First a row inserted to valid position, then to invalid. <p>
57 * Has <b> OK </b> status if in the first case number of rows increases
58 * by 1, and in the second an exception is thrown. <p>
60 public void _insertByIndex() {
62 boolean result
= true;
64 requiredMethod("removeByIndex()");
67 log
.println("Inserting row before first row");
68 oObj
.insertByIndex(0,1);
69 result
&= checkCell(1,15);
70 if (checkCell(1,15)) log
.println("... successful");
73 oObj
.insertByIndex(-1,1);
74 log
.println("No Exception occurred while inserting row at -1");
76 } catch (Exception e
) {
77 log
.println("Inserting row at Index -1 ... OK");
81 tRes
.tested( "insertByIndex()", result
);
83 } // end insertByIndex()
86 * First a row removed from valid position, then from invalid. <p>
88 * Has <b> OK </b> status if in the first case number of columns decreases
89 * by 1, and in the second an exception is thrown. <p>
91 public void _removeByIndex() {
93 boolean result
= true;
95 oObj
.removeByIndex(0,1);
96 log
.println("Removing first row");
97 result
&= checkCell(0,15);
98 if (checkCell(0,15)) log
.println("... successful");
101 oObj
.removeByIndex(-1,1);
102 log
.println("No Exception occurred while Removing row at -1");
104 } catch (Exception e
) {
105 log
.println("Removing row at Index -1 ... OK");
109 tRes
.tested( "removeByIndex()", result
);
110 } // end removeByIndex()
112 public boolean checkCell(int row
,double expected
) {
115 getting
= range
.getCellByPosition(0,row
).getValue();
116 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
117 log
.println("Couldn't set value for Cell A1");
120 boolean res
= (getting
==expected
);
122 log
.println("Expected for row "+row
+" was "+expected
);
123 log
.println("Getting for row "+row
+" - "+getting
);
124 log
.println("=> FAILED");
129 } //finish class _XTableRows