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"
20 class TAO_PropertySet_Tester
23 // The testing code for the PropertySet interface are grouped
24 // under the functions of this class.
27 // Go thru the functions to understand the usage of the various
28 // methods of the PropertySet interaface.
30 friend class TAO_PropertyNamesIterator_Tester
;
31 // He has to instantiate TAO_NamesIterator class using the instance
32 // of TAO_PropertySet.
34 TAO_PropertySet_Tester ();
37 ~TAO_PropertySet_Tester ();
40 int test_define_property ();
41 // Defines a char,a short, a long, a float and a string property.
43 int test_get_number_of_properties ();
44 // Gets the number of properties currently defined in the PropertySet.
46 int test_delete_property (const char *property_name
);
47 // Delete a given property.
49 int test_is_property_defined ();
50 // Check the following properties are defined or
51 // no. "char_property", "short_property" and a "string_property".
53 int test_get_property_value ();
54 // Get the "float_property" and "string_property" and print them
57 int test_delete_properties ();
58 // Delete char, short,long, and string properties.
60 int test_delete_all_properties ();
61 // Delete all the properties.
63 int test_define_properties ();
64 // Define a sequence of properties. a char, a short, a long, a float
68 TAO_PropertySet property_set_
;
72 class TAO_PropertyNamesIterator_Tester
75 // The testing code for the PropertyNamesIterator interface are grouped
76 // under the functions of this class.
79 // Go thru the functions to understand the usage of the various
80 // methods of the PropertyNamesIterator interaface.
82 TAO_PropertyNamesIterator_Tester (TAO_PropertySet_Tester
&propertyset_tester
);
83 // Constructor. To make names iterator from the property set object.
85 ~TAO_PropertyNamesIterator_Tester ();
89 // Test next one method. Iterate thru all the names in the
90 // PropertySet and print them out.
93 // Test the reset method.
95 int test_next_n (size_t n
);
96 // Test the next_n method.
98 TAO_PropertyNamesIterator iterator_
;
99 // Our names iterator.
104 TAO_PropertySet_Tester::TAO_PropertySet_Tester ()
109 TAO_PropertySet_Tester::~TAO_PropertySet_Tester ()
113 // Defines a char, a short, a long, a float and a string.
115 TAO_PropertySet_Tester::test_define_property ()
117 ACE_DEBUG ((LM_DEBUG
,
118 "\nChecking define_property\n"));
122 // Prepare a char and "define" that in the PropertySet.
123 CORBA::Char ch
= '#';
124 anyval
<<= from_char (ch
);
126 anyval
>>= to_char (ch
);
127 ACE_DEBUG ((LM_DEBUG
,
128 "Main : Char ch = %c\n",
130 property_set_
.define_property ("char_property",
133 // Prepare a Short and "define" that in the PropertySet.
138 ACE_DEBUG ((LM_DEBUG
,
139 "Main : Short s = %d\n",
141 property_set_
.define_property ("short_property",
145 // Prepare a Long and "define" that in the PropertySet.
146 CORBA::Long l
= 931232;
150 ACE_DEBUG ((LM_DEBUG
,
151 "Main : Long l = %d\n",
153 CORBA::Any
newany(anyval
);
155 property_set_
.define_property ("long_property",
158 // Prepare a Float and "define" that in the PropertySet.
159 CORBA::Float f
= 3.14;
163 ACE_DEBUG ((LM_DEBUG
,
164 "Main : Float f = %f\n",
166 property_set_
.define_property ("float_property",
169 // Prepare a String and "define" that in the PropertySet.
170 ACE_DEBUG ((LM_DEBUG
,
171 "Main: Any holding String\n"));
172 CORBA::String_var
strvar (CORBA::string_dup ("Test_String"));
173 anyval
<<= strvar
.in ();
174 CORBA::String newstr
;
176 ACE_DEBUG ((LM_DEBUG
,
177 "Main: String : %s, From any : %s\n",
180 property_set_
.define_property ("string_property",
186 // Testing, get_number_of_properties.
188 TAO_PropertySet_Tester::test_get_number_of_properties ()
190 ACE_DEBUG ((LM_DEBUG
,
191 "Main : Number of props : %d\n",
192 property_set_
.get_number_of_properties ()));
197 // Testing the delete_property. Delets property, with the given name,
200 TAO_PropertySet_Tester::test_delete_property (const char *property_name
)
202 ACE_DEBUG ((LM_DEBUG
, "\nChecking delete_property\n"));
203 property_set_
.delete_property (property_name
);
208 // Gets the value of "short_property" and "string_property".
211 TAO_PropertySet_Tester::test_get_property_value ()
213 ACE_DEBUG ((LM_DEBUG
,
214 "\nChecking get_property_value\n"));
216 CORBA::Any_ptr anyptr
= property_set_
.get_property_value ("short_property");
218 // Get the short value.
223 ACE_DEBUG ((LM_DEBUG
,
228 ACE_DEBUG ((LM_DEBUG
,
229 "Short property not found\n"));
231 anyptr
= property_set_
.get_property_value ("string_property");
236 ACE_DEBUG ((LM_DEBUG
,
240 ACE_DEBUG ((LM_DEBUG
,
241 "string_property not found\n"));
245 // Check the following properties are defined or no. "short_property",
246 // "string_property" and "char_property".
249 TAO_PropertySet_Tester::test_is_property_defined ()
251 ACE_DEBUG ((LM_DEBUG
,
252 "\nChecking is_property_defined ()\n"));
253 if (property_set_
.is_property_defined ("short_property") == 0)
254 ACE_DEBUG ((LM_DEBUG
,
255 "short_property not defined\n"));
257 ACE_DEBUG ((LM_DEBUG
,
258 "short_property defined\n"));
259 if (property_set_
.is_property_defined ("string_property") == 0)
260 ACE_DEBUG ((LM_DEBUG
,
261 "string_property not defined\n"));
263 ACE_DEBUG ((LM_DEBUG
,
264 "string_property defined\n"));
265 if (property_set_
.is_property_defined ("char_property") == 0)
266 ACE_DEBUG ((LM_DEBUG
,
267 "char_property not defined\n"));
269 ACE_DEBUG ((LM_DEBUG
,
270 "char_property defined\n"));
275 // Make a sequence of property names and delete them from the
276 // PropertySet. Deleting char, short, long, float and string
279 TAO_PropertySet_Tester::test_delete_properties ()
281 ACE_DEBUG ((LM_DEBUG
,
282 "\nChecking delete_properties == Deleting a sequence of Properties\n"));
283 CosPropertyService::PropertyNames prop_names
;
284 prop_names
.length (4);
285 prop_names
[0] = CORBA::string_dup ("char_property");
286 prop_names
[1] = CORBA::string_dup ("short_property");
287 prop_names
[2] = CORBA::string_dup ("long_property");
288 prop_names
[3] = CORBA::string_dup ("float_property");
289 ACE_DEBUG ((LM_DEBUG
,
290 "Length of sequence %d, Maxlength : %d\n",
291 prop_names
.length (),
292 prop_names
.maximum ()));
293 property_set_
.delete_properties (prop_names
);
298 // Defines a sequnce of properties containing, char, short, long,
299 // float and string property in the property set.
301 TAO_PropertySet_Tester::test_define_properties ()
303 ACE_DEBUG ((LM_DEBUG
,
304 "\nChecking define_properties == Defining sequence of properties\n"));
307 CosPropertyService::Properties nproperties
;
308 nproperties
.length (5);
310 // Prepare a char and "define" that in the PropertySet.
311 CORBA::Char ch
= '#';
312 anyval
<<= from_char (ch
);
314 anyval
>>= to_char (ch
);
315 nproperties
[0].property_name
= CORBA::string_dup ("char_property");
316 nproperties
[0].property_value
<<= from_char (ch
);
318 // Prepare a Short and "define" that in the PropertySet.
323 nproperties
[1].property_name
= CORBA::string_dup ("short_property");
324 nproperties
[1].property_value
<<= s
;
326 // Prepare a Long and "define" that in the PropertySet.
327 CORBA::Long l
= 931232;
331 nproperties
[2].property_name
= CORBA::string_dup ("long_property");
332 nproperties
[2].property_value
<<= l
;
334 // Prepare a Float and "define" that in the PropertySet.
335 CORBA::Float f
= 3.14;
339 nproperties
[3].property_name
= CORBA::string_dup ("float_property");
340 nproperties
[3].property_value
<<= f
;
342 // Prepare a String and "define" that in the PropertySet.
343 CORBA::String_var
strvar (CORBA::string_dup ("Test_String"));
344 anyval
<<= strvar
.in ();
345 nproperties
[4].property_name
= CORBA::string_dup ("string_property");
346 nproperties
[4].property_value
<<= strvar
.in ();
348 // Define this sequence of properties now.
349 property_set_
.define_properties (nproperties
);
354 // Delete all the properties.
356 TAO_PropertySet_Tester::test_delete_all_properties ()
358 // Deleting all the properties
359 ACE_DEBUG ((LM_DEBUG
,
360 "\nChecking delete_all_properties\n"));
361 int ret
= property_set_
.delete_all_properties ();
363 ACE_DEBUG ((LM_DEBUG
,
364 "All properties deleted, I guess\n"));
366 ACE_DEBUG ((LM_DEBUG
,
367 "delete_all_properties failed\n"));
371 // Constructor. To make names iterator from the property set object.
372 TAO_PropertyNamesIterator_Tester::TAO_PropertyNamesIterator_Tester (TAO_PropertySet_Tester
&propertyset_tester
)
373 : iterator_ (propertyset_tester
.property_set_
)
378 TAO_PropertyNamesIterator_Tester::~TAO_PropertyNamesIterator_Tester ()
382 // Test next one method. Iterate thru all the names in the
383 // PropertySet and print them out.
385 TAO_PropertyNamesIterator_Tester::test_next_one ()
387 CORBA::String_var strvar
;
388 ACE_DEBUG ((LM_DEBUG
,
389 "\nTesting next_one of NamesIterator, Iterating thru names.\n"));
390 // Let us iterate, now.
391 int ret
= iterator_
.next_one (strvar
.out ());
394 ACE_DEBUG ((LM_DEBUG
, "Str : %s\n", strvar
.in ()));
395 ret
= iterator_
.next_one (strvar
.out ());
400 // Reset the names iterator.
402 TAO_PropertyNamesIterator_Tester::test_reset ()
404 ACE_DEBUG ((LM_DEBUG
,
405 "Resetting (reset ()) the NamesIterator."));
410 // Test the next_n method. Get the next n names and print them all.
412 TAO_PropertyNamesIterator_Tester::test_next_n (size_t n
)
414 CosPropertyService::PropertyNames_var pnames_var
;
415 ACE_DEBUG ((LM_DEBUG
,
416 "Checking next_n (), next %d\n",
418 int ret
= iterator_
.next_n (n
, pnames_var
.out ());
421 // Return if no more items in the iterator.
422 ACE_DEBUG ((LM_DEBUG
,
423 "Iterator has no more items\n"));
426 for (size_t i
= 0; i
< pnames_var
.in ().length (); i
++)
427 ACE_DEBUG ((LM_DEBUG
,
429 (const char *) pnames_var
[i
]));
434 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
438 CORBA::ORB_var orb_var
= CORBA::ORB_init (argc
,
442 // = Checking PropertySet interface.
444 ACE_DEBUG ((LM_DEBUG
,
445 "\nTAO_PropertySet Testing\n"));
446 TAO_PropertySet_Tester propertyset_tester
;
448 // Checking define_property. define a char, a short,a long, a float
450 propertyset_tester
.test_define_property ();
452 // Test the number of properties and print it out.
453 propertyset_tester
.test_get_number_of_properties ();
455 // Test delete property. Delete "string_property"
456 propertyset_tester
.test_delete_property ("string_property");
458 // Test the number of properties and print it out.
459 propertyset_tester
.test_get_number_of_properties ();
461 // Test delete_properties. Delete char, short, long and float.
462 propertyset_tester
.test_delete_properties ();
464 // Test the number of properties and print it out.
465 propertyset_tester
.test_get_number_of_properties ();
467 // Define a sequence of properties. char, short, long, float and
469 propertyset_tester
.test_define_properties ();
471 // Test the number of properties and print it out.
472 propertyset_tester
.test_get_number_of_properties ();
474 // Checking get_property_value. get the value of short and string.
475 propertyset_tester
.test_get_property_value ();
477 // Checking delete_all_properties.
478 propertyset_tester
.test_delete_all_properties ();
480 // Test the number of properties and print it out.
481 propertyset_tester
.test_get_number_of_properties ();
483 // Define a sequence of properties. char, short, long, float and
485 propertyset_tester
.test_define_properties ();
487 // Test the number of properties and print it out.
488 propertyset_tester
.test_get_number_of_properties ();
490 // = Checking the PropertyNamesIterator interface.
492 ACE_DEBUG ((LM_DEBUG
,
493 "\nTAO_PropertyNamesIterator Testing\n"));
495 // Construct the names iterator from the PropertySet object.
496 TAO_PropertyNamesIterator_Tester
names_iterator_tester (propertyset_tester
);
498 // Checking next_one. Iterate thru the property names.
499 names_iterator_tester
.test_next_one ();
501 // Checking the reset () method.
502 names_iterator_tester
.test_reset ();
504 // Iterating again thru the property names.
505 names_iterator_tester
.test_next_one ();
508 names_iterator_tester
.test_reset ();
510 // Checking next_n. Prints out all the names it has got.
511 names_iterator_tester
.test_next_n (6);
513 // Try next_n without resetting.
514 names_iterator_tester
.test_next_n (6);
516 catch (const CORBA::SystemException
& sysex
)
518 .print_exception ("System Exception");
521 catch (const CORBA::UserException
& userex
)
523 .print_exception ("User Exception");