merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScCellFormatsEnumeration.java
blobb8ba701e23732d3b9cbca0fb318124fdf8673276
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: ScCellFormatsEnumeration.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.lang.XComponent;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.sheet.XCellFormatRangesSupplier;
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 /**
55 * Test for object which is represented by service
56 * <code>com.sun.star.sheet.CellFormatRangesEnumeration</code>. <p>
57 * Object implements the following interfaces :
58 * <ul>
59 * <li> <code>com::sun::star::container::XEnumeration</code></li>
60 * </ul>
61 * @see com.sun.star.sheet.CellFormatRangesEnumeration
62 * @see com.sun.star.container.XEnumeration
63 * @see ifc.container._XEnumeration
65 public class ScCellFormatsEnumeration extends TestCase {
66 static XSpreadsheetDocument xSheetDoc = null;
68 /**
69 * Creates Spreadsheet document.
71 protected void initialize( TestParameters tParam, PrintWriter log ) {
72 // get a soffice factory object
73 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
75 try {
76 log.println( "creating a sheetdocument" );
77 xSheetDoc = SOF.createCalcDoc(null);;
78 } catch (com.sun.star.uno.Exception e) {
79 // Some exception occures.FAILED
80 e.printStackTrace( log );
81 throw new StatusException( "Couldn't create document", e);
85 /**
86 * Disposes Spreadsheet document.
88 protected void cleanup( TestParameters tParam, PrintWriter log ) {
89 log.println( " disposing xSheetDoc " );
90 XComponent oComp = (XComponent)
91 UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
92 util.DesktopTools.closeDoc(oComp);
95 /**
96 * Creating a Testenvironment for the interfaces to be tested.
97 * Retrieves a collection of spreadsheets from a document,
98 * and takes one of them. Then retrieves a collection of cell format range
99 * using the interface <code>XCellFormatRangesSupplier</code>, creates the
100 * enumeration of this collection using interface <code>XEnumerationAccess</code>.
101 * This enumeration is the instance of the service
102 * <code>com.sun.star.sheet.CellFormatRangesEnumeration</code>.
103 * Object relations created :
104 * <ul>
105 * <li> <code>'ENUM'</code> for
106 * {@link ifc.container._XEnumeration} (type of
107 * <code>XEnumerationAccess</code> that was queried from the collection
108 * of cell format range)</li>
109 * </ul>
110 * @see com.sun.star.sheet.CellFormatRangesEnumeration
111 * @see com.sun.star.sheet.XCellFormatRangesSupplier
112 * @see com.sun.star.container.XEnumerationAccess
114 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
116 XInterface oObj = null;
118 log.println("getting sheets");
119 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSheetDoc.getSheets();
121 log.println("getting a sheet");
122 XSpreadsheet oSheet = null;
123 XIndexAccess oIndexAccess = (XIndexAccess)
124 UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
126 try {
127 oSheet = (XSpreadsheet) AnyConverter.toObject(
128 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
129 } catch (com.sun.star.lang.WrappedTargetException e) {
130 e.printStackTrace(log);
131 throw new StatusException( "Couldn't get a spreadsheet", e);
132 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
133 e.printStackTrace(log);
134 throw new StatusException( "Couldn't get a spreadsheet", e);
135 } catch (com.sun.star.lang.IllegalArgumentException e) {
136 e.printStackTrace(log);
137 throw new StatusException( "Couldn't get a spreadsheet", e);
140 log.println("getting CellFormats");
142 XCellFormatRangesSupplier xCFRS = (XCellFormatRangesSupplier)
143 UnoRuntime.queryInterface(XCellFormatRangesSupplier.class,oSheet);
144 XIndexAccess formats = xCFRS.getCellFormatRanges();
146 log.println("getting Enumeration");
147 XEnumerationAccess oEnum = (XEnumerationAccess)
148 UnoRuntime.queryInterface(XEnumerationAccess.class,formats);
149 oObj = oEnum.createEnumeration();
151 log.println("creating a new environment for object");
152 TestEnvironment tEnv = new TestEnvironment(oObj);
154 tEnv.addObjRelation("ENUM", oEnum);
156 return tEnv;
159 } // finish class ScCellFormatsEnumeration