1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScDatabaseRangesObj.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.beans
.XPropertySet
;
42 import com
.sun
.star
.lang
.XComponent
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.sheet
.XDatabaseRanges
;
45 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
46 import com
.sun
.star
.table
.CellRangeAddress
;
47 import com
.sun
.star
.uno
.AnyConverter
;
48 import com
.sun
.star
.uno
.Type
;
49 import com
.sun
.star
.uno
.UnoRuntime
;
50 import com
.sun
.star
.uno
.XInterface
;
53 * Test for object which is represented by service
54 * <code>com.sun.star.sheet.DatabaseRanges</code>. <p>
55 * Object implements the following interfaces :
57 * <li> <code>com::sun::star::sheet::XDatabaseRanges</code></li>
58 * <li> <code>com::sun::star::container::XNameAccess</code></li>
59 * <li> <code>com::sun::star::container::XElementAccess</code></li>
61 * @see com.sun.star.sheet.DatabaseRanges
62 * @see com.sun.star.sheet.XDatabaseRanges
63 * @see com.sun.star.container.XNameAccess
64 * @see com.sun.star.container.XElementAccess
65 * @see ifc.sheet._XDatabaseRanges
66 * @see ifc.container._XNameAccess
67 * @see ifc.container._XElementAccess
69 public class ScDatabaseRangesObj
extends TestCase
{
70 static XSpreadsheetDocument xSheetDoc
= null;
73 * Creates Spreadsheet document.
75 protected void initialize( TestParameters tParam
, PrintWriter log
) {
76 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
79 log
.println( "creating a Spreadsheet document" );
80 xSheetDoc
= SOF
.createCalcDoc(null);
81 } catch ( com
.sun
.star
.uno
.Exception e
) {
82 // Some exception occures.FAILED
83 e
.printStackTrace( log
);
84 throw new StatusException( "Couldn't create document", e
);
90 * Disposes Spreadsheet document.
92 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
93 log
.println( " disposing xSheetDoc " );
94 XComponent oComp
= (XComponent
)
95 UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
) ;
96 util
.DesktopTools
.closeDoc(oComp
);
100 * Creating a Testenvironment for the interfaces to be tested.
101 * Retrieves the collection of database ranges in the document.
102 * If the database range with name <code>'dbRange'</code> doesn't exist
103 * in the collection then creates new database range and adds it to the
104 * collection with the name <code>'dbRange'</code> to have one element
105 * for the test of the interface <code>ElementAccess</code> at least.
106 * The collection of database ranges is the instance of the service
107 * <code>com.sun.star.sheet.DatabaseRanges</code>.
108 * @see com.sun.star.sheet.DatabaseRanges
109 * @see com.sun.star.container.XElementAccess
111 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
113 XInterface oObj
= null;
115 // creation of testobject here
116 // first we write what we are intend to do to log file
117 log
.println( "Creating a test environment" );
119 log
.println("Getting test object ") ;
120 XPropertySet docProps
= (XPropertySet
)
121 UnoRuntime
.queryInterface(XPropertySet
.class, xSheetDoc
);
123 XDatabaseRanges dbRanges
= null;
125 dbRanges
= (XDatabaseRanges
) AnyConverter
.toObject(
126 new Type(XDatabaseRanges
.class),
127 docProps
.getPropertyValue("DatabaseRanges"));
128 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
129 e
.printStackTrace(log
) ;
130 throw new StatusException(
131 "Error getting test object from spreadsheet document",e
) ;
132 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
133 e
.printStackTrace(log
) ;
134 throw new StatusException(
135 "Error getting test object from spreadsheet document",e
) ;
136 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
137 e
.printStackTrace(log
) ;
138 throw new StatusException(
139 "Error getting test object from spreadsheet document",e
) ;
142 log
.println("Adding at least one element for ElementAccess interface");
143 CellRangeAddress aRange
= new CellRangeAddress((short)0, 2, 4, 5, 6);
144 if (!dbRanges
.hasByName("dbRange")) {
145 dbRanges
.addNewByName("dbRange", aRange
);
149 TestEnvironment tEnv
= new TestEnvironment( oObj
);
151 // Other parameters required for interface tests