Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Bug_2289_Regression / client.cpp
blobbd921ac2c4b29f2ad85e1759780ba78ef6038790
1 #include "TestS.h"
2 #include "MyInterfaceImpl.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_stdio.h"
6 const ACE_TCHAR *server_ior = ACE_TEXT("");
7 const ACE_TCHAR *ior_output_file = ACE_TEXT("client.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 server_ior = get_opts.opt_arg ();
20 break;
21 case 'o':
22 ior_output_file = get_opts.opt_arg ();
23 break;
24 case '?':
25 default:
26 ACE_ERROR_RETURN ((LM_ERROR,
27 "usage: %s "
28 "-k <ior> "
29 "\n",
30 argv [0]),
31 -1);
33 // Indicates successful parsing of the command line
34 return 0;
37 int
38 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
40 int result = 0;
41 try
43 CORBA::ORB_var orb =
44 CORBA::ORB_init (argc, argv);
46 if (parse_args (argc, argv) != 0)
47 return 1;
49 CORBA::Object_var poa_object =
50 orb->resolve_initial_references("RootPOA");
52 PortableServer::POA_var root_poa =
53 PortableServer::POA::_narrow (poa_object.in ());
55 if (CORBA::is_nil (root_poa.in ()))
56 ACE_ERROR_RETURN ((LM_ERROR,
57 " (%P|%t) Panic: nil RootPOA\n"),
58 1);
60 PortableServer::POAManager_var poa_manager =
61 root_poa->the_POAManager ();
63 if (parse_args (argc, argv) != 0)
64 return 1;
66 MyInterfaceImpl *test_impl;
67 ACE_NEW_RETURN (test_impl,
68 MyInterfaceImpl (orb.in ()),
69 1);
71 PortableServer::ServantBase_var owner_transfer(test_impl);
73 PortableServer::ObjectId_var id =
74 root_poa->activate_object (test_impl);
76 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
78 MyInterface_var test_ref =
79 MyInterface::_narrow (object.in ());
81 CORBA::String_var ior =
82 orb->object_to_string (test_ref.in ());
84 // Output the IOR to the <ior_output_file>
85 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
86 if (output_file != 0)
88 ACE_OS::fprintf (output_file, "%s", ior.in ());
89 ACE_OS::fclose (output_file);
92 poa_manager->activate ();
94 CORBA::Object_var tmp =
95 orb->string_to_object(server_ior);
97 MyInterface_var server =
98 MyInterface::_narrow(tmp.in ());
100 if (CORBA::is_nil (server.in ()))
102 ACE_ERROR_RETURN ((LM_DEBUG,
103 "Nil server reference <%s>\n",
104 ior.in()),
109 CORBA::Boolean temp = server->myMethod (MyInterfaceImpl::my_string);
111 if (temp)
113 ACE_DEBUG ((LM_DEBUG, "Test succeeded\n"));
115 else
117 ACE_DEBUG ((LM_ERROR, "Test failed\n"));
118 result = 1;
121 //hello->shutdown ();
123 orb->destroy ();
125 catch (const CORBA::Exception& ex)
127 ex._tao_print_exception ("Exception caught:");
128 return 1;
131 return result;