bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScTableConditionalEntry.java
blobe2235f5cc33164a471e4688e20e78c832da4f1a2
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;
28 import util.utils;
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.sheet.ConditionOperator;
35 import com.sun.star.sheet.XSheetConditionalEntries;
36 import com.sun.star.sheet.XSheetConditionalEntry;
37 import com.sun.star.sheet.XSpreadsheet;
38 import com.sun.star.sheet.XSpreadsheetDocument;
39 import com.sun.star.sheet.XSpreadsheets;
40 import com.sun.star.table.CellAddress;
41 import com.sun.star.uno.AnyConverter;
42 import com.sun.star.uno.Type;
43 import com.sun.star.uno.UnoRuntime;
44 import com.sun.star.uno.XInterface;
46 /**
47 * Test for object which is represented by service
48 * <code>com.sun.star.sheet.TableConditionalEntry</code>. <p>
49 * Object implements the following interfaces :
50 * <ul>
51 * <li> <code>com::sun::star::sheet::XSheetConditionalEntry</code></li>
52 * <li> <code>com::sun::star::sheet::XSheetCondition</code></li>
53 * </ul>
54 * @see com.sun.star.sheet.TableConditionalEntry
55 * @see com.sun.star.sheet.XSheetConditionalEntry
56 * @see com.sun.star.sheet.XSheetCondition
57 * @see ifc.sheet._XSheetConditionalEntry
58 * @see ifc.sheet._XSheetCondition
60 public class ScTableConditionalEntry extends TestCase {
61 private XSpreadsheetDocument xSpreadsheetDoc = null;
63 /**
64 * Creates Spreadsheet document.
66 @Override
67 protected void initialize( TestParameters tParam, PrintWriter log ) {
68 // get a soffice factory object
69 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
71 try {
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 );
81 /**
82 * Disposes Spreadsheet document.
84 @Override
85 protected void cleanup( TestParameters tParam, PrintWriter log ) {
86 log.println( " disposing xSheetDoc " );
87 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ;
88 util.DesktopTools.closeDoc(oComp);
91 /**
92 * Creating a Testenvironment for the interfaces to be tested.
93 * Retrieves a collection of spreadsheets from the document and takes one of
94 * them. Fills some cells of the spreadsheet. Retrieves value of the property
95 * <code>'ConditionalFormat'</code> that is the collection of the conditions
96 * of a conditional format. Adds new conditional entry to the collection
97 * using the interface <code>XSheetConditionalEntries</code>. Sets new value
98 * of the property <code>'ConditionalFormat'</code>. Obtains the conditional
99 * entry with index 0 that is the instance of the service
100 * <code>com.sun.star.sheet.TableConditionalEntry</code>.
101 * @see com.sun.star.sheet.XSheetConditionalEntries
102 * @see com.sun.star.sheet.TableConditionalEntry
104 @Override
105 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
107 XInterface oObj = null;
108 log.println("getting sheets");
109 XSpreadsheets xSpreadsheets = xSpreadsheetDoc.getSheets();
111 log.println("getting a sheet");
112 XSpreadsheet oSheet = null;
113 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
115 try {
116 oSheet = (XSpreadsheet) AnyConverter.toObject(
117 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
118 } catch (com.sun.star.lang.WrappedTargetException e) {
119 e.printStackTrace(log);
120 throw new StatusException( "Couldn't get a spreadsheet", e);
121 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
122 e.printStackTrace(log);
123 throw new StatusException( "Couldn't get a spreadsheet", e);
124 } catch (com.sun.star.lang.IllegalArgumentException e) {
125 e.printStackTrace(log);
126 throw new StatusException( "Couldn't get a spreadsheet", e);
129 log.println("filling some cells");
130 try {
131 oSheet.getCellByPosition(5, 5).setValue(15);
132 oSheet.getCellByPosition(1, 4).setValue(10);
133 oSheet.getCellByPosition(2, 0).setValue(-5.15);
134 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
135 log.println("Exception occurred while filling cells");
136 e.printStackTrace(log);
139 Object CFormat = null;
140 XPropertySet Props = null;
142 try {
143 Props = UnoRuntime.queryInterface(XPropertySet.class, oSheet);
144 CFormat = Props.getPropertyValue("ConditionalFormat");
145 if (utils.isVoid(CFormat)) {
146 log.println("Property 'ConditionalFormat' is void");
148 } catch (com.sun.star.lang.WrappedTargetException e){
149 e.printStackTrace(log);
150 throw new StatusException("Couldn't create instance", e);
151 } catch (com.sun.star.beans.UnknownPropertyException e){
152 e.printStackTrace(log);
153 throw new StatusException("Couldn't create instance", e);
156 try {
157 XSheetConditionalEntries xSCE = UnoRuntime.queryInterface(XSheetConditionalEntries.class, CFormat);
158 xSCE.addNew(Conditions());
159 Props.setPropertyValue("ConditionalFormat", xSCE);
160 oObj = (XSheetConditionalEntry) AnyConverter.toObject(
161 new Type(XSheetConditionalEntry.class),xSCE.getByIndex(0));
162 } catch (com.sun.star.lang.WrappedTargetException e) {
163 e.printStackTrace(log);
164 throw new StatusException(
165 "Exception occurred while getting Entry", e);
166 } catch (com.sun.star.lang.IllegalArgumentException e) {
167 e.printStackTrace(log);
168 throw new StatusException(
169 "Exception occurred while getting Entry", e);
170 } catch (com.sun.star.beans.PropertyVetoException e) {
171 e.printStackTrace(log);
172 throw new StatusException(
173 "Exception occurred while getting Entry", e);
174 } catch (com.sun.star.beans.UnknownPropertyException e) {
175 e.printStackTrace(log);
176 throw new StatusException(
177 "Exception occurred while getting Entry", e);
178 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
179 e.printStackTrace(log);
180 throw new StatusException(
181 "Exception occurred while getting Entry", e);
184 log.println("creating a new environment for object");
185 TestEnvironment tEnv = new TestEnvironment(oObj);
187 return tEnv;
188 } // finish method getTestEnvironment
191 * Returns the array of the property values that was filled by condition
192 * values.
194 protected PropertyValue[] Conditions() {
195 PropertyValue[] con = new PropertyValue[5];
196 CellAddress ca = new CellAddress();
197 ca.Column = 1;
198 ca.Row = 5;
199 ca.Sheet = 0;
200 con[0] = new PropertyValue();
201 con[0].Name = "StyleName";
202 con[0].Value = "Result2";
203 con[1] = new PropertyValue();
204 con[1].Name = "Formula1";
205 con[1].Value = "$Sheet1.$B$5";
206 con[2] = new PropertyValue();
207 con[2].Name = "Formula2";
208 con[2].Value = "";
209 con[3] = new PropertyValue();
210 con[3].Name = "Operator";
211 con[3].Value = ConditionOperator.EQUAL;
212 con[4] = new PropertyValue();
213 con[4].Name = "SourcePosition";
214 con[4].Value = ca;
215 return con;
218 } // finish class ScTableConditionalEntry