1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package ifc.sheet;
28 
29 import com.sun.star.sheet.XCalculatable;
30 import com.sun.star.table.XCell;
31 import lib.MultiMethodTest;
32 import lib.Status;
33 import lib.StatusException;
34 
35 /**
36  *
37  */
38 public class _XCalculatable extends MultiMethodTest {
39     public XCalculatable oObj = null;
40     private boolean bIsAutomaticCalculationEnabled = false;
41     private XCell[] xCells = null;
42 
43     /**
44      * Get object relation: four cells with values and formulas.
45      * @see mod._sc.ScModelObj
46      */
47     public void before() {
48         xCells = (XCell[])tEnv.getObjRelation("XCalculatable.Cells");
49         if (xCells == null || xCells.length != 3)
50             throw new StatusException(Status.failed("Couldn't find correct object relation 'XCalculatable.Cells'"));
51 
52     }
53 
54     /**
55      * Restore begin setting
56      */
57     public void after() {
58         // reset to begin value
59         oObj.enableAutomaticCalculation(bIsAutomaticCalculationEnabled);
60     }
61 
62 
63     public void _calculate() {
64         requiredMethod("isAutomaticCalculationEnabled()");
65         boolean result = true;
66         double ergValue1 = xCells[2].getValue();
67         double sourceValue1 = xCells[0].getValue();
68         xCells[0].setValue(sourceValue1 +1);
69         double ergValue2 = xCells[2].getValue();
70         result &= ergValue1 == ergValue2;
71         oObj.calculate();
72         ergValue2 = xCells[2].getValue();
73         result &= ergValue1 != ergValue2;
74         tRes.tested("calculate()", result);
75     }
76 
77     public void _calculateAll() {
78         requiredMethod("isAutomaticCalculationEnabled()");
79         boolean result = true;
80         double ergValue1 = xCells[2].getValue();
81         double sourceValue1 = xCells[0].getValue();
82         xCells[0].setValue(sourceValue1 +1);
83         double ergValue2 = xCells[2].getValue();
84         result &= ergValue1 == ergValue2;
85         oObj.calculateAll();
86         ergValue2 = xCells[2].getValue();
87         result &= ergValue1 != ergValue2;
88         oObj.calculateAll();
89         tRes.tested("calculateAll()", result);
90     }
91 
92     public void _enableAutomaticCalculation() {
93         bIsAutomaticCalculationEnabled = oObj.isAutomaticCalculationEnabled();
94         oObj.enableAutomaticCalculation(!bIsAutomaticCalculationEnabled);
95         tRes.tested("enableAutomaticCalculation()", true);
96     }
97 
98     public void _isAutomaticCalculationEnabled() {
99         requiredMethod("enableAutomaticCalculation()");
100         boolean result = oObj.isAutomaticCalculationEnabled();
101         oObj.enableAutomaticCalculation(false);
102         tRes.tested("isAutomaticCalculationEnabled()", result != bIsAutomaticCalculationEnabled);
103     }
104 
105 }
106