2 //=============================================================================
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>
10 //=============================================================================
13 #include "test_config.h"
14 #include "ace/Get_Opt.h"
16 #include "ace/CDR_Stream.h"
17 #include "ace/CDR_Size.h"
18 #include "ace/SString.h"
20 #include "ace/OS_NS_stdlib.h"
21 #include "ace/OS_NS_string.h"
22 #include "ace/OS_NS_wchar.h"
26 static int nloops
= 100;
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
;
43 ACE_CDR::UShort repus
;
46 ACE_CDR::Boolean repb
;
47 const ACE_CDR::Char repc
;
48 ACE_CDR::LongLong repll
;
49 ACE_CDR::ULongLong repull
;
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;
64 ACE_CDR::Short a
[ARRAY_SIZE
];
67 CDR_Test_Types::CDR_Test_Types ()
74 #if !defined(ACE_LACKS_STD_WSTRING)
84 repll (-5000000000LL),
85 repull (5000000000LL),
91 i
< CDR_Test_Types::ARRAY_SIZE
;
102 // Build an output stream
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");
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");
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
);
140 os
<< std_stringview
;
141 #if !defined(ACE_LACKS_STD_WSTRING)
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.
163 ss
<< std_stringview
;
164 #if !defined(ACE_LACKS_STD_WSTRING)
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);
181 if (ss
.total_length () != os
.total_length ())
182 ACE_ERROR_RETURN ((LM_ERROR
,
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
,
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
,
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;
220 std::string std_str1
;
221 std::string std_stringview1
;
222 #if !defined(ACE_LACKS_STD_WSTRING)
223 std::wstring std_wstr1
;
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");
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
);
244 ACE_InputCDR::to_wchar
twc (wch1
);
247 ACE_InputCDR::to_wstring
twstr (wstr1
, 0);
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
);
253 is
>> std_stringview1
;
254 #if !defined(ACE_LACKS_STD_WSTRING)
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);
270 ACE_ERROR_RETURN ((LM_ERROR
,
272 ACE_TEXT ("char transfer error")),
276 ACE_ERROR_RETURN ((LM_ERROR
,
278 ACE_TEXT ("wchar transfer error")),
282 ACE_ERROR_RETURN ((LM_ERROR
,
284 ACE_TEXT ("string transfer error")),
287 if (ACE_OS::wscmp (wstr1
, wstr
))
288 ACE_ERROR_RETURN ((LM_ERROR
,
290 ACE_TEXT ("wide string transfer error")),
293 if (std_str1
!= std_str
)
294 ACE_ERROR_RETURN ((LM_ERROR
,
296 ACE_TEXT ("std::string transfer error")),
299 if (std_stringview1
!= std_stringview
)
300 ACE_ERROR_RETURN ((LM_ERROR
,
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
,
309 ACE_TEXT ("std::wstring transfer error")),
314 ACE_ERROR_RETURN ((LM_ERROR
,
316 ACE_TEXT ("short transfer error")),
320 ACE_ERROR_RETURN ((LM_ERROR
,
322 ACE_TEXT ("ushort transfer error")),
326 ACE_ERROR_RETURN ((LM_ERROR
,
328 ACE_TEXT ("long transfer error")),
332 ACE_ERROR_RETURN ((LM_ERROR
,
334 ACE_TEXT ("ulong transfer error")),
337 if (!ACE::is_equal (f1
, f
))
338 ACE_ERROR_RETURN ((LM_ERROR
,
340 ACE_TEXT ("float transfer error")),
343 if (!ACE::is_equal (d1
, d
))
344 ACE_ERROR_RETURN ((LM_ERROR
,
346 ACE_TEXT ("double transfer error")),
350 ACE_ERROR_RETURN ((LM_ERROR
,
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
,
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
,
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
,
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
,
380 ACE_TEXT ("double array transfer error")),
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"),
448 CDR_Test_Types::test_get (ACE_InputCDR
&cdr
) const
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"),
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"),
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"),
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"),
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"),
501 ACE_ERROR_RETURN ((LM_ERROR
,
502 ACE_TEXT ("long-2[%d] differs\n"),
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"),
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"),
563 CDR_Test_Types::test_put_placeholder (ACE_OutputCDR
&cdr
)
565 // Write a placeholder then a bunch of other stuff, then replace.
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")),
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")),
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")),
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")),
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")),
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")),
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")),
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")),
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")),
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")),
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")),
691 CDR_Test_Types::test_get_placeholder (ACE_InputCDR
&cdr
) const
699 ACE_CDR::LongLong xll
;
700 ACE_CDR::ULongLong xull
;
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")),
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:"));
871 while ((opt
= get_opt ()) != EOF
)
879 n
= ACE_OS::atoi (get_opt
.opt_arg ());
882 nloops
= ACE_OS::atoi (get_opt
.opt_arg ());
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> ")
892 ACE_TEXT ("CDR_Test")));
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 )
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)
926 ACE_InputCDR
input (output
);
929 ACE_DEBUG ((LM_DEBUG
,
930 ACE_TEXT ("Output CDR:\n")));
931 ACE_HEX_DUMP ((LM_DEBUG
,
934 ACE_DEBUG ((LM_DEBUG
,
935 ACE_TEXT ("Input CDR:\n")));
936 ACE_HEX_DUMP ((LM_DEBUG
,
941 if (test_types
.test_get (input
) != 0)
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)
957 ACE_InputCDR
input (output
.begin ());
960 ACE_DEBUG ((LM_DEBUG
,
961 ACE_TEXT ("Output CDR:\n")));
962 ACE_HEX_DUMP ((LM_DEBUG
,
965 ACE_DEBUG ((LM_DEBUG
,
966 ACE_TEXT ("Input CDR:\n")));
967 ACE_HEX_DUMP ((LM_DEBUG
,
972 if (test_types
.test_get (input
) != 0)
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)
986 if (output
.begin () == output
.end ())
987 ACE_DEBUG ((LM_WARNING
,
988 ACE_TEXT ("Only one block needed; test no effective.\n")));
991 if (output
.consolidate () != 0)
992 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("%p\n"), ACE_TEXT ("consolidate")));
995 ACE_InputCDR
input (output
);
998 ACE_DEBUG ((LM_DEBUG
,
999 ACE_TEXT ("Output CDR:\n")));
1000 ACE_HEX_DUMP ((LM_DEBUG
,
1003 ACE_DEBUG ((LM_DEBUG
,
1004 ACE_TEXT ("Input CDR:\n")));
1005 ACE_HEX_DUMP ((LM_DEBUG
,
1010 if (test_types
.test_get (input
) != 0)
1013 ACE_DEBUG ((LM_DEBUG
,
1014 ACE_TEXT ("Consolidation - no errors\n\n")
1015 ACE_TEXT ("Testing placeholder/replace\n\n")));
1018 if (test_types
.test_put_placeholder (output
) != 0)
1021 input
= ACE_InputCDR(output
);
1024 ACE_DEBUG ((LM_DEBUG
,
1025 ACE_TEXT ("Output CDR:\n")));
1026 ACE_HEX_DUMP ((LM_DEBUG
,
1029 ACE_DEBUG ((LM_DEBUG
,
1030 ACE_TEXT ("Input CDR:\n")));
1031 ACE_HEX_DUMP ((LM_DEBUG
,
1036 if (test_types
.test_get_placeholder (input
) != 0)
1039 ACE_DEBUG ((LM_DEBUG
,
1040 ACE_TEXT ("Placeholder/Replace - no errors\n\n")));