Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / InterfaceRepo / Bug_3174_Regression / test_idl.cpp
blobc145440b16f45d8433c92ba8b1254ace4e79ae13
1 #include "ace/Get_Opt.h"
2 #include "ace/OS_NS_string.h"
3 #include "tao/DynamicAny/DynamicAny.h"
4 #include "tao/ORB.h"
5 #include "tao/IFR_Client/IFR_ComponentsC.h"
7 namespace
9 const ACE_TCHAR *ifr_ior_file = 0;
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("i:s:"));
16 const unsigned char full_success = 0x01;
17 unsigned char success = 0;
19 while (true)
21 int c = get_opts ();
22 if (success == full_success)
24 break;
27 if (c == -1)
29 ACE_ERROR_RETURN ((LM_ERROR,
30 "usage: %s"
31 " -i <ifr_ior>"
32 "\n",
33 argv [0]),
34 -1);
37 switch (c)
39 case 'i':
40 ifr_ior_file = get_opts.opt_arg ();
41 success |= 0x01;
42 break;
46 // Indicates successful parsing of the command line
47 return 0;
50 // ----------------------------------------------------------------------
52 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
54 int result= 0;
55 ACE_DEBUG (( LM_DEBUG, "Start\n" ));
57 try
59 // init orb
60 CORBA::ORB_var the_orb =
61 CORBA::ORB_init (argc, argv);
63 if (parse_args (argc, argv) == -1)
64 return -1;
66 ACE_DEBUG (( LM_DEBUG, "Get IFR\n" ));
67 CORBA::Object_var objref =
68 the_orb->string_to_object (ifr_ior_file);
69 if (objref.in () == 0)
71 ACE_ERROR_RETURN ((LM_ERROR,
72 "The received objref is nil\n"),
73 -1);
76 ACE_DEBUG (( LM_DEBUG, "Narrow IFR\n" ));
77 CORBA::ComponentIR::Repository_var the_repo_ref;
78 the_repo_ref = CORBA::ComponentIR::Repository::_narrow (objref.in ());
80 ACE_DEBUG (( LM_DEBUG, "Obtaining DynamicAny\n" ));
81 CORBA::Object_var factory_obj =
82 the_orb->resolve_initial_references ("DynAnyFactory");
83 DynamicAny::DynAnyFactory_var dynanyfactory =
84 DynamicAny::DynAnyFactory::_narrow (factory_obj.in ());
86 ACE_DEBUG (( LM_DEBUG, "\nLook up c2\n" ));
87 CORBA::Contained_var c2 =
88 the_repo_ref->lookup_id ("IDL:m1/c2:1.0");
89 if (CORBA::is_nil (c2.in ()))
91 ACE_ERROR_RETURN ((LM_ERROR,
92 "Can't look up the const m1/c2\n"),
93 -1);
95 CORBA::ConstantDef_var c2_def = CORBA::ConstantDef::_narrow (c2.in ());
96 CORBA::String_var c2_name= c2_def->absolute_name ();
97 CORBA::TypeCode_var c2_tc = c2_def->type ();
98 CORBA::String_var c2_id = c2_tc->id ();
99 ACE_DEBUG (( LM_DEBUG, "constant \"%C\" is type \"%C\"", c2_name.in (), c2_id.in () ));
100 CORBA::TCKind c2_tckind = c2_tc->kind ();
101 ACE_DEBUG (( LM_DEBUG, ", tkkind %d", c2_tckind ));
102 if (CORBA::tk_enum == c2_tckind)
104 ACE_DEBUG (( LM_DEBUG, " (CORBA::tk_enum)\n" ));
105 CORBA::Any_var the_value = c2_def->value ();
107 DynamicAny::DynAny_var dany =
108 dynanyfactory->create_dyn_any (the_value.in ());
109 DynamicAny::DynEnum_var denum =
110 DynamicAny::DynEnum::_narrow (dany.in ());
111 CORBA::String_var the_strValue = denum->get_as_string ();
112 CORBA::ULong the_intValue = denum->get_as_ulong ();
114 ACE_DEBUG ((LM_DEBUG, "Whose value is \"%C\" which has an integer value of %d\n",
115 the_strValue.in (), the_intValue ));
117 if (0 == ACE_OS::strcmp( "e1_2", the_strValue.in () ))
119 ACE_DEBUG ((LM_DEBUG, "The string value is correct\n" ));
121 else
123 ACE_DEBUG ((LM_DEBUG, "ERROR: The string value should be \"e1_2\"\n" ));
124 result = -1;
126 if (1 == the_intValue )
128 ACE_DEBUG ((LM_DEBUG, "The corresponding integer value is correct\n" ));
130 else
132 ACE_DEBUG ((LM_DEBUG, "ERROR: The corresponding integer value should be 1\n" ));
133 result = -1;
136 else
138 ACE_DEBUG ((LM_DEBUG, "\nERROR: Wrong tkkind for m1::c2, should be %d\n", CORBA::tk_enum));
139 result= -1;
142 catch (const CORBA::Exception &ex)
144 ex._tao_print_exception ("ERROR: CORBA Exception");
145 result= -1;
147 catch (...)
149 ACE_DEBUG ((LM_DEBUG, "ERROR: UNKNOWN Excetion\n"));
150 result= -1;
153 ACE_DEBUG (( LM_DEBUG, "\nDone\n" ));
154 return result;