/**
   * Creating a Testenvironment for the interfaces to be tested. Creates an instance of the service
   * <code>com.sun.star.ucprmt.ContentProvider</code>.
   *
   * <p>Object relations created :
   *
   * <ul>
   *   <li><code>'FACTORY'</code> for {@link ifc.ucb._XContentProvider} factory for content
   *       identifiers. Here it is <code>UniversalContentBroker</code> service.
   *   <li><code>'CONTENT1'</code> for {@link ifc.ucb._XContentProvider}: suitable content URL for
   *       this provider
   *   <li><code>'CONTENT2'</code> for {@link ifc.ucb._XContentProvider}: another suitable content
   *       URL for this provider
   * </ul>
   */
  public TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
    XInterface oObj = null;
    XMultiServiceFactory xMSF = (XMultiServiceFactory) Param.getMSF();
    XContentIdentifierFactory cntIDFac = null;

    try {
      oObj = (XInterface) xMSF.createInstance("com.sun.star.ucb.RemoteAccessContentProvider");
      cntIDFac = UnoRuntime.queryInterface(XContentIdentifierFactory.class, oObj);
    } catch (com.sun.star.uno.Exception e) {
      log.println("Can't create an object.");
      throw new StatusException("Can't create an object", e);
    }

    if (oObj == null) {
      log.println("!!! Object wasn't created !!!");
      throw new StatusException(Status.failed("!!! Object wasn't created !!!"));
    }

    TestEnvironment tEnv = new TestEnvironment(oObj);

    // adding relation for XContentProvider
    tEnv.addObjRelation("FACTORY", cntIDFac);
    tEnv.addObjRelation("CONTENT1", "vnd.sun.star.wfs:///user/work");
    tEnv.addObjRelation("CONTENT2", "vnd.sun.star.wfs:///user/config");

    return tEnv;
  } // finish method getTestEnvironment
Beispiel #2
0
  /**
   * Creates an instance of the service <code>com.sun.star.sdbc.Driver</code>.
   *
   * <p>Object relations created :
   *
   * <ul>
   *   <li><code>'XDriver.URL'</code> for {@link ifc.sdbc._XDriver}: is the URL of the database to
   *       which to connect. The URL is obtained from the parameter <code>mozab.url</code>
   *   <li><code>'XDriver.UNSUITABLE_URL'</code> for {@link ifc.sdbc._XDriver}: the wrong kind of
   *       URL to connect using given driver. The URL is obtained from the parameter <code>jdbc.url
   *       </code>
   *   <li><code>'XDriver.INFO'</code> for {@link ifc.sdbc._XDriver}: a list of arbitrary string
   *       tag/value pairs as connection arguments.
   * </ul>
   */
  @Override
  protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log)
      throws Exception {

    XInterface oObj =
        (XInterface) Param.getMSF().createInstance("com.sun.star.comp.sdbc.MozabDriver");

    log.println("creating a new environment for object");
    TestEnvironment tEnv = new TestEnvironment(oObj);

    // adding relation for sdbc.XDriver
    String mozabURL = (String) Param.get("mozab.url");
    if (mozabURL == null) {
      throw new StatusException(Status.failed("Couldn't get 'mozabURL' from ini-file"));
    }
    tEnv.addObjRelation("XDriver.URL", "sdbc:address:" + mozabURL);

    PropertyValue[] info = new PropertyValue[0];
    tEnv.addObjRelation("XDriver.INFO", info);

    String jdbcUrl = (String) Param.get("jdbc.url");
    if (jdbcUrl == null) {
      throw new StatusException(Status.failed("Couldn't get 'jdbc.url' from ini-file"));
    }
    tEnv.addObjRelation("XDriver.UNSUITABLE_URL", "jdbc:" + jdbcUrl);

    return tEnv;
  }
  /**
   * Creating a Testenvironment for the interfaces to be tested. Creates an instance of the service
   * <code>com.sun.star.sheet.RecentFunctions</code> and an instance of the service <code>
   * com.sun.star.sheet.FunctionDescriptions</code>. Object relations created :
   *
   * <ul>
   *   <li><code>'FUNCTIONLIST'</code> for {@link ifc.sheet._XRecentFunctions}(the second created
   *       instance)
   * </ul>
   */
  public synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log)
      throws StatusException {

    XInterface oObj = null;
    XInterface allFunctions = null;

    // creation of testobject here
    // first we write what we are intend to do to log file
    log.println("Creating a test environment");

    try {
      log.println("Getting test object ");
      XMultiServiceFactory oDocMSF = (XMultiServiceFactory) Param.getMSF();
      oObj = (XInterface) oDocMSF.createInstance("com.sun.star.sheet.RecentFunctions");
      allFunctions = (XInterface) oDocMSF.createInstance("com.sun.star.sheet.FunctionDescriptions");

      log.println("Creating object - " + ((oObj == null) ? "FAILED" : "OK"));
    } catch (com.sun.star.uno.Exception e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't create instance", e);
    }

    TestEnvironment tEnv = new TestEnvironment(oObj);

    // Other parameters required for interface tests
    XNameAccess NA = UnoRuntime.queryInterface(XNameAccess.class, allFunctions);
    tEnv.addObjRelation("FUNCTIONLIST", NA);

    return tEnv;
  }
  /**
   * Creating a TestEnvironment for the interfaces to be tested. Creates an instance of the service
   * <code>com.sun.star.frame.ContentHandlerFactory</code>.
   *
   * <p>
   */
  @Override
  protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log)
      throws Exception {
    XInterface oObj = null;
    Object oInterface = null;

    // now get the OButtonControl
    oInterface = Param.getMSF().createInstance("com.sun.star.frame.ContentHandlerFactory");

    oObj = (XInterface) oInterface;
    log.println("ImplName: " + utils.getImplName(oObj));

    log.println("creating a new environment for object");
    TestEnvironment tEnv = new TestEnvironment(oObj);

    XNameAccess xNA = UnoRuntime.queryInterface(XNameAccess.class, oObj);
    tEnv.addObjRelation("XMSF.serviceNames", xNA.getElementNames());
    xNA.getElementNames();

    // com.sun.star.container.XContainerQuery
    NamedValue[] querySequenze = new NamedValue[1];
    NamedValue query = new NamedValue();
    query.Name = "Name";
    query.Value = "com.sun.star.comp.framework.SoundHandler";
    querySequenze[0] = query;

    tEnv.addObjRelation("XContainerQuery.createSubSetEnumerationByProperties", querySequenze);

    return tEnv;
  } // finish method getTestEnvironment
