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 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
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
.XCellFormatRangesSupplier
;
33 import com
.sun
.star
.sheet
.XSpreadsheet
;
34 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
35 import com
.sun
.star
.sheet
.XSpreadsheets
;
36 import com
.sun
.star
.uno
.AnyConverter
;
37 import com
.sun
.star
.uno
.Type
;
38 import com
.sun
.star
.uno
.UnoRuntime
;
39 import com
.sun
.star
.uno
.XInterface
;
42 * Test for object which is represented by service
43 * <code>com.sun.star.sheet.CellFormatRanges</code>. <p>
44 * Object implements the following interfaces :
46 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
47 * <li> <code>com::sun::star::container::XElementAccess</code></li>
49 * @see com.sun.star.sheet.CellFormatRanges
50 * @see com.sun.star.container.XEnumerationAccess
51 * @see com.sun.star.container.XElementAccess
52 * @see ifc.container._XEnumerationAccess
53 * @see ifc.container._XElementAccess
55 public class ScCellFormatsObj
extends TestCase
{
56 private XSpreadsheetDocument xSheetDoc
= null;
59 * Creates Spreadsheet document.
61 protected void initialize( TestParameters tParam
, PrintWriter log
) {
62 // get a soffice factory object
63 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
66 log
.println( "creating a sheetdocument" );
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
);
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
);
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. Then retrieves a collection of format cell
88 * range using the interface <code>XCellFormatRangesSupplier</code> that is
89 * instance of service <code>com.sun.star.sheet.CellFormatRanges</code>.
90 * @see com.sun.star.sheet.CellFormatRanges
91 * @see com.sun.star.sheet.XCellFormatRangesSupplier
93 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
95 XInterface oObj
= null;
97 log
.println("getting sheets");
98 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets();
100 log
.println("getting a sheet");
101 XSpreadsheet oSheet
= null;
102 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
104 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
105 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
106 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
107 e
.printStackTrace(log
);
108 throw new StatusException( "Couldn't get a spreadsheet", e
);
109 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
110 e
.printStackTrace(log
);
111 throw new StatusException( "Couldn't get a spreadsheet", e
);
112 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
113 e
.printStackTrace(log
);
114 throw new StatusException( "Couldn't get a spreadsheet", e
);
117 log
.println("getting CellFormats");
118 XCellFormatRangesSupplier xCFRS
= UnoRuntime
.queryInterface(XCellFormatRangesSupplier
.class, oSheet
);
119 XIndexAccess formats
= xCFRS
.getCellFormatRanges();
123 log
.println("creating a new environment for object");
124 TestEnvironment tEnv
= new TestEnvironment(oObj
);
128 } // finish class ScCellFormatsObj