Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Property / main.cpp
blobcfa6d7e40bd8d7731a7717200ee8679e4980e5e4
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"
20 class TAO_PropertySet_Tester
22 // = TITLE
23 // The testing code for the PropertySet interface are grouped
24 // under the functions of this class.
26 // = DESCRIPTION
27 // Go thru the functions to understand the usage of the various
28 // methods of the PropertySet interaface.
29 public:
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 ();
35 // Constructor.
37 ~TAO_PropertySet_Tester ();
38 // Destructor.
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
55 // out.
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
65 // and a string.
67 private:
68 TAO_PropertySet property_set_;
69 // The PropertySet.
72 class TAO_PropertyNamesIterator_Tester
74 // = TITLE
75 // The testing code for the PropertyNamesIterator interface are grouped
76 // under the functions of this class.
78 // = DESCRIPTION
79 // Go thru the functions to understand the usage of the various
80 // methods of the PropertyNamesIterator interaface.
81 public:
82 TAO_PropertyNamesIterator_Tester (TAO_PropertySet_Tester &propertyset_tester);
83 // Constructor. To make names iterator from the property set object.
85 ~TAO_PropertyNamesIterator_Tester ();
86 // Destructor.
88 int test_next_one ();
89 // Test next one method. Iterate thru all the names in the
90 // PropertySet and print them out.
92 int test_reset ();
93 // Test the reset method.
95 int test_next_n (size_t n);
96 // Test the next_n method.
97 private:
98 TAO_PropertyNamesIterator iterator_;
99 // Our names iterator.
103 // Constructor.
104 TAO_PropertySet_Tester::TAO_PropertySet_Tester ()
108 // Destructor.
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"));
120 CORBA::Any anyval;
122 // Prepare a char and "define" that in the PropertySet.
123 CORBA::Char ch = '#';
124 anyval <<= from_char (ch);
125 ch = '*';
126 anyval >>= to_char (ch);
127 ACE_DEBUG ((LM_DEBUG,
128 "Main : Char ch = %c\n",
129 ch));
130 property_set_.define_property ("char_property",
131 anyval);
133 // Prepare a Short and "define" that in the PropertySet.
134 CORBA::Short s = 3;
135 anyval <<= s;
136 s = 7;
137 anyval >>= s;
138 ACE_DEBUG ((LM_DEBUG,
139 "Main : Short s = %d\n",
140 s));
141 property_set_.define_property ("short_property",
142 anyval);
145 // Prepare a Long and "define" that in the PropertySet.
146 CORBA::Long l = 931232;
147 anyval <<= l;
148 l = 931233;
149 anyval >>= l;
150 ACE_DEBUG ((LM_DEBUG,
151 "Main : Long l = %d\n",
152 l));
153 CORBA::Any newany(anyval);
155 property_set_.define_property ("long_property",
156 anyval);
158 // Prepare a Float and "define" that in the PropertySet.
159 CORBA::Float f = 3.14;
160 anyval <<= f;
161 f = 4.14;
162 anyval >>= f;
163 ACE_DEBUG ((LM_DEBUG,
164 "Main : Float f = %f\n",
165 f));
166 property_set_.define_property ("float_property",
167 anyval);
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;
175 anyval >>= newstr;
176 ACE_DEBUG ((LM_DEBUG,
177 "Main: String : %s, From any : %s\n",
178 strvar.in (),
179 newstr));
180 property_set_.define_property ("string_property",
181 anyval);
183 return 0;
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 ()));
194 return 0;
197 // Testing the delete_property. Delets property, with the given name,
198 // if that exsists.
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);
205 return 0;
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.
219 if (anyptr != 0)
221 CORBA::Short s;
222 *anyptr >>= s;
223 ACE_DEBUG ((LM_DEBUG,
224 "Short %d\n",
225 s));
227 else
228 ACE_DEBUG ((LM_DEBUG,
229 "Short property not found\n"));
230 // Get the string.
231 anyptr = property_set_.get_property_value ("string_property");
232 if (anyptr != 0)
234 CORBA::String str;
235 *anyptr >>= str;
236 ACE_DEBUG ((LM_DEBUG,
237 "Str %s\n", str));
239 else
240 ACE_DEBUG ((LM_DEBUG,
241 "string_property not found\n"));
242 return 0;
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"));
256 else
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"));
262 else
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"));
268 else
269 ACE_DEBUG ((LM_DEBUG,
270 "char_property defined\n"));
272 return 0;
275 // Make a sequence of property names and delete them from the
276 // PropertySet. Deleting char, short, long, float and string
277 // properties.
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);
295 return 0;
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"));
305 // TAO_TRY
306 // {
307 CosPropertyService::Properties nproperties;
308 nproperties.length (5);
309 CORBA::Any anyval;
310 // Prepare a char and "define" that in the PropertySet.
311 CORBA::Char ch = '#';
312 anyval <<= from_char (ch);
313 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.
319 CORBA::Short s = 3;
320 anyval <<= s;
321 s = 7;
322 anyval >>= s;
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;
328 anyval <<= l;
329 l = 931233;
330 anyval >>= l;
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;
336 anyval <<= f;
337 f = 4.14;
338 anyval >>= f;
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);
351 return 0;
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 ();
362 if (ret == 1)
363 ACE_DEBUG ((LM_DEBUG,
364 "All properties deleted, I guess\n"));
365 else
366 ACE_DEBUG ((LM_DEBUG,
367 "delete_all_properties failed\n"));
368 return 0;
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_)
377 // Destructor.
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 ());
392 while (ret != 0)
394 ACE_DEBUG ((LM_DEBUG, "Str : %s\n", strvar.in ()));
395 ret = iterator_.next_one (strvar.out ());
397 return 0;
400 // Reset the names iterator.
402 TAO_PropertyNamesIterator_Tester::test_reset ()
404 ACE_DEBUG ((LM_DEBUG,
405 "Resetting (reset ()) the NamesIterator."));
406 iterator_.reset ();
407 return 0;
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",
417 n));
418 int ret = iterator_.next_n (n, pnames_var.out ());
419 if (ret == 0)
421 // Return if no more items in the iterator.
422 ACE_DEBUG ((LM_DEBUG,
423 "Iterator has no more items\n"));
424 return 0;
426 for (size_t i = 0; i < pnames_var.in ().length (); i++)
427 ACE_DEBUG ((LM_DEBUG,
428 "str %s\n",
429 (const char *) pnames_var[i]));
430 return 0;
434 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
438 CORBA::ORB_var orb_var = CORBA::ORB_init (argc,
439 argv,
440 "internet");
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
449 // and a string.
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
468 // string.
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
484 // string.
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 ();
507 // Reset again.
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");
519 return -1;
521 catch (const CORBA::UserException& userex)
523 .print_exception ("User Exception");
524 return -1;
526 return 0;