Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Param_Test / client.cpp
blobc163d094f6fa28652b53b54a04b1c3070be1a435
2 //=============================================================================
3 /**
4 * @file client.cpp
6 * This file contains the implementation of the client-side of the
7 * Param_Test application.
9 * @author Aniruddha Gokhale
11 //=============================================================================
14 #ifndef CLIENT_CPP
15 #define CLIENT_CPP
17 #include "options.h"
18 #include "results.h"
19 #include "client.h"
21 // Constructor.
22 template <class T>
23 Param_Test_Client<T>::Param_Test_Client (CORBA::ORB_ptr orb,
24 Param_Test_ptr objref,
25 T *t)
26 : orb_ (orb),
27 param_test_ (objref),
28 test_object_ (t)
32 // destructor
33 template <class T>
34 Param_Test_Client<T>::~Param_Test_Client ()
36 delete this->test_object_;
39 // All the individual tests.
40 template <class T> int
41 Param_Test_Client<T>::run_sii_test ()
43 CORBA::ULong i = 0; // loop index
44 Options *opt = OPTIONS::instance (); // get the options
45 const char *opname = this->test_object_->opname (); // operation
47 if (opt->debug ())
48 ACE_DEBUG ((LM_DEBUG,
49 "********** %C SII *********\n",
50 opname));
52 // Initialize call count and error count.
53 this->results_.call_count (0);
54 this->results_.error_count (0);
55 this->results_.iterations (opt->loop_count ());
57 // Declare the Env
58 // Initialize parameters for the test.
59 int check = this->test_object_->init_parameters (this->param_test_);
61 if (check == -1)
63 ACE_ERROR_RETURN ((LM_ERROR,
64 "(%N:%l) client.cpp - run_sii_test:"
65 "init_parameters failed for opname - %C",
66 opname),
67 -1);
71 // Make the calls in a loop.
72 for (i = 0; i < opt->loop_count (); i++)
74 try
76 this->results_.call_count (this->results_.call_count () + 1);
77 if (opt->debug ())
79 ACE_DEBUG ((LM_DEBUG, "\n****** Before call values *****\n"));
80 this->test_object_->print_values ();
83 // start the timing
84 this->results_.start_timer ();
86 // make the call
87 this->test_object_->run_sii_test (this->param_test_);
89 // stop the timer.
90 this->results_.stop_timer ();
92 // now check if the values returned are as expected
93 if (opt->debug ())
95 ACE_DEBUG ((LM_DEBUG, "\n****** After call values *****\n"));
96 this->test_object_->print_values ();
99 catch (const CORBA::Exception& ex)
101 this->results_.error_count (this->results_.error_count () + 1);
102 ex._tao_print_exception (opname);
103 ACE_ERROR ((LM_ERROR,
104 "(%N:%l) client.cpp - run_sii_test:"
105 "run_sii_test exception in iteration %d",
106 i));
107 goto loop_around;
110 if (!this->test_object_->check_validity ())
112 this->results_.error_count (this->results_.error_count () + 1);
113 ACE_ERROR ((LM_ERROR,
114 "(%N:%l) client.cpp - run_sii_test: "
115 "Invalid results in iteration %d\n",
116 i));
117 continue;
119 // reset parameters for the test.
120 if (this->test_object_->reset_parameters () == -1)
121 ACE_ERROR_RETURN ((LM_ERROR,
122 "(%N:%l) client.cpp - run_sii_test:"
123 "init_parameters failed for opname - %C",
124 opname), -1);
125 loop_around: continue;
128 // print statistics
129 this->results_.print_stats ();
130 if (this->results_.error_count () != 0)
132 ACE_DEBUG ((LM_DEBUG,
133 "********** Error running %C SII *********\n",
134 opname));
136 else if (opt->debug ())
138 ACE_DEBUG ((LM_DEBUG,
139 "********** Finished running %C SII *********\n",
140 opname));
142 return this->results_.error_count ()? -1:0;
145 // use DII
146 template <class T> int
147 Param_Test_Client<T>::run_dii_test ()
149 const char *opname = this->test_object_->opname ();
150 Options *opt = OPTIONS::instance ();
152 if (opt->debug ())
153 ACE_DEBUG ((LM_DEBUG,
154 "********** %C DII *********\n",
155 opname));
157 // initialize call count and error count
158 this->results_.call_count (0);
159 this->results_.error_count (0);
160 this->results_.iterations (opt->loop_count ());
162 // Environment variable
163 // initialize parameters for the test
164 int check = this->test_object_->init_parameters (this->param_test_);
166 if (check == -1)
168 ACE_ERROR_RETURN ((LM_ERROR,
169 "(%N:%l) client.cpp - run_dii_test:"
170 "init_parameters failed for opname - %C",
171 opname),
172 -1);
175 // Make the calls in a loop.
176 for (CORBA::ULong i = 0; i < opt->loop_count (); i++)
178 this->results_.call_count (this->results_.call_count () + 1);
180 // start the timing. We measure the entire overhead of DII, including the
181 // time required to create and populate the NVList
182 this->results_.start_timer ();
184 // create the request
185 CORBA::Request_var req;
189 req = this->param_test_->_request (opname);
191 if (opt->debug ())
193 ACE_DEBUG ((LM_DEBUG, "\n****** Before call values *****\n"));
194 this->test_object_->print_values ();
197 // Make the invocation, verify the result.
198 this->test_object_->dii_req_invoke (req.in ());
200 catch (const CORBA::Exception& ex)
202 this->results_.error_count (this->results_.error_count () + 1);
204 ex._tao_print_exception (opname);
205 goto loop_around;
208 if (opt->debug ())
210 ACE_DEBUG ((LM_DEBUG, "\n****** After call values *****\n"));
211 this->test_object_->print_values ();
213 // now check if the values returned are as expected
214 if (!this->test_object_->check_validity (req.in ()))
216 this->results_.error_count (this->results_.error_count () + 1);
217 ACE_ERROR ((LM_ERROR,
218 "(%N:%l) client.cpp - "
219 "Invalid results in run_dii_test in iteration %d\n",
220 i));
222 continue;
225 // stop the this->results_.
226 this->results_.stop_timer ();
228 // reset parameters for the test
229 this->test_object_->reset_parameters ();
231 loop_around:continue;
232 } // for loop
234 // print statistics
235 this->results_.print_stats ();
236 if (this->results_.error_count () != 0)
238 ACE_DEBUG ((LM_DEBUG,
239 "********** Error running %C DII *********\n",
240 opname));
242 else if (opt->debug ())
244 ACE_DEBUG ((LM_DEBUG,
245 "********** Finished running %C DII *********\n",
246 opname));
248 return this->results_.error_count () ? -1 : 0;
252 #endif /* CLIENT_CPP */