Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Bug_3821_Regression / test.cpp
blobb25544377c1fa8887919ed86638d41aa999b6a04
1 #include "testC.h"
2 #include "tao/CDR.h"
4 namespace
6 template<typename T>
7 int
8 marshal (TAO_OutputCDR &out, T const &t)
10 if (!(out << t))
12 ACE_ERROR_RETURN ((LM_ERROR,
13 "ERROR: Cannot marshal\n"),
14 -1);
16 return 0;
19 template<typename T>
20 int
21 demarshal (TAO_InputCDR &in, T &t,
22 test::Enumeration wrong_disc,
23 test::Enumeration expect_disc)
25 if (!(in >> t))
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "ERROR: Cannot demarshal (test::Enumeration)\n"),
29 -1);
31 if (t._d () == wrong_disc || t._d () != expect_disc)
33 ACE_ERROR_RETURN ((LM_ERROR,
34 "ERROR: Demarshalled (test::Enumeration) _d=%d, wrong=%d, expected=%d\n",
35 t._d (), wrong_disc, expect_disc),
36 -1);
38 return 0;
41 template<typename T>
42 int
43 demarshal (TAO_InputCDR &in, T &t,
44 CORBA::Boolean wrong_disc,
45 CORBA::Boolean expect_disc)
47 if (!(in >> t))
49 ACE_ERROR_RETURN ((LM_ERROR,
50 "ERROR: Cannot demarshal (CORBA::Boolean)\n"),
51 -1);
53 if (t._d () == wrong_disc || t._d () != expect_disc)
55 ACE_ERROR_RETURN ((LM_ERROR,
56 "ERROR: Demarshalled (CORBA::Boolean) _d=%d, wrong=%d, expected=%d\n",
57 t._d (), wrong_disc, expect_disc),
58 -1);
60 return 0;
63 template<typename T>
64 int
65 demarshal (TAO_InputCDR &in, T &t,
66 CORBA::Char wrong_disc,
67 CORBA::Char expect_disc)
69 if (!(in >> t))
71 ACE_ERROR_RETURN ((LM_ERROR,
72 "ERROR: Cannot demarshal (CORBA::Char)\n"),
73 -1);
75 if (t._d () == wrong_disc || t._d () != expect_disc)
77 ACE_ERROR_RETURN ((LM_ERROR,
78 "ERROR: Demarshalled (CORBA::Char) _d=%d, wrong=%d, expected=%d\n",
79 t._d (), wrong_disc, expect_disc),
80 -1);
82 return 0;
85 template<typename T>
86 int
87 demarshal (TAO_InputCDR &in, T &t,
88 CORBA::Long wrong_disc,
89 CORBA::Long expect_disc)
91 if (!(in >> t))
93 ACE_ERROR_RETURN ((LM_ERROR,
94 "ERROR: Cannot demarshal (CORBA::Long)\n"),
95 -1);
97 if (t._d () == wrong_disc || t._d () != expect_disc)
99 ACE_ERROR_RETURN ((LM_ERROR,
100 "ERROR: Demarshalled (CORBA::Long) _d=%d, wrong=%d, expected=%d\n",
101 t._d (), wrong_disc, expect_disc),
102 -1);
104 return 0;
109 ACE_TMAIN (int, ACE_TCHAR *[])
111 int error= 0;
115 // Marshal part.
117 TAO_OutputCDR cdr_out;
119 test::UnionAllCovered_EnumerationDiscriminant uac_ed_out;
120 // UnionAllCovered_EnumerationDiscriminant must have _default()
121 // despite it has cases for all possible
122 // values of enumeration. But since enumeration is just int it has
123 // much more values than those listed in IDL.
124 uac_ed_out._default ();
125 marshal (cdr_out, uac_ed_out);
127 test::UnionAllCovered_EnumerationDiscriminant uac_ed2_out;
128 uac_ed2_out._d (static_cast<test::Enumeration> (10));
129 marshal (cdr_out, uac_ed2_out);
131 test::UnionWithDefault_EnumerationDiscriminant uwd_ed_out;
132 uwd_ed_out._d (static_cast<test::Enumeration> (20));
133 marshal (cdr_out, uwd_ed_out);
135 test::UnionWithImplicitDefault_EnumerationDiscriminant uwid_ed_out;
136 uwid_ed_out._default ();
137 marshal (cdr_out, uwid_ed_out);
139 test::UnionWithImplicitDefault_EnumerationDiscriminant uwid_ed2_out;
140 uwid_ed2_out._d (static_cast<test::Enumeration> (30));
141 marshal (cdr_out, uwid_ed2_out);
143 test::UnionAllCovered_TypedefedEnumerationDiscriminant uac_ted_out;
144 // UnionAllCovered_TypedefedEnumerationDiscriminant must have _default()
145 // despite it has cases for all possible
146 // values of enumeration. But since enumeration is just int it has
147 // much more values than those listed in IDL.
148 uac_ted_out._default ();
149 marshal (cdr_out, uac_ted_out);
151 test::UnionAllCovered_TypedefedEnumerationDiscriminant uac_ted2_out;
152 uac_ted2_out._d (static_cast<test::Enumeration> (40));
153 marshal (cdr_out, uac_ted2_out);
155 test::UnionWithDefault_TypedefedEnumerationDiscriminant uwd_ted_out;
156 uwd_ted_out._d (static_cast<test::Enumeration> (50));
157 marshal (cdr_out, uwd_ted_out);
159 test::UnionWithImplicitDefault_TypedefedEnumerationDiscriminant uwid_ted_out;
160 uwid_ted_out._default ();
161 marshal (cdr_out, uwid_ted_out);
163 test::UnionWithImplicitDefault_TypedefedEnumerationDiscriminant uwid_ted2_out;
164 uwid_ted2_out._d (static_cast<test::Enumeration> (60));
165 marshal (cdr_out, uwid_ted2_out);
167 test::UnionAllCovered_BooleanDiscriminant uac_bd_out;
168 // uac_bd_out._default (); // no _default() since all labels are covered.
169 uac_bd_out._d (static_cast<CORBA::Boolean> (3));
170 marshal (cdr_out, uac_bd_out);
172 test::UnionAllCovered_BooleanDiscriminant uac_bd2_out;
173 uac_bd2_out._d (static_cast<CORBA::Boolean> (5));
174 marshal (cdr_out, uac_bd2_out);
176 test::UnionWithDefault_BooleanDiscriminant uwd_bd_out;
177 uwd_bd_out._d (static_cast<CORBA::Boolean> (7));
178 marshal (cdr_out, uwd_bd_out);
180 test::UnionWithImplicitDefault_BooleanDiscriminant uwid_bd_out;
181 uwid_bd_out._default ();
182 marshal (cdr_out, uwid_bd_out);
184 test::UnionWithImplicitDefault_BooleanDiscriminant uwid_bd2_out;
185 uwid_bd2_out._d (static_cast<CORBA::Boolean> (9));
186 marshal (cdr_out, uwid_bd2_out);
188 test::UnionAllCovered_CharDiscriminant uac_cd_out;
189 // uac_cd_out._default (); // no _default() since all labels are covered.
190 marshal (cdr_out, uac_cd_out);
192 test::UnionAllCovered_CharDiscriminant uac_cd2_out;
193 uac_cd2_out._d (100);
194 marshal (cdr_out, uac_cd2_out);
196 test::UnionWithDefault_CharDiscriminant uwd_cd_out;
197 uwd_cd_out._d (110);
198 marshal (cdr_out, uwd_cd_out);
200 test::UnionWithImplicitDefault_CharDiscriminant uwid_cd_out;
201 uwid_cd_out._default ();
202 marshal (cdr_out, uwid_cd_out);
204 test::UnionWithImplicitDefault_CharDiscriminant uwid_cd2_out;
205 uwid_cd2_out._d (120);
206 marshal (cdr_out, uwid_cd2_out);
208 test::UnionWithDefault_LongDiscriminant uwd_ld_out;
209 uwd_ld_out._d (1000);
210 marshal (cdr_out, uwd_ld_out);
212 test::UnionWithImplicitDefault_LongDiscriminant uwid_ld_out;
213 uwid_ld_out._default ();
214 marshal (cdr_out, uwid_ld_out);
216 test::UnionWithImplicitDefault_LongDiscriminant uwid_ld2_out;
217 uwid_ld2_out._d (2000);
218 marshal (cdr_out, uwid_ld2_out);
220 // Demarshal part.
222 TAO_InputCDR cdr_in (cdr_out);
224 test::UnionAllCovered_EnumerationDiscriminant uac_ed_in;
225 uac_ed_in._d (test::Enum1);
226 demarshal (cdr_in, uac_ed_in, test::Enum1, uac_ed_out._d ());
228 test::UnionAllCovered_EnumerationDiscriminant uac_ed2_in;
229 uac_ed2_in._d (test::Enum1);
230 demarshal (cdr_in, uac_ed2_in, test::Enum1, uac_ed2_out._d ());
232 test::UnionWithDefault_EnumerationDiscriminant uwd_ed_in;
233 uwd_ed_in._d (test::Enum1);
234 demarshal (cdr_in, uwd_ed_in, test::Enum1, uwd_ed_out._d ());
236 test::UnionWithImplicitDefault_EnumerationDiscriminant uwid_ed_in;
237 uwid_ed_in._d (test::Enum1);
238 demarshal (cdr_in, uwid_ed_in, test::Enum1, uwid_ed_out._d ());
240 test::UnionWithImplicitDefault_EnumerationDiscriminant uwid_ed2_in;
241 uwid_ed2_in._d (test::Enum1);
242 demarshal (cdr_in, uwid_ed2_in, test::Enum1, uwid_ed2_out._d ());
244 test::UnionAllCovered_TypedefedEnumerationDiscriminant uac_ted_in;
245 uac_ted_in._d (test::Enum1);
246 demarshal (cdr_in, uac_ted_in, test::Enum1, uac_ted_out._d ());
248 test::UnionAllCovered_TypedefedEnumerationDiscriminant uac_ted2_in;
249 uac_ted2_in._d (test::Enum1);
250 demarshal (cdr_in, uac_ted2_in, test::Enum1, uac_ted2_out._d ());
252 test::UnionWithDefault_TypedefedEnumerationDiscriminant uwd_ted_in;
253 uwd_ted_in._d (test::Enum1);
254 demarshal (cdr_in, uwd_ted_in, test::Enum1, uwd_ted_out._d ());
256 test::UnionWithImplicitDefault_TypedefedEnumerationDiscriminant uwid_ted_in;
257 uwid_ted_in._d (test::Enum1);
258 demarshal (cdr_in, uwid_ted_in, test::Enum1, uwid_ted_out._d ());
260 test::UnionWithImplicitDefault_TypedefedEnumerationDiscriminant uwid_ted2_in;
261 uwid_ted2_in._d (test::Enum1);
262 demarshal (cdr_in, uwid_ted2_in, test::Enum1, uwid_ted2_out._d ());
264 test::UnionAllCovered_BooleanDiscriminant uac_bd_in;
265 uac_bd_in._d (false);
266 demarshal (cdr_in, uac_bd_in, false, uac_bd_out._d ());
268 test::UnionAllCovered_BooleanDiscriminant uac_bd2_in;
269 uac_bd2_in._d (false);
270 demarshal (cdr_in, uac_bd2_in, false, uac_bd2_out._d ());
272 test::UnionWithDefault_BooleanDiscriminant uwd_bd_in;
273 uwd_bd_in._d (false);
274 demarshal (cdr_in, uwd_bd_in, false, uwd_bd_out._d ());
276 test::UnionWithImplicitDefault_BooleanDiscriminant uwid_bd_in;
277 uwid_bd_in._d (true);
278 demarshal (cdr_in, uwid_bd_in, true, uwid_bd_out._d ());
280 test::UnionWithImplicitDefault_BooleanDiscriminant uwid_bd2_in;
281 uwid_bd2_in._d (false);
282 demarshal (cdr_in, uwid_bd2_in, false, uwid_bd2_out._d ());
284 test::UnionAllCovered_CharDiscriminant uac_cd_in;
285 uac_cd_in._d ('a');
286 demarshal (cdr_in, uac_cd_in, 'a', uac_cd_out._d ());
288 test::UnionAllCovered_CharDiscriminant uac_cd2_in;
289 uac_cd2_in._d ('a');
290 demarshal (cdr_in, uac_cd2_in, 'a', uac_cd2_out._d ());
292 test::UnionWithDefault_CharDiscriminant uwd_cd_in;
293 uwd_cd_in._d ('\1');
294 demarshal (cdr_in, uwd_cd_in, '\1', uwd_cd_out._d ());
296 test::UnionWithImplicitDefault_CharDiscriminant uwid_cd_in;
297 uwid_cd_in._d ('\1');
298 demarshal (cdr_in, uwid_cd_in, '\1', uwid_cd_out._d ());
300 test::UnionWithImplicitDefault_CharDiscriminant uwid_cd2_in;
301 uwid_cd2_in._d ('\1');
302 demarshal (cdr_in, uwid_cd2_in, '\1', uwid_cd2_out._d ());
304 test::UnionWithDefault_LongDiscriminant uwd_ld_in;
305 uwd_ld_in._d (1);
306 demarshal (cdr_in, uwd_ld_in, 1, uwd_ld_out._d ());
308 test::UnionWithImplicitDefault_LongDiscriminant uwid_ld_in;
309 uwid_ld_in._d (1);
310 demarshal (cdr_in, uwid_ld_in, 1, uwid_ld_out._d ());
312 test::UnionWithImplicitDefault_LongDiscriminant uwid_ld2_in;
313 uwid_ld2_in._d (1);
314 demarshal (cdr_in, uwid_ld2_in, 1, uwid_ld2_out._d ());
316 catch (const CORBA::Exception& ex)
318 ex._tao_print_exception ("Exception caught:");
319 error= 1;
322 return error;