Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / tests / Simple_Naming / client.h
blob2c186d1f129c3bb6069faa5da4f7b3d74399e1cd
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file client.h
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"
18 #include "ace/Task.h"
20 /**
21 * @class Naming_Test
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
29 * chosen at runtime.
31 class Naming_Test
33 public:
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;
39 protected:
40 Naming_Test (PortableServer::POA_ptr poa);
42 PortableServer::POA_var poa_;
45 /**
46 * @class Simple_Test
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
55 public:
56 Simple_Test (PortableServer::POA_ptr poa);
58 /// Execute the simple test code.
59 virtual int execute (TAO_Naming_Client &root_context);
62 /**
63 * @class MT_Test
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
73 public:
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,
77 int size = 10);
79 /// Execute the MT test code.
80 virtual int execute (TAO_Naming_Client &root_context);
82 /// This code is executed by each thread.
83 virtual int svc ();
85 private:
86 /// Number of threads to spawn. By default is set to 10.
87 int size_;
89 /// A pointer to our ORB.
90 CORBA::ORB_var orb_;
92 /**
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
97 * happen...
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_;
112 * @class Tree_Test
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
125 * level2 context.
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
133 public:
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()
149 * on the iterator.
151 class Iterator_Test : public Naming_Test
153 public:
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
180 public:
181 /// Execute the exceptions test code.
182 Exceptions_Test (PortableServer::POA_ptr poa);
183 virtual int execute (TAO_Naming_Client &root_context);
185 private:
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
211 public:
212 /// Execute the destroy test code.
213 Destroy_Test (PortableServer::POA_ptr poa);
214 virtual int execute (TAO_Naming_Client &root_context);
216 private:
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
226 * Service test.
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
234 public:
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);
240 /// Destructor.
241 virtual ~Persistent_Test_Begin ();
243 /// Execute the persistent test (part 1) code.
244 virtual int execute (TAO_Naming_Client &root_context);
246 private:
247 /// A pointer to our ORB (needed for object/string conversion).
248 CORBA::ORB_var orb_;
250 /// File where we output the ior for use by part 2 of persistent test.
251 FILE *file_;
255 * @class Persistent_Test_End
257 * @brief This class implements the second part of the Persistent Naming
258 * Service test.
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
268 public:
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);
275 /// Destructor.
276 virtual ~Persistent_Test_End ();
278 /// Execute the persistent test (part 2).
279 virtual int execute (TAO_Naming_Client &root_context);
281 private:
282 /// A pointer to our ORB (used for string/object conversion).
283 CORBA::ORB_var orb_;
285 /// IOR of <level1_context> recorded during the run of part 1 of
286 /// persistent test.
287 const ACE_TCHAR* ior_;
291 * @class Persistent_List_Test
293 * @brief This class implements the third part of the Persistent Naming
294 * Service test.
296 * This test attempts to invoke various list() methods on different
297 * known contexts.
299 class Persistent_List_Test : public Naming_Test
301 public:
302 /// Constructor. Takes in an orb pointer.
303 Persistent_List_Test (CORBA::ORB_ptr orb,
304 PortableServer::POA_ptr poa);
306 /// Destructor.
307 virtual ~Persistent_List_Test ();
309 /// Execute the persistent test (part 3).
310 virtual int execute (TAO_Naming_Client &root_context);
312 private:
313 /// A pointer to our ORB (used for string/object conversion).
314 CORBA::ORB_var orb_;
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
327 * is needed.
329 class CosNaming_Client
331 public:
332 /// Constructor.
333 CosNaming_Client ();
335 /// Destructor.
336 ~CosNaming_Client ();
338 /// Execute client example code.
339 int run ();
341 /// Initialize the client communication endpoint with server.
342 int init (int argc, ACE_TCHAR **argv);
344 // = Symbolic ids.
345 enum OBJ_ID
347 OBJ1_ID = 5,
348 OBJ2_ID = 6
351 private:
352 /// Parses the arguments passed on the command line.
353 int parse_args ();
355 /// # of arguments on the command line.
356 int argc_;
358 /// arguments from command line.
359 ACE_TCHAR **argv_;
361 /// A pointer to the specific Naming Service test a client will
362 /// execute.
363 Naming_Test *test_;
365 /// Our ORB manager helper class.
366 TAO_ORB_Manager orbmgr_;
368 /// Our naming client helper class.
369 TAO_Naming_Client naming_client_;