Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / POA / EndpointPolicy / client.cpp
blob99120e971d0e7d678a9772bb544fa2b2898b3307
1 #include "TestC.h"
2 #include "ace/Get_Opt.h"
4 const ACE_TCHAR *ior = ACE_TEXT ("file://test.ior");
5 int bad_ior = 0;
7 int
8 parse_args (int argc, ACE_TCHAR *argv[])
10 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:b"));
11 int c;
13 while ((c = get_opts ()) != -1)
14 switch (c)
16 case 'k':
17 ior = get_opts.opt_arg ();
18 break;
20 case 'b':
21 bad_ior = 1;
22 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 CORBA::ORB_var orb;
41 CORBA::Object_var tmp;
43 try
45 orb = CORBA::ORB_init (argc, argv);
47 if (parse_args (argc, argv) != 0)
48 return 1;
50 tmp = orb->string_to_object (ior);
52 catch (const CORBA::Exception& ex)
54 ex._tao_print_exception ("Exception caught:");
55 return 1;
58 try
60 ACE_DEBUG ((LM_DEBUG, "client: Invocation expecting to %s\n",
61 (bad_ior ? ACE_TEXT ("fail") : ACE_TEXT ("work"))));
62 Test::Hello_var hello =
63 Test::Hello::_narrow(tmp.in ());
65 if (CORBA::is_nil (hello.in ()))
67 ACE_ERROR_RETURN ((LM_DEBUG,
68 "Nil Test::Hello reference <%s>\n",
69 ior),
70 1);
73 CORBA::String_var the_string =
74 hello->get_string ();
76 if (bad_ior)
78 ACE_DEBUG ((LM_DEBUG,"client: Error: was expecting an exception.\n"));
79 return 1;
82 ACE_DEBUG ((LM_DEBUG, "client: success!\n"));
84 hello->shutdown ();
86 catch (const CORBA::Exception& ex)
88 if (!bad_ior)
90 ex._tao_print_exception ("client: Exception caught:");
91 return 1;
93 ACE_DEBUG ((LM_DEBUG, "client: success!\n"));
96 orb->destroy ();
98 return 0;