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
.XEnumerationAccess
;
30 import com
.sun
.star
.container
.XIndexAccess
;
31 import com
.sun
.star
.lang
.XComponent
;
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
33 import com
.sun
.star
.sheet
.XCellFormatRangesSupplier
;
34 import com
.sun
.star
.sheet
.XSpreadsheet
;
35 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
36 import com
.sun
.star
.sheet
.XSpreadsheets
;
37 import com
.sun
.star
.uno
.AnyConverter
;
38 import com
.sun
.star
.uno
.Type
;
39 import com
.sun
.star
.uno
.UnoRuntime
;
40 import com
.sun
.star
.uno
.XInterface
;
43 * Test for object which is represented by service
44 * <code>com.sun.star.sheet.CellFormatRangesEnumeration</code>. <p>
45 * Object implements the following interfaces :
47 * <li> <code>com::sun::star::container::XEnumeration</code></li>
49 * @see com.sun.star.sheet.CellFormatRangesEnumeration
50 * @see com.sun.star.container.XEnumeration
51 * @see ifc.container._XEnumeration
53 public class ScCellFormatsEnumeration
extends TestCase
{
54 private XSpreadsheetDocument xSheetDoc
= null;
57 * Creates Spreadsheet document.
59 protected void initialize( TestParameters tParam
, PrintWriter log
) {
60 // get a soffice factory object
61 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
64 log
.println( "creating a sheetdocument" );
65 xSheetDoc
= SOF
.createCalcDoc(null);
66 } catch (com
.sun
.star
.uno
.Exception e
) {
67 // Some exception occurs.FAILED
68 e
.printStackTrace( log
);
69 throw new StatusException( "Couldn't create document", e
);
74 * Disposes Spreadsheet document.
76 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
77 log
.println( " disposing xSheetDoc " );
78 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
);
79 util
.DesktopTools
.closeDoc(oComp
);
83 * Creating a Testenvironment for the interfaces to be tested.
84 * Retrieves a collection of spreadsheets from a document,
85 * and takes one of them. Then retrieves a collection of cell format range
86 * using the interface <code>XCellFormatRangesSupplier</code>, creates the
87 * enumeration of this collection using interface <code>XEnumerationAccess</code>.
88 * This enumeration is the instance of the service
89 * <code>com.sun.star.sheet.CellFormatRangesEnumeration</code>.
90 * Object relations created :
92 * <li> <code>'ENUM'</code> for
93 * {@link ifc.container._XEnumeration} (type of
94 * <code>XEnumerationAccess</code> that was queried from the collection
95 * of cell format range)</li>
97 * @see com.sun.star.sheet.CellFormatRangesEnumeration
98 * @see com.sun.star.sheet.XCellFormatRangesSupplier
99 * @see com.sun.star.container.XEnumerationAccess
101 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
103 XInterface oObj
= null;
105 log
.println("getting sheets");
106 XSpreadsheets xSpreadsheets
= xSheetDoc
.getSheets();
108 log
.println("getting a sheet");
109 XSpreadsheet oSheet
= null;
110 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
113 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
114 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
115 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
116 e
.printStackTrace(log
);
117 throw new StatusException( "Couldn't get a spreadsheet", e
);
118 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
119 e
.printStackTrace(log
);
120 throw new StatusException( "Couldn't get a spreadsheet", e
);
121 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
122 e
.printStackTrace(log
);
123 throw new StatusException( "Couldn't get a spreadsheet", e
);
126 log
.println("getting CellFormats");
128 XCellFormatRangesSupplier xCFRS
= UnoRuntime
.queryInterface(XCellFormatRangesSupplier
.class,oSheet
);
129 XIndexAccess formats
= xCFRS
.getCellFormatRanges();
131 log
.println("getting Enumeration");
132 XEnumerationAccess oEnum
= UnoRuntime
.queryInterface(XEnumerationAccess
.class,formats
);
133 oObj
= oEnum
.createEnumeration();
135 log
.println("creating a new environment for object");
136 TestEnvironment tEnv
= new TestEnvironment(oObj
);
138 tEnv
.addObjRelation("ENUM", oEnum
);
143 } // finish class ScCellFormatsEnumeration