Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Param_Test / ub_string.cpp
blob75c70bd84b8aad8a2c8f4e3032088cf807159848
2 //=============================================================================
3 /**
4 * @file ub_string.cpp
6 * tests unbounded strings
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
13 #include "helper.h"
14 #include "ub_string.h"
16 // ************************************************************************
17 // Test_Unbounded_String
18 // ************************************************************************
20 Test_Unbounded_String::Test_Unbounded_String ()
21 : opname_ (CORBA::string_dup ("test_unbounded_string")),
22 in_ (0),
23 inout_ (0),
24 out_ (0),
25 ret_ (0)
29 Test_Unbounded_String::~Test_Unbounded_String ()
31 CORBA::string_free (this->opname_);
32 CORBA::string_free (this->in_);
33 CORBA::string_free (this->inout_);
34 CORBA::string_free (this->out_);
35 CORBA::string_free (this->ret_);
36 this->opname_ = 0;
37 this->in_ = 0;
38 this->inout_ = 0;
39 this->out_ = 0;
40 this->ret_ = 0;
43 const char *
44 Test_Unbounded_String::opname () const
46 return this->opname_;
49 void
50 Test_Unbounded_String::dii_req_invoke (CORBA::Request *req)
52 req->add_in_arg ("s1") <<= this->in_;
53 req->add_inout_arg ("s2") <<= this->inout_;
54 req->add_out_arg ("s3") <<= this->out_;
56 // The Any arg manages its memory but this class member does not.
57 CORBA::string_free (this->inout_);
59 req->set_return_type (CORBA::_tc_string);
61 req->invoke ();
63 const char *tmp;
64 req->return_value () >>= tmp;
65 this->ret_ = CORBA::string_dup (tmp);
67 CORBA::NamedValue_ptr o2 =
68 req->arguments ()->item (1);
69 *o2->value () >>= tmp;
70 this->inout_ = CORBA::string_dup (tmp);
72 CORBA::NamedValue_ptr o3 =
73 req->arguments ()->item (2);
74 *o3->value () >>= tmp;
75 this->out_ = CORBA::string_dup (tmp);
78 int
79 Test_Unbounded_String::init_parameters (Param_Test_ptr)
81 Generator *gen = GENERATOR::instance (); // value generator
84 // release any previously occupied values
85 CORBA::string_free (this->in_);
86 CORBA::string_free (this->inout_);
87 CORBA::string_free (this->out_);
88 CORBA::string_free (this->ret_);
89 this->in_ = 0;
90 this->inout_ = 0;
91 this->out_ = 0;
92 this->ret_ = 0;
94 this->in_ = gen->gen_string ();
95 this->inout_ = CORBA::string_dup (this->in_);
96 return 0;
99 int
100 Test_Unbounded_String::reset_parameters ()
102 // release any previously occupied values
103 CORBA::string_free (this->inout_);
104 CORBA::string_free (this->out_);
105 CORBA::string_free (this->ret_);
106 this->inout_ = 0;
107 this->out_ = 0;
108 this->ret_ = 0;
110 this->inout_ = CORBA::string_dup (this->in_);
111 return 0;
115 Test_Unbounded_String::run_sii_test (Param_Test_ptr objref)
119 CORBA::String_out str_out (this->out_);
121 this->ret_ = objref->test_unbounded_string (this->in_,
122 this->inout_,
123 str_out);
125 return 0;
127 catch (const CORBA::Exception& ex)
129 ex._tao_print_exception ("Test_Unbounded_String::run_sii_test\n");
131 return -1;
134 CORBA::Boolean
135 Test_Unbounded_String::check_validity ()
137 CORBA::ULong len = ACE_OS::strlen (this->in_);
139 if (!ACE_OS::strcmp (this->in_, this->out_) &&
140 !ACE_OS::strcmp (this->in_, this->ret_) &&
141 ACE_OS::strlen (this->inout_) == 2*len &&
142 !ACE_OS::strncmp (this->in_, this->inout_, len) &&
143 !ACE_OS::strncmp (this->in_, &this->inout_[len], len))
144 return 1;
146 return 0; // otherwise
149 CORBA::Boolean
150 Test_Unbounded_String::check_validity (CORBA::Request_ptr )
152 // No need to retrieve anything because, for all the args and
153 // the return, we provided the memory and we own it.
154 return this->check_validity ();
157 void
158 Test_Unbounded_String::print_values ()
160 ACE_DEBUG ((LM_DEBUG,
161 "\n=*=*=*=*=*=*\n"
162 "in with len (%d) = %C\n"
163 "inout with len (%d) = %C\n"
164 "out with len (%d) = %C\n"
165 "ret with len (%d) = %C\n"
166 "\n=*=*=*=*=*=*\n",
167 (this->in_ ? ACE_OS::strlen (this->in_):0),
168 (this->in_ ? this->in_:"<nul string>"),
169 (this->inout_ ? ACE_OS::strlen (this->inout_):0),
170 (this->inout_ ? this->inout_:"<nul string>"),
171 (this->out_ ? ACE_OS::strlen (this->out_):0),
172 (this->out_ ? this->out_:"<nul string>"),
173 (this->ret_ ? ACE_OS::strlen (this->ret_):0),
174 (this->ret_ ? this->ret_:"<nul string>")));