Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / objref_comparison_test / main.cpp
blob482e851600016234c6c168ceecb47289ab31c773
1 #include "ace/Functor.h"
2 #include "ace/Task.h"
3 #include "fooS.h"
5 /*
6 This isn't too complicated, but it is a little convoluted. So, here's the
7 explanation:
9 1. Two threads. One thread is a CORBA server, the other a CORBA
10 client to that CORBA server.
12 2. the main thread sets up the server-side stuff, and then fires off
13 a task to run the server.
15 3. once the server thread/task is running, the main thread makes
16 invocations to "match_references()" and reports the outcome.
18 The CORBA Object compares the stringified representation of two IORs
19 both generated from the ORB but in different contexts, and returns the
20 result of the comparison as a boolean.
23 class Foo_Impl : public virtual POA_foo
25 public:
26 CORBA::Boolean match_references ();
28 CORBA::String_var ior_from_main_;
29 ACE_Equal_To<const char*> equal_func;
30 ACE_Hash<const char*> hash_func;
33 CORBA::Boolean
34 Foo_Impl::match_references ()
36 CORBA::Object_var o = _this ();
37 CORBA::ORB_var orb = o->_get_orb ();
38 CORBA::String_var ior_from_upcall = orb->object_to_string (o.in());
40 CORBA::Boolean r1 = equal_func (this->ior_from_main_.in(), ior_from_upcall.in());
42 return r1;
45 class Server_Task : public ACE_Task_Base
47 public:
48 Server_Task (CORBA::ORB_ptr orb)
49 : orb_ (CORBA::ORB::_duplicate (orb))
52 virtual ~Server_Task ();
54 virtual int svc ();
55 private:
56 CORBA::ORB_var orb_;
59 Server_Task::~Server_Task() { }
61 int
62 Server_Task::svc ()
64 this->orb_->run ();
65 return 0;
68 int
69 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
71 CORBA::ORB_var s_orb;
72 try
74 s_orb = CORBA::ORB_init (argc, argv);
76 CORBA::Object_var o = s_orb->resolve_initial_references ("RootPOA");
77 PortableServer::POA_var rootpoa = PortableServer::POA::_narrow (o.in());
78 if (CORBA::is_nil (rootpoa.in()))
79 ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t): failed to get root poa\n"), 1);
81 PortableServer::POAManager_var poamgr = rootpoa->the_POAManager();
83 Foo_Impl* foo = 0;
84 ACE_NEW_RETURN (foo, Foo_Impl, 1);
85 PortableServer::ServantBase_var owner_transfer (foo);
86 PortableServer::ObjectId_var id = rootpoa->activate_object (foo);
87 o = rootpoa->id_to_reference (id.in());
89 Foo_Impl* foo2 = 0;
90 ACE_NEW_RETURN (foo2, Foo_Impl, 1);
91 PortableServer::ServantBase_var foo_owner (foo2);
92 foo_var f2 = foo2->_this (); // implicit activation
94 poamgr->activate ();
96 foo->ior_from_main_ = s_orb->object_to_string (o.in());
97 foo2->ior_from_main_ = foo->ior_from_main_;
99 Server_Task server(s_orb.in());
100 server.activate(1); // activate one thread running the task
102 foo_var f = foo::_narrow (o.in()); // ignore the possibility that
103 // it's not a 'foo' since we
104 // created it above
106 int const iterations = 10;
107 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client: next %d iterations should match\n",
108 iterations));
109 for (int i = 0; i < iterations; ++i)
111 CORBA::Boolean b = f->match_references ();
112 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client: iteration %d, match = %d\n",
113 i, b));
116 ACE_DEBUG ((LM_DEBUG,
117 "(%P|%t) client: next %d iterations should NOT match\n",
118 iterations));
119 for (int i = 0; i < iterations; ++i)
121 CORBA::Boolean b = f2->match_references ();
122 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client: iteration %d, match = %d\n",
123 i, b));
126 catch (...)
130 return 0;