1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.table;
25 
26 import com.sun.star.table.XCellRange;
27 import lib.MultiMethodTest;
28 
29 import com.sun.star.table.XTableRows;
30 import lib.Status;
31 import lib.StatusException;
32 
33 /**
34 * Testing <code>com.sun.star.table.XTableRows</code>
35 * interface methods :
36 * <ul>
37 *  <li><code> insertByIndex()</code></li>
38 *  <li><code> removeByIndex()</code></li>
39 * </ul>
40 */
41 public class _XTableRows extends MultiMethodTest {
42 
43     public XTableRows oObj = null;
44     public XCellRange range = null;
45 
before()46     public void before() {
47         range = (XCellRange) tEnv.getObjRelation("XTableRows.XCellRange");
48         if (range==null) {
49             throw new StatusException(Status.failed("ObjectRelation missing"));
50         }
51         try {
52             range.getCellByPosition(0,0).setValue(17);
53             range.getCellByPosition(0,1).setValue(15);
54         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
55             log.println("Couldn't set value for Cell A1");
56         }
57     }
58 
59     /**
60      * First a row inserted to valid position, then to invalid. <p>
61      * Has <b> OK </b> status if in the first case number of rows increases
62      * by 1, and in the second an exception is thrown. <p>
63      */
_insertByIndex()64     public void _insertByIndex() {
65 
66         boolean result = true;
67 
68         requiredMethod("removeByIndex()");
69 
70         int origCnt = oObj.getCount();
71         log.println("Inserting row before first row");
72         oObj.insertByIndex(0,1);
73         result &= checkCell(1,15);
74         if (checkCell(1,15)) log.println("... successful");
75 
76         try {
77             oObj.insertByIndex(-1,1);
78             log.println("No Exception occurred while inserting row at -1");
79             result &= false;
80         } catch (Exception e) {
81             log.println("Inserting row at Index -1 ... OK");
82             result &= true;
83         }
84 
85         tRes.tested( "insertByIndex()", result );
86 
87     } // end insertByIndex()
88 
89     /**
90      * First a row removed from valid position, then from invalid. <p>
91      *
92      * Has <b> OK </b> status if in the first case number of columns decreases
93      * by 1, and in the second an exception is thrown. <p>
94      */
_removeByIndex()95     public void _removeByIndex() {
96 
97         boolean result = true;
98 
99         oObj.removeByIndex(0,1);
100         log.println("Removing first row");
101         result &= checkCell(0,15);
102         if (checkCell(0,15)) log.println("... successful");
103 
104         try {
105             oObj.removeByIndex(-1,1);
106             log.println("No Exception occurred while Removing row at -1");
107             result &= false;
108         } catch (Exception e) {
109             log.println("Removing row at Index -1 ... OK");
110             result &= true;
111         }
112 
113         tRes.tested( "removeByIndex()", result );
114     } // end removeByIndex()
115 
checkCell(int row,double expected)116     public boolean checkCell(int row,double expected) {
117         double getting=0;
118         try {
119             getting = range.getCellByPosition(0,row).getValue();
120         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
121             log.println("Couldn't set value for Cell A1");
122         }
123 
124         boolean res = (getting==expected);
125         if (!res) {
126             log.println("Expected for row "+row+" was "+expected);
127             log.println("Getting for row "+row+" - "+getting);
128             log.println("=> FAILED");
129         }
130         return res;
131     }
132 
133 } //finish class _XTableRows
134 
135