Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / ORB_init / ORB_init.cpp
blobee8127dc8041667887f5fa4dff5516c08b986f88
1 // -*- C++ -*-
2 #include "tao/ORB.h"
3 #include "tao/Object.h"
4 #include "tao/SystemException.h"
6 #include "ace/Log_Msg.h"
8 // Valid test IOR.
9 // Do not attempt to narrow the object represented by this IOR, nor
10 // should you modify the IOR unless you replace it with another
11 // valid one!
12 static const char IOR[] =
13 "IOR:010000001600000049444c3a43756269745f466163746f72793a312e30000000010000000000000090000000010102cd14000000616e647572696c2e6563652e7563692e6564750057fecdcd2d00000014010f004e5550000000130000000001000000006368696c645f706f61000000000001000000666163746f7279cdcdcd03000000000000000800000001cdcdcd004f4154010000001400000001cdcdcd01000100000000000901010000000000004f41540400000001cd0000";
15 int
16 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
18 CORBA::ORB_var orb;
20 try
22 const char orbid[] = "mighty_orb";
24 CORBA::ORB_ptr my_orb = CORBA::ORB::_nil();
27 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, orbid);
29 my_orb = orb.in ();
31 // Once we leave this scope, the ORB is released but it should
32 // be possible to obtain the same ORB with another call to
33 // CORBA::ORB_init() by using the same ORBid argument that was
34 // assigned to this ORB.
37 // -------------------------------------------------------------
38 // Verify that the same ORB is returned from a second call to
39 // CORBA::ORB_init() in a different scope when the same ORBid is
40 // used in that scope.
41 // -------------------------------------------------------------
43 orb = CORBA::ORB_init (argc, argv, orbid);
45 // This isn't portable, but TAO implements an ORB_ptr as a
46 // pointer so we're okay.
48 // Check if the ORB returned from the ORB_init() call is the
49 // same.
50 if (my_orb == orb.in ())
52 ACE_DEBUG ((LM_INFO,
53 "\n"
54 "The ORB <%C> was successfully returned from a second\n"
55 "call to CORBA::ORB_init() after it was released in\n"
56 "a previous scope.\n"
57 "\n",
58 orbid));
60 else
62 ACE_ERROR_RETURN ((LM_ERROR,
63 "\n"
64 "ORB <%C> was not successfully returned from a\n"
65 "second call to CORBA::ORB_init() despite the\n"
66 "fact it wasn't explicitly destroyed.\n"
67 "\n",
68 orbid),
69 1);
72 // -------------------------------------------------------------
73 // Now explicitly destroy the ORB with the given ORBid and
74 // attempt to initialize a new ORB with the same ORBid.
75 // -------------------------------------------------------------
77 orb->destroy ();
79 orb = CORBA::ORB_init (argc, argv, orbid);
81 // This isn't portable, but TAO implements an ORB_ptr as a
82 // pointer so we're okay.
84 // Check if the ORB returned from the ORB_init() call is the
85 // same.
86 if (my_orb != orb.in ())
88 ACE_DEBUG ((LM_INFO,
89 "\n"
90 "A new ORB with ORBid <%C> was successfully returned\n"
91 "from a second call to CORBA::ORB_init() after the\n"
92 "first ORB with the same ORBid was destroyed.\n"
93 "\n",
94 orbid));
96 else
98 ACE_ERROR ((LM_ERROR,
99 "\n"
100 "ORB <%C> was not successfully destroyed.\n"
101 "\n",
102 orbid));
104 throw CORBA::INTERNAL ();
107 // -------------------------------------------------------------
108 // Create an object (but don't narrow() it) so that we can test
109 // that some of the TAO_Stub internals are functioning properly
110 // (leaks, etc).
111 // -------------------------------------------------------------
113 CORBA::Object_var object =
114 orb->string_to_object (IOR);
116 // -------------------------------------------------------------
117 // Initialize another two ORBs but don't explicitly destroy them
118 // to allow testing of TAO's internal ORB table resource
119 // clean-up.
120 // -------------------------------------------------------------
121 CORBA::ORB_var orb2 =
122 CORBA::ORB_init (argc, argv, "ORB number 2");
124 CORBA::ORB_var orb3 =
125 CORBA::ORB_init (argc, argv, "ORB number 3");
127 // -------------------------------------------------------------
128 // Now try to perform an operation using the destroyed ORB
129 // pseudo object. A CORBA::OBJECT_NOT_EXIST() exception should
130 // be thrown. This also tests whether or not exceptions or the
131 // ORB itself break when the last ORB is released.
132 // -------------------------------------------------------------
134 orb->destroy ();
136 CORBA::Object_var obj =
137 orb->resolve_initial_references ("RootPOA");
139 // If we get here, then something went wrong. A
140 // CORBA::OBJECT_NOT_EXIST() exception should have been thrown!.
141 ACE_ERROR ((LM_ERROR,
142 "\n"
143 "CORBA::OBJECT_NOT_EXIST() exception was not thrown\n"
144 "during attempt to perform an ORB operation using\n"
145 "destroyed ORB <%C>\n"
146 "The CORBA::OBJECT_NOT_EXIST() exception should have\n"
147 "been thrown!\n"
148 "\n",
149 orbid));
151 throw CORBA::INTERNAL ();
153 catch (const CORBA::OBJECT_NOT_EXIST& exc)
155 // Do something with the exception to make sure it actually
156 // exists. If it doesn't exist then there is something wrong
157 // with exception lifetime.
158 ACE_DEBUG ((LM_INFO,
159 "\n"
160 "Successfully caught CORBA system exception after the\n"
161 "last ORB was released with the following repository ID:\n"
162 " %C\n"
163 "This exception was expected. It is safe to ignore it.\n",
164 exc._rep_id ()));
166 catch (const CORBA::Exception& ex)
168 ex._tao_print_exception ("Caught unexpected exception:");
171 ACE_DEBUG ((LM_ERROR,
172 "\n"
173 "ORB_init test failed.\n"));
175 return 1;
178 ACE_DEBUG ((LM_INFO,
179 "\n"
180 "ORB_init test completed successfully.\n"));
182 return 0;