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 lib.MultiMethodTest;
27 
28 import com.sun.star.table.XCell;
29 import com.sun.star.table.XCellRange;
30 
31 /**
32 * Testing <code>com.sun.star.table.XCellRange</code>
33 * interface methods :
34 * <ul>
35 *  <li><code> getCellByPosition()</code></li>
36 *  <li><code> getCellRangeByPosition()</code></li>
37 *  <li><code> getCellRangeByName()</code></li>
38 * </ul> <p>
39 * This test needs the following object relations :
40 * <ul>
41 *  <li> <code>'ValidRange'</code> (of type <code>String</code>):
42 *   cell range that can be defined by the object test instead of
43 *   definition at this test ("<code>A1:A1</code>")</li>
44 * </ul> <p>
45 * Test is <b> NOT </b> multithread compilant. <p>
46 * @see com.sun.star.table.XCellRange
47 */
48 public class _XCellRange extends MultiMethodTest {
49     public XCellRange oObj = null;
50 
51     /**
52      * First a cell get from valid position, second - from invalid. <p>
53      * Has <b> OK </b> status if in the first case not null value is
54      * returned and no exceptions are thrown, and in the second
55      * case <code>IndexOutOfBoundsException</code> is thrown. <p>
56      */
_getCellByPosition()57     public void _getCellByPosition() {
58 
59         boolean result = false;
60 
61         try {
62             XCell cell = oObj.getCellByPosition(0,0);
63             result = cell != null ;
64             log.println("Getting cell by position with a valid position ... OK");
65         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
66             log.println("Exception occurred while getting cell by position with a valid position");
67             e.printStackTrace(log);
68             result = false;
69         }
70 
71         try {
72             oObj.getCellByPosition(-1,1);
73             log.println("No Exception occurred while getting cell by position with invalid position");
74             result &= false;
75         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
76             log.println("Getting cell by position with a invalid position ... OK");
77             result &= true;
78         }
79 
80         tRes.tested( "getCellByPosition()", result );
81 
82     } // end getCellByPosition()
83 
84     /**
85      * A range is tried to obtain with valid name. <p>
86      * Has <b> OK </b> status if not null range is
87      * returned. <p>
88      */
_getCellRangeByName()89     public void _getCellRangeByName() {
90 
91         boolean result = false;
92 
93         String valid = (String) tEnv.getObjRelation("ValidRange");
94         if (valid == null ) valid = "A1:A1";
95         XCellRange range = oObj.getCellRangeByName(valid);
96         result = range != null ;
97         log.println("Getting cellrange by name with a valid name ... OK");
98 
99         tRes.tested( "getCellRangeByName()", result );
100 
101 
102     } // end getCellRangeByName()
103 
104     /**
105      * First a range is tried to obtain with valid bounds,
106      * second - with invalid. <p>
107      * Has <b> OK </b> status if in the first case not null range is
108      * returned and no exceptions are thrown, and in the second
109      * case <code>IndexOutOfBoundsException</code> is thrown. <p>
110      */
_getCellRangeByPosition()111     public void _getCellRangeByPosition() {
112 
113         boolean result = false;
114 
115         try {
116             XCellRange range = oObj.getCellRangeByPosition(0,0,0,0);
117             result = range != null;
118             log.println("Getting cellrange by Position with a valid position ... OK");
119         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
120             log.println("Exception occurred while getting cellrange by position with a valid position");
121             e.printStackTrace(log);
122             result = false;
123         }
124 
125         try {
126             oObj.getCellRangeByPosition(-1,0,-1,1);
127             log.println("No Exception occurred while getting cellrange by position with invalid position");
128             result &= false;
129         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
130             log.println("Getting cellrange by position with a invalid position ... OK");
131             result &= true;
132         }
133 
134         tRes.tested( "getCellRangeByPosition()", result );
135 
136 
137     } // end getCellRangeByPosition()
138 
139     /**
140     * Forces environment recreation.
141     */
after()142     protected void after() {
143         disposeEnvironment();
144     }
145 
146 } // finish class _XCellRange
147 
148