bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScIndexEnumeration_TableConditionalEntryEnumeration.java
bloba31fd05d52360877d75e0dbe63a6ede5b5c6d083
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.XEnumerationAccess;
33 import com.sun.star.container.XIndexAccess;
34 import com.sun.star.lang.XComponent;
35 import com.sun.star.sheet.ConditionOperator;
36 import com.sun.star.sheet.XSheetConditionalEntries;
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 public class ScIndexEnumeration_TableConditionalEntryEnumeration extends TestCase {
47 private XSpreadsheetDocument xSpreadsheetDoc = null;
49 /**
50 * Creates Spreadsheet document.
52 @Override
53 protected void initialize( TestParameters tParam, PrintWriter log ) {
54 // get a soffice factory object
55 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
57 try {
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 );
67 /**
68 * Disposes Spreadsheet document.
70 @Override
71 protected void cleanup( TestParameters tParam, PrintWriter log ) {
72 log.println( " disposing xSheetDoc " );
73 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ;
74 util.DesktopTools.closeDoc(oComp);
77 @Override
78 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
80 XInterface oObj = null;
81 log.println("getting sheets");
82 XSpreadsheets xSpreadsheets = xSpreadsheetDoc.getSheets();
84 log.println("getting a sheet");
85 XSpreadsheet oSheet = null;
86 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
88 try {
89 oSheet = (XSpreadsheet) AnyConverter.toObject(
90 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
91 } catch (com.sun.star.lang.WrappedTargetException e) {
92 e.printStackTrace(log);
93 throw new StatusException( "Couldn't get a spreadsheet", e);
94 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
95 e.printStackTrace(log);
96 throw new StatusException( "Couldn't get a spreadsheet", e);
97 } catch (com.sun.star.lang.IllegalArgumentException e) {
98 e.printStackTrace(log);
99 throw new StatusException( "Couldn't get a spreadsheet", e);
102 log.println("filling some cells");
103 try {
104 oSheet.getCellByPosition(5, 5).setValue(15);
105 oSheet.getCellByPosition(1, 4).setValue(10);
106 oSheet.getCellByPosition(2, 0).setValue(-5.15);
107 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
108 log.println("Exception occurred while filling cells");
109 e.printStackTrace(log);
112 Object CFormat = null;
113 XPropertySet Props = null;
115 try {
116 Props = UnoRuntime.queryInterface(XPropertySet.class, oSheet);
117 CFormat = Props.getPropertyValue("ConditionalFormat");
118 if (utils.isVoid(CFormat)) {
119 log.println("Property 'ConditionalFormat' is void");
121 } catch (com.sun.star.lang.WrappedTargetException e){
122 e.printStackTrace(log);
123 throw new StatusException("Couldn't create instance", e);
124 } catch (com.sun.star.beans.UnknownPropertyException e){
125 e.printStackTrace(log);
126 throw new StatusException("Couldn't create instance", e);
129 try {
130 XSheetConditionalEntries xSCE = UnoRuntime.queryInterface(XSheetConditionalEntries.class, CFormat);
131 xSCE.addNew(Conditions());
132 Props.setPropertyValue("ConditionalFormat", xSCE);
133 oObj = xSCE;
134 } catch (com.sun.star.lang.WrappedTargetException e) {
135 e.printStackTrace(log);
136 throw new StatusException(
137 "Exception occurred while getting Entry", e);
138 } catch (com.sun.star.lang.IllegalArgumentException e) {
139 e.printStackTrace(log);
140 throw new StatusException(
141 "Exception occurred while getting Entry", e);
142 } catch (com.sun.star.beans.PropertyVetoException e) {
143 e.printStackTrace(log);
144 throw new StatusException(
145 "Exception occurred while getting Entry", e);
146 } catch (com.sun.star.beans.UnknownPropertyException e) {
147 e.printStackTrace(log);
148 throw new StatusException(
149 "Exception occurred while getting Entry", e);
152 log.println("creating a new environment for object");
153 XEnumerationAccess ea = UnoRuntime.queryInterface(XEnumerationAccess.class,oObj);
155 oObj = ea.createEnumeration();
157 log.println("ImplementationName: "+util.utils.getImplName(oObj));
158 // creating test environment
159 TestEnvironment tEnv = new TestEnvironment( oObj );
161 tEnv.addObjRelation("ENUM",ea);
163 return tEnv;
164 } // finish method getTestEnvironment
167 * Returns the array of the property values that was filled by condition
168 * values.
170 protected PropertyValue[] Conditions() {
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$5";
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 ScTableConditionalEntry