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"
19 // Don't change the strings thinking that they are typos
21 const ACE_Byte normal_stream
[] = "This is a sample test stream, to test simple Base64 encoding";
23 const ACE_Byte one_padded_stream
[] = "This stream is different from the above in that, it results in one padding character to be adde";
25 const ACE_Byte two_padded_stream
[] = "This stream is different from the above in that, it results in two padding characters to be addedddd";
28 encode_decode_stream (const ACE_Byte
* stream
, size_t length
)
30 size_t encode_len
= 0;
33 ACE_TEXT ("Input stream = %C\n"),
36 ACE_Byte
* encodeBuf
= ACE_Base64::encode (stream
, length
,
40 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Error in encoding stream\n")));
45 ACE_TEXT ("Base64 encoded stream = %C\n"),
49 ACE_Auto_Basic_Array_Ptr
<ACE_Byte
> cleanup_encodeBuf (encodeBuf
);
51 size_t decode_len
= 0;
52 ACE_Byte
* decodeBuf
= ACE_Base64::decode (encodeBuf
, &decode_len
);
57 ACE_TEXT ("Error in decoding encoded stream\n")));
61 ACE_Auto_Basic_Array_Ptr
<ACE_Byte
> cleanup_decodeBuf (decodeBuf
);
64 ACE_TEXT ("Decoded Base64 encoded stream = %C\n"),
67 for (size_t i
= 0; i
< length
; ++i
)
68 if (decodeBuf
[i
] != stream
[i
])
71 ACE_TEXT ("Encoded->Decoded stream differs from original stream\n")));
78 run_main (int argc
, ACE_TCHAR
*argv
[])
80 ACE_UNUSED_ARG (argc
);
81 ACE_UNUSED_ARG (argv
);
83 ACE_START_TEST (ACE_TEXT ("Codecs_Test"));
87 ACE_TEXT ("This is ACE Version %u.%u.%u\n\n"),
88 ACE::major_version (),
90 ACE::micro_version()));
93 ACE_TEXT ("Testing ACE Base64 - normal stream\n\n")));
95 status
= encode_decode_stream (normal_stream
, sizeof (normal_stream
) - 1);
99 ACE_TEXT ("Testing ACE Base64 - one padded stream\n\n")));
100 status
= encode_decode_stream (one_padded_stream
,
101 sizeof (one_padded_stream
) - 1);
104 ACE_DEBUG ((LM_DEBUG
,
105 ACE_TEXT ("Testing ACE Base64 - two padded stream\n\n")));
106 status
= encode_decode_stream (two_padded_stream
,
107 sizeof (two_padded_stream
) - 1);