summaryrefslogtreecommitdiff
path: root/tests/Alt_Mapping/ub_struct_seq.cpp
blob: 87b1dcb498b29dc2bd2b6c0b7ceef33eba4068c6 (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

// ============================================================================
//
// = LIBRARY
//    TAO/tests/Alt_Mapping
//
// = FILENAME
//    ub_struct_seq.cpp
//
// = DESCRIPTION
//    tests unbounded struct sequences
//
// = AUTHORS
//      Aniruddha Gokhale
//      Jeff Parsons
//
// ============================================================================


#include "helper.h"
#include "ub_struct_seq.h"

// ************************************************************************
//               Test_Struct_Sequence
// ************************************************************************

Test_Unbounded_Struct_Sequence::Test_Unbounded_Struct_Sequence (
  void)
  : opname_ (CORBA::string_dup ("test_struct_sequence"))
{
}

Test_Unbounded_Struct_Sequence::~Test_Unbounded_Struct_Sequence (
  void)
{
  CORBA::string_free (this->opname_);
  this->opname_ = 0;
}

const char *
Test_Unbounded_Struct_Sequence::opname (void) const
{
  return this->opname_;
}

int
Test_Unbounded_Struct_Sequence::init_parameters (Alt_Mapping_ptr)
{
  Generator *gen = GENERATOR::instance (); // value generator

  // Get some sequence length (not more than 10).
  CORBA::ULong len = (CORBA::ULong) (gen->gen_long () % 10) + 1;

  // set the length of the sequence
  this->in_.resize (len);
  this->inout_.resize (len);

  // Now set each individual element.
  for (CORBA::ULong i = 0; i < this->in_.size (); i++)
    {
      // Generate some arbitrary struct to be filled into the ith location in
      // the sequence.
      this->in_[i] = gen->gen_fixed_struct ();
      this->inout_[i] = gen->gen_fixed_struct ();
    }

  return 0;
}

int
Test_Unbounded_Struct_Sequence::reset_parameters (void)
{
  this->inout_.clear ();
  this->out_.clear ();
  this->ret_.clear ();

  return 0;
}

int
Test_Unbounded_Struct_Sequence::run_sii_test (
  Alt_Mapping_ptr objref)
{
  try
    {
      this->ret_ = objref->test_struct_sequence (this->in_,
                                                 this->inout_,
                                                 this->out_);

      return 0;
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Test_Struct_Sequence::run_sii_test\n");

    }
    
  return -1;
}

CORBA::Boolean
Test_Unbounded_Struct_Sequence::check_validity (void)
{
  return (this->compare (this->in_, this->inout_)
          && this->compare (this->in_, this->out_)
          && this->compare (this->in_, this->ret_));
}

void
Test_Unbounded_Struct_Sequence::print_values (void)
{
  ACE_DEBUG ((LM_DEBUG,
              "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
              "IN sequence\n"));
  this->print_sequence (this->in_);
  ACE_DEBUG ((LM_DEBUG,
              "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
              "INOUT sequence\n"));
  this->print_sequence (this->inout_);
  ACE_DEBUG ((LM_DEBUG,
              "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
              "OUT sequence\n"));
  this->print_sequence (this->out_);
  ACE_DEBUG ((LM_DEBUG,
              "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
              "RET sequence\n"));
  this->print_sequence (this->ret_);
}

CORBA::Boolean
Test_Unbounded_Struct_Sequence::compare (
  const Alt_Mapping::StructSeq &s1,
  const Alt_Mapping::StructSeq &s2)
{
  ACE_CDR::ULong s1v = s1.capacity ();
  ACE_CDR::ULong s2v = s2.capacity ();

  if (s1v != s2v)
    {
      return false;
    }

  s1v = s1.size ();
  s2v = s2.size ();

  if (s1v != s2v)
    {
      return false;
    }

  for (CORBA::ULong i=0; i < s1.size (); i++)
    {
      const Alt_Mapping::Fixed_Struct& vs1 = s1[i];
      const Alt_Mapping::Fixed_Struct& vs2 = s2[i];

      if (vs1.l != vs2.l
          || vs1.c != vs2.c
          || vs1.s != vs2.s
          || vs1.o != vs2.o
          || !ACE::is_equal (vs1.f, vs2.f)
          || vs1.b != vs2.b
          || !ACE::is_equal (vs1.d, vs2.d))
        return false;
    }

  return true; // success
}

void
Test_Unbounded_Struct_Sequence::print_sequence (
  const Alt_Mapping::StructSeq &s)
{
  ACE_DEBUG ((LM_DEBUG,
              "maximum = %d\n"
              "length = %d\n",
              s.capacity (),
              s.size ()));
  ACE_DEBUG ((LM_DEBUG, "Elements -\n"));

  for (CORBA::ULong i = 0; i < s.size (); i++)
    {
      const Alt_Mapping::Fixed_Struct& vs = s[i];

      ACE_DEBUG ((LM_DEBUG,
                  "Element #%d\n"
                  "\tl = %d\n"
                  "\tc = %c\n"
                  "\ts = %d\n"
                  "\to = %x\n"
                  "\tf = %f\n"
                  "\tb = %d\n"
                  "\td = %f\n",
                  i,
                  vs.l, vs.c, vs.s, vs.o, vs.f, vs.b, vs.d));
    }
}