Exemplo n.º 1
0
  /**
   * Test the exceptions raised while accessing the member Name/Value DynAny pairs in a DynStruct
   * object.
   */
  public void testAccessStructPairsEx() {
    String msg;
    org.omg.CORBA.Any any = null;
    org.omg.CORBA.TypeCode tc = null;
    org.omg.DynamicAny.DynStruct dynAny = null;
    org.omg.DynamicAny.NameValuePair[] pairs = null;

    tc = orb.create_exception_tc(ID, NAME, MEMBERS);
    dynAny = createDynAnyFromTypeCode(tc);

    // test inserting a sequence with the wrong number of members
    pairs = new NameValuePair[1];
    any = orb.create_any();
    any.insert_char('a');
    pairs[0] = new NameValuePair("name", any);

    msg = "Failed to raise an InvalidValue exception when passing in a ";
    msg += "name/value sequence containing too many members";
    try {
      dynAny.set_members(pairs);

      fail(msg);
    } catch (org.omg.DynamicAny.DynAnyPackage.InvalidValue ex) {
      // success
    } catch (org.omg.DynamicAny.DynAnyPackage.TypeMismatch ex) {
      fail(msg + ": " + ex);
    }
  }
Exemplo n.º 2
0
  /** Test accessing the member Name/Value pairs in a DynStruct object. */
  public void testAccessStructNameValuePairs() {
    String msg;
    org.omg.CORBA.Any any = null;
    EmptyException type = null;
    org.omg.DynamicAny.DynStruct dynAny = null;
    org.omg.DynamicAny.NameValuePair[] pairs = null;

    type = new EmptyException();
    any = orb.create_any();
    EmptyExceptionHelper.insert(any, type);
    dynAny = createDynAnyFromAny(any);

    // test extracting the name/value pairs as Anys
    pairs = dynAny.get_members();
    msg = "Returned number of members from DynStruct::get_members operation ";
    msg += "is non-zero";
    assertEquals(msg, 0, pairs.length);

    pairs = new NameValuePair[0];
    try {
      dynAny.set_members(pairs);
    } catch (Throwable ex) {
      msg = "Failed to set DynStruct members using DynStruct::set_members ";
      msg += "operation";
      fail(msg + ": " + ex);
    }
  }