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
.XEnumerationAccess
;
33 import com
.sun
.star
.container
.XIndexAccess
;
34 import com
.sun
.star
.lang
.XComponent
;
35 import com
.sun
.star
.lang
.XMultiServiceFactory
;
36 import com
.sun
.star
.sheet
.ConditionOperator
;
37 import com
.sun
.star
.sheet
.XSheetConditionalEntries
;
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
;
47 public class ScIndexEnumeration_TableConditionalEntryEnumeration
extends TestCase
{
48 private XSpreadsheetDocument xSpreadsheetDoc
= null;
51 * Creates Spreadsheet document.
53 protected void initialize( TestParameters tParam
, PrintWriter log
) {
54 // get a soffice factory object
55 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
58 log
.println( "creating a sheetdocument" );
59 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
60 } catch (com
.sun
.star
.uno
.Exception e
) {
61 // Some exception occurs.FAILED
62 e
.printStackTrace( log
);
63 throw new StatusException( "Couldn't create document", e
);
68 * Disposes Spreadsheet document.
70 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
71 log
.println( " disposing xSheetDoc " );
72 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
) ;
73 util
.DesktopTools
.closeDoc(oComp
);
76 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
78 XInterface oObj
= null;
79 log
.println("getting sheets");
80 XSpreadsheets xSpreadsheets
= xSpreadsheetDoc
.getSheets();
82 log
.println("getting a sheet");
83 XSpreadsheet oSheet
= null;
84 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
87 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
88 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
89 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
90 e
.printStackTrace(log
);
91 throw new StatusException( "Couldn't get a spreadsheet", e
);
92 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
93 e
.printStackTrace(log
);
94 throw new StatusException( "Couldn't get a spreadsheet", e
);
95 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
96 e
.printStackTrace(log
);
97 throw new StatusException( "Couldn't get a spreadsheet", e
);
100 log
.println("filling some cells");
102 oSheet
.getCellByPosition(5, 5).setValue(15);
103 oSheet
.getCellByPosition(1, 4).setValue(10);
104 oSheet
.getCellByPosition(2, 0).setValue(-5.15);
105 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
106 log
.println("Exception occurred while filling cells");
107 e
.printStackTrace(log
);
110 Object CFormat
= null;
111 XPropertySet Props
= null;
114 Props
= UnoRuntime
.queryInterface(XPropertySet
.class, oSheet
);
115 CFormat
= Props
.getPropertyValue("ConditionalFormat");
116 if (utils
.isVoid(CFormat
)) {
117 log
.println("Property 'ConditionalFormat' is void");
119 } catch (com
.sun
.star
.lang
.WrappedTargetException e
){
120 e
.printStackTrace(log
);
121 throw new StatusException("Couldn't create instance", e
);
122 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
){
123 e
.printStackTrace(log
);
124 throw new StatusException("Couldn't create instance", e
);
128 XSheetConditionalEntries xSCE
= UnoRuntime
.queryInterface(XSheetConditionalEntries
.class, CFormat
);
129 xSCE
.addNew(Conditions());
130 Props
.setPropertyValue("ConditionalFormat", xSCE
);
132 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
133 e
.printStackTrace(log
);
134 throw new StatusException(
135 "Exception occurred while getting Entry", e
);
136 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
137 e
.printStackTrace(log
);
138 throw new StatusException(
139 "Exception occurred while getting Entry", e
);
140 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
141 e
.printStackTrace(log
);
142 throw new StatusException(
143 "Exception occurred while getting Entry", e
);
144 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
145 e
.printStackTrace(log
);
146 throw new StatusException(
147 "Exception occurred while getting Entry", e
);
150 log
.println("creating a new environment for object");
151 XEnumerationAccess ea
= UnoRuntime
.queryInterface(XEnumerationAccess
.class,oObj
);
153 oObj
= ea
.createEnumeration();
155 log
.println("ImplementationName: "+util
.utils
.getImplName(oObj
));
156 // creating test environment
157 TestEnvironment tEnv
= new TestEnvironment( oObj
);
159 tEnv
.addObjRelation("ENUM",ea
);
162 } // finish method getTestEnvironment
165 * Returns the array of the property values that was filled by condition
168 protected PropertyValue
[] Conditions() {
169 PropertyValue
[] con
= new PropertyValue
[5];
170 CellAddress ca
= new CellAddress();
174 con
[0] = new PropertyValue();
175 con
[0].Name
= "StyleName";
176 con
[0].Value
= "Result2";
177 con
[1] = new PropertyValue();
178 con
[1].Name
= "Formula1";
179 con
[1].Value
= "$Sheet1.$B$5";
180 con
[2] = new PropertyValue();
181 con
[2].Name
= "Formula2";
183 con
[3] = new PropertyValue();
184 con
[3].Name
= "Operator";
185 con
[3].Value
= ConditionOperator
.EQUAL
;
186 con
[4] = new PropertyValue();
187 con
[4].Name
= "SourcePosition";
192 } // finish class ScTableConditionalEntry