diff options
Diffstat (limited to 'qadevOOo/tests/java/ifc/sheet')
6 files changed, 1032 insertions, 0 deletions
diff --git a/qadevOOo/tests/java/ifc/sheet/_SpreadsheetDocument.java b/qadevOOo/tests/java/ifc/sheet/_SpreadsheetDocument.java new file mode 100644 index 000000000..513315634 --- /dev/null +++ b/qadevOOo/tests/java/ifc/sheet/_SpreadsheetDocument.java @@ -0,0 +1,41 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.sheet; + +import lib.MultiPropertyTest; + +/** +* Testing <code>com.sun.star.sheet.SpreadsheetDocument</code> +* service properties : +* <ul> +* <li><code> NamedRanges</code></li> +* <li><code> DatabaseRanges</code></li> +* <li><code> ColumnLabelRanges</code></li> +* <li><code> RowLabelRanges</code></li> +* <li><code> SheetLinks</code></li> +* <li><code> AreaLinks</code></li> +* <li><code> DDELinks</code></li> +* </ul> <p> +* Properties testing is automated by <code>lib.MultiPropertyTest</code>. +* @see com.sun.star.sheet.SpreadsheetDocument +*/ +public class _SpreadsheetDocument extends MultiPropertyTest { +} // finish class _SpreadsheetDocument + + diff --git a/qadevOOo/tests/java/ifc/sheet/_TableAutoFormatField.java b/qadevOOo/tests/java/ifc/sheet/_TableAutoFormatField.java new file mode 100644 index 000000000..305d3e219 --- /dev/null +++ b/qadevOOo/tests/java/ifc/sheet/_TableAutoFormatField.java @@ -0,0 +1,124 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.sheet; + +import lib.MultiPropertyTest; + +import com.sun.star.lang.Locale; + +/** +* Testing <code>com.sun.star.sheet.TableAutoFormatField</code> +* service properties : +* <ul> +* <li><code> CharFontName</code></li> +* <li><code> CharHeight</code></li> +* <li><code> CharWeight</code></li> +* <li><code> CharPosture</code></li> +* <li><code> CharUnderline</code></li> +* <li><code> CharCrossedOut</code></li> +* <li><code> CharContoured</code></li> +* <li><code> CharShadowed</code></li> +* <li><code> CharColor</code></li> +* <li><code> CharLocale</code></li> +* <li><code> CellBackColor</code></li> +* <li><code> IsCellBackgroundTransparent</code></li> +* <li><code> ShadowFormat</code></li> +* <li><code> ParaRightMargin </code></li> +* <li><code> ParaLeftMargin </code></li> +* <li><code> ParaBottomMargin </code></li> +* <li><code> ParaTopMargin </code></li> +* <li><code> RotateReference </code></li> +* <li><code> RotateAngle </code></li> +* <li><code> Orientation </code></li> +* <li><code> IsTextWrapped </code></li> +* <li><code> VertJustify </code></li> +* <li><code> HoriJustify </code></li> +* <li><code> CharPostureComplex </code></li> +* <li><code> CharPostureAsian </code></li> +* <li><code> CharWeightComplex </code></li> +* <li><code> CharWeightAsian </code></li> +* <li><code> CharHeightComplex </code></li> +* <li><code> CharHeightAsian </code></li> +* <li><code> CharFontPitchComplex </code></li> +* <li><code> CharFontPitchAsian </code></li> +* <li><code> CharFontPitch </code></li> +* <li><code> CharFontFamilyComplex </code></li> +* <li><code> CharFontFamilyAsian </code></li> +* <li><code> CharFontFamily </code></li> +* <li><code> CharFontCharSetComplex </code></li> +* <li><code> CharFontCharSetAsian </code></li> +* <li><code> CharFontCharSet </code></li> +* <li><code> CharFontStyleNameComplex </code></li> +* <li><code> CharFontStyleNameAsian </code></li> +* <li><code> CharFontStyleName </code></li> +* <li><code> CharFontNameComplex </code></li> +* <li><code> CharFontNameAsian </code></li> +* </ul> <p> +* Properties testing is automated by <code>lib.MultiPropertyTest</code>. +* @see com.sun.star.sheet.TableAutoFormatField +*/ +public class _TableAutoFormatField extends MultiPropertyTest { + + /** + * Only some values can be used (which identify font name). + * In this property value is changed from 'Times New Roman' + * to 'Courier' and viceversa. + */ + public void _CharFontName() { + testProperty("CharFontName", new PropertyTester() { + @Override + protected Object getNewValue(String p, Object old) { + return "Courier".equals(old) ? "Times New Roman" : "Courier" ; + } + }) ; + } + + /** + * Locale values are predefined and can't be arbitrary changed. + * In this property value is changed from ('de', 'DE', '') + * to ('es', 'ES', '') and vice versa. + */ + public void _CharLocale() { + testProperty("CharLocale", new PropertyTester() { + @Override + protected Object getNewValue(String p, Object old) { + return old == null || ((Locale)old).Language.equals( "de" ) ? + new Locale("es", "ES", "") : new Locale("de", "DE", "") ; + } + }) ; + } + + /** + * This property can be void, so if old value is <code> null </code> + * new value must be specified. + */ + public void _ShadowFormat() { + testProperty("ShadowFormat", new PropertyTester() { + @Override + protected Object getNewValue(String p, Object old) { + return old == null ? new com.sun.star.table.ShadowFormat() : + super.getNewValue(p, old) ; + } + }) ; + } + +} //finish class _TableAutoFormatField + + + diff --git a/qadevOOo/tests/java/ifc/sheet/_XCellRangeData.java b/qadevOOo/tests/java/ifc/sheet/_XCellRangeData.java new file mode 100644 index 000000000..18d8ca0f9 --- /dev/null +++ b/qadevOOo/tests/java/ifc/sheet/_XCellRangeData.java @@ -0,0 +1,76 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.sheet; + +import lib.MultiMethodTest; +import util.ValueComparer; + +import com.sun.star.sheet.XCellRangeData; + +public class _XCellRangeData extends MultiMethodTest { + + public XCellRangeData oObj = null; + private Object[][] maCRData = null; + + /** + * Test calls the method + * state is OK if the resulting Object array + * isn't empty + */ + public void _getDataArray() { + maCRData = oObj.getDataArray(); + boolean bResult = (maCRData.length > 0); + tRes.tested("getDataArray()", bResult); + } + + /** + * Test creates an Array and calls the method + * with this Array as argument + * Then the method getDataArray is called + * and the resulting Array is compared with the + * one formerly set. + */ + public void _setDataArray() { + Object[][] newData = (Object[][]) tEnv.getObjRelation("NewData"); + if (newData == null) { + newData = new Object[maCRData.length][maCRData[0].length]; + for (int i=0; i<newData.length; i++) { + for (int j=0; j<newData[i].length; j++) { + newData[i][j] = new Double(10*i +j); + } + } + } + oObj.setDataArray(newData); + Object[][] oCRData = oObj.getDataArray(); + boolean res = ValueComparer.equalValue(oCRData[0][0],newData[0][0]); + res &= ValueComparer.equalValue(oCRData[0][1],newData[0][1]); + res &= ValueComparer.equalValue(oCRData[1][0],newData[1][0]); + res &= ValueComparer.equalValue(oCRData[1][1],newData[1][1]); + // delete values + Object[][] emptyData = new Object[newData.length][newData[0].length]; + for (int i=0; i<emptyData.length; i++) { + for (int j=0; j<emptyData[i].length; j++) { + emptyData[i][j] = ""; + } + } + oObj.setDataArray(emptyData); + tRes.tested("setDataArray()", res); + } +} + diff --git a/qadevOOo/tests/java/ifc/sheet/_XCellRangesQuery.java b/qadevOOo/tests/java/ifc/sheet/_XCellRangesQuery.java new file mode 100644 index 000000000..de0c327af --- /dev/null +++ b/qadevOOo/tests/java/ifc/sheet/_XCellRangesQuery.java @@ -0,0 +1,300 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package ifc.sheet; + +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; + +import com.sun.star.beans.XPropertySet; +import com.sun.star.sheet.CellFlags; +import com.sun.star.sheet.FormulaResult; +import com.sun.star.sheet.XCellRangesQuery; +import com.sun.star.sheet.XSheetCellRanges; +import com.sun.star.sheet.XSpreadsheet; +import com.sun.star.table.CellAddress; +import com.sun.star.table.CellRangeAddress; +import com.sun.star.table.XColumnRowRange; +import com.sun.star.table.XTableColumns; +import com.sun.star.table.XTableRows; +import com.sun.star.uno.UnoRuntime; + +/** + * Test the XCellRangesQuery interface. + * Needed object relations: + * <ul> + * <li>"SHEET": an XSpreadSheet object + * </li> + * <li>"XCellRangesQuery.EXPECTEDRESULTS": the expected results for the test + * methods as a String array.<br> + * @see mod._sc.ScCellCursorObj or + * @see mod._sc.ScCellObj for an example how this should look like. + * </li> + * </ul> + */ +public class _XCellRangesQuery extends MultiMethodTest { + public XCellRangesQuery oObj; + protected XSpreadsheet oSheet; + protected XTableRows oRows; + protected XTableColumns oColumns; + protected String[] mExpectedResults = null; + protected boolean bMakeEntriesAndDispose = false; + String getting = ""; + String expected = ""; + // provide the object with constants to fill the expected results array + public static final int QUERYCOLUMNDIFFERENCES = 0; + public static final int QUERYCONTENTCELLS = 1; + public static final int QUERYEMPTYCELLS = 2; + public static final int QUERYFORMULACELLS = 3; + public static final int QUERYINTERSECTION = 4; + public static final int QUERYROWDIFFERENCES = 5; + public static final int QUERYVISIBLECELLS = 6; + + @Override + protected void before() { + oSheet = (XSpreadsheet) tEnv.getObjRelation("SHEET"); + + if (oSheet == null) { + log.println("Object relation oSheet is missing"); + log.println("Trying to query the needed Interface"); + oSheet = UnoRuntime.queryInterface( + XSpreadsheet.class, tEnv.getTestObject()); + + if (oSheet == null) { + throw new StatusException(Status.failed( + "Object relation oSheet is missing")); + } + } + + // expected results + mExpectedResults = (String[])tEnv.getObjRelation( + "XCellRangesQuery.EXPECTEDRESULTS"); + + XColumnRowRange oColumnRowRange = UnoRuntime.queryInterface( + XColumnRowRange.class, + oSheet); + oRows = oColumnRowRange.getRows(); + oColumns = oColumnRowRange.getColumns(); + + // set this in object if the interface has to make its own settings + // and the environment has to be disposed: this is necessary for objects + // that do not make entries on the sheet themselves + Object o = tEnv.getObjRelation("XCellRangesQuery.CREATEENTRIES"); + if (o instanceof Boolean) { + bMakeEntriesAndDispose = ((Boolean)o).booleanValue(); + } + if(bMakeEntriesAndDispose) { + oRows.removeByIndex(4, oRows.getCount() - 4); + oColumns.removeByIndex(4, oColumns.getCount() - 4); + + try { + oSheet.getCellByPosition(1, 1).setValue(5); + oSheet.getCellByPosition(1, 2).setValue(15); + oSheet.getCellByPosition(2, 1).setFormula("=B2+B3"); + oSheet.getCellByPosition(1, 3).setFormula("=B2+B4"); + oSheet.getCellByPosition(3, 2).setFormula(""); + oSheet.getCellByPosition(3, 3).setFormula(""); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + log.println("Couldn't fill cells " + e.getLocalizedMessage()); + } + } + + } + + /** + * Tested method returns each cell of each column that is different to the + * cell in a given row + */ + public void _queryColumnDifferences() { + boolean res = true; + XSheetCellRanges ranges = oObj.queryColumnDifferences( + new CellAddress((short) 0, 1, 1)); + getting = ranges.getRangeAddressesAsString(); + expected = mExpectedResults[QUERYCOLUMNDIFFERENCES]; + + if (!getting.startsWith(expected)) { + log.println("Getting: " + getting); + log.println("Should have started with: " + expected); + res = false; + } + + tRes.tested("queryColumnDifferences()", res); + } + + /** + * Tested method returns all cells of a given type, defined in + * CellFlags + * @see com.sun.star.sheet.CellFlags + */ + public void _queryContentCells() { + boolean res = true; + XSheetCellRanges ranges = oObj.queryContentCells( + (short) CellFlags.VALUE); + getting = ranges.getRangeAddressesAsString(); + expected = mExpectedResults[QUERYCONTENTCELLS]; + + if (!getting.startsWith(expected)) { + log.println("Getting: " + getting); + log.println("Should have started with: " + expected); + res = false; + } + + tRes.tested("queryContentCells()", res); + } + + /** + * Tested method returns all empty cells of the range + */ + public void _queryEmptyCells() { + boolean res = true; + XSheetCellRanges ranges = oObj.queryEmptyCells(); + getting = ranges.getRangeAddressesAsString(); + expected = mExpectedResults[QUERYEMPTYCELLS]; + + int startIndex = 0; + int endIndex = -5; + String checkString = null; + + while (endIndex != -1) { + startIndex = endIndex + 5; + endIndex = expected.indexOf(" ... ", startIndex); + if (endIndex == -1) { + checkString = expected.substring(startIndex); + } + else { + checkString = expected.substring(startIndex, endIndex); + } + res &= (getting.indexOf(checkString) > -1); + } + + if (!res) { + log.println("Getting: " + getting); + log.println("Should have contained: " + expected); + } + + tRes.tested("queryEmptyCells()", res); + } + + /** + * Tested method returns all cells of a given type, defined in + * FormulaResult + * @see com.sun.star.sheet.FormulaResult + */ + public void _queryFormulaCells() { + boolean res = true; + XSheetCellRanges ranges = oObj.queryFormulaCells( + (short) FormulaResult.VALUE); + getting = ranges.getRangeAddressesAsString(); + expected = mExpectedResults[QUERYFORMULACELLS]; + + if (!getting.equals(expected)) { + log.println("Getting: " + getting); + log.println("Expected: " + expected); + res = false; + } + + tRes.tested("queryFormulaCells()", res); + } + + public void _queryIntersection() { + boolean res = true; + XSheetCellRanges ranges = oObj.queryIntersection( + new CellRangeAddress((short) 0, 3, 3, 7, 7)); + getting = ranges.getRangeAddressesAsString(); + expected = mExpectedResults[QUERYINTERSECTION]; + + if (!getting.startsWith(expected)) { + log.println("Getting: " + getting); + log.println("Should have started with: " + expected); + res = false; + } + + tRes.tested("queryIntersection()", res); + } + + /** + * Tested method returns each cell of each row that is different to the + * cell in a given column + */ + public void _queryRowDifferences() { + boolean res = true; + XSheetCellRanges ranges = oObj.queryRowDifferences( + new CellAddress((short) 0, 1, 1)); + getting = ranges.getRangeAddressesAsString(); + expected = mExpectedResults[QUERYROWDIFFERENCES]; + + if (!getting.startsWith(expected)) { + log.println("Getting: " + getting); + log.println("Should have started with: " + expected); + res = false; + } + + tRes.tested("queryRowDifferences()", res); + } + + public void _queryVisibleCells() { + setRowVisible(false); + + boolean res = true; + XSheetCellRanges ranges = oObj.queryVisibleCells(); + getting = ranges.getRangeAddressesAsString(); + expected = mExpectedResults[QUERYVISIBLECELLS]; + + if (!getting.startsWith(expected)) { + log.println("Getting: " + getting); + log.println("Should have started with: " + expected); + res = false; + } + + setRowVisible(true); + tRes.tested("queryVisibleCells()", res); + } + + protected void setRowVisible(boolean vis) { + try { + XPropertySet rowProp = UnoRuntime.queryInterface( + XPropertySet.class, + oRows.getByIndex(0)); + rowProp.setPropertyValue("IsVisible", Boolean.valueOf(vis)); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + log.println("couldn't get Row " + e.getLocalizedMessage()); + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("problems setting Property 'isVisible' " + + e.getLocalizedMessage()); + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("problems setting Property 'isVisible' " + + e.getLocalizedMessage()); + } catch (com.sun.star.beans.PropertyVetoException e) { + log.println("problems setting Property 'isVisible' " + + e.getLocalizedMessage()); + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("problems setting Property 'isVisible' " + + e.getLocalizedMessage()); + } + } + + /** + * Forces environment recreation. + */ + @Override + protected void after() { + if(bMakeEntriesAndDispose) { + disposeEnvironment(); + } + } +} diff --git a/qadevOOo/tests/java/ifc/sheet/_XEnhancedMouseClickBroadcaster.java b/qadevOOo/tests/java/ifc/sheet/_XEnhancedMouseClickBroadcaster.java new file mode 100644 index 000000000..fdcbcd4ff --- /dev/null +++ b/qadevOOo/tests/java/ifc/sheet/_XEnhancedMouseClickBroadcaster.java @@ -0,0 +1,138 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package ifc.sheet; + +import com.sun.star.accessibility.AccessibleRole; +import com.sun.star.accessibility.XAccessible; +import com.sun.star.accessibility.XAccessibleComponent; +import com.sun.star.awt.Point; +import com.sun.star.awt.Rectangle; +import com.sun.star.awt.XEnhancedMouseClickHandler; +import com.sun.star.awt.XWindow; +import com.sun.star.frame.XModel; +import com.sun.star.sheet.XEnhancedMouseClickBroadcaster; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; + +import lib.MultiMethodTest; +import util.AccessibilityTools; +import util.DesktopTools; +import java.awt.Robot; +import java.awt.event.InputEvent; + + +public class _XEnhancedMouseClickBroadcaster extends MultiMethodTest { + public XEnhancedMouseClickBroadcaster oObj; + protected boolean mousePressed = false; + protected boolean mouseReleased = false; + protected XEnhancedMouseClickHandler listener = new MyListener(); + private XModel docModel = null; + + @Override + public void before() { + docModel = UnoRuntime.queryInterface( + XModel.class,tEnv.getObjRelation("FirstModel")); + DesktopTools.bringWindowToFront(docModel); + } + + public void _addEnhancedMouseClickHandler() { + oObj.addEnhancedMouseClickHandler(listener); + clickOnSheet(); + + //make sure that the listener is removed even if the test fails + if ((!mousePressed) || (!mouseReleased)) { + oObj.removeEnhancedMouseClickHandler(listener); + } + + tRes.tested("addEnhancedMouseClickHandler()", + mousePressed && mouseReleased); + } + + public void _removeEnhancedMouseClickHandler() { + requiredMethod("addEnhancedMouseClickHandler()"); + mousePressed = false; + mouseReleased = false; + oObj.removeEnhancedMouseClickHandler(listener); + clickOnSheet(); + tRes.tested("removeEnhancedMouseClickHandler()", + (!mousePressed) && (!mouseReleased)); + } + + protected boolean clickOnSheet() { + log.println("try to open context menu..."); + + XWindow xWindow = AccessibilityTools.getCurrentWindow(docModel); + + XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow); + + XInterface oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL); + + XAccessibleComponent window = UnoRuntime.queryInterface( + XAccessibleComponent.class, oObj); + + Point point = window.getLocationOnScreen(); + Rectangle rect = window.getBounds(); + + log.println("click mouse button..."); + try { + Robot rob = new Robot(); + int x = point.X + (rect.Width / 2)+50; + int y = point.Y + (rect.Height / 2)+50; + rob.mouseMove(x, y); + System.out.println("Press Button"); + rob.mousePress(InputEvent.BUTTON3_MASK); + System.out.println("Release Button"); + rob.mouseRelease(InputEvent.BUTTON3_MASK); + System.out.println("done"); + System.out.println("wait"); + waitForEventIdle(); + System.out.println("Press Button"); + rob.mousePress(InputEvent.BUTTON1_MASK); + System.out.println("Release Button"); + rob.mouseRelease(InputEvent.BUTTON1_MASK); + System.out.println("done "+rob.getAutoDelay()); + } catch (java.awt.AWTException e) { + log.println("couldn't press mouse button"); + } + + + return true; + } + + protected class MyListener implements XEnhancedMouseClickHandler { + public void disposing( + com.sun.star.lang.EventObject eventObject) { + } + + public boolean mousePressed( + com.sun.star.awt.EnhancedMouseEvent enhancedMouseEvent) { + log.println("mousePressed"); + mousePressed = true; + + return true; + } + + public boolean mouseReleased( + com.sun.star.awt.EnhancedMouseEvent enhancedMouseEvent) { + log.println("mouseReleased"); + mouseReleased = true; + + return true; + } + } +} diff --git a/qadevOOo/tests/java/ifc/sheet/_XRangeSelection.java b/qadevOOo/tests/java/ifc/sheet/_XRangeSelection.java new file mode 100644 index 000000000..e2a2aa01c --- /dev/null +++ b/qadevOOo/tests/java/ifc/sheet/_XRangeSelection.java @@ -0,0 +1,353 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package ifc.sheet; + +import com.sun.star.accessibility.AccessibleRole; +import com.sun.star.accessibility.XAccessible; +import com.sun.star.accessibility.XAccessibleComponent; +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.awt.Point; +import com.sun.star.awt.PosSize; +import com.sun.star.awt.Rectangle; +import com.sun.star.awt.XExtendedToolkit; +import com.sun.star.awt.XTopWindow; +import com.sun.star.awt.XWindow; +import com.sun.star.beans.PropertyValue; +import com.sun.star.frame.XModel; +import com.sun.star.lang.EventObject; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.sheet.RangeSelectionEvent; +import com.sun.star.sheet.XRangeSelection; +import com.sun.star.sheet.XRangeSelectionChangeListener; +import com.sun.star.sheet.XRangeSelectionListener; +import com.sun.star.uno.UnoRuntime; +import java.awt.Robot; +import java.awt.event.InputEvent; +import java.io.PrintWriter; +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; +import util.AccessibilityTools; + +/** + * Check the XRangeSelection interface. + */ +public class _XRangeSelection extends MultiMethodTest { + public XRangeSelection oObj = null; + MyRangeSelectionListener aListener = null; + + @Override + public void before() { + aListener = new _XRangeSelection.MyRangeSelectionListener(log); + // workaround for i34499 + XModel xModel = (XModel)tEnv.getObjRelation("FirstModel"); + if (xModel == null) + throw new StatusException(Status.failed("Object relation FirstModel' not set.")); + XWindow xWindow = xModel.getCurrentController().getFrame().getContainerWindow(); + XTopWindow xTopWindow = UnoRuntime.queryInterface(XTopWindow.class, xWindow); + xTopWindow.toFront(); + waitForEventIdle(); + } + + + public void _abortRangeSelection() { + requiredMethod("removeRangeSelectionChangeListener()"); + requiredMethod("removeRangeSelectionListener()"); + oObj.abortRangeSelection(); + tRes.tested("abortRangeSelection()", true); + } + + public void _addRangeSelectionChangeListener() { + oObj.addRangeSelectionChangeListener(aListener); + tRes.tested("addRangeSelectionChangeListener()", true); + } + + public void _addRangeSelectionListener() { + oObj.addRangeSelectionListener(aListener); + tRes.tested("addRangeSelectionListener()", true); + } + + public void _removeRangeSelectionChangeListener() { + oObj.removeRangeSelectionChangeListener(aListener); + tRes.tested("removeRangeSelectionChangeListener()", true); + } + + public void _removeRangeSelectionListener() { + oObj.removeRangeSelectionListener(aListener); + tRes.tested("removeRangeSelectionListener()", true); + } + + public void _startRangeSelection() { + requiredMethod("addRangeSelectionChangeListener()"); + requiredMethod("addRangeSelectionListener()"); + + // get the sheet center + Point center = getSheetCenter(); + if (center == null) + throw new StatusException(Status.failed("Couldn't get the sheet center.")); + + PropertyValue[] props = new PropertyValue[3]; + props[0] = new PropertyValue(); + props[0].Name = "InitialValue"; + props[0].Value = "B3:D5"; + props[1] = new PropertyValue(); + props[1].Name = "Title"; + props[1].Value = "the title"; + props[2] = new PropertyValue(); + props[2].Name = "CloseOnMouseRelease"; + props[2].Value = Boolean.FALSE; + oObj.startRangeSelection(props); + // wait for listeners + waitForEventIdle(); + + // get closer button: move if window covers the sheet center + Point closer = getCloser(center); + if (closer == null) + throw new StatusException(Status.failed("Couldn't get the close Button.")); + + // do something to trigger the listeners + clickOnSheet(center); + waitForEventIdle(); + + // click on closer + clickOnSheet(closer); + waitForEventIdle(); + + // open a new range selection + props[0].Value = "C4:E6"; + oObj.startRangeSelection(props); + waitForEventIdle(); + props[0].Value = "C2:E3"; + oObj.startRangeSelection(props); + waitForEventIdle(); + + oObj.startRangeSelection(props); + waitForEventIdle(); + oObj.abortRangeSelection(); + aListener.reset(); + System.out.println("Listener called: " + aListener.bAbortCalled); + + tRes.tested("startRangeSelection()", aListener.listenerCalled()); + } + + /** + * Determine the current top window center and return this as a point. + * @return a point representing the sheet center. + */ + protected Point getSheetCenter() { + log.println("Trying to get AccessibleSpreadsheet"); + + XComponent xSheetDoc = (XComponent) tEnv.getObjRelation("DOCUMENT"); + + XModel xModel = UnoRuntime.queryInterface(XModel.class, xSheetDoc); + System.out.println("Name: " + xModel.getCurrentController().getFrame().getName()); + + XWindow xWindow = AccessibilityTools.getCurrentWindow(xModel); + XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow); + + XAccessibleContext ctx = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE ); + + XAccessibleComponent AccessibleSpreadsheet = UnoRuntime.queryInterface(XAccessibleComponent.class,ctx); + + log.println("Got " + util.utils.getImplName(AccessibleSpreadsheet)); + + Object toolkit = null; + + try { + toolkit = tParam.getMSF().createInstance("com.sun.star.awt.Toolkit"); + } catch (com.sun.star.uno.Exception e) { + log.println("Couldn't get toolkit"); + e.printStackTrace(log); + throw new StatusException("Couldn't get toolkit", e); + } + + XExtendedToolkit tk = UnoRuntime.queryInterface( + XExtendedToolkit.class, toolkit); + + XTopWindow tw = null; + + int k = tk.getTopWindowCount(); + for (int i=0;i<k;i++) { + try { + XTopWindow tw_temp = tk.getTopWindow(i); + XAccessible xacc = UnoRuntime.queryInterface(XAccessible.class, tw_temp); + if (xacc != null) { + if (xacc.getAccessibleContext().getAccessibleName().indexOf("d2")>0) { + tw=tw_temp; + } + } else { + log.println("\t unknown window"); + } + + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } + } + if (tw == null) { + System.out.println("No TopWindow :-("); + return null; + } + + Point point = AccessibleSpreadsheet.getLocationOnScreen(); + Rectangle rect = AccessibleSpreadsheet.getBounds(); + Point retPoint = new Point(); + retPoint.X = point.X + (rect.Width / 2); + retPoint.Y = point.Y + (rect.Height / 2); + return retPoint; + } + + /** + * Get the closer button on the right top of the current window. + * @return A point representing the closer button. + */ + private Point getCloser(Point center) { + XMultiServiceFactory xMSF = tParam.getMSF(); + Object aToolkit = null; + try { + aToolkit = xMSF.createInstance("com.sun.star.awt.Toolkit"); + } + catch(com.sun.star.uno.Exception e) { + throw new StatusException("Could not create 'com.sun.star.awt.Toolkit'.", e); + } + XExtendedToolkit xExtendedToolkit = UnoRuntime.queryInterface(XExtendedToolkit.class, aToolkit); + XTopWindow tw = null; + + XAccessibleComponent xAccessibleComponent = null; + int k = xExtendedToolkit.getTopWindowCount(); + for (int i=0;i<k;i++) { + try { + XTopWindow tw_temp = xExtendedToolkit.getTopWindow(i); + XAccessible xacc = UnoRuntime.queryInterface(XAccessible.class, tw_temp); + if (xacc != null) { + System.out.println("Name: " + xacc.getAccessibleContext().getAccessibleName()); + if (xacc.getAccessibleContext().getAccessibleName().startsWith("the title")) { + tw = tw_temp; + XAccessibleContext xContext = xacc.getAccessibleContext(); + xAccessibleComponent = UnoRuntime.queryInterface(XAccessibleComponent.class, xContext); + if (xAccessibleComponent == null) + System.out.println("!!!! MIST !!!!"); + else + System.out.println("########## KLAPPT ########## "); + } + } + else { + log.println("\t unknown window"); + } + + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + } + } + if (tw == null) { + System.out.println("No TopWindow :-("); + return null; + } + + XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, tw); + Rectangle posSize = xWindow.getPosSize(); + + // compare the center point with the dimensions of the current top window + boolean windowOK = false; + while(!windowOK) { + if (posSize.X <= center.X && center.X <= posSize.X + posSize.Width) { + if (posSize.Y <= center.Y && center.Y <= posSize.Y +posSize.Height) { + // move window out of the way + posSize.X = posSize.X + 10; + posSize.Y = posSize.Y +10; + xWindow.setPosSize(posSize.X, posSize.Y, posSize.Width, posSize.Height, PosSize.POS); + } + else { + windowOK = true; + } + } + else { + windowOK = true; + } + + } + + Point p = xAccessibleComponent.getLocationOnScreen(); + Point closer = new Point(); + closer.X = p.X + posSize.Width - 2; + closer.Y = p.Y + 5; + System.out.println("Closer: " + closer.X + " " + closer.Y); + return closer; + } + + protected boolean clickOnSheet(Point point) { + log.println("Clicking in the center of the AccessibleSpreadsheet"); + + try { + Robot rob = new Robot(); + rob.mouseMove(point.X, point.Y); + rob.mousePress(InputEvent.BUTTON1_MASK); + waitForEventIdle(); + rob.mouseRelease(InputEvent.BUTTON1_MASK); + waitForEventIdle(); + } catch (java.awt.AWTException e) { + log.println("couldn't press mouse button"); + } + + return true; + } + + /** + * + */ + public static class MyRangeSelectionListener implements XRangeSelectionListener, XRangeSelectionChangeListener { + boolean bAbortCalled = false; + boolean bChangeCalled = false; + boolean bDoneCalled = false; + PrintWriter log = null; + + public MyRangeSelectionListener(PrintWriter log) { + this.log = log; + } + + public void aborted(RangeSelectionEvent rangeSelectionEvent) { + log.println("Called 'aborted' with: " + rangeSelectionEvent.RangeDescriptor); + bAbortCalled = true; + } + + public void descriptorChanged(RangeSelectionEvent rangeSelectionEvent) { + log.println("Called 'descriptorChanged' with: " + rangeSelectionEvent.RangeDescriptor); + bChangeCalled = true; + } + + public void done(RangeSelectionEvent rangeSelectionEvent) { + log.println("Called 'done' with: " + rangeSelectionEvent.RangeDescriptor); + bDoneCalled = true; + } + + public boolean listenerCalled() { + return bAbortCalled & bChangeCalled & bDoneCalled; + } + + public void reset() { + bAbortCalled = false; + bChangeCalled = false; + bDoneCalled = false; + } + + /** + * ignore disposing + * @param eventObject The event. + */ + public void disposing(EventObject eventObject) { + } + } +} |