Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / InterfaceRepo / Bug_2962_Regression / client.cpp
bloba5dc3af54cefd1b29dc7afeff3c854385f89f4e3
1 // -*- C++ -*-
2 // The run_test.pl perl script will check for the expected output.
4 #include "ace/config.h"
5 #include "tao/IFR_Client/IFR_ComponentsC.h"
6 #include "ace/Get_Opt.h"
8 const ACE_TCHAR *ifr_ior= ACE_TEXT("file://ifr.ior");
9 const ACE_TCHAR *member_type_id= ACE_TEXT("IDL:arrayOfStruct:1.0");
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("i:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'i':
21 ifr_ior = get_opts.opt_arg ();
22 break;
23 case '?':
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR,
26 "usage: %s "
27 "-i <ior> "
28 "\n",
29 argv [0]),
30 -1);
32 // Indicates successful parsing of the command line
33 return 0;
36 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
38 try
40 CORBA::ORB_var the_orb = CORBA::ORB_init (argc, argv);
42 if (parse_args (argc, argv) != 0)
43 return 1;
45 CORBA::Object_var obj = the_orb->string_to_object (ACE_TEXT_ALWAYS_CHAR(ifr_ior));
46 if (CORBA::is_nil (obj.in()))
48 ACE_DEBUG ((LM_DEBUG, "Obtained nil reference to Object for interface repository\n" ));
49 return 1;
52 CORBA::ComponentIR::Repository_var ifr;
54 try
56 ifr = CORBA::ComponentIR::Repository::_narrow (obj.in());
58 catch (const CORBA::SystemException &)
60 ACE_DEBUG ((LM_DEBUG, "exception catched .. narrowing IFR object\n" ));
61 return 1;
64 if (CORBA::is_nil (ifr.in()))
66 ACE_DEBUG ((LM_DEBUG, "Can't narrow to IFR\n" ));
67 return 1;
70 ACE_DEBUG ((LM_DEBUG, "Looking up %C", member_type_id ));
71 CORBA::Contained_var
72 dependency = ifr->lookup_id (ACE_TEXT_ALWAYS_CHAR(member_type_id));
73 if (CORBA::is_nil (dependency.in ()))
75 ACE_DEBUG ((LM_DEBUG, " *** failed ***\n" ));
76 return 1;
79 CORBA::AliasDef_var
80 the_alias = CORBA::AliasDef::_narrow (dependency.in ());
81 if (CORBA::is_nil (the_alias.in ()))
83 ACE_DEBUG ((LM_DEBUG, " *** not an alias ***\n" ));
84 return 1;
87 CORBA::IDLType_var
88 orig_type = the_alias->original_type_def ();
89 CORBA::TypeCode_var
90 tc_content = orig_type->type ();
91 const CORBA::ULong
92 length= tc_content->length ();
93 CORBA::TypeCode_var
94 cont_type = tc_content->content_type ();
95 const char
96 *name= cont_type->name ();
97 ACE_DEBUG ((LM_DEBUG,
98 " = %C [%u]\n",
99 name,
100 length ));
102 if (2u == length)
104 ACE_DEBUG ((LM_DEBUG, "Correct result, test passed\n" ));
106 else
108 ACE_DEBUG ((LM_DEBUG, "Error: Should have been %C [2]\n", name));
109 return 2;
112 catch (const ::CORBA::Exception &ex)
114 ex._tao_print_exception("ERROR : unexpected CORBA exception caugth :");
115 return 1;
117 return 0;