summaryrefslogtreecommitdiff
path: root/TAO/tests/CSD_Strategy_Tests/TP_Foo_B/Foo_B_i.cpp
blob: 73105ff17138578f9295ab58b2224fdc920ccf0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
// $Id$
#include "Foo_B_i.h"
#include "AppShutdown.h"
#include "TestAppExceptionC.h"
#include "ace/OS.h"
#include "ace/SString.h"


Foo_B_i::Foo_B_i()
: error_count_ (0)
{
   for (unsigned i = 0; i < 16; i++)
    {
      op_count_[i] = 0; 
    }
}


Foo_B_i::~Foo_B_i()
{
}


void
Foo_B_i::op1(ACE_ENV_SINGLE_ARG_DECL_NOT_USED)  
  ACE_THROW_SPEC((CORBA::SystemException))
{
  this->op_count_[0] ++;
}


void
Foo_B_i::op2(CORBA::Long value ACE_ENV_ARG_DECL_NOT_USED)  
  ACE_THROW_SPEC((CORBA::SystemException))
{
  this->op_count_[1] ++;
  this->in_long_[1].push_back (value);
}


CORBA::Long
Foo_B_i::op3(CORBA::Long value ACE_ENV_ARG_DECL_NOT_USED)  
  ACE_THROW_SPEC((CORBA::SystemException))
{
  this->op_count_[2] ++;
  this->in_long_[2].push_back (value);
  return value;
}


void
Foo_B_i::op4(CORBA::Long value ACE_ENV_ARG_DECL_NOT_USED)  
  ACE_THROW_SPEC((CORBA::SystemException))
{
  this->op_count_[3] ++;
  this->in_long_[3].push_back (value);
}


void
Foo_B_i::op5(ACE_ENV_SINGLE_ARG_DECL)  
  ACE_THROW_SPEC((CORBA::SystemException, FooException))
{
  this->op_count_[4] ++;
  ACE_THROW (FooException());
}


CORBA::Boolean 
Foo_B_i::op6(const TimeOfDay& t, 
             char*& message
             ACE_ENV_ARG_DECL_NOT_USED)
                        ACE_THROW_SPEC((CORBA::SystemException))
{
  this->op_count_[5] ++;
  char buf [20];
  ACE_OS::sprintf (buf, "%s %d:%d:%d", message, t.hour, t.minute, t.second);
  message = CORBA::string_dup (buf);
    
  return 1;
}


