1 // ========================================================================
4 // Program to test the property services.
7 // Here all the objects are at one address space. See the
8 // client.cpp and server.cpp to see property calls on remote
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
24 // The testing code for the PropertySet interface are grouped
25 // under the functions of this class.
28 // Go thru the functions to understand the usage of the various
29 // methods of the PropertySet interaface.
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);
38 ~TAO_PropertySet_Tester (void);
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
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
69 TAO_PropertySet property_set_
;
73 class TAO_PropertyNamesIterator_Tester
76 // The testing code for the PropertyNamesIterator interface are grouped
77 // under the functions of this class.
80 // Go thru the functions to understand the usage of the various
81 // methods of the PropertyNamesIterator interaface.
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);
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.
99 TAO_PropertyNamesIterator iterator_
;
100 // Our names iterator.
105 TAO_PropertySet_Tester::TAO_PropertySet_Tester (void)
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"));
123 // Prepare a char and "define" that in the PropertySet.
124 CORBA::Char ch
= '#';
125 anyval
<<= from_char (ch
);
127 anyval
>>= to_char (ch
);
128 ACE_DEBUG ((LM_DEBUG
,
129 "Main : Char ch = %c\n",
131 property_set_
.define_property ("char_property",
134 // Prepare a Short and "define" that in the PropertySet.
139 ACE_DEBUG ((LM_DEBUG
,
140 "Main : Short s = %d\n",
142 property_set_
.define_property ("short_property",
146 // Prepare a Long and "define" that in the PropertySet.
147 CORBA::Long l
= 931232;
151 ACE_DEBUG ((LM_DEBUG
,
152 "Main : Long l = %d\n",
154 CORBA::Any
newany(anyval
);
156 property_set_
.define_property ("long_property",
159 // Prepare a Float and "define" that in the PropertySet.
160 CORBA::Float f
= 3.14;
164 ACE_DEBUG ((LM_DEBUG
,
165 "Main : Float f = %f\n",
167 property_set_
.define_property ("float_property",
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
;
177 ACE_DEBUG ((LM_DEBUG
,
178 "Main: String : %s, From any : %s\n",
181 property_set_
.define_property ("string_property",
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 ()));
198 // Testing the delete_property. Delets property, with the given name,
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
);
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.
224 ACE_DEBUG ((LM_DEBUG
,
229 ACE_DEBUG ((LM_DEBUG
,
230 "Short property not found\n"));
232 anyptr
= property_set_
.get_property_value ("string_property");
237 ACE_DEBUG ((LM_DEBUG
,
241 ACE_DEBUG ((LM_DEBUG
,
242 "string_property not found\n"));
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"));
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"));
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"));
270 ACE_DEBUG ((LM_DEBUG
,
271 "char_property defined\n"));
276 // Make a sequence of property names and delete them from the
277 // PropertySet. Deleting char, short, long, float and string
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
);
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"));
308 CosPropertyService::Properties nproperties
;
309 nproperties
.length (5);
311 // Prepare a char and "define" that in the PropertySet.
312 CORBA::Char ch
= '#';
313 anyval
<<= from_char (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.
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;
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;
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
);
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 ();
364 ACE_DEBUG ((LM_DEBUG
,
365 "All properties deleted, I guess\n"));
367 ACE_DEBUG ((LM_DEBUG
,
368 "delete_all_properties failed\n"));
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_
)
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 ());
395 ACE_DEBUG ((LM_DEBUG
, "Str : %s\n", strvar
.in ()));
396 ret
= iterator_
.next_one (strvar
.out ());
401 // Reset the names iterator.
403 TAO_PropertyNamesIterator_Tester::test_reset (void)
405 ACE_DEBUG ((LM_DEBUG
,
406 "Resetting (reset ()) the NamesIterator."));
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",
419 int ret
= iterator_
.next_n (n
, pnames_var
.out ());
422 // Return if no more items in the iterator.
423 ACE_DEBUG ((LM_DEBUG
,
424 "Iterator has no more items\n"));
427 for (size_t i
= 0; i
< pnames_var
.in ().length (); i
++)
428 ACE_DEBUG ((LM_DEBUG
,
430 (const char *) pnames_var
[i
]));
435 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
439 CORBA::ORB_var orb_var
= CORBA::ORB_init (argc
,
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
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
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
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 ();
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");
522 catch (const CORBA::UserException
& userex
)
524 .print_exception ("User Exception");