bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScCellsEnumeration.java
blob0b30d844d4d51dcb62f182d3c449a0e00a7c6713
1 /*
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 .
18 package mod._sc;
20 import java.io.PrintWriter;
22 import lib.StatusException;
23 import lib.TestCase;
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.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;
44 /**
45 * Test for object which is represented by service
46 * <code>com.sun.star.sheet.CellsEnumeration</code>. <p>
47 * Object implements the following interfaces :
48 * <ul>
49 * <li> <code>com::sun::star::container::XEnumeration</code></li>
50 * </ul>
51 * @see com.sun.star.sheet.CellsEnumeration
52 * @see com.sun.star.container.XEnumeration
53 * @see ifc.container._XEnumeration
55 public class ScCellsEnumeration extends TestCase {
56 private XSpreadsheetDocument xSheetDoc = null;
58 /**
59 * Creates Spreadsheet document.
61 protected void initialize( TestParameters tParam, PrintWriter log ) {
63 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
65 try {
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 );
75 /**
76 * Disposes Spreadsheet document.
78 protected void cleanup( TestParameters tParam, PrintWriter log ) {
79 log.println( " disposing xSheetDoc " );
80 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
81 util.DesktopTools.closeDoc(oComp);
84 /**
85 * Creating a Testenvironment for the interfaces to be tested.
86 * Retrieves a collection of spreadsheets from a document
87 * and takes one of them. Replaces text of some cells.
88 * Retrives a cell range of the visible cells using the interface
89 * <code>XCellRangesQuery</code>. Retrieves a collection of cells from
90 * this cell range and creates it's enumeration using the interface
91 * <code>XEnumerationAccess</code>.The created enumeration is the instance
92 * of the service <code>com.sun.star.sheet.CellsEnumeration</code>.
93 * Object relations created :
94 * <ul>
95 * <li> <code>'ENUM'</code> for
96 * {@link ifc.container._XEnumeration} (type of
97 * <code>XEnumerationAccess</code> that was retrieved from the
98 * collection of visible cells)</li>
99 * </ul>
100 * @see com.sun.star.sheet.XCellRangesQuery
101 * @see com.sun.star.container.XEnumerationAccess
103 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
105 XInterface oObj = null;
106 Object cellArr[] = new Object[3] ;
107 XEnumerationAccess oEnum = null;
109 // creation of testobject here
110 XSpreadsheets oSheets = xSheetDoc.getSheets();
111 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
112 XCellRange oSheet = null;
113 try {
114 oSheet = (XCellRange) AnyConverter.toObject(
115 new Type(XCellRange.class),oIndexAccess.getByIndex(0));
117 XCell oCell_1 = oSheet.getCellByPosition(0, 0);
118 XTextRange oTextRange = UnoRuntime.queryInterface(XTextRange.class, oCell_1);
119 oTextRange.setString("Test string 1");
121 XCell oCell_2 = oSheet.getCellByPosition(5, 1);
122 oCell_2.setValue(15);
124 XCell oCell_3 = oSheet.getCellByPosition(3, 9);
125 oTextRange = UnoRuntime.queryInterface(XTextRange.class, oCell_3);
126 oTextRange.setString("test 2");
127 cellArr[0] = oCell_1;
128 cellArr[1] = oCell_2;
129 cellArr[2] = oCell_3;
130 } catch(com.sun.star.lang.WrappedTargetException e) {
131 log.println ("Exception occurred while creating test Object.");
132 e.printStackTrace(log);
133 throw new StatusException("Couldn't create test object", e);
134 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
135 log.println ("Exception occurred while creating test Object.");
136 e.printStackTrace(log);
137 throw new StatusException("Couldn't create test object", e);
138 } catch(com.sun.star.lang.IllegalArgumentException e) {
139 log.println ("Exception occurred while creating test Object.");
140 e.printStackTrace(log);
141 throw new StatusException("Couldn't create test object", e);
144 XCellRangesQuery oCellRangesQuery = UnoRuntime.queryInterface(XCellRangesQuery.class, oSheet);
145 XSheetCellRanges oSheetCellRanges = oCellRangesQuery.queryVisibleCells();
146 oEnum = oSheetCellRanges.getCells();
147 oObj = oSheetCellRanges.getCells().createEnumeration();
149 TestEnvironment tEnv = new TestEnvironment(oObj);
151 // ENUM: XEnumeration
152 tEnv.addObjRelation("ENUM", oEnum);
154 return tEnv;
157 } // finish class ScCellsEnumeration