Use override/default for RTPortableServer
[ACE_TAO.git] / ACE / tests / CDR_Test.cpp
blobc9fcf68dcf2ae780280ce2ce6f4eba022f46eda2
2 //=============================================================================
3 /**
4 * @file CDR_Test.cpp
6 * Checks the functionality of the ACE CDR streams.
8 * @author Istvan Buki <istvan.buki@euronet.be> and Jeff Parsons <parsons@cs.wustl.edu> and Carlos O'Ryan <coryan@cs.wustl.edu>
9 */
10 //=============================================================================
13 #include "test_config.h"
14 #include "ace/Get_Opt.h"
15 #include "ace/Auto_Ptr.h"
16 #include "ace/CDR_Stream.h"
17 #include "ace/CDR_Size.h"
18 #include "ace/SString.h"
19 #include "ace/ACE.h"
20 #include "ace/OS_NS_stdlib.h"
21 #include "ace/OS_NS_string.h"
22 #include "ace/OS_NS_wchar.h"
25 static int n = 4096;
26 static int nloops = 100;
28 struct CDR_Test_Types
30 CDR_Test_Types ();
32 ACE_CDR::Octet o;
33 ACE_CDR::Short s;
34 ACE_CDR::Long l;
35 const ACE_CDR::Char *str;
36 const ACE_CDR::WChar *wstr;
37 const std::string std_str;
38 #if !defined(ACE_LACKS_STD_WSTRING)
39 const std::wstring std_wstr;
40 #endif
41 ACE_CDR::Double d;
42 ACE_CDR::Short reps;
43 ACE_CDR::UShort repus;
44 ACE_CDR::Long repl;
45 ACE_CDR::ULong repul;
46 ACE_CDR::Boolean repb;
47 const ACE_CDR::Char repc;
48 ACE_CDR::LongLong repll;
49 ACE_CDR::ULongLong repull;
50 ACE_CDR::Octet repo;
51 ACE_CDR::Float repf;
52 ACE_CDR::Double repd;
54 int test_put (ACE_OutputCDR& cdr);
55 int test_get (ACE_InputCDR& cdr) const;
56 int test_put_placeholder (ACE_OutputCDR& cdr);
57 int test_get_placeholder (ACE_InputCDR& cdr) const;
59 enum
61 ARRAY_SIZE = 10
64 ACE_CDR::Short a[ARRAY_SIZE];
67 CDR_Test_Types::CDR_Test_Types ()
68 : o (1),
69 s (2),
70 l (4),
71 str ("abc"),
72 wstr (0),
73 std_str ("xyz"),
74 #if !defined(ACE_LACKS_STD_WSTRING)
75 std_wstr (L"xyz"),
76 #endif
77 d (8),
78 reps (-123),
79 repus (456),
80 repl (-65800L),
81 repul (65800L),
82 repb (false),
83 repc ('d'),
84 repll (-5000000000LL),
85 repull (5000000000LL),
86 repo (05),
87 repf (3.14F),
88 repd (6.00)
90 for (int i = 0;
91 i < CDR_Test_Types::ARRAY_SIZE;
92 ++i)
93 a[i] = i;
96 static int
97 short_stream ()
99 // counter
100 u_int i;
102 // Build an output stream
103 ACE_OutputCDR os;
104 ACE_SizeCDR ss;
106 // Basic types for output
107 ACE_CDR::Char ch = 'A';
108 ACE_CDR::Char wchtmp[] = {'\xF3'};
109 ACE_CDR::WChar wch = *wchtmp;
110 ACE_CDR::WChar wchar2[] = {'\x00'}; // empty wide string
111 ACE_CDR::WChar *wstr = wchar2;
112 ACE_CString str ("Test String");
113 std::string std_str ("std string");
114 #if !defined(ACE_LACKS_STD_WSTRING)
115 std::wstring std_wstr (L"std wstring");
116 #endif
117 ACE_CDR::Short s = -123;
118 ACE_CDR::UShort us = 123;
119 ACE_CDR::Long l = -65800L;
120 ACE_CDR::ULong ul = 65800UL;
121 ACE_CDR::Float f = 1.23f;
122 ACE_CDR::Double d = 123.456789;
123 ACE_CDR::Fixed fx = ACE_CDR::Fixed::from_string ("8158901571290874");
125 // Arrays for output
126 ACE_CDR::Short s_array[3] = { -1, 0, 1 };
127 ACE_CDR::Long l_array[3] = { -345678, 0, 345678 };
128 ACE_CDR::Float f_array[3] = { -1.23f, 0.0f, 1.23f };
129 ACE_CDR::Double d_array[3] = { -123.456789, 0.0, 123.456789 };
130 ACE_CDR::Boolean b_array[3] = { false, true, false };
132 ACE_OutputCDR::from_char fc (ch);
133 ACE_OutputCDR::from_wchar fwc (wch);
134 os << fc;
135 os << fwc;
136 os << str;
137 os << wstr;
138 os << std_str;
139 #if !defined(ACE_LACKS_STD_WSTRING)
140 os << std_wstr;
141 #endif
142 os << s;
143 os << us;
144 os << l;
145 os << ul;
146 os << f;
147 os << d;
148 os << fx;
149 os.write_short_array (s_array, 3);
150 os.write_long_array (l_array, 3);
151 os.write_float_array (f_array, 3);
152 os.write_double_array (d_array, 3);
153 os.write_boolean_array (b_array, 3);
155 // Do the same for size stream.
156 ss << fc;
157 ss << fwc;
158 ss << str;
159 ss << wstr;
160 ss << std_str;
161 #if !defined(ACE_LACKS_STD_WSTRING)
162 ss << std_wstr;
163 #endif
164 ss << s;
165 ss << us;
166 ss << l;
167 ss << ul;
168 ss << f;
169 ss << d;
170 ss << fx;
171 ss.write_short_array (s_array, 3);
172 ss.write_long_array (l_array, 3);
173 ss.write_float_array (f_array, 3);
174 ss.write_double_array (d_array, 3);
175 ss.write_boolean_array (b_array, 3);
177 // Check the size.
178 if (ss.total_length () != os.total_length ())
179 ACE_ERROR_RETURN ((LM_ERROR,
180 ACE_TEXT ("%p\n"),
181 ACE_TEXT ("representation length does not match")),
184 const ACE_Message_Block *out_mb = os.begin ();
185 size_t len = out_mb->length ();
187 // Create an input stream (copy constructor)
188 ACE_InputCDR is (os);
189 const ACE_Message_Block *in_mb = is.start ();
191 if (in_mb->length () != len)
192 ACE_ERROR_RETURN ((LM_ERROR,
193 ACE_TEXT ("%p\n"),
194 ACE_TEXT ("buffer length not preserved")),
197 for (i = 0; i < len; i++)
199 unsigned long const in_chunk =
200 static_cast<unsigned long> (* (in_mb->rd_ptr () + i));
202 unsigned long const out_chunk =
203 static_cast<unsigned long> (* (out_mb->rd_ptr () + i));
205 if (in_chunk != out_chunk)
206 ACE_ERROR_RETURN ((LM_ERROR,
207 ACE_TEXT ("%p\n"),
208 ACE_TEXT ("buffer contents not preserved")),
212 // Basic types for input
213 ACE_CDR::Char ch1 = '\0';
214 ACE_CDR::WChar wch1 = '\x00';
215 ACE_CDR::WChar *wstr1 = 0;
216 ACE_CString str1;
217 std::string std_str1;
218 #if !defined(ACE_LACKS_STD_WSTRING)
219 std::wstring std_wstr1;
220 #endif
221 ACE_CDR::Short s1 = 0;
222 ACE_CDR::UShort us1 = 0;
223 ACE_CDR::Long l1 = 0L;
224 ACE_CDR::ULong ul1 = 0UL;
225 ACE_CDR::Float f1 = 0.0f;
226 ACE_CDR::Double d1 = 0.0;
227 ACE_CDR::Fixed fx1 = ACE_CDR::Fixed::from_string ("0");
229 // Arrays for input
230 ACE_CDR::Short s_array1[3];
231 ACE_CDR::Long l_array1[3];
232 ACE_CDR::Float f_array1[3];
233 ACE_CDR::Double d_array1[3];
235 ACE_DEBUG ((LM_DEBUG,
236 ACE_TEXT ("Checking operators and arrays\n\n")));
238 ACE_InputCDR::to_char tc (ch1);
239 is >> tc;
240 ACE_InputCDR::to_wchar twc (wch1);
241 is >> twc;
242 is >> str1;
243 ACE_InputCDR::to_wstring twstr (wstr1, 0);
244 is >> twstr;
245 // @todo Lose the ACE_Auto_Array_Ptr. We should be using a
246 // std::string, or the like.
247 ACE_Auto_Array_Ptr<ACE_CDR::WChar> safe_wstr (wstr1);
248 is >> std_str1;
249 #if !defined(ACE_LACKS_STD_WSTRING)
250 is >> std_wstr1;
251 #endif
252 is >> s1;
253 is >> us1;
254 is >> l1;
255 is >> ul1;
256 is >> f1;
257 is >> d1;
258 is >> fx1;
259 is.read_short_array (s_array1, 3);
260 is.read_long_array (l_array1, 3);
261 is.read_float_array (f_array1, 3);
262 is.read_double_array (d_array1, 3);
264 if (ch1 != ch)
265 ACE_ERROR_RETURN ((LM_ERROR,
266 ACE_TEXT ("%p\n"),
267 ACE_TEXT ("char transfer error")),
270 if (wch1 != wch)
271 ACE_ERROR_RETURN ((LM_ERROR,
272 ACE_TEXT ("%p\n"),
273 ACE_TEXT ("wchar transfer error")),
276 if (str1 != str)
277 ACE_ERROR_RETURN ((LM_ERROR,
278 ACE_TEXT ("%p\n"),
279 ACE_TEXT ("string transfer error")),
282 if (ACE_OS::wscmp (wstr1, wstr))
283 ACE_ERROR_RETURN ((LM_ERROR,
284 ACE_TEXT ("%p\n"),
285 ACE_TEXT ("wide string transfer error")),
288 if (std_str1 != std_str)
289 ACE_ERROR_RETURN ((LM_ERROR,
290 ACE_TEXT ("%p\n"),
291 ACE_TEXT ("std::string transfer error")),
294 #if !defined(ACE_LACKS_STD_WSTRING)
295 if (std_wstr1 != std_wstr)
296 ACE_ERROR_RETURN ((LM_ERROR,
297 ACE_TEXT ("%p\n"),
298 ACE_TEXT ("std::wstring transfer error")),
300 #endif
302 if (s1 != s)
303 ACE_ERROR_RETURN ((LM_ERROR,
304 ACE_TEXT ("%p\n"),
305 ACE_TEXT ("short transfer error")),
308 if (us1 != us)
309 ACE_ERROR_RETURN ((LM_ERROR,
310 ACE_TEXT ("%p\n"),
311 ACE_TEXT ("ushort transfer error")),
314 if (l1 != l)
315 ACE_ERROR_RETURN ((LM_ERROR,
316 ACE_TEXT ("%p\n"),
317 ACE_TEXT ("long transfer error")),
320 if (ul1 != ul)
321 ACE_ERROR_RETURN ((LM_ERROR,
322 ACE_TEXT ("%p\n"),
323 ACE_TEXT ("ulong transfer error")),
326 if (!ACE::is_equal (f1, f))
327 ACE_ERROR_RETURN ((LM_ERROR,
328 ACE_TEXT ("%p\n"),
329 ACE_TEXT ("float transfer error")),
332 if (!ACE::is_equal (d1, d))
333 ACE_ERROR_RETURN ((LM_ERROR,
334 ACE_TEXT ("%p\n"),
335 ACE_TEXT ("double transfer error")),
338 if (fx1 != fx)
339 ACE_ERROR_RETURN ((LM_ERROR,
340 ACE_TEXT ("%p\n"),
341 ACE_TEXT ("fixed transfer error")),
344 for (i = 0 ; i < 3; i++)
345 if (s_array1[i] != s_array[i])
346 ACE_ERROR_RETURN ((LM_ERROR,
347 ACE_TEXT ("%p\n"),
348 ACE_TEXT ("short array transfer error")),
351 for (i = 0 ; i < 3; i++)
352 if (l_array1[i] != l_array[i])
353 ACE_ERROR_RETURN ((LM_ERROR,
354 ACE_TEXT ("%p\n"),
355 ACE_TEXT ("long array transfer error")),
358 for (i = 0 ; i < 3; i++)
359 if (!ACE::is_equal (f_array1[i], f_array[i]))
360 ACE_ERROR_RETURN ((LM_ERROR,
361 ACE_TEXT ("%p\n"),
362 ACE_TEXT ("float array transfer error")),
365 for (i = 0 ; i < 3; i++)
366 if (!ACE::is_equal (d_array1[i], d_array[i]))
367 ACE_ERROR_RETURN ((LM_ERROR,
368 ACE_TEXT ("%p\n"),
369 ACE_TEXT ("double array transfer error")),
372 return 0;
376 CDR_Test_Types::test_put (ACE_OutputCDR &cdr)
378 for (int i = 0; i < n; ++i)
380 if (cdr.write_octet (this->o) == 0)
381 ACE_ERROR_RETURN ((LM_ERROR,
382 ACE_TEXT ("write_octet[%d] failed\n"),
385 if (cdr.write_short (this->s) == 0)
386 ACE_ERROR_RETURN ((LM_ERROR,
387 ACE_TEXT ("write_short[%d] failed\n"),
390 if (cdr.write_octet (this->o) == 0)
391 ACE_ERROR_RETURN ((LM_ERROR,
392 ACE_TEXT ("write_octet-2[%d] failed\n"),
395 if (cdr.write_long (this->l) == 0)
396 ACE_ERROR_RETURN ((LM_ERROR,
397 ACE_TEXT ("write_long[%d] failed\n"),
400 if (cdr.write_long (this->l) == 0)
401 ACE_ERROR_RETURN ((LM_ERROR,
402 ACE_TEXT ("write_long-2[%d] failed\n"),
406 if (cdr.write_string (this->str) == 0)
407 ACE_ERROR_RETURN ((LM_ERROR,
408 ACE_TEXT ("write_string[%d] failed\n"),
412 if (cdr.write_wstring (this->wstr) == 0)
413 ACE_ERROR_RETURN ((LM_ERROR,
414 ACE_TEXT ("write_wstring[%d] failed\n"),
418 if (cdr.write_string (this->std_str) == 0)
419 ACE_ERROR_RETURN ((LM_ERROR,
420 ACE_TEXT ("write_string(std)[%d] failed\n"),
424 #if !defined(ACE_LACKS_STD_WSTRING)
425 if (cdr.write_wstring (this->std_wstr) == 0)
426 ACE_ERROR_RETURN ((LM_ERROR,
427 ACE_TEXT ("write_wstring(std)[%d] failed\n"),
430 #endif
433 return 0;
437 CDR_Test_Types::test_get (ACE_InputCDR &cdr) const
439 ACE_CDR::Octet xo;
440 ACE_CDR::Short xs;
441 ACE_CDR::Long xl;
443 for (int i = 0; i < n; ++i)
445 if (cdr.read_octet (xo) == 0)
446 ACE_ERROR_RETURN ((LM_ERROR,
447 ACE_TEXT ("read_octet[%d] failed\n"),
450 if (xo != this->o)
451 ACE_ERROR_RETURN ((LM_ERROR,
452 ACE_TEXT ("octet[%d] differs\n"),
455 if (cdr.read_short (xs) == 0)
456 ACE_ERROR_RETURN ((LM_ERROR,
457 ACE_TEXT ("read_short[%d] failed\n"),
458 i), 1);
459 if (xs != this->s)
460 ACE_ERROR_RETURN ((LM_ERROR,
461 ACE_TEXT ("short[%d] differs\n"),
464 if (cdr.read_octet (xo) == 0)
465 ACE_ERROR_RETURN ((LM_ERROR,
466 ACE_TEXT ("read_octet-2[%d] failed\n"),
469 if (xo != this->o)
470 ACE_ERROR_RETURN ((LM_ERROR,
471 ACE_TEXT ("octet-2[%d] differs\n"),
474 if (cdr.read_long (xl) == 0)
475 ACE_ERROR_RETURN ((LM_ERROR,
476 ACE_TEXT ("read_long[%d] failed\n"),
479 if (xl != this->l)
480 ACE_ERROR_RETURN ((LM_ERROR,
481 ACE_TEXT ("long[%d] differs\n"),
484 if (cdr.read_long (xl) == 0)
485 ACE_ERROR_RETURN ((LM_ERROR,
486 ACE_TEXT ("read_long-2[%d] failed\n"),
489 if (xl != this->l)
490 ACE_ERROR_RETURN ((LM_ERROR,
491 ACE_TEXT ("long-2[%d] differs\n"),
495 ACE_CDR::Char *xstr;
496 if (cdr.read_string (xstr) == 0)
497 ACE_ERROR_RETURN ((LM_ERROR,
498 ACE_TEXT ("read_string2[%d] failed\n"),
501 ACE_Auto_Basic_Array_Ptr<ACE_CDR::Char> auto_xstr (xstr);
502 if (ACE_OS::strcmp (auto_xstr.get (), this->str) != 0)
503 ACE_ERROR_RETURN ((LM_ERROR,
504 ACE_TEXT ("string[%d] differs\n"),
508 ACE_CDR::WChar *wstr1;
509 if (cdr.read_wstring (wstr1) == 0)
510 ACE_ERROR_RETURN ((LM_ERROR,
511 ACE_TEXT ("read_wstring2[%d] failed\n"),
514 // zero length
515 ACE_Auto_Basic_Array_Ptr<ACE_CDR::WChar> auto_xwstr (wstr1);
516 if (ACE_OS::wslen(auto_xwstr.get () ))
517 ACE_ERROR_RETURN ((LM_ERROR,
518 ACE_TEXT ("wstring[%d] differs\n"),
522 std::string std_xstr;
523 if (cdr.read_string (std_xstr) == 0)
524 ACE_ERROR_RETURN ((LM_ERROR,
525 ACE_TEXT ("read_string(std)[%d] failed\n"),
528 if (std_xstr != this->std_str)
529 ACE_ERROR_RETURN ((LM_ERROR,
530 ACE_TEXT ("std::string[%d] differs\n"),
534 #if !defined(ACE_LACKS_STD_WSTRING)
535 std::wstring std_xwstr;
536 if (cdr.read_wstring (std_xwstr) == 0)
537 ACE_ERROR_RETURN ((LM_ERROR,
538 ACE_TEXT ("read_wstring(std)[%d] failed\n"),
541 if (std_xwstr != this->std_wstr)
542 ACE_ERROR_RETURN ((LM_ERROR,
543 ACE_TEXT ("std::wstring[%d] differs\n"),
546 #endif
548 return 0;
552 CDR_Test_Types::test_put_placeholder (ACE_OutputCDR &cdr)
554 // Write a placeholder then a bunch of other stuff, then replace.
555 // Long
556 char *pos = cdr.write_long_placeholder ();
557 if (test_put (cdr) != 0)
558 ACE_ERROR_RETURN ((LM_ERROR,
559 ACE_TEXT ("test_put (long placeholder) failed\n")),
561 if (!cdr.replace (this->repl, pos))
562 ACE_ERROR_RETURN ((LM_ERROR,
563 ACE_TEXT ("replace(long) failed\n")),
566 // ULong
567 pos = cdr.write_long_placeholder ();
568 if (test_put (cdr) != 0)
569 ACE_ERROR_RETURN ((LM_ERROR,
570 ACE_TEXT ("test_put (long placeholder) failed\n")),
572 if (!cdr.replace (this->repul, pos))
573 ACE_ERROR_RETURN ((LM_ERROR,
574 ACE_TEXT ("replace(ulong) failed\n")),
577 // Short
578 pos = cdr.write_short_placeholder ();
579 if (test_put (cdr) != 0)
580 ACE_ERROR_RETURN ((LM_ERROR,
581 ACE_TEXT ("test_put (short placeholder) failed\n")),
583 if (!cdr.replace (this->reps, pos))
584 ACE_ERROR_RETURN ((LM_ERROR,
585 ACE_TEXT ("replace(short) failed\n")),
588 // UShort
589 pos = cdr.write_short_placeholder ();
590 if (test_put (cdr) != 0)
591 ACE_ERROR_RETURN ((LM_ERROR,
592 ACE_TEXT ("test_put (short placeholder) failed\n")),
594 if (!cdr.replace (this->repus, pos))
595 ACE_ERROR_RETURN ((LM_ERROR,
596 ACE_TEXT ("replace(ushort) failed\n")),
599 // Boolean
600 pos = cdr.write_boolean_placeholder ();
601 if (test_put (cdr) != 0)
602 ACE_ERROR_RETURN ((LM_ERROR,
603 ACE_TEXT ("test_put (boolean placeholder) failed\n")),
605 if (!cdr.replace (this->repb, pos))
606 ACE_ERROR_RETURN ((LM_ERROR,
607 ACE_TEXT ("replace(boolean) failed\n")),
610 // Char
611 pos = cdr.write_char_placeholder ();
612 if (test_put (cdr) != 0)
613 ACE_ERROR_RETURN ((LM_ERROR,
614 ACE_TEXT ("test_put (char placeholder) failed\n")),
616 if (!cdr.replace (this->repc, pos))
617 ACE_ERROR_RETURN ((LM_ERROR,
618 ACE_TEXT ("replace(char) failed\n")),
621 // LongLong
622 pos = cdr.write_longlong_placeholder ();
623 if (test_put (cdr) != 0)
624 ACE_ERROR_RETURN ((LM_ERROR,
625 ACE_TEXT ("test_put (longlong placeholder) failed\n")),
627 if (!cdr.replace (this->repll, pos))
628 ACE_ERROR_RETURN ((LM_ERROR,
629 ACE_TEXT ("replace(longlong) failed\n")),
632 // ULongLong
633 pos = cdr.write_longlong_placeholder ();
634 if (test_put (cdr) != 0)
635 ACE_ERROR_RETURN ((LM_ERROR,
636 ACE_TEXT ("test_put (longlong placeholder) failed\n")),
638 if (!cdr.replace (this->repull, pos))
639 ACE_ERROR_RETURN ((LM_ERROR,
640 ACE_TEXT ("replace(ulonglong) failed\n")),
643 // Octet
644 pos = cdr.write_octet_placeholder ();
645 if (test_put (cdr) != 0)
646 ACE_ERROR_RETURN ((LM_ERROR,
647 ACE_TEXT ("test_put (octet placeholder) failed\n")),
649 if (!cdr.replace (this->repo, pos))
650 ACE_ERROR_RETURN ((LM_ERROR,
651 ACE_TEXT ("replace(octet) failed\n")),
654 // Float
655 pos = cdr.write_float_placeholder ();
656 if (test_put (cdr) != 0)
657 ACE_ERROR_RETURN ((LM_ERROR,
658 ACE_TEXT ("test_put (float placeholder) failed\n")),
660 if (!cdr.replace (this->repf, pos))
661 ACE_ERROR_RETURN ((LM_ERROR,
662 ACE_TEXT ("replace(float) failed\n")),
665 // Double
666 pos = cdr.write_double_placeholder ();
667 if (test_put (cdr) != 0)
668 ACE_ERROR_RETURN ((LM_ERROR,
669 ACE_TEXT ("test_put (double placeholder) failed\n")),
671 if (!cdr.replace (this->repd, pos))
672 ACE_ERROR_RETURN ((LM_ERROR,
673 ACE_TEXT ("replace(double) failed\n")),
676 return 0;
680 CDR_Test_Types::test_get_placeholder (ACE_InputCDR &cdr) const
682 ACE_CDR::Short xs;
683 ACE_CDR::UShort xus;
684 ACE_CDR::Long xl;
685 ACE_CDR::ULong xul;
686 ACE_CDR::Boolean xb;
687 ACE_CDR::Char xc;
688 ACE_CDR::LongLong xll;
689 ACE_CDR::ULongLong xull;
690 ACE_CDR::Octet xo;
691 ACE_CDR::Float xf;
692 ACE_CDR::Double xd;
694 if (cdr.read_long (xl) == 0)
695 ACE_ERROR_RETURN ((LM_ERROR,
696 ACE_TEXT ("read_long failed\n")),
698 if (xl != this->repl)
699 ACE_ERROR_RETURN ((LM_ERROR,
700 ACE_TEXT ("replaced long differs\n")),
703 // The bunch of stuff written after the placeholder by test_put_placeholder
704 // should still be valid; check that it is.
705 if (test_get (cdr) != 0)
706 ACE_ERROR_RETURN ((LM_ERROR,
707 ACE_TEXT ("test_get (long) failed\n")),
710 if (cdr.read_ulong (xul) == 0)
711 ACE_ERROR_RETURN ((LM_ERROR,
712 ACE_TEXT ("read_ulong failed\n")), 1);
713 if (xul != this->repul)
714 ACE_ERROR_RETURN ((LM_ERROR,
715 ACE_TEXT ("replaced ulong differs\n")),
718 if (test_get (cdr) != 0)
719 ACE_ERROR_RETURN ((LM_ERROR,
720 ACE_TEXT ("test_get (ulong) failed\n")),
723 if (cdr.read_short (xs) == 0)
724 ACE_ERROR_RETURN ((LM_ERROR,
725 ACE_TEXT ("read_short failed\n")), 1);
726 if (xs != this->reps)
727 ACE_ERROR_RETURN ((LM_ERROR,
728 ACE_TEXT ("replaced short differs\n")),
731 if (test_get (cdr) != 0)
732 ACE_ERROR_RETURN ((LM_ERROR,
733 ACE_TEXT ("test_get (short) failed\n")),
736 if (cdr.read_ushort (xus) == 0)
737 ACE_ERROR_RETURN ((LM_ERROR,
738 ACE_TEXT ("read_ushort failed\n")), 1);
739 if (xus != this->repus)
740 ACE_ERROR_RETURN ((LM_ERROR,
741 ACE_TEXT ("replaced ushort differs\n")),
744 if (test_get (cdr) != 0)
745 ACE_ERROR_RETURN ((LM_ERROR,
746 ACE_TEXT ("test_get (ushort) failed\n")),
749 if (cdr.read_boolean (xb) == 0)
750 ACE_ERROR_RETURN ((LM_ERROR,
751 ACE_TEXT ("read_boolean failed\n")), 1);
752 if (xb != this->repb)
753 ACE_ERROR_RETURN ((LM_ERROR,
754 ACE_TEXT ("replaced boolean differs\n")),
757 if (test_get (cdr) != 0)
758 ACE_ERROR_RETURN ((LM_ERROR,
759 ACE_TEXT ("test_get (boolean) failed\n")),
762 if (cdr.read_char (xc) == 0)
763 ACE_ERROR_RETURN ((LM_ERROR,
764 ACE_TEXT ("read_char failed\n")), 1);
765 if (xc != this->repc)
766 ACE_ERROR_RETURN ((LM_ERROR,
767 ACE_TEXT ("replaced char differs\n")),
770 if (test_get (cdr) != 0)
771 ACE_ERROR_RETURN ((LM_ERROR,
772 ACE_TEXT ("test_get (char) failed\n")),
776 if (cdr.read_longlong (xll) == 0)
777 ACE_ERROR_RETURN ((LM_ERROR,
778 ACE_TEXT ("read_longlong failed\n")), 1);
779 if (xll != this->repll)
780 ACE_ERROR_RETURN ((LM_ERROR,
781 ACE_TEXT ("replaced longlong differs\n")),
784 if (test_get (cdr) != 0)
785 ACE_ERROR_RETURN ((LM_ERROR,
786 ACE_TEXT ("test_get (longlong) failed\n")),
789 if (cdr.read_ulonglong (xull) == 0)
790 ACE_ERROR_RETURN ((LM_ERROR,
791 ACE_TEXT ("read_ulonglong failed\n")), 1);
792 if (xull != this->repull)
793 ACE_ERROR_RETURN ((LM_ERROR,
794 ACE_TEXT ("replaced ulonglong differs\n")),
797 if (test_get (cdr) != 0)
798 ACE_ERROR_RETURN ((LM_ERROR,
799 ACE_TEXT ("test_get (ulonglong) failed\n")),
802 if (cdr.read_octet (xo) == 0)
803 ACE_ERROR_RETURN ((LM_ERROR,
804 ACE_TEXT ("read_octet failed\n")), 1);
805 if (xo != this->repo)
806 ACE_ERROR_RETURN ((LM_ERROR,
807 ACE_TEXT ("replaced octet differs\n")),
810 if (test_get (cdr) != 0)
811 ACE_ERROR_RETURN ((LM_ERROR,
812 ACE_TEXT ("test_get (octet) failed\n")),
815 if (cdr.read_float (xf) == 0)
816 ACE_ERROR_RETURN ((LM_ERROR,
817 ACE_TEXT ("read_float failed\n")), 1);
818 if (xf != this->repf)
819 ACE_ERROR_RETURN ((LM_ERROR,
820 ACE_TEXT ("replaced float differs\n")),
823 if (test_get (cdr) != 0)
824 ACE_ERROR_RETURN ((LM_ERROR,
825 ACE_TEXT ("test_get (float) failed\n")),
828 if (cdr.read_double (xd) == 0)
829 ACE_ERROR_RETURN ((LM_ERROR,
830 ACE_TEXT ("read_double failed\n")), 1);
831 if (xd != this->repd)
832 ACE_ERROR_RETURN ((LM_ERROR,
833 ACE_TEXT ("replaced double differs\n")),
836 if (test_get (cdr) != 0)
837 ACE_ERROR_RETURN ((LM_ERROR,
838 ACE_TEXT ("test_get (double) failed\n")),
841 return 0;
846 run_main (int argc, ACE_TCHAR *argv[])
848 ACE_START_TEST (ACE_TEXT ("CDR_Test"));
850 ACE_DEBUG ((LM_DEBUG,
851 ACE_TEXT ("This is ACE Version %u.%u.%u\n\n"),
852 ACE::major_version (),
853 ACE::minor_version(),
854 ACE::micro_version()));
856 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("dn:l:"));
857 int opt;
858 int debug = 0;
860 while ((opt = get_opt ()) != EOF)
862 switch (opt)
864 case 'd':
865 debug++;
866 break;
867 case 'n':
868 n = ACE_OS::atoi (get_opt.opt_arg ());
869 break;
870 case 'l':
871 nloops = ACE_OS::atoi (get_opt.opt_arg ());
872 break;
873 case '?':
874 default:
875 ACE_DEBUG ((LM_DEBUG,
876 ACE_TEXT ("Usage: %s ")
877 ACE_TEXT ("-d debug")
878 ACE_TEXT ("-n <num> ")
879 ACE_TEXT ("-l <loops> ")
880 ACE_TEXT ("\n"),
881 ACE_TEXT ("CDR_Test")));
882 return -1;
886 // Sanity checks.
887 ACE_TEST_ASSERT (sizeof (ACE_CDR::Boolean) >= 1);
888 ACE_TEST_ASSERT (sizeof (ACE_CDR::Octet) == 1);
889 ACE_TEST_ASSERT (sizeof (ACE_CDR::WChar) >= 2);
890 ACE_TEST_ASSERT (sizeof (ACE_CDR::Short) == 2);
891 ACE_TEST_ASSERT (sizeof (ACE_CDR::Long) == 4);
892 ACE_TEST_ASSERT (sizeof (ACE_CDR::LongLong) == 8);
893 ACE_TEST_ASSERT (sizeof (ACE_CDR::Float) == 4);
894 ACE_TEST_ASSERT (sizeof (ACE_CDR::Double) == 8);
895 ACE_TEST_ASSERT (sizeof (ACE_CDR::LongDouble) == 16);
897 ACE_DEBUG ((LM_DEBUG,
898 ACE_TEXT ("Testing ACE CDR functions - short stream\n\n")));
900 if (short_stream () != 0 )
901 return 1;
903 ACE_DEBUG ((LM_DEBUG,
904 ACE_TEXT ("Short stream - no errors\n\n")
905 ACE_TEXT ("Testing basic types - long stream\n\n")));
907 for (int i = 0; i < nloops; ++i)
909 ACE_OutputCDR output;
910 CDR_Test_Types test_types;
912 if (test_types.test_put (output) != 0)
913 return 1;
915 ACE_InputCDR input (output);
916 if (debug > 0)
918 ACE_DEBUG ((LM_DEBUG,
919 ACE_TEXT ("Output CDR:\n")));
920 ACE_HEX_DUMP ((LM_DEBUG,
921 input.rd_ptr(),
922 64));
923 ACE_DEBUG ((LM_DEBUG,
924 ACE_TEXT ("Input CDR:\n")));
925 ACE_HEX_DUMP ((LM_DEBUG,
926 input.rd_ptr(),
927 64));
930 if (test_types.test_get (input) != 0)
931 return 1;
934 ACE_DEBUG ((LM_DEBUG,
935 ACE_TEXT ("Long stream - no errors\n\n")
936 ACE_TEXT ("Testing basic types - long stream[2]\n\n")));
938 for (int j = 0; j < nloops; ++j)
940 ACE_OutputCDR output;
941 CDR_Test_Types test_types;
943 if (test_types.test_put (output) != 0)
944 return 1;
946 ACE_InputCDR input (output.begin ());
947 if (debug > 0)
949 ACE_DEBUG ((LM_DEBUG,
950 ACE_TEXT ("Output CDR:\n")));
951 ACE_HEX_DUMP ((LM_DEBUG,
952 input.rd_ptr(),
953 64));
954 ACE_DEBUG ((LM_DEBUG,
955 ACE_TEXT ("Input CDR:\n")));
956 ACE_HEX_DUMP ((LM_DEBUG,
957 input.rd_ptr(),
958 64));
961 if (test_types.test_get (input) != 0)
962 return 1;
965 ACE_DEBUG ((LM_DEBUG,
966 ACE_TEXT ("Long stream[2] - no errors\n\n")
967 ACE_TEXT ("Testing consolidation\n\n")));
969 ACE_OutputCDR output (30);
970 CDR_Test_Types test_types;
972 if (test_types.test_put (output) != 0)
973 return 1;
975 if (output.begin () == output.end ())
976 ACE_DEBUG ((LM_WARNING,
977 ACE_TEXT ("Only one block needed; test no effective.\n")));
978 else
980 if (output.consolidate () != 0)
981 ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("consolidate")));
984 ACE_InputCDR input (output);
985 if (debug > 0)
987 ACE_DEBUG ((LM_DEBUG,
988 ACE_TEXT ("Output CDR:\n")));
989 ACE_HEX_DUMP ((LM_DEBUG,
990 input.rd_ptr(),
991 64));
992 ACE_DEBUG ((LM_DEBUG,
993 ACE_TEXT ("Input CDR:\n")));
994 ACE_HEX_DUMP ((LM_DEBUG,
995 input.rd_ptr(),
996 64));
999 if (test_types.test_get (input) != 0)
1000 return 1;
1002 ACE_DEBUG ((LM_DEBUG,
1003 ACE_TEXT ("Consolidation - no errors\n\n")
1004 ACE_TEXT ("Testing placeholder/replace\n\n")));
1006 output.reset();
1007 if (test_types.test_put_placeholder (output) != 0)
1008 return 1;
1010 input = ACE_InputCDR(output);
1011 if (debug > 0)
1013 ACE_DEBUG ((LM_DEBUG,
1014 ACE_TEXT ("Output CDR:\n")));
1015 ACE_HEX_DUMP ((LM_DEBUG,
1016 input.rd_ptr(),
1017 64));
1018 ACE_DEBUG ((LM_DEBUG,
1019 ACE_TEXT ("Input CDR:\n")));
1020 ACE_HEX_DUMP ((LM_DEBUG,
1021 input.rd_ptr(),
1022 64));
1025 if (test_types.test_get_placeholder (input) != 0)
1026 return 1;
1028 ACE_DEBUG ((LM_DEBUG,
1029 ACE_TEXT ("Placeholder/Replace - no errors\n\n")));
1031 ACE_END_TEST;
1032 return 0;