Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_3673_Regression / client.cpp
blobcc4ea47298a643715e1e2e09bb4f174d9f47be4c
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;
9 int test_count = 10;
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'k':
21 ior = get_opts.opt_arg ();
22 shutdown_nsmain = true;
23 break;
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR,
26 "usage: %s "
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 = CORBA::ORB_init (argc, argv);
42 if (parse_args (argc, argv) != 0)
43 return 1;
45 CORBA::Object_var tmp =
46 orb->string_to_object("corbaloc:iiop:1.2@localhost:9931/NameService");
48 CosNaming::NamingContext_var root =
49 CosNaming::NamingContext::_narrow(tmp.in());
51 if (CORBA::is_nil (root.in ()))
53 ACE_ERROR_RETURN ((LM_DEBUG,
54 "Nil NamingService reference\n"),
55 1);
58 ACE_DEBUG ((LM_INFO, "**** Narrowed root NamingContext\n"));
60 CosNaming::Name name;
61 name.length(4);
62 name[0].id = CORBA::string_dup("This");
63 name[0].kind = CORBA::string_dup("");
64 name[1].id = CORBA::string_dup("eat");
65 name[1].kind = CORBA::string_dup("");
66 name[2].id = CORBA::string_dup("my");
67 name[2].kind = CORBA::string_dup("");
68 name[3].id = CORBA::string_dup("memory");
69 name[3].kind = CORBA::string_dup("");
71 for (int i = 0; i < test_count; i++)
73 try
75 tmp = root->resolve (name);
76 ACE_DEBUG ((LM_INFO, "**** Resolved #example/Hello\n"));
78 Test::Hello_var hello =
79 Test::Hello::_narrow(tmp.in ());
81 ACE_ERROR_RETURN ((LM_DEBUG,
82 "Nil Test::Hello reference\n"),
83 1);
85 catch (const CosNaming::NamingContext::NotFound&)
87 ACE_DEBUG ((LM_DEBUG, "Caught correct exception for iteration %d\n", i));
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;