1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XSheetAuditing.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import com
.sun
.star
.beans
.XPropertySet
;
33 import com
.sun
.star
.drawing
.XDrawPage
;
34 import com
.sun
.star
.drawing
.XDrawPageSupplier
;
35 import com
.sun
.star
.drawing
.XShape
;
36 import com
.sun
.star
.sheet
.ValidationType
;
37 import com
.sun
.star
.sheet
.XSheetAuditing
;
38 import com
.sun
.star
.sheet
.XSpreadsheet
;
39 import com
.sun
.star
.table
.CellAddress
;
40 import com
.sun
.star
.table
.XCell
;
41 import com
.sun
.star
.text
.XText
;
42 import com
.sun
.star
.uno
.UnoRuntime
;
43 import lib
.MultiMethodTest
;
45 import lib
.StatusException
;
50 public class _XSheetAuditing
extends MultiMethodTest
{
51 public XSheetAuditing oObj
= null;
52 CellAddress address
= null;
53 CellAddress precedentAddress
= null;
54 CellAddress dependentAddress
= null;
55 XCell xAddress
= null;
56 XCell xPrecedentAddress
= null;
57 XCell xDependentAddress
= null;
58 XDrawPage xDrawPage
= null;
61 public void before() {
62 address
= (CellAddress
)tEnv
.getObjRelation("XSheetAuditing.CellAddress");
63 precedentAddress
= (CellAddress
)tEnv
.getObjRelation("XSheetAuditing.PrecedentCellAddress");
64 dependentAddress
= (CellAddress
)tEnv
.getObjRelation("XSheetAuditing.DependentCellAddress");
65 if (address
== null || precedentAddress
== null || dependentAddress
== null) {
66 throw new StatusException(Status
.failed("Necessary CellAddress object relations not found."));
69 // get the draw page for checking the shapes
70 xDrawPage
= (XDrawPage
)tEnv
.getObjRelation("XSheetAuditing.DrawPage");
71 if (xDrawPage
== null) { // get from object
72 XDrawPageSupplier oDPS
= (XDrawPageSupplier
)
73 UnoRuntime
.queryInterface(XDrawPageSupplier
.class, oObj
);
74 xDrawPage
= (XDrawPage
) oDPS
.getDrawPage();
76 if (xDrawPage
== null) {
77 throw new StatusException(Status
.failed("'XSheetAuditing.DrawPage' object relation not found."));
79 if (xDrawPage
.hasElements()) {
80 elementCount
= xDrawPage
.getCount();
83 // get a sheet for changing the cells
84 XSpreadsheet xSheet
= (XSpreadsheet
)tEnv
.getObjRelation("XSheetAuditing.Spreadsheet");
85 if (xSheet
== null) // query on ther object
86 xSheet
= (XSpreadsheet
)UnoRuntime
.queryInterface(XSpreadsheet
.class, oObj
);
88 throw new StatusException(Status
.failed("'XSheetAuditing.Spreadsheet' object relation not found."));
90 xAddress
= xSheet
.getCellByPosition(address
.Column
, address
.Row
);
91 xDependentAddress
= xSheet
.getCellByPosition(dependentAddress
.Column
, dependentAddress
.Row
);
92 xPrecedentAddress
= xSheet
.getCellByPosition(precedentAddress
.Column
, precedentAddress
.Row
);
94 catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
95 throw new StatusException(Status
.failed("Invalid cell addresses in object relations."));
99 public void _clearArrows() {
100 requiredMethod("hideDependents()");
102 oObj
.showDependents(address
);
103 oObj
.showPrecedents(address
);
104 erg
= hasRightAmountOfShapes(3);
106 erg
&= hasRightAmountOfShapes(0);
107 tRes
.tested("clearArrows()", erg
);
110 public void _hideDependents() {
111 requiredMethod("showDependents()");
112 oObj
.hideDependents(address
);
113 tRes
.tested("hideDependents()", hasRightAmountOfShapes(0));
116 public void _hidePrecedents() {
117 requiredMethod("showPrecedents()");
118 // requiredMethod("showPrecedents()");
119 oObj
.hidePrecedents(address
);
120 tRes
.tested("hidePrecedents()", hasRightAmountOfShapes(0));
123 public void _showDependents() {
124 requiredMethod("hidePrecedents()");
125 oObj
.showDependents(address
);
126 tRes
.tested("showDependents()", hasRightAmountOfShapes(1));
129 public void _showErrors() {
130 requiredMethod("clearArrows()");
131 // construct an error: square root from -3
132 xPrecedentAddress
.setValue(-9);
133 String cellAddress
= new String(new byte[]{(byte)(precedentAddress
.Column
+ 65)}) + (precedentAddress
.Row
+1);
134 xAddress
.setFormula("=SQRT(" + cellAddress
+ ")");
135 XText xText
= (XText
)UnoRuntime
.queryInterface(XText
.class, xAddress
);
136 // correct error in cell:
137 String error
= xText
.getString();
138 boolean erg
= error
.equals("Err:502");
139 log
.println("Content: " + error
);
140 oObj
.showErrors(dependentAddress
);
141 erg
&= hasRightAmountOfShapes(2);
142 tRes
.tested("showErrors()", erg
);
145 public void _showInvalid() {
146 requiredMethod("showErrors()");
147 boolean result
= true;
149 xAddress
.setValue(2.5);
151 // add a validitation to a cell: only whole numbers are allowed
152 XPropertySet xPropertySet
= (XPropertySet
)UnoRuntime
.queryInterface(XPropertySet
.class, xAddress
);
153 Object o
= xPropertySet
.getPropertyValue("Validation");
154 XPropertySet xValidation
= (XPropertySet
)UnoRuntime
.queryInterface(XPropertySet
.class, o
);
155 xValidation
.setPropertyValue("Type", ValidationType
.WHOLE
);
156 xPropertySet
.setPropertyValue("Validation", xValidation
);
159 result
= hasRightAmountOfShapes(1);
161 result
&= hasRightAmountOfShapes(0);
162 // revoke the validitation to a cell
163 xValidation
.setPropertyValue("Type", ValidationType
.ANY
);
164 xPropertySet
.setPropertyValue("Validation", xValidation
);
167 result
&= hasRightAmountOfShapes(0);
169 catch(com
.sun
.star
.uno
.Exception e
) {
170 e
.printStackTrace((java
.io
.PrintWriter
)log
);
174 tRes
.tested("showInvalid()", result
);
177 public void _showPrecedents() {
178 oObj
.showPrecedents(address
);
179 tRes
.tested("showPrecedents()", hasRightAmountOfShapes(2));
183 * Check if the amount of shapes is the right one after displaying that stuff
184 * 2do improve this: check taht the shapes are the correct ones -> convwatch
185 * @desiredValue That's the amount of shapes that have to be here.
186 * @return True, if the actual count of shapes is the same
188 private boolean hasRightAmountOfShapes(int desiredValue
) {
189 int newCount
= xDrawPage
.getCount();
190 if (newCount
!= elementCount
+ desiredValue
) {
194 if (desiredValue
>= 0) {
195 for (int i
=elementCount
; i
<newCount
; i
++) {
197 Object o
= xDrawPage
.getByIndex(i
);
198 XShape xShape
= (XShape
)UnoRuntime
.queryInterface(XShape
.class, o
);
199 System
.out
.println("Shape Type: " + xShape
.getShapeType());
201 catch(com
.sun
.star
.uno
.Exception e
) {