Exemplo n.º 1
0
    /**
     * This method clicks into the middle of a document. It uses Accessibility to get the document
     * and query for its position and its range to calculate the middle. This values was used for
     * <CODE>Robot</CODE> Class. This Robot class is able to move the mouse and to click a mouse
     * button
     *
     * @see java.awt.Robot
     */
    private void clickIntoDoc() {
      try {
        // get the position and the range of a scroll bar

        XWindow xWindow = AccessibilityTools.getCurrentWindow(xModel);

        XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);

        XAccessibleContext xPanel =
            AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL);
        XAccessibleComponent xPanelCont =
            UnoRuntime.queryInterface(XAccessibleComponent.class, xPanel);

        // the position of the panel
        Point point = xPanelCont.getLocationOnScreen();

        // the range of the panel
        Rectangle rect = xPanelCont.getBounds();

        try {
          Robot rob = new Robot();
          int x = point.X + (rect.Width / 2);
          int y = point.Y + (rect.Height / 2);
          System.out.println("try to click into the middle of the document");
          rob.mouseMove(x, y);
          rob.mousePress(InputEvent.BUTTON1_MASK);
          rob.mouseRelease(InputEvent.BUTTON1_MASK);
        } catch (java.awt.AWTException e) {
          System.out.println("couldn't press mouse button");
        }
      } catch (java.lang.Exception e) {
        System.out.println("could not click into the scroll bar: " + e.toString());
      }
    }
  /** Disposes Writer document. */
  protected void cleanup(TestParameters tParam, PrintWriter log) {
    // closing the appearing dialog before disposing the document
    XInterface toolkit = null;

    try {
      toolkit =
          (XInterface)
              ((XMultiServiceFactory) 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);

    Object atw = tk.getActiveTopWindow();

    XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, atw);

    XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);

    XInterface button =
        AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON);

    XAccessibleAction action = UnoRuntime.queryInterface(XAccessibleAction.class, button);

    try {
      action.doAccessibleAction(0);
    } catch (com.sun.star.lang.IndexOutOfBoundsException iob) {
      log.println("couldn't close dialog");
    } catch (com.sun.star.lang.DisposedException e) {
      log.println("couldn't close dialog");
    }

    log.println("    disposing xTextDoc ");

    try {
      XCloseable closer = UnoRuntime.queryInterface(XCloseable.class, xTextDoc);
      closer.close(true);
    } catch (com.sun.star.util.CloseVetoException e) {
      log.println("couldn't close document");
    } catch (com.sun.star.lang.DisposedException e) {
      log.println("couldn't close document");
    }
  }
