Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Param_Test / small_union.cpp
blob8f00ade64f42a5b77ce1a4f8c11499a3b2ebd270
2 //=============================================================================
3 /**
4 * @file small_union.cpp
6 * tests Small_Unions
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
13 #include "helper.h"
14 #include "small_union.h"
16 // ************************************************************************
17 // Test_Small_Union
18 // ************************************************************************
20 size_t Test_Small_Union::counter = 0;
22 Test_Small_Union::Test_Small_Union ()
23 : opname_ (CORBA::string_dup ("test_small_union"))
27 Test_Small_Union::~Test_Small_Union ()
29 CORBA::string_free (this->opname_);
30 this->opname_ = 0;
33 const char *
34 Test_Small_Union::opname () const
36 return this->opname_;
39 void
40 Test_Small_Union::dii_req_invoke (CORBA::Request *req)
42 req->add_in_arg ("s1") <<= this->in_;
43 req->add_inout_arg ("s2") <<= this->inout_;
44 req->add_out_arg ("s3") <<= this->out_.in ();
46 req->set_return_type (Param_Test::_tc_Small_Union);
48 req->invoke ();
50 const Param_Test::Small_Union *tmp = 0;
51 req->return_value () >>= tmp;
52 this->ret_ = new Param_Test::Small_Union (*tmp);
54 CORBA::NamedValue_ptr o2 =
55 req->arguments ()->item (1);
56 *o2->value () >>= tmp;
57 this->inout_ = *tmp;
59 CORBA::NamedValue_ptr o3 =
60 req->arguments ()->item (2);
61 *o3->value () >>= tmp;
62 this->out_ = new Param_Test::Small_Union (*tmp);
65 int
66 Test_Small_Union::init_parameters (Param_Test_ptr objref)
68 try
70 // get access to a Coffee Object
71 this->cobj_ = objref->make_coffee ();
73 this->reset_parameters ();
74 return 0;
76 catch (const CORBA::SystemException& sysex)
78 sysex._tao_print_exception ("System Exception doing make_coffee");
80 catch (const CORBA::Exception& ex)
82 ex._tao_print_exception (
83 "An exception caught in make_coffee");
85 return -1;
88 int
89 Test_Small_Union::reset_parameters ()
91 Generator *gen = GENERATOR::instance (); // value generator
92 CORBA::ULong index = (counter++ % 2);
94 switch (index)
96 case 0:
98 CORBA::Long l = gen->gen_long ();
99 this->in_.the_long (l);
100 this->inout_.the_long (l);
102 break;
103 default:
104 case 1:
106 CORBA::Short s = gen->gen_short ();
107 this->in_.the_short (s);
108 this->inout_.the_short (s);
110 break;
112 this->out_ = new Param_Test::Small_Union (this->in_);
113 this->ret_ = new Param_Test::Small_Union (this->in_);
114 return 0;
118 Test_Small_Union::run_sii_test (Param_Test_ptr objref)
122 this->ret_ = objref->test_small_union (this->in_,
123 this->inout_,
124 this->out_);
126 return 0;
128 catch (const CORBA::Exception& ex)
130 ex._tao_print_exception ("Test_Small_Union::run_sii_test\n");
132 return -1;
135 CORBA::Boolean
136 Test_Small_Union::check_validity ()
138 if (this->in_._d () != this->inout_._d ()
139 || this->in_._d () != this->out_->_d ()
140 || this->in_._d () != this->ret_->_d ())
142 ACE_DEBUG ((LM_DEBUG, "mismatch of discriminators\n"));
143 return 0;
147 switch (this->in_._d ())
149 case Param_Test::A_LONG:
151 CORBA::Long in = this->in_.the_long ();
152 CORBA::Long inout = this->inout_.the_long ();
153 CORBA::Long out = this->out_->the_long ();
154 CORBA::Long ret = this->ret_->the_long ();
155 if (in != out || in != inout || in != ret)
156 return 0;
158 break;
160 case Param_Test::A_SHORT:
162 CORBA::Short in = this->in_.the_short ();
163 CORBA::Short inout = this->inout_.the_short ();
164 CORBA::Short out = this->out_->the_short ();
165 CORBA::Short ret = this->ret_->the_short ();
166 if (in != out || in != inout || in != ret)
167 return 0;
169 break;
171 default:
172 return 0;
175 return 1;
178 CORBA::Boolean
179 Test_Small_Union::check_validity (CORBA::Request_ptr /*req*/)
181 //ACE_UNUSED_ARG (req);
182 return this->check_validity ();
185 void
186 Test_Small_Union::print_values ()