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"
15 #include "ace/Auto_Ptr.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 #if !defined(ACE_LACKS_STD_WSTRING)
115 std::wstring
std_wstr (L
"std wstring");
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");
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
);
139 #if !defined(ACE_LACKS_STD_WSTRING)
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.
161 #if !defined(ACE_LACKS_STD_WSTRING)
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);
178 if (ss
.total_length () != os
.total_length ())
179 ACE_ERROR_RETURN ((LM_ERROR
,
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
,
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
,
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;
217 std::string std_str1
;
218 #if !defined(ACE_LACKS_STD_WSTRING)
219 std::wstring std_wstr1
;
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");
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
);
240 ACE_InputCDR::to_wchar
twc (wch1
);
243 ACE_InputCDR::to_wstring
twstr (wstr1
, 0);
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
);
249 #if !defined(ACE_LACKS_STD_WSTRING)
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);
265 ACE_ERROR_RETURN ((LM_ERROR
,
267 ACE_TEXT ("char transfer error")),
271 ACE_ERROR_RETURN ((LM_ERROR
,
273 ACE_TEXT ("wchar transfer error")),
277 ACE_ERROR_RETURN ((LM_ERROR
,
279 ACE_TEXT ("string transfer error")),
282 if (ACE_OS::wscmp (wstr1
, wstr
))
283 ACE_ERROR_RETURN ((LM_ERROR
,
285 ACE_TEXT ("wide string transfer error")),
288 if (std_str1
!= std_str
)
289 ACE_ERROR_RETURN ((LM_ERROR
,
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
,
298 ACE_TEXT ("std::wstring transfer error")),
303 ACE_ERROR_RETURN ((LM_ERROR
,
305 ACE_TEXT ("short transfer error")),
309 ACE_ERROR_RETURN ((LM_ERROR
,
311 ACE_TEXT ("ushort transfer error")),
315 ACE_ERROR_RETURN ((LM_ERROR
,
317 ACE_TEXT ("long transfer error")),
321 ACE_ERROR_RETURN ((LM_ERROR
,
323 ACE_TEXT ("ulong transfer error")),
326 if (!ACE::is_equal (f1
, f
))
327 ACE_ERROR_RETURN ((LM_ERROR
,
329 ACE_TEXT ("float transfer error")),
332 if (!ACE::is_equal (d1
, d
))
333 ACE_ERROR_RETURN ((LM_ERROR
,
335 ACE_TEXT ("double transfer error")),
339 ACE_ERROR_RETURN ((LM_ERROR
,
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
,
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
,
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
,
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
,
369 ACE_TEXT ("double array transfer error")),
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"),
437 CDR_Test_Types::test_get (ACE_InputCDR
&cdr
) const
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"),
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"),
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"),
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"),
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"),
490 ACE_ERROR_RETURN ((LM_ERROR
,
491 ACE_TEXT ("long-2[%d] differs\n"),
496 if (cdr
.read_string (xstr
) == 0)
497 ACE_ERROR_RETURN ((LM_ERROR
,
498 ACE_TEXT ("read_string2[%d] failed\n"),
501 std::unique_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"),
515 std::unique_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"),
552 CDR_Test_Types::test_put_placeholder (ACE_OutputCDR
&cdr
)
554 // Write a placeholder then a bunch of other stuff, then replace.
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")),
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")),
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")),
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")),
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")),
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")),
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")),
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")),
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")),
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")),
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")),
680 CDR_Test_Types::test_get_placeholder (ACE_InputCDR
&cdr
) const
688 ACE_CDR::LongLong xll
;
689 ACE_CDR::ULongLong xull
;
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")),
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:"));
860 while ((opt
= get_opt ()) != EOF
)
868 n
= ACE_OS::atoi (get_opt
.opt_arg ());
871 nloops
= ACE_OS::atoi (get_opt
.opt_arg ());
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> ")
881 ACE_TEXT ("CDR_Test")));
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 )
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)
915 ACE_InputCDR
input (output
);
918 ACE_DEBUG ((LM_DEBUG
,
919 ACE_TEXT ("Output CDR:\n")));
920 ACE_HEX_DUMP ((LM_DEBUG
,
923 ACE_DEBUG ((LM_DEBUG
,
924 ACE_TEXT ("Input CDR:\n")));
925 ACE_HEX_DUMP ((LM_DEBUG
,
930 if (test_types
.test_get (input
) != 0)
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)
946 ACE_InputCDR
input (output
.begin ());
949 ACE_DEBUG ((LM_DEBUG
,
950 ACE_TEXT ("Output CDR:\n")));
951 ACE_HEX_DUMP ((LM_DEBUG
,
954 ACE_DEBUG ((LM_DEBUG
,
955 ACE_TEXT ("Input CDR:\n")));
956 ACE_HEX_DUMP ((LM_DEBUG
,
961 if (test_types
.test_get (input
) != 0)
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)
975 if (output
.begin () == output
.end ())
976 ACE_DEBUG ((LM_WARNING
,
977 ACE_TEXT ("Only one block needed; test no effective.\n")));
980 if (output
.consolidate () != 0)
981 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("%p\n"), ACE_TEXT ("consolidate")));
984 ACE_InputCDR
input (output
);
987 ACE_DEBUG ((LM_DEBUG
,
988 ACE_TEXT ("Output CDR:\n")));
989 ACE_HEX_DUMP ((LM_DEBUG
,
992 ACE_DEBUG ((LM_DEBUG
,
993 ACE_TEXT ("Input CDR:\n")));
994 ACE_HEX_DUMP ((LM_DEBUG
,
999 if (test_types
.test_get (input
) != 0)
1002 ACE_DEBUG ((LM_DEBUG
,
1003 ACE_TEXT ("Consolidation - no errors\n\n")
1004 ACE_TEXT ("Testing placeholder/replace\n\n")));
1007 if (test_types
.test_put_placeholder (output
) != 0)
1010 input
= ACE_InputCDR(output
);
1013 ACE_DEBUG ((LM_DEBUG
,
1014 ACE_TEXT ("Output CDR:\n")));
1015 ACE_HEX_DUMP ((LM_DEBUG
,
1018 ACE_DEBUG ((LM_DEBUG
,
1019 ACE_TEXT ("Input CDR:\n")));
1020 ACE_HEX_DUMP ((LM_DEBUG
,
1025 if (test_types
.test_get_placeholder (input
) != 0)
1028 ACE_DEBUG ((LM_DEBUG
,
1029 ACE_TEXT ("Placeholder/Replace - no errors\n\n")));