Beispiel #5
0
  /**
   * calls <CODE>createTestEnvironment()</CODE> from it's super class
   *
   * @param Param the test parameter
   * @param log the log writer
   * @return lib.TestEnvironment
   */
  @Override
  protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log)
      throws Exception {
    TestEnvironment tEnv = super.createTestEnvironment(Param, log);
    tEnv.addObjRelation("DataAwareControlModel.NewFieldName", DBTools.TST_INT_F);
    PropertyValue prop = new PropertyValue();
    prop.Name = "HelpText";
    prop.Value = "new Help Text since XPropertyAccess";
    tEnv.addObjRelation("XPropertyAccess.propertyToChange", prop);
    tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "HelpText");

    return tEnv;
  }
  public synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {

    XInterface oObj = null;
    TestEnvironment tEnv = null;

    try {

      // creation of testobject here
      XPropertySet props = UnoRuntime.queryInterface(XPropertySet.class, xSheetDoc);
      oObj =
          (XInterface)
              AnyConverter.toObject(
                  new Type(XInterface.class), props.getPropertyValue("AreaLinks"));
      XAreaLinks links = null;

      // adding one link into collection (for best testing)
      links = UnoRuntime.queryInterface(XAreaLinks.class, oObj);
      CellAddress addr = new CellAddress((short) 1, 2, 3);
      String aSourceArea = util.utils.getFullTestURL("calcshapes.sxc");
      links.insertAtPosition(addr, aSourceArea, "a2:b5", "", "");

      XEnumerationAccess ea = UnoRuntime.queryInterface(XEnumerationAccess.class, oObj);

      oObj = ea.createEnumeration();

      log.println("ImplementationName: " + util.utils.getImplName(oObj));
      // creating test environment
      tEnv = new TestEnvironment(oObj);

      tEnv.addObjRelation("ENUM", ea);

    } catch (com.sun.star.beans.UnknownPropertyException e) {
      log.println("Exception occurred while creating test Object.");
      e.printStackTrace(log);
      throw new StatusException("Couldn't create test object", e);
    } catch (com.sun.star.lang.WrappedTargetException e) {
      log.println("Exception occurred while creating test Object.");
      e.printStackTrace(log);
      throw new StatusException("Couldn't create test object", e);
    } catch (com.sun.star.lang.IllegalArgumentException e) {
      log.println("Exception occurred while creating test Object.");
      e.printStackTrace(log);
      throw new StatusException("Couldn't create test object", e);
    }

    return tEnv;
  }
  /**
   * creating a TestEnvironment for the interfaces to be tested
   *
   * @param tParam class which contains additional test parameters
   * @param log class to log the test state and result
   * @return Status class
   * @see TestParameters
   * @see PrintWriter
   */
  @Override
  protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {

    XInterface oObj = null;
    // create testobject here

    XEnumerationAccess xEA = null;
    try {
      SOfficeFactory SOF = SOfficeFactory.getFactory(tParam.getMSF());
      XShape oShape = SOF.createShape(xDrawDoc, 5000, 3500, 7500, 5000, "Text");
      DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc, 0)).add(oShape);

      XSimpleText text = UnoRuntime.queryInterface(XSimpleText.class, oShape);

      XTextCursor cursor = text.createTextCursor();

      text.insertString(cursor, "Paragraph 1", false);
      text.insertControlCharacter(cursor, ControlCharacter.PARAGRAPH_BREAK, false);
      text.insertString(cursor, "Paragraph 2", false);
      text.insertControlCharacter(cursor, ControlCharacter.PARAGRAPH_BREAK, false);
      text.insertString(cursor, "Paragraph 3", false);
      text.insertControlCharacter(cursor, ControlCharacter.PARAGRAPH_BREAK, false);

      xEA = UnoRuntime.queryInterface(XEnumerationAccess.class, text);

      XInterface oTextContent =
          (XInterface)
              AnyConverter.toObject(
                  new Type(XInterface.class), xEA.createEnumeration().nextElement());

      xEA = UnoRuntime.queryInterface(XEnumerationAccess.class, oTextContent);

      oObj = xEA.createEnumeration();

    } catch (Exception e) {
      log.println("Can't create test object");
      e.printStackTrace(log);
    }

    // create test environment here
    TestEnvironment tEnv = new TestEnvironment(oObj);

    tEnv.addObjRelation("ENUM", xEA);

    return tEnv;
  } // finish method getTestEnvironment
