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.sheet;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.sheet.XLabelRanges;
29 import com.sun.star.table.CellRangeAddress;
30 
31 /**
32 * Testing <code>com.sun.star.sheet.XLabelRanges</code>
33 * interface methods :
34 * <ul>
35 *  <li><code> addNew()</code></li>
36 *  <li><code> removeByIndex()</code></li>
37 * </ul> <p>
38 * @see com.sun.star.sheet.XLabelRanges
39 */
40 public class _XLabelRanges extends MultiMethodTest {
41 
42     public XLabelRanges oObj = null;
43 
44     /**
45     * Test calls the method and compares number of label range before method
46     * call and after. <p>
47     * Has <b>OK</b> status if number of label range before method call is less
48     * than after and no exceptions were thrown. <p>
49     */
_addNew()50     public void _addNew() {
51         int anz = oObj.getCount();
52         oObj.addNew(
53             new CellRangeAddress((short)0, 1, 0, 1, 0),
54             new CellRangeAddress((short)0, 1, 1, 1, 6) );
55         tRes.tested("addNew()", anz < oObj.getCount());
56     }
57 
58     /**
59     * Test removes an existent label range first and tries to remove
60     * non-existent label range. <p>
61     * Has <b> OK </b> status if number of range decreased by one after first
62     * call and exception was thrown in second. <p>
63     * The following method tests are to be completed successfully before :
64     * <ul>
65     *  <li> <code> addNew() </code> : to have one label range at least </li>
66     * </ul>
67     */
_removeByIndex()68     public void _removeByIndex() {
69         requiredMethod("addNew()");
70         int anz = oObj.getCount();
71         log.println("First remove an existent LabelRange");
72 
73         oObj.removeByIndex(anz - 1);
74         boolean result = (anz - 1 == oObj.getCount());
75 
76         log.println("Remove a nonexistent LabelRange");
77         try {
78             oObj.removeByIndex(anz);
79             log.println("No Exception thrown while removing nonexisting "+
80                 "LabelRange");
81             result &= false;
82         } catch (com.sun.star.uno.RuntimeException e) {
83             log.println("Expected exception thrown while removing "+
84                 "nonexisting LabelRange: "+e);
85             result &= true;
86         }
87 
88         tRes.tested("removeByIndex()", result);
89     }
90 
91 }  // finish class _XLabelRanges
92 
93 
94