From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- sc/qa/complex/calcPreview/TestDocument.java | 30 + sc/qa/complex/calcPreview/ViewForwarder.java | 1003 ++++++++++++++++++++ sc/qa/complex/calcPreview/makefile.mk | 114 +++ .../calcPreview/test_documents/calcshapes.sxc | Bin 0 -> 13030 bytes sc/qa/complex/dataPilot/_XDataPilotDescriptor.java | 420 ++++++++ sc/qa/complex/dataPilot/_XDataPilotTable.java | 97 ++ sc/qa/complex/dataPilot/_XNamed.java | 133 +++ sc/qa/complex/dataPilot/_XPropertySet.java | 601 ++++++++++++ sc/qa/complex/sc/CalcRTL.java | 493 ++++++++++ 9 files changed, 2891 insertions(+) create mode 100644 sc/qa/complex/calcPreview/TestDocument.java create mode 100644 sc/qa/complex/calcPreview/ViewForwarder.java create mode 100644 sc/qa/complex/calcPreview/makefile.mk create mode 100644 sc/qa/complex/calcPreview/test_documents/calcshapes.sxc create mode 100644 sc/qa/complex/dataPilot/_XDataPilotDescriptor.java create mode 100644 sc/qa/complex/dataPilot/_XDataPilotTable.java create mode 100644 sc/qa/complex/dataPilot/_XNamed.java create mode 100644 sc/qa/complex/dataPilot/_XPropertySet.java create mode 100644 sc/qa/complex/sc/CalcRTL.java (limited to 'sc/qa/complex') diff --git a/sc/qa/complex/calcPreview/TestDocument.java b/sc/qa/complex/calcPreview/TestDocument.java new file mode 100644 index 000000000..1ab9bdd3f --- /dev/null +++ b/sc/qa/complex/calcPreview/TestDocument.java @@ -0,0 +1,30 @@ +/* + * 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 complex.calcPreview; + +import java.io.File; +import org.openoffice.test.OfficeFileUrl; + +final class TestDocument { + public static String getUrl(String name) { + return OfficeFileUrl.getAbsolute(new File("test_documents", name)); + } + + private TestDocument() {} +} diff --git a/sc/qa/complex/calcPreview/ViewForwarder.java b/sc/qa/complex/calcPreview/ViewForwarder.java new file mode 100644 index 000000000..4abbedc9b --- /dev/null +++ b/sc/qa/complex/calcPreview/ViewForwarder.java @@ -0,0 +1,1003 @@ +/* + * 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 complex.calcPreview; + +import com.sun.star.awt.XWindow; +import com.sun.star.container.XIndexAccess; +import com.sun.star.frame.XController; +import com.sun.star.frame.XDispatch; +import com.sun.star.frame.XDispatchProvider; +import com.sun.star.frame.XModel; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.sheet.XSpreadsheet; +import com.sun.star.sheet.XSpreadsheets; +import com.sun.star.table.XCell; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.util.URL; +import com.sun.star.util.XURLTransformer; +import com.sun.star.accessibility.AccessibleRole; +import com.sun.star.accessibility.XAccessible; +import com.sun.star.accessibility.XAccessibleText; +import com.sun.star.accessibility.XAccessibleValue; +import com.sun.star.accessibility.XAccessibleComponent; +import com.sun.star.accessibility.XAccessibleContext; + +import util.AccessibilityTools; +import util.SOfficeFactory; +import util.utils; + +import com.sun.star.beans.XPropertySet; +import com.sun.star.container.XNameAccess; +import com.sun.star.lang.XComponent; +import com.sun.star.sheet.XHeaderFooterContent; +import com.sun.star.sheet.XSpreadsheetDocument; +import com.sun.star.style.XStyle; +import com.sun.star.style.XStyleFamiliesSupplier; +import com.sun.star.text.XText; + +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openoffice.test.OfficeConnection; +import static org.junit.Assert.*; + +/** + * A complex test for the preview of Calc documents. This complex test + * needs interaction from the user: documents have to be resized and moved. + */ +public class ViewForwarder { + + /** The MultiServiceFactory **/ + private XMultiServiceFactory mXMSF = null; + + /** + * Get a MultiServiceFactory from the Office before the test. + */ + @Before public void before() + { + mXMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); + } + + + /** Create a spreadsheet document, insert some text, header and footer. + * Let the user resize the document and check the contents. + */ + @Test public void checkPositiveViewForwarder() { + SOfficeFactory SOF = SOfficeFactory.getFactory( mXMSF ); + XSpreadsheetDocument xSpreadsheetDoc = null; + + try { + System.out.println("Creating a spreadsheet document"); + xSpreadsheetDoc = SOF.createCalcDoc(null); + } catch (com.sun.star.uno.Exception e) { + fail(e.getMessage()); + return; + } + + XInterface oObj = null; + + // inserting some content to have non-empty page preview + XCell xCell = null; + try { + XSpreadsheets oSheets = xSpreadsheetDoc.getSheets() ; + XIndexAccess oIndexSheets = + UnoRuntime.queryInterface(XIndexAccess.class, oSheets); + Object o = oIndexSheets.getByIndex(0); + XSpreadsheet oSheet = (XSpreadsheet)AnyConverter.toObject( + new com.sun.star.uno.Type(XSpreadsheet.class), o); + xCell = oSheet.getCellByPosition(0, 0) ; + xCell.setFormula("ScAccessiblePageHeader"); + + xCell = oSheet.getCellByPosition(0, 1) ; + xCell.setFormula("Cell 1"); + xCell = oSheet.getCellByPosition(0, 2) ; + xCell.setFormula("Cell 2"); + } catch(com.sun.star.lang.IllegalArgumentException e) { + System.out.println("Exception creating relation :"); + fail(e.getMessage()); + } catch(com.sun.star.lang.WrappedTargetException e) { + System.out.println("Exception creating relation :"); + fail(e.getMessage()); + } catch(com.sun.star.lang.IndexOutOfBoundsException e) { + System.out.println("Exception creating relation :"); + fail(e.getMessage()); + } + + XModel aModel = + UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc); + + XController xController = aModel.getCurrentController(); + + // get page styles + XStyleFamiliesSupplier StyleFam = + UnoRuntime.queryInterface( + XStyleFamiliesSupplier.class, + xSpreadsheetDoc ); + XNameAccess StyleFamNames = StyleFam.getStyleFamilies(); + XStyle StdStyle = null; + + try{ + Object o = StyleFamNames.getByName("PageStyles"); + XNameAccess PageStyles = (XNameAccess)AnyConverter.toObject( + new com.sun.star.uno.Type(XNameAccess.class), o); + + o = PageStyles.getByName("Default"); + StdStyle = (XStyle)AnyConverter.toObject( + new com.sun.star.uno.Type(XStyle.class), o); + } catch(com.sun.star.lang.IllegalArgumentException e) { + fail(e.getMessage()); + } catch(com.sun.star.lang.WrappedTargetException e){ + fail(e.getMessage()); + return; + } catch(com.sun.star.container.NoSuchElementException e){ + fail(e.getMessage()); + return; + } + + //get the property-set + final XPropertySet PropSet = + UnoRuntime.queryInterface(XPropertySet.class, StdStyle); + + XHeaderFooterContent RPHFC = null; + + // get the header + try { + Object o = PropSet.getPropertyValue("RightPageHeaderContent"); + RPHFC = (XHeaderFooterContent)AnyConverter.toObject( + new com.sun.star.uno.Type(XHeaderFooterContent.class), o); + + } catch(com.sun.star.lang.IllegalArgumentException e) { + fail(e.getMessage()); + } catch(com.sun.star.lang.WrappedTargetException e){ + fail(e.getMessage()); + return; + } catch(com.sun.star.beans.UnknownPropertyException e){ + fail(e.getMessage()); + return; + } + + // insert text into header + XText center = RPHFC.getCenterText(); + center.setString("First line \n\r Second line \n\r third line "); + try { + PropSet.setPropertyValue("RightPageHeaderContent",RPHFC); + } catch (com.sun.star.beans.UnknownPropertyException e) { + } catch (com.sun.star.beans.PropertyVetoException e) { + } catch (com.sun.star.lang.IllegalArgumentException e) { + } catch (com.sun.star.lang.WrappedTargetException e) {} + + // get footer + RPHFC = null; + try { + Object o = PropSet.getPropertyValue("RightPageHeaderContent"); + RPHFC = (XHeaderFooterContent)AnyConverter.toObject( + new com.sun.star.uno.Type(XHeaderFooterContent.class), o); + } catch(com.sun.star.lang.IllegalArgumentException e) { + fail(e.getMessage()); + } catch(com.sun.star.lang.WrappedTargetException e){ + fail(e.getMessage()); + return; + } catch(com.sun.star.beans.UnknownPropertyException e){ + fail(e.getMessage()); + return; + } + + // insert text into footer + center = RPHFC.getCenterText(); + center.setString("Third last line\n\r Second last line\n\r last line"); + try { + PropSet.setPropertyValue("RightPageFooterContent",RPHFC); + } catch (com.sun.star.beans.UnknownPropertyException e) { + } catch (com.sun.star.beans.PropertyVetoException e) { + } catch (com.sun.star.lang.IllegalArgumentException e) { + } catch (com.sun.star.lang.WrappedTargetException e) {} + + // switching to 'Page Preview' mode + try { + XDispatchProvider xDispProv = + UnoRuntime.queryInterface(XDispatchProvider.class, xController); + XURLTransformer xParser = + UnoRuntime.queryInterface(XURLTransformer.class, + mXMSF.createInstance("com.sun.star.util.URLTransformer")); + // Because it's an in/out parameter we must use an + // array of URL objects. + URL[] aParseURL = new URL[1]; + aParseURL[0] = new URL(); + aParseURL[0].Complete = ".uno:PrintPreview"; + xParser.parseStrict(aParseURL); + URL aURL = aParseURL[0]; + XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0); + if(xDispatcher != null) + { + xDispatcher.dispatch( aURL, null ); + } + } catch (com.sun.star.uno.Exception e) { + fail("Couldn't change mode"); + return; + } + + util.utils.waitForEventIdle(mXMSF); + + System.out.println("Press any key after resizing "); + try{ + byte[]b = new byte[16]; + System.in.read(b); + } catch (Exception e) { + e.printStackTrace(); + } + + XWindow xWindow = AccessibilityTools.getCurrentWindow(aModel); + XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow); + XAccessible parent = null; + + try { + parent = AccessibilityTools.getAccessibleObjectForRole + (xRoot, AccessibleRole.HEADER, "").getAccessibleChild(0); + oObj = parent.getAccessibleContext().getAccessibleChild(0); + } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) { + fail(iabe.getMessage()); + return; + } + + System.out.println("ImplementationName " + utils.getImplName(oObj)); + + XAccessibleComponent accPC = + UnoRuntime.queryInterface(XAccessibleComponent.class, parent); + + System.out.println("Parent-BoundsX= "+accPC.getBounds().X); + System.out.println("Parent-BoundsY= "+accPC.getBounds().Y); + System.out.println("Parent-BoundsWidth= "+accPC.getBounds().Width); + System.out.println("Parent-BoundsHeight= "+accPC.getBounds().Height); + + XAccessibleComponent accPPC = + UnoRuntime.queryInterface(XAccessibleComponent.class, + parent.getAccessibleContext().getAccessibleParent()); + + System.out.println("P-Parent-BoundsX= "+accPPC.getBounds().X); + System.out.println("P-Parent-BoundsY= "+accPPC.getBounds().Y); + System.out.println("P-Parent-BoundsWidth= "+accPPC.getBounds().Width); + System.out.println("P-Parent-BoundsHeight= "+accPPC.getBounds().Height); + + util.utils.waitForEventIdle(mXMSF); + + System.out.println("Press any key when the second line is on top"); + try{ + byte[]b = new byte[16]; + System.in.read(b); + } catch (Exception e) { + e.printStackTrace(); + } + + try { + System.out.println("ChildCount: "+ + parent.getAccessibleContext().getAccessibleChildCount()); + System.out.println("Getting child 0 again"); + oObj = parent.getAccessibleContext().getAccessibleChild(0); + } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) { + fail(iabe.getMessage()); + return; + } + + XAccessibleText accT = + UnoRuntime.queryInterface(XAccessibleText.class, oObj); + System.out.println("Getting the text: "+accT.getText()); + + XAccessibleComponent accC = + UnoRuntime.queryInterface(XAccessibleComponent.class, oObj); + System.out.println("BoundsX= "+accC.getBounds().X); + System.out.println("BoundsY= "+accC.getBounds().Y); + System.out.println("BoundsWidth= "+accC.getBounds().Width); + System.out.println("BoundsHeight= "+accC.getBounds().Height); + + accPC = + UnoRuntime.queryInterface(XAccessibleComponent.class, parent); + + System.out.println("Parent-BoundsX= "+accPC.getBounds().X); + System.out.println("Parent-BoundsY= "+accPC.getBounds().Y); + System.out.println("Parent-BoundsWidth= "+accPC.getBounds().Width); + System.out.println("Parent-BoundsHeight= "+accPC.getBounds().Height); + + accPPC = + UnoRuntime.queryInterface(XAccessibleComponent.class, + parent.getAccessibleContext().getAccessibleParent()); + + System.out.println("P-Parent-BoundsX= "+accPPC.getBounds().X); + System.out.println("P-Parent-BoundsY= "+accPPC.getBounds().Y); + System.out.println("P-Parent-BoundsWidth= "+accPPC.getBounds().Width); + System.out.println("P-Parent-BoundsHeight= "+accPPC.getBounds().Height); + + + + System.out.println("Press any key when the footer is visible."); + try{ + byte[]b = new byte[16]; + System.in.read(b); + } catch (Exception e) { + e.printStackTrace(); + } + + try { + parent = AccessibilityTools.getAccessibleObjectForRole + (xRoot, AccessibleRole.FOOTER, "").getAccessibleChild(0); + } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) { + fail(iabe.getMessage()); + return; + } + + accPC = + UnoRuntime.queryInterface(XAccessibleComponent.class, parent); + + try { + System.out.println("ChildCount: "+ + parent.getAccessibleContext().getAccessibleChildCount()); + System.out.println("Getting child 0 again"); + oObj = parent.getAccessibleContext().getAccessibleChild(0); + } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) { + fail(iabe.getMessage()); + return; + } + + accT = + UnoRuntime.queryInterface(XAccessibleText.class, oObj); + System.out.println("Getting the text: "+accT.getText()); + + accC = + UnoRuntime.queryInterface(XAccessibleComponent.class, oObj); + System.out.println("BoundsX= "+accC.getBounds().X); + System.out.println("BoundsY= "+accC.getBounds().Y); + System.out.println("BoundsWidth= "+accC.getBounds().Width); + System.out.println("BoundsHeight= "+accC.getBounds().Height); + + accPC = + UnoRuntime.queryInterface(XAccessibleComponent.class, parent); + + System.out.println("Parent-BoundsX= "+accPC.getBounds().X); + System.out.println("Parent-BoundsY= "+accPC.getBounds().Y); + System.out.println("Parent-BoundsWidth= "+accPC.getBounds().Width); + System.out.println("Parent-BoundsHeight= "+accPC.getBounds().Height); + + accPPC = + UnoRuntime.queryInterface(XAccessibleComponent.class, + parent.getAccessibleContext().getAccessibleParent()); + + System.out.println("P-Parent-BoundsX= "+accPPC.getBounds().X); + System.out.println("P-Parent-BoundsY= "+accPPC.getBounds().Y); + System.out.println("P-Parent-BoundsWidth= "+accPPC.getBounds().Width); + System.out.println("P-Parent-BoundsHeight= "+accPPC.getBounds().Height); + + + System.out.println("Press any key when the page content is on top"); + try{ + byte[]b = new byte[16]; + System.in.read(b); + } catch (Exception e) { + e.printStackTrace(); + } + + try { + parent = AccessibilityTools.getAccessibleObjectForRole + (xRoot, AccessibleRole.DOCUMENT, "").getAccessibleChild(0); + } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) { + fail(iabe.getMessage()); + return; + } + System.out.println("PARENT: " + parent.getAccessibleContext().getAccessibleName()); + accPC = + UnoRuntime.queryInterface(XAccessibleComponent.class, parent); + + int cCount = 0; + try { + cCount = + parent.getAccessibleContext().getAccessibleChildCount(); + System.out.println("ChildCount: "+cCount); + System.out.println("Getting child 0 again"); + oObj = parent.getAccessibleContext().getAccessibleChild(0); + } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) { + fail(iabe.getMessage()); + return; + } + + for (int i=0; icom.sun.star.sheet.XDataPilotDescriptor +* interface methods : +*
    +*
  • getTag()
  • +*
  • setTag()
  • +*
  • getSourceRange()
  • +*
  • setSourceRange()
  • +*
  • getFilterDescriptor()
  • +*
  • getDataPilotFields()
  • +*
  • getColumnFields()
  • +*
  • getRowFields()
  • +*
  • getPageFields()
  • +*
  • getDataFields()
  • +*
  • getHiddenFields()
  • +*

+* This test needs the following object relations : +*

    +*
  • 'FIELDSAMOUNT' (of type Integer): +* to have number of fields
  • +*

      +* @see com.sun.star.sheet.XDataPilotDescriptor +*/ +public class _XDataPilotDescriptor { + + private final XDataPilotDescriptor oObj; + private final CellRangeAddress CRA = new CellRangeAddress((short)1, 0, 0, 5, 5); + + private static final String sTag = "XDataPilotDescriptor_Tag"; + private String fieldsNames[]; + private int tEnvFieldsAmount = 0; + + /** + * The test parameters + */ + private final TestParameters param; + + /** + * Constructor: gets the object to test, a logger and the test parameters + * @param xObj The test object + * @param param The test parameters + */ + public _XDataPilotDescriptor(XDataPilotDescriptor xObj/*, + LogWriter log*/, TestParameters param) { + oObj = xObj; + this.param = param; + } + + /** + * Retrieves object relations. + + */ + public boolean before() { + Integer amount = (Integer)param.get("FIELDSAMOUNT"); + if (amount == null) { + System.out.println("Relation 'FIELDSAMOUNT' not found"); + return false; + } + tEnvFieldsAmount = amount.intValue(); + return true; + } + + /** + * Test calls the method and compares returned value with value that was set + * in method setSourceRange().

      + * Has OK status if all fields of cell range addresses are equal.

      + * The following method tests are to be completed successfully before : + *

        + *
      • setSourceRange() : to have current source range
      • + *
      + */ + public boolean _getSourceRange(){ +// requiredMethod("setSourceRange()"); + boolean bResult = true; + + CellRangeAddress objRA = oObj.getSourceRange(); + bResult &= objRA.Sheet == CRA.Sheet; + bResult &= objRA.StartRow == CRA.StartRow; + bResult &= objRA.StartColumn == CRA.StartColumn; + bResult &= objRA.EndRow == CRA.EndRow; + bResult &= objRA.EndColumn == CRA.EndColumn; + + return bResult; + } + + /** + * Test gets the current source range, stores it and sets new source range.

      + * Has OK status if the method successfully returns.

      + * The following method tests are to be executed before : + *

        + *
      • getColumnFields()
      • + *
      • getRowFields()
      • + *
      • getDataFields()
      • + *
      • getHiddenFields()
      • + *
      • getPageFields()
      • + *
      + */ + public boolean _setSourceRange(){ + + oObj.setSourceRange(CRA); + + return true; + } + + /** + * Test calls the method and checks returned value with value that was set + * by method setTag().

      + * Has OK status if returned value is equal to value that was set + * by method setTag().

      + * The following method tests are to be completed successfully before : + *

        + *
      • setTag() : to have current tag
      • + *
      + */ + public boolean _getTag(){ + boolean bResult = true; + + String objTag = oObj.getTag(); + bResult &= objTag.equals(sTag); + + return bResult; + } + + /** + * Test just calls the method.

      + * Has OK status if the method successfully returns.

      + */ + public boolean _setTag(){ + oObj.setTag(sTag); + return true; + } + + /** + * Test calls the method , checks returned value, compares + * number of fields goten from returned value and obtained by object + * relation 'FIELDSAMOUNT' and set property + * Orientation to one of DataPilotFieldOrientation values.

      + * Has OK status if returned value isn't null, number of fields + * goten from returned value is less than number of fields obtained by relation + * and no exceptions were thrown.

      + */ + public boolean _getDataPilotFields(){ + boolean bResult = true; + XIndexAccess IA = null; + + IA = oObj.getDataPilotFields(); + if (IA == null) { + System.out.println("Returned value is null."); + return false; + } else {System.out.println("getDataPilotFields returned not Null value -- OK");} + + int fieldsAmount = IA.getCount(); + if (fieldsAmount < tEnvFieldsAmount) { + System.out.println("Number of fields is less than number goten by relation."); + return false; + } else {System.out.println("count of returned fields -- OK");} + + fieldsNames = new String[tEnvFieldsAmount]; + int i = -1 ; + int cnt = 0 ; + while (++i < fieldsAmount) { + Object field; + try { + field = IA.getByIndex(i); + } catch(com.sun.star.lang.WrappedTargetException e) { + e.printStackTrace(); + return false; + } catch(com.sun.star.lang.IndexOutOfBoundsException e) { + e.printStackTrace(); + return false; + } + + XNamed named = UnoRuntime.queryInterface(XNamed.class, field); + String name = named.getName(); + + System.out.println("Field : '" + name + "' ... ") ; + + if (!name.equals("Data")) { + + fieldsNames[cnt] = name ; + + XPropertySet props = + UnoRuntime.queryInterface(XPropertySet.class, field); + + try { + switch (cnt % 5) { + case 0 : + props.setPropertyValue("Orientation", + DataPilotFieldOrientation.COLUMN); + System.out.println(" Column") ; + break; + case 1 : + props.setPropertyValue("Orientation", + DataPilotFieldOrientation.ROW); + System.out.println(" Row") ; + break; + case 2 : + props.setPropertyValue("Orientation", + DataPilotFieldOrientation.DATA); + System.out.println(" Data") ; + break; + case 3 : + props.setPropertyValue("Orientation", + DataPilotFieldOrientation.HIDDEN); + System.out.println(" Hidden") ; + break; + case 4 : + props.setPropertyValue("Orientation", + DataPilotFieldOrientation.PAGE); + System.out.println(" Page") ; + props.setPropertyValue("CurrentPage", "20"); + break; + } } catch (com.sun.star.lang.WrappedTargetException e) { + e.printStackTrace(); + return false; + } catch (com.sun.star.lang.IllegalArgumentException e) { + e.printStackTrace(); + return false; + } catch (com.sun.star.beans.PropertyVetoException e) { + e.printStackTrace(); + return false; + } catch (com.sun.star.beans.UnknownPropertyException e) { + e.printStackTrace(); + return false; + } + if (++cnt > 4) + { + break; + } + } + else + { + return false; + } + } + + return bResult; + } + + /** + * Test calls the method and checks returned collection using the method + * CheckNames().

      + * Has OK status if the method CheckNames() returns true + * and no exceptions were thrown.

      + * The following method tests are to be completed successfully before : + *

        + *
      • getDataPilotFields() : to have array of field names
      • + *
      + */ + public boolean _getColumnFields(){ + System.out.println("getColumnFields") ; + XIndexAccess IA = oObj.getColumnFields(); + return CheckNames(IA, 0); + } + + /** + * Test calls the method and checks returned collection using the method + * CheckNames().

      + * Has OK status if the method CheckNames() returned true + * and no exceptions were thrown.

      + * The following method tests are to be completed successfully before : + *

        + *
      • getDataPilotFields() : to have array of field names
      • + *
      + */ + public boolean _getDataFields(){ + System.out.println("getDataFields") ; + XIndexAccess IA = oObj.getDataFields(); + return CheckNames(IA, 2); + } + + /** + * Test calls the method and checks returned collection using the method + * CheckNames().

      + * Has OK status if the method CheckNames() returned true + * and no exceptions were thrown.

      + * The following method tests are to be completed successfully before : + *

        + *
      • getDataPilotFields() : to have array of field names
      • + *
      + */ + public boolean _getHiddenFields(){ + System.out.println("getHiddenFields") ; + XIndexAccess IA = oObj.getHiddenFields(); + return CheckNames(IA, 3); + } + + /** + * Test calls the method and checks returned collection using the method + * CheckNames().

      + * Has OK status if the method CheckNames() returned true + * and no exceptions were thrown.

      + * The following method tests are to be completed successfully before : + *

        + *
      • getDataPilotFields() : to have array of field names
      • + *
      + */ + public boolean _getRowFields(){ + System.out.println("getRowFields") ; + XIndexAccess IA = oObj.getRowFields(); + boolean bResult = CheckNames(IA, 1); + return bResult; + } + + /** + * setting of PageFields isn't supported by StarOffice Calc + * Has OK status if the returned IndexAccess + * isn't NULL.

      + * The following method tests are to be completed successfully before : + *

        + *
      • getDataPilotFields() : to have array of field names
      • + *
      + */ + public boolean _getPageFields(){ + System.out.println("getPageFields") ; + XIndexAccess IA = oObj.getPageFields(); + boolean bResult = CheckNames(IA, 4); + return bResult; + } + + /** + * Test calls the method and checks returned value.

      + * Has OK status if returned value isn't null + * and no exceptions were thrown.

      + */ + public boolean _getFilterDescriptor(){ + boolean bResult = oObj.getFilterDescriptor() != null; + return bResult; + } + + /** + * Method checks that the field with index rem exists + * in the array IA. + * @param IA collection of elements that support interface XNamed + * @param rem index of field in the array of field names that was stored in + * the method getDataPilotFields() + * @return true if required field name exists in passed collection; + * false otherwise + * @see com.sun.star.container.XNamed + */ + private boolean CheckNames(XIndexAccess IA, int rem) { + String name = null; + + if (IA == null) { + System.out.println("Null returned.") ; + return false ; + } + + if (fieldsNames[rem] == null) { + System.out.println("No fields were set to this orientation - can't check result") ; + return true ; + } + + if (IA.getCount() == 0) { + System.out.println("No fields found. Must be at least '" + + fieldsNames[rem] + "'") ; + return false ; + } + + try { + System.out.println("Fields returned ") ; + for (int i = 0; i < IA.getCount(); i++) { + Object field = IA.getByIndex(i); + XNamed named = UnoRuntime.queryInterface + (XNamed.class, field); + name = named.getName(); + System.out.println(" " + name) ; + if (fieldsNames[rem].equals(name)) { + System.out.println(" - OK") ; + return true ; + } + } + } catch (com.sun.star.lang.WrappedTargetException e) { + e.printStackTrace(); + return false ; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + e.printStackTrace(); + return false ; + } + System.out.println(" - FAILED (field " + fieldsNames[rem] + " was not found.") ; + return false ; + } + + /** + * Recreates object(to back old orientations of the fields). + * + protected void after() { + disposeEnvironment(); + }*/ +} + diff --git a/sc/qa/complex/dataPilot/_XDataPilotTable.java b/sc/qa/complex/dataPilot/_XDataPilotTable.java new file mode 100644 index 000000000..1c29a0f77 --- /dev/null +++ b/sc/qa/complex/dataPilot/_XDataPilotTable.java @@ -0,0 +1,97 @@ +/* + * 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 complex.dataPilot; + +import com.sun.star.sheet.XDataPilotTable; +import com.sun.star.table.CellAddress; +import com.sun.star.table.CellRangeAddress; +import com.sun.star.table.XCell; +import lib.TestParameters; + +/** +* Testing com.sun.star.sheet.XDataPilotTable +* interface methods : +*

        +*
      • getOutputRange()
      • +*
      • refresh()
      • +*

      +* This test needs the following object relations : +*

        +*
      • 'OUTPUTRANGE' (of type CellAddress): +* to check value returned by method getOutputRange()
      • +*
      • 'CELLFORCHANGE' (of type XCell): +* to check the method refresh(value of this cell will be changed)
      • +*
      • 'CELLFORCHECK' (of type XCell): +* to check the method refresh (value of this cell must be changed after refresh +* call)
        • +* @see com.sun.star.sheet.XDataPilotTable +* @see com.sun.star.table.CellAddress +*/ +public class _XDataPilotTable { + + private final XDataPilotTable oObj; + private XCell xCellForChange = null; + private XCell xCellForCheck = null; + private CellAddress OutputRange = null; + + /** + * The test parameters + */ + private final TestParameters param; + + /** + * Constructor: gets the object to test, a logger and the test parameters + * @param xObj The test object + + * @param param The test parameters + */ + public _XDataPilotTable(XDataPilotTable xObj/*, + LogWriter log*/, TestParameters param) { + oObj = xObj; + this.param = param; + } + + public boolean before() { + xCellForChange = (XCell)param.get("CELLFORCHANGE"); + xCellForCheck = (XCell)param.get("CELLFORCHECK"); + OutputRange = (CellAddress)param.get("OUTPUTRANGE"); + + if (xCellForChange == null || OutputRange == null || + xCellForCheck == null) { + System.out.println("Relation not found"); + return false; + } + return true; + } + /** + * Test calls the method and checks returned value using value obtained by + * object relation 'OUTPUTRANGE'.

          + * Has OK status if values are equal.

          + */ + public boolean _getOutputRange(){ + boolean bResult = true; + CellRangeAddress objRange = oObj.getOutputRange(); + bResult &= OutputRange.Sheet == objRange.Sheet; + bResult &= OutputRange.Row == objRange.StartRow; + bResult &= OutputRange.Column == objRange.StartColumn; + return bResult; + } + +} + diff --git a/sc/qa/complex/dataPilot/_XNamed.java b/sc/qa/complex/dataPilot/_XNamed.java new file mode 100644 index 000000000..2161abdd0 --- /dev/null +++ b/sc/qa/complex/dataPilot/_XNamed.java @@ -0,0 +1,133 @@ +/* + * 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 complex.dataPilot; + +import com.sun.star.container.XNamed; +import lib.TestParameters; + +/** +* Testing com.sun.star.container.XNamed +* interface methods : +*

            +*
          • getName()
          • +*
          • setName()
          • +*
          +* This test need the following object relations : +*
            +*
          • 'setName' : of Boolean +* type. If it exists then setName method +* isn't to be tested and result of this test will be +* equal to relation value.
          • +*

              +* Test is NOT multithread compliant.

              +* @see com.sun.star.container.XNamed +*/ +public class _XNamed { + + /** + * The object that is testsed. + */ + private final XNamed oObj; + + /** + * Constructor: gets the object to test, a logger and the test parameters + * @param xObj The test object + * @param param The test parameters + */ + public _XNamed(XNamed xObj/*, LogWriter log*/, TestParameters param) { + oObj = xObj; + } + + /** + * Test calls the method and checks return value and that + * no exceptions were thrown.

              + * Has OK status if the method returns non null value + * and no exceptions were thrown.

              + */ + public boolean _getName() { + + // write to log what we try next + System.out.println( "test for getName()" ); + + boolean result = true; + boolean loc_result = true; + String name = null; + + loc_result = ((name = oObj.getName()) != null); + System.out.println("getting the name \"" + name + "\""); + + if (loc_result) + { + System.out.println("... getName() - OK"); + } + else + { + System.out.println("... getName() - FAILED"); + } + result &= loc_result; + return result; + } + + /** + * Sets a new name for object and checks if it was properly + * set. Special cases for the following objects : + *

                + *
              • ScSheetLinkObj : name must be in form of URL.
              • + *
              • ScDDELinkObj : name must contain link to cell in + * some external Sheet.
              • + *
              + * Has OK status if new name was successfully set, or if + * object environment contains relation 'setName' with + * value true.

              + * The following method tests are to be completed successfully before : + *

                + *
              • getName() : to be sure the method works
              • + *
              + */ + public boolean _setName(){ + System.out.println("testing setName() ... "); + + String oldName = oObj.getName(); + String NewName = oldName == null ? "XNamed" : oldName + "X" ; + + boolean result = true; + boolean loc_result = true; + System.out.println("set the name of object to \"" + NewName + "\""); + oObj.setName(NewName); + System.out.println("check that container has element with this name"); + + String name = oObj.getName(); + System.out.println("getting the name \"" + name + "\""); + loc_result = name.equals(NewName); + + if (loc_result) + { + System.out.println("... setName() - OK"); + } + else + { + System.out.println("... setName() - FAILED"); + } + result &= loc_result; + oObj.setName(oldName); + return result; + } +} + + diff --git a/sc/qa/complex/dataPilot/_XPropertySet.java b/sc/qa/complex/dataPilot/_XPropertySet.java new file mode 100644 index 000000000..c7174c975 --- /dev/null +++ b/sc/qa/complex/dataPilot/_XPropertySet.java @@ -0,0 +1,601 @@ +/* + * 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 complex.dataPilot; + +import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyAttribute; +import com.sun.star.beans.PropertyChangeEvent; +import com.sun.star.beans.XPropertyChangeListener; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.XPropertySetInfo; +import com.sun.star.beans.XVetoableChangeListener; +import com.sun.star.lang.EventObject; +import java.util.Random; +import java.util.StringTokenizer; +import lib.TestParameters; +import util.ValueChanger; +import util.utils; + +/** +* Testing com.sun.star.beans.XPropertySet +* interface methods : +*
                +*
              • getPropertySetInfo()
              • +*
              • setPropertyValue()
              • +*
              • getPropertyValue()
              • +*
              • addPropertyChangeListener()
              • +*
              • removePropertyChangeListener()
              • +*
              • addVetoableChangeListener()
              • +*
              • removeVetoableChangeListener()
              • +*
              +* @see com.sun.star.beans.XPropertySet +*/ +public class _XPropertySet { + + /** + * The object that is testsed. + */ + private final XPropertySet oObj; + + /** + * The test parameters + */ + private final TestParameters param; + + /** + * Flag that indicates change listener was called. + */ + private boolean propertyChanged = false; + + + /** + * The own property change listener + */ + private final XPropertyChangeListener PClistener = new MyChangeListener(); + + /** + * Listener that must be called on bound property changing. + */ + private class MyChangeListener implements XPropertyChangeListener { + /** + * Just set propertyChanged flag to true. + */ + public void propertyChange(PropertyChangeEvent e) { + propertyChanged = true; + } + public void disposing (EventObject obj) {} + } + + + /** + * Flag that indicates veto listener was called. + */ + private boolean vetoableChanged = false; + + /** + * The own vetoable change listener + */ + private final XVetoableChangeListener VClistener = new MyVetoListener(); + + /** + * Listener that must be called on constrained property changing. + */ + private class MyVetoListener implements XVetoableChangeListener { + /** + * Just set vetoableChanged flag to true. + */ + public void vetoableChange(PropertyChangeEvent e) { + vetoableChanged = true; + } + public void disposing (EventObject obj) {} + } + + + /** + * Properties to test + */ + private final PropsToTest PTT = new PropsToTest(); + + /** + * Structure that collects three properties of each type to test : + * Constrained, Bound and Normal. + */ + private class PropsToTest { + private String constrained = null; + private String bound = null; + String normal = null; + } + + /** + * Constructor: gets the object to test, a logger and the test parameters + * @param xObj The test object + * @param param The test parameters + */ + public _XPropertySet(XPropertySet xObj/*, LogWriter log*/, TestParameters param) { + oObj = xObj; + // this.log = log; + this.param = param; + } + + /** + * Tests method getPropertySetInfo. After test completed + * call {@link #getPropsToTest} method to retrieve different kinds + * of properties to test then.

              + * Has OK status if not null XPropertySetInfo + * object returned.

              + * Since getPropertySetInfo is optional, it may return null, + * if it is not implemented. This method uses then an object relation + * PTT (Properties To Test) to determine available properties. + * All tests for services without getPropertySetInfo must + * provide this object relation. + */ + public boolean _getPropertySetInfo() { + XPropertySetInfo propertySetInfo = oObj.getPropertySetInfo(); + + if (propertySetInfo == null) { + System.out.println("getPropertySetInfo() method returned null"); + String[] ptt = (String[]) param.get("PTT"); + PTT.normal=ptt[0]; + PTT.bound=ptt[1]; + PTT.constrained=ptt[2]; + } else { + getPropsToTest(propertySetInfo); + } + + return true; + + } // end of getPropertySetInfo() + + /** + * Tests change listener which added for bound properties. + * Adds listener to bound property (if it exists), then changes + * its value and check if listener was called.

              + * Method tests to be successfully completed before : + *

                + *
              • getPropertySetInfo : in this method test + * one of bound properties is retrieved.
              • + *

              + * Has OK status if NO bound properties exist or if listener + * was successfully called. + */ + public boolean _addPropertyChangeListener() { + + propertyChanged = false; + boolean result = true; + + if ( PTT.bound.equals("none") ) { + System.out.println("*** No bound properties found ***"); + } else { + try { + oObj.addPropertyChangeListener(PTT.bound,PClistener); + Object gValue = oObj.getPropertyValue(PTT.bound); + oObj.setPropertyValue(PTT.bound, + ValueChanger.changePValue(gValue)); + } catch (com.sun.star.beans.PropertyVetoException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.bound+"'"); + e.printStackTrace(); + } catch (com.sun.star.lang.IllegalArgumentException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.bound+"'"); + e.printStackTrace(); + } catch (com.sun.star.beans.UnknownPropertyException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.bound+"'"); + e.printStackTrace(); + } catch (com.sun.star.lang.WrappedTargetException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.bound+"'"); + e.printStackTrace(); + } // end of try-catch + result = propertyChanged; + if (!propertyChanged) { + System.out.println("propertyChangeListener wasn't called for '"+ + PTT.bound+"'"); + } + } //endif + + return result; + + } // end of addPropertyChangeListener() + + /** + * Tests vetoable listener which added for constrained properties. + * Adds listener to constrained property (if it exists), then changes + * its value and check if listener was called.

              + * Method tests to be successfully completed before : + *

                + *
              • getPropertySetInfo : in this method test + * one of constrained properties is retrieved.
              • + *

              + * Has OK status if NO constrained properties exist or if listener + * was successfully called. + */ + public boolean _addVetoableChangeListener() { + + vetoableChanged = false; + boolean result = true; + + if ( PTT.constrained.equals("none") ) { + System.out.println("*** No constrained properties found ***"); + } else { + try { + oObj.addVetoableChangeListener(PTT.constrained,VClistener); + Object gValue = oObj.getPropertyValue(PTT.constrained); + oObj.setPropertyValue(PTT.constrained, + ValueChanger.changePValue(gValue)); + } catch (com.sun.star.beans.PropertyVetoException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.constrained+"'"); + e.printStackTrace(); + } catch (com.sun.star.lang.IllegalArgumentException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.constrained+"'"); + e.printStackTrace(); + } catch (com.sun.star.beans.UnknownPropertyException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.constrained+"'"); + e.printStackTrace(); + } catch (com.sun.star.lang.WrappedTargetException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.constrained+"'"); + e.printStackTrace(); + } // end of try-catch + result = vetoableChanged; + if (!vetoableChanged) { + System.out.println("vetoableChangeListener wasn't called for '"+ + PTT.constrained+"'"); + } + } //endif + + return result; + + } // end of addVetoableChangeListener() + + + /** + * Tests setPropertyValue method. + * Stores value before call, and compares it with value after + * call.

              + * Method tests to be successfully completed before : + *

                + *
              • getPropertySetInfo : in this method test + * one of normal properties is retrieved.
              • + *

              + * Has OK status if NO normal properties exist or if value before + * method call is not equal to value after. + */ + public boolean _setPropertyValue() { + + Object gValue = null; + Object sValue = null; + + boolean result = true; + + if ( PTT.normal.equals("none") ) { + System.out.println("*** No changeable properties found ***"); + } else { + try { + gValue = oObj.getPropertyValue(PTT.normal); + sValue = ValueChanger.changePValue(gValue); + oObj.setPropertyValue(PTT.normal, sValue); + sValue = oObj.getPropertyValue(PTT.normal); + } catch (com.sun.star.beans.PropertyVetoException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.normal+"'"); + e.printStackTrace(); + } catch (com.sun.star.lang.IllegalArgumentException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.normal+"'"); + e.printStackTrace(); + } catch (com.sun.star.beans.UnknownPropertyException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.normal+"'"); + e.printStackTrace(); + } catch (com.sun.star.lang.WrappedTargetException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.normal+"'"); + e.printStackTrace(); + } // end of try-catch + result = !gValue.equals(sValue); + } //endif + + return result; + + } // end of setPropertyValue() + + /** + * Tests getPropertyValue method. + * Just call this method and checks for no exceptions

              + * Method tests to be successfully completed before : + *

                + *
              • getPropertySetInfo : in this method test + * one of normal properties is retrieved.
              • + *

              + * Has OK status if NO normal properties exist or if no + * exceptions were thrown. + */ + public boolean _getPropertyValue() { + + boolean result = true; + String toCheck = PTT.normal; + + if ( PTT.normal.equals("none") ) { + toCheck = oObj.getPropertySetInfo().getProperties()[0].Name; + System.out.println("All properties are Read Only"); + System.out.println("Using: "+toCheck); + } + + try { + oObj.getPropertyValue(toCheck); + } catch (com.sun.star.beans.UnknownPropertyException e) { + System.out.println("Exception occurred while trying to get property '"+ + PTT.normal+"'"); + e.printStackTrace(); + result = false; + } catch (com.sun.star.lang.WrappedTargetException e) { + System.out.println("Exception occurred while trying to get property '"+ + PTT.normal+"'"); + e.printStackTrace(); + result = false; + } // end of try-catch + + return result; + } + + /** + * Tests removePropertyChangeListener method. + * Removes change listener, then changes bound property value + * and checks if the listener was NOT called. + * Method tests to be successfully completed before : + *

                + *
              • addPropertyChangeListener : here listener + * was added.
              • + *

              + * Has OK status if NO bound properties exist or if listener + * was not called and no exceptions arose. + */ + public boolean _removePropertyChangeListener() { + + propertyChanged = false; + boolean result = true; + + if ( PTT.bound.equals("none") ) { + System.out.println("*** No bound properties found ***"); + } else { + try { + propertyChanged = false; + oObj.removePropertyChangeListener(PTT.bound,PClistener); + Object gValue = oObj.getPropertyValue(PTT.bound); + oObj.setPropertyValue(PTT.bound, + ValueChanger.changePValue(gValue)); + } catch (com.sun.star.beans.PropertyVetoException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.bound+"'"); + e.printStackTrace(); + } catch (com.sun.star.lang.IllegalArgumentException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.bound+"'"); + e.printStackTrace(); + } catch (com.sun.star.beans.UnknownPropertyException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.bound+"'"); + e.printStackTrace(); + } catch (com.sun.star.lang.WrappedTargetException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.bound+"'"); + e.printStackTrace(); + } // end of try-catch + + result = !propertyChanged; + if (propertyChanged) { + System.out.println("propertyChangeListener was called after removing"+ + " for '"+PTT.bound+"'"); + } + } //endif + + return result; + + } // end of removePropertyChangeListener() + + + /** + * Tests removeVetoableChangeListener method. + * Removes vetoable listener, then changes constrained property value + * and checks if the listener was NOT called. + * Method tests to be successfully completed before : + *

                + *
              • addPropertyChangeListener : here vetoable listener + * was added.
              • + *

              + * Has OK status if NO constrained properties exist or if listener + * was NOT called and no exceptions arose. + */ + public boolean _removeVetoableChangeListener() { + + vetoableChanged = false; + boolean result = true; + + if ( PTT.constrained.equals("none") ) { + System.out.println("*** No constrained properties found ***"); + } else { + try { + oObj.removeVetoableChangeListener(PTT.constrained,VClistener); + Object gValue = oObj.getPropertyValue(PTT.constrained); + oObj.setPropertyValue(PTT.constrained, + ValueChanger.changePValue(gValue)); + } catch (com.sun.star.beans.PropertyVetoException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.constrained+"'"); + e.printStackTrace(); + } catch (com.sun.star.lang.IllegalArgumentException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.constrained+"'"); + e.printStackTrace(); + } catch (com.sun.star.beans.UnknownPropertyException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.constrained+"'"); + e.printStackTrace(); + } catch (com.sun.star.lang.WrappedTargetException e) { + System.out.println("Exception occurred while trying to change "+ + "property '"+ PTT.constrained+"'"); + e.printStackTrace(); + } // end of try-catch + + result = !vetoableChanged; + if (vetoableChanged) { + System.out.println("vetoableChangeListener was called after "+ + "removing for '"+PTT.constrained+"'"); + } + } //endif + + return result; + + } // end of removeVetoableChangeListener() + + + /** + * Gets the properties being tested. Searches and stores by one + * property of each kind (Bound, Vetoable, Normal). + */ + private PropsToTest getPropsToTest(XPropertySetInfo xPSI) { + + Property[] properties = xPSI.getProperties(); + String bound = ""; + String constrained = ""; + String normal = ""; + + for (int i = 0; i < properties.length; i++) { + + Property property = properties[i]; + String name = property.Name; + System.out.println("Checking '"+name+"'"); + boolean isWritable = ((property.Attributes & + PropertyAttribute.READONLY) == 0); + boolean isNotNull = ((property.Attributes & + PropertyAttribute.MAYBEVOID) == 0); + boolean isBound = ((property.Attributes & + PropertyAttribute.BOUND) != 0); + boolean isConstr = ((property.Attributes & + PropertyAttribute.CONSTRAINED) != 0); + boolean canChange = false; + + if ( !isWritable ) System.out.println("Property '"+name+"' is READONLY"); + + if (name.endsWith("URL")) isWritable = false; + if (name.startsWith("Fill")) isWritable = false; + if (name.startsWith("Font")) isWritable = false; + if (name.startsWith("IsNumbering")) isWritable = false; + if (name.startsWith("LayerName")) isWritable = false; + if (name.startsWith("Line")) isWritable = false; + + if ( isWritable && isNotNull ) canChange = isChangeable(name); + + if ( isWritable && isNotNull && isBound && canChange) { + bound+=name+";"; + } + + if ( isWritable && isNotNull && isConstr && canChange) { + constrained+=name+";"; + } + + if ( isWritable && isNotNull && canChange) normal+=name+";"; + + + } // endfor + + //get a random bound property + PTT.bound=getRandomString(bound); + System.out.println("Bound: "+PTT.bound); + + //get a random constrained property + PTT.constrained=getRandomString(constrained); + System.out.println("Constrained: "+PTT.constrained); + + //get a random normal property + PTT.normal=getRandomString(normal); + + return PTT; + + } + + /** + * Retrieves one random property name from list (property names separated + * by ';') of property names. + */ + private String getRandomString(String str) { + + String gRS = "none"; + Random rnd = new Random(); + + if (str.equals("")) str = "none"; + StringTokenizer ST=new StringTokenizer(str,";"); + int nr = rnd.nextInt(ST.countTokens()); + if (nr < 1) nr+=1; + for (int i=1; i + * (REMARK: the testcases expects the TableLayout to be LR_TB) + *
              + * 1. A calc document is opened and the properties in css.sheet.Spreadsheet are checked + *
              + * 2. A calc document is opened and a shape inserted, afterwards the properties in css.sheet.Shape are checked + *
              + * 3. A calc document is opened and a shape inserted, afterwards the effect of changing the TableLayout to the shape is checked + */ + + /* + * In this method a spreadsheet document is opened and a shape inserted
              + * afterwards all calc specific properties of the Shape are checked.
              + *

              + * These are + *

                + *
              • Anchor + *
              • HoriOrientPosition + *
              • VertOrientPosition + *
              + */ + @Test public void checkShapeProperties() { + assertTrue("Couldn't open document", openSpreadsheetDocument()); + + XPropertySet set = UnoRuntime.queryInterface( + XPropertySet.class, getInsertedShape()); + + try { + assertTrue("Problems when setting property 'Anchor'", + changeProperty(set, "Anchor", + getSpreadsheet().getCellByPosition(5, 5))); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + // assure("Problems when setting property 'Anchor'", false); + fail("Problems when setting property 'Anchor'"); + } + + assertTrue("Problems when setting property 'HoriOrientPosition'", + changeProperty(set, "HoriOrientPosition", Integer.valueOf(1000))); + + assertTrue("Problems when setting property 'VertOrientPosition'", + changeProperty(set, "VertOrientPosition", Integer.valueOf(1000))); + + assertTrue("Couldn't close document", closeSpreadsheetDocument()); + } + + @Test public void checkInfluenceOfSpreadsheetChange() { + assertTrue("Couldn't open document", openSpreadsheetDocument()); + + XShape oShape = getInsertedShape(); + XPropertySet sheetProps = UnoRuntime.queryInterface( + XPropertySet.class, getSpreadsheet()); + XPropertySet shapeProps = UnoRuntime.queryInterface( + XPropertySet.class, oShape); + + String[] previous = getShapeProps(shapeProps, oShape); + assertTrue("Problems when setting property 'TableLayout'", + changeProperty(sheetProps, "TableLayout", + Short.valueOf(com.sun.star.text.WritingMode2.RL_TB))); + + String[] RL_TB = getShapeProps(shapeProps, oShape); + assertTrue("Problems when setting property 'TableLayout'", + changeProperty(sheetProps, "TableLayout", + Short.valueOf(com.sun.star.text.WritingMode2.LR_TB))); + + String[] LR_TB = getShapeProps(shapeProps, oShape); + assertTrue("Anchor has changed", + (previous[0].equals(RL_TB[0]) && previous[0].equals(LR_TB[0]))); + assertEquals("HoriOrientPosition has changed", + 2100, Integer.parseInt(previous[1]) + Integer.parseInt(RL_TB[1]) + + Integer.parseInt(LR_TB[1])); + assertEquals("VertOrientPosition has changed", + 3*Integer.parseInt(previous[2]), + (Integer.parseInt(previous[2]) + Integer.parseInt(RL_TB[2]) + + Integer.parseInt(LR_TB[2]))); + assertTrue("x-position hasn't changed", + (previous[3].equals(LR_TB[3]) && + ((Integer.parseInt(previous[3]) * (-1)) - + oShape.getSize().Width != Integer.parseInt(LR_TB[2])))); + assertTrue("Couldn't close document", closeSpreadsheetDocument()); + } + + protected String[] getShapeProps(XPropertySet set, XShape oShape) { + String[] reValue = new String[4]; + + try { + reValue[0] = toString(getRealValue(set.getPropertyValue("Anchor"))); + reValue[1] = toString(set.getPropertyValue("HoriOrientPosition")); + reValue[2] = toString(set.getPropertyValue("VertOrientPosition")); + reValue[3] = toString(Integer.valueOf(oShape.getPosition().X)); + } catch (com.sun.star.beans.UnknownPropertyException e) { + } catch (com.sun.star.lang.WrappedTargetException e) { + } + + System.out.println("\t Anchor :" + reValue[0]); + System.out.println("\t HoriOrientPosition :" + reValue[1]); + System.out.println("\t VertOrientPosition :" + reValue[2]); + System.out.println("\t Shape Position (x,y) : (" + oShape.getPosition().X + + "," + oShape.getPosition().Y + ")"); + + return reValue; + } + + /* + * this method opens a calc document and sets the corresponding class variable xSheetDoc + */ + protected boolean openSpreadsheetDocument() { + final XMultiServiceFactory xMsf = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); + SOfficeFactory SOF = SOfficeFactory.getFactory(xMsf); + + boolean worked = true; + + try { + System.out.println("creating a sheetdocument"); + xSheetDoc = SOF.createCalcDoc(null); + } catch (com.sun.star.uno.Exception e) { + // Some exception occurs.FAILED + worked = false; + e.printStackTrace(/*(PrintWriter) log*/ System.err); + } + + return worked; + } + + /* + * this method closes a calc document and resets the corresponding class variable xSheetDoc + */ + protected boolean closeSpreadsheetDocument() { + boolean worked = true; + + System.out.println(" disposing xSheetDoc "); + + try { + XCloseable oCloser = UnoRuntime.queryInterface( + XCloseable.class, xSheetDoc); + oCloser.close(true); + } catch (com.sun.star.util.CloseVetoException e) { + worked = false; + System.out.println("Couldn't close document"); + } catch (com.sun.star.lang.DisposedException e) { + worked = false; + System.out.println("Document already disposed"); + } catch (NullPointerException e) { + worked = false; + System.out.println("Couldn't get XCloseable"); + } + + xSheetDoc = null; + + return worked; + } + + /* + * This method gets the first Sheet of the SpreadsheetDocument + * + */ + protected XSpreadsheet getSpreadsheet() { + XSpreadsheet oSheet = null; + + System.out.println("getting sheets"); + + XSpreadsheets xSpreadsheets = xSheetDoc.getSheets(); + + System.out.println("getting a sheet"); + + XIndexAccess oIndexAccess = UnoRuntime.queryInterface( + XIndexAccess.class, xSpreadsheets); + + try { + oSheet = UnoRuntime.queryInterface( + XSpreadsheet.class, oIndexAccess.getByIndex(0)); + } catch (com.sun.star.lang.WrappedTargetException e) { + e.printStackTrace(System.err); + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + e.printStackTrace(System.err); + } + + return oSheet; + } + + /* + * This method changes a given property to a given value + * Parameters: + * @param set : The XPropertySet that contains the properties + * @param pName : The name of the Property that has to be changed + * @param pValue : The value, the property should be changed too. + */ + protected boolean changeProperty(XPropertySet set, String pName, + Object pValue) { + boolean worked = true; + + try { + Object oldValue = set.getPropertyValue(pName); + + // for an exception thrown during setting new value + // to pass it to checkResult method + Exception exception = null; + + try { + set.setPropertyValue(pName, pValue); + } catch (IllegalArgumentException e) { + exception = e; + } catch (PropertyVetoException e) { + exception = e; + } catch (WrappedTargetException e) { + exception = e; + } catch (UnknownPropertyException e) { + exception = e; + } catch (RuntimeException e) { + exception = e; + } + + // getting result value + Object resValue = set.getPropertyValue(pName); + + + // checking results + worked = checkResult(set, pName, oldValue, pValue, resValue, + exception); + } catch (Exception e) { + System.out.println("Exception occurred while testing property '" + + pName + "'"); + e.printStackTrace(); + worked = false; + } + + return worked; + } + + /* + * This methods checks if a property has changed as expected + * Parameters: + * @param set : the given XPropertySet + * @param propName : the name of the property that has been changed + * @param oldValue : the value of the property before it has been changed + * @param newValue : the value the property has been set to + * @param resValue : the value getPropertyValue returned for the property + * @param exception : the exception thrown during the change of the property + */ + protected boolean checkResult(XPropertySet set, String propName, + Object oldValue, Object newValue, + Object resValue, Exception exception) + throws Exception { + XPropertySetInfo info = set.getPropertySetInfo(); + Property prop = info.getPropertyByName(propName); + + oldValue = getRealValue(oldValue); + newValue = getRealValue(newValue); + resValue = getRealValue(resValue); + + boolean readOnly = (prop.Attributes & PropertyAttribute.READONLY) != 0; + boolean maybeVoid = (prop.Attributes & PropertyAttribute.MAYBEVOID) != 0; + + //check get-set methods + if (maybeVoid) { + System.out.println("Property " + propName + " is void"); + } + + if (readOnly) { + System.out.println("Property " + propName + " is readOnly"); + } + + if (util.utils.isVoid(oldValue) && !maybeVoid) { + System.out.println(propName + " is void, but it's not MAYBEVOID"); + + return false; + } else if (oldValue == null) { + System.out.println(propName + + " has null value, and therefore can't be changed"); + + return true; + } else if (readOnly) { + // check if exception was thrown + if (exception != null) { + if (exception instanceof PropertyVetoException) { + // the change of read only prohibited - OK + System.out.println("Property is ReadOnly and wasn't changed"); + System.out.println("Property '" + propName + "' OK"); + + return true; + } else if (exception instanceof IllegalArgumentException) { + // the change of read only prohibited - OK + System.out.println("Property is ReadOnly and wasn't changed"); + System.out.println("Property '" + propName + "' OK"); + + return true; + } else if (exception instanceof UnknownPropertyException) { + // the change of read only prohibited - OK + System.out.println("Property is ReadOnly and wasn't changed"); + System.out.println("Property '" + propName + "' OK"); + + return true; + } else if (exception instanceof RuntimeException) { + // the change of read only prohibited - OK + System.out.println("Property is ReadOnly and wasn't changed"); + System.out.println("Property '" + propName + "' OK"); + + return true; + } else { + throw exception; + } + } else { + // if no exception - check that value + // has not changed + if (!ValueComparer.equalValue(resValue, oldValue)) { + System.out.println("Read only property '" + propName + + "' has changed"); + + System.out.println("old = " + toString(oldValue)); + System.out.println("new = " + toString(newValue)); + System.out.println("result = " + toString(resValue)); + + return false; + } else { + System.out.println("Read only property '" + propName + + "' hasn't changed"); + System.out.println("Property '" + propName + "' OK"); + + return true; + } + } + } else { + if (exception == null) { + // if no exception thrown + // check that the new value is set + if (!ValueComparer.equalValue(resValue, newValue)) { + System.out.println("Value for '" + propName + + "' hasn't changed as expected"); + + System.out.println("old = " + toString(oldValue)); + System.out.println("new = " + toString(newValue)); + System.out.println("result = " + toString(resValue)); + + if (!ValueComparer.equalValue(resValue, oldValue)) { + System.out.println("But it has changed."); + return true; + } else { + return false; + } + } else { + System.out.println("Property '" + propName + "' OK"); + + System.out.println("old = " + toString(oldValue)); + System.out.println("new = " + toString(newValue)); + System.out.println("result = " + toString(resValue)); + + return true; + } + } else { + throw exception; + } + } + } + + /* + * Returns a String representation of a given object, returns "null" in case of a NullObject + * @param obj : the given object + */ + protected String toString(Object obj) { + return (obj == null) ? "null" : obj.toString(); + } + + /* + * Returns a human readable String representation for CellRangeAddressable + */ + protected Object getRealValue(Object obj) { + Object value = null; + + if (UnoRuntime.queryInterface(XCellRangeAddressable.class, obj) != null) { + XCellRangeAddressable aCell = UnoRuntime.queryInterface( + XCellRangeAddressable.class, + obj); + value = "Cell in Column " + aCell.getRangeAddress().StartColumn + + " and Row " + aCell.getRangeAddress().StartRow; + } else { + return obj; + } + + return value; + } + + /* + * This method inserts a RectangleShape into the calc document xSheetDoc and returns the resulting XShape-object + */ + protected XShape getInsertedShape() { + XShape insertedShape = null; + + try { + System.out.println("getting Drawpages"); + + XDrawPagesSupplier oDPS = UnoRuntime.queryInterface( + XDrawPagesSupplier.class, + xSheetDoc); + XDrawPages oDP = oDPS.getDrawPages(); + XDrawPage firstDrawPage = UnoRuntime.queryInterface( + XDrawPage.class, + oDP.getByIndex(0)); + + final XMultiServiceFactory xMsf = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); + SOfficeFactory SOF = SOfficeFactory.getFactory(xMsf); + + XComponent xComp = UnoRuntime.queryInterface( + XComponent.class, xSheetDoc); + insertedShape = SOF.createShape(xComp, 5000, 3500, 700, 500, + "Rectangle"); + DrawTools.getShapes(firstDrawPage).add(insertedShape); + } catch (com.sun.star.lang.WrappedTargetException e) { + System.out.println("Couldn't create instance"); + e.printStackTrace(); + + return null; + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + System.out.println("Couldn't create instance"); + e.printStackTrace(); + + return null; + } + + return insertedShape; + } + + + + + @BeforeClass public static void setUpConnection() throws Exception { + connection.setUp(); + } + + @AfterClass public static void tearDownConnection() + throws InterruptedException, com.sun.star.uno.Exception + { + connection.tearDown(); + } + + private static final OfficeConnection connection = new OfficeConnection(); + +} -- cgit v1.2.3