Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / ICMG_Any_Bug / client.cpp
blob27117435628c93a5e2e99423282e9abf4e961c62
1 #include "tao/DynamicInterface/Request.h"
2 #include "TestC.h"
3 #include "tao/ORB.h"
4 #include "ace/Get_Opt.h"
5 #include <string>
7 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
9 int
10 parse_args (int argc, ACE_TCHAR *argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
13 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'k':
19 ior = get_opts.opt_arg ();
20 break;
22 case '?':
23 default:
24 ACE_ERROR_RETURN ((LM_ERROR,
25 "usage: %s "
26 "-k <ior> "
27 "\n",
28 argv [0]),
29 -1);
31 // Indicates successful parsing of the command line
32 return 0;
35 int
36 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
38 try
40 CORBA::ORB_var orb =
41 CORBA::ORB_init (argc, argv);
43 if (parse_args (argc, argv) != 0)
44 return 1;
46 CORBA::Object_var tmp =
47 orb->string_to_object(ior);
49 Test::Hello_var hello =
50 Test::Hello::_narrow (tmp.in ());
52 if (CORBA::is_nil (hello.in ()))
54 ACE_ERROR_RETURN ((LM_DEBUG,
55 "Nil Test::Hello reference\n"),
56 1);
59 CORBA::Request_var request;
60 request = tmp->_request ("get_helloworld");
61 request->set_return_type (Test::_tc_HelloWorld);
63 CORBA::Any any;
64 any <<= "Hi From DOC Group";
65 request->arguments ()->add_value ("msg", any, CORBA::ARG_IN);
67 request->invoke ();
69 CORBA::NamedValue_ptr results = request->result ();
70 CORBA::Any * obj_any = results->value ();
72 CORBA::Object_var obj2;
73 *obj_any >>= CORBA::Any::to_object (obj2);
74 if (CORBA::is_nil (obj2.in ()))
76 ACE_ERROR_RETURN ((LM_DEBUG,
77 "Nil Any_To_Object reference\n"),
78 1);
81 Test::HelloWorld_var hello_world =
82 Test::HelloWorld::_narrow (obj2.in ());
84 if (CORBA::is_nil (hello_world.in ()))
86 ACE_ERROR_RETURN ((LM_DEBUG,
87 "Nil Test::HelloWorld reference\n"),
88 1);
91 CORBA::String_var the_string =
92 hello_world->get_string ();
94 ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n",
95 the_string.in ()));
97 hello->shutdown ();
99 orb->destroy ();
101 catch (const CORBA::Exception& ex)
103 ex._tao_print_exception ("Exception caught:");
104 return 1;
107 return 0;