summaryrefslogtreecommitdiff
path: root/TAO/tests/Multiple/Collocation_Tester.cpp
blob: 886e9d8183019723eaa0952f905fd5ab34893de1 (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
// $Id$

#include "Collocation_Tester.h"

ACE_RCSID (tests, Collocation_Tester, "$Id$")

const char *Quote::top = "Ciao";
const char *Quote::left = "Hola";
const char *Quote::right = "Hello";
const char *Quote::bottom = "Previet";

Collocation_Tester::Collocation_Tester (CORBA::Object_ptr object)
{
  this->object_ = CORBA::Object::_duplicate (object);
}

Collocation_Tester::~Collocation_Tester (void)
{
  // No-Op.
}

int
Collocation_Tester::match_answer (const char *actual_answer,
                                  const char *right_answer,
                                  const char *method_name)
{
  if (ACE_OS::strcmp (actual_answer, right_answer))
    {
      ACE_ERROR ((LM_DEBUG,
                  ACE_TEXT ("Call to <%s> returned the wrong value!\n"), method_name));
      return 1;
    }
  else
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("Call to <%s> returned with success: %s \n"), method_name, actual_answer));
      return 0;
    }
}

int
Collocation_Tester::test_top (CORBA::Environment &ACE_TRY_ENV)
{
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT("\n------------------------<TOP>-------------------------------\n")));
  int failure = 0;
  int call_num = 1;
  Multiple::Top_var top =
    Multiple::Top::_narrow (this->object_.in ());

  if (CORBA::is_nil (top.in ()))
    {
      ACE_ERROR ((LM_DEBUG,
                  ACE_TEXT ("Unable to Narrow to Multiple::Top\n")));
      return 1;
    }

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("\n\nCalling all method supported by the Interface Top\n\n")));

  CORBA::String_var msg = top->top_quote (ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

  failure += this->match_answer (Quote::top, msg.in (), "top_quote");

  if (failure)
    ACE_ERROR ((LM_DEBUG,
                ACE_TEXT ("The test had %d/%d Failure\n"), failure, call_num));

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT("\n------------------------<TOP>-------------------------------\n")));

  return failure;
}

int
Collocation_Tester::test_right (CORBA::Environment &ACE_TRY_ENV)
{
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT("\n------------------------<RIGHT>-------------------------------\n")));
  int failure = 0;
  int call_num = 2;
  Multiple::Right_var right =
    Multiple::Right::_narrow (this->object_.in ());

  if (CORBA::is_nil (right.in ()))
    {
      ACE_ERROR ((LM_DEBUG,
                  ACE_TEXT ("Unable to Narrow to Multiple::Right\n")));
      return 1;
    }

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("\n\nCalling all method supported by the Interface Right\n\n")));

  CORBA::String_var msg = right->top_quote (ACE_TRY_ENV);
  ACE_CHECK_RETURN (1);

  failure += this->match_answer (Quote::top, msg.in (), "top_quote");

  msg = right->right_quote (ACE_TRY_ENV);
  ACE_CHECK_RETURN (1);

  failure += this->match_answer (Quote::right, msg.in (), "right_quote");

  if (failure)
    ACE_ERROR ((LM_DEBUG,
                ACE_TEXT ("The test had %d/%d Failure"), failure, call_num));

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT("\n------------------------<RIGHT>-------------------------------\n")));

  return failure;
}


int
Collocation_Tester::test_left (CORBA::Environment &ACE_TRY_ENV)
{
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT("\n------------------------<LEFT>-------------------------------\n")));
  int failure = 0;
  int call_num = 2;

  Multiple::Left_var left =
    Multiple::Left::_narrow (this->object_.in ());

  if (CORBA::is_nil (left.in ()))
    {
      ACE_ERROR ((LM_DEBUG,
                  ACE_TEXT ("Unable to Narrow to Multiple::Right\n")));
      return 1;
    }

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("\n\nCalling all method supported by the Interface Left\n\n")));

  CORBA::String_var msg = left->top_quote (ACE_TRY_ENV);
  ACE_CHECK_RETURN (1);

  failure += this->match_answer (Quote::top, msg.in (), "top_quote");

  msg = left->left_quote (ACE_TRY_ENV);
  ACE_CHECK_RETURN(1);

  failure += this->match_answer (Quote::left, msg.in (), "left_quote");

  if (failure)
    ACE_ERROR ((LM_DEBUG,
                ACE_TEXT ("The test had %d/%d Failure"), failure, call_num));

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT("\n------------------------<LEFT>-------------------------------\n")));

  return failure;
}


int
Collocation_Tester::test_bottom (CORBA::Environment &ACE_TRY_ENV)
{
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT("\n-----------------------<BOTTOM>-------------------------------\n")));
  int failure = 0;
  int call_num = 4;

  Multiple::Bottom_var bottom =
    Multiple::Bottom::_narrow (this->object_.in ());

  if (CORBA::is_nil (bottom.in ()))
    {
      ACE_ERROR ((LM_DEBUG,
                  ACE_TEXT ("Unable to Narrow to Multiple::Right\n")));
      return 1;
    }

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("\n\nCalling all method supported by the Interface Bottom\n\n")));

  CORBA::String_var msg = bottom->top_quote (ACE_TRY_ENV);
  ACE_CHECK_RETURN(1);

  failure += this->match_answer (Quote::top, msg.in (), "top_quote");

  msg = bottom->left_quote (ACE_TRY_ENV);
  ACE_CHECK_RETURN (1);

  failure += this->match_answer (Quote::left, msg.in (), "left_quote");

  msg = bottom->right_quote (ACE_TRY_ENV);
  ACE_CHECK_RETURN(1);

  failure += this->match_answer (Quote::right, msg.in (), "right_quote");

  msg = bottom->bottom_quote (ACE_TRY_ENV);
  ACE_CHECK_RETURN(1);

  failure += this->match_answer (Quote::bottom, msg.in (), "bottom_quote");

  if (failure)
    ACE_ERROR ((LM_DEBUG,
                ACE_TEXT ("The test had %d/%d Failure"), failure, call_num));

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT("\n-----------------------<BOTTOM>-------------------------------\n")));

  return failure;
}

void
Collocation_Tester::shutdown (CORBA::Environment &ACE_TRY_ENV)
{
  Multiple::Top_var top =
    Multiple::Top::_narrow (this->object_.in ());

  if (CORBA::is_nil (top.in ()))
    {
      ACE_ERROR ((LM_DEBUG,
                  ACE_TEXT ("Unable to Narrow to Multiple::Top\n")));
      return;
    }

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("\n\nCalling ShutDown on Top.\n\n")));

  top->shutdown (ACE_TRY_ENV);
  ACE_CHECK;
}

void
Collocation_Tester::run (CORBA::Environment &ACE_TRY_ENV)
{
  int failure_num =   this->test_top (ACE_TRY_ENV);
  ACE_CHECK;

  failure_num += this->test_left (ACE_TRY_ENV);
  ACE_CHECK;

  failure_num += this->test_right (ACE_TRY_ENV);
  ACE_CHECK;

  failure_num += this->test_bottom (ACE_TRY_ENV);
  ACE_CHECK;

  if (failure_num)
    ACE_ERROR ((LM_DEBUG,
                ACE_TEXT ("\n\nThe Test failed in %d cases."), failure_num));
  else
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("\n\nThe Test Completed Successfully. Congratulations! ")));

  this->shutdown (ACE_TRY_ENV);
}