Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Param_Test / bd_wstring.cpp
blobafed5732f774daba3026a0a3dddd3a0e7ddb7340
2 //=============================================================================
3 /**
4 * @file bd_wstring.cpp
6 * tests bounded wide strings
8 * @author Jeff Parsons
9 */
10 //=============================================================================
13 #include "helper.h"
14 #include "bd_wstring.h"
15 #include "ace/OS_NS_wchar.h"
17 // ************************************************************************
18 // Test_Bounded_WString
19 // ************************************************************************
21 Test_Bounded_WString::Test_Bounded_WString ()
22 : opname_ (CORBA::string_dup ("test_bounded_wstring")),
23 in_ (0),
24 inout_ (0),
25 out_ (0),
26 ret_ (0)
30 Test_Bounded_WString::~Test_Bounded_WString ()
32 CORBA::string_free (this->opname_);
33 CORBA::wstring_free (this->in_);
34 CORBA::wstring_free (this->inout_);
35 CORBA::wstring_free (this->out_);
36 CORBA::wstring_free (this->ret_);
37 this->opname_ = 0;
38 this->in_ = 0;
39 this->inout_ = 0;
40 this->out_ = 0;
41 this->ret_ = 0;
44 const char *
45 Test_Bounded_WString::opname () const
47 return this->opname_;
50 void
51 Test_Bounded_WString::dii_req_invoke (CORBA::Request *req)
53 req->add_in_arg ("s1") <<= CORBA::Any::from_wstring (this->in_, 128);
54 req->add_inout_arg ("s2") <<= CORBA::Any::from_wstring (this->inout_, 128);
55 req->add_out_arg ("s3") <<= CORBA::Any::from_wstring (this->out_, 128);
57 // The Any arg manages its memory but this class member does not.
58 CORBA::wstring_free (this->inout_);
60 req->set_return_type (Param_Test::_tc_short_wstring);
62 req->invoke ();
64 CORBA::WChar *tmp;
65 req->return_value () >>= CORBA::Any::to_wstring (tmp, 128);
66 this->ret_ = CORBA::wstring_dup (tmp);
68 CORBA::NamedValue_ptr arg2 =
69 req->arguments ()->item (1);
70 *arg2->value () >>= CORBA::Any::to_wstring (tmp, 128);
71 this->inout_ = CORBA::wstring_dup (tmp);
73 CORBA::NamedValue_ptr arg3 =
74 req->arguments ()->item (2);
75 *arg3->value () >>= CORBA::Any::to_wstring (tmp, 128);
76 this->out_ = CORBA::wstring_dup (tmp);
79 int
80 Test_Bounded_WString::init_parameters (Param_Test_ptr)
82 Generator *gen = GENERATOR::instance (); // value generator
84 // release any previously occupied values
85 CORBA::wstring_free (this->in_);
86 CORBA::wstring_free (this->inout_);
87 CORBA::wstring_free (this->out_);
88 CORBA::wstring_free (this->ret_);
89 this->in_ = 0;
90 this->inout_ = 0;
91 this->out_ = 0;
92 this->ret_ = 0;
94 this->in_ = gen->gen_wstring (32);
95 this->inout_ = CORBA::wstring_dup (this->in_);
96 return 0;
99 int
100 Test_Bounded_WString::reset_parameters ()
102 // release any previously occupied values
103 CORBA::wstring_free (this->inout_);
104 CORBA::wstring_free (this->out_);
105 CORBA::wstring_free (this->ret_);
106 this->inout_ = 0;
107 this->out_ = 0;
108 this->ret_ = 0;
110 this->inout_ = CORBA::wstring_dup (this->in_);
111 return 0;
115 Test_Bounded_WString::run_sii_test (Param_Test_ptr objref)
119 CORBA::WString_out str_out (this->out_);
121 this->ret_ = objref->test_bounded_wstring (this->in_,
122 this->inout_,
123 str_out);
125 return 0;
127 catch (const CORBA::Exception& ex)
129 ex._tao_print_exception ("Test_Bounded_WString::run_sii_test\n");
131 return -1;
134 CORBA::Boolean
135 Test_Bounded_WString::check_validity ()
137 CORBA::ULong len = ACE_OS::wslen (this->in_);
139 if (!ACE_OS::wscmp (this->in_, this->out_) &&
140 !ACE_OS::wscmp (this->in_, this->ret_) &&
141 ACE_OS::wslen (this->inout_) == 2*len &&
142 !ACE_OS::wsncmp (this->in_, this->inout_, len) &&
143 !ACE_OS::wsncmp (this->in_, &this->inout_[len], len))
144 return 1;
146 return 0; // otherwise
149 CORBA::Boolean
150 Test_Bounded_WString::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_Bounded_WString::print_values ()