Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_2800_Regression / client.cpp
blobfe5851434683f9176937d07e77c4814dcc1c73a4
1 #include "TestC.h"
2 #include "orbsvcs/CosNamingC.h"
3 #include "ace/Get_Opt.h"
7 const ACE_TCHAR *ior = ACE_TEXT("file://shutdown.ior");
8 bool shutdown_nsmain = false;
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'k':
20 ior = get_opts.opt_arg ();
21 shutdown_nsmain = true;
22 break;
23 default:
24 ACE_ERROR_RETURN ((LM_ERROR,
25 "usage: %s "
26 "\n",
27 argv [0]),
28 -1);
30 // Indicates successful parsing of the command line
31 return 0;
34 int
35 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
37 try
39 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
41 if (parse_args (argc, argv) != 0)
42 return 1;
44 CORBA::Object_var tmp =
45 orb->string_to_object("corbaloc:iiop:1.2@localhost:9931/NameService");
47 CosNaming::NamingContext_var root =
48 CosNaming::NamingContext::_narrow(tmp.in());
50 if (CORBA::is_nil (root.in ()))
52 ACE_ERROR_RETURN ((LM_DEBUG,
53 "Nil NamingService reference\n"),
54 1);
57 ACE_DEBUG ((LM_INFO, "**** Narrowed root NamingContext\n"));
59 CosNaming::Name name;
60 name.length(2);
61 name[0].id = CORBA::string_dup("example");
62 name[1].id = CORBA::string_dup("Hello");
64 try
66 tmp = root->resolve (name);
67 ACE_DEBUG ((LM_INFO, "**** Resolved #example/Hello\n"));
69 Test::Hello_var hello =
70 Test::Hello::_narrow(tmp.in ());
72 if (CORBA::is_nil (hello.in ()))
74 ACE_ERROR_RETURN ((LM_DEBUG,
75 "Nil Test::Hello reference\n"),
76 1);
79 CORBA::String_var the_string = hello->get_string ();
81 ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n",
82 the_string.in ()));
84 hello->shutdown ();
86 catch (const CosNaming::NamingContext::CannotProceed&)
88 ACE_DEBUG ((LM_DEBUG, "Caught correct exception\n"));
91 if (shutdown_nsmain)
93 CORBA::Object_var shutdowntmp = orb->string_to_object(ior);
95 Test::NsShutdown_var shutdown =
96 Test::NsShutdown::_narrow(shutdowntmp.in ());
98 ACE_DEBUG ((LM_DEBUG, "Shutdown nsmain\n"));
99 shutdown->shutdown ();
102 orb->shutdown ();
103 orb->destroy ();
105 catch (const CORBA::Exception& ex)
107 ex._tao_print_exception ("Exception caught:");
108 return 1;
111 return 0;