summaryrefslogtreecommitdiff
path: root/TAO/tests/CSD_Strategy_Tests/TP_Foo_B/Foo_B_Statistics.cpp
blob: 6cf19e95125393c8f31d09b919ed89a268178827 (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
// $Id$
#include "Foo_B_Statistics.h"
#include "Foo_B_ClientEngine.h"

extern const char* ONEWAY_ARG_TEST_STR;
extern CORBA::Boolean special_value;

Foo_B_Statistics::Foo_B_Statistics(unsigned num_remote_clients, 
                                   unsigned num_collcated_clients)
: num_clients_ (num_remote_clients + num_collcated_clients),
  num_collcated_clients_ (num_collcated_clients),
  expected_callbacks_ (0),
  actual_callbacks_ (0),
  servant_error_count_ (0)
{
  for (unsigned i = 0; i < 16; i++)
    {
      this->expected_op_count_[i] = 0;
      this->actual_op_count_[i] = 0;
    }
}


Foo_B_Statistics::~Foo_B_Statistics()
{
}


void
Foo_B_Statistics::expected(unsigned op_num, unsigned count, In_Value_Type type)
{
  this->expected_op_count_[op_num-1] = count * this->num_clients_;
  this->expected_in_value_type_[op_num-1] = type;
}


void
Foo_B_Statistics::actual(unsigned op_num, unsigned count)
{
  this->actual_op_count_[op_num-1] += count;
}


void
Foo_B_Statistics::actual(unsigned op_num, LongVector lv)
{
  unsigned sz = lv.size();
  for (unsigned i = 0; i < sz; i++)
    {
      this->actual_in_long_[op_num-1].push_back (lv[i]);
    }
}


void
Foo_B_Statistics::actual(unsigned op_num, StringVector sv)
{
  unsigned sz = sv.size();
  for (unsigned i = 0; i < sz; i++)
    {
      this->actual_in_string_[op_num-1].push_back (sv[i]);
    }
}


void 
Foo_B_Statistics::expected_callbacks (unsigned num_cbs)
{
  expected_callbacks_ = num_cbs * this->num_collcated_clients_;
}


void 
Foo_B_Statistics::actual_callbacks (unsigned num_cbs)
{
  actual_callbacks_ += num_cbs;
}


void
Foo_B_Statistics::servant_error_count (unsigned error_count)
{
  this->servant_error_count_ += error_count;
}


bool
Foo_B_Statistics::actual_vs_expected()
{
  bool ret = true;

  // Verify the checking results in servant operation code.
  if (this->servant_error_count_ > 0)
    {
      ACE_ERROR((LM_ERROR, "(%P|%t)Foo_B_Statistics::actual_vs_expected  "
        "servant_error_count_=%u\n", servant_error_count_));
      if (ret) 
        ret = false;
    }

  // Verify the number of callbacks received for the collocated
  // client.
  if (actual_callbacks_ != expected_callbacks_)
    {
      ACE_ERROR((LM_ERROR, "(%P|%t)Foo_B_Statistics::actual_vs_expected  "
        "actual_callbacks_=%u expected_callbacks_=%u \n", 
        actual_callbacks_, expected_callbacks_));
      if (ret) 
        ret = false;
    }

  // Verify the number of operations server received.
  for (unsigned int z = 0; z < 16; z++)
    {
      if (this->expected_op_count_[z] != this->actual_op_count_[z])
        {
          ACE_ERROR((LM_ERROR, "(%P|%t)Foo_B_Statistics::actual_vs_expected  "
            "expected_op_count_[%u]=%u actual_op_count_[%u]=%u \n", 
            z, expected_op_count_[z], z, actual_op_count_[z]));
          if (ret) 
            ret = false;
        }
    }

  Foo_B_Statistics stats (1, 0);
  Foo_B_ClientEngine::expected_results (stats);

  for (unsigned i = 0; i < 16; i++)
    {
      switch (expected_in_value_type_[i])
      {
        case FOO_B_STAT_LONG:
          {
            unsigned actual_size 
              = this->actual_in_long_[i].size ();
            unsigned expected_size 
              = this->num_clients_ * stats.expected_op_count_[i];
            if (actual_size != expected_size)
              {
                ACE_ERROR((LM_ERROR, "(%P|%t)Foo_B_Statistics::actual_vs_expected  "
                  "actual_size=%u expected_size=%u\n", actual_size, expected_size));
                if (ret) 
                  ret = false;
              }
            sort (this->actual_in_long_[i]);

            for (unsigned j = 0; j < actual_size - 1; j++)
              {
                if (this->actual_in_long_[i][j] != this->actual_in_long_[i][j + 1] - 1)
                  {
                    ACE_ERROR((LM_ERROR, "(%P|%t)Foo_B_Statistics::actual_vs_expected  "
                      "actual_in_long_[%u][%u]=%d actual_in_long_[%u][%u]=%d\n", 
                      i, j, actual_in_long_[i][j], i, j+1, actual_in_long_[i][j + 1]));
                    if (ret) 
                      ret = false;
                  }
              }
          }
          break;

        case FOO_B_STAT_STRING:
          {
            unsigned actual_size 
              = this->actual_in_string_[i].size ();
            unsigned expected_size 
              = this->num_clients_ * stats.expected_op_count_[i];
            if (actual_size != expected_size)
              {
                ACE_ERROR((LM_ERROR, "(%P|%t)Foo_B_Statistics::actual_vs_expected  "
                  "actual_size=%u expected_size=%u\n", actual_size, expected_size));
                if (ret) 
                  ret = false;
              }

            LongVector lvec;
            char buffer[50];

            for (unsigned k = 0; k < actual_size; k++)
              {
                unsigned client_id;
                sscanf (this->actual_in_string_[i][k].c_str(), "%u %s", &client_id, buffer);
                if (ACE_OS::strcmp (buffer, ONEWAY_ARG_TEST_STR) != 0)
                  {
                    ACE_ERROR((LM_ERROR, "(%P|%t)Foo_B_Statistics::actual_vs_expected  "
                      "actual_in_string_[%u][%u]=%s \n", 
                      i, k, actual_in_string_[i][k].c_str()));
                    if (ret) 
                      ret = false;
                  }
                lvec.push_back (client_id);
              }

            sort (lvec);

            for (unsigned j = 0; j < actual_size - 1; j++)
              {
                if (lvec[j] != lvec[j + 1] - 1)
                  {
                    ACE_ERROR((LM_ERROR, "(%P|%t)Foo_B_Statistics::actual_vs_expected  "
                      "lvec[%u]=%d lvec[%u]=%d\n", 
                      j, lvec[j], j+1, lvec[j + 1]));
                    if (ret) 
                      ret = false;
                  }
              }
          }
          break;
        
        case FOO_B_STAT_NONE:
        default:
          break;
      }
         
    }   

  return ret;
}