merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScCellsEnumeration.java
blobad1a5f03d01db7b4190ab211306f419ad0b18773
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScCellsEnumeration.java,v $
10 * $Revision: 1.9 $
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 ************************************************************************/
30 package mod._sc;
32 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
38 import util.SOfficeFactory;
40 import com.sun.star.container.XEnumerationAccess;
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;
56 /**
57 * Test for object which is represented by service
58 * <code>com.sun.star.sheet.CellsEnumeration</code>. <p>
59 * Object implements the following interfaces :
60 * <ul>
61 * <li> <code>com::sun::star::container::XEnumeration</code></li>
62 * </ul>
63 * @see com.sun.star.sheet.CellsEnumeration
64 * @see com.sun.star.container.XEnumeration
65 * @see ifc.container._XEnumeration
67 public class ScCellsEnumeration extends TestCase {
68 static XSpreadsheetDocument xSheetDoc = null;
70 /**
71 * Creates Spreadsheet document.
73 protected void initialize( TestParameters tParam, PrintWriter log ) {
75 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
77 try {
78 log.println( "creating a Spreadsheet document" );
79 xSheetDoc = SOF.createCalcDoc(null);
80 } catch ( com.sun.star.uno.Exception e ) {
81 // Some exception occures.FAILED
82 e.printStackTrace( log );
83 throw new StatusException( "Couldn't create document", e );
87 /**
88 * Disposes Spreadsheet document.
90 protected void cleanup( TestParameters tParam, PrintWriter log ) {
91 log.println( " disposing xSheetDoc " );
92 XComponent oComp = (XComponent)
93 UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
94 util.DesktopTools.closeDoc(oComp);
97 /**
98 * Creating a Testenvironment for the interfaces to be tested.
99 * Retrieves a collection of spreadsheets from a document
100 * and takes one of them. Replaces text of some cells.
101 * Retrives a cell range of the visible cells using the interface
102 * <code>XCellRangesQuery</code>. Retrieves a collection of cells from
103 * this cell range and creates it's enumeration using the interface
104 * <code>XEnumerationAccess</code>.The created enumeration is the instance
105 * of the service <code>com.sun.star.sheet.CellsEnumeration</code>.
106 * Object relations created :
107 * <ul>
108 * <li> <code>'ENUM'</code> for
109 * {@link ifc.container._XEnumeration} (type of
110 * <code>XEnumerationAccess</code> that was retrieved from the
111 * collection of visible cells)</li>
112 * </ul>
113 * @see com.sun.star.sheet.XCellRangesQuery
114 * @see com.sun.star.container.XEnumerationAccess
116 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
118 XInterface oObj = null;
119 Object cellArr[] = new Object[3] ;
120 XEnumerationAccess oEnum = null;
122 // creation of testobject here
123 XSpreadsheets oSheets = (XSpreadsheets)xSheetDoc.getSheets();
124 XIndexAccess oIndexAccess = (XIndexAccess)
125 UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
126 XCellRange oSheet = null;
127 try {
128 oSheet = (XCellRange) AnyConverter.toObject(
129 new Type(XCellRange.class),oIndexAccess.getByIndex(0));
131 XCell oCell_1 = (XCell)oSheet.getCellByPosition(0, 0);
132 XTextRange oTextRange = (XTextRange)
133 UnoRuntime.queryInterface(XTextRange.class, oCell_1);
134 oTextRange.setString("Test string 1");
136 XCell oCell_2 = (XCell)oSheet.getCellByPosition(5, 1);
137 oCell_2.setValue(15);
139 XCell oCell_3 = (XCell)oSheet.getCellByPosition(3, 9);
140 oTextRange = (XTextRange)
141 UnoRuntime.queryInterface(XTextRange.class, oCell_3);
142 oTextRange.setString("test 2");
143 cellArr[0] = oCell_1;
144 cellArr[1] = oCell_2;
145 cellArr[2] = oCell_3;
146 } catch(com.sun.star.lang.WrappedTargetException e) {
147 log.println ("Exception occured while creating test Object.");
148 e.printStackTrace(log);
149 throw new StatusException("Couldn't create test object", e);
150 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
151 log.println ("Exception occured while creating test Object.");
152 e.printStackTrace(log);
153 throw new StatusException("Couldn't create test object", e);
154 } catch(com.sun.star.lang.IllegalArgumentException e) {
155 log.println ("Exception occured while creating test Object.");
156 e.printStackTrace(log);
157 throw new StatusException("Couldn't create test object", e);
160 XCellRangesQuery oCellRangesQuery = (XCellRangesQuery)
161 UnoRuntime.queryInterface(XCellRangesQuery.class, oSheet);
162 XSheetCellRanges oSheetCellRanges = oCellRangesQuery.queryVisibleCells();
163 oEnum = (XEnumerationAccess) oSheetCellRanges.getCells();
164 oObj = oSheetCellRanges.getCells().createEnumeration();
166 TestEnvironment tEnv = new TestEnvironment(oObj);
168 // ENUM: XEnumeration
169 tEnv.addObjRelation("ENUM", oEnum);
171 return tEnv;
174 } // finish class ScCellsEnumeration