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: ScCellFormatsObj.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
.XCellFormatRangesSupplier
;
45 import com
.sun
.star
.sheet
.XSpreadsheet
;
46 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
47 import com
.sun
.star
.sheet
.XSpreadsheets
;
48 import com
.sun
.star
.uno
.AnyConverter
;
49 import com
.sun
.star
.uno
.Type
;
50 import com
.sun
.star
.uno
.UnoRuntime
;
51 import com
.sun
.star
.uno
.XInterface
;
54 * Test for object which is represented by service
55 * <code>com.sun.star.sheet.CellFormatRanges</code>. <p>
56 * Object implements the following interfaces :
58 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
59 * <li> <code>com::sun::star::container::XElementAccess</code></li>
61 * @see com.sun.star.sheet.CellFormatRanges
62 * @see com.sun.star.container.XEnumerationAccess
63 * @see com.sun.star.container.XElementAccess
64 * @see ifc.container._XEnumerationAccess
65 * @see ifc.container._XElementAccess
67 public class ScCellFormatsObj
extends TestCase
{
68 static XSpreadsheetDocument xSheetDoc
= null;
71 * Creates Spreadsheet document.
73 protected void initialize( TestParameters tParam
, PrintWriter log
) {
74 // get a soffice factory object
75 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
78 log
.println( "creating a sheetdocument" );
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
);
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
);
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. Then retrieves a collection of format cell
101 * range using the interface <code>XCellFormatRangesSupplier</code> that is
102 * instance of service <code>com.sun.star.sheet.CellFormatRanges</code>.
103 * @see com.sun.star.sheet.CellFormatRanges
104 * @see com.sun.star.sheet.XCellFormatRangesSupplier
106 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
108 XInterface oObj
= null;
110 log
.println("getting sheets");
111 XSpreadsheets xSpreadsheets
= (XSpreadsheets
)xSheetDoc
.getSheets();
113 log
.println("getting a sheet");
114 XSpreadsheet oSheet
= null;
115 XIndexAccess oIndexAccess
= (XIndexAccess
)
116 UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
118 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
119 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
120 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
121 e
.printStackTrace(log
);
122 throw new StatusException( "Couldn't get a spreadsheet", e
);
123 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
124 e
.printStackTrace(log
);
125 throw new StatusException( "Couldn't get a spreadsheet", e
);
126 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
127 e
.printStackTrace(log
);
128 throw new StatusException( "Couldn't get a spreadsheet", e
);
131 log
.println("getting CellFormats");
132 XCellFormatRangesSupplier xCFRS
= (XCellFormatRangesSupplier
)
133 UnoRuntime
.queryInterface(XCellFormatRangesSupplier
.class, oSheet
);
134 XIndexAccess formats
= xCFRS
.getCellFormatRanges();
138 log
.println("creating a new environment for object");
139 TestEnvironment tEnv
= new TestEnvironment(oObj
);
143 } // finish class ScCellFormatsObj