예제 #1
0
  /** Tests the stripchars expression. */
  public void testStripchars() {

    assertEquals(
        "test",
        zx.getExpressionHandler().eval("stripchars('t1e2s3t4', '[1234]')").getStringValue());
    // Same as stripnonxchars('t-e!s.t@', '[a-zA-Z0-9]')
    assertEquals(
        "test",
        zx.getExpressionHandler().eval("stripchars('t-e!s.t@', '[^a-zA-Z0-9]')").getStringValue());
  }
예제 #2
0
  /** Tests expressions with no arguments. */
  public void testNoArgs() {

    assertEquals("", zx.getExpressionHandler().eval("null()").getStringValue());
    assertEquals(true, zx.getExpressionHandler().eval("null()").isNull);

    assertEquals("\r", zx.getExpressionHandler().eval("cr()").getStringValue());

    // assertEquals(new Date().toString(),
    // ((Property)zx.getExpressionHandler().eval("now()")).dateValue().toString());

    zx.trace.addError("test");
    assertEquals("test", zx.getExpressionHandler().eval("systemmsg()").getStringValue());
  }
  /**
   * Tests boTableInit and boTableRowPopulate
   *
   * @throws Exception
   */
  public void testBoTableInit() throws Exception {
    AbstractDocument doc = new OpenOfficeDocument();
    try {
      String strGroup = "*";
      ZXBO objBO = zx.createBO("test/test");
      objBO.setPKValue("12");
      objBO.loadBO();

      assertEquals("Activate Openoffice", zXType.rc.rcOK.pos, doc.activate().pos);
      assertEquals("Open test document", zXType.rc.rcOK.pos, doc.openDoc("c:/tmp/test.doc").pos);

      /** Get the placeholder table. */
      Object objTable = doc.getTable(1, 1, zXType.wordSection.wsPage);
      assertEquals(
          "Setup the table", zXType.rc.rcOK.pos, doc.boTableInit(objTable, objBO, strGroup).pos);

      objTable = doc.getTable(1, 1, zXType.wordSection.wsPage);
      XTextTable xTable = (XTextTable) UnoRuntime.queryInterface(XTextTable.class, objTable);
      XCellRange objRow = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, xTable);
      objRow = objRow.getCellRangeByName("A2:C2");

      assertEquals(
          "Populate table row.",
          zXType.rc.rcOK.pos,
          doc.boTableRowPopulate(objRow, objBO, strGroup).pos);

    } finally {
      assertEquals("Close document", zXType.rc.rcOK.pos, doc.closeDoc(false).pos);
    }
  }
예제 #4
0
  /** Test expressions with variable arguements */
  public void testVarArgs() {

    // choose(3, 'a', 'b', 'c', 'd') - > c
    assertEquals(
        "c", zx.getExpressionHandler().eval("choose(3, 'a', 'b', 'c', 'd')").getStringValue());

    // translate(1, 0, 'a', 1, 'b', 2, 'c', 3, 'd') - > b
    assertEquals(
        "b",
        zx.getExpressionHandler()
            .eval("translate(1, 0, 'a', 1, 'b', 2, 'c', 3, 'd')")
            .getStringValue());
    assertEquals(
        "charlie",
        zx.getExpressionHandler()
            .eval("translate('c', 'a', 'alpha', 'b', 'bravo', 'c', 'charlie', 'd', 'delta')")
            .getStringValue());

    assertEquals(
        "abcd", zx.getExpressionHandler().eval("concat('a','b','c','d')").getStringValue());
    assertEquals(
        "12)4", zx.getExpressionHandler().eval("concat('1', '2', ')', '4')").getStringValue());
  }
 /** @see TestCase#tearDown() */
 protected void tearDown() throws Exception {
   zx.cleanup();
   super.tearDown();
 }
예제 #6
0
  /** Test expressions with a single argument. */
  public void testOneArgs() {
    // char(3) - > 3
    assertEquals("3", zx.getExpressionHandler().eval("chr(3)").getStringValue());

    assertEquals(true, zx.getExpressionHandler().eval("setqs('test','hello')").booleanValue());
    assertEquals("hello", zx.getExpressionHandler().eval("qs('test')").getStringValue());
    assertEquals(true, zx.getExpressionHandler().eval("setqs('test','')").booleanValue());
    assertEquals(true, zx.getExpressionHandler().eval("qs('test')").isNull);

    assertEquals(10, zx.getExpressionHandler().eval("add(5,5)").longValue());
    assertEquals(5.5, zx.getExpressionHandler().eval("add(5,0.5)").doubleValue(), 0.0);

    assertEquals(25, zx.getExpressionHandler().eval("mul(5,5)").longValue());
    assertEquals(2.5, zx.getExpressionHandler().eval("mul(5,0.5)").doubleValue(), 0.0);

    assertEquals(0, zx.getExpressionHandler().eval("sub(5,5)").longValue());
    assertEquals(4.5, zx.getExpressionHandler().eval("sub(5,0.5)").doubleValue(), 0.0);

    assertEquals(1, zx.getExpressionHandler().eval("div(5,5)").longValue());
    assertEquals(10, zx.getExpressionHandler().eval("div(5,0.5)").doubleValue(), 0.0);

    assertEquals("Hello", zx.getExpressionHandler().eval("getline('Hello',0)").getStringValue());
    assertEquals("Hello", zx.getExpressionHandler().eval("getline('Hello',1)").getStringValue());

    assertEquals("Hello", zx.getExpressionHandler().eval("getline('Hello','-1')").getStringValue());
    assertEquals("Hello", zx.getExpressionHandler().eval("getline('Hello',-1)").getStringValue());
    assertEquals(
        "World", zx.getExpressionHandler().eval("getline('Hello\nWorld','-1')").getStringValue());

    // getword
    assertEquals("", zx.getExpressionHandler().eval("getword('', 0, ' ')").getStringValue());
    assertEquals("", zx.getExpressionHandler().eval("getword('', 2, ' ')").getStringValue());
    assertEquals("", zx.getExpressionHandler().eval("getword('', -1)").getStringValue());
    assertEquals("t", zx.getExpressionHandler().eval("getword('t', -1, ' ')").getStringValue());
    assertEquals("t", zx.getExpressionHandler().eval("getword('t', 1)").getStringValue());
    assertEquals("", zx.getExpressionHandler().eval("getword('testing', 2, ' ')").getStringValue());
    assertEquals(
        "", zx.getExpressionHandler().eval("getword('testing', -2, ' ')").getStringValue());
    assertEquals(
        "testing", zx.getExpressionHandler().eval("getword('testing', 1, ' ')").getStringValue());
    assertEquals(
        "yes", zx.getExpressionHandler().eval("getword('yes test', 1, ' ')").getStringValue());
    assertEquals(
        "test", zx.getExpressionHandler().eval("getword('yes test', 2, ' ')").getStringValue());
    assertEquals(
        "four",
        zx.getExpressionHandler()
            .eval("getword('yes test one four you', 4, ' ')")
            .getStringValue());
  }