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
;
30 import com
.sun
.star
.beans
.PropertyValue
;
31 import com
.sun
.star
.beans
.XPropertySet
;
32 import com
.sun
.star
.container
.XIndexAccess
;
33 import com
.sun
.star
.lang
.XComponent
;
34 import com
.sun
.star
.lang
.XMultiServiceFactory
;
35 import com
.sun
.star
.sheet
.ConditionOperator
;
36 import com
.sun
.star
.sheet
.XSheetConditionalEntries
;
37 import com
.sun
.star
.sheet
.XSheetConditionalEntry
;
38 import com
.sun
.star
.sheet
.XSpreadsheet
;
39 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
40 import com
.sun
.star
.sheet
.XSpreadsheets
;
41 import com
.sun
.star
.table
.CellAddress
;
42 import com
.sun
.star
.uno
.AnyConverter
;
43 import com
.sun
.star
.uno
.Type
;
44 import com
.sun
.star
.uno
.UnoRuntime
;
45 import com
.sun
.star
.uno
.XInterface
;
48 * Test for object which is represented by service
49 * <code>com.sun.star.sheet.TableConditionalEntry</code>. <p>
50 * Object implements the following interfaces :
52 * <li> <code>com::sun::star::sheet::XSheetConditionalEntry</code></li>
53 * <li> <code>com::sun::star::sheet::XSheetCondition</code></li>
55 * @see com.sun.star.sheet.TableConditionalEntry
56 * @see com.sun.star.sheet.XSheetConditionalEntry
57 * @see com.sun.star.sheet.XSheetCondition
58 * @see ifc.sheet._XSheetConditionalEntry
59 * @see ifc.sheet._XSheetCondition
61 public class ScTableConditionalEntry
extends TestCase
{
62 private XSpreadsheetDocument xSpreadsheetDoc
= null;
65 * Creates Spreadsheet document.
67 protected void initialize( TestParameters tParam
, PrintWriter log
) {
68 // get a soffice factory object
69 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
72 log
.println( "creating a sheetdocument" );
73 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
74 } catch (com
.sun
.star
.uno
.Exception e
) {
75 // Some exception occurs.FAILED
76 e
.printStackTrace( log
);
77 throw new StatusException( "Couldn't create document", e
);
82 * Disposes Spreadsheet document.
84 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
85 log
.println( " disposing xSheetDoc " );
86 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
) ;
87 util
.DesktopTools
.closeDoc(oComp
);
91 * Creating a Testenvironment for the interfaces to be tested.
92 * Retrieves a collection of spreadsheets from the document and takes one of
93 * them. Fills some cells of the spreadsheet. Retrieves value of the property
94 * <code>'ConditionalFormat'</code> that is the collection of the conditions
95 * of a conditional format. Adds new conditional entry to the collection
96 * using the interface <code>XSheetConditionalEntries</code>. Sets new value
97 * of the property <code>'ConditionalFormat'</code>. Obtains the conditional
98 * entry with index 0 that is the instance of the service
99 * <code>com.sun.star.sheet.TableConditionalEntry</code>.
100 * @see com.sun.star.sheet.XSheetConditionalEntries
101 * @see com.sun.star.sheet.TableConditionalEntry
103 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
105 XInterface oObj
= null;
106 log
.println("getting sheets");
107 XSpreadsheets xSpreadsheets
= xSpreadsheetDoc
.getSheets();
109 log
.println("getting a sheet");
110 XSpreadsheet oSheet
= null;
111 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
114 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
115 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
116 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
117 e
.printStackTrace(log
);
118 throw new StatusException( "Couldn't get a spreadsheet", e
);
119 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
120 e
.printStackTrace(log
);
121 throw new StatusException( "Couldn't get a spreadsheet", e
);
122 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
123 e
.printStackTrace(log
);
124 throw new StatusException( "Couldn't get a spreadsheet", e
);
127 log
.println("filling some cells");
129 oSheet
.getCellByPosition(5, 5).setValue(15);
130 oSheet
.getCellByPosition(1, 4).setValue(10);
131 oSheet
.getCellByPosition(2, 0).setValue(-5.15);
132 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
133 log
.println("Exception occurred while filling cells");
134 e
.printStackTrace(log
);
137 Object CFormat
= null;
138 XPropertySet Props
= null;
141 Props
= UnoRuntime
.queryInterface(XPropertySet
.class, oSheet
);
142 CFormat
= Props
.getPropertyValue("ConditionalFormat");
143 if (utils
.isVoid(CFormat
)) {
144 log
.println("Property 'ConditionalFormat' is void");
146 } catch (com
.sun
.star
.lang
.WrappedTargetException e
){
147 e
.printStackTrace(log
);
148 throw new StatusException("Couldn't create instance", e
);
149 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
){
150 e
.printStackTrace(log
);
151 throw new StatusException("Couldn't create instance", e
);
155 XSheetConditionalEntries xSCE
= UnoRuntime
.queryInterface(XSheetConditionalEntries
.class, CFormat
);
156 xSCE
.addNew(Conditions());
157 Props
.setPropertyValue("ConditionalFormat", xSCE
);
158 oObj
= (XSheetConditionalEntry
) AnyConverter
.toObject(
159 new Type(XSheetConditionalEntry
.class),xSCE
.getByIndex(0));
160 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
161 e
.printStackTrace(log
);
162 throw new StatusException(
163 "Exception occurred while getting Entry", e
);
164 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
165 e
.printStackTrace(log
);
166 throw new StatusException(
167 "Exception occurred while getting Entry", e
);
168 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
169 e
.printStackTrace(log
);
170 throw new StatusException(
171 "Exception occurred while getting Entry", e
);
172 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
173 e
.printStackTrace(log
);
174 throw new StatusException(
175 "Exception occurred while getting Entry", e
);
176 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
177 e
.printStackTrace(log
);
178 throw new StatusException(
179 "Exception occurred while getting Entry", e
);
182 log
.println("creating a new environment for object");
183 TestEnvironment tEnv
= new TestEnvironment(oObj
);
186 } // finish method getTestEnvironment
189 * Returns the array of the property values that was filled by condition
192 protected PropertyValue
[] Conditions() {
193 PropertyValue
[] con
= new PropertyValue
[5];
194 CellAddress ca
= new CellAddress();
198 con
[0] = new PropertyValue();
199 con
[0].Name
= "StyleName";
200 con
[0].Value
= "Result2";
201 con
[1] = new PropertyValue();
202 con
[1].Name
= "Formula1";
203 con
[1].Value
= "$Sheet1.$B$5";
204 con
[2] = new PropertyValue();
205 con
[2].Name
= "Formula2";
207 con
[3] = new PropertyValue();
208 con
[3].Name
= "Operator";
209 con
[3].Value
= ConditionOperator
.EQUAL
;
210 con
[4] = new PropertyValue();
211 con
[4].Name
= "SourcePosition";
216 } // finish class ScTableConditionalEntry