Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Property / main.cpp
blob261b126d5207334dfb82c5e70f0618a2785019b8
1 // ========================================================================
2 //
3 // = FILE
4 // Program to test the property services.
5 //
6 // = DESCRIPTION
7 // Here all the objects are at one address space. See the
8 // client.cpp and server.cpp to see property calls on remote
9 // objects.
11 // = AUTHOR
12 // Alexander Babu Arulanthu <alex@cs.wustl.edu>
14 // ========================================================================
16 #include "orbsvcs/CosPropertyS.h"
17 #include "orbsvcs/Property/CosPropertyService_i.h"
21 class TAO_PropertySet_Tester
23 // = TITLE
24 // The testing code for the PropertySet interface are grouped
25 // under the functions of this class.
27 // = DESCRIPTION
28 // Go thru the functions to understand the usage of the various
29 // methods of the PropertySet interaface.
30 public:
31 friend class TAO_PropertyNamesIterator_Tester;
32 // He has to instantiate TAO_NamesIterator class using the instance
33 // of TAO_PropertySet.
35 TAO_PropertySet_Tester (void);
36 // Constructor.
38 ~TAO_PropertySet_Tester (void);
39 // Destructor.
41 int test_define_property (void);
42 // Defines a char,a short, a long, a float and a string property.
44 int test_get_number_of_properties (void);
45 // Gets the number of properties currently defined in the PropertySet.
47 int test_delete_property (const char *property_name);
48 // Delete a given property.
50 int test_is_property_defined (void);
51 // Check the following properties are defined or
52 // no. "char_property", "short_property" and a "string_property".
54 int test_get_property_value (void);
55 // Get the "float_property" and "string_property" and print them
56 // out.
58 int test_delete_properties (void);
59 // Delete char, short,long, and string properties.
61 int test_delete_all_properties (void);
62 // Delete all the properties.
64 int test_define_properties (void);
65 // Define a sequence of properties. a char, a short, a long, a float
66 // and a string.
68 private:
69 TAO_PropertySet property_set_;
70 // The PropertySet.
73 class TAO_PropertyNamesIterator_Tester
75 // = TITLE
76 // The testing code for the PropertyNamesIterator interface are grouped
77 // under the functions of this class.
79 // = DESCRIPTION
80 // Go thru the functions to understand the usage of the various
81 // methods of the PropertyNamesIterator interaface.
82 public:
83 TAO_PropertyNamesIterator_Tester (TAO_PropertySet_Tester &propertyset_tester);
84 // Constructor. To make names iterator from the property set object.
86 ~TAO_PropertyNamesIterator_Tester (void);
87 // Destructor.
89 int test_next_one (void);
90 // Test next one method. Iterate thru all the names in the
91 // PropertySet and print them out.
93 int test_reset (void);
94 // Test the reset method.
96 int test_next_n (size_t n);
97 // Test the next_n method.
98 private:
99 TAO_PropertyNamesIterator iterator_;
100 // Our names iterator.
104 // Constructor.
105 TAO_PropertySet_Tester::TAO_PropertySet_Tester (void)
109 // Destructor.
110 TAO_PropertySet_Tester::~TAO_PropertySet_Tester (void)
114 // Defines a char, a short, a long, a float and a string.
116 TAO_PropertySet_Tester::test_define_property (void)
118 ACE_DEBUG ((LM_DEBUG,
119 "\nChecking define_property\n"));
121 CORBA::Any anyval;
123 // Prepare a char and "define" that in the PropertySet.
124 CORBA::Char ch = '#';
125 anyval <<= from_char (ch);
126 ch = '*';
127 anyval >>= to_char (ch);
128 ACE_DEBUG ((LM_DEBUG,
129 "Main : Char ch = %c\n",
130 ch));
131 property_set_.define_property ("char_property",
132 anyval);
134 // Prepare a Short and "define" that in the PropertySet.
135 CORBA::Short s = 3;
136 anyval <<= s;
137 s = 7;
138 anyval >>= s;
139 ACE_DEBUG ((LM_DEBUG,
140 "Main : Short s = %d\n",
141 s));
142 property_set_.define_property ("short_property",
143 anyval);
146 // Prepare a Long and "define" that in the PropertySet.
147 CORBA::Long l = 931232;
148 anyval <<= l;
149 l = 931233;
150 anyval >>= l;
151 ACE_DEBUG ((LM_DEBUG,
152 "Main : Long l = %d\n",
153 l));
154 CORBA::Any newany(anyval);
156 property_set_.define_property ("long_property",
157 anyval);
159 // Prepare a Float and "define" that in the PropertySet.
160 CORBA::Float f = 3.14;
161 anyval <<= f;
162 f = 4.14;
163 anyval >>= f;
164 ACE_DEBUG ((LM_DEBUG,
165 "Main : Float f = %f\n",
166 f));
167 property_set_.define_property ("float_property",
168 anyval);
170 // Prepare a String and "define" that in the PropertySet.
171 ACE_DEBUG ((LM_DEBUG,
172 "Main: Any holding String\n"));
173 CORBA::String_var strvar (CORBA::string_dup ("Test_String"));
174 anyval <<= strvar.in ();
175 CORBA::String newstr;
176 anyval >>= newstr;
177 ACE_DEBUG ((LM_DEBUG,
178 "Main: String : %s, From any : %s\n",
179 strvar.in (),
180 newstr));
181 property_set_.define_property ("string_property",
182 anyval);
184 return 0;
187 // Testing, get_number_of_properties.
189 TAO_PropertySet_Tester::test_get_number_of_properties (void)
191 ACE_DEBUG ((LM_DEBUG,
192 "Main : Number of props : %d\n",
193 property_set_.get_number_of_properties ()));
195 return 0;
198 // Testing the delete_property. Delets property, with the given name,
199 // if that exsists.
201 TAO_PropertySet_Tester::test_delete_property (const char *property_name)
203 ACE_DEBUG ((LM_DEBUG, "\nChecking delete_property\n"));
204 property_set_.delete_property (property_name);
206 return 0;
209 // Gets the value of "short_property" and "string_property".
212 TAO_PropertySet_Tester::test_get_property_value (void)
214 ACE_DEBUG ((LM_DEBUG,
215 "\nChecking get_property_value\n"));
217 CORBA::Any_ptr anyptr = property_set_.get_property_value ("short_property");
219 // Get the short value.
220 if (anyptr != 0)
222 CORBA::Short s;
223 *anyptr >>= s;
224 ACE_DEBUG ((LM_DEBUG,
225 "Short %d\n",
226 s));
228 else
229 ACE_DEBUG ((LM_DEBUG,
230 "Short property not found\n"));
231 // Get the string.
232 anyptr = property_set_.get_property_value ("string_property");
233 if (anyptr != 0)
235 CORBA::String str;
236 *anyptr >>= str;
237 ACE_DEBUG ((LM_DEBUG,
238 "Str %s\n", str));
240 else
241 ACE_DEBUG ((LM_DEBUG,
242 "string_property not found\n"));
243 return 0;
246 // Check the following properties are defined or no. "short_property",
247 // "string_property" and "char_property".
250 TAO_PropertySet_Tester::test_is_property_defined (void)
252 ACE_DEBUG ((LM_DEBUG,
253 "\nChecking is_property_defined ()\n"));
254 if (property_set_.is_property_defined ("short_property") == 0)
255 ACE_DEBUG ((LM_DEBUG,
256 "short_property not defined\n"));
257 else
258 ACE_DEBUG ((LM_DEBUG,
259 "short_property defined\n"));
260 if (property_set_.is_property_defined ("string_property") == 0)
261 ACE_DEBUG ((LM_DEBUG,
262 "string_property not defined\n"));
263 else
264 ACE_DEBUG ((LM_DEBUG,
265 "string_property defined\n"));
266 if (property_set_.is_property_defined ("char_property") == 0)
267 ACE_DEBUG ((LM_DEBUG,
268 "char_property not defined\n"));
269 else
270 ACE_DEBUG ((LM_DEBUG,
271 "char_property defined\n"));
273 return 0;
276 // Make a sequence of property names and delete them from the
277 // PropertySet. Deleting char, short, long, float and string
278 // properties.
280 TAO_PropertySet_Tester::test_delete_properties (void)
282 ACE_DEBUG ((LM_DEBUG,
283 "\nChecking delete_properties == Deleting a sequence of Properties\n"));
284 CosPropertyService::PropertyNames prop_names;
285 prop_names.length (4);
286 prop_names [0] = CORBA::string_dup ("char_property");
287 prop_names [1] = CORBA::string_dup ("short_property");
288 prop_names [2] = CORBA::string_dup ("long_property");
289 prop_names [3] = CORBA::string_dup ("float_property");
290 ACE_DEBUG ((LM_DEBUG,
291 "Length of sequence %d, Maxlength : %d\n",
292 prop_names.length (),
293 prop_names.maximum ()));
294 property_set_.delete_properties (prop_names);
296 return 0;
299 // Defines a sequnce of properties containing, char, short, long,
300 // float and string property in the property set.
302 TAO_PropertySet_Tester::test_define_properties (void)
304 ACE_DEBUG ((LM_DEBUG,
305 "\nChecking define_properties == Defining sequence of properties\n"));
306 // TAO_TRY
307 // {
308 CosPropertyService::Properties nproperties;
309 nproperties.length (5);
310 CORBA::Any anyval;
311 // Prepare a char and "define" that in the PropertySet.
312 CORBA::Char ch = '#';
313 anyval <<= from_char (ch);
314 ch = '*';
315 anyval >>= to_char (ch);
316 nproperties[0].property_name = CORBA::string_dup ("char_property");
317 nproperties[0].property_value <<= from_char (ch);
319 // Prepare a Short and "define" that in the PropertySet.
320 CORBA::Short s = 3;
321 anyval <<= s;
322 s = 7;
323 anyval >>= s;
324 nproperties[1].property_name = CORBA::string_dup ("short_property");
325 nproperties[1].property_value <<= s;
327 // Prepare a Long and "define" that in the PropertySet.
328 CORBA::Long l = 931232;
329 anyval <<= l;
330 l = 931233;
331 anyval >>= l;
332 nproperties[2].property_name = CORBA::string_dup ("long_property");
333 nproperties[2].property_value <<= l;
335 // Prepare a Float and "define" that in the PropertySet.
336 CORBA::Float f = 3.14;
337 anyval <<= f;
338 f = 4.14;
339 anyval >>= f;
340 nproperties[3].property_name = CORBA::string_dup ("float_property");
341 nproperties[3].property_value <<= f;
343 // Prepare a String and "define" that in the PropertySet.
344 CORBA::String_var strvar (CORBA::string_dup ("Test_String"));
345 anyval <<= strvar.in ();
346 nproperties[4].property_name = CORBA::string_dup ("string_property");
347 nproperties[4].property_value <<= strvar.in ();
349 // Define this sequence of properties now.
350 property_set_.define_properties (nproperties);
352 return 0;
355 // Delete all the properties.
357 TAO_PropertySet_Tester::test_delete_all_properties (void)
359 // Deleting all the properties
360 ACE_DEBUG ((LM_DEBUG,
361 "\nChecking delete_all_properties\n"));
362 int ret = property_set_.delete_all_properties ();
363 if (ret == 1)
364 ACE_DEBUG ((LM_DEBUG,
365 "All properties deleted, I guess\n"));
366 else
367 ACE_DEBUG ((LM_DEBUG,
368 "delete_all_properties failed\n"));
369 return 0;
372 // Constructor. To make names iterator from the property set object.
373 TAO_PropertyNamesIterator_Tester::TAO_PropertyNamesIterator_Tester (TAO_PropertySet_Tester &propertyset_tester)
374 : iterator_ (propertyset_tester.property_set_)
378 // Destructor.
379 TAO_PropertyNamesIterator_Tester::~TAO_PropertyNamesIterator_Tester (void)
383 // Test next one method. Iterate thru all the names in the
384 // PropertySet and print them out.
386 TAO_PropertyNamesIterator_Tester::test_next_one (void)
388 CORBA::String_var strvar;
389 ACE_DEBUG ((LM_DEBUG,
390 "\nTesting next_one of NamesIterator, Iterating thru names.\n"));
391 // Let us iterate, now.
392 int ret = iterator_.next_one (strvar.out ());
393 while (ret != 0)
395 ACE_DEBUG ((LM_DEBUG, "Str : %s\n", strvar.in ()));
396 ret = iterator_.next_one (strvar.out ());
398 return 0;
401 // Reset the names iterator.
403 TAO_PropertyNamesIterator_Tester::test_reset (void)
405 ACE_DEBUG ((LM_DEBUG,
406 "Resetting (reset ()) the NamesIterator."));
407 iterator_.reset ();
408 return 0;
411 // Test the next_n method. Get the next n names and print them all.
413 TAO_PropertyNamesIterator_Tester::test_next_n (size_t n)
415 CosPropertyService::PropertyNames_var pnames_var;
416 ACE_DEBUG ((LM_DEBUG,
417 "Checking next_n (), next %d\n",
418 n));
419 int ret = iterator_.next_n (n, pnames_var.out ());
420 if (ret == 0)
422 // Return if no more items in the iterator.
423 ACE_DEBUG ((LM_DEBUG,
424 "Iterator has no more items\n"));
425 return 0;
427 for (size_t i = 0; i < pnames_var.in ().length (); i++)
428 ACE_DEBUG ((LM_DEBUG,
429 "str %s\n",
430 (const char *) pnames_var[i]));
431 return 0;
435 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
439 CORBA::ORB_var orb_var = CORBA::ORB_init (argc,
440 argv,
441 "internet");
443 // = Checking PropertySet interface.
445 ACE_DEBUG ((LM_DEBUG,
446 "\nTAO_PropertySet Testing\n"));
447 TAO_PropertySet_Tester propertyset_tester;
449 // Checking define_property. define a char, a short,a long, a float
450 // and a string.
451 propertyset_tester.test_define_property ();
453 // Test the number of properties and print it out.
454 propertyset_tester.test_get_number_of_properties ();
456 // Test delete property. Delete "string_property"
457 propertyset_tester.test_delete_property ("string_property");
459 // Test the number of properties and print it out.
460 propertyset_tester.test_get_number_of_properties ();
462 // Test delete_properties. Delete char, short, long and float.
463 propertyset_tester.test_delete_properties ();
465 // Test the number of properties and print it out.
466 propertyset_tester.test_get_number_of_properties ();
468 // Define a sequence of properties. char, short, long, float and
469 // string.
470 propertyset_tester.test_define_properties ();
472 // Test the number of properties and print it out.
473 propertyset_tester.test_get_number_of_properties ();
475 // Checking get_property_value. get the value of short and string.
476 propertyset_tester.test_get_property_value ();
478 // Checking delete_all_properties.
479 propertyset_tester.test_delete_all_properties ();
481 // Test the number of properties and print it out.
482 propertyset_tester.test_get_number_of_properties ();
484 // Define a sequence of properties. char, short, long, float and
485 // string.
486 propertyset_tester.test_define_properties ();
488 // Test the number of properties and print it out.
489 propertyset_tester.test_get_number_of_properties ();
491 // = Checking the PropertyNamesIterator interface.
493 ACE_DEBUG ((LM_DEBUG,
494 "\nTAO_PropertyNamesIterator Testing\n"));
496 // Construct the names iterator from the PropertySet object.
497 TAO_PropertyNamesIterator_Tester names_iterator_tester (propertyset_tester);
499 // Checking next_one. Iterate thru the property names.
500 names_iterator_tester.test_next_one ();
502 // Checking the reset () method.
503 names_iterator_tester.test_reset ();
505 // Iterating again thru the property names.
506 names_iterator_tester.test_next_one ();
508 // Reset again.
509 names_iterator_tester.test_reset ();
511 // Checking next_n. Prints out all the names it has got.
512 names_iterator_tester.test_next_n (6);
514 // Try next_n without resetting.
515 names_iterator_tester.test_next_n (6);
517 catch (const CORBA::SystemException& sysex)
519 .print_exception ("System Exception");
520 return -1;
522 catch (const CORBA::UserException& userex)
524 .print_exception ("User Exception");
525 return -1;
527 return 0;