Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Param_Test / bd_string.cpp
blob3b1ac0fbada188a5ce1cc512404c29b424b4799d
2 //=============================================================================
3 /**
4 * @file bd_string.cpp
6 * tests bounded strings
8 * @author Carlos O'Ryan
9 */
10 //=============================================================================
13 #include "helper.h"
14 #include "bd_string.h"
16 // ************************************************************************
17 // Test_Bounded_String
18 // ************************************************************************
20 Test_Bounded_String::Test_Bounded_String ()
21 : opname_ (CORBA::string_dup ("test_bounded_string")),
22 in_ (0),
23 inout_ (0),
24 out_ (0),
25 ret_ (0)
29 Test_Bounded_String::~Test_Bounded_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_Bounded_String::opname () const
46 return this->opname_;
49 void
50 Test_Bounded_String::dii_req_invoke (CORBA::Request *req)
52 req->add_in_arg ("s1") <<= CORBA::Any::from_string (this->in_, 128);
53 req->add_inout_arg ("s2") <<= CORBA::Any::from_string (this->inout_, 128);
54 req->add_out_arg ("s3") <<= CORBA::Any::from_string (this->out_, 128);
56 // The Any arg manages its memory but this class member does not.
57 CORBA::string_free (this->inout_);
59 req->set_return_type (Param_Test::_tc_short_string);
61 req->invoke ();
63 char *tmp;
64 req->return_value () >>= CORBA::Any::to_string (tmp, 128);
65 this->ret_ = CORBA::string_dup (tmp);
67 CORBA::NamedValue_ptr arg2 =
68 req->arguments ()->item (1);
69 *arg2->value () >>= CORBA::Any::to_string (tmp, 128);
70 this->inout_ = CORBA::string_dup (tmp);
72 CORBA::NamedValue_ptr arg3 =
73 req->arguments ()->item (2);
74 *arg3->value () >>= CORBA::Any::to_string (tmp, 128);
75 this->out_ = CORBA::string_dup (tmp);
78 int
79 Test_Bounded_String::init_parameters (Param_Test_ptr)
81 Generator *gen = GENERATOR::instance (); // value generator
83 // release any previously occupied values
84 CORBA::string_free (this->in_);
85 CORBA::string_free (this->inout_);
86 CORBA::string_free (this->out_);
87 CORBA::string_free (this->ret_);
88 this->in_ = 0;
89 this->inout_ = 0;
90 this->out_ = 0;
91 this->ret_ = 0;
93 this->in_ = gen->gen_string (32);
94 this->inout_ = CORBA::string_dup (this->in_);
95 return 0;
98 int
99 Test_Bounded_String::reset_parameters ()
101 // release any previously occupied values
102 CORBA::string_free (this->inout_);
103 CORBA::string_free (this->out_);
104 CORBA::string_free (this->ret_);
105 this->inout_ = 0;
106 this->out_ = 0;
107 this->ret_ = 0;
109 this->inout_ = CORBA::string_dup (this->in_);
110 return 0;
114 Test_Bounded_String::run_sii_test (Param_Test_ptr objref)
118 CORBA::String_out str_out (this->out_);
120 this->ret_ = objref->test_bounded_string (this->in_,
121 this->inout_,
122 str_out);
124 return 0;
126 catch (const CORBA::Exception& ex)
128 ex._tao_print_exception ("Test_Bounded_String::run_sii_test\n");
130 return -1;
133 CORBA::Boolean
134 Test_Bounded_String::check_validity ()
136 CORBA::ULong len = ACE_OS::strlen (this->in_);
138 if (!ACE_OS::strcmp (this->in_, this->out_) &&
139 !ACE_OS::strcmp (this->in_, this->ret_) &&
140 ACE_OS::strlen (this->inout_) == 2*len &&
141 !ACE_OS::strncmp (this->in_, this->inout_, len) &&
142 !ACE_OS::strncmp (this->in_, &this->inout_[len], len))
143 return 1;
145 return 0; // otherwise
148 CORBA::Boolean
149 Test_Bounded_String::check_validity (CORBA::Request_ptr)
151 // No need to retrieve anything because, for all the args and
152 // the return, we provided the memory and we own it.
153 return this->check_validity ();
156 void
157 Test_Bounded_String::print_values ()
159 ACE_DEBUG ((LM_DEBUG,
160 "\n=*=*=*=*=*=*\n"
161 "in with len (%d) = %C\n"
162 "inout with len (%d) = %C\n"
163 "out with len (%d) = %C\n"
164 "ret with len (%d) = %C\n"
165 "\n=*=*=*=*=*=*\n",
166 (this->in_ ? ACE_OS::strlen (this->in_):0),
167 (this->in_ ? this->in_:"<nul string>"),
168 (this->inout_ ? ACE_OS::strlen (this->inout_):0),
169 (this->inout_ ? this->inout_:"<nul string>"),
170 (this->out_ ? ACE_OS::strlen (this->out_):0),
171 (this->out_ ? this->out_:"<nul string>"),
172 (this->ret_ ? ACE_OS::strlen (this->ret_):0),
173 (this->ret_ ? this->ret_:"<nul string>")));