2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.beans
.XPropertySet
;
30 import com
.sun
.star
.lang
.XComponent
;
31 import com
.sun
.star
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.sheet
.XDatabaseRanges
;
33 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
34 import com
.sun
.star
.table
.CellRangeAddress
;
35 import com
.sun
.star
.uno
.AnyConverter
;
36 import com
.sun
.star
.uno
.Type
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.uno
.XInterface
;
41 * Test for object which is represented by service
42 * <code>com.sun.star.sheet.DatabaseRanges</code>. <p>
43 * Object implements the following interfaces :
45 * <li> <code>com::sun::star::sheet::XDatabaseRanges</code></li>
46 * <li> <code>com::sun::star::container::XNameAccess</code></li>
47 * <li> <code>com::sun::star::container::XElementAccess</code></li>
49 * @see com.sun.star.sheet.DatabaseRanges
50 * @see com.sun.star.sheet.XDatabaseRanges
51 * @see com.sun.star.container.XNameAccess
52 * @see com.sun.star.container.XElementAccess
53 * @see ifc.sheet._XDatabaseRanges
54 * @see ifc.container._XNameAccess
55 * @see ifc.container._XElementAccess
57 public class ScDatabaseRangesObj
extends TestCase
{
58 private XSpreadsheetDocument xSheetDoc
= null;
61 * Creates Spreadsheet document.
63 protected void initialize( TestParameters tParam
, PrintWriter log
) {
64 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
67 log
.println( "creating a Spreadsheet document" );
68 xSheetDoc
= SOF
.createCalcDoc(null);
69 } catch ( com
.sun
.star
.uno
.Exception e
) {
70 // Some exception occurs.FAILED
71 e
.printStackTrace( log
);
72 throw new StatusException( "Couldn't create document", e
);
78 * Disposes Spreadsheet document.
80 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
81 log
.println( " disposing xSheetDoc " );
82 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
) ;
83 util
.DesktopTools
.closeDoc(oComp
);
87 * Creating a Testenvironment for the interfaces to be tested.
88 * Retrieves the collection of database ranges in the document.
89 * If the database range with name <code>'dbRange'</code> doesn't exist
90 * in the collection then creates new database range and adds it to the
91 * collection with the name <code>'dbRange'</code> to have one element
92 * for the test of the interface <code>ElementAccess</code> at least.
93 * The collection of database ranges is the instance of the service
94 * <code>com.sun.star.sheet.DatabaseRanges</code>.
95 * @see com.sun.star.sheet.DatabaseRanges
96 * @see com.sun.star.container.XElementAccess
98 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
100 XInterface oObj
= null;
102 // creation of testobject here
103 // first we write what we are intend to do to log file
104 log
.println( "Creating a test environment" );
106 log
.println("Getting test object ") ;
107 XPropertySet docProps
= UnoRuntime
.queryInterface(XPropertySet
.class, xSheetDoc
);
109 XDatabaseRanges dbRanges
= null;
111 dbRanges
= (XDatabaseRanges
) AnyConverter
.toObject(
112 new Type(XDatabaseRanges
.class),
113 docProps
.getPropertyValue("DatabaseRanges"));
114 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
115 e
.printStackTrace(log
) ;
116 throw new StatusException(
117 "Error getting test object from spreadsheet document",e
) ;
118 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
119 e
.printStackTrace(log
) ;
120 throw new StatusException(
121 "Error getting test object from spreadsheet document",e
) ;
122 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
123 e
.printStackTrace(log
) ;
124 throw new StatusException(
125 "Error getting test object from spreadsheet document",e
) ;
128 log
.println("Adding at least one element for ElementAccess interface");
129 CellRangeAddress aRange
= new CellRangeAddress((short)0, 2, 4, 5, 6);
130 if (!dbRanges
.hasByName("dbRange")) {
131 dbRanges
.addNewByName("dbRange", aRange
);
135 TestEnvironment tEnv
= new TestEnvironment( oObj
);
137 // Other parameters required for interface tests