* Test accessing the discriminator of a DynUnion object.
*/
public void testAccessUnionDisc ()
{
String msg;
TCKind discKind = null;
org.omg.CORBA.TypeCode tc = null;
org.omg.DynamicAny.DynUnion dynAny = null;
org.omg.DynamicAny.DynAny disc = null;
org.omg.DynamicAny.DynAny invalidDisc = null;
tc = UnionDefaultIntTypeHelper.type ();
dynAny = createDynAnyFromTypeCode (tc);
// test setting the discriminator
tc = orb.get_primitive_tc (TCKind.tk_short);
try
{
disc = factory.create_dyn_any_from_type_code (tc);
}
catch (Throwable ex)
{
fail ("Failed to create DynAny with correct TypeCode: " + ex);
}
try
{
disc.insert_short ((short) 1); // specific to IDL
}
catch (Throwable ex)
{
fail ("Failed to set value of discriminator: " + ex);
}
try
{
dynAny.set_discriminator (disc);
}
catch (Throwable ex)
{
msg = "Failed to set the value of the discriminator using the ";
msg += "DynUnion::set_discriminator operation";
fail (msg + ": " + ex);
}
// test getting the discriminator
msg = "Failed to get the correct value of the discriminator using the ";
msg += "DynUnion::get_discriminator operation";
disc = dynAny.get_discriminator ();
// specific to IDL
assertEquals (msg, (short) 1, disc.to_any ().extract_short ());
// test getting the kind of the discriminator
msg = "Failed to get the correct kind of the discriminator using ";
msg += "DynUnion::discriminator_kind operation";
discKind = dynAny.discriminator_kind ();
// specific to IDL
assertEquals (msg, TCKind._tk_short, discKind.value ());
// test setting an invalid discriminator
tc = orb.get_primitive_tc (TCKind.tk_boolean);
try
{