コード例 #1
0
  @Test
  public void checkBasics() {
    createEmptyBag();
    System.out.println("testing the basics");

    // check whether empty property names are rejected
    boolean caughtExpected = false;
    try {
      m_bag.addProperty("", PropertyAttribute.BOUND, Integer.valueOf(3));
    } catch (com.sun.star.lang.IllegalArgumentException e) {
      caughtExpected = true;
    } catch (com.sun.star.uno.Exception e) {
    }
    if (!caughtExpected) {
      fail("empty property names are not rejected by XPropertyContainer::addProperty");
    }

    // check whether duplicate insertions are rejected
    caughtExpected = false;
    try {
      m_bag.addProperty(VALUE, PropertyAttribute.BOUND, "");
      m_bag.addProperty(VALUE, PropertyAttribute.BOUND, "");
    } catch (com.sun.star.beans.PropertyExistException e) {
      caughtExpected = true;
    } catch (com.sun.star.uno.Exception e) {
    }
    if (!caughtExpected) {
      fail("insertion of duplicate property names is not rejected");
    }

    // try removing the property we just added - this should fail, as it does not have
    // the REMOVABLE attribute
    caughtExpected = false;
    try {
      m_bag.removeProperty(VALUE);
    } catch (com.sun.star.beans.NotRemoveableException e) {
      caughtExpected = true;
    } catch (com.sun.star.uno.Exception e) {
    }
    if (!caughtExpected) {
      fail("removing non-removable properties is expected to fail - but it didn't");
    }

    // try removing a non-existent property
    caughtExpected = false;
    try {
      m_bag.removeProperty("NonExistent");
    } catch (com.sun.star.beans.UnknownPropertyException e) {
      caughtExpected = true;
    } catch (com.sun.star.uno.Exception e) {
    }
    if (!caughtExpected) {
      fail("removing non-existent properties is expected to fail - but it didn't");
    }

    // try writing and reading a value for the one property we have so far
    try {
      final String testValue = "someArbitraryValue";
      m_set.setPropertyValue(VALUE, testValue);
      final String currentValue = (String) m_set.getPropertyValue(VALUE);
      if (!currentValue.equals(testValue)) {
        fail("set property is not remembered");
      }
    } catch (com.sun.star.uno.Exception e) {
      fail("setting or getting a property value failed");
    }

    // try setting an illegal value for the property
    caughtExpected = false;
    try {
      m_set.setPropertyValue(VALUE, Integer.valueOf(3));
    } catch (com.sun.star.lang.IllegalArgumentException e) {
      caughtExpected = true;
    } catch (com.sun.star.uno.Exception e) {
    }
    if (!caughtExpected) {
      fail("the bag does not respect the property type we declared for the property");
    }
  }