2 //=============================================================================
4 * @file Codecs_Test.cpp
6 * Checks the functionality of the ACE Codecs class.
8 * @author Krishnakumar B <kitty@cs.wustl.edu>
10 //=============================================================================
13 #include "test_config.h"
14 #include "ace/Codecs.h"
15 #include "ace/Auto_Ptr.h"
20 // Don't change the strings thinking that they are typos
22 const ACE_Byte normal_stream
[] = "This is a sample test stream, to test simple Base64 encoding";
24 const ACE_Byte one_padded_stream
[] = "This stream is different from the above in that, it results in one padding character to be adde";
26 const ACE_Byte two_padded_stream
[] = "This stream is different from the above in that, it results in two padding characters to be addedddd";
29 encode_decode_stream (const ACE_Byte
* stream
, size_t length
)
31 size_t encode_len
= 0;
34 ACE_TEXT ("Input stream = %C\n"),
37 ACE_Byte
* encodeBuf
= ACE_Base64::encode (stream
, length
,
41 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Error in encoding stream\n")));
46 ACE_TEXT ("Base64 encoded stream = %C\n"),
50 ACE_Auto_Basic_Array_Ptr
<ACE_Byte
> cleanup_encodeBuf (encodeBuf
);
52 size_t decode_len
= 0;
53 ACE_Byte
* decodeBuf
= ACE_Base64::decode (encodeBuf
, &decode_len
);
58 ACE_TEXT ("Error in decoding encoded stream\n")));
62 ACE_Auto_Basic_Array_Ptr
<ACE_Byte
> cleanup_decodeBuf (decodeBuf
);
65 ACE_TEXT ("Decoded Base64 encoded stream = %C\n"),
68 for (size_t i
= 0; i
< length
; ++i
)
69 if (decodeBuf
[i
] != stream
[i
])
72 ACE_TEXT ("Encoded->Decoded stream differs from original stream\n")));
79 run_main (int argc
, ACE_TCHAR
*argv
[])
81 ACE_UNUSED_ARG (argc
);
82 ACE_UNUSED_ARG (argv
);
84 ACE_START_TEST (ACE_TEXT ("Codecs_Test"));
88 ACE_TEXT ("This is ACE Version %u.%u.%u\n\n"),
89 ACE::major_version (),
91 ACE::micro_version()));
94 ACE_TEXT ("Testing ACE Base64 - normal stream\n\n")));
96 status
= encode_decode_stream (normal_stream
, sizeof (normal_stream
) - 1);
100 ACE_TEXT ("Testing ACE Base64 - one padded stream\n\n")));
101 status
= encode_decode_stream (one_padded_stream
,
102 sizeof (one_padded_stream
) - 1);
105 ACE_DEBUG ((LM_DEBUG
,
106 ACE_TEXT ("Testing ACE Base64 - two padded stream\n\n")));
107 status
= encode_decode_stream (two_padded_stream
,
108 sizeof (two_padded_stream
) - 1);