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
.container
.XIndexAccess
;
30 import com
.sun
.star
.lang
.XComponent
;
31 import com
.sun
.star
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.sheet
.XCellRangesQuery
;
33 import com
.sun
.star
.sheet
.XSheetCellRanges
;
34 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
35 import com
.sun
.star
.sheet
.XSpreadsheets
;
36 import com
.sun
.star
.table
.XCell
;
37 import com
.sun
.star
.table
.XCellRange
;
38 import com
.sun
.star
.text
.XTextRange
;
39 import com
.sun
.star
.uno
.AnyConverter
;
40 import com
.sun
.star
.uno
.Type
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
45 * Test for object which is represented by service
46 * <code>com.sun.star.sheet.Cells</code>. <p>
47 * Object implements the following interfaces :
49 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
50 * <li> <code>com::sun::star::container::XElementAccess</code></li>
52 * @see com.sun.star.sheet.Cells
53 * @see com.sun.star.container.XEnumerationAccess
54 * @see com.sun.star.container.XElementAccess
55 * @see ifc.container._XEnumerationAccess
56 * @see ifc.container._XElementAccess
58 public class ScCellsObj
extends TestCase
{
59 private XSpreadsheetDocument xSheetDoc
= null;
62 * Creates Spreadsheet document.
64 protected void initialize( TestParameters tParam
, PrintWriter log
) {
66 // get a soffice factory object
67 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
70 log
.println( "creating a sheetdocument" );
71 xSheetDoc
= SOF
.createCalcDoc(null);
72 } catch (com
.sun
.star
.uno
.Exception e
) {
73 // Some exception occurs.FAILED
74 e
.printStackTrace( log
);
75 throw new StatusException( "Couldn't create document", e
);
80 * 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. Replaces text of some cells.
92 * Retrives a cell range of the visible cells using the interface
93 * <code>XCellRangesQuery</code>. Retrieves a collection of cells from
94 * this cell range, this collection is instance of the service
95 * <code>com.sun.star.sheet.Cells</code>.
96 * @see com.sun.star.sheet.XCellRangesQuery
98 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
100 XInterface oObj
= null;
101 Object cellArr
[] = new Object
[3];
103 // creation of testobject here
104 XSpreadsheets oSheets
= xSheetDoc
.getSheets();
105 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
106 XCellRange oSheet
= null;
108 oSheet
= (XCellRange
) AnyConverter
.toObject(
109 new Type(XCellRange
.class),oIndexAccess
.getByIndex(0));
111 XCell oCell_1
= oSheet
.getCellByPosition(0, 0);
112 XTextRange oTextRange
= UnoRuntime
.queryInterface(XTextRange
.class, oCell_1
);
114 oTextRange
.setString("ScCellsObj test 1");
116 XCell oCell_2
= oSheet
.getCellByPosition(5, 1);
117 oCell_2
.setValue(15);
119 XCell oCell_3
= oSheet
.getCellByPosition(3, 9);
120 oTextRange
= UnoRuntime
.queryInterface(XTextRange
.class, oCell_3
);
122 oTextRange
.setString("ScCellsObj test 2");
124 cellArr
[0] = oCell_1
;
125 cellArr
[2] = oCell_2
;
126 cellArr
[1] = oCell_3
;
127 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
128 log
.println ("Exception occurred while creating test Object.");
129 e
.printStackTrace(log
);
130 throw new StatusException("Couldn't create test object", e
);
131 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
132 log
.println ("Exception occurred while creating test Object.");
133 e
.printStackTrace(log
);
134 throw new StatusException("Couldn't create test object", e
);
135 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
136 log
.println ("Exception occurred while creating test Object.");
137 e
.printStackTrace(log
);
138 throw new StatusException("Couldn't create test object", e
);
141 XCellRangesQuery oCellRangesQuery
= UnoRuntime
.queryInterface(XCellRangesQuery
.class, oSheet
);
142 XSheetCellRanges oSheetCellRanges
= oCellRangesQuery
.queryVisibleCells();
144 oObj
= oSheetCellRanges
.getCells();
146 TestEnvironment tEnv
= new TestEnvironment(oObj
) ;
147 log
.println ("Object created.") ;
152 } // finish class ScCellsObj