コード例 #1
0
ファイル: MozabDriver.java プロジェクト: zzz99977/core
  /**
   * 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;
  }
コード例 #2
0
  /**
   * Retrieves object relations.
   *
   * @throws StatusException If one of relations not found.
   */
  protected void before() {
    locale = (Locale) tEnv.getObjRelation("Locale");
    if (locale == null) {
      throw new StatusException(Status.failed("Relation 'Locale' not found"));
    }

    UnicodeString = (String) tEnv.getObjRelation("UnicodeString");
    if (UnicodeString == null) {
      throw new StatusException(Status.failed("Relation 'UnicodeString' not found"));
    }
  }
コード例 #3
0
  public void _startRangeSelection() {
    requiredMethod("addRangeSelectionChangeListener()");
    requiredMethod("addRangeSelectionListener()");

    // get the sheet center
    Point center = getSheetCenter();
    if (center == null) throw new StatusException(Status.failed("Couldn't get the sheet center."));

    PropertyValue[] props = new PropertyValue[3];
    props[0] = new PropertyValue();
    props[0].Name = "InitialValue";
    props[0].Value = "B3:D5";
    props[1] = new PropertyValue();
    props[1].Name = "Title";
    props[1].Value = "the title";
    props[2] = new PropertyValue();
    props[2].Name = "CloseOnMouseRelease";
    props[2].Value = Boolean.FALSE;
    oObj.startRangeSelection(props);
    // wait for listeners
    util.utils.shortWait(1000);

    // get closer button: move if window cobvers the sheet center
    Point closer = getCloser(center);
    if (closer == null) throw new StatusException(Status.failed("Couldn't get the close Button."));

    // do something to trigger the listeners
    clickOnSheet(center);
    util.utils.shortWait(5000);

    // click on closer
    clickOnSheet(closer);
    util.utils.shortWait(5000);

    // open a new range selection
    props[0].Value = "C4:E6";
    oObj.startRangeSelection(props);
    util.utils.shortWait(1000);
    props[0].Value = "C2:E3";
    oObj.startRangeSelection(props);
    util.utils.shortWait(1000);

    oObj.startRangeSelection(props);
    util.utils.shortWait(1000);
    oObj.abortRangeSelection();
    aListener.reset();
    System.out.println("Listener called: " + aListener.bAbortCalled);

    tRes.tested("startRangeSelection()", aListener.listenerCalled());
  }
コード例 #4
0
ファイル: _XFrameLoader.java プロジェクト: vancuvit/core
  /**
   * Retrieves all relations. If optional ones are not found creates their default values.
   *
   * <p>
   *
   * @throws StatusException If one of required relations not found.
   */
  public void before() {
    url = (String) tEnv.getObjRelation("FrameLoader.URL");
    frame = (XFrame) tEnv.getObjRelation("FrameLoader.Frame");

    if (frame == null) {
      SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory) tParam.getMSF());

      try {
        log.println("creating a textdocument");
        frameSup = SOF.createTextDoc(null);

        Object oDsk =
            ((XMultiServiceFactory) tParam.getMSF()).createInstance("com.sun.star.frame.Desktop");
        XDesktop dsk = UnoRuntime.queryInterface(XDesktop.class, oDsk);

        shortWait();
        frame = dsk.getCurrentFrame();
      } catch (com.sun.star.uno.Exception e) {
        // Some exception occurs.FAILED
        e.printStackTrace(log);
        throw new StatusException("Couldn't create a frame.", e);
      }
    }

    Object args = tEnv.getObjRelation("FrameLoader.args");
    if (args != null) this.args = (PropertyValue[]) args;

    if (url == null /*|| frame == null*/) {
      throw new StatusException(Status.failed("Some relations not found"));
    }
  }
  /**
   * Creating a Testenvironment for the interfaces to be tested. Creates an instance of the service
   * <code>com.sun.star.sdb.DatasourceAdministrationDialog</code>.
   */
  public TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log)
      throws StatusException {
    XInterface oObj = null;
    Object oInterface = null;

    try {
      oInterface =
          ((XMultiServiceFactory) Param.getMSF())
              .createInstance("com.sun.star.sdb.DatasourceAdministrationDialog");
    } catch (com.sun.star.uno.Exception e) {
      log.println("Service not available");
      throw new StatusException("Service not available", e);
    }

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

    oObj = (XInterface) oInterface;

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

    return tEnv;
  } // finish method getTestEnvironment
