bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScTableConditionalFormat.java
blobdce6796864601aea5fc5fec1206476dae5cd2226
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.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.lang.XMultiServiceFactory;
34 import com.sun.star.sheet.ConditionOperator;
35 import com.sun.star.sheet.XSheetConditionalEntries;
36 import com.sun.star.sheet.XSpreadsheet;
37 import com.sun.star.sheet.XSpreadsheetDocument;
38 import com.sun.star.sheet.XSpreadsheets;
39 import com.sun.star.table.CellAddress;
40 import com.sun.star.uno.AnyConverter;
41 import com.sun.star.uno.Type;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
45 /**
46 * Test for object which is represented by service
47 * <code>com.sun.star.sheet.TableConditionalFormat</code>. <p>
48 * Object implements the following interfaces :
49 * <ul>
50 * <li> <code>com::sun::star::container::XNameAccess</code></li>
51 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
52 * <li> <code>com::sun::star::sheet::XSheetConditionalEntries</code></li>
53 * <li> <code>com::sun::star::container::XElementAccess</code></li>
54 * </ul>
55 * @see com.sun.star.sheet.TableConditionalFormat
56 * @see com.sun.star.container.XNameAccess
57 * @see com.sun.star.container.XIndexAccess
58 * @see com.sun.star.sheet.XSheetConditionalEntries
59 * @see com.sun.star.container.XElementAccess
60 * @see ifc.container._XNameAccess
61 * @see ifc.container._XIndexAccess
62 * @see ifc.sheet._XSheetConditionalEntries
63 * @see ifc.container._XElementAccess
65 public class ScTableConditionalFormat extends TestCase {
67 private XSpreadsheetDocument xSpreadsheetDoc = null;
69 /**
70 * Creates Spreadsheet document.
72 protected void initialize( TestParameters tParam, PrintWriter log ) {
73 // get a soffice factory object
74 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
76 try {
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 );
86 /**
87 * Disposes Spreadsheet document.
89 protected void cleanup( TestParameters tParam, PrintWriter log ) {
90 log.println( " disposing xSheetDoc " );
91 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ;
92 util.DesktopTools.closeDoc(oComp);
95 /**
96 * Creating a Testenvironment for the interfaces to be tested.
97 * Retrieves a collection of spreadsheets from the document and takes one of
98 * them. Fills some cells of the spreadsheet. Retrieves value of the property
99 * <code>'ConditionalFormat'</code> that is the collection of the conditions
100 * of a conditional format. Adds new two conditional entries to the
101 * collection using the interface <code>XSheetConditionalEntries</code>.
102 * The retrieved collection is the instance of the service
103 * <code>com.sun.star.sheet.TableConditionalFormat</code>.
104 * @see com.sun.star.sheet.TableConditionalFormat
106 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
108 XInterface oObj = null;
110 log.println("getting sheets");
111 XSpreadsheets xSpreadsheets = xSpreadsheetDoc.getSheets();
113 log.println("getting a sheet");
114 XSpreadsheet oSheet = null;
115 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
116 try {
117 oSheet = (XSpreadsheet) AnyConverter.toObject(
118 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
119 } catch (com.sun.star.lang.WrappedTargetException e) {
120 e.printStackTrace(log);
121 throw new StatusException( "Couldn't get a spreadsheet", e);
122 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
123 e.printStackTrace(log);
124 throw new StatusException( "Couldn't get a spreadsheet", e);
125 } catch (com.sun.star.lang.IllegalArgumentException e) {
126 e.printStackTrace(log);
127 throw new StatusException( "Couldn't get a spreadsheet", e);
130 log.println("filling some cells");
131 try {
132 oSheet.getCellByPosition(5, 5).setValue(15);
133 oSheet.getCellByPosition(1, 4).setValue(10);
134 oSheet.getCellByPosition(2, 0).setValue(-5.15);
135 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
136 log.println("Exception occurred while filling cells");
137 e.printStackTrace(log);
140 XPropertySet Props = UnoRuntime.queryInterface(XPropertySet.class, oSheet);
141 try {
142 oObj = (XInterface) AnyConverter.toObject(
143 new Type(XInterface.class),
144 Props.getPropertyValue("ConditionalFormat"));
145 } catch(com.sun.star.lang.WrappedTargetException e) {
146 e.printStackTrace(log);
147 throw new StatusException("Couldn't get ConditionalFromat", e);
148 } catch(com.sun.star.beans.UnknownPropertyException e) {
149 e.printStackTrace(log);
150 throw new StatusException("Couldn't get ConditionalFromat", e);
151 } catch(com.sun.star.lang.IllegalArgumentException e) {
152 e.printStackTrace(log);
153 throw new StatusException("Couldn't get ConditionalFromat", e);
156 XSheetConditionalEntries xSCE = UnoRuntime.queryInterface(XSheetConditionalEntries.class, oObj);
157 xSCE.addNew(Conditions(5));
158 xSCE.addNew(Conditions(2));
160 log.println("creating a new environment for object");
161 TestEnvironment tEnv = new TestEnvironment(oObj);
163 return tEnv;
164 } // finish method getTestEnvironment
167 * Returns the array of the property values that was filled by condition
168 * values.
170 public PropertyValue[] Conditions(int nr) {
171 PropertyValue[] con = new PropertyValue[5];
172 CellAddress ca = new CellAddress();
173 ca.Column = 1;
174 ca.Row = 5;
175 ca.Sheet = 0;
176 con[0] = new PropertyValue();
177 con[0].Name = "StyleName";
178 con[0].Value = "Result2";
179 con[1] = new PropertyValue();
180 con[1].Name = "Formula1";
181 con[1].Value = "$Sheet1.$B$"+nr;
182 con[2] = new PropertyValue();
183 con[2].Name = "Formula2";
184 con[2].Value = "";
185 con[3] = new PropertyValue();
186 con[3].Name = "Operator";
187 con[3].Value = ConditionOperator.EQUAL;
188 con[4] = new PropertyValue();
189 con[4].Name = "SourcePosition";
190 con[4].Value = ca;
191 return con;
194 } // finish class ScTableConditionalFormat