summaryrefslogtreecommitdiff
path: root/CIAO/connectors/dds4ccm/tests/TypeSupport/main.cpp
blob: 76fcad830ab1e8e8dc0a3d38dca627ee627567a5 (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
284
285
286
287
288
289
290
// $Id$

#include "ace/OS_main.h"
#include "ace/Log_Msg.h"
#include "ace/Env_Value_T.h"

#include "dds4ccm/impl/ndds/TypeSupport.h"
#include "dds4ccm/impl/ndds/DomainParticipant.h"
#include "dds4ccm/impl/ndds/DomainParticipantFactory.h"

typedef ::CIAO::NDDS::DDS_DomainParticipantFactory_i
    DomainParticipantFactory;

class TestTypeFactory : public ::CIAO::NDDS::DDS_TypeFactory_i
{
  virtual DDS::DataWriter_ptr create_datawriter (DDSDataWriter* ,
                                                  ::DDS::DomainParticipant_ptr ,
                                                  ::DDS::Publisher_ptr )
  {
    return ::DDS::DataWriter::_nil ();
  }

  virtual DDS::DataReader_ptr create_datareader (DDSDataReader* ,
                                                  ::DDS::DomainParticipant_ptr ,
                                                  ::DDS::Subscriber_ptr )
  {
    return ::DDS::DataReader::_nil ();
  }
};

int
ACE_TMAIN (int , ACE_TCHAR **)
{
#if (CIAO_DDS4CCM_NDDS != 1)
  ACE_DEBUG ((LM_DEBUG, "RTI DDS only test\n"));
  return 0;
#endif

  // first turn on or off tracing
  ACE_Env_Value<int> trace (ACE_TEXT("DDS4CCM_TRACE_ENABLE"), 0);
  if (trace)
    {
      DDS4CCM_ENABLE_TRACE ();
    }
  else
    {
      DDS4CCM_DISABLE_TRACE ();
    }
  DDS4CCM_debug_level = 0;

  int ret = 0;

  try
    {
      int domain_id = 0;
      ACE_Env_Value<int> id (ACE_TEXT("DDS4CCM_DEFAULT_DOMAIN_ID"), domain_id);
      domain_id = id;

      DomainParticipantFactory pf;

      ::DDS::DomainParticipantQos qos;
      ::DDS::DomainParticipant_var dp1 = pf.create_participant (
                                            domain_id,
                                            qos,
                                            ::DDS::DomainParticipantListener::_nil (),
                                            0);

      ::DDS::DomainParticipant_var dp2  = pf.create_participant (
                                            domain_id,
                                            qos,
                                            ::DDS::DomainParticipantListener::_nil (),
                                            0);

      const char * type1 = "DataType1";
      const char * type2 = "DataType2";
      const char * type3 = "DataType3";

      TestTypeFactory * f1 = 0;
      TestTypeFactory * f2 = 0;
      TestTypeFactory * f3 = 0;

      ACE_NEW_THROW_EX (f1,
                        TestTypeFactory (),
                        ::CORBA::NO_MEMORY ());
      ACE_NEW_THROW_EX (f2,
                        TestTypeFactory (),
                        ::CORBA::NO_MEMORY ());
      ACE_NEW_THROW_EX (f3,
                        TestTypeFactory (),
                        ::CORBA::NO_MEMORY ());

      /// Register type 1 with f1
      if (::CIAO::NDDS::DDS_TypeSupport_i::register_type(type1, f1, dp1.in()))
        {
          ACE_DEBUG ((LM_DEBUG, "OK - Type <%C> and Factory <%@> for DP1 succesfully registered\n",
                    type1, f1));
        }
      else
        {
          ACE_ERROR ((LM_ERROR, "ERROR - Type <%C> and Factory <%@> for DP1 could not be registered\n",
                    type1, f1));
          ++ret;
        }
      /// DP1 should now contain one type-factory combination

      /// Register the same factory again
      if (::CIAO::NDDS::DDS_TypeSupport_i::register_type(type1, f1, dp1.in()))
        {
          ACE_ERROR ((LM_ERROR, "ERROR - Type <%C> and Factory <%@> for DP1 could be registered\n",
                    type1, f1));
          ++ret;
        }
      else
        {
          ACE_DEBUG ((LM_DEBUG, "OK - Type <%C> and Factory <%@> for DP1 could not be registered\n",
                    type1, f1));
        }
      /// DP1 should now contain one type-factory combination

      /// Register the same factory again but with another name
      if (::CIAO::NDDS::DDS_TypeSupport_i::register_type(type2, f1, dp1.in()))
        {
          ACE_DEBUG ((LM_DEBUG, "OK - Type <%C> and Factory <%@> for DP1 could be registered\n",
                    type2, f1));
        }
      else
        {
          ACE_ERROR ((LM_ERROR, "ERROR - Type <%C> and Factory <%@> for DP1 could not be registered\n",
                    type2, f1));
          ++ret;
        }
      /// DP1 should now contain two type-factory combinations

      /// Register the same type with another factory
      if (::CIAO::NDDS::DDS_TypeSupport_i::register_type(type2, f2, dp1.in()))
        {
          ACE_ERROR ((LM_ERROR, "ERROR - Type <%C>  and Factory <%@> for DP1 could be registered\n",
                    type2, f2));
          ++ret;
        }
      else
        {
          ACE_DEBUG ((LM_DEBUG, "OK - Type <%C> and Factory <%@> for DP1 could not be registered\n",
                    type2, f2));
        }
      /// DP1 should now contain two type-factory combinations

      /// Just register type 3 with f3
      if (::CIAO::NDDS::DDS_TypeSupport_i::register_type(type3, f3, dp1.in()))
        {
          ACE_DEBUG ((LM_DEBUG, "OK - Type <%C> and Factory <%@> for DP1 succesfully registered\n",
                    type3, f3));
        }
      else
        {
          ACE_ERROR ((LM_ERROR, "ERROR - Type <%C> and Factory <%@> for DP1 could not be registered\n",
                    type3, f3));
          ++ret;
        }
      /// DP1 should now contain three type-factory combinations



      /// Unregister an unused factory by using an unused domain participant
      ::CIAO::NDDS::DDS_TypeFactory_i * tmp = ::CIAO::NDDS::DDS_TypeSupport_i::unregister_type(type1, dp2.in());

      if (tmp)
        {
          ACE_ERROR ((LM_ERROR, "ERROR - Unregistered type <%C> for DP2 could be unregistered\n",
                    type1));
          ++ret;
        }
      else
        {
          ACE_DEBUG ((LM_DEBUG, "OK - Unregistered type <%C> for DP2 could not be unregistered\n",
                    type1));
        }

      /// Unregister a registered type by using a used domain participant
      tmp = ::CIAO::NDDS::DDS_TypeSupport_i::unregister_type(type1, dp1.in());

      if (tmp)
        {
          ACE_DEBUG ((LM_DEBUG, "OK - Unregistered type <%C> for DP1 could be unregistered\n",
                    type1));
        }
      else
        {
          ACE_ERROR ((LM_ERROR, "ERROR - Unregistered type <%C> for DP1 could not be unregistered\n",
                    type1));
          ++ret;
        }
      /// DP1 should now contain two type-factory combinations

      /// Unregister a the same type and domain participant again
      tmp = ::CIAO::NDDS::DDS_TypeSupport_i::unregister_type(type1, dp1.in());

      if (tmp)
        {
          ACE_ERROR ((LM_ERROR, "ERROR - Unregistered type <%C> for DP1 could be unregistered\n",
                    type1));
          ++ret;
        }
      else
        {
          ACE_DEBUG ((LM_DEBUG, "OK - Unregistered type <%C> for DP1 could not be unregistered\n",
                    type1));
        }
      /// DP1 should now contain two type-factory combinations

      /// Call Close on TypeSupport. This should remove the last remaining entries.
      ::CIAO::NDDS::DDS_TypeSupport_i::close();

      /// Unregister the type and domain participant which should be removed by 'close'
      tmp = ::CIAO::NDDS::DDS_TypeSupport_i::unregister_type(type2, dp1.in());

      if (tmp)
        {
          ACE_ERROR ((LM_ERROR, "ERROR - Deleted type <%C> for DP1 could be unregistered\n",
                    type2));
          ++ret;
        }
      else
        {
          ACE_DEBUG ((LM_DEBUG, "OK - Deleted type <%C> for DP1 could not be unregistered\n",
                    type2));
        }

      /// Unregister the type and domain participant which should be removed by 'close'
      tmp = ::CIAO::NDDS::DDS_TypeSupport_i::unregister_type(type3, dp1.in());

      if (tmp)
        {
          ACE_ERROR ((LM_ERROR, "ERROR - Deleted type <%C> for DP1 could be unregistered\n",
                    type3));
          ++ret;
        }
      else
        {
          ACE_DEBUG ((LM_DEBUG, "OK - Deleted type <%C> for DP1 could not be unregistered\n",
                    type3));
        }

      /// We should now be able to register type 3 again
      if (::CIAO::NDDS::DDS_TypeSupport_i::register_type(type3, f3, dp1.in()))
        {
          ACE_DEBUG ((LM_DEBUG, "OK - Type <%C> and Factory <%@> for DP1 succesfully registered\n",
                    type3, f3));
        }
      else
        {
          ACE_ERROR ((LM_ERROR, "ERROR - Type <%C> and Factory <%@> for DP1 could not be registered\n",
                    type3, f3));
          ++ret;
        }
      /// DP1 should now contain one type-factory combination

      /// Call Close on TypeSupport. This should remove the last remaining entries.
      ::CIAO::NDDS::DDS_TypeSupport_i::close();

      delete f3;
      delete f2;
      delete f1;

      pf.delete_participant(dp1);
      pf.delete_participant(dp2);
    }
  catch (const ::CORBA::Exception& e)
    {
      e._tao_print_exception ("ACE_TMAIN - Caught unexpected "
                              "CORBA exception\n");
      return 1;
    }
  catch (...)
    {
      ACE_ERROR ((LM_ERROR, "ACE_TMAIN - ERROR: Caught unexpected "
                            "exception\n"));
      return 1;
    }
  if (ret == 0)
    {
      ACE_DEBUG ((LM_DEBUG, "Test passed !\n"));
    }
  else
    {
      ACE_ERROR ((LM_ERROR, "%d errors found during test. \n",
                  ret));
    }
  return ret;
}