Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_3676_Regression / client.cpp
blob61ced8300875d8975fef9386247c00ca3634ba89
1 #include "TestC.h"
2 #include "tao/Profile_Transport_Resolver.h"
3 #include "tao/Transport.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR *ior = ACE_TEXT ("file://test.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 ior = get_opts.opt_arg ();
20 break;
22 case '?':
23 default:
24 ACE_ERROR_RETURN ((LM_ERROR,
25 "usage: %s "
26 "-k <ior> "
27 "\n",
28 argv [0]),
29 -1);
31 // Indicates successful parsing of the command line
32 return 0;
35 // This function does what TAO does in order to get a transport.
36 CORBA::Boolean
37 first_request_flag (CORBA::Object_ptr obj)
39 TAO_Stub *const stub = obj->_stubobj ();
40 if (0 == stub)
42 ACE_ERROR_RETURN ((LM_DEBUG,
43 "CORBA::Object has stub = 0\n"),
44 1);
47 TAO::Profile_Transport_Resolver resolver (obj, stub, true);
49 resolver.resolve (0);
51 TAO_Transport *transport = resolver.transport ();
52 if (0 == transport)
54 ACE_ERROR_RETURN ((LM_DEBUG,
55 "Transport is 0\n"),
56 1);
59 return transport->first_request ();
62 int
63 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
65 try
67 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
69 if (parse_args (argc, argv) != 0)
70 return 1;
72 CORBA::Object_var tmp = orb->string_to_object (ior);
74 // No remote calls, first request flag is on.
75 if (!first_request_flag (tmp.in ()))
77 ACE_ERROR ((LM_ERROR,
78 "Test FAILED at the beginning (why?)\n"));
81 // This call must issue LocateRequest message.
82 CORBA::PolicyList_var pl;
83 tmp->_validate_connection (pl.out ());
85 // There was a LocateRequest call, first request flag
86 // must be still on.
87 if (!first_request_flag (tmp.in ()))
89 ACE_ERROR ((LM_ERROR,
90 "Test FAILED after LocateRequest (bug#3676 is not fixed)!!\n"));
93 Test::Hello_var hello = Test::Hello::_narrow (tmp.in ());
95 if (CORBA::is_nil (hello.in ()))
97 ACE_ERROR_RETURN ((LM_DEBUG,
98 "Nil Test::Hello reference <%s>\n",
99 ior),
103 CORBA::String_var the_string = hello->get_string ();
105 // Either _narrow or get_string issued a remote call,
106 // first request flag is off.
107 if (first_request_flag (tmp.in ()))
109 ACE_ERROR ((LM_ERROR,
110 "Test FAILED after normal request (why?)\n"));
113 hello->shutdown ();
115 orb->destroy ();
117 catch (const CORBA::Exception& ex)
119 ex._tao_print_exception ("Exception caught:");
120 return 1;
123 return 0;