bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XGoalSeek.java
blobd19a94cb85e5827f15489d06c723cd44f2b047ac
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 .
18 package ifc.sheet;
20 import com.sun.star.container.XIndexAccess;
21 import com.sun.star.sheet.GoalResult;
22 import com.sun.star.sheet.XGoalSeek;
23 import com.sun.star.sheet.XSpreadsheet;
24 import com.sun.star.sheet.XSpreadsheetDocument;
25 import com.sun.star.sheet.XSpreadsheets;
26 import com.sun.star.table.CellAddress;
27 import com.sun.star.uno.UnoRuntime;
28 import lib.MultiMethodTest;
29 import lib.StatusException;
31 /**
34 public class _XGoalSeek extends MultiMethodTest {
35 public XGoalSeek oObj = null;
36 XSpreadsheet xSheet = null;
37 CellAddress aFormula = null;
38 CellAddress aValue = null;
40 public void before() {
41 Exception ex = null;
42 // get two sheets
43 try {
44 XSpreadsheetDocument xSpreadsheetDocument = UnoRuntime.queryInterface(XSpreadsheetDocument.class, oObj);
45 XSpreadsheets oSheets = xSpreadsheetDocument.getSheets();
46 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(
47 XIndexAccess.class, oSheets);
48 xSheet = UnoRuntime.queryInterface(
49 XSpreadsheet.class, oIndexSheets.getByIndex(1));
51 catch(com.sun.star.lang.IndexOutOfBoundsException e) {
52 ex = e;
54 catch(com.sun.star.lang.WrappedTargetException e) {
55 ex = e;
57 catch(java.lang.NullPointerException e) {
58 ex = e;
60 if (ex != null) {
61 throw new StatusException("Could not get a sheet.", ex);
64 // set value and formula
65 try {
66 xSheet.getCellByPosition(3, 4).setValue(9);
67 xSheet.getCellByPosition(3, 5).setFormula("= SQRT(D5)");
68 aValue = new CellAddress((short)1, 3, 4);
69 aFormula = new CellAddress((short)1, 3, 5);
71 catch(Exception e) {
72 throw new StatusException("Could not get set formulas on the sheet.", e);
76 public void _seekGoal() {
77 boolean result = true;
78 double divergence = 0.01;
79 GoalResult goal = oObj.seekGoal(aFormula, aValue, "4");
80 log.println("Goal Result: " + goal.Result + " Divergence: " + goal.Divergence);
81 result &= goal.Divergence < divergence;
82 result &= goal.Result > 16 - divergence || goal.Result < 16 + divergence;
84 goal = oObj.seekGoal(aFormula, aValue, "-4");
85 log.println("Goal Result: " + goal.Result + " Divergence: " + goal.Divergence);
86 result &= goal.Divergence > 1/divergence;
87 result &= goal.Result < divergence || goal.Result > -divergence;
89 // just curious: let goal seek find a limiting value
90 try {
91 xSheet.getCellByPosition(3, 4).setValue(0.8);
92 xSheet.getCellByPosition(3, 5).setFormula("= (D5 ^ 2 - 1) / (D5 - 1)");
94 catch(Exception e) {}
95 goal = oObj.seekGoal(aFormula, aValue, "2");
96 log.println("Goal Result: " + goal.Result + " Divergence: " + goal.Divergence);
97 result &= goal.Divergence < divergence;
98 result &= goal.Result > 16 - divergence || goal.Result < 16 + divergence;
100 tRes.tested("seekGoal()", result);