Beispiel #8
0
  /**
   * Creating a TestEnvironment for the interfaces to be tested. Creates an instance of the service
   * <code>com.sun.star.comp.Chart.XMLExporter</code> with argument which is an implementation of
   * <code>XDocumentHandler</code> and which can check if required tags and character data is
   * exported.
   *
   * <p>The chart document is set as a source document for exporter created. A new 'main title' is
   * set for chart. This made for checking if this title is successfully exported within the
   * document content. Object relations created :
   *
   * <ul>
   *   <li><code>'MediaDescriptor'</code> for {@link ifc.document._XFilter} interface
   *   <li><code>'XFilter.Checker'</code> for {@link ifc.document._XFilter} interface
   *   <li><code>'SourceDocument'</code> for {@link ifc.document._XExporter} interface
   * </ul>
   */
  @Override
  public TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log)
      throws Exception {

    XMultiServiceFactory xMSF = tParam.getMSF();
    XInterface oObj = null;
    final String exportStr = "XMLExporter test.";

    FilterChecker filter = new FilterChecker(log);
    Any arg = new Any(new Type(XDocumentHandler.class), filter);

    oObj =
        (XInterface)
            xMSF.createInstanceWithArguments(
                "com.sun.star.comp.Chart.XMLExporter", new Object[] {arg});
    XExporter xEx = UnoRuntime.queryInterface(XExporter.class, oObj);
    xEx.setSourceDocument(xChartDoc);

    Object oTitle = xChartDoc.getTitle();
    XPropertySet xTitleProp = UnoRuntime.queryInterface(XPropertySet.class, oTitle);
    xTitleProp.setPropertyValue("String", exportStr);

    filter.addTag(new XMLTools.Tag("office:document"));
    filter.addTagEnclosed(new XMLTools.Tag("office:meta"), new XMLTools.Tag("office:document"));
    filter.addTagEnclosed(new XMLTools.Tag("office:body"), new XMLTools.Tag("office:document"));
    filter.addCharactersEnclosed(exportStr, new XMLTools.Tag("chart:title"));

    // create testobject here
    log.println("creating a new environment");
    TestEnvironment tEnv = new TestEnvironment(oObj);

    tEnv.addObjRelation(
        "MediaDescriptor",
        XMLTools.createMediaDescriptor(
            new String[] {"FilterName"}, new Object[] {"schart: StarOffice XML (Chart)"}));
    tEnv.addObjRelation("SourceDocument", xChartDoc);
    tEnv.addObjRelation("XFilter.Checker", filter);
    log.println("Implementation Name: " + util.utils.getImplName(oObj));

    return tEnv;
  }
  /**
   * Creating a Testenvironment for the interfaces to be tested. In case if OS is Win or not
   * specified tries to create an instance of the service <code>com.sun.star.system.SimpleSystemMail
   * </code>.
   *
   * <p>Object relations created :
   *
   * <ul>
   *   <li><code>'SystemMailExist'</code> for {@link ifc.system._XSimpleMailClientSupplier} : the
   *       value depends on tested platform and <code>test.system.mail.isExist</code> INI parameter.
   * </ul>
   */
  public TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log)
      throws StatusException {
    XInterface oObj = null;
    Object oInterface = null;
    boolean isWinOS = false;
    boolean isSystemMailExist = false;

    // if 'OS' parameter is not defined then by default
    // Win platform is used. If really not the error will occurs.
    isWinOS = Param.get("OS") == null || "wntmsci".equals(Param.get("OS"));
    isSystemMailExist = "true".equalsIgnoreCase((String) Param.get("test.system.mail.isExist"));

    XMultiServiceFactory xMSF = Param.getMSF();
    try {
      if (isWinOS) {
        log.println("The OS is Win : trying to create service");
        oInterface = xMSF.createInstance("com.sun.star.system.SimpleSystemMail");
      } else {
        log.println("The OS is NOT Win, SKIPPING this component");
        log.println("Creating Dummy object ...");
        oInterface = xMSF.createInstance("com.sun.star.io.Pipe");
      }
    } catch (com.sun.star.uno.Exception e) {
      log.println("Can't create an object.");
      throw new StatusException("Can't create an object", e);
    }

    oObj = (XInterface) oInterface;

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

    TestEnvironment tEnv = new TestEnvironment(oObj);

    tEnv.addObjRelation("SystemMailExist", new Boolean(isSystemMailExist));

    return tEnv;
  } // finish method getTestEnvironment
  /**
   * Creating a Testenvironment for the interfaces to be tested. Creates an instance of the service
   * <code>com.sun.star.text.AutoTextContainer</code>, then selects the 'mytexts' group from the
   * given container using <code>XNameAccess</code> interface, and inserts some text entry to this
   * group. Then entry passed as test component.
   *
   * <p>Object relations created :
   *
   * <ul>
   *   <li><code>'XTEXTINFO'</code> for {@link ifc.text._XText} : creates tables 6x4
   *   <li><code>'TEXTDOC'</code> for {@link ifc.text._XAutoTextEntry} : text document
   * </ul>
   */
  protected synchronized TestEnvironment createTestEnvironment(
      TestParameters Param, PrintWriter log) {

    XAutoTextEntry oEntry = null;
    XAutoTextContainer oContainer;
    XInterface oObj = null;
    log.println("creating a test environment");
    try {
      XMultiServiceFactory myMSF = (XMultiServiceFactory) Param.getMSF();
      Object oInst = myMSF.createInstance("com.sun.star.text.AutoTextContainer");
      oContainer = UnoRuntime.queryInterface(XAutoTextContainer.class, oInst);
    } catch (com.sun.star.uno.Exception e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't create AutoTextContainer", e);
    }

    XNameAccess oContNames = UnoRuntime.queryInterface(XNameAccess.class, oContainer);

    String contNames[] = oContNames.getElementNames();
    for (int i = 0; i < contNames.length; i++) {
      log.println("ContainerNames[ " + i + "]: " + contNames[i]);
    }

    try {
      oObj =
          (XInterface)
              AnyConverter.toObject(new Type(XInterface.class), oContNames.getByName("mytexts"));
    } catch (com.sun.star.uno.Exception e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get AutoTextGroup", e);
    }

    oGroup = UnoRuntime.queryInterface(XAutoTextGroup.class, oObj);
    String[] oENames = oGroup.getElementNames();
    for (int i = 0; i < oENames.length; i++) {
      log.println("AutoTextEntryNames[" + i + "]: " + oENames[i]);
    }

    XText oText = xTextDoc.getText();
    oText.insertString(oText.getStart(), "New AutoText", true);
    XTextRange oTextRange = oText;
    try {
      if (oGroup.hasByName("NewEntryName")) {
        oGroup.removeByName("NewEntryName");
        log.println("Element 'NewEntryName' exists, removing...");
      }
      log.println("Adding new element 'NewEntryName' to group...");
      oGroup.insertNewByName("NewEntryName", "NewEntryTitle", oTextRange);
      oEntry =
          (XAutoTextEntry)
              AnyConverter.toObject(
                  new Type(XAutoTextEntry.class), oGroup.getByName("NewEntryName"));
    } catch (com.sun.star.container.ElementExistException e) {
      e.printStackTrace(log);
    } catch (com.sun.star.container.NoSuchElementException e) {
      e.printStackTrace(log);
    } catch (com.sun.star.lang.WrappedTargetException e) {
      e.printStackTrace(log);
    } catch (com.sun.star.lang.IllegalArgumentException e) {
      e.printStackTrace(log);
    }

    oObj = oEntry;

    log.println("Trying to use XText as TextRange in the method applyTo");
    oEntry.applyTo(oTextRange);

    oTextRange = oText.createTextCursor();
    log.println("Trying to use XTextCursor as TextRange in the method applyTo");
    oEntry.applyTo(oTextRange);

    log.println("creating a new environment for AutoTextEntry object");
    TestEnvironment tEnv = new TestEnvironment(oObj);

    // adding relation for XText
    DefaultDsc tDsc =
        new DefaultDsc("com.sun.star.text.XTextContent", "com.sun.star.text.TextField.DateTime");
    log.println("    adding InstCreator object");
    tEnv.addObjRelation("XTEXTINFO", new InstCreator(xTextDoc, tDsc));

    log.println("adding TextDocument as mod relation to environment");
    tEnv.addObjRelation("TEXTDOC", xTextDoc);

    return tEnv;
  } // finish method getTestEnvironment
  /**
   * Creating a Testenvironment for the interfaces to be tested.
   * For object creation first a
   * <code>com.sun.star.form.component.GridControl<code> instance
   * is added to the <code>ControlShape</code>. Then this model's
   * control is retrieved.
   *
   *     Object relations created :
   * <ul>
   *  <li> <code>'GRAPHICS'</code> for
   *      {@link ifc.awt._XView} test : <code>XGraphics</code>
   *   object different that belong to the object tested.</li>
   *  <li> <code>'CONTEXT'</code> for
   *      {@link ifc.awt._XControl} </li>
   *  <li> <code>'WINPEER'</code> for
   *      {@link ifc.awt._XControl} </li>
   *  <li> <code>'TOOLKIT'</code> for
   *      {@link ifc.awt._XControl} </li>
   *  <li> <code>'MODEL'</code> for
   *      {@link ifc.awt._XControl} </li>
   *  <li> <code>'XWindow.AnotherWindow'</code> for
   *      {@link ifc.awt._XWindow} for switching focus.</li>
   *  <li> <code>'XDispatch.URL'</code> for
   *      {@link ifc.frame._XDispatch} the url which moves
   *      DB cursor to the next row (".uno:FormSlots/moveToNext").</li>
   *  <li> <code>'XContainer.Container'</code> for
   *      {@link ifc.container._XContainer} as the component created
   *      doesn't support <code>XContainer</code> itself, but
   *      it is supported by its model. So this model is passed.</li>
   *  <li> <code>'INSTANCE'</code> for
   *      {@link ifc.container._XContainer} the instance to be
   *      inserted into collection. Is a column instance.</li>
   * </ul>
   */
  protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
    XInterface oObj = null;
    XWindowPeer the_win = null;
    XToolkit the_kit = null;
    XDevice aDevice = null;
    XGraphics aGraphic = null;
    XPropertySet aControl = null;
    XPropertySet aControl2 = null;
    XPropertySet aControl3 = null;
    XPropertySet aControl4 = null;
    XGridColumnFactory columns = null;

    // Insert a ControlShape and get the ControlModel
    XControlShape aShape = createGrid(xTextDoc, 3000, 4500, 15000, 10000);

    XControlModel the_Model = aShape.getControl();

    WriterTools.getDrawPage(xTextDoc).add(aShape);

    XLoadable formLoader = FormTools.bindForm(xTextDoc);

    // Try to query XControlAccess
    XControlAccess the_access =
        UnoRuntime.queryInterface(XControlAccess.class, xTextDoc.getCurrentController());

    try {
      columns = UnoRuntime.queryInterface(XGridColumnFactory.class, the_Model);
      aControl = columns.createColumn("TextField");
      aControl.setPropertyValue("DataField", "Identifier");
      aControl.setPropertyValue("Label", "Identifier");
      aControl2 = columns.createColumn("TextField");
      aControl2.setPropertyValue("DataField", "Publisher");
      aControl2.setPropertyValue("Label", "Publisher");
      aControl3 = columns.createColumn("TextField");
      aControl3.setPropertyValue("DataField", "Author");
      aControl3.setPropertyValue("Label", "Author");
      aControl4 = columns.createColumn("TextField");
      aControl4.setPropertyValue("DataField", "Title");
      aControl4.setPropertyValue("Label", "Title");
    } catch (com.sun.star.lang.IllegalArgumentException e) {
      // Some exception occurs.FAILED
      log.println("!!! Couldn't create instance : " + e);
      throw new StatusException("Can't create column instances.", e);
    } catch (com.sun.star.lang.WrappedTargetException e) {
      // Some exception occurs.FAILED
      log.println("!!! Couldn't create instance : " + e);
      throw new StatusException("Can't create column instances.", e);
    } catch (com.sun.star.beans.PropertyVetoException e) {
      // Some exception occurs.FAILED
      log.println("!!! Couldn't create instance : " + e);
      throw new StatusException("Can't create column instances.", e);
    } catch (com.sun.star.beans.UnknownPropertyException e) {
      // Some exception occurs.FAILED
      log.println("!!! Couldn't create instance : " + e);
      throw new StatusException("Can't create column instances.", e);
    }

    XNameContainer aContainer = UnoRuntime.queryInterface(XNameContainer.class, the_Model);

    try {
      aContainer.insertByName("First", aControl);
      aContainer.insertByName("Second", aControl2);
    } catch (com.sun.star.uno.Exception e) {
      log.println("!!! Could't insert column Instance");
      e.printStackTrace(log);
      throw new StatusException("Can't insert columns", e);
    }

    // now get the OGridControl
    try {
      oObj = the_access.getControl(the_Model);
      the_win = the_access.getControl(the_Model).getPeer();
      the_kit = the_win.getToolkit();
      aDevice = the_kit.createScreenCompatibleDevice(200, 200);
      aGraphic = aDevice.createGraphics();
    } catch (com.sun.star.uno.Exception e) {
      log.println("Couldn't get GridControl");
      e.printStackTrace(log);
      throw new StatusException("Couldn't get GridControl", e);
    }

    // creating another window
    aShape = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000, 10000, "TextField");

    WriterTools.getDrawPage(xTextDoc).add(aShape);

    the_Model = aShape.getControl();

    // Try to query XControlAccess
    the_access = UnoRuntime.queryInterface(XControlAccess.class, xTextDoc.getCurrentController());

    // now get the TextControl
    XWindow win = null;
    Object cntrl = null;

    try {
      cntrl = the_access.getControl(the_Model);
      win = UnoRuntime.queryInterface(XWindow.class, cntrl);
    } catch (com.sun.star.uno.Exception e) {
      log.println("Couldn't get Control");
      e.printStackTrace(log);
      throw new StatusException("Couldn't get Control", e);
    }

    log.println("creating a new environment for object");

    TestEnvironment tEnv = new TestEnvironment(oObj);

    // Relations for XSelectionSupplier
    tEnv.addObjRelation(
        "Selections", new Object[] {new Object[] {new Integer(0)}, new Object[] {new Integer(1)}});
    tEnv.addObjRelation(
        "Comparer",
        new Comparator<Integer>() {
          public int compare(Integer o1, Integer o2) {
            return o1.compareTo(o2);
          }
        });

    // Realtion for XContainer
    tEnv.addObjRelation("XContainer.Container", aContainer);
    tEnv.addObjRelation("INSTANCE", aControl3);
    tEnv.addObjRelation("INSTANCE2", aControl4);

    // Adding ObjRelation for XView
    tEnv.addObjRelation("GRAPHICS", aGraphic);

    // Adding ObjRelation for XControl
    tEnv.addObjRelation("CONTEXT", xTextDoc);
    tEnv.addObjRelation("WINPEER", the_win);
    tEnv.addObjRelation("TOOLKIT", the_kit);
    tEnv.addObjRelation("MODEL", the_Model);

    // Adding relation for XWindow
    tEnv.addObjRelation("XWindow.AnotherWindow", win);

    // Adding relation for XDispatch
    URL url = new URL();
    url.Complete = ".uno:FormSlots/moveToNext";

    // url.Complete = ".uno:GridSlots/RowHeight";
    // url.Complete = ".uno:GridSlots/RowHeight" ;
    tEnv.addObjRelation("XDispatch.URL", url);

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

    FormTools.switchDesignOf((XMultiServiceFactory) Param.getMSF(), xTextDoc);

    // adding relation for XUpdateBroadcaster
    final XInterface ctrl = oObj;
    final XLoadable formLoaderF = formLoader;
    final XPropertySet ps = UnoRuntime.queryInterface(XPropertySet.class, aControl2);
    tEnv.addObjRelation(
        "XUpdateBroadcaster.Checker",
        new ifc.form._XUpdateBroadcaster.UpdateChecker() {
          private String lastText = "";

          public void update() throws com.sun.star.uno.Exception {
            if (!formLoaderF.isLoaded()) {
              formLoaderF.load();
            }

            lastText = "_" + ps.getPropertyValue("Text");
            ps.setPropertyValue("Text", lastText);
          }

          public void commit() throws com.sun.star.sdbc.SQLException {
            XBoundComponent bound = UnoRuntime.queryInterface(XBoundComponent.class, ctrl);
            XResultSetUpdate update =
                UnoRuntime.queryInterface(XResultSetUpdate.class, formLoaderF);

            bound.commit();
            update.updateRow();
          }

          public boolean wasCommited() throws com.sun.star.uno.Exception {
            String getS = (String) ps.getPropertyValue("Text");

            return lastText.equals(getS);
          }
        });

    return tEnv;
  } // finish method getTestEnvironment
  /** * creating a Testenvironment for the interfaces to be tested */
  protected synchronized TestEnvironment createTestEnvironment(
      TestParameters Param, PrintWriter log) {
    if (xTextDoc != null) {
      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");
      }

      log.println("Existing document disposed");
    }

    log.println("creating a text document");
    xTextDoc = WriterTools.createTextDoc(((XMultiServiceFactory) Param.getMSF()));

    // initialize test table
    if (isMySQLDB) {
      try {
        dbTools.initTestTableUsingJDBC(tableName, srcInf);
      } catch (java.sql.SQLException e) {
        e.printStackTrace(log);
        throw new StatusException(Status.failed("Couldn't " + " init test table. SQLException..."));
      } catch (java.lang.ClassNotFoundException e) {
        throw new StatusException(Status.failed("Couldn't " + "register mysql driver"));
      }
    }

    XInterface oObj = null;
    XShapes oShapes = null;
    XInterface oInstance = null;
    XConnection connection = null;

    // creation of testobject here
    // first we write what we are intend to do to log file
    log.println("creating a test environment");

    XNameContainer forms = FormTools.getForms(WriterTools.getDrawPage(xTextDoc));

    try {
      String[] formNames = forms.getElementNames();

      for (int i = 0; i < formNames.length; i++) {
        log.println("Removing form '" + formNames[i] + "' ...");
        forms.removeByName(formNames[i]);
      }
    } catch (com.sun.star.lang.WrappedTargetException e) {
      e.printStackTrace(log);
    } catch (com.sun.star.container.NoSuchElementException e) {
      e.printStackTrace(log);
    }

    String[] formNames = forms.getElementNames();
    FormTools.insertForm(xTextDoc, forms, "MyForm");
    formNames = forms.getElementNames();

    XLoadable formLoader = null;

    try {
      formLoader = FormTools.bindForm(xTextDoc, "MyForm", dbSourceName, tableName);
    } catch (com.sun.star.uno.Exception e) {
      log.println(
          "Cann't bind the form to source '" + dbSourceName + "', table '" + tableName + "' :");
      e.printStackTrace(log);
      throw new StatusException("Cann't bind a form", e);
    }

    // DEBUG
    log.println("Forms before adding controls : ");
    formNames = forms.getElementNames();

    for (int i = 0; i < formNames.length; i++) {
      log.println("    '" + formNames[i] + "'");
    }

    XControlShape shape1 = null;
    XControlShape shape2 = null;

    try {

      log.println("Elements in the 'MyForm' :");

      XIndexAccess formElements1 =
          UnoRuntime.queryInterface(XIndexAccess.class, forms.getByName("MyForm"));

      for (int i = 0; i < formElements1.getCount(); i++) {
        XNamed elemName = UnoRuntime.queryInterface(XNamed.class, formElements1.getByIndex(i));
        log.println("   '" + elemName.getName() + "'");
      }

      // END DEBUG
      // put something on the drawpage
      log.println("inserting some ControlShapes");
      oShapes = DrawTools.getShapes(WriterTools.getDrawPage(xTextDoc));
      shape1 = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000, 1000, "CommandButton");
      shape2 = FormTools.createControlShape(xTextDoc, 5000, 3500, 7500, 5000, "TextField");

      XControlShape shape3 =
          FormTools.createControlShape(xTextDoc, 2000, 1500, 1000, 1000, "CheckBox");
      oShapes.add(shape1);
      oShapes.add(shape2);
      oShapes.add(shape3);
    } catch (Exception e) {
      e.printStackTrace(log);
    }

    log.println("Forms after adding controls : ");
    formNames = forms.getElementNames();

    for (int i = 0; i < formNames.length; i++) {
      log.println("    '" + formNames[i] + "'");
    }

    try {
      log.println("Elements in the 'MyForm' :");

      XIndexAccess formElements1 =
          UnoRuntime.queryInterface(XIndexAccess.class, forms.getByName("MyForm"));

      for (int i = 0; i < formElements1.getCount(); i++) {
        XNamed elemName = UnoRuntime.queryInterface(XNamed.class, formElements1.getByIndex(i));
        log.println("   '" + elemName.getName() + "'");
      }
    } catch (Exception e) {
      e.printStackTrace(log);
    }

    formLoader.load();

    try {
      oObj =
          (XForm)
              AnyConverter.toObject(
                  new Type(XForm.class),
                  (FormTools.getForms(WriterTools.getDrawPage(xTextDoc))).getByName("MyForm"));

      XPropertySet xSetProp = UnoRuntime.queryInterface(XPropertySet.class, oObj);
      connection =
          (XConnection)
              AnyConverter.toObject(
                  new Type(XConnection.class), xSetProp.getPropertyValue("ActiveConnection"));
    } catch (com.sun.star.uno.Exception e) {
      log.println("Couldn't get Form");
      e.printStackTrace(log);
    }

    // get a control
    oInstance = FormTools.createControl(xTextDoc, "TextField");

    log.println("creating a new environment for drawpage object");

    TestEnvironment tEnv = new TestEnvironment(oObj);

    // adding relation for closing connection while environment disposing.
    this.conn = connection;

    // adding relation for XSubmit
    XControlModel the_Model = shape2.getControl();
    XControlAccess the_access =
        UnoRuntime.queryInterface(XControlAccess.class, xTextDoc.getCurrentController());
    XControl cntrl = null;

    // now get the OEditControl
    try {
      cntrl = the_access.getControl(the_Model);
      log.println(cntrl.getClass().getName());
    } catch (com.sun.star.container.NoSuchElementException e) {
      log.println("Couldn't get OEditControl");
      e.printStackTrace(log);
      throw new StatusException("Couldn't get OEditControl", e);
    }

    XResultSet the_set = UnoRuntime.queryInterface(XResultSet.class, oObj);

    try {
      the_set.first();
    } catch (SQLException e) {
      log.println("Cann't move cursor to the first row.");
      e.printStackTrace();
      throw new StatusException("Can't move cursor to the first row.", e);
    }

    tEnv.addObjRelation("Model1", shape1.getControl());
    tEnv.addObjRelation("Model2", shape2.getControl());

    // adding an object for XNameReplace testing
    log.println("adding oInstace as obj relation to environment");
    tEnv.addObjRelation("INSTANCE", oInstance);

    // INDEX : _XNameContainer
    log.println("adding INDEX as obj relation to environment");
    tEnv.addObjRelation("INDEX", "0");

    // INDEX : _XNameReplace
    log.println("adding NameReplaceIndex as obj relation to environment");
    tEnv.addObjRelation("XNameReplaceINDEX", "2");

    // INSTANCEn : _XNameContainer; _XNameReplace
    log.println("adding INSTANCEn as obj relation to environment");

    // XComponent xComp = (XComponent)
    //    UnoRuntime.queryInterface(XComponent.class, xDrawDoc);
    String tc = (String) Param.get("THRCNT");
    int THRCNT = 1;

    if (tc != null) {
      THRCNT = Integer.parseInt(tc);
    }

    for (int n = 1; n < (2 * (THRCNT + 1)); n++) {
      log.println("adding INSTANCE" + n + " as obj relation to environment");
      tEnv.addObjRelation("INSTANCE" + n, FormTools.createControl(xTextDoc, "CheckBox"));
    }

    // adding relation for XNameContainer
    tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object());

    // adding relation for XPersistObject
    tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component.Form");

    if (the_set != null) {
      log.println("The Form has a not empty ResultSet");
    }

    // Adding obj relation for XRowSetApproveBroadcaster test
    final XResultSet xResSet = UnoRuntime.queryInterface(XResultSet.class, oObj);
    final XResultSetUpdate xResSetUpdate = UnoRuntime.queryInterface(XResultSetUpdate.class, oObj);
    final XRowSet xRowSet = UnoRuntime.queryInterface(XRowSet.class, oObj);
    final PrintWriter logF = log;
    tEnv.addObjRelation(
        "XRowSetApproveBroadcaster.ApproveChecker",
        new ifc.sdb._XRowSetApproveBroadcaster.RowSetApproveChecker() {
          public void moveCursor() {
            try {
              xResSet.beforeFirst();
              xResSet.afterLast();
            } catch (com.sun.star.sdbc.SQLException e) {
              logF.println(
                  "### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.moveCursor() :");
              e.printStackTrace(logF);
            }
          }

          public RowChangeEvent changeRow() {
            try {
              xResSet.first();

              XRowUpdate row = UnoRuntime.queryInterface(XRowUpdate.class, xResSet);
              row.updateString(1, "1");
              xResSetUpdate.updateRow();
            } catch (com.sun.star.sdbc.SQLException e) {
              logF.println(
                  "### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.changeRow() :");
              e.printStackTrace(logF);
            }

            RowChangeEvent ev = new RowChangeEvent();
            ev.Action = com.sun.star.sdb.RowChangeAction.UPDATE;
            ev.Rows = 1;

            return ev;
          }

          public void changeRowSet() {
            try {
              xRowSet.execute();
            } catch (com.sun.star.sdbc.SQLException e) {
              logF.println(
                  "### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.changeRowSet() :");
              e.printStackTrace(logF);
            }
          }
        });

    // Adding relation for XColumnLocate test
    tEnv.addObjRelation("XColumnLocate.ColumnName", DBTools.TST_STRING_F);

    // Adding relation for XParameters ifc test
    ArrayList<Object> params = new ArrayList<Object>();

    /** *** statement parameter types and their initial values must be added here as relation. */
    params.add("SAU99");
    params.add(new Boolean(false));
    params.add(new Byte((byte) 123));
    params.add(new Short((short) 234));
    params.add(new Integer(12345));
    params.add(new Long(23456));
    params.add(new Float(1.234));
    params.add(new Double(2.345));
    params.add(new byte[] {1, 2, 3});
    Date d = new Date();
    d.Day = 26;
    d.Month = 1;
    d.Year = 2001;
    params.add(d);
    Time t = new Time();
    t.Hours = 1;
    t.NanoSeconds = 123456789;
    t.Minutes = 25;
    t.Seconds = 14;
    params.add(t);
    DateTime dt = new DateTime();
    dt.Day = 26;
    dt.Month = 1;
    dt.Year = 2001;
    dt.Hours = 1;
    dt.NanoSeconds = 123456789;
    dt.Minutes = 25;
    dt.Seconds = 14;
    params.add(dt);
    tEnv.addObjRelation("XParameters.ParamValues", params);

    // Adding relation for XCompletedExecution
    tEnv.addObjRelation("InteractionHandlerChecker", new InteractionHandlerImpl());

    // Adding for XWarningSupplier
    tEnv.addObjRelation("CheckWarningsSupplier", new Boolean(isMySQLDB));

    // Adding relation for XDatabaseParameterBroadcaster
    tEnv.addObjRelation("ParameterListenerChecker", new ODatabaseForm.ParameterListenerImpl());
    XPropertySet xSetProp = UnoRuntime.queryInterface(XPropertySet.class, oObj);
    try {
      xSetProp.setPropertyValue("DataSourceName", dbSourceName);
      if (isMySQLDB) {
        xSetProp.setPropertyValue(
            "Command", "SELECT Column0  FROM soffice_test_table  WHERE ( (  Column0 = :param1 ) )");
      } else {
        xSetProp.setPropertyValue(
            "Command",
            "SELECT \"_TEXT\" FROM \"ODatabaseForm_tmp0\" WHERE ( ( \"_TEXT\" = :param1 ) )");
      }

      xSetProp.setPropertyValue("CommandType", new Integer(CommandType.COMMAND));
    } catch (Exception e) {
    }

    // Adding relation for XResultSetUpdate
    final XRowUpdate xRowUpdate = UnoRuntime.queryInterface(XRowUpdate.class, oObj);
    final XRow xRow = UnoRuntime.queryInterface(XRow.class, oObj);

    tEnv.addObjRelation(
        "XResultSetUpdate.UpdateTester",
        new ifc.sdbc._XResultSetUpdate.UpdateTester() {
          String lastUpdate = null;

          public int rowCount() throws SQLException {
            int prevPos = xResSet.getRow();
            xResSet.last();

            int count = xResSet.getRow();
            xResSet.absolute(prevPos);

            return count;
          }

          public void update() throws SQLException {
            lastUpdate = xRow.getString(1);
            lastUpdate += "_";
            xRowUpdate.updateString(1, lastUpdate);
          }

          public boolean wasUpdated() throws SQLException {
            String getStr = xRow.getString(1);

            return lastUpdate.equals(getStr);
          }

          public int currentRow() throws SQLException {
            return xResSet.getRow();
          }
        });

    // Adding relations for XRow as a Vector with all data
    // of current row of RowSet.

    ArrayList<Object> rowData = new ArrayList<Object>();

    for (int i = 0; i < DBTools.TST_TABLE_VALUES[0].length; i++) {
      rowData.add(DBTools.TST_TABLE_VALUES[0][i]);
    }

    tEnv.addObjRelation("CurrentRowData", rowData);

    // Adding relation for XRowUpdate
    XRow row = UnoRuntime.queryInterface(XRow.class, oObj);
    tEnv.addObjRelation("XRowUpdate.XRow", row);

    tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "Cycle");

    PropertyValue propVal = new PropertyValue();
    propVal.Name = "Name";
    propVal.Value = "Text since XPropertyAccess";

    tEnv.addObjRelation("XPropertyAccess.propertyToChange", propVal);

    return tEnv;
  } // finish method getTestEnvironment
  /**
   * 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;
  }
Beispiel #14
0
  /**
   * Creating a Testenvironment for the interfaces to be tested. The database (DBF) file is copied
   * from test document directory into SOffice temp dir with unique name for each environment
   * creation. If the file cann't be copied (is not released) then another unique name is used (file
   * name suffix incremented by 1).
   *
   * <p><code>com.sun.star.sdb.RowSet</code> service created and its source is all rows from the
   * current copy of the table. Then row set command ("select all rows from a table") is executed
   * and cursor is positioned to the first row.
   *
   * <p>Object relations created :
   *
   * <ul>
   *   <li><code>'ORowSet.Connection'</code> for internal component test usage. Is used for closing
   *       connection when cleaning up environment.
   *   <li><code>'XRowSetApproveBroadcaster.ApproveChecker'</code> for {@link
   *       ifc.sdb._XRowSetApproveBroadcaster} interface implementation which made actions required
   *   <li><code>'CurrentRowData'</code> for {@link ifc.sdbc._XRow}, {@link ifc.sdbc._XRowUpdate} :
   *       exports types and values of the current row data.
   *   <li><code>'XColumnLocate.ColumnName'</code> for {@link ifc.sdbc._XColumnLocate} : the name of
   *       the first column of the table.
   *   <li><code>'XParameters.ParamValues'</code> for {@link ifc.sdbc._XParameters} : Collection of
   *       parameter types presented in the query.
   *   <li><code>'XRowUpdate.XRow'</code> for {@link ifc.sdbc._XRowUpdate} : <code>XRow</code>
   *       interface of the current component.
   *   <li><code>'XResultSetUpdate.UpdateTester'</code> for {@link ifc.sdbc._XResultSetUpdate}
   * </ul>
   *
   * @see com.sun.star.sdb.DatabaseContext
   * @see com.sun.star.sdb.DataSource
   */
  protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
    XMultiServiceFactory orb = (XMultiServiceFactory) Param.getMSF();
    uniqueSuffix++;
    boolean envCreatedOK = false;

    // initialize test table
    if (isMySQLDB) {
      try {
        DBTools.DataSourceInfo legacyDescriptor = dbTools.newDataSourceInfo();
        legacyDescriptor.Name = srcInf.Name;
        legacyDescriptor.User = srcInf.User;
        legacyDescriptor.Password = srcInf.Password;
        legacyDescriptor.Info = srcInf.Info;
        legacyDescriptor.URL = srcInf.URL;
        legacyDescriptor.IsPasswordRequired = srcInf.IsPasswordRequired;
        dbTools.initTestTableUsingJDBC(tableName, legacyDescriptor);
      } catch (java.sql.SQLException e) {
        e.printStackTrace(log);
        throw new StatusException(Status.failed("Couldn't " + " init test table. SQLException..."));
      } catch (java.lang.ClassNotFoundException e) {
        throw new StatusException(Status.failed("Couldn't " + "register mysql driver"));
      }
    } else {
      String oldF = null;
      String newF = null;
      String tempFolder = utils.getOfficeTemp(orb);
      do {
        tableName = "ORowSet_tmp" + uniqueSuffix;
        oldF = utils.getFullURL(origDB);
        newF = tempFolder + tableName + ".dbf";
      } while (!utils.tryOverwriteFile(orb, oldF, newF));
      m_tableFile = newF;
    }

    try {
      m_rowSet = orb.createInstance("com.sun.star.sdb.RowSet");

      XPropertySet rowSetProps = UnoRuntime.queryInterface(XPropertySet.class, m_rowSet);

      log.println("Trying to open: " + tableName);

      rowSetProps.setPropertyValue("DataSourceName", dbSourceName);
      rowSetProps.setPropertyValue("Command", tableName);
      rowSetProps.setPropertyValue("CommandType", new Integer(CommandType.TABLE));

      final XRowSet rowSet = UnoRuntime.queryInterface(XRowSet.class, m_rowSet);
      rowSet.execute();
      m_connection =
          UnoRuntime.queryInterface(
              XConnection.class, rowSetProps.getPropertyValue("ActiveConnection"));

      XResultSet xRes = UnoRuntime.queryInterface(XResultSet.class, m_rowSet);
      xRes.first();

      log.println("creating a new environment for object");
      TestEnvironment tEnv = new TestEnvironment((XInterface) m_rowSet);

      // Adding obj relation for XRowSetApproveBroadcaster test
      {
        final XResultSet resultSet = UnoRuntime.queryInterface(XResultSet.class, m_rowSet);
        final XResultSetUpdate resultSetUpdate =
            UnoRuntime.queryInterface(XResultSetUpdate.class, m_rowSet);
        final XRowUpdate rowUpdate = UnoRuntime.queryInterface(XRowUpdate.class, m_rowSet);
        final PrintWriter logF = log;
        tEnv.addObjRelation(
            "XRowSetApproveBroadcaster.ApproveChecker",
            new ifc.sdb._XRowSetApproveBroadcaster.RowSetApproveChecker() {
              public void moveCursor() {
                try {
                  resultSet.beforeFirst();
                  resultSet.afterLast();
                  resultSet.first();
                } catch (com.sun.star.sdbc.SQLException e) {
                  logF.println(
                      "### _XRowSetApproveBroadcaster.RowSetApproveChecker.moveCursor() :");
                  e.printStackTrace(logF);
                  throw new StatusException("RowSetApproveChecker.moveCursor failed", e);
                }
              }

              public RowChangeEvent changeRow() {
                try {
                  resultSet.first();
                  rowUpdate.updateString(1, "ORowSetTest2");
                  resultSetUpdate.updateRow();
                } catch (com.sun.star.sdbc.SQLException e) {
                  logF.println("### _XRowSetApproveBroadcaster.RowSetApproveChecker.changeRow() :");
                  e.printStackTrace(logF);
                  throw new StatusException("RowSetApproveChecker.changeRow failed", e);
                }
                RowChangeEvent ev = new RowChangeEvent();
                ev.Action = com.sun.star.sdb.RowChangeAction.UPDATE;
                ev.Rows = 1;

                return ev;
              }

              public void changeRowSet() {
                try {
                  // since we gave the row set a parametrized statement, we need to ensure the
                  // parameter is actually filled, otherwise we would get an empty result set,
                  // which would imply some further tests failing
                  XParameters rowSetParams =
                      UnoRuntime.queryInterface(XParameters.class, resultSet);
                  rowSetParams.setString(1, "String2");
                  rowSet.execute();
                  resultSet.first();
                } catch (com.sun.star.sdbc.SQLException e) {
                  logF.println(
                      "### _XRowSetApproveBroadcaster.RowSetApproveChecker.changeRowSet() :");
                  e.printStackTrace(logF);
                  throw new StatusException("RowSetApproveChecker.changeRowSet failed", e);
                }
              }
            });
      }
      // Adding relations for XRow as a Vector with all data
      // of current row of RowSet.

      ArrayList<Object> rowData = new ArrayList<Object>();

      for (int i = 0; i < DBTools.TST_TABLE_VALUES[0].length; i++) {
        rowData.add(DBTools.TST_TABLE_VALUES[0][i]);
      }

      // here XRef must be added
      // here XBlob must be added
      // here XClob must be added
      // here XArray must be added

      tEnv.addObjRelation("CurrentRowData", rowData);

      // Adding relation for XColumnLocate ifc test
      tEnv.addObjRelation("XColumnLocate.ColumnName", DBTools.TST_STRING_F);

      // Adding relation for XCompletedExecution
      tEnv.addObjRelation("InteractionHandlerChecker", new InteractionHandlerImpl());
      try {
        String sqlCommand =
            isMySQLDB
                ? "SELECT Column0  FROM soffice_test_table  WHERE ( (  Column0 = :param1 ) )"
                : "SELECT \"_TEXT\" FROM \"" + tableName + "\" WHERE ( ( \"_TEXT\" = :param1 ) )";
        rowSetProps.setPropertyValue("DataSourceName", dbSourceName);
        rowSetProps.setPropertyValue("Command", sqlCommand);
        rowSetProps.setPropertyValue("CommandType", new Integer(CommandType.COMMAND));
      } catch (Exception e) {
        throw new StatusException("setting up the RowSet with a parametrized command failed", e);
      }

      // Adding relation for XParameters ifc test
      tEnv.addObjRelation("XParameters.ParamValues", new ArrayList<String>());

      // Adding relation for XRowUpdate
      final XRow row = UnoRuntime.queryInterface(XRow.class, m_rowSet);
      tEnv.addObjRelation("XRowUpdate.XRow", row);

      // Adding relation for XResultSetUpdate
      {
        final XResultSet resultSet = UnoRuntime.queryInterface(XResultSet.class, m_rowSet);
        final XRowUpdate rowUpdate = UnoRuntime.queryInterface(XRowUpdate.class, m_rowSet);

        tEnv.addObjRelation(
            "XResultSetUpdate.UpdateTester",
            new ifc.sdbc._XResultSetUpdate.UpdateTester() {
              String lastUpdate = null;

              public int rowCount() throws SQLException {
                int prevPos = resultSet.getRow();
                resultSet.last();
                int count = resultSet.getRow();
                resultSet.absolute(prevPos);

                return count;
              }

              public void update() throws SQLException {
                lastUpdate = row.getString(1);
                lastUpdate += "_";
                rowUpdate.updateString(1, lastUpdate);
              }

              public boolean wasUpdated() throws SQLException {
                String getStr = row.getString(1);
                return lastUpdate.equals(getStr);
              }

              public int currentRow() throws SQLException {
                return resultSet.getRow();
              }
            });
      }

      envCreatedOK = true;
      return tEnv;

    } catch (com.sun.star.uno.Exception e) {
      log.println("couldn't set up test environment:");
      e.printStackTrace(log);
      try {
        if (m_connection != null) m_connection.close();
      } catch (Exception ex) {
      }
      throw new StatusException("couldn't set up test environment", e);
    } finally {
      if (!envCreatedOK) {
        try {
          m_connection.close();
        } catch (Exception ex) {
        }
      }
    }
  } // finish method getTestEnvironment
