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
.sheet
.XCellFormatRangesSupplier
;
32 import com
.sun
.star
.sheet
.XSpreadsheet
;
33 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
34 import com
.sun
.star
.sheet
.XSpreadsheets
;
35 import com
.sun
.star
.uno
.AnyConverter
;
36 import com
.sun
.star
.uno
.Type
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.uno
.XInterface
;
41 * Test for object which is represented by service
42 * <code>com.sun.star.sheet.CellFormatRanges</code>. <p>
43 * Object implements the following interfaces :
45 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
46 * <li> <code>com::sun::star::container::XElementAccess</code></li>
48 * @see com.sun.star.sheet.CellFormatRanges
49 * @see com.sun.star.container.XEnumerationAccess
50 * @see com.sun.star.container.XElementAccess
51 * @see ifc.container._XEnumerationAccess
52 * @see ifc.container._XElementAccess
54 public class ScCellFormatsObj
extends TestCase
{
55 private XSpreadsheetDocument xSheetDoc
= null;
58 * Creates Spreadsheet document.
61 protected void initialize( TestParameters tParam
, PrintWriter log
) {
62 // get a soffice factory object
63 SOfficeFactory SOF
= SOfficeFactory
.getFactory( 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.
79 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
80 log
.println( " disposing xSheetDoc " );
81 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
);
82 util
.DesktopTools
.closeDoc(oComp
);
86 * Creating a Testenvironment for the interfaces to be tested.
87 * Retrieves a collection of spreadsheets from a document,
88 * and takes one of them. Then retrieves a collection of format cell
89 * range using the interface <code>XCellFormatRangesSupplier</code> that is
90 * instance of service <code>com.sun.star.sheet.CellFormatRanges</code>.
91 * @see com.sun.star.sheet.CellFormatRanges
92 * @see com.sun.star.sheet.XCellFormatRangesSupplier
95 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
97 XInterface oObj
= null;
99 log
.println("getting sheets");
100 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets();
102 log
.println("getting a sheet");
103 XSpreadsheet oSheet
= null;
104 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
106 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
107 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
108 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
109 e
.printStackTrace(log
);
110 throw new StatusException( "Couldn't get a spreadsheet", e
);
111 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
112 e
.printStackTrace(log
);
113 throw new StatusException( "Couldn't get a spreadsheet", e
);
114 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
115 e
.printStackTrace(log
);
116 throw new StatusException( "Couldn't get a spreadsheet", e
);
119 log
.println("getting CellFormats");
120 XCellFormatRangesSupplier xCFRS
= UnoRuntime
.queryInterface(XCellFormatRangesSupplier
.class, oSheet
);
121 XIndexAccess formats
= xCFRS
.getCellFormatRanges();
125 log
.println("creating a new environment for object");
126 TestEnvironment tEnv
= new TestEnvironment(oObj
);
130 } // finish class ScCellFormatsObj