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 .
20 import java
.io
.PrintWriter
;
22 import lib
.StatusException
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
28 import com
.sun
.star
.container
.XEnumerationAccess
;
29 import com
.sun
.star
.container
.XIndexAccess
;
30 import com
.sun
.star
.lang
.XComponent
;
31 import com
.sun
.star
.sheet
.XCellRangesQuery
;
32 import com
.sun
.star
.sheet
.XSheetCellRanges
;
33 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
34 import com
.sun
.star
.sheet
.XSpreadsheets
;
35 import com
.sun
.star
.table
.XCell
;
36 import com
.sun
.star
.table
.XCellRange
;
37 import com
.sun
.star
.text
.XTextRange
;
38 import com
.sun
.star
.uno
.AnyConverter
;
39 import com
.sun
.star
.uno
.Type
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
44 * Test for object which is represented by service
45 * <code>com.sun.star.sheet.CellsEnumeration</code>. <p>
46 * Object implements the following interfaces :
48 * <li> <code>com::sun::star::container::XEnumeration</code></li>
50 * @see com.sun.star.sheet.CellsEnumeration
51 * @see com.sun.star.container.XEnumeration
52 * @see ifc.container._XEnumeration
54 public class ScCellsEnumeration
extends TestCase
{
55 private XSpreadsheetDocument xSheetDoc
= null;
58 * Creates Spreadsheet document.
61 protected void initialize( TestParameters tParam
, PrintWriter log
) {
63 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
66 log
.println( "creating a Spreadsheet document" );
67 xSheetDoc
= SOF
.createCalcDoc(null);
68 } catch ( com
.sun
.star
.uno
.Exception e
) {
69 // Some exception occurs.FAILED
70 e
.printStackTrace( log
);
71 throw new StatusException( "Couldn't create document", e
);
76 * Disposes Spreadsheet document.
79 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
80 log
.println( " disposing xSheetDoc " );
81 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
) ;
82 util
.DesktopTools
.closeDoc(oComp
);
86 * Creating a Testenvironment for the interfaces to be tested.
87 * Retrieves a collection of spreadsheets from a document
88 * and takes one of them. Replaces text of some cells.
89 * Retrieves a cell range of the visible cells using the interface
90 * <code>XCellRangesQuery</code>. Retrieves a collection of cells from
91 * this cell range and creates it's enumeration using the interface
92 * <code>XEnumerationAccess</code>.The created enumeration is the instance
93 * of the service <code>com.sun.star.sheet.CellsEnumeration</code>.
94 * Object relations created :
96 * <li> <code>'ENUM'</code> for
97 * {@link ifc.container._XEnumeration} (type of
98 * <code>XEnumerationAccess</code> that was retrieved from the
99 * collection of visible cells)</li>
101 * @see com.sun.star.sheet.XCellRangesQuery
102 * @see com.sun.star.container.XEnumerationAccess
105 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
107 XInterface oObj
= null;
108 Object cellArr
[] = new Object
[3] ;
109 XEnumerationAccess oEnum
= null;
111 // creation of testobject here
112 XSpreadsheets oSheets
= xSheetDoc
.getSheets();
113 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
114 XCellRange oSheet
= null;
116 oSheet
= (XCellRange
) AnyConverter
.toObject(
117 new Type(XCellRange
.class),oIndexAccess
.getByIndex(0));
119 XCell oCell_1
= oSheet
.getCellByPosition(0, 0);
120 XTextRange oTextRange
= UnoRuntime
.queryInterface(XTextRange
.class, oCell_1
);
121 oTextRange
.setString("Test string 1");
123 XCell oCell_2
= oSheet
.getCellByPosition(5, 1);
124 oCell_2
.setValue(15);
126 XCell oCell_3
= oSheet
.getCellByPosition(3, 9);
127 oTextRange
= UnoRuntime
.queryInterface(XTextRange
.class, oCell_3
);
128 oTextRange
.setString("test 2");
129 cellArr
[0] = oCell_1
;
130 cellArr
[1] = oCell_2
;
131 cellArr
[2] = oCell_3
;
132 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
133 log
.println ("Exception occurred while creating test Object.");
134 e
.printStackTrace(log
);
135 throw new StatusException("Couldn't create test object", e
);
136 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
137 log
.println ("Exception occurred while creating test Object.");
138 e
.printStackTrace(log
);
139 throw new StatusException("Couldn't create test object", e
);
140 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
141 log
.println ("Exception occurred while creating test Object.");
142 e
.printStackTrace(log
);
143 throw new StatusException("Couldn't create test object", e
);
146 XCellRangesQuery oCellRangesQuery
= UnoRuntime
.queryInterface(XCellRangesQuery
.class, oSheet
);
147 XSheetCellRanges oSheetCellRanges
= oCellRangesQuery
.queryVisibleCells();
148 oEnum
= oSheetCellRanges
.getCells();
149 oObj
= oSheetCellRanges
.getCells().createEnumeration();
151 TestEnvironment tEnv
= new TestEnvironment(oObj
);
153 // ENUM: XEnumeration
154 tEnv
.addObjRelation("ENUM", oEnum
);
159 } // finish class ScCellsEnumeration