Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / tests / CDR_Test.cpp
blob3cdcac82ec49140beca4e570888d0c07043f33a1
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 <memory>
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 std::string_view std_stringview {"std stringview"};
115 #if !defined(ACE_LACKS_STD_WSTRING)
116 std::wstring std_wstr (L"std wstring");
117 #endif
118 ACE_CDR::Short s = -123;
119 ACE_CDR::UShort us = 123;
120 ACE_CDR::Long l = -65800L;
121 ACE_CDR::ULong ul = 65800UL;
122 ACE_CDR::Float f = 1.23f;
123 ACE_CDR::Double d = 123.456789;
124 ACE_CDR::Fixed fx = ACE_CDR::Fixed::from_string ("8158901571290874");
126 // Arrays for output
127 ACE_CDR::Short s_array[3] = { -1, 0, 1 };
128 ACE_CDR::Long l_array[3] = { -345678, 0, 345678 };
129 ACE_CDR::Float f_array[3] = { -1.23f, 0.0f, 1.23f };
130 ACE_CDR::Double d_array[3] = { -123.456789, 0.0, 123.456789 };
131 ACE_CDR::Boolean b_array[3] = { false, true, false };
133 ACE_OutputCDR::from_char fc (ch);
134 ACE_OutputCDR::from_wchar fwc (wch);
135 os << fc;
136 os << fwc;
137 os << str;
138 os << wstr;
139 os << std_str;
140 os << std_stringview;
141 #if !defined(ACE_LACKS_STD_WSTRING)
142 os << std_wstr;
143 #endif
144 os << s;
145 os << us;
146 os << l;
147 os << ul;
148 os << f;
149 os << d;
150 os << fx;
151 os.write_short_array (s_array, 3);
152 os.write_long_array (l_array, 3);
153 os.write_float_array (f_array, 3);
154 os.write_double_array (d_array, 3);
155 os.write_boolean_array (b_array, 3);
157 // Do the same for size stream.
158 ss << fc;
159 ss << fwc;
160 ss << str;
161 ss << wstr;
162 ss << std_str;
163 ss << std_stringview;
164 #if !defined(ACE_LACKS_STD_WSTRING)
165 ss << std_wstr;
166 #endif
167 ss << s;
168 ss << us;
169 ss << l;
170 ss << ul;
171 ss << f;
172 ss << d;
173 ss << fx;
174 ss.write_short_array (s_array, 3);
175 ss.write_long_array (l_array, 3);
176 ss.write_float_array (f_array, 3);
177 ss.write_double_array (d_array, 3);
178 ss.write_boolean_array (b_array, 3);
180 // Check the size.
181 if (ss.total_length () != os.total_length ())
182 ACE_ERROR_RETURN ((LM_ERROR,
183 ACE_TEXT ("%p\n"),
184 ACE_TEXT ("representation length does not match")),
187 const ACE_Message_Block *out_mb = os.begin ();
188 size_t len = out_mb->length ();
190 // Create an input stream (copy constructor)
191 ACE_InputCDR is (os);
192 const ACE_Message_Block *in_mb = is.start ();
194 if (in_mb->length () != len)
195 ACE_ERROR_RETURN ((LM_ERROR,
196 ACE_TEXT ("%p\n"),
197 ACE_TEXT ("buffer length not preserved")),
200 for (i = 0; i < len; i++)
202 unsigned long const in_chunk =
203 static_cast<unsigned long> (* (in_mb->rd_ptr () + i));
205 unsigned long const out_chunk =
206 static_cast<unsigned long> (* (out_mb->rd_ptr () + i));
208 if (in_chunk != out_chunk)
209 ACE_ERROR_RETURN ((LM_ERROR,
210 ACE_TEXT ("%p\n"),
211 ACE_TEXT ("buffer contents not preserved")),
215 // Basic types for input
216 ACE_CDR::Char ch1 = '\0';
217 ACE_CDR::WChar wch1 = '\x00';
218 ACE_CDR::WChar *wstr1 = 0;
219 ACE_CString str1;
220 std::string std_str1;
221 std::string std_stringview1;
222 #if !defined(ACE_LACKS_STD_WSTRING)
223 std::wstring std_wstr1;
224 #endif
225 ACE_CDR::Short s1 = 0;
226 ACE_CDR::UShort us1 = 0;
227 ACE_CDR::Long l1 = 0L;
228 ACE_CDR::ULong ul1 = 0UL;
229 ACE_CDR::Float f1 = 0.0f;
230 ACE_CDR::Double d1 = 0.0;
231 ACE_CDR::Fixed fx1 = ACE_CDR::Fixed::from_string ("0");
233 // Arrays for input
234 ACE_CDR::Short s_array1[3];
235 ACE_CDR::Long l_array1[3];
236 ACE_CDR::Float f_array1[3];
237 ACE_CDR::Double d_array1[3];
239 ACE_DEBUG ((LM_DEBUG,
240 ACE_TEXT ("Checking operators and arrays\n\n")));
242 ACE_InputCDR::to_char tc (ch1);
243 is >> tc;
244 ACE_InputCDR::to_wchar twc (wch1);
245 is >> twc;
246 is >> str1;
247 ACE_InputCDR::to_wstring twstr (wstr1, 0);
248 is >> twstr;
249 // @todo Lose the std::unique_ptr. We should be using a
250 // std::string, or the like.
251 std::unique_ptr<ACE_CDR::WChar[]> safe_wstr (wstr1);
252 is >> std_str1;
253 is >> std_stringview1;
254 #if !defined(ACE_LACKS_STD_WSTRING)
255 is >> std_wstr1;
256 #endif
257 is >> s1;
258 is >> us1;
259 is >> l1;
260 is >> ul1;
261 is >> f1;
262 is >> d1;
263 is >> fx1;
264 is.read_short_array (s_array1, 3);
265 is.read_long_array (l_array1, 3);
266 is.read_float_array (f_array1, 3);
267 is.read_double_array (d_array1, 3);
269 if (ch1 != ch)
270 ACE_ERROR_RETURN ((LM_ERROR,
271 ACE_TEXT ("%p\n"),
272 ACE_TEXT ("char transfer error")),
275 if (wch1 != wch)
276 ACE_ERROR_RETURN ((LM_ERROR,
277 ACE_TEXT ("%p\n"),
278 ACE_TEXT ("wchar transfer error")),
281 if (str1 != str)
282 ACE_ERROR_RETURN ((LM_ERROR,
283 ACE_TEXT ("%p\n"),
284 ACE_TEXT ("string transfer error")),
287 if (ACE_OS::wscmp (wstr1, wstr))
288 ACE_ERROR_RETURN ((LM_ERROR,
289 ACE_TEXT ("%p\n"),
290 ACE_TEXT ("wide string transfer error")),
293 if (std_str1 != std_str)
294 ACE_ERROR_RETURN ((LM_ERROR,
295 ACE_TEXT ("%p\n"),
296 ACE_TEXT ("std::string transfer error")),
299 if (std_stringview1 != std_stringview)
300 ACE_ERROR_RETURN ((LM_ERROR,
301 ACE_TEXT ("%p\n"),
302 ACE_TEXT ("std::string_view transfer error")),
305 #if !defined(ACE_LACKS_STD_WSTRING)
306 if (std_wstr1 != std_wstr)
307 ACE_ERROR_RETURN ((LM_ERROR,
308 ACE_TEXT ("%p\n"),
309 ACE_TEXT ("std::wstring transfer error")),
311 #endif
313 if (s1 != s)
314 ACE_ERROR_RETURN ((LM_ERROR,
315 ACE_TEXT ("%p\n"),
316 ACE_TEXT ("short transfer error")),
319 if (us1 != us)
320 ACE_ERROR_RETURN ((LM_ERROR,
321 ACE_TEXT ("%p\n"),
322 ACE_TEXT ("ushort transfer error")),
325 if (l1 != l)
326 ACE_ERROR_RETURN ((LM_ERROR,
327 ACE_TEXT ("%p\n"),
328 ACE_TEXT ("long transfer error")),
331 if (ul1 != ul)
332 ACE_ERROR_RETURN ((LM_ERROR,
333 ACE_TEXT ("%p\n"),
334 ACE_TEXT ("ulong transfer error")),
337 if (!ACE::is_equal (f1, f))
338 ACE_ERROR_RETURN ((LM_ERROR,
339 ACE_TEXT ("%p\n"),
340 ACE_TEXT ("float transfer error")),
343 if (!ACE::is_equal (d1, d))
344 ACE_ERROR_RETURN ((LM_ERROR,
345 ACE_TEXT ("%p\n"),
346 ACE_TEXT ("double transfer error")),
349 if (fx1 != fx)
350 ACE_ERROR_RETURN ((LM_ERROR,
351 ACE_TEXT ("%p\n"),
352 ACE_TEXT ("fixed transfer error")),
355 for (i = 0 ; i < 3; i++)
356 if (s_array1[i] != s_array[i])
357 ACE_ERROR_RETURN ((LM_ERROR,
358 ACE_TEXT ("%p\n"),
359 ACE_TEXT ("short array transfer error")),
362 for (i = 0 ; i < 3; i++)
363 if (l_array1[i] != l_array[i])
364 ACE_ERROR_RETURN ((LM_ERROR,
365 ACE_TEXT ("%p\n"),
366 ACE_TEXT ("long array transfer error")),
369 for (i = 0 ; i < 3; i++)
370 if (!ACE::is_equal (f_array1[i], f_array[i]))
371 ACE_ERROR_RETURN ((LM_ERROR,
372 ACE_TEXT ("%p\n"),
373 ACE_TEXT ("float array transfer error")),
376 for (i = 0 ; i < 3; i++)
377 if (!ACE::is_equal (d_array1[i], d_array[i]))
378 ACE_ERROR_RETURN ((LM_ERROR,
379 ACE_TEXT ("%p\n"),
380 ACE_TEXT ("double array transfer error")),
383 return 0;
387 CDR_Test_Types::test_put (ACE_OutputCDR &cdr)
389 for (int i = 0; i < n; ++i)
391 if (cdr.write_octet (this->o) == 0)
392 ACE_ERROR_RETURN ((LM_ERROR,
393 ACE_TEXT ("write_octet[%d] failed\n"),
396 if (cdr.write_short (this->s) == 0)
397 ACE_ERROR_RETURN ((LM_ERROR,
398 ACE_TEXT ("write_short[%d] failed\n"),
401 if (cdr.write_octet (this->o) == 0)
402 ACE_ERROR_RETURN ((LM_ERROR,
403 ACE_TEXT ("write_octet-2[%d] failed\n"),
406 if (cdr.write_long (this->l) == 0)
407 ACE_ERROR_RETURN ((LM_ERROR,
408 ACE_TEXT ("write_long[%d] failed\n"),
411 if (cdr.write_long (this->l) == 0)
412 ACE_ERROR_RETURN ((LM_ERROR,
413 ACE_TEXT ("write_long-2[%d] failed\n"),
417 if (cdr.write_string (this->str) == 0)
418 ACE_ERROR_RETURN ((LM_ERROR,
419 ACE_TEXT ("write_string[%d] failed\n"),
423 if (cdr.write_wstring (this->wstr) == 0)
424 ACE_ERROR_RETURN ((LM_ERROR,
425 ACE_TEXT ("write_wstring[%d] failed\n"),
429 if (cdr.write_string (this->std_str) == 0)
430 ACE_ERROR_RETURN ((LM_ERROR,
431 ACE_TEXT ("write_string(std)[%d] failed\n"),
435 #if !defined(ACE_LACKS_STD_WSTRING)
436 if (cdr.write_wstring (this->std_wstr) == 0)
437 ACE_ERROR_RETURN ((LM_ERROR,
438 ACE_TEXT ("write_wstring(std)[%d] failed\n"),
441 #endif
444 return 0;
448 CDR_Test_Types::test_get (ACE_InputCDR &cdr) const
450 ACE_CDR::Octet xo;
451 ACE_CDR::Short xs;
452 ACE_CDR::Long xl;
454 for (int i = 0; i < n; ++i)
456 if (cdr.read_octet (xo) == 0)
457 ACE_ERROR_RETURN ((LM_ERROR,
458 ACE_TEXT ("read_octet[%d] failed\n"),
461 if (xo != this->o)
462 ACE_ERROR_RETURN ((LM_ERROR,
463 ACE_TEXT ("octet[%d] differs\n"),
466 if (cdr.read_short (xs) == 0)
467 ACE_ERROR_RETURN ((LM_ERROR,
468 ACE_TEXT ("read_short[%d] failed\n"),
469 i), 1);
470 if (xs != this->s)
471 ACE_ERROR_RETURN ((LM_ERROR,
472 ACE_TEXT ("short[%d] differs\n"),
475 if (cdr.read_octet (xo) == 0)
476 ACE_ERROR_RETURN ((LM_ERROR,
477 ACE_TEXT ("read_octet-2[%d] failed\n"),
480 if (xo != this->o)
481 ACE_ERROR_RETURN ((LM_ERROR,
482 ACE_TEXT ("octet-2[%d] differs\n"),
485 if (cdr.read_long (xl) == 0)
486 ACE_ERROR_RETURN ((LM_ERROR,
487 ACE_TEXT ("read_long[%d] failed\n"),
490 if (xl != this->l)
491 ACE_ERROR_RETURN ((LM_ERROR,
492 ACE_TEXT ("long[%d] differs\n"),
495 if (cdr.read_long (xl) == 0)
496 ACE_ERROR_RETURN ((LM_ERROR,
497 ACE_TEXT ("read_long-2[%d] failed\n"),
500 if (xl != this->l)
501 ACE_ERROR_RETURN ((LM_ERROR,
502 ACE_TEXT ("long-2[%d] differs\n"),
506 ACE_CDR::Char *xstr;
507 if (cdr.read_string (xstr) == 0)
508 ACE_ERROR_RETURN ((LM_ERROR,
509 ACE_TEXT ("read_string2[%d] failed\n"),
512 std::unique_ptr<ACE_CDR::Char[]> auto_xstr (xstr);
513 if (ACE_OS::strcmp (auto_xstr.get (), this->str) != 0)
514 ACE_ERROR_RETURN ((LM_ERROR,
515 ACE_TEXT ("string[%d] differs\n"),
519 ACE_CDR::WChar *wstr1;
520 if (cdr.read_wstring (wstr1) == 0)
521 ACE_ERROR_RETURN ((LM_ERROR,
522 ACE_TEXT ("read_wstring2[%d] failed\n"),
525 // zero length
526 std::unique_ptr<ACE_CDR::WChar[]> auto_xwstr (wstr1);
527 if (ACE_OS::wslen(auto_xwstr.get () ))
528 ACE_ERROR_RETURN ((LM_ERROR,
529 ACE_TEXT ("wstring[%d] differs\n"),
533 std::string std_xstr;
534 if (cdr.read_string (std_xstr) == 0)
535 ACE_ERROR_RETURN ((LM_ERROR,
536 ACE_TEXT ("read_string(std)[%d] failed\n"),
539 if (std_xstr != this->std_str)
540 ACE_ERROR_RETURN ((LM_ERROR,
541 ACE_TEXT ("std::string[%d] differs\n"),
545 #if !defined(ACE_LACKS_STD_WSTRING)
546 std::wstring std_xwstr;
547 if (cdr.read_wstring (std_xwstr) == 0)
548 ACE_ERROR_RETURN ((LM_ERROR,
549 ACE_TEXT ("read_wstring(std)[%d] failed\n"),
552 if (std_xwstr != this->std_wstr)
553 ACE_ERROR_RETURN ((LM_ERROR,
554 ACE_TEXT ("std::wstring[%d] differs\n"),
557 #endif
559 return 0;
563 CDR_Test_Types::test_put_placeholder (ACE_OutputCDR &cdr)
565 // Write a placeholder then a bunch of other stuff, then replace.
566 // Long
567 char *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->repl, pos))
573 ACE_ERROR_RETURN ((LM_ERROR,
574 ACE_TEXT ("replace(long) failed\n")),
577 // ULong
578 pos = cdr.write_long_placeholder ();
579 if (test_put (cdr) != 0)
580 ACE_ERROR_RETURN ((LM_ERROR,
581 ACE_TEXT ("test_put (long placeholder) failed\n")),
583 if (!cdr.replace (this->repul, pos))
584 ACE_ERROR_RETURN ((LM_ERROR,
585 ACE_TEXT ("replace(ulong) failed\n")),
588 // Short
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->reps, pos))
595 ACE_ERROR_RETURN ((LM_ERROR,
596 ACE_TEXT ("replace(short) failed\n")),
599 // UShort
600 pos = cdr.write_short_placeholder ();
601 if (test_put (cdr) != 0)
602 ACE_ERROR_RETURN ((LM_ERROR,
603 ACE_TEXT ("test_put (short placeholder) failed\n")),
605 if (!cdr.replace (this->repus, pos))
606 ACE_ERROR_RETURN ((LM_ERROR,
607 ACE_TEXT ("replace(ushort) failed\n")),
610 // Boolean
611 pos = cdr.write_boolean_placeholder ();
612 if (test_put (cdr) != 0)
613 ACE_ERROR_RETURN ((LM_ERROR,
614 ACE_TEXT ("test_put (boolean placeholder) failed\n")),
616 if (!cdr.replace (this->repb, pos))
617 ACE_ERROR_RETURN ((LM_ERROR,
618 ACE_TEXT ("replace(boolean) failed\n")),
621 // Char
622 pos = cdr.write_char_placeholder ();
623 if (test_put (cdr) != 0)
624 ACE_ERROR_RETURN ((LM_ERROR,
625 ACE_TEXT ("test_put (char placeholder) failed\n")),
627 if (!cdr.replace (this->repc, pos))
628 ACE_ERROR_RETURN ((LM_ERROR,
629 ACE_TEXT ("replace(char) failed\n")),
632 // LongLong
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->repll, pos))
639 ACE_ERROR_RETURN ((LM_ERROR,
640 ACE_TEXT ("replace(longlong) failed\n")),
643 // ULongLong
644 pos = cdr.write_longlong_placeholder ();
645 if (test_put (cdr) != 0)
646 ACE_ERROR_RETURN ((LM_ERROR,
647 ACE_TEXT ("test_put (longlong placeholder) failed\n")),
649 if (!cdr.replace (this->repull, pos))
650 ACE_ERROR_RETURN ((LM_ERROR,
651 ACE_TEXT ("replace(ulonglong) failed\n")),
654 // Octet
655 pos = cdr.write_octet_placeholder ();
656 if (test_put (cdr) != 0)
657 ACE_ERROR_RETURN ((LM_ERROR,
658 ACE_TEXT ("test_put (octet placeholder) failed\n")),
660 if (!cdr.replace (this->repo, pos))
661 ACE_ERROR_RETURN ((LM_ERROR,
662 ACE_TEXT ("replace(octet) failed\n")),
665 // Float
666 pos = cdr.write_float_placeholder ();
667 if (test_put (cdr) != 0)
668 ACE_ERROR_RETURN ((LM_ERROR,
669 ACE_TEXT ("test_put (float placeholder) failed\n")),
671 if (!cdr.replace (this->repf, pos))
672 ACE_ERROR_RETURN ((LM_ERROR,
673 ACE_TEXT ("replace(float) failed\n")),
676 // Double
677 pos = cdr.write_double_placeholder ();
678 if (test_put (cdr) != 0)
679 ACE_ERROR_RETURN ((LM_ERROR,
680 ACE_TEXT ("test_put (double placeholder) failed\n")),
682 if (!cdr.replace (this->repd, pos))
683 ACE_ERROR_RETURN ((LM_ERROR,
684 ACE_TEXT ("replace(double) failed\n")),
687 return 0;
691 CDR_Test_Types::test_get_placeholder (ACE_InputCDR &cdr) const
693 ACE_CDR::Short xs;
694 ACE_CDR::UShort xus;
695 ACE_CDR::Long xl;
696 ACE_CDR::ULong xul;
697 ACE_CDR::Boolean xb;
698 ACE_CDR::Char xc;
699 ACE_CDR::LongLong xll;
700 ACE_CDR::ULongLong xull;
701 ACE_CDR::Octet xo;
702 ACE_CDR::Float xf;
703 ACE_CDR::Double xd;
705 if (cdr.read_long (xl) == 0)
706 ACE_ERROR_RETURN ((LM_ERROR,
707 ACE_TEXT ("read_long failed\n")),
709 if (xl != this->repl)
710 ACE_ERROR_RETURN ((LM_ERROR,
711 ACE_TEXT ("replaced long differs\n")),
714 // The bunch of stuff written after the placeholder by test_put_placeholder
715 // should still be valid; check that it is.
716 if (test_get (cdr) != 0)
717 ACE_ERROR_RETURN ((LM_ERROR,
718 ACE_TEXT ("test_get (long) failed\n")),
721 if (cdr.read_ulong (xul) == 0)
722 ACE_ERROR_RETURN ((LM_ERROR,
723 ACE_TEXT ("read_ulong failed\n")), 1);
724 if (xul != this->repul)
725 ACE_ERROR_RETURN ((LM_ERROR,
726 ACE_TEXT ("replaced ulong differs\n")),
729 if (test_get (cdr) != 0)
730 ACE_ERROR_RETURN ((LM_ERROR,
731 ACE_TEXT ("test_get (ulong) failed\n")),
734 if (cdr.read_short (xs) == 0)
735 ACE_ERROR_RETURN ((LM_ERROR,
736 ACE_TEXT ("read_short failed\n")), 1);
737 if (xs != this->reps)
738 ACE_ERROR_RETURN ((LM_ERROR,
739 ACE_TEXT ("replaced short differs\n")),
742 if (test_get (cdr) != 0)
743 ACE_ERROR_RETURN ((LM_ERROR,
744 ACE_TEXT ("test_get (short) failed\n")),
747 if (cdr.read_ushort (xus) == 0)
748 ACE_ERROR_RETURN ((LM_ERROR,
749 ACE_TEXT ("read_ushort failed\n")), 1);
750 if (xus != this->repus)
751 ACE_ERROR_RETURN ((LM_ERROR,
752 ACE_TEXT ("replaced ushort differs\n")),
755 if (test_get (cdr) != 0)
756 ACE_ERROR_RETURN ((LM_ERROR,
757 ACE_TEXT ("test_get (ushort) failed\n")),
760 if (cdr.read_boolean (xb) == 0)
761 ACE_ERROR_RETURN ((LM_ERROR,
762 ACE_TEXT ("read_boolean failed\n")), 1);
763 if (xb != this->repb)
764 ACE_ERROR_RETURN ((LM_ERROR,
765 ACE_TEXT ("replaced boolean differs\n")),
768 if (test_get (cdr) != 0)
769 ACE_ERROR_RETURN ((LM_ERROR,
770 ACE_TEXT ("test_get (boolean) failed\n")),
773 if (cdr.read_char (xc) == 0)
774 ACE_ERROR_RETURN ((LM_ERROR,
775 ACE_TEXT ("read_char failed\n")), 1);
776 if (xc != this->repc)
777 ACE_ERROR_RETURN ((LM_ERROR,
778 ACE_TEXT ("replaced char differs\n")),
781 if (test_get (cdr) != 0)
782 ACE_ERROR_RETURN ((LM_ERROR,
783 ACE_TEXT ("test_get (char) failed\n")),
787 if (cdr.read_longlong (xll) == 0)
788 ACE_ERROR_RETURN ((LM_ERROR,
789 ACE_TEXT ("read_longlong failed\n")), 1);
790 if (xll != this->repll)
791 ACE_ERROR_RETURN ((LM_ERROR,
792 ACE_TEXT ("replaced longlong differs\n")),
795 if (test_get (cdr) != 0)
796 ACE_ERROR_RETURN ((LM_ERROR,
797 ACE_TEXT ("test_get (longlong) failed\n")),
800 if (cdr.read_ulonglong (xull) == 0)
801 ACE_ERROR_RETURN ((LM_ERROR,
802 ACE_TEXT ("read_ulonglong failed\n")), 1);
803 if (xull != this->repull)
804 ACE_ERROR_RETURN ((LM_ERROR,
805 ACE_TEXT ("replaced ulonglong differs\n")),
808 if (test_get (cdr) != 0)
809 ACE_ERROR_RETURN ((LM_ERROR,
810 ACE_TEXT ("test_get (ulonglong) failed\n")),
813 if (cdr.read_octet (xo) == 0)
814 ACE_ERROR_RETURN ((LM_ERROR,
815 ACE_TEXT ("read_octet failed\n")), 1);
816 if (xo != this->repo)
817 ACE_ERROR_RETURN ((LM_ERROR,
818 ACE_TEXT ("replaced octet differs\n")),
821 if (test_get (cdr) != 0)
822 ACE_ERROR_RETURN ((LM_ERROR,
823 ACE_TEXT ("test_get (octet) failed\n")),
826 if (cdr.read_float (xf) == 0)
827 ACE_ERROR_RETURN ((LM_ERROR,
828 ACE_TEXT ("read_float failed\n")), 1);
829 if (xf != this->repf)
830 ACE_ERROR_RETURN ((LM_ERROR,
831 ACE_TEXT ("replaced float differs\n")),
834 if (test_get (cdr) != 0)
835 ACE_ERROR_RETURN ((LM_ERROR,
836 ACE_TEXT ("test_get (float) failed\n")),
839 if (cdr.read_double (xd) == 0)
840 ACE_ERROR_RETURN ((LM_ERROR,
841 ACE_TEXT ("read_double failed\n")), 1);
842 if (xd != this->repd)
843 ACE_ERROR_RETURN ((LM_ERROR,
844 ACE_TEXT ("replaced double differs\n")),
847 if (test_get (cdr) != 0)
848 ACE_ERROR_RETURN ((LM_ERROR,
849 ACE_TEXT ("test_get (double) failed\n")),
852 return 0;
857 run_main (int argc, ACE_TCHAR *argv[])
859 ACE_START_TEST (ACE_TEXT ("CDR_Test"));
861 ACE_DEBUG ((LM_DEBUG,
862 ACE_TEXT ("This is ACE Version %u.%u.%u\n\n"),
863 ACE::major_version (),
864 ACE::minor_version(),
865 ACE::micro_version()));
867 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("dn:l:"));
868 int opt;
869 int debug = 0;
871 while ((opt = get_opt ()) != EOF)
873 switch (opt)
875 case 'd':
876 debug++;
877 break;
878 case 'n':
879 n = ACE_OS::atoi (get_opt.opt_arg ());
880 break;
881 case 'l':
882 nloops = ACE_OS::atoi (get_opt.opt_arg ());
883 break;
884 case '?':
885 default:
886 ACE_DEBUG ((LM_DEBUG,
887 ACE_TEXT ("Usage: %s ")
888 ACE_TEXT ("-d debug")
889 ACE_TEXT ("-n <num> ")
890 ACE_TEXT ("-l <loops> ")
891 ACE_TEXT ("\n"),
892 ACE_TEXT ("CDR_Test")));
893 return -1;
897 // Sanity checks.
898 ACE_TEST_ASSERT (sizeof (ACE_CDR::Boolean) >= 1);
899 ACE_TEST_ASSERT (sizeof (ACE_CDR::Octet) == 1);
900 ACE_TEST_ASSERT (sizeof (ACE_CDR::WChar) >= 2);
901 ACE_TEST_ASSERT (sizeof (ACE_CDR::Short) == 2);
902 ACE_TEST_ASSERT (sizeof (ACE_CDR::Long) == 4);
903 ACE_TEST_ASSERT (sizeof (ACE_CDR::LongLong) == 8);
904 ACE_TEST_ASSERT (sizeof (ACE_CDR::Float) == 4);
905 ACE_TEST_ASSERT (sizeof (ACE_CDR::Double) == 8);
906 ACE_TEST_ASSERT (sizeof (ACE_CDR::LongDouble) == 16);
908 ACE_DEBUG ((LM_DEBUG,
909 ACE_TEXT ("Testing ACE CDR functions - short stream\n\n")));
911 if (short_stream () != 0 )
912 return 1;
914 ACE_DEBUG ((LM_DEBUG,
915 ACE_TEXT ("Short stream - no errors\n\n")
916 ACE_TEXT ("Testing basic types - long stream\n\n")));
918 for (int i = 0; i < nloops; ++i)
920 ACE_OutputCDR output;
921 CDR_Test_Types test_types;
923 if (test_types.test_put (output) != 0)
924 return 1;
926 ACE_InputCDR input (output);
927 if (debug > 0)
929 ACE_DEBUG ((LM_DEBUG,
930 ACE_TEXT ("Output CDR:\n")));
931 ACE_HEX_DUMP ((LM_DEBUG,
932 input.rd_ptr(),
933 64));
934 ACE_DEBUG ((LM_DEBUG,
935 ACE_TEXT ("Input CDR:\n")));
936 ACE_HEX_DUMP ((LM_DEBUG,
937 input.rd_ptr(),
938 64));
941 if (test_types.test_get (input) != 0)
942 return 1;
945 ACE_DEBUG ((LM_DEBUG,
946 ACE_TEXT ("Long stream - no errors\n\n")
947 ACE_TEXT ("Testing basic types - long stream[2]\n\n")));
949 for (int j = 0; j < nloops; ++j)
951 ACE_OutputCDR output;
952 CDR_Test_Types test_types;
954 if (test_types.test_put (output) != 0)
955 return 1;
957 ACE_InputCDR input (output.begin ());
958 if (debug > 0)
960 ACE_DEBUG ((LM_DEBUG,
961 ACE_TEXT ("Output CDR:\n")));
962 ACE_HEX_DUMP ((LM_DEBUG,
963 input.rd_ptr(),
964 64));
965 ACE_DEBUG ((LM_DEBUG,
966 ACE_TEXT ("Input CDR:\n")));
967 ACE_HEX_DUMP ((LM_DEBUG,
968 input.rd_ptr(),
969 64));
972 if (test_types.test_get (input) != 0)
973 return 1;
976 ACE_DEBUG ((LM_DEBUG,
977 ACE_TEXT ("Long stream[2] - no errors\n\n")
978 ACE_TEXT ("Testing consolidation\n\n")));
980 ACE_OutputCDR output (30);
981 CDR_Test_Types test_types;
983 if (test_types.test_put (output) != 0)
984 return 1;
986 if (output.begin () == output.end ())
987 ACE_DEBUG ((LM_WARNING,
988 ACE_TEXT ("Only one block needed; test no effective.\n")));
989 else
991 if (output.consolidate () != 0)
992 ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("consolidate")));
995 ACE_InputCDR input (output);
996 if (debug > 0)
998 ACE_DEBUG ((LM_DEBUG,
999 ACE_TEXT ("Output CDR:\n")));
1000 ACE_HEX_DUMP ((LM_DEBUG,
1001 input.rd_ptr(),
1002 64));
1003 ACE_DEBUG ((LM_DEBUG,
1004 ACE_TEXT ("Input CDR:\n")));
1005 ACE_HEX_DUMP ((LM_DEBUG,
1006 input.rd_ptr(),
1007 64));
1010 if (test_types.test_get (input) != 0)
1011 return 1;
1013 ACE_DEBUG ((LM_DEBUG,
1014 ACE_TEXT ("Consolidation - no errors\n\n")
1015 ACE_TEXT ("Testing placeholder/replace\n\n")));
1017 output.reset();
1018 if (test_types.test_put_placeholder (output) != 0)
1019 return 1;
1021 input = ACE_InputCDR(output);
1022 if (debug > 0)
1024 ACE_DEBUG ((LM_DEBUG,
1025 ACE_TEXT ("Output CDR:\n")));
1026 ACE_HEX_DUMP ((LM_DEBUG,
1027 input.rd_ptr(),
1028 64));
1029 ACE_DEBUG ((LM_DEBUG,
1030 ACE_TEXT ("Input CDR:\n")));
1031 ACE_HEX_DUMP ((LM_DEBUG,
1032 input.rd_ptr(),
1033 64));
1036 if (test_types.test_get_placeholder (input) != 0)
1037 return 1;
1039 ACE_DEBUG ((LM_DEBUG,
1040 ACE_TEXT ("Placeholder/Replace - no errors\n\n")));
1042 ACE_END_TEST;
1043 return 0;