コード例 #6
0
  /**
   * 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
コード例 #7
0
  public void before() {
    xSpreadsheetView = UnoRuntime.queryInterface(XSpreadsheetView.class, tEnv.getTestObject());

    two = (XSpreadsheet) tEnv.getObjRelation("Sheet");

    if ((xSpreadsheetView == null) || (two == null)) {
      throw new StatusException(Status.failed("precondition for test is missing"));
    }
  }
コード例 #8
0
  /**
   * Test reads persist object from stream and compares properties of the object with properties of
   * persist object obtained from relation <code>'PersistObject'</code>
   *
   * <p>Has <b> OK </b> status if returned value isn't null and values of objects properties are
   * equal.
   *
   * <p>
   */
  public void _readObject() {
    Object objWrite = tEnv.getObjRelation("PersistObject");
    if (objWrite == null) {
      log.println("PersistObject not found in relations");
      tRes.tested("readObject()", false);
      return;
    }

    // write the object
    try {
      XObjectOutputStream oStream = (XObjectOutputStream) tEnv.getObjRelation("StreamWriter");
      oStream.writeObject((XPersistObject) objWrite);
    } catch (com.sun.star.io.IOException e) {
      log.println("Couldn't write object to stream");
      e.printStackTrace(log);
      tRes.tested("readObject()", Status.skipped(false));
      return;
    }

    Object objRead = null;
    try {
      objRead = oObj.readObject();
    } catch (com.sun.star.io.IOException e) {
      log.println("Couldn't read object from stream");
      e.printStackTrace(log);
      tRes.tested("readObject()", false);
      return;
    }

    if (objRead == null) {
      log.println("No object was read.");
      tRes.tested("readObject()", false);
      return;
    }

    XPropertySet props1 = null;
    XPropertySet props2 = null;

    props1 = UnoRuntime.queryInterface(XPropertySet.class, objRead);

    props2 = UnoRuntime.queryInterface(XPropertySet.class, objWrite);

    if (props1 == null) {
      log.println("Object read doesn't implement XPropertySet");
      tRes.tested("readObject()", false);
      return;
    }
    if (props2 == null) {
      log.println("Object written doesn't implement XPropertySet");
      tRes.tested("readObject()", false);
      return;
    }

    tRes.tested("readObject()", compareProperties(props1, props2));
  }
コード例 #9
0
 public void before() {
   aListener = new _XRangeSelection.MyRangeSelectionListener(log);
   // workaround for i34499
   XModel xModel = (XModel) tEnv.getObjRelation("FirstModel");
   if (xModel == null)
     throw new StatusException(Status.failed("Object relation FirstModel' not set."));
   XWindow xWindow = xModel.getCurrentController().getFrame().getContainerWindow();
   XTopWindow xTopWindow = UnoRuntime.queryInterface(XTopWindow.class, xWindow);
   xTopWindow.toFront();
   util.utils.shortWait(500);
 }
コード例 #10
0
 public void _setViewData() {
   if (xAccess == null) {
     log.println("No view data to change available");
     tRes.tested("setViewData()", Status.skipped(true));
   } else {
     // 2do: provide an own implementation of the XIndexAccess to set.
     // this will work without "setViewData()", it just checks that a
     // setViewData can be done.
     oObj.setViewData(xAccess);
     XIndexAccess xAccess2 = oObj.getViewData();
     String newView = getViewID(xAccess2);
     tRes.tested("setViewData()", newView.equals(myview));
   }
 }
コード例 #11
0
  /**
   * Test calls the method and checks that no exceptions were thrown. Has <b> OK </b> status if no
   * exceptions were thrown.
   *
   * <p>
   */
  public void _setInteractionHandler() {
    XInteractionHandler handler = null;
    Object oHandler = tEnv.getObjRelation("InteractionHandler");

    if (oHandler == null)
      throw new StatusException(Status.failed("Reelation InteractionHandler not found"));

    try {
      handler = UnoRuntime.queryInterface(XInteractionHandler.class, oHandler);
      oObj.setInteractionHandler(handler);
      tRes.tested("setInteractionHandler()", true);
    } catch (Exception ex) {
      log.println("Exception occurred while testing 'setInteractionHandler()'");
      ex.printStackTrace(log);
      tRes.tested("setInteractionHandler()", false);
    }
  } // EOF setInteractionHandler()
コード例 #12
0
ファイル: _XControlAccess.java プロジェクト: personal-wu/core
  /**
   * Tries to query <code>com.sun.star.ui.dialogs.XControlInformation</code> interface, and obtain
   * properties' names of each available control.
   *
   * <p>
   *
   * @throw StatusException if interface is not supported or properties couldn't be get.
   */
  @Override
  protected void before() {
    XControlInformation xCI = UnoRuntime.queryInterface(XControlInformation.class, oObj);

    if (xCI == null) throw new StatusException(Status.failed("XControlInformation not supported"));

    supControls = xCI.getSupportedControls();
    supProperties = new String[supControls.length][];
    for (int i = 0; i < supControls.length; i++) {
      try {
        supProperties[i] = xCI.getSupportedControlProperties(supControls[i]);
      } catch (com.sun.star.lang.IllegalArgumentException e) {
        e.printStackTrace(log);
        throw new StatusException("Exception while init.", e);
      }
    }
  }
コード例 #13
0
ファイル: _XText.java プロジェクト: vancuvit/core
  /**
   * Removes the text contet added before.
   *
   * <p>Has <b> OK </b> status if the method successfully returns and no exceptions were thrown.
   *
   * <p>The following method tests are to be completed successfully before :
   *
   * <ul>
   *   <li><code> insertTextContent() </code> : inserts the content to be removed in this test.
   * </ul>
   */
  public void _removeTextContent() {

    // leads to a method which should be called previously
    requiredMethod("insertTextContent()");

    // write to log what we try next
    log.println("test for  removeTextContent");
    try {
      oObj.removeTextContent((XTextContent) oInt);
      // oObj.removeTextContent( (XTextContent)oInt );
    } catch (com.sun.star.container.NoSuchElementException nseE) {
      // Some exception.FAILED
      Status.failed(nseE.toString());
      return;
    }

    // no exception occurred so it works
    tRes.tested("removeTextContent()", true);
  }
コード例 #14
0
  /** * 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
コード例 #15
0
ファイル: ORowSet.java プロジェクト: vancuvit/core
  /**
   * 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
コード例 #16
0
 /** Just log output */
 @Override
 protected void after() {
   log.println(
       "Skipping all XApproveActionBroadcaster methods, since they" + " need user interaction");
   throw new StatusException(Status.skipped(true));
 }