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
.container
.XEnumerationAccess
;
31 import com
.sun
.star
.lang
.XComponent
;
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
33 import com
.sun
.star
.sheet
.XNamedRanges
;
34 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
35 import com
.sun
.star
.table
.CellAddress
;
36 import com
.sun
.star
.table
.CellRangeAddress
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.uno
.XInterface
;
40 public class ScIndexEnumeration_NamedRangesEnumeration
extends TestCase
{
41 private XSpreadsheetDocument xSheetDoc
= null;
44 * Creates Spreadsheet document.
46 protected void initialize( TestParameters tParam
, PrintWriter log
) {
47 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
50 log
.println( "creating a Spreadsheet document" );
51 xSheetDoc
= SOF
.createCalcDoc(null);
52 } catch ( com
.sun
.star
.uno
.Exception e
) {
53 // Some exception occurs.FAILED
54 e
.printStackTrace( log
);
55 throw new StatusException( "Couldn't create document", e
);
60 * Disposes Spreadsheet document.
62 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
63 log
.println( " disposing xSheetDoc " );
64 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
) ;
65 util
.DesktopTools
.closeDoc(oComp
);
68 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
70 XInterface oObj
= null;
72 // creation of testobject here
73 // first we write what we are intend to do to log file
74 log
.println( "Creating a test environment" );
76 log
.println("Getting test object ");
78 // Getting named ranges.
79 XPropertySet docProps
= UnoRuntime
.queryInterface(XPropertySet
.class, xSheetDoc
);
82 ranges
= docProps
.getPropertyValue("NamedRanges");
83 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
84 e
.printStackTrace(log
);
85 throw new StatusException("Couldn't get NamedRanges", e
);
86 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
87 e
.printStackTrace(log
);
88 throw new StatusException("Couldn't get NamedRanges", e
);
91 XNamedRanges xNamedRanges
= UnoRuntime
.queryInterface(XNamedRanges
.class, ranges
);
93 CellRangeAddress DataArea
= new CellRangeAddress((short)0, 0, 0, 2, 2);
94 CellAddress base
= new CellAddress(DataArea
.Sheet
,
98 xNamedRanges
.addNewByName("ANamedRange", "A1:B2", base
, 0);
100 CellAddress listOutputPosition
= new CellAddress((short)0, 1, 1);
101 xNamedRanges
.outputList(listOutputPosition
);
105 XEnumerationAccess ea
= UnoRuntime
.queryInterface(XEnumerationAccess
.class,oObj
);
107 oObj
= ea
.createEnumeration();
109 log
.println("ImplementationName: "+util
.utils
.getImplName(oObj
));
110 // creating test environment
111 TestEnvironment tEnv
= new TestEnvironment( oObj
);
113 tEnv
.addObjRelation("ENUM",ea
);