3 //=============================================================================
7 * This class tests the facilities to connect to the naming service.
9 * @author Marina Spivak <marina@cs.wustl.edu>
11 //=============================================================================
14 #include "test_objectS.h"
15 #include "orbsvcs/CosNamingC.h"
16 #include "orbsvcs/Naming/Naming_Client.h"
17 #include "tao/Utils/ORB_Manager.h"
23 * @brief This is an abstract class which is subclassed
24 * to create different Naming Service tests.
26 * This is a basic example of the "Strategy" pattern. This class
27 * provides a common interface for different tests (or
28 * "strategies"), so that a specific test to be used can be
34 /// Execute the test code. <root_context> is the context to assume
35 /// as the root for all tests operations.
36 virtual ~Naming_Test ();
37 virtual int execute (TAO_Naming_Client
&root_context
) = 0;
40 Naming_Test (PortableServer::POA_ptr poa
);
42 PortableServer::POA_var poa_
;
48 * @brief This class implements a simple Naming Service test.
50 * The test binds(), resolves(), and unbinds() an object
51 * reference from the given Naming Context.
53 class Simple_Test
: public Naming_Test
56 Simple_Test (PortableServer::POA_ptr poa
);
58 /// Execute the simple test code.
59 virtual int execute (TAO_Naming_Client
&root_context
);
65 * @brief This class implements a simple Multithreaded (multiclient) Naming Service test.
67 * The test spawns multiple threads: each attempts to
68 * bind(), resolve(), and unbind() an object
69 * reference using the same name, and the same Naming Context.
71 class MT_Test
: public Naming_Test
, public ACE_Task_Base
74 /// Constructor. Takes in an orb pointer and number of threads to spawn.
75 MT_Test (CORBA::ORB_ptr orb
,
76 PortableServer::POA_ptr poa
,
79 /// Execute the MT test code.
80 virtual int execute (TAO_Naming_Client
&root_context
);
82 /// This code is executed by each thread.
86 /// Number of threads to spawn. By default is set to 10.
89 /// A pointer to our ORB.
93 * IOR in the string format for Naming Service we are to deal with.
94 * Each thread will use string_to_object() and this IOR to create
95 * its own NamingContext stub for invoking operations on the
96 * Naming Service. If all threads try to use the same stub, bad things
99 CORBA::String_var name_service_ior_
;
101 // This can be replaced with CORBA::String_var when <string_to_object>
102 // is fixed - this will clean up the memory properly.
104 /// Holds name used for registering the object with Naming Service.
105 CosNaming::Name test_name_
;
107 /// Holds object to be registered with the Naming Service by each thread.
108 Test_Object_var test_ref_
;
114 * @brief This class implements a test of all Naming Service functions
115 * on a tree of Naming Contexts.
117 * Bind_context() under the root context with the name level1.
118 * Create_new_context(), bind() foo object into it, and
119 * bind the context into root/level1 under the name level2.
120 * Resolve (root/level1/level2/foo).
121 * Unbind (root/level1/level2/foo).
122 * Bind (root/level1/level2/foo, obj)
123 * Create_new_context()
124 * and invoke rebind_context() to substitute it for the current
126 * Bind (root/level1/level2/foo, obj)
127 * Resolve (root/level1/level2/foo).
128 * Rebind() to have a different object under the name bar.
129 * Resolve (root/level1/level2/foo) to make sure correct reference is returned.
131 class Tree_Test
: public Naming_Test
134 /// Execute the tree test code.
135 Tree_Test (PortableServer::POA_ptr poa
);
136 virtual int execute (TAO_Naming_Client
&root_context
);
140 * @class Iterator_Test
142 * @brief This class implements a test of Naming Service functions
143 * which involve BindingIterator.
145 * The test binds foo1, foo2, foo3, and foo4 objects to the
146 * Naming Context. It lists() one binding and receives
147 * BindingIterator to iterate over the rest of the bindings. It
148 * then invokes next_one(), next_n(2), next_one(), and destroy()
151 class Iterator_Test
: public Naming_Test
154 /// Execute the iterator test code.
155 Iterator_Test (PortableServer::POA_ptr poa
);
156 virtual int execute (TAO_Naming_Client
&root_context
);
160 * @class Exceptions_Test
162 * @brief This class implements a test of exceptions in the Naming Service.
164 * Makes sure that Naming Service throws exceptions as expected, and
165 * data inside exceptions is set correctly. The test creates a tree of
166 * of Naming Contexts: root context -> level1 -> level2. It then binds() an
167 * object with the name foo to each of Naming Contexts in the tree.
168 * Invoke resolve() with a Name of length 0 - make sure we get InvalidName exception.
169 * Invoke bind( foo, obj) on root context - make sure we get AlreadyBound exception.
170 * Invoke bind( level1/foo, obj) on root context - make sure we get AlreadyBound exc.
171 * Invoke unbind( level1/level2/bar) on root context - make sure we get NotFound exc.
172 * with why = not_object, rest_of_name = bar.
173 * Invoke unbind( level1/level3/foo) on root context - make sure we get NotFound exc.
174 * with why = missing_node, rest_of_name = level3/foo.
175 * Invoke unbind( level1/foo/foo) on root context - make sure we get NotFound exc.
176 * with why = not_context, rest_of_name = foo/foo.
178 class Exceptions_Test
: public Naming_Test
181 /// Execute the exceptions test code.
182 Exceptions_Test (PortableServer::POA_ptr poa
);
183 virtual int execute (TAO_Naming_Client
&root_context
);
186 // the following functions isolate specific tests due to the
187 // limitation of only 1 TAO_TRY being allowed per function.
189 void invalid_name_test (TAO_Naming_Client
&root_context
);
190 void already_bound_test (TAO_Naming_Client
&root_context
);
191 void already_bound_test2 (TAO_Naming_Client
&root_context
);
192 void not_found_test (TAO_Naming_Client
&root_context
);
193 void not_found_test2 (TAO_Naming_Client
&root_context
);
194 void not_found_test3 (TAO_Naming_Client
&root_context
);
198 * @class Destroy_Test
200 * @brief This class implements a test of destroy() function
201 * in the Naming Service.
203 * Create a context and bind an object under it.
204 * Attempt to destroy the context - NotEmpty exception should be raised.
205 * Unbind the object and call destroy on the context.
206 * Attempt to call destroy on the object again - OBJECT_NOT_EXIST
207 * exception should be raised.
209 class Destroy_Test
: public Naming_Test
212 /// Execute the destroy test code.
213 Destroy_Test (PortableServer::POA_ptr poa
);
214 virtual int execute (TAO_Naming_Client
&root_context
);
217 // = The following functions isolate specific tests.
218 void not_empty_test (CosNaming::NamingContext_var
&ref
);
219 void not_exist_test (CosNaming::NamingContext_var
&ref
);
223 * @class Persistent_Test_Begin
225 * @brief This class implements the first part of the Persistent Naming
228 * This test creates the Naming Context hierarchy:
229 * root -> level1_context -> level2_context,
230 * and prints out the ior of the <level1_context>.
232 class Persistent_Test_Begin
: public Naming_Test
235 /// Constructor. Takes in an orb pointer.
236 Persistent_Test_Begin (CORBA::ORB_ptr orb
,
237 PortableServer::POA_ptr poa
,
238 FILE * ior_output_file
);
241 virtual ~Persistent_Test_Begin ();
243 /// Execute the persistent test (part 1) code.
244 virtual int execute (TAO_Naming_Client
&root_context
);
247 /// A pointer to our ORB (needed for object/string conversion).
250 /// File where we output the ior for use by part 2 of persistent test.
255 * @class Persistent_Test_End
257 * @brief This class implements the second part of the Persistent Naming
260 * This test attempts to resolve <level2_context> both through the
261 * <root> Naming Context, which it gets from <resolve_initial_references>, and
262 * through <level1_context> stringified ior, which it gets from part 1 of
263 * the persistent test. The results of both methods are then
264 * compared for equality.
266 class Persistent_Test_End
: public Naming_Test
269 /// Constructor. Takes in an orb pointer and the ior received from
270 /// <Persistent_Test_Begin>.
271 Persistent_Test_End (CORBA::ORB_ptr orb
,
272 PortableServer::POA_ptr poa
,
273 const ACE_TCHAR
* ior
);
276 virtual ~Persistent_Test_End ();
278 /// Execute the persistent test (part 2).
279 virtual int execute (TAO_Naming_Client
&root_context
);
282 /// A pointer to our ORB (used for string/object conversion).
285 /// IOR of <level1_context> recorded during the run of part 1 of
287 const ACE_TCHAR
* ior_
;
291 * @class Persistent_List_Test
293 * @brief This class implements the third part of the Persistent Naming
296 * This test attempts to invoke various list() methods on different
299 class Persistent_List_Test
: public Naming_Test
302 /// Constructor. Takes in an orb pointer.
303 Persistent_List_Test (CORBA::ORB_ptr orb
,
304 PortableServer::POA_ptr poa
);
307 virtual ~Persistent_List_Test ();
309 /// Execute the persistent test (part 3).
310 virtual int execute (TAO_Naming_Client
&root_context
);
313 /// A pointer to our ORB (used for string/object conversion).
318 * @class CosNaming_Client
320 * @brief Defines a class that encapsulates behaviour of the CosNaming
321 * client example. Provides a better understanding of the logic
322 * in an object-oriented way.
324 * This class declares an interface to run the example client for
325 * CosNaming CORBA server. All the complexity for initializing
326 * the server is hidden in the class. Just the <run> interface
329 class CosNaming_Client
336 ~CosNaming_Client ();
338 /// Execute client example code.
341 /// Initialize the client communication endpoint with server.
342 int init (int argc
, ACE_TCHAR
**argv
);
352 /// Parses the arguments passed on the command line.
355 /// # of arguments on the command line.
358 /// arguments from command line.
361 /// A pointer to the specific Naming Service test a client will
365 /// Our ORB manager helper class.
366 TAO_ORB_Manager orbmgr_
;
368 /// Our naming client helper class.
369 TAO_Naming_Client naming_client_
;