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