merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScIndexEnumeration_SheetCellRangesEnumeration.java
blobb659c5bfe7a42659dffef4f83f77663666afafb4
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: ScIndexEnumeration_SheetCellRangesEnumeration.java,v $
10 * $Revision: 1.8 $
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 ************************************************************************/
31 package mod._sc;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.SOfficeFactory;
41 import com.sun.star.container.XEnumerationAccess;
42 import com.sun.star.container.XIndexAccess;
43 import com.sun.star.container.XNameContainer;
44 import com.sun.star.lang.XComponent;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.sheet.XSpreadsheet;
47 import com.sun.star.sheet.XSpreadsheetDocument;
48 import com.sun.star.sheet.XSpreadsheets;
49 import com.sun.star.uno.AnyConverter;
50 import com.sun.star.uno.Type;
51 import com.sun.star.uno.UnoRuntime;
52 import com.sun.star.uno.XInterface;
54 public class ScIndexEnumeration_SheetCellRangesEnumeration extends TestCase {
55 static XSpreadsheetDocument xSheetDoc = null;
57 /**
58 * Creates Spreadsheet document.
60 protected void initialize( TestParameters tParam, PrintWriter log ) {
62 // get a soffice factory object
63 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
65 try {
66 log.println( "creating a sheetdocument" );
67 xSheetDoc = SOF.createCalcDoc(null);;
68 } catch (com.sun.star.uno.Exception e) {
69 // Some exception occures.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 =
81 (XComponent) UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
82 util.DesktopTools.closeDoc(oComp);
85 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
87 XInterface oObj = null;
88 Object oRange = null ;
90 // creation of testobject here
91 // first we write what we are intend to do to log file
92 log.println( "Creating a test environment" );
94 // get a soffice factory object
95 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF() );
97 log.println("Getting test object ");
99 XComponent oComp = (XComponent)
100 UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
102 oObj = (XInterface)
103 SOF.createInstance(oComp, "com.sun.star.sheet.SheetCellRanges");
105 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
106 XIndexAccess oIndSheets = (XIndexAccess)
107 UnoRuntime.queryInterface (XIndexAccess.class, oSheets);
108 XSpreadsheet oSheet = null;
109 try {
110 oSheet = (XSpreadsheet) AnyConverter.toObject(
111 new Type(XSpreadsheet.class),oIndSheets.getByIndex(0));
112 XNameContainer oRanges = (XNameContainer)
113 UnoRuntime.queryInterface(XNameContainer.class, oObj);
115 oRange = oSheet.getCellRangeByName("C1:D4");
116 oRanges.insertByName("Range1", oRange);
117 oRange = oSheet.getCellRangeByName("E2:F5");
118 oRanges.insertByName("Range2", oRange);
119 oRange = oSheet.getCellRangeByName("G2:H3");
120 oRanges.insertByName("Range3", oRange);
121 oRange = oSheet.getCellRangeByName("I7:J8");
122 oRanges.insertByName("Range4", oRange);
123 } catch(com.sun.star.lang.WrappedTargetException e) {
124 e.printStackTrace(log);
125 throw new StatusException("Couldn't create test object", e);
126 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
127 e.printStackTrace(log);
128 throw new StatusException("Couldn't create test object", e);
129 } catch(com.sun.star.container.ElementExistException e) {
130 e.printStackTrace(log);
131 throw new StatusException("Couldn't create test object", e);
132 } catch(com.sun.star.lang.IllegalArgumentException e) {
133 e.printStackTrace(log);
134 throw new StatusException("Couldn't create test object", e);
137 log.println("filling some cells");
138 try {
139 for (int i = 0; i < 10; i++) {
140 for (int j = 0; j < 5; j++) {
141 oSheet.getCellByPosition(i, j).setFormula("a");
144 for (int i = 0; i < 10; i++) {
145 for (int j = 5; j < 10; j++) {
146 oSheet.getCellByPosition(i, j).setValue(i + j);
149 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
150 e.printStackTrace(log);
151 throw new StatusException (
152 "Exception occurred while filling cells", e);
155 XEnumerationAccess ea = (XEnumerationAccess)
156 UnoRuntime.queryInterface(XEnumerationAccess.class,oObj);
158 oObj = ea.createEnumeration();
160 log.println("ImplementationName: "+util.utils.getImplName(oObj));
161 // creating test environment
162 TestEnvironment tEnv = new TestEnvironment( oObj );
164 tEnv.addObjRelation("ENUM",ea);
166 return tEnv ;