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
.beans
.PropertyValue
;
30 import com
.sun
.star
.beans
.XPropertySet
;
31 import com
.sun
.star
.container
.XIndexAccess
;
32 import com
.sun
.star
.lang
.XComponent
;
33 import com
.sun
.star
.sheet
.ConditionOperator
;
34 import com
.sun
.star
.sheet
.XSheetConditionalEntries
;
35 import com
.sun
.star
.sheet
.XSpreadsheet
;
36 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
37 import com
.sun
.star
.sheet
.XSpreadsheets
;
38 import com
.sun
.star
.table
.CellAddress
;
39 import com
.sun
.star
.uno
.AnyConverter
;
40 import com
.sun
.star
.uno
.Type
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
45 * Test for object which is represented by service
46 * <code>com.sun.star.sheet.TableConditionalFormat</code>. <p>
47 * Object implements the following interfaces :
49 * <li> <code>com::sun::star::container::XNameAccess</code></li>
50 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
51 * <li> <code>com::sun::star::sheet::XSheetConditionalEntries</code></li>
52 * <li> <code>com::sun::star::container::XElementAccess</code></li>
54 * @see com.sun.star.sheet.TableConditionalFormat
55 * @see com.sun.star.container.XNameAccess
56 * @see com.sun.star.container.XIndexAccess
57 * @see com.sun.star.sheet.XSheetConditionalEntries
58 * @see com.sun.star.container.XElementAccess
59 * @see ifc.container._XNameAccess
60 * @see ifc.container._XIndexAccess
61 * @see ifc.sheet._XSheetConditionalEntries
62 * @see ifc.container._XElementAccess
64 public class ScTableConditionalFormat
extends TestCase
{
66 private XSpreadsheetDocument xSpreadsheetDoc
= null;
69 * Creates Spreadsheet document.
72 protected void initialize( TestParameters tParam
, PrintWriter log
) {
73 // get a soffice factory object
74 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
77 log
.println( "creating a sheetdocument" );
78 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
79 } catch (com
.sun
.star
.uno
.Exception e
) {
80 // Some exception occurs.FAILED
81 e
.printStackTrace( log
);
82 throw new StatusException( "Couldn't create document", e
);
87 * Disposes Spreadsheet document.
90 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
91 log
.println( " disposing xSheetDoc " );
92 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
) ;
93 util
.DesktopTools
.closeDoc(oComp
);
97 * Creating a Testenvironment for the interfaces to be tested.
98 * Retrieves a collection of spreadsheets from the document and takes one of
99 * them. Fills some cells of the spreadsheet. Retrieves value of the property
100 * <code>'ConditionalFormat'</code> that is the collection of the conditions
101 * of a conditional format. Adds new two conditional entries to the
102 * collection using the interface <code>XSheetConditionalEntries</code>.
103 * The retrieved collection is the instance of the service
104 * <code>com.sun.star.sheet.TableConditionalFormat</code>.
105 * @see com.sun.star.sheet.TableConditionalFormat
108 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
110 XInterface oObj
= null;
112 log
.println("getting sheets");
113 XSpreadsheets xSpreadsheets
= xSpreadsheetDoc
.getSheets();
115 log
.println("getting a sheet");
116 XSpreadsheet oSheet
= null;
117 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
119 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
120 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
121 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
122 e
.printStackTrace(log
);
123 throw new StatusException( "Couldn't get a spreadsheet", e
);
124 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
125 e
.printStackTrace(log
);
126 throw new StatusException( "Couldn't get a spreadsheet", e
);
127 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
128 e
.printStackTrace(log
);
129 throw new StatusException( "Couldn't get a spreadsheet", e
);
132 log
.println("filling some cells");
134 oSheet
.getCellByPosition(5, 5).setValue(15);
135 oSheet
.getCellByPosition(1, 4).setValue(10);
136 oSheet
.getCellByPosition(2, 0).setValue(-5.15);
137 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
138 log
.println("Exception occurred while filling cells");
139 e
.printStackTrace(log
);
142 XPropertySet Props
= UnoRuntime
.queryInterface(XPropertySet
.class, oSheet
);
144 oObj
= (XInterface
) AnyConverter
.toObject(
145 new Type(XInterface
.class),
146 Props
.getPropertyValue("ConditionalFormat"));
147 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
148 e
.printStackTrace(log
);
149 throw new StatusException("Couldn't get ConditionalFromat", e
);
150 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
151 e
.printStackTrace(log
);
152 throw new StatusException("Couldn't get ConditionalFromat", e
);
153 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
154 e
.printStackTrace(log
);
155 throw new StatusException("Couldn't get ConditionalFromat", e
);
158 XSheetConditionalEntries xSCE
= UnoRuntime
.queryInterface(XSheetConditionalEntries
.class, oObj
);
159 xSCE
.addNew(Conditions(5));
160 xSCE
.addNew(Conditions(2));
162 log
.println("creating a new environment for object");
163 TestEnvironment tEnv
= new TestEnvironment(oObj
);
166 } // finish method getTestEnvironment
169 * Returns the array of the property values that was filled by condition
172 public PropertyValue
[] Conditions(int nr
) {
173 PropertyValue
[] con
= new PropertyValue
[5];
174 CellAddress ca
= new CellAddress();
178 con
[0] = new PropertyValue();
179 con
[0].Name
= "StyleName";
180 con
[0].Value
= "Result2";
181 con
[1] = new PropertyValue();
182 con
[1].Name
= "Formula1";
183 con
[1].Value
= "$Sheet1.$B$"+nr
;
184 con
[2] = new PropertyValue();
185 con
[2].Name
= "Formula2";
187 con
[3] = new PropertyValue();
188 con
[3].Name
= "Operator";
189 con
[3].Value
= ConditionOperator
.EQUAL
;
190 con
[4] = new PropertyValue();
191 con
[4].Name
= "SourcePosition";
196 } // finish class ScTableConditionalFormat