summaryrefslogtreecommitdiff
path: root/TAO/tests/CSD_Strategy_Tests/TP_Foo_B/Foo_B_ClientEngine.cpp
blob: 93f48ae90554c58b95da26d4d50fca0ed6dd412a (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
// $Id$
#include "Foo_B_ClientEngine.h"
#include "Callback_i.h"
#include "Foo_B_Statistics.h"
#include "TestAppExceptionC.h"
#include "AppHelper.h"
#include "ace/Log_Msg.h"
#include "ace/OS.h"

const char* ONEWAY_ARG_TEST_STR = "TEST";

Foo_B_ClientEngine::Foo_B_ClientEngine(Foo_B_ptr obj,
                                       Callback_ptr callback,
                                       unsigned client_id,
                                       bool collocated)
  : obj_(Foo_B::_duplicate(obj)),
    callback_(Callback::_duplicate(callback)),
    client_id_(client_id),
    collocated_(collocated)
{
}


Foo_B_ClientEngine::~Foo_B_ClientEngine()
{
}


bool
Foo_B_ClientEngine::execute(ACE_ENV_SINGLE_ARG_DECL)
{
  // Make sure the connection is established before making
  // remote invocations.
  if (AppHelper::validate_connection (this->obj_.in ()) == false)
    {
      ACE_ERROR((LM_ERROR, "(%P|%t)Foo_A_ClientEngine::execute  " \
                          "client %d connect failed.\n", this->client_id_));
      return false;
    }

  // Verify the return values and return the results.
  bool check_validity = true;

  this->obj_->op1(ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (false);

  this->obj_->op2(this->client_id_ ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (false);

  CORBA::Long value = this->obj_->op3(this->client_id_ ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (false);

  if (value != static_cast<CORBA::Long>(this->client_id_))
    {
      check_validity = false;
    }

  for (CORBA::ULong j = 1; j <= 5; j++)
    {
      this->obj_->op4(495 + (this->client_id_ * 5) + j ACE_ENV_ARG_PARAMETER);
      ACE_CHECK_RETURN (false);
    }

  bool caught_exception = false;

  ACE_TRY
  {
    this->obj_->op5(ACE_ENV_SINGLE_ARG_PARAMETER);
    ACE_TRY_CHECK;
  }
  ACE_CATCH (FooException, ex)
  {
    // Expected
    caught_exception = true;
  }
  ACE_ENDTRY;

  if (! caught_exception)
    {
      check_validity = false;
    }

  TimeOfDay t;
  t.hour = 12;
  t.minute = 30;
  t.second = 10;

  char test_str [20];
  ACE_OS::sprintf (test_str, "%d %s", this->client_id_, ONEWAY_ARG_TEST_STR);

  char buffer [20];

  // Two-Way calls with "inout" and fixed size "in" arguments.
  CORBA::String_var message = CORBA::string_dup(test_str);

  CORBA::Boolean result = this->obj_->op6( t, message.inout() ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (false);

  ACE_UNUSED_ARG(result);

  ACE_OS::sprintf (buffer, "%d %s %d:%d:%d", this->client_id_, ONEWAY_ARG_TEST_STR,
    t.hour, t.minute, t.second);

  if (ACE_OS::strncmp (message.in (), buffer, ACE_OS::strlen (buffer)) != 0)
    {
      check_validity = false;
    }

  // Callback test.
  this->obj_->op7 (this->callback_.in () ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (false);

  // One-Way calls with various arguments.
  CORBA::String_var ub_string = CORBA::string_dup( test_str );
  this->obj_->test_unbounded_string_arg (ub_string.in () ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (false);

  CORBA::String_var bd_string = CORBA::string_dup( test_str );
  this->obj_->test_bounded_string_arg (bd_string.in () ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (false);

  Fixed_Array fixed_array;

  for (CORBA::ULong m = 0 ; m < 20; m ++)
  {
     fixed_array[m] = this->client_id_ + m;
  }

  this->obj_->test_fixed_array_arg (fixed_array ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (false);

  Var_Array var_array;

  for (CORBA::ULong k = 0; k < 3; k++)
    {
      ACE_OS::sprintf (buffer, "%d %s %d",
                       this->client_id_, ONEWAY_ARG_TEST_STR, k);
      var_array[k] = CORBA::string_dup(buffer);
    }

  this->obj_->test_var_array_arg (var_array ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (false);

  Bounded_Var_Size_var bd_var_size_string = new Bounded_Var_Size();

  bd_var_size_string->replace (bd_var_size_string->maximum (),
                        ACE_OS::strlen (test_str) + 1,
                        test_str);
  this->obj_->test_bounded_var_size_arg (bd_var_size_string.in ()
                                         ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (false);

  Unbounded_Var_Size_var ub_var_size_string = new Unbounded_Var_Size(100);
  ub_var_size_string->replace (ub_var_size_string->maximum (),
                            ACE_OS::strlen (test_str) + 1,
                            test_str);
  this->obj_->test_unbounded_var_size_arg (ub_var_size_string.in ()
                                           ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (false);

  this->obj_->test_fixed_size_arg (t ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (false);

  this->obj_->test_special_basic_arg (this->client_id_ % 2,
                                      this->client_id_
                                      ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (false);

  this->obj_->test_objref_arg (this->callback_.in () ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (false);

  // Sleep for 5 seconds before invoking done().  
  // This is a workaround with the problem that some oneway requests lost 
  // when the server has multiple orb threads.
  ACE_OS::sleep (5);
  this->obj_->done(ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (false);

  return check_validity;
}


void
Foo_B_ClientEngine::expected_results(Foo_B_Statistics& stats)
{
  stats.expected(1, 1, Foo_B_Statistics::FOO_B_STAT_NONE);
  stats.expected(2, 1, Foo_B_Statistics::FOO_B_STAT_LONG);
  stats.expected(3, 1, Foo_B_Statistics::FOO_B_STAT_LONG);
  stats.expected(4, 5, Foo_B_Statistics::FOO_B_STAT_LONG);
  stats.expected(5, 1, Foo_B_Statistics::FOO_B_STAT_NONE);
  stats.expected(6, 1, Foo_B_Statistics::FOO_B_STAT_NONE);
  stats.expected(7, 1, Foo_B_Statistics::FOO_B_STAT_NONE);
  stats.expected(8, 1, Foo_B_Statistics::FOO_B_STAT_STRING);
  stats.expected(9, 1, Foo_B_Statistics::FOO_B_STAT_STRING);
  stats.expected(10, 1, Foo_B_Statistics::FOO_B_STAT_LONG);
  stats.expected(11, 1, Foo_B_Statistics::FOO_B_STAT_STRING);
  stats.expected(12, 1, Foo_B_Statistics::FOO_B_STAT_STRING);
  stats.expected(13, 1, Foo_B_Statistics::FOO_B_STAT_NONE);
  stats.expected(14, 1, Foo_B_Statistics::FOO_B_STAT_STRING);
  stats.expected(15, 1, Foo_B_Statistics::FOO_B_STAT_NONE);
  stats.expected(16, 1, Foo_B_Statistics::FOO_B_STAT_NONE);
  stats.expected_callbacks (1);
}


unsigned
Foo_B_ClientEngine::expected_callbacks ()
{
  return 1;
}