Exemple #1
0
 private void insertLinebreaks(long seed) {
   XText xText = m_xDoc.getText();
   java.util.Random rnd = new java.util.Random(seed);
   XTextCursor xCursor = m_xDoc.getText().createTextCursor();
   for (int i = 0; i < 30; i++) {
     xCursor.goRight((short) rnd.nextInt(300), false);
     XTextRange xCursorAsRange = UnoRuntime.queryInterface(XTextRange.class, xCursor);
     xText.insertControlCharacter(
         xCursorAsRange, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false);
   }
 }
  public void addTextArea(Object documentObj, String text, int x, int y, int width, int height)
      throws Exception {
    XTextDocument document = (XTextDocument) documentObj;
    XMultiServiceFactory factory = query(XMultiServiceFactory.class, document);

    XTextFrame xFrame = create(XTextFrame.class, factory, X_TEXTFRAME);

    setPositionAndSize(xFrame, x, y, width, height);

    XText xText = document.getText();
    xText.insertTextContent(xText.getEnd(), xFrame, false);

    appendText(xFrame.getText(), text);
  }
  /**
   * Creating a TestEnvironment for the interfaces to be tested. Creates an instance of the service
   * <code>com.sun.star.text.Endnote</code>. Then created endnote is inserted to the text document,
   * and finally endnote settings are gotten from text document using <code>XEndnotesSupplier</code>
   * interface.
   */
  @Override
  public TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log)
      throws Exception {
    XEndnotesSupplier oInterface = null;
    XInterface oObj = null;
    XInterface oEndnote;

    log.println("Creating a test environment");
    XMultiServiceFactory msf = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
    log.println("creating a endnote");
    oEndnote =
        UnoRuntime.queryInterface(
            XInterface.class, msf.createInstance("com.sun.star.text.Endnote"));

    XText oText = xTextDoc.getText();
    XTextCursor oCursor = oText.createTextCursor();

    log.println("inserting the footnote into text document");
    XTextContent xTC = UnoRuntime.queryInterface(XTextContent.class, oEndnote);
    oText.insertTextContent(oCursor, xTC, false);

    oInterface = UnoRuntime.queryInterface(XEndnotesSupplier.class, xTextDoc);
    oObj = oInterface.getEndnoteSettings();
    dbg.printPropertiesNames((XPropertySet) oObj);

    TestEnvironment tEnv = new TestEnvironment(oObj);
    return tEnv;
  }
Exemple #4
0
 private void insertRandomParts(long seed) {
   java.util.Random rnd = new java.util.Random(seed);
   XTextCursor xCursor = m_xDoc.getText().createTextCursor();
   for (int i = 0; i < 600; i++) {
     xCursor.goRight((short) rnd.nextInt(100), false);
     xCursor.setString(Long.toString(rnd.nextLong()));
   }
 }
Exemple #5
0
 private void deleteRandomParts(long seed) {
   java.util.Random rnd = new java.util.Random(seed);
   XTextCursor xCursor = m_xDoc.getText().createTextCursor();
   for (int i = 0; i < 600; i++) {
     xCursor.goRight((short) rnd.nextInt(100), false);
     xCursor.goRight((short) rnd.nextInt(20), true);
     xCursor.setString("");
   }
 }
  /** Disposes the document, if exists, created in <code>createTestEnvironment</code> method. */
  @Override
  protected void cleanup(TestParameters Param, PrintWriter log) {

    log.println("disposing xTextDoc");

    if (xTextDoc != null) {
      xTextDoc.dispose();
    }
  }
Exemple #7
0
  private void insertBookmark(XTextCursor crsr, String name, String content)
      throws com.sun.star.uno.Exception {
    XMultiServiceFactory xDocFactory =
        UnoRuntime.queryInterface(XMultiServiceFactory.class, m_xDoc);

    Object xBookmark = xDocFactory.createInstance("com.sun.star.text.Bookmark");
    XTextContent xBookmarkAsTextContent = UnoRuntime.queryInterface(XTextContent.class, xBookmark);
    crsr.setString(content);
    XNamed xBookmarkAsNamed = UnoRuntime.queryInterface(XNamed.class, xBookmark);
    xBookmarkAsNamed.setName(name);
    m_xDoc.getText().insertTextContent(crsr, xBookmarkAsTextContent, true);
  }
