bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScCellFormatsEnumeration.java
blob36e79f78120b1600f7d34d9c8a1425c331ed29cc
1 /*
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 .
19 package mod._sc;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
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.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;
41 /**
42 * Test for object which is represented by service
43 * <code>com.sun.star.sheet.CellFormatRangesEnumeration</code>. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 * <li> <code>com::sun::star::container::XEnumeration</code></li>
47 * </ul>
48 * @see com.sun.star.sheet.CellFormatRangesEnumeration
49 * @see com.sun.star.container.XEnumeration
50 * @see ifc.container._XEnumeration
52 public class ScCellFormatsEnumeration extends TestCase {
53 private XSpreadsheetDocument xSheetDoc = null;
55 /**
56 * Creates Spreadsheet document.
58 @Override
59 protected void initialize( TestParameters tParam, PrintWriter log ) {
60 // get a soffice factory object
61 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
63 try {
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);
73 /**
74 * Disposes Spreadsheet document.
76 @Override
77 protected void cleanup( TestParameters tParam, PrintWriter log ) {
78 log.println( " disposing xSheetDoc " );
79 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
80 util.DesktopTools.closeDoc(oComp);
83 /**
84 * Creating a Testenvironment for the interfaces to be tested.
85 * Retrieves a collection of spreadsheets from a document,
86 * and takes one of them. Then retrieves a collection of cell format range
87 * using the interface <code>XCellFormatRangesSupplier</code>, creates the
88 * enumeration of this collection using interface <code>XEnumerationAccess</code>.
89 * This enumeration is the instance of the service
90 * <code>com.sun.star.sheet.CellFormatRangesEnumeration</code>.
91 * Object relations created :
92 * <ul>
93 * <li> <code>'ENUM'</code> for
94 * {@link ifc.container._XEnumeration} (type of
95 * <code>XEnumerationAccess</code> that was queried from the collection
96 * of cell format range)</li>
97 * </ul>
98 * @see com.sun.star.sheet.CellFormatRangesEnumeration
99 * @see com.sun.star.sheet.XCellFormatRangesSupplier
100 * @see com.sun.star.container.XEnumerationAccess
102 @Override
103 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
105 XInterface oObj = null;
107 log.println("getting sheets");
108 XSpreadsheets xSpreadsheets = xSheetDoc.getSheets();
110 log.println("getting a sheet");
111 XSpreadsheet oSheet = null;
112 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
114 try {
115 oSheet = (XSpreadsheet) AnyConverter.toObject(
116 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
117 } catch (com.sun.star.lang.WrappedTargetException e) {
118 e.printStackTrace(log);
119 throw new StatusException( "Couldn't get a spreadsheet", e);
120 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
121 e.printStackTrace(log);
122 throw new StatusException( "Couldn't get a spreadsheet", e);
123 } catch (com.sun.star.lang.IllegalArgumentException e) {
124 e.printStackTrace(log);
125 throw new StatusException( "Couldn't get a spreadsheet", e);
128 log.println("getting CellFormats");
130 XCellFormatRangesSupplier xCFRS = UnoRuntime.queryInterface(XCellFormatRangesSupplier.class,oSheet);
131 XIndexAccess formats = xCFRS.getCellFormatRanges();
133 log.println("getting Enumeration");
134 XEnumerationAccess oEnum = UnoRuntime.queryInterface(XEnumerationAccess.class,formats);
135 oObj = oEnum.createEnumeration();
137 log.println("creating a new environment for object");
138 TestEnvironment tEnv = new TestEnvironment(oObj);
140 tEnv.addObjRelation("ENUM", oEnum);
142 return tEnv;
145 } // finish class ScCellFormatsEnumeration