1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScTableConditionalFormat.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.beans
.PropertyValue
;
42 import com
.sun
.star
.beans
.XPropertySet
;
43 import com
.sun
.star
.container
.XIndexAccess
;
44 import com
.sun
.star
.lang
.XComponent
;
45 import com
.sun
.star
.lang
.XMultiServiceFactory
;
46 import com
.sun
.star
.sheet
.ConditionOperator
;
47 import com
.sun
.star
.sheet
.XSheetConditionalEntries
;
48 import com
.sun
.star
.sheet
.XSpreadsheet
;
49 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
50 import com
.sun
.star
.sheet
.XSpreadsheets
;
51 import com
.sun
.star
.table
.CellAddress
;
52 import com
.sun
.star
.uno
.AnyConverter
;
53 import com
.sun
.star
.uno
.Type
;
54 import com
.sun
.star
.uno
.UnoRuntime
;
55 import com
.sun
.star
.uno
.XInterface
;
58 * Test for object which is represented by service
59 * <code>com.sun.star.sheet.TableConditionalFormat</code>. <p>
60 * Object implements the following interfaces :
62 * <li> <code>com::sun::star::container::XNameAccess</code></li>
63 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
64 * <li> <code>com::sun::star::sheet::XSheetConditionalEntries</code></li>
65 * <li> <code>com::sun::star::container::XElementAccess</code></li>
67 * @see com.sun.star.sheet.TableConditionalFormat
68 * @see com.sun.star.container.XNameAccess
69 * @see com.sun.star.container.XIndexAccess
70 * @see com.sun.star.sheet.XSheetConditionalEntries
71 * @see com.sun.star.container.XElementAccess
72 * @see ifc.container._XNameAccess
73 * @see ifc.container._XIndexAccess
74 * @see ifc.sheet._XSheetConditionalEntries
75 * @see ifc.container._XElementAccess
77 public class ScTableConditionalFormat
extends TestCase
{
79 static XSpreadsheetDocument xSpreadsheetDoc
= null;
82 * Creates Spreadsheet document.
84 protected void initialize( TestParameters tParam
, PrintWriter log
) {
85 // get a soffice factory object
86 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
89 log
.println( "creating a sheetdocument" );
90 xSpreadsheetDoc
= SOF
.createCalcDoc(null);;
91 } catch (com
.sun
.star
.uno
.Exception e
) {
92 // Some exception occures.FAILED
93 e
.printStackTrace( log
);
94 throw new StatusException( "Couldn't create document", e
);
99 * Disposes Spreadsheet document.
101 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
102 log
.println( " disposing xSheetDoc " );
103 XComponent oComp
= (XComponent
)
104 UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
) ;
105 util
.DesktopTools
.closeDoc(oComp
);
109 * Creating a Testenvironment for the interfaces to be tested.
110 * Retrieves a collection of spreadsheets from the document and takes one of
111 * them. Fills some cells of the spreadsheet. Retrieves value of the property
112 * <code>'ConditionalFormat'</code> that is the collection of the conditions
113 * of a conditional format. Adds new two conditional entries to the
114 * collection using the interface <code>XSheetConditionalEntries</code>.
115 * The retrieved collection is the instance of the service
116 * <code>com.sun.star.sheet.TableConditionalFormat</code>.
117 * @see com.sun.star.sheet.TableConditionalFormat
119 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
121 XInterface oObj
= null;
123 log
.println("getting sheets");
124 XSpreadsheets xSpreadsheets
= (XSpreadsheets
)xSpreadsheetDoc
.getSheets();
126 log
.println("getting a sheet");
127 XSpreadsheet oSheet
= null;
128 XIndexAccess oIndexAccess
= (XIndexAccess
)
129 UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
131 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
132 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
133 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
134 e
.printStackTrace(log
);
135 throw new StatusException( "Couldn't get a spreadsheet", e
);
136 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
137 e
.printStackTrace(log
);
138 throw new StatusException( "Couldn't get a spreadsheet", e
);
139 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
140 e
.printStackTrace(log
);
141 throw new StatusException( "Couldn't get a spreadsheet", e
);
144 log
.println("filling some cells");
146 oSheet
.getCellByPosition(5, 5).setValue(15);
147 oSheet
.getCellByPosition(1, 4).setValue(10);
148 oSheet
.getCellByPosition(2, 0).setValue(-5.15);
149 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
150 log
.println("Exception occurred while filling cells");
151 e
.printStackTrace(log
);
154 XPropertySet Props
= (XPropertySet
)
155 UnoRuntime
.queryInterface(XPropertySet
.class, oSheet
);
157 oObj
= (XInterface
) AnyConverter
.toObject(
158 new Type(XInterface
.class),
159 Props
.getPropertyValue("ConditionalFormat"));
160 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
161 e
.printStackTrace(log
);
162 throw new StatusException("Couldn't get ConditionalFromat", e
);
163 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
164 e
.printStackTrace(log
);
165 throw new StatusException("Couldn't get ConditionalFromat", e
);
166 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
167 e
.printStackTrace(log
);
168 throw new StatusException("Couldn't get ConditionalFromat", e
);
171 XSheetConditionalEntries xSCE
= (XSheetConditionalEntries
)
172 UnoRuntime
.queryInterface(XSheetConditionalEntries
.class, oObj
);
173 xSCE
.addNew(Conditions(5));
174 xSCE
.addNew(Conditions(2));
176 log
.println("creating a new environment for object");
177 TestEnvironment tEnv
= new TestEnvironment(oObj
);
180 } // finish method getTestEnvironment
183 * Returns the array of the property values that was filled by condition
186 public PropertyValue
[] Conditions(int nr
) {
187 PropertyValue
[] con
= new PropertyValue
[5];
188 CellAddress ca
= new CellAddress();
192 con
[0] = new PropertyValue();
193 con
[0].Name
= "StyleName";
194 con
[0].Value
= "Result2";
195 con
[1] = new PropertyValue();
196 con
[1].Name
= "Formula1";
197 con
[1].Value
= "$Sheet1.$B$"+nr
;
198 con
[2] = new PropertyValue();
199 con
[2].Name
= "Formula2";
201 con
[3] = new PropertyValue();
202 con
[3].Name
= "Operator";
203 con
[3].Value
= ConditionOperator
.EQUAL
;
204 con
[4] = new PropertyValue();
205 con
[4].Name
= "SourcePosition";
210 } // finish class ScTableConditionalFormat