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
.sheet
.XNamedRanges
;
32 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
33 import com
.sun
.star
.table
.CellAddress
;
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.NamedRange</code>. <p>
43 * Object implements the following interfaces :
45 * <li> <code>com::sun::star::container::XNamed</code></li>
46 * <li> <code>com::sun::star::sheet::XNamedRange</code></li>
47 * <li> <code>com::sun::star::sheet::XCellRangeReferrer</code></li>
49 * @see com.sun.star.sheet.NamedRange
50 * @see com.sun.star.container.XNamed
51 * @see com.sun.star.sheet.XNamedRange
52 * @see com.sun.star.sheet.XCellRangeReferrer
53 * @see ifc.container._XNamed
54 * @see ifc.sheet._XNamedRange
55 * @see ifc.sheet._XCellRangeReferrer
57 public class ScNamedRangeObj
extends TestCase
{
58 private XSpreadsheetDocument xSheetDoc
= null;
61 * Creates Spreadsheet document.
64 protected void initialize( TestParameters tParam
, PrintWriter log
) {
65 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
68 log
.println( "creating a Spreadsheet document" );
69 xSheetDoc
= SOF
.createCalcDoc(null);
70 } catch ( com
.sun
.star
.uno
.Exception e
) {
71 // Some exception occurs.FAILED
72 e
.printStackTrace( log
);
73 throw new StatusException( "Couldn't create document", e
);
79 * Disposes Spreadsheet document.
82 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
83 log
.println( " disposing xSheetDoc " );
84 XComponent oComp
= UnoRuntime
.queryInterface(XComponent
.class, xSheetDoc
) ;
85 util
.DesktopTools
.closeDoc(oComp
);
89 * Creating a Testenvironment for the interfaces to be tested.
90 * Retrieves a collection of spreadsheets from a document
91 * and takes one of them. Obtains the value of the property
92 * <code>'NamedRanges'</code> that is the collection of named ranges.
93 * Creates and adds new range to the collection. This new range is the instance of the
94 * service <code>com.sun.star.sheet.NamedRange</code>.
95 * Object relations created :
97 * <li> <code>'DATAAREA'</code> for
98 * {@link ifc.sheet._XCellRangeReferrer} (the cell range address of the
99 * created range) </li>
103 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
105 XInterface oObj
= null;
107 // creation of testobject here
108 // first we write what we are intend to do to log file
109 log
.println( "Creating a test environment" );
111 log
.println("Getting test object ") ;
113 // Getting named ranges.
114 XPropertySet docProps
= UnoRuntime
.queryInterface(XPropertySet
.class, xSheetDoc
);
116 Object ranges
= null;
118 ranges
= docProps
.getPropertyValue("NamedRanges");
119 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
120 e
.printStackTrace(log
);
121 throw new StatusException("Couldn't get NamedRanges", e
);
122 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
123 e
.printStackTrace(log
);
124 throw new StatusException("Couldn't get NamedRanges", e
);
127 XNamedRanges xNamedRanges
= UnoRuntime
.queryInterface(XNamedRanges
.class, ranges
);
129 CellRangeAddress DataArea
= new CellRangeAddress((short)0, 0, 0, 1, 1);
130 CellAddress base
= new CellAddress(DataArea
.Sheet
,
131 DataArea
.StartColumn
,
134 if (xNamedRanges
.hasByName("ANamedRange")) {
135 xNamedRanges
.removeByName("ANamedRange");
138 xNamedRanges
.addNewByName("ANamedRange", "A1:B2", base
, 0);
140 CellAddress listOutputPosition
= new CellAddress((short)0, 1, 1);
141 xNamedRanges
.outputList(listOutputPosition
);
144 oObj
= (XInterface
) AnyConverter
.toObject(
145 new Type(XInterface
.class),xNamedRanges
.getByName("ANamedRange"));
146 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
147 e
.printStackTrace(log
);
148 throw new StatusException("Couldn't get by name", e
);
149 } catch(com
.sun
.star
.container
.NoSuchElementException e
){
150 e
.printStackTrace(log
);
151 throw new StatusException("Couldn't get by name", e
);
152 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
){
153 e
.printStackTrace(log
);
154 throw new StatusException("Couldn't get by name", e
);
157 TestEnvironment tEnv
= new TestEnvironment( oObj
);
159 // Other parameters required for interface tests
160 tEnv
.addObjRelation("DATAAREA", DataArea
);