Exemple #8
0
 private void setupBookmarks() throws com.sun.star.uno.Exception {
   XText xText = m_xDoc.getText();
   UnoRuntime.queryInterface(XSimpleText.class, xText);
   for (int nPara = 0; nPara < 10; ++nPara) {
     for (int nBookmark = 0; nBookmark < 100; ++nBookmark) {
       insertBookmark(
           xText.createTextCursor(),
           "P" + nPara + "word" + nBookmark,
           "P" + nPara + "word" + nBookmark);
       XTextCursor xWordCursor = xText.createTextCursor();
       xWordCursor.setString(" ");
     }
     XTextCursor xParaCursor = xText.createTextCursor();
     XTextRange xParaCursorAsRange = UnoRuntime.queryInterface(XTextRange.class, xParaCursor);
     xText.insertControlCharacter(
         xParaCursorAsRange, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false);
   }
 }
  /**
   * Creating a Testenvironment for the interfaces to be tested. Creates an instance of the service
   * <code>com.sun.star.text.TextFrame</code>. Then inserts created text frame to the text, and
   * finally gets all frames of text document using <code>XTextFramesSupplier</code> interface.<br>
   */
  public synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log)
      throws StatusException {
    XInterface oObj = null;
    XTextFrame oFrame1 = null;
    XText oText = null;
    XTextCursor oCursor = null;
    XMultiServiceFactory oDocMSF = null;
    XTextFramesSupplier oInterface = null;

    log.println("creating a test environment");
    try {
      oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
      Object oInt = oDocMSF.createInstance("com.sun.star.text.TextFrame");
      oFrame1 = UnoRuntime.queryInterface(XTextFrame.class, oInt);
    } catch (com.sun.star.uno.Exception e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't create instance of TextFrame", e);
    }

    oText = xTextDoc.getText();
    oCursor = oText.createTextCursor();

    try {
      oText.insertTextContent(oCursor, oFrame1, false);
    } catch (com.sun.star.lang.IllegalArgumentException e) {
      e.printStackTrace(log);
      throw new StatusException("Error: can't insert text content to text document", e);
    }

    oInterface = UnoRuntime.queryInterface(XTextFramesSupplier.class, xTextDoc);

    oObj = oInterface.getTextFrames();

    log.println("creating a new environment for Frame object");
    TestEnvironment tEnv = new TestEnvironment(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.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
  private XComponent loadRDFa(String file) throws Exception {
    XComponent xComp = null;

    System.out.println("Loading test document...");

    PropertyValue[] loadProps = new PropertyValue[1];
    loadProps[0] = new PropertyValue();
    loadProps[0].Name = "Hidden";
    loadProps[0].Value = true;

    xComp = util.DesktopTools.loadDoc(xMSF, file, loadProps);

    XRepositorySupplier xRepoSupplier = UnoRuntime.queryInterface(XRepositorySupplier.class, xComp);
    assertTrue("xRS null", null != xRepoSupplier);

    XDocumentRepository xDocRepository =
        UnoRuntime.queryInterface(XDocumentRepository.class, xRepoSupplier.getRDFRepository());
    assertTrue("xRep null", null != xDocRepository);

    XTextDocument xTextDoc = UnoRuntime.queryInterface(XTextDocument.class, xComp);

    XText xText = xTextDoc.getText();

    XEnumerationAccess xEA = UnoRuntime.queryInterface(XEnumerationAccess.class, xText);
    XEnumeration xEnum = xEA.createEnumeration();

    System.out.println("...done");

    System.out.println("Checking RDFa in loaded test document...");

    XMetadatable xPara;
    Pair<Statement[], Boolean> result;

    Statement x_FooBarLit1 = new Statement(foo, bar, mkLit("1"), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 1", !result.Second && eq(result.First, new Statement[] {x_FooBarLit1}));

    Statement x_FooBarLit2 = new Statement(foo, bar, mkLit("2"), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 2", !result.Second && eq(result.First, new Statement[] {x_FooBarLit2}));

    Statement x_BlankBarLit3 = new Statement(blank1, bar, mkLit("3"), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 3", !result.Second && eq(result.First, new Statement[] {x_BlankBarLit3}));
    XBlankNode b3 = UnoRuntime.queryInterface(XBlankNode.class, result.First[0].Subject);

    Statement x_BlankBarLit4 = new Statement(blank2, bar, mkLit("4"), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 4", !result.Second && eq(result.First, new Statement[] {x_BlankBarLit4}));
    XBlankNode b4 = UnoRuntime.queryInterface(XBlankNode.class, result.First[0].Subject);

    Statement x_BlankBarLit5 = new Statement(blank1, bar, mkLit("5"), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 5", !result.Second && eq(result.First, new Statement[] {x_BlankBarLit5}));
    XBlankNode b5 = UnoRuntime.queryInterface(XBlankNode.class, result.First[0].Subject);

    assertTrue("RDFa: 3 != 4", !b3.getStringValue().equals(b4.getStringValue()));
    assertTrue("RDFa: 3 == 5", b3.getStringValue().equals(b5.getStringValue()));

    Statement x_FooBarLit6 = new Statement(foo, bar, mkLit("6"), null);
    Statement x_FooBazLit6 = new Statement(foo, baz, mkLit("6"), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue(
        "RDFa: 6",
        !result.Second && eq(result.First, new Statement[] {x_FooBarLit6, x_FooBazLit6}));

    Statement x_FooBarLit7 = new Statement(foo, bar, mkLit("7"), null);
    Statement x_FooBazLit7 = new Statement(foo, baz, mkLit("7"), null);
    Statement x_FooFooLit7 = new Statement(foo, foo, mkLit("7"), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue(
        "RDFa: 7",
        !result.Second
            && eq(result.First, new Statement[] {x_FooBarLit7, x_FooBazLit7, x_FooFooLit7}));

    XNode lit = mkLit("a fooish bar");
    XNode lit_type = mkLit("a fooish bar", bar);
    Statement x_FooBarLit = new Statement(foo, bar, lit, null);
    Statement x_FooBarLittype = new Statement(foo, bar, lit_type, null);

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 8", result.Second && eq(result.First, new Statement[] {x_FooBarLit}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 9", result.Second && eq(result.First, new Statement[] {x_FooBarLit}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 10", result.Second && eq(result.First, new Statement[] {x_FooBarLittype}));

    Statement x_FooBarLit11 = new Statement(foo, bar, mkLit("11", bar), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 11", !result.Second && eq(result.First, new Statement[] {x_FooBarLit11}));

    XURI xFile = URI.createNS(xContext, file, "/" + contentPath);
    Statement x_FileBarLit12 = new Statement(xFile, bar, mkLit("12"), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 12", !result.Second && eq(result.First, new Statement[] {x_FileBarLit12}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 13", result.Second && eq(result.First, new Statement[] {x_FooBarLit}));

    new Statement(foo, rdfs_label, mkLit("14"), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue(
        "RDFa: 14",
        result.Second && eq(result.First, new Statement[] {/* x_FooLabelLit14 */ x_FooBarLit}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 15", eq(result.First, new Statement[] {}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 16", eq(result.First, new Statement[] {}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 17", eq(result.First, new Statement[] {}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 18", eq(result.First, new Statement[] {}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 19", eq(result.First, new Statement[] {}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 20", eq(result.First, new Statement[] {}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 21", eq(result.First, new Statement[] {}));

    System.out.println("...done");

    return xComp;
  }
  /**
   * 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;
  }
  @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
Exemple #16
0
 /** Disposes the document created in <code>before</code> method. */
 @Override
 protected void after() {
   aTextDoc.dispose();
 }
  /**
   * 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;
  }
  @Test
  public void check() throws Exception {
    XComponent xComp = null;
    XComponent xComp2 = null;
    try {
      XEnumeration xStmtsEnum;
      XNamedGraph xManifest;

      System.out.println("Creating document with Repository...");

      // we cannot create a XDMA directly, we must create
      // a document and get it from there :(
      // create document
      PropertyValue[] loadProps = new PropertyValue[1];
      loadProps[0] = new PropertyValue();
      loadProps[0].Name = "Hidden";
      loadProps[0].Value = true;
      xComp = util.DesktopTools.openNewDoc(xMSF, "swriter", loadProps);
      XTextDocument xText = UnoRuntime.queryInterface(XTextDocument.class, xComp);

      XRepositorySupplier xRepoSupplier =
          UnoRuntime.queryInterface(XRepositorySupplier.class, xComp);
      assertNotNull("xRS null", xRepoSupplier);
      XDocumentMetadataAccess xDocMDAccess =
          UnoRuntime.queryInterface(XDocumentMetadataAccess.class, xRepoSupplier);
      assertNotNull("xDMA null", xDocMDAccess);
      xRep = xRepoSupplier.getRDFRepository();
      assertNotNull("xRep null", xRep);

      System.out.println("...done");

      System.out.println("Checking that new repository is initialized...");

      XURI xBaseURI = xDocMDAccess;
      String baseURI = xBaseURI.getStringValue();
      assertNotNull("new: baseURI", xBaseURI);
      assertTrue("new: baseURI", !xBaseURI.getStringValue().equals(""));

      assertTrue("new: # graphs", 1 == xRep.getGraphNames().length);
      XURI manifest = URI.createNS(xContext, xBaseURI.getStringValue(), manifestPath);
      xManifest = xRep.getGraph(manifest);
      assertTrue("new: manifest graph", null != xManifest);

      Statement[] manifestStmts = getManifestStmts(xBaseURI);
      xStmtsEnum = xRep.getStatements(null, null, null);
      assertTrue("new: manifest graph", eq(xStmtsEnum, manifestStmts));

      System.out.println("...done");

      System.out.println("Checking some invalid args...");

      String content = "behold, for I am the content.";
      new TestRange(content);

      try {
        xDocMDAccess.getElementByURI(null);
        fail("getElementByURI: null allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.getMetadataGraphsWithType(null);
        fail("getMetadataGraphsWithType: null URI allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("", new XURI[0]);
        fail("addMetadataFile: empty filename allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("/foo", new XURI[0]);
        fail("addMetadataFile: absolute filename allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("fo\"o", new XURI[0]);
        fail("addMetadataFile: invalid filename allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("../foo", new XURI[0]);
        fail("addMetadataFile: filename with .. allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("foo/../../bar", new XURI[0]);
        fail("addMetadataFile: filename with nest .. allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("foo/././bar", new XURI[0]);
        fail("addMetadataFile: filename with nest . allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("content.xml", new XURI[0]);
        fail("addMetadataFile: content.xml allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("styles.xml", new XURI[0]);
        fail("addMetadataFile: styles.xml allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("meta.xml", new XURI[0]);
        fail("addMetadataFile: meta.xml allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("settings.xml", new XURI[0]);
        fail("addMetadataFile: settings.xml allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.importMetadataFile(FileFormat.RDF_XML, null, "foo", foo, new XURI[0]);
        fail("importMetadataFile: null stream allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }

      final String sEmptyRDF = TestDocument.getUrl("empty.rdf");
      try {
        XInputStream xFooIn = new StreamSimulator(sEmptyRDF, true, param);
        xDocMDAccess.importMetadataFile(FileFormat.RDF_XML, xFooIn, "", foo, new XURI[0]);
        fail("importMetadataFile: empty filename allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        XInputStream xFooIn = new StreamSimulator(sEmptyRDF, true, param);
        xDocMDAccess.importMetadataFile(FileFormat.RDF_XML, xFooIn, "meta.xml", foo, new XURI[0]);
        fail("importMetadataFile: meta.xml filename allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        XInputStream xFooIn = new StreamSimulator(sEmptyRDF, true, param);
        xDocMDAccess.importMetadataFile(FileFormat.RDF_XML, xFooIn, "foo", null, new XURI[0]);
        fail("importMetadataFile: null base URI allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        XInputStream xFooIn = new StreamSimulator(sEmptyRDF, true, param);
        xDocMDAccess.importMetadataFile(FileFormat.RDF_XML, xFooIn, "foo", rdf_type, new XURI[0]);
        fail("importMetadataFile: non-absolute base URI allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.removeMetadataFile(null);
        fail("removeMetadataFile: null URI allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addContentOrStylesFile("");
        fail("addContentOrStylesFile: empty filename allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addContentOrStylesFile("/content.xml");
        fail("addContentOrStylesFile: absolute filename allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addContentOrStylesFile("foo.rdf");
        fail("addContentOrStylesFile: invalid filename allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.removeContentOrStylesFile("");
        fail("removeContentOrStylesFile: empty filename allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.loadMetadataFromStorage(null, foo, null);
        fail("loadMetadataFromStorage: null storage allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.storeMetadataToStorage(null /*, base*/);
        fail("storeMetadataToStorage: null storage allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.loadMetadataFromMedium(new PropertyValue[0]);
        fail("loadMetadataFromMedium: empty medium allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.storeMetadataToMedium(new PropertyValue[0]);
        fail("storeMetadataToMedium: empty medium allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }

      System.out.println("...done");

      System.out.println("Checking file addition/removal...");

      xDocMDAccess.removeContentOrStylesFile(contentPath);
      xStmtsEnum = xManifest.getStatements(null, null, null);
      assertTrue(
          "removeContentOrStylesFile (content)",
          eq(xStmtsEnum, new Statement[] {manifestStmts[0], manifestStmts[2], manifestStmts[4]}));

      xDocMDAccess.addContentOrStylesFile(contentPath);
      xStmtsEnum = xManifest.getStatements(null, null, null);
      assertTrue("addContentOrStylesFile (content)", eq(xStmtsEnum, manifestStmts));

      xDocMDAccess.removeContentOrStylesFile(stylesPath);
      xStmtsEnum = xManifest.getStatements(null, null, null);
      assertTrue(
          "removeContentOrStylesFile (styles)",
          eq(xStmtsEnum, new Statement[] {manifestStmts[0], manifestStmts[1], manifestStmts[3]}));

      xDocMDAccess.addContentOrStylesFile(stylesPath);
      xStmtsEnum = xManifest.getStatements(null, null, null);
      assertTrue("addContentOrStylesFile (styles)", eq(xStmtsEnum, manifestStmts));

      XURI xFoo = URI.createNS(xContext, xBaseURI.getStringValue(), fooPath);
      Statement xM_BaseHaspartFoo = new Statement(xBaseURI, pkg_hasPart, xFoo, manifest);
      Statement xM_FooTypeMetadata = new Statement(xFoo, rdf_type, pkg_MetadataFile, manifest);
      Statement xM_FooTypeBar = new Statement(xFoo, rdf_type, bar, manifest);
      xDocMDAccess.addMetadataFile(fooPath, new XURI[] {bar});
      xStmtsEnum = xManifest.getStatements(null, null, null);
      assertTrue(
          "addMetadataFile",
          eq(
              xStmtsEnum,
              merge(
                  manifestStmts,
                  new Statement[] {xM_BaseHaspartFoo, xM_FooTypeMetadata, xM_FooTypeBar})));

      XURI[] graphsBar = xDocMDAccess.getMetadataGraphsWithType(bar);
      assertTrue("getMetadataGraphsWithType", graphsBar.length == 1 && eq(graphsBar[0], xFoo));

      xDocMDAccess.removeMetadataFile(xFoo);
      xStmtsEnum = xManifest.getStatements(null, null, null);
      assertTrue("removeMetadataFile", eq(xStmtsEnum, manifestStmts));

      System.out.println("...done");

      System.out.println("Checking mapping...");

      XEnumerationAccess xTextEnum =
          UnoRuntime.queryInterface(XEnumerationAccess.class, xText.getText());
      Object o = xTextEnum.createEnumeration().nextElement();
      XMetadatable xMeta1 = UnoRuntime.queryInterface(XMetadatable.class, o);

      XMetadatable xMeta;
      xMeta = xDocMDAccess.getElementByURI(xMeta1);
      assertTrue("getElementByURI: null", null != xMeta);
      String XmlId = xMeta.getMetadataReference().Second;
      String XmlId1 = xMeta1.getMetadataReference().Second;
      assertTrue("getElementByURI: no xml id", !XmlId.equals(""));
      assertTrue("getElementByURI: different xml id", XmlId.equals(XmlId1));

      System.out.println("...done");

      System.out.println("Checking storing and loading...");

      XURI xFoobar = URI.createNS(xContext, xBaseURI.getStringValue(), fooBarPath);
      Statement[] metadataStmts = getMetadataFileStmts(xBaseURI, fooBarPath);
      xDocMDAccess.addMetadataFile(fooBarPath, new XURI[0]);
      xStmtsEnum = xRep.getStatements(null, null, null);
      assertTrue("addMetadataFile", eq(xStmtsEnum, merge(manifestStmts, metadataStmts)));

      Statement xFoobar_FooBarFoo = new Statement(foo, bar, foo, xFoobar);
      xRep.getGraph(xFoobar).addStatement(foo, bar, foo);
      xStmtsEnum = xRep.getStatements(null, null, null);
      assertTrue(
          "addStatement",
          eq(
              xStmtsEnum,
              merge(manifestStmts, merge(metadataStmts, new Statement[] {xFoobar_FooBarFoo}))));

      PropertyValue noMDNoContentFile = new PropertyValue();
      noMDNoContentFile.Name = "URL";
      noMDNoContentFile.Value = TestDocument.getUrl("CUSTOM.odt");
      PropertyValue noMDFile = new PropertyValue();
      noMDFile.Name = "URL";
      noMDFile.Value = TestDocument.getUrl("TEST.odt");
      PropertyValue file = new PropertyValue();
      file.Name = "URL";
      file.Value = tempDir + "TESTDMA.odt";
      PropertyValue mimetype = new PropertyValue();
      mimetype.Name = "MediaType";
      mimetype.Value = "application/vnd.oasis.opendocument.text";
      PropertyValue[] argsEmptyNoContent = {mimetype, noMDNoContentFile};
      PropertyValue[] argsEmpty = {mimetype, noMDFile};
      PropertyValue[] args = {mimetype, file};

      xStmtsEnum = xRep.getStatements(null, null, null);
      XURI[] graphs = xRep.getGraphNames();

      xDocMDAccess.storeMetadataToMedium(args);

      // this should re-init
      xDocMDAccess.loadMetadataFromMedium(argsEmptyNoContent);
      xRep = xRepoSupplier.getRDFRepository();
      assertTrue("xRep null", null != xRep);
      assertTrue("baseURI still tdoc?", !baseURI.equals(xDocMDAccess.getStringValue()));
      Statement[] manifestStmts2 = getManifestStmts(xDocMDAccess);
      xStmtsEnum = xRep.getStatements(null, null, null);
      // there is no content or styles file in here, so we have just
      // the package stmt
      assertTrue(
          "loadMetadataFromMedium (no metadata, no content)",
          eq(xStmtsEnum, new Statement[] {manifestStmts2[0]}));

      // this should re-init
      xDocMDAccess.loadMetadataFromMedium(argsEmpty);
      xRep = xRepoSupplier.getRDFRepository();
      assertTrue("xRep null", null != xRep);
      assertTrue("baseURI still tdoc?", !baseURI.equals(xDocMDAccess.getStringValue()));
      Statement[] manifestStmts3 = getManifestStmts(xDocMDAccess);

      xStmtsEnum = xRep.getStatements(null, null, null);
      assertTrue("loadMetadataFromMedium (no metadata)", eq(xStmtsEnum, manifestStmts3));

      xDocMDAccess.loadMetadataFromMedium(args);
      xRep = xRepoSupplier.getRDFRepository();
      assertTrue("xRep null", null != xRep);
      Statement[] manifestStmts4 = getManifestStmts(xDocMDAccess);
      Statement[] metadataStmts4 = getMetadataFileStmts(xDocMDAccess, fooBarPath);

      xStmtsEnum = xRep.getStatements(null, null, null);
      assertTrue("some graph(s) not reloaded", graphs.length == xRep.getGraphNames().length);

      XURI xFoobar4 = URI.createNS(xContext, xDocMDAccess.getStringValue(), fooBarPath);
      Statement xFoobar_FooBarFoo4 = new Statement(foo, bar, foo, xFoobar4);
      assertTrue(
          "loadMetadataFromMedium (re-load)",
          eq(
              xStmtsEnum,
              merge(manifestStmts4, merge(metadataStmts4, new Statement[] {xFoobar_FooBarFoo4}))));

      System.out.println("...done");

      System.out.println("Checking storing and loading via model...");

      String f = tempDir + "TESTPARA.odt";

      XStorable xStor = UnoRuntime.queryInterface(XStorable.class, xRepoSupplier);

      xStor.storeToURL(f, new PropertyValue[0]);

      xComp2 = util.DesktopTools.loadDoc(xMSF, f, loadProps);

      XDocumentMetadataAccess xDMA2 =
          UnoRuntime.queryInterface(XDocumentMetadataAccess.class, xComp2);
      assertTrue("xDMA2 null", null != xDMA2);

      XRepositorySupplier xRS2 = UnoRuntime.queryInterface(XRepositorySupplier.class, xComp2);
      assertTrue("xRS2 null", null != xRS2);

      XRepository xRep2 = xRS2.getRDFRepository();
      assertTrue("xRep2 null", null != xRep2);

      Statement[] manifestStmts5 = getManifestStmts(xDMA2);
      Statement[] metadataStmts5 = getMetadataFileStmts(xDMA2, fooBarPath);
      XURI xFoobar5 = URI.createNS(xContext, xDMA2.getStringValue(), fooBarPath);
      Statement xFoobar_FooBarFoo5 = new Statement(foo, bar, foo, xFoobar5);
      xStmtsEnum = xRep.getStatements(null, null, null);
      XEnumeration xStmtsEnum2 = xRep2.getStatements(null, null, null);
      assertTrue(
          "load: repository differs",
          eq(
              xStmtsEnum2,
              merge(manifestStmts5, merge(metadataStmts5, new Statement[] {xFoobar_FooBarFoo5}))));

      System.out.println("...done");

    } finally {
      close(xComp);
      close(xComp2);
    }
  }