Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_3673_Regression / client.cpp
blob10d56888f1a989d4ac762dc85fad20f343e7554b
1 #include "TestC.h"
2 #include "orbsvcs/CosNamingC.h"
3 #include "ace/Get_Opt.h"
6 const ACE_TCHAR *ior = ACE_TEXT("file://shutdown.ior");
7 bool shutdown_nsmain = false;
8 int test_count = 10;
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(4);
61 name[0].id = CORBA::string_dup("This");
62 name[0].kind = CORBA::string_dup("");
63 name[1].id = CORBA::string_dup("eat");
64 name[1].kind = CORBA::string_dup("");
65 name[2].id = CORBA::string_dup("my");
66 name[2].kind = CORBA::string_dup("");
67 name[3].id = CORBA::string_dup("memory");
68 name[3].kind = CORBA::string_dup("");
70 for (int i = 0; i < test_count; i++)
72 try
74 tmp = root->resolve (name);
75 ACE_DEBUG ((LM_INFO, "**** Resolved #example/Hello\n"));
77 Test::Hello_var hello =
78 Test::Hello::_narrow(tmp.in ());
80 ACE_ERROR_RETURN ((LM_DEBUG,
81 "Nil Test::Hello reference\n"),
82 1);
84 catch (const CosNaming::NamingContext::NotFound&)
86 ACE_DEBUG ((LM_DEBUG, "Caught correct exception for iteration %d\n", i));
90 if (shutdown_nsmain)
92 CORBA::Object_var shutdowntmp = orb->string_to_object(ior);
94 Test::NsShutdown_var shutdown =
95 Test::NsShutdown::_narrow(shutdowntmp.in ());
97 ACE_DEBUG ((LM_DEBUG, "Shutdown nsmain\n"));
98 shutdown->shutdown ();
101 orb->shutdown ();
102 orb->destroy ();
104 catch (const CORBA::Exception& ex)
106 ex._tao_print_exception ("Exception caught:");
107 return 1;
110 return 0;