Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XDocumentAuditing.java
blob084ce09934c7fba8051837e45577cf4f27aafdec
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
27 package ifc.sheet;
29 import com.sun.star.awt.Point;
30 import com.sun.star.beans.PropertyValue;
31 import com.sun.star.container.XIndexAccess;
32 import com.sun.star.container.XNamed;
33 import com.sun.star.drawing.XDrawPage;
34 import com.sun.star.drawing.XDrawPagesSupplier;
35 import com.sun.star.drawing.XShape;
36 import com.sun.star.frame.XDispatchHelper;
37 import com.sun.star.frame.XDispatchProvider;
38 import com.sun.star.frame.XModel;
39 import com.sun.star.lang.XMultiServiceFactory;
40 import com.sun.star.sheet.XDocumentAuditing;
41 import com.sun.star.sheet.XSheetAuditing;
42 import com.sun.star.sheet.XSpreadsheet;
43 import com.sun.star.sheet.XSpreadsheetDocument;
44 import com.sun.star.sheet.XSpreadsheets;
45 import com.sun.star.table.CellAddress;
46 import com.sun.star.uno.UnoRuntime;
47 import lib.MultiMethodTest;
48 import lib.Status;
49 import lib.StatusException;
51 /**
54 public class _XDocumentAuditing extends MultiMethodTest {
55 public XDocumentAuditing oObj = null;
56 XDrawPage xDrawPage = null;
57 XSpreadsheet[] xSheet = null;
58 int elementCount = 0;
59 String sheetName = null;
60 Point pos = null;
62 public void before() {
63 Exception ex = null;
64 // get two sheets
65 xSheet = new XSpreadsheet[2];
66 try {
67 XSpreadsheetDocument xSpreadsheetDocument = (XSpreadsheetDocument)
68 UnoRuntime.queryInterface(XSpreadsheetDocument.class, oObj);
69 XSpreadsheets oSheets = xSpreadsheetDocument.getSheets();
70 XIndexAccess oIndexSheets = (XIndexAccess) UnoRuntime.queryInterface(
71 XIndexAccess.class, oSheets);
72 XSpreadsheet oSheet = (XSpreadsheet) UnoRuntime.queryInterface(
73 XSpreadsheet.class, oIndexSheets.getByIndex(0));
74 xSheet[0] = oSheet;
75 oSheet = (XSpreadsheet) UnoRuntime.queryInterface(
76 XSpreadsheet.class, oIndexSheets.getByIndex(1));
77 xSheet[1] = oSheet;
79 catch(com.sun.star.lang.IndexOutOfBoundsException e) {
80 ex = e;
82 catch(com.sun.star.lang.WrappedTargetException e) {
83 ex = e;
85 catch(java.lang.NullPointerException e) {
86 ex = e;
88 if (ex != null) {
89 throw new StatusException("Could not get two sheets.", ex);
92 // get the draw page for checking the shapes
93 xDrawPage = (XDrawPage)tEnv.getObjRelation("XDocumentAuditing.DrawPage");
94 if (xDrawPage == null) { // get from object
95 try {
96 XDrawPagesSupplier oDPS = (XDrawPagesSupplier)
97 UnoRuntime.queryInterface(XDrawPagesSupplier.class, oObj);
98 Object o = oDPS.getDrawPages().getByIndex(1);
99 xDrawPage = (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, o);
101 catch(com.sun.star.lang.IndexOutOfBoundsException e) {
102 } // ignore exceptions, we'll run into next if statement anyway
103 catch(com.sun.star.lang.WrappedTargetException e) {
106 if (xDrawPage == null) {
107 throw new StatusException(Status.failed("'XSheetAuditing.DrawPage' object relation not found."));
109 if (xDrawPage.hasElements()) {
110 elementCount = xDrawPage.getCount();
113 // switch off the automatic refresh
114 PropertyValue[] props = new PropertyValue[1];
115 props[0] = new PropertyValue();
116 props[0].Name = "AutoRefreshArrows";
117 props[0].Value = Boolean.FALSE;
118 XModel xModel = (XModel)UnoRuntime.queryInterface(XModel.class, oObj);
119 dispatch(xModel.getCurrentController().getFrame(), (XMultiServiceFactory)tParam.getMSF(), ".uno:AutoRefreshArrows", props);
121 // prepare the sheets
122 try {
123 xSheet[0].getCellByPosition(6, 6).setValue(9);
124 XNamed xNamed = (XNamed)UnoRuntime.queryInterface(XNamed.class, xSheet[0]);
125 sheetName = xNamed.getName();
126 xSheet[1].getCellByPosition(6, 6).setValue(16);
127 xSheet[1].getCellByPosition(6, 7).setFormula("= SQRT(G7)");
128 XSheetAuditing xSheetAuditing = (XSheetAuditing)UnoRuntime.queryInterface(XSheetAuditing.class, xSheet[1]);
129 CellAddress add = new CellAddress((short)1, 6, 7);
130 xSheetAuditing.showPrecedents(add);
131 boolean ok = hasRightAmountOfShapes(1);
132 if (!ok)
133 throw new StatusException(Status.failed("Wrong amount of shapes on page."));
135 catch(com.sun.star.lang.IndexOutOfBoundsException e) {
136 throw new StatusException("Could not set formulas on sheets.", e);
140 public void after() {
141 // switch the automatic refresh back on
142 PropertyValue[] props = new PropertyValue[1];
143 props[0] = new PropertyValue();
144 props[0].Name = "AutoRefreshArrows";
145 props[0].Value = Boolean.TRUE;
146 XModel xModel = (XModel)UnoRuntime.queryInterface(XModel.class, oObj);
147 dispatch(xModel.getCurrentController().getFrame(), (XMultiServiceFactory)tParam.getMSF(), ".uno:AutoRefreshArrows", props);
150 public void _refreshArrows() {
151 boolean result = true;
153 Point p0 = pos;
155 try {
156 result &= xSheet[1].getCellByPosition(6, 7).getValue() == 4;
157 xSheet[1].getCellByPosition(6, 7).setFormula("= SQRT(" + sheetName + ".G7)");
158 result &= xSheet[1].getCellByPosition(6, 7).getValue() == 3;
160 catch(com.sun.star.lang.IndexOutOfBoundsException e) {
161 throw new StatusException("Could not set formulas on sheets.", e);
164 result &= hasRightAmountOfShapes(1);
165 Point p1 = pos;
167 // points have to be the same: if not we have an auto update
168 boolean res = (p0.X == p1.X && p0.Y == p1.Y);
169 result &= res;
170 if (!res)
171 log.println("Arrow has been refreshed, but this should have been switched off.");
173 oObj.refreshArrows();
175 result &= hasRightAmountOfShapes(1);
176 Point p2 = pos;
178 // points have to differ
179 res = (p1.X != p2.X || p1.Y != p2.Y);
180 result &= res;
181 if (!res)
182 log.println("Arrow has not been refreshed.");
184 tRes.tested("refreshArrows()", result);
188 * Check if the amount of shapes is the right one after displaying that stuff
189 * 2do improve this: check taht the shapes are the correct ones -> convwatch
190 * @desiredValue That's the amount of shapes that have to be here.
191 * @return True, if the actual count of shapes is the same
193 private boolean hasRightAmountOfShapes(int desiredValue) {
194 int newCount = xDrawPage.getCount();
195 if (newCount != elementCount + desiredValue) {
196 return false;
198 else {
199 if (desiredValue >= 0) {
200 for (int i=elementCount; i<newCount; i++) {
201 try {
202 Object o = xDrawPage.getByIndex(i);
203 XShape xShape = (XShape)UnoRuntime.queryInterface(XShape.class, o);
204 pos = xShape.getPosition();
205 System.out.println("Shape Type: " + xShape.getShapeType());
207 catch(com.sun.star.uno.Exception e) {
208 e.printStackTrace();
213 return true;
216 private void dispatch(Object oProvider, XMultiServiceFactory xMSF, String url, PropertyValue[] prop) {
217 XDispatchProvider xDispatchProvider = (XDispatchProvider)UnoRuntime.queryInterface(XDispatchProvider.class, oProvider);
218 Object dispatcher = null;
219 try {
220 dispatcher = xMSF.createInstance("com.sun.star.frame.DispatchHelper");
222 catch(com.sun.star.uno.Exception e) {
225 XDispatchHelper xDispatchHelper = (XDispatchHelper)UnoRuntime.queryInterface(XDispatchHelper.class, dispatcher);
226 xDispatchHelper.executeDispatch(xDispatchProvider, url, "", 0, prop);