Beispiel #15
0
  @Override
  protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log)
      throws Exception {
    XInterface oObj = null;
    XWindowPeer the_win = null;
    XToolkit the_kit = null;
    XDevice aDevice = null;
    XGraphics aGraphic = null;
    XControl aControl = null;

    // Insert a ControlShape and get the ControlModel
    XControlShape aShape =
        FormTools.createUnoControlShape(
            xTextDoc, 3000, 4500, 15000, 10000, "ScrollBar", "UnoControlScrollBar");

    WriterTools.getDrawPage(xTextDoc).add(aShape);

    XControlModel the_Model = aShape.getControl();

    XControlShape aShape2 =
        FormTools.createControlShape(xTextDoc, 3000, 4500, 5000, 10000, "TextField");

    WriterTools.getDrawPage(xTextDoc).add(aShape2);

    XControlModel the_Model2 = aShape2.getControl();

    // Try to query XControlAccess
    XControlAccess the_access =
        UnoRuntime.queryInterface(XControlAccess.class, xTextDoc.getCurrentController());

    // get the ScrollBarControl for the needed Object relations
    oObj = the_access.getControl(the_Model);
    aControl = the_access.getControl(the_Model2);
    the_win = the_access.getControl(the_Model).getPeer();
    the_kit = the_win.getToolkit();
    aDevice = the_kit.createScreenCompatibleDevice(200, 200);
    aGraphic = aDevice.createGraphics();

    log.println("creating a new environment for UnoControlScrollBar object");

    TestEnvironment tEnv = new TestEnvironment(oObj);

    // adding Object-Relation for XScrollBar
    tEnv.addObjRelation("Document", xTextDoc);

    // Adding ObjRelation for XView
    tEnv.addObjRelation("GRAPHICS", aGraphic);

    // Adding ObjRelation for XControl
    tEnv.addObjRelation("CONTEXT", xTextDoc);
    tEnv.addObjRelation("WINPEER", the_win);
    tEnv.addObjRelation("TOOLKIT", the_kit);
    tEnv.addObjRelation("MODEL", the_Model);

    XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class, aControl);

    tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);

    System.out.println("ImplementationName: " + utils.getImplName(oObj));

    return tEnv;
  } // finish method getTestEnvironment
  /**
   * Creating a Testenvironment for the interfaces to be tested. Creates an instance of the service
   * <code>com.sun.star.comp.Calc.XMLSettingsImporter</code>
   *
   * <p>The calc document is set as a target document for importer. Imported XML-data contains only
   * settings tags including tag with new number of iteration steps. After import 'IterationCount'
   * proeprty getting from target document is checked. Object relations created :
   *
   * <ul>
   *   <li><code>'XDocumentHandler.XMLData'</code> for {@link ifc.xml.sax._XDocumentHandler}
   *       interface
   *   <li><code>'XDocumentHandler.ImportChecker'</code> for {@link ifc.xml.sax._XDocumentHandler}
   *       interface
   *   <li><code>'TargetDocument'</code> for {@link ifc.document._XImporter} interface
   * </ul>
   */
  public synchronized TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log)
      throws StatusException {

    XInterface oObj = null;
    Object oInt = null;

    // creation of testobject here
    // first we write what we are intend to do to log file
    log.println("creating a test environment");

    XMultiServiceFactory xMSF = (XMultiServiceFactory) tParam.getMSF();
    final XPropertySet xPropSet;

    try {
      oInt = xMSF.createInstance("com.sun.star.comp.Calc.XMLSettingsImporter");
      XImporter imp = UnoRuntime.queryInterface(XImporter.class, oInt);
      imp.setTargetDocument(comp);

      XModel xSheetModel = UnoRuntime.queryInterface(XModel.class, xSheetDoc);
      XController xController = xSheetModel.getCurrentController();
      xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xController);
    } catch (com.sun.star.uno.Exception e) {
      e.printStackTrace(log);
      throw new StatusException("Can't create component.", e);
    }

    oObj = (XInterface) oInt;

    // create testobject here
    log.println("creating a new environment for Paragraph object");
    TestEnvironment tEnv = new TestEnvironment(oObj);

    // adding relation
    tEnv.addObjRelation("TargetDocument", comp);

    // adding relation for XDocumentHandler
    String[][] xml =
        new String[][] {
          {
            "start",
            "office:document-settings",
            "xmlns:office",
            "CDATA",
            "http://openoffice.org/2000/office",
            "xmlns:xlink",
            "CDATA",
            "http://www.w3.org/1999/xlink",
            "xmlns:config",
            "CDATA",
            "http://openoffice.org/2001/config"
          },
          {"start", "office:settings"},
          {"start", "config:config-item-set", "config:name", "CDATA", "view-settings"},
          {"start", "config:config-item-map-indexed", "config:name", "CDATA", "Views"},
          {"start", "config:config-item-map-entry"},
          {
            "start",
            "config:config-item",
            "config:name",
            "CDATA",
            "ShowGrid",
            "config:type",
            "CDATA",
            "boolean"
          },
          {"chars", "false"},
          {"end", "config:config-item"},
          {
            "start",
            "config:config-item",
            "config:name",
            "CDATA",
            "ZoomType",
            "config:type",
            "CDATA",
            "short"
          },
          {"chars", "0"},
          {
            "start",
            "config:config-item",
            "config:name",
            "CDATA",
            "ZoomValue",
            "config:type",
            "CDATA",
            "int"
          },
          {"chars", "124"},
          {"end", "config:config-item"},
          {"end", "config:config-item"},
          {"end", "config:config-item-map-entry"},
          {"end", "config:config-item-map-indexed"},
          {"end", "config:config-item-set"},
          {"end", "office:settings"},
          {"end", "office:document-settings"}
        };

    tEnv.addObjRelation("XDocumentHandler.XMLData", xml);

    final PrintWriter logF = log;

    tEnv.addObjRelation(
        "XDocumentHandler.ImportChecker",
        new ifc.xml.sax._XDocumentHandler.ImportChecker() {
          public boolean checkImport() {
            try {
              Object gVal = xPropSet.getPropertyValue("ShowGrid");
              logF.println("ShowGrid = " + gVal);
              return "false".equals(gVal);
            } catch (com.sun.star.uno.Exception e) {
              logF.println("Exception occurred while checking filter :");
              e.printStackTrace(logF);
              return false;
            }
          }
        });

    return tEnv;
  } // finish method getTestEnvironment
  /**
   * 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;
  }
  /**
   * Creating a Testenvironment for the interfaces to be tested. Retrieves the collection of style
   * families available in the document using the interface <code>XStyleFamiliesSupplier</code>.
   * Obtains default style from the style family <code>'PageStyles'</code>. Retrieves value of the
   * property <code>'RightPageHeaderContent'</code>. Sets some string for the text which is printed
   * in the center part of the header or footer using the interface <code>XHeaderFooterContent
   * </code> and sets new value of the property <code>'RightPageHeaderContent'</code>. Creates text
   * cursor for the text which is printed in the center part of the header or footer. This text
   * cursor is the instance of the service <code>com.sun.star.text.TextCursor</code>.
   * </ul>
   */
  protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {

    XInterface oObj = null;
    XPropertySet PropSet;
    XNameAccess PageStyles = null;
    XStyle StdStyle = null;

    XStyleFamiliesSupplier StyleFam =
        UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xSpreadsheetDoc);

    XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
    try {
      PageStyles =
          (XNameAccess)
              AnyConverter.toObject(
                  new Type(XNameAccess.class), StyleFamNames.getByName("PageStyles"));
      StdStyle =
          (XStyle) AnyConverter.toObject(new Type(XStyle.class), PageStyles.getByName("Default"));
    } catch (com.sun.star.lang.WrappedTargetException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get by name", e);
    } catch (com.sun.star.container.NoSuchElementException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get by name", e);
    } catch (com.sun.star.lang.IllegalArgumentException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get by name", e);
    }

    // get the property-set
    PropSet = UnoRuntime.queryInterface(XPropertySet.class, StdStyle);

    XHeaderFooterContent RPHC = null;
    // creation of testobject here
    // first we write what we are intend to do to log file
    log.println("creating a test environment");
    try {
      RPHC =
          (XHeaderFooterContent)
              AnyConverter.toObject(
                  new Type(XHeaderFooterContent.class),
                  PropSet.getPropertyValue("RightPageHeaderContent"));
    } catch (com.sun.star.lang.WrappedTargetException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get HeaderContent", e);
    } catch (com.sun.star.beans.UnknownPropertyException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get HeaderContent", e);
    } catch (com.sun.star.lang.IllegalArgumentException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get HeaderContent", e);
    }

    XText center = RPHC.getCenterText();
    center.setString("CENTER");

    try {
      PropSet.setPropertyValue("RightPageHeaderContent", RPHC);
    } catch (com.sun.star.lang.WrappedTargetException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't set HeaderContent", e);
    } catch (com.sun.star.lang.IllegalArgumentException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't set HeaderContent", e);
    } catch (com.sun.star.beans.PropertyVetoException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't set HeaderContent", e);
    } catch (com.sun.star.beans.UnknownPropertyException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't set HeaderContent", e);
    }

    // create testobject here
    oObj = center.createTextCursor();
    TestEnvironment tEnv = new TestEnvironment(oObj);

    // add relation for XTextRange
    tEnv.addObjRelation("XTEXT", UnoRuntime.queryInterface(XText.class, center));

    return tEnv;
  } // finish method getTestEnvironment