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.XDatabaseRanges;
29 import com.sun.star.table.CellRangeAddress;
30 
31 /**
32 * Testing <code>com.sun.star.sheet.XDatabaseRanges</code>
33 * interface methods :
34 * <ul>
35 *  <li><code> addNewByName()</code></li>
36 *  <li><code> removeByName()</code></li>
37 * </ul> <p>
38 * @see com.sun.star.sheet.XDatabaseRanges
39 */
40 public class _XDatabaseRanges extends MultiMethodTest {
41 
42     public XDatabaseRanges oObj = null;
43     CellRangeAddress CRA = null;
44     String name = null;
45 
46     /**
47     * Test adds a new database range to the collection, checks that range with
48     * this name exist in collection and then tries to add range with the same
49     * name. <p>
50     * Has <b> OK </b> status if the added range exists in collection and
51     * exception was thrown when trying to add range with name that is same as name
52     * of existent range. <p>
53     */
54     public void _addNewByName() {
55         boolean bResult = true;
56         log.println("Trying to add range with proper name.");
57 
58         CRA = new CellRangeAddress((short)0, 1, 2, 3, 4);
59         name = "_XDatabaseRanges_addNewByRange";
60 
61         oObj.addNewByName(name, CRA);
62 
63         bResult &= oObj.hasByName(name);
64 
65         if (bResult) log.println("Ok");
66         log.println("Trying to add existing element.");
67 
68         try {
69             oObj.addNewByName(name, CRA);
70             log.println("Exception expected... Test failed.");
71             bResult = false;
72         } catch(com.sun.star.uno.RuntimeException e) {
73             log.println("Exception occured while testing addNewByName() : " + e);
74             bResult = true;
75         }
76 
77         tRes.tested("addNewByName()", bResult);
78     }
79 
80     /**
81     * Test removes the database range with name that exist exactly and then
82     * tries to remove the range with name that doesn't exist exactly. <p>
83     * Has <b> OK </b> status if first range was succesfully removed and
84     * exception was thrown when trying to remove non-existent database range.<p>
85     * The following method tests are to be completed successfully before :
86     * <ul>
87     *  <li> <code> addNewByName() </code> : to have definitely existed database
88     *  range </li>
89     * </ul>
90     */
91     public void _removeByName(){
92         boolean bResult = true;
93         requiredMethod("addNewByName()");
94 
95         log.println("Remove inserted element.");
96 
97         try {
98             oObj.removeByName(name);
99             bResult &= !oObj.hasByName(name);
100         } catch (com.sun.star.uno.RuntimeException e) {
101             log.println("Exception occured while testing removeByName() : " + e);
102             bResult = false;
103         }
104 
105         log.println("OK.\nTrying to remove unexistant element.");
106 
107         try {
108             oObj.removeByName(name);
109             log.println("Exception expected... - FAILED");
110             bResult = false;
111         } catch (com.sun.star.uno.RuntimeException e) {
112             log.println("Expected exception. - OK : " + e);
113         }
114         tRes.tested("removeByName()", bResult);
115     }
116 }
117 
118