void 
Foo_B_i::op7(Callback_ptr cb
             ACE_ENV_ARG_DECL)  
  ACE_THROW_SPEC((CORBA::SystemException,
                  FooException))
{
  this->op_count_[6] ++;

  if (CORBA::is_nil (cb))
    {
      error_count_ ++;
      ACE_THROW (FooException ());
    }
  else
    {
      cb->test_method (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_CHECK;
    }
}


void 
Foo_B_i::test_unbounded_string_arg(const char* message
                                   ACE_ENV_ARG_DECL_NOT_USED)
                            ACE_THROW_SPEC((CORBA::SystemException))
{
  this->op_count_[7] ++;
  //ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Foo_B_i::test_unbounded_string_arg ")
  //                     ACE_TEXT("got unbounded string %s\n"), 
  //                     message));
  this->in_string_[7].push_back (message);
}


void 
Foo_B_i::test_bounded_string_arg(const char* message
                                 ACE_ENV_ARG_DECL_NOT_USED)
                            ACE_THROW_SPEC((CORBA::SystemException))
{
  this->op_count_[8] ++;
  //ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Foo_B_i::test_bounded_string_arg ")
  //                     ACE_TEXT("got bounded string %s\n"), 
  //                     message));
  this->in_string_[8].push_back (message);
}


void 
Foo_B_i::test_fixed_array_arg(const Fixed_Array message
                              ACE_ENV_ARG_DECL_NOT_USED)
                            ACE_THROW_SPEC((CORBA::SystemException))
{
  this->op_count_[9] ++;

  for (unsigned i = 0; i < 19; i++)
    {
      //ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Foo_B_i::test_fixed_array_arg ")
      //                     ACE_TEXT("got fixed array[i] = %d\n"), 
      //                     i, message[i]));

      if (message[i] != message[i + 1] -1)
        {
          error_count_ ++;
          break;
        }
    }

  
  this->in_long_[9].push_back (message[0]);
}


void 
Foo_B_i::test_bounded_var_size_arg(const Bounded_Var_Size& message
                                   ACE_ENV_ARG_DECL_NOT_USED)
                           ACE_THROW_SPEC((CORBA::SystemException))
{
  this->op_count_[10] ++;
  //ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Foo_B_i::test_bounded_var_size_arg ")
  //                    ACE_TEXT("got var array chars %s\n"), 
  //                    message.get_buffer ()));
  this->in_string_[10].push_back (message.get_buffer ());
}


void 
Foo_B_i::test_unbounded_var_size_arg(const Unbounded_Var_Size& message
                                     ACE_ENV_ARG_DECL_NOT_USED)
                          ACE_THROW_SPEC((CORBA::SystemException))
{
  this->op_count_[11] ++;
  //ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Foo_B_i::test_unbounded_var_size_arg ")
  //                     ACE_TEXT("got var array chars %s\n"),
  //                     message.get_buffer ()));
  this->in_string_[11].push_back (message.get_buffer ());
}


void 
Foo_B_i::test_fixed_size_arg(const TimeOfDay& t
                             ACE_ENV_ARG_DECL_NOT_USED)
                           ACE_THROW_SPEC ((CORBA::SystemException))
{
  ACE_UNUSED_ARG(t);

  this->op_count_[12] ++;
  //ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Foo_B_i::test_fixed_size_arg ")
  //                     ACE_TEXT("got timeofday %d:%d:%d\n"),
  //                     t.hour, t.minute, t.second));
}


void 
Foo_B_i::test_var_array_arg(const Var_Array messages
                            ACE_ENV_ARG_DECL_NOT_USED)
                          ACE_THROW_SPEC((CORBA::SystemException))
{
  this->op_count_[13] ++;
  //ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Foo_B_i::test_var_array_arg ")
  //                     ACE_TEXT(" %s \n"), messages[0].in ()));
  //ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Foo_B_i::test_var_array_arg ")
  //                     ACE_TEXT(" %s \n"), messages[1].in ()));
  //ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Foo_B_i::test_var_array_arg ")
  //                     ACE_TEXT(" %s \n"), messages[2].in ()));
  unsigned cur_client_id = 0;
  
  for (unsigned i = 0 ; i < 3; i ++)
  {
    unsigned client_id = 0;
    unsigned str_id = 0;
    char test_str[20];
    sscanf (messages[i].in (), "%d %s %d", &client_id, test_str, &str_id);

    if (str_id != i)
    {
      error_count_ ++;
    }

    if (i == 0)
    {
       cur_client_id = client_id;
    }
    else if (client_id != cur_client_id) 
    {
       error_count_ ++;
    }
  }
  this->in_string_[13].push_back (messages[0].in ());
}


void 
Foo_B_i::test_special_basic_arg(CORBA::Boolean value, 
                                CORBA::Long client_id
                                ACE_ENV_ARG_DECL_NOT_USED)
                           ACE_THROW_SPEC((CORBA::SystemException))
{
  this->op_count_[14] ++;
  //ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Foo_B_i::test_special_basic_arg ")
  //                     ACE_TEXT(" got special basic arg: %d \n"), value));

  CORBA::Boolean expected_special_value = client_id % 2;
  if (expected_special_value != value)
    {
      error_count_ ++;
    }
}


void 
Foo_B_i::test_objref_arg(Callback_ptr cb
                         ACE_ENV_ARG_DECL_NOT_USED)
                            ACE_THROW_SPEC ((CORBA::SystemException))
{
  ACE_UNUSED_ARG(cb);
  this->op_count_[15] ++;
  //ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Foo_B_i::test_objref_arg ")
  //                     ACE_TEXT(" got callback object. \n")));
}


void
Foo_B_i::done(ACE_ENV_SINGLE_ARG_DECL_NOT_USED)  
  ACE_THROW_SPEC((CORBA::SystemException))
{
  TheAppShutdown->client_done();
}


void
Foo_B_i::gather_stats (Foo_B_Statistics& stats) 
{
  for (unsigned i = 0; i < 16; i++)
    {
      stats.actual (i+1, this->op_count_[i]);
      stats.actual (i+1, this->in_string_[i]);
      stats.actual (i+1, this->in_long_[i]);
      stats.servant_error_count (this->error_count_);
    }
}