1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package ifc.sheet;
24 
25 import com.sun.star.sheet.XCalculatable;
26 import com.sun.star.table.XCell;
27 import lib.MultiMethodTest;
28 import lib.Status;
29 import lib.StatusException;
30 
31 /**
32  *
33  */
34 public class _XCalculatable extends MultiMethodTest {
35     public XCalculatable oObj = null;
36     private boolean bIsAutomaticCalculationEnabled = false;
37     private XCell[] xCells = null;
38 
39     /**
40      * Get object relation: four cells with values and formulas.
41      * @see mod._sc.ScModelObj
42      */
before()43     public void before() {
44         xCells = (XCell[])tEnv.getObjRelation("XCalculatable.Cells");
45         if (xCells == null || xCells.length != 3)
46             throw new StatusException(Status.failed("Couldn't find correct object relation 'XCalculatable.Cells'"));
47 
48     }
49 
50     /**
51      * Restore begin setting
52      */
after()53     public void after() {
54         // reset to begin value
55         oObj.enableAutomaticCalculation(bIsAutomaticCalculationEnabled);
56     }
57 
58 
_calculate()59     public void _calculate() {
60         requiredMethod("isAutomaticCalculationEnabled()");
61         boolean result = true;
62         double ergValue1 = xCells[2].getValue();
63         double sourceValue1 = xCells[0].getValue();
64         xCells[0].setValue(sourceValue1 +1);
65         double ergValue2 = xCells[2].getValue();
66         result &= ergValue1 == ergValue2;
67         oObj.calculate();
68         ergValue2 = xCells[2].getValue();
69         result &= ergValue1 != ergValue2;
70         tRes.tested("calculate()", result);
71     }
72 
_calculateAll()73     public void _calculateAll() {
74         requiredMethod("isAutomaticCalculationEnabled()");
75         boolean result = true;
76         double ergValue1 = xCells[2].getValue();
77         double sourceValue1 = xCells[0].getValue();
78         xCells[0].setValue(sourceValue1 +1);
79         double ergValue2 = xCells[2].getValue();
80         result &= ergValue1 == ergValue2;
81         oObj.calculateAll();
82         ergValue2 = xCells[2].getValue();
83         result &= ergValue1 != ergValue2;
84         oObj.calculateAll();
85         tRes.tested("calculateAll()", result);
86     }
87 
_enableAutomaticCalculation()88     public void _enableAutomaticCalculation() {
89         bIsAutomaticCalculationEnabled = oObj.isAutomaticCalculationEnabled();
90         oObj.enableAutomaticCalculation(!bIsAutomaticCalculationEnabled);
91         tRes.tested("enableAutomaticCalculation()", true);
92     }
93 
_isAutomaticCalculationEnabled()94     public void _isAutomaticCalculationEnabled() {
95         requiredMethod("enableAutomaticCalculation()");
96         boolean result = oObj.isAutomaticCalculationEnabled();
97         oObj.enableAutomaticCalculation(false);
98         tRes.tested("isAutomaticCalculationEnabled()", result != bIsAutomaticCalculationEnabled);
99     }
100 
101 }
102