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