1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScCellsObj.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.container
.XIndexAccess
;
42 import com
.sun
.star
.lang
.XComponent
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.sheet
.XCellRangesQuery
;
45 import com
.sun
.star
.sheet
.XSheetCellRanges
;
46 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
47 import com
.sun
.star
.sheet
.XSpreadsheets
;
48 import com
.sun
.star
.table
.XCell
;
49 import com
.sun
.star
.table
.XCellRange
;
50 import com
.sun
.star
.text
.XTextRange
;
51 import com
.sun
.star
.uno
.AnyConverter
;
52 import com
.sun
.star
.uno
.Type
;
53 import com
.sun
.star
.uno
.UnoRuntime
;
54 import com
.sun
.star
.uno
.XInterface
;
57 * Test for object which is represented by service
58 * <code>com.sun.star.sheet.Cells</code>. <p>
59 * Object implements the following interfaces :
61 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
62 * <li> <code>com::sun::star::container::XElementAccess</code></li>
64 * @see com.sun.star.sheet.Cells
65 * @see com.sun.star.container.XEnumerationAccess
66 * @see com.sun.star.container.XElementAccess
67 * @see ifc.container._XEnumerationAccess
68 * @see ifc.container._XElementAccess
70 public class ScCellsObj
extends TestCase
{
71 static XSpreadsheetDocument xSheetDoc
= null;
74 * Creates Spreadsheet document.
76 protected void initialize( TestParameters tParam
, PrintWriter log
) {
78 // get a soffice factory object
79 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
82 log
.println( "creating a sheetdocument" );
83 xSheetDoc
= SOF
.createCalcDoc(null);;
84 } catch (com
.sun
.star
.uno
.Exception e
) {
85 // Some exception occures.FAILED
86 e
.printStackTrace( log
);
87 throw new StatusException( "Couldn't create document", e
);
92 * Disposes Spreadsheet document.
94 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
95 log
.println( " disposing xSheetDoc " );
96 XComponent oComp
= (XComponent
)
97 UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
) ;
98 util
.DesktopTools
.closeDoc(oComp
);
102 * Creating a Testenvironment for the interfaces to be tested.
103 * Retrieves a collection of spreadsheets from a document,
104 * and takes one of them. Replaces text of some cells.
105 * Retrives a cell range of the visible cells using the interface
106 * <code>XCellRangesQuery</code>. Retrieves a collection of cells from
107 * this cell range, this collection is instance of the service
108 * <code>com.sun.star.sheet.Cells</code>.
109 * @see com.sun.star.sheet.XCellRangesQuery
111 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
113 XInterface oObj
= null;
114 Object cellArr
[] = new Object
[3];
116 // creation of testobject here
117 XSpreadsheets oSheets
= (XSpreadsheets
)xSheetDoc
.getSheets();
118 XIndexAccess oIndexAccess
= (XIndexAccess
)
119 UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
120 XCellRange oSheet
= null;
122 oSheet
= (XCellRange
) AnyConverter
.toObject(
123 new Type(XCellRange
.class),oIndexAccess
.getByIndex(0));
125 XCell oCell_1
= (XCell
)oSheet
.getCellByPosition(0, 0);
126 XTextRange oTextRange
= (XTextRange
)
127 UnoRuntime
.queryInterface(XTextRange
.class, oCell_1
);
129 oTextRange
.setString("ScCellsObj test 1");
131 XCell oCell_2
= (XCell
)oSheet
.getCellByPosition(5, 1);
132 oCell_2
.setValue(15);
134 XCell oCell_3
= (XCell
)oSheet
.getCellByPosition(3, 9);
135 oTextRange
= (XTextRange
)
136 UnoRuntime
.queryInterface(XTextRange
.class, oCell_3
);
138 oTextRange
.setString("ScCellsObj test 2");
140 cellArr
[0] = oCell_1
;
141 cellArr
[2] = oCell_2
;
142 cellArr
[1] = oCell_3
;
143 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
144 log
.println ("Exception occured while creating test Object.");
145 e
.printStackTrace(log
);
146 throw new StatusException("Couldn't create test object", e
);
147 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
148 log
.println ("Exception occured while creating test Object.");
149 e
.printStackTrace(log
);
150 throw new StatusException("Couldn't create test object", e
);
151 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
152 log
.println ("Exception occured while creating test Object.");
153 e
.printStackTrace(log
);
154 throw new StatusException("Couldn't create test object", e
);
157 XCellRangesQuery oCellRangesQuery
= (XCellRangesQuery
)
158 UnoRuntime
.queryInterface(XCellRangesQuery
.class, oSheet
);
159 XSheetCellRanges oSheetCellRanges
= oCellRangesQuery
.queryVisibleCells();
161 oObj
= oSheetCellRanges
.getCells();
163 TestEnvironment tEnv
= new TestEnvironment(oObj
) ;
164 log
.println ("Object created.") ;
169 } // finish class ScCellsObj