Exemplo n.º 3
0
  /**
   * Called to create an instance of <code>TestEnvironment</code> with an object to test and related
   * objects. Subclasses should implement this method to provide the implementation and related
   * objects. The method is called from <code>getTestEnvironment()</code>.
   *
   * @param tParam test parameters
   * @param log writer to log information while testing
   * @see TestEnvironment
   * @see #getTestEnvironment
   */
  @Override
  protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log)
      throws Exception {

    log.println("creating a test environment");

    if (xTextDoc != null) {
      xTextDoc.dispose(); // get a soffice factory object
    }
    SOfficeFactory SOF = SOfficeFactory.getFactory(tParam.getMSF());

    log.println("creating a text document");
    xTextDoc = SOF.createTextDoc(null);

    util.utils.waitForEventIdle(tParam.getMSF());

    XModel aModel1 = UnoRuntime.queryInterface(XModel.class, xTextDoc);

    XController secondController = aModel1.getCurrentController();

    XDispatchProvider aProv = UnoRuntime.queryInterface(XDispatchProvider.class, secondController);

    XDispatch getting = null;

    log.println("opening DatasourceBrowser");
    URL the_url = new URL();
    the_url.Complete = ".component:DB/DataSourceBrowser";
    getting = aProv.queryDispatch(the_url, "_beamer", 12);
    PropertyValue[] noArgs = new PropertyValue[0];
    getting.dispatch(the_url, noArgs);

    util.utils.waitForEventIdle(tParam.getMSF());

    XFrame the_frame1 = the_Desk.getCurrentFrame();

    if (the_frame1 == null) {
      log.println("Current frame was not found !!!");
    }

    XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);

    the_frame2.setName("DatasourceBrowser");

    XInterface oObj = null;

    final XSelectionSupplier xSelect =
        UnoRuntime.queryInterface(XSelectionSupplier.class, the_frame2.getController());

    PropertyValue[] params =
        new PropertyValue[] {new PropertyValue(), new PropertyValue(), new PropertyValue()};
    params[0].Name = "DataSourceName";
    params[0].Value = "Bibliography";
    params[1].Name = "CommandType";
    params[1].Value = Integer.valueOf(com.sun.star.sdb.CommandType.TABLE);
    params[2].Name = "Command";
    params[2].Value = "biblio";

    final PropertyValue[] fParams = params;

    util.utils.waitForEventIdle(tParam.getMSF());

    XWindow xWindow = secondController.getFrame().getContainerWindow();

    XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);

    AccessibilityTools.printAccessibleTree(
        log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));

    oObj =
        AccessibilityTools.getAccessibleObjectForRole(
            xRoot, AccessibleRole.PANEL, "", "AccessibleBrowseBox");

    log.println("ImplementationName: " + util.utils.getImplName(oObj));

    TestEnvironment tEnv = new TestEnvironment(oObj);

    tEnv.addObjRelation(
        "EventProducer",
        new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {

          public void fireEvent() {
            try {
              xSelect.select(fParams);
            } catch (com.sun.star.lang.IllegalArgumentException e) {
              e.printStackTrace();
            }
          }
        });

    return tEnv;
  }
  /**
   * Called to create an instance of <code>TestEnvironment</code> with an object to test and related
   * objects. Creates a frame and inserts it into document. Obtains accessible object for the
   * inserted text frame.
   *
   * @param Param test parameters
   * @param log writer to log information while testing
   * @see TestEnvironment
   * @see #getTestEnvironment
   */
  protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {

    XInterface oObj = null;
    XTextFrame oFrame1 = null;
    XPropertySet oPropSet = null;
    XText oText = null;
    XTextCursor oCursor = null;

    // get a soffice factory object
    SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory) Param.getMSF());
    // creating Frames
    log.println("creating Frames");
    try {
      oFrame1 = SOfficeFactory.createTextFrame(xTextDoc, 500, 500);
      oPropSet = UnoRuntime.queryInterface(XPropertySet.class, oFrame1);
      oPropSet.setPropertyValue("AnchorType", TextContentAnchorType.AS_CHARACTER);
      oText = xTextDoc.getText();
      oCursor = oText.createTextCursor();

      log.println("inserting Frame1");
      XTextContent the_content = UnoRuntime.queryInterface(XTextContent.class, oFrame1);
      oText.insertTextContent(oCursor, the_content, true);
    } catch (Exception e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't insert TextFrame", e);
    }

    XModel aModel = UnoRuntime.queryInterface(XModel.class, xTextDoc);

    AccessibilityTools at = new AccessibilityTools();

    XWindow xWindow =
        AccessibilityTools.getCurrentWindow((XMultiServiceFactory) Param.getMSF(), aModel);
    XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);

    oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TEXT_FRAME);

    log.println("ImplementationName " + utils.getImplName(oObj));
    AccessibilityTools.printAccessibleTree(
        log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));

    TestEnvironment tEnv = new TestEnvironment(oObj);

    XController xController = xTextDoc.getCurrentController();
    XViewSettingsSupplier xViewSetSup =
        UnoRuntime.queryInterface(XViewSettingsSupplier.class, xController);

    final XPropertySet PropSet = xViewSetSup.getViewSettings();

    tEnv.addObjRelation(
        "EventProducer",
        new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
          public void fireEvent() {
            try {
              // change zoom value to 15%
              PropSet.setPropertyValue("ZoomValue", new Short("15"));
              // and back to 100%
              PropSet.setPropertyValue("ZoomValue", new Short("100"));
            } catch (com.sun.star.lang.WrappedTargetException e) {

            } catch (com.sun.star.lang.IllegalArgumentException e) {

            } catch (com.sun.star.beans.PropertyVetoException e) {

            } catch (com.sun.star.beans.UnknownPropertyException e) {

            }
          }
        });

    return tEnv;
  }
  /**
   * 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");
    new AccessibilityTools();
    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;
  }