2 //=============================================================================
6 * Test client for the Property Service.
8 * @author Alexander Babu Arulanthu <alex@cs.wustl.edu>
10 //=============================================================================
14 #include "tao/debug.h"
22 Client::init (int argc
,
26 manager_
.init (argc
, argv
);
27 CORBA::ORB_var orb
= manager_
.orb();
28 // Initialize the naming services
29 if (my_name_client_
.init (orb
.in ()) != 0)
30 ACE_ERROR_RETURN ((LM_ERROR
,
31 " (%P|%t) Unable to initialize "
32 "the TAO_Naming_Client.\n"),
35 // Bind PropertySetDef Object.
37 CosNaming::Name
propsetdef_name (1);
38 propsetdef_name
.length (1);
39 propsetdef_name
[0].id
= CORBA::string_dup ("PropertySetDef");
40 CORBA::Object_var propsetdef_obj
= my_name_client_
->resolve (propsetdef_name
);
42 this->propsetdef_
= CosPropertyService::PropertySetDef::_narrow (propsetdef_obj
.in ());
44 if (CORBA::is_nil (this->propsetdef_
.in ()))
45 ACE_ERROR_RETURN ((LM_ERROR
,
46 "Could not resolve propsetdef in Naming server"),
52 // Testing the methods of the property service.
55 Client::property_tester ()
57 // = Testing PropertySet & Iterators.
59 // Testing define_property () of PropertySet interface.
60 this->test_define_property ();
62 // Test the number of properties.
63 this->test_get_number_of_properties ();
65 // Testing get_all_property_names.
66 this->test_get_all_property_names ();
68 // Test get_property_value.
69 this->test_get_property_value ();
71 // Testing delete property.
72 this->test_delete_property ("no_property");
74 // Testing get_properties.
75 this->test_get_properties ();
77 // Testing delete_properties.
78 this->test_delete_properties ();
80 // Test the number of properties.
81 this->test_get_number_of_properties ();
83 // Testing define_properties.
84 this->test_define_properties ();
86 // Test the number of properties.
87 this->test_get_number_of_properties ();
89 // Testing get_all_property_names.
90 this->test_get_all_property_names ();
92 // Testing get_all_properties.
93 this->test_get_all_properties ();
95 // = Testing PropertySetDef & Iterators.
97 // Testing define_property_with_mode.
98 this->test_define_property_with_mode ();
103 // Testing define_property.
106 Client::test_define_property ()
110 // Prepare a char and "define" that in the PropertySet.
111 CORBA::Char ch
= '#';
112 anyval
<<= CORBA::Any::from_char (ch
);
114 anyval
>>= CORBA::Any::to_char (ch
);
116 this->propsetdef_
->define_property ("char_property",
119 // Prepare a Short and "define" that in the PropertySet.
125 propsetdef_
->define_property ("short_property",
128 // Prepare a Long and "define" that in the PropertySet.
129 CORBA::Long l
= 931232;
133 CORBA::Any
newany(anyval
);
134 propsetdef_
->define_property ("long_property",
137 // Prepare a Float and "define" that in the PropertySet.
138 CORBA::Float f
= 3.14F
;
143 propsetdef_
->define_property ("float_property",
147 // Prepare a String and "define" that in the PropertySet.
148 CORBA::String_var
strvar (CORBA::string_dup ("Test_String"));
149 anyval
<<= strvar
.in ();
152 propsetdef_
->define_property ("string_property",
159 // Testing get_all_property_names of the PropertySet.
162 Client::test_get_all_property_names ()
165 CORBA::ULong num_of_properties
=
166 propsetdef_
->get_number_of_properties ();
168 // Get half on the names and half of on the iterator.
169 CORBA::ULong how_many
= num_of_properties
/ 2;
171 // The extra ptr's and out's required to avoind SunnCC's warning
172 // when foo.out () is passed to a function.
173 CosPropertyService::PropertyNames_var names_var
;
174 CosPropertyService::PropertyNames
*names_ptr
= 0;
175 CosPropertyService::PropertyNames_out
names_out (names_ptr
);
177 CosPropertyService::PropertyNamesIterator_var iterator_var
;
178 CosPropertyService::PropertyNamesIterator_ptr iterator_ptr
;
179 CosPropertyService::PropertyNamesIterator_out
iterator_out (iterator_ptr
);
181 propsetdef_
->get_all_property_names (how_many
,
185 // Get the values back to var.
186 names_var
= names_out
.ptr ();
187 iterator_var
= iterator_out
.ptr ();
189 // Print out the names in the names-sequence.
190 if (TAO_debug_level
> 0)
192 if (names_var
.ptr () != 0)
194 CORBA::ULong len
= names_var
->length ();
196 for (CORBA::ULong ni
= 0; ni
< len
; ni
++)
197 ACE_DEBUG ((LM_DEBUG
,
199 (const char *) names_var
[ni
]));
202 // Iterate thru and print out the names in the iterator, if any.
203 if (iterator_var
.ptr () != 0)
205 // Helper variables to stop the SunCC warnings on on foo.out
207 CosPropertyService::PropertyName name_ptr
= 0;
208 CosPropertyService::PropertyName_out
name_out (name_ptr
);
210 // Call the function.
211 CORBA::Boolean next_one_result
= iterator_var
->next_one (name_out
);
213 // Get the values back on a _var variable.
214 CosPropertyService::PropertyName_var name_var
= name_out
.ptr ();
216 while (next_one_result
== 1)
218 ACE_DEBUG ((LM_DEBUG
, "%s\n", name_var
.in ()));
220 // Call the function to iterate again.
221 next_one_result
= iterator_var
->next_one (name_out
);
223 // Get the values back on a _var variable.
224 name_var
= name_out
.ptr ();
232 // Test get_properties. Give a sequence of names and get all their
236 Client::test_get_properties ()
238 // Get float_property, string_property and no_property. If return
239 // value is false and type is tc_void then that name is not there in
241 CosPropertyService::PropertyNames_var names
;
242 CosPropertyService::PropertyNames
*names_ptr
;
244 ACE_NEW_RETURN (names_ptr
,
245 CosPropertyService::PropertyNames
,
250 names
[0u] = CORBA::string_dup ("float_property");
251 //names [1] = CORBA::string_dup ("string_property");
252 names
[1u] = CORBA::string_dup ("long_property");
253 names
[2u] = CORBA::string_dup ("char_property");
254 //names [2] = CORBA::string_dup ("no_property");
257 CosPropertyService::Properties
*properties_ptr
= 0;
258 CosPropertyService::Properties_out
properties_out (properties_ptr
);
260 // Get the properties.
261 CORBA::Boolean return_val
= propsetdef_
->get_properties (names
.in (),
263 ACE_UNUSED_ARG (return_val
);
265 // Get the value to the _var.
266 CosPropertyService::Properties_var properties
= properties_out
.ptr ();
268 if (TAO_debug_level
> 0)
270 if (properties
.ptr () != 0)
272 // Go thru the properties and print them out, if they are not
273 // _tc_void typed values.
274 CORBA::ULong len
= properties
->length ();
276 for (CORBA::ULong pi
= 0; pi
< len
; pi
++)
279 ACE_DEBUG ((LM_DEBUG
,
281 (const char *) properties
[pi
].property_name
.in ()));
284 CORBA::Char char_val
;
285 CORBA::Long long_val
;
286 CORBA::ULong ulong_val
;
287 CORBA::Float float_val
;
288 CORBA::Double double_val
;
289 const char * string_val
;
291 if (properties
[pi
].property_value
>>=
292 CORBA::Any::to_char (char_val
))
294 ACE_DEBUG ((LM_DEBUG
, "%c\n", char_val
));
296 else if (properties
[pi
].property_value
>>= long_val
)
298 ACE_DEBUG ((LM_DEBUG
, "%d\n", long_val
));
300 else if (properties
[pi
].property_value
>>= ulong_val
)
302 ACE_DEBUG ((LM_DEBUG
, "%ld\n", ulong_val
));
304 else if (properties
[pi
].property_value
>>= float_val
)
306 ACE_DEBUG ((LM_DEBUG
, "%f\n", long_val
));
308 else if (properties
[pi
].property_value
>>= double_val
)
310 ACE_DEBUG ((LM_DEBUG
, "%f\n", double_val
));
312 else if (properties
[pi
].property_value
>>= string_val
)
314 ACE_DEBUG ((LM_DEBUG
, "%s\n", string_val
));
322 // Testing, get_number_of_properties.
325 Client::test_get_number_of_properties ()
327 CORBA::ULong nproperties
= this->propsetdef_
->get_number_of_properties ();
329 if (TAO_debug_level
> 0)
331 ACE_DEBUG ((LM_DEBUG
,
332 "\nNumber of props : %d\n",
338 // Test delete_property.
341 Client::test_delete_property (const char *property_name
)
345 CORBA::String_var
property_name_var (property_name
);
347 this->propsetdef_
->delete_property (property_name_var
.in ());
349 catch (const CORBA::UserException
&)
351 // For no property, it is ok to get the user exception.
354 catch (const CORBA::Exception
& ex
)
356 ex
._tao_print_exception ("Not an user exception");
363 // Test delete_properties.
364 // Make a sequence of property names and delete them from the
365 // PropertySet. Deleting char, short, long, float and string
369 Client::test_delete_properties ()
371 CosPropertyService::PropertyNames prop_names
;
372 prop_names
.length (3);
373 prop_names
[0] = CORBA::string_dup ("char_property");
374 prop_names
[1] = CORBA::string_dup ("short_property");
375 prop_names
[2] = CORBA::string_dup ("long_property");
376 // prop_names [3] = CORBA::string_dup ("no_property");
377 this->propsetdef_
->delete_properties (prop_names
);
382 // Defines a sequnce of properties containing, char, short, long,
383 // float in the property set.
386 Client::test_define_properties ()
388 CosPropertyService::Properties nproperties
;
389 nproperties
.length (4);
391 // Prepare a char and "define" that in the PropertySet.
392 CORBA::Char ch
= '#';
393 anyval
<<= CORBA::Any::from_char (ch
);
395 anyval
>>= CORBA::Any::to_char (ch
);
396 nproperties
[0].property_name
= CORBA::string_dup ("char_property");
397 nproperties
[0].property_value
<<= CORBA::Any::from_char (ch
);
399 // Prepare a Short and "define" that in the PropertySet.
404 nproperties
[1].property_name
= CORBA::string_dup ("short_property");
405 nproperties
[1].property_value
<<= s
;
407 // Prepare a Long and "define" that in the PropertySet.
408 CORBA::Long l
= 931232;
412 nproperties
[2].property_name
= CORBA::string_dup ("long_property");
413 nproperties
[2].property_value
<<= l
;
415 // Prepare a Float and "define" that in the PropertySet.
416 CORBA::Float f
= 3.14F
;
420 nproperties
[3].property_name
= CORBA::string_dup ("float_property");
421 nproperties
[3].property_value
<<= f
;
423 // Define this sequence of properties now.
424 this->propsetdef_
->define_properties (nproperties
);
429 // Test get_all_properties.
432 Client::test_get_all_properties ()
434 // Get the number of current properties.
435 CORBA::ULong num_of_properties
=
436 this->propsetdef_
->get_number_of_properties ();
437 ACE_UNUSED_ARG (num_of_properties
);
439 // Get half on the properties and half of on the iterator.
440 CORBA::ULong how_many
= 1;
442 // Helper variables to avoid SunCC warnings.
443 CosPropertyService::Properties
*properties_ptr
= 0;
444 CosPropertyService::Properties_out
properties_out (properties_ptr
);
445 CosPropertyService::PropertiesIterator_ptr iterator_ptr
= 0;
446 CosPropertyService::PropertiesIterator_out
iterator_out (iterator_ptr
);
448 propsetdef_
->get_all_properties (how_many
,
452 // Get these values to the _var's.
453 CosPropertyService::Properties_var properties
= properties_out
.ptr ();
454 CosPropertyService::PropertiesIterator_var iterator
= iterator_out
.ptr ();
456 // Print out the properties now.
457 if (TAO_debug_level
> 0)
459 if (properties
.ptr () != 0)
461 CORBA::ULong len
= properties
->length ();
463 for (CORBA::ULong pi
= 0; pi
< len
; pi
++)
465 // Print the property_name.
466 ACE_DEBUG ((LM_DEBUG
,
468 properties
[pi
].property_name
.in ()));
470 // Print the value if type is not tk_void.
471 if (properties
[pi
].property_value
.type () == CORBA::_tc_void
)
472 ACE_DEBUG ((LM_DEBUG
,"Void\n"));
474 if (properties
[pi
].property_value
.type () == CORBA::_tc_float
)
477 properties
[pi
].property_value
>>= f
;
478 ACE_DEBUG ((LM_DEBUG
,"%f\n", f
));
481 if (properties
[pi
].property_value
.type () == CORBA::_tc_string
)
484 properties
[pi
].property_value
>>= str
;
485 ACE_DEBUG ((LM_DEBUG
,"%s\n", str
));
488 if (properties
[pi
].property_value
.type () == CORBA::_tc_long
)
491 properties
[pi
].property_value
>>= l
;
492 ACE_DEBUG ((LM_DEBUG
,"%d\n", l
));
497 // Pass thru the iterator.
498 if (iterator
.ptr () != 0)
500 // Helper variables to avoid warnings with .out () in SunCC.
501 CosPropertyService::Property
* property_ptr
= 0;
502 CosPropertyService::Property_out
property_out (property_ptr
);
504 // Call the function.
505 CORBA::Boolean next_one_result
= iterator
->next_one (property_out
);
507 // Get the value to the _var variable.
508 CosPropertyService::Property_var property
= property_out
.ptr ();
510 while (next_one_result
!= 0)
512 ACE_DEBUG ((LM_DEBUG
,
514 property
->property_name
.in ()));
516 // Print the property_value.
517 if (property
->property_value
.type () == CORBA::_tc_char
)
520 property
->property_value
>>= CORBA::Any::to_char (c
);
521 ACE_DEBUG ((LM_DEBUG
,"%c\n", c
));
524 if (property
->property_value
.type () == CORBA::_tc_short
)
527 property
->property_value
>>= s
;
528 ACE_DEBUG ((LM_DEBUG
,"%d\n", s
));
531 if (property
->property_value
.type () == CORBA::_tc_float
)
534 property
->property_value
>>= f
;
535 ACE_DEBUG ((LM_DEBUG
,"%f\n", f
));
538 if (property
->property_value
.type () == CORBA::_tc_string
)
541 property
->property_value
>>= str
;
542 ACE_DEBUG ((LM_DEBUG
,"%s\n", str
));
545 if (property
->property_value
.type () == CORBA::_tc_long
)
548 property
->property_value
>>= l
;
549 ACE_DEBUG ((LM_DEBUG
,"%d\n", l
));
552 // Call the function for the next iteraton.
553 next_one_result
= iterator
->next_one (property_out
);
555 // Get the value to the _var variable.
556 property
= property_out
.ptr ();
563 // Testing define property with mode.
564 // Defines char, short, long and float properties with different modes.
566 Client::test_define_property_with_mode ()
570 // Prepare a char and "define" that in the PropertySet.
571 CORBA::Char ch
= '#';
572 anyval
<<= CORBA::Any::from_char (ch
);
574 anyval
>>= CORBA::Any::to_char (ch
);
576 this->propsetdef_
->define_property_with_mode ("char_property",
578 CosPropertyService::normal
);
580 // Prepare a Short and "define" that in the PropertySet.
586 propsetdef_
->define_property_with_mode ("short_property",
588 CosPropertyService::read_only
);
590 // Prepare a Long and "define" that in the PropertySet.
591 CORBA::Long l
= 931232;
595 CORBA::Any
newany(anyval
);
596 propsetdef_
->define_property_with_mode ("long_property",
598 CosPropertyService::fixed_normal
);
601 // Prepare a Float and "define" that in the PropertySet.
602 CORBA::Float f
= 3.14F
;
606 propsetdef_
->define_property_with_mode ("float_property",
608 CosPropertyService::fixed_readonly
);
610 // Prepare a String and "define" that in the PropertySet.
611 CORBA::String_var
strvar (CORBA::string_dup ("Test_String"));
612 anyval
<<= strvar
.in ();
616 propsetdef_
->define_property ("string_property",
623 Client::test_get_property_value ()
627 // Get the ior property.
628 CORBA::Any_var any_ptr
= this->propsetdef_
->get_property_value ("PropertySetDef_IOR");
630 // Check whether the IOR is fine.
631 CORBA::Object_var propsetdef_object
;
632 (*any_ptr
) >>= CORBA::Any::to_object (propsetdef_object
.out ());
634 CosPropertyService::PropertySetDef_var propsetdef
=
635 CosPropertyService::PropertySetDef::_narrow (propsetdef_object
.in ());
637 if (CORBA::is_nil (propsetdef
.in ()))
638 ACE_ERROR_RETURN ((LM_ERROR
,
639 "invalid object reference\n"),
642 catch (const CORBA::Exception
& ex
)
644 ex
._tao_print_exception ("get_property_value");
651 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
657 if (client
.init (argc
, argv
) == -1)
661 int ret
= client
.property_tester ();
663 ACE_DEBUG ((LM_DEBUG
, "Test failed\n"));
665 ACE_DEBUG ((LM_DEBUG
, "Test succeeded\n"));
667 catch (const CORBA::Exception
& ex
)
669 ex
._tao_print_exception ("PropertyService Test : client");