Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_1383_Regression / SimpleClient.cpp
blob98ae89f398b2ef311d19726fe48b2881d4828ab4
1 #include "tao/corba.h"
2 #include "ace/OS_NS_unistd.h"
3 #include "ace/Thread.h"
4 #include "simpleC.h"
5 #include "Callee_i.h"
6 #include "tao/IORManipulation/IORManip_Loader.h"
8 CORBA::ORB_var _orb;
10 ACE_THR_FUNC_RETURN RunFunc(void *)
12 ACE_DEBUG ((LM_DEBUG, "running the _orb\n"));
13 _orb->run();
14 ACE_DEBUG ((LM_DEBUG, "done running _orb\n"));
15 return 0;
18 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
20 try
22 // initialize the ORB
23 _orb = CORBA::ORB_init (argc, argv);
25 // Get the "RootPOA"
26 CORBA::Object_var obj = _orb->resolve_initial_references("RootPOA");
27 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in ());
29 // activate its managers so it can handle incoming requests
30 poa->the_POAManager()->activate();
32 // get a thread going to handle incoming requests
33 ACE_Thread::spawn(RunFunc);
35 // we could also use the c_orbaloc syntax to get a reference to the
36 // object. This will cause the _orb to talk directly to the other
37 // _orb with no name service or common file involved.
38 obj = _orb->string_to_object("c_orbaloc::localhost:9999/Simple");
40 if (CORBA::is_nil(obj.in ()))
42 ACE_ERROR ((LM_ERROR, "could not get reference\n"));
43 return 1;
46 // narrow the reference to the particular type we wish to deal with
47 Simple_var simple = Simple::_narrow(obj.in ());
48 if (CORBA::is_nil(simple.in ()))
50 ACE_ERROR ((LM_ERROR, "could not get reference\n"));
51 return 1;
54 // create an object reference that has a bogus value for the first
55 // profile
56 obj = _orb->resolve_initial_references("IORManipulation");
57 TAO_IOP::TAO_IOR_Manipulation_var iorm =
58 TAO_IOP::TAO_IOR_Manipulation::_narrow(obj.in());
60 // Status: The following scenarios appear to work:
61 // - first profile invalid host name, second profile valid.
62 // - first profile invalid ip number, second profiel valid.
63 // - first profiel invalid port number, second profile valid.
65 // The following causes a core dump of the server:
66 // - first and second invalid
68 // Note that he iormanip is being used since it is not practical
69 // to have a test case that depends on a VPN being present.
71 CORBA::Object_var name1 =
72 _orb->string_to_object ("c_orbaloc:iiop:10.0.2.3:6060/xyz");
73 CORBA::Object_var name2 =
74 _orb->string_to_object ("c_orbaloc:iiop:daisnot:7070/xyz");
75 CORBA::String_var name1_ior = _orb->object_to_string(name1.in());
76 CORBA::String_var name2_ior = _orb->object_to_string(name2.in());
78 // create a callback object
79 Callee_i * callee_i = new Callee_i;
80 // get the CORBA reference
81 PortableServer::ObjectId_var id =
82 poa->activate_object (callee_i);
84 CORBA::Object_var object_act = poa->id_to_reference (id.in ());
86 Callee_var callee = Callee::_narrow (object_act.in ());
88 if (CORBA::is_nil(callee.in ()))
90 ACE_ERROR ((LM_ERROR, "could not get callback object\n"));
91 return 1;
93 else
95 CORBA::String_var str = _orb->object_to_string(callee.in ());
96 FILE *output_file= ACE_OS::fopen ("ior", "w");
97 if (output_file == 0)
98 ACE_ERROR_RETURN ((LM_ERROR,
99 "Cannot open output file for writing IOR: ior\n"),
101 ACE_OS::fprintf (output_file, "%s", str.in ());
102 ACE_OS::fclose (output_file);
105 // create a reference with two profiles with the first on being
106 // bogus. If things work as they should the callback should be
107 // succesful with the ORB trying the second profile.
108 TAO_IOP::TAO_IOR_Manipulation::IORList iors (2);
109 iors.length (2);
110 iors [0] = name1;
111 iors [1] = name2;
113 CORBA::Object_var merged = iorm->merge_iors(iors);
114 Callee_var doubleCallee = Callee::_unchecked_narrow(merged.in());
116 ACE_DEBUG ((LM_DEBUG, "Profile count is %d\n",
117 iorm->get_profile_count(merged.in())));
119 simple->registerCallee(doubleCallee.in ());
121 ACE_OS::sleep(120);
123 ACE_DEBUG ((LM_DEBUG, "done sleeping\n"));
125 _orb->shutdown(1);
127 catch (const ::CORBA::Exception &ex)
129 ex._tao_print_exception("Caught unexpected CORBA exception :");
131 return 0;