ACE+TAO-7_0_8
[ACE_TAO.git] / ACE / tests / Codecs_Test.cpp
blobc851b26c08e235df8236a9bd22b8ecb742bdb0d3
2 //=============================================================================
3 /**
4 * @file Codecs_Test.cpp
6 * Checks the functionality of the ACE Codecs class.
8 * @author Krishnakumar B <kitty@cs.wustl.edu>
9 */
10 //=============================================================================
13 #include "test_config.h"
14 #include "ace/Codecs.h"
15 #include "ace/Auto_Ptr.h"
16 #include "ace/ACE.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";
28 int
29 encode_decode_stream (const ACE_Byte* stream, size_t length)
31 size_t encode_len = 0;
33 ACE_DEBUG ((LM_DEBUG,
34 ACE_TEXT ("Input stream = %C\n"),
35 stream));
37 ACE_Byte* encodeBuf = ACE_Base64::encode (stream, length,
38 &encode_len);
39 if (encodeBuf == 0)
41 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error in encoding stream\n")));
42 return -1;
45 ACE_DEBUG ((LM_DEBUG,
46 ACE_TEXT ("Base64 encoded stream = %C\n"),
47 encodeBuf));
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);
55 if (decodeBuf == 0)
57 ACE_ERROR ((LM_ERROR,
58 ACE_TEXT ("Error in decoding encoded stream\n")));
59 return -1;
62 ACE_Auto_Basic_Array_Ptr<ACE_Byte> cleanup_decodeBuf (decodeBuf);
64 ACE_DEBUG ((LM_DEBUG,
65 ACE_TEXT ("Decoded Base64 encoded stream = %C\n"),
66 decodeBuf));
68 for (size_t i = 0; i < length; ++i)
69 if (decodeBuf[i] != stream[i])
71 ACE_ERROR ((LM_ERROR,
72 ACE_TEXT ("Encoded->Decoded stream differs from original stream\n")));
73 return -1;
75 return 0;
78 int
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"));
85 int status = 0;
87 ACE_DEBUG ((LM_DEBUG,
88 ACE_TEXT ("This is ACE Version %u.%u.%u\n\n"),
89 ACE::major_version (),
90 ACE::minor_version(),
91 ACE::micro_version()));
93 ACE_DEBUG ((LM_DEBUG,
94 ACE_TEXT ("Testing ACE Base64 - normal stream\n\n")));
96 status = encode_decode_stream (normal_stream, sizeof (normal_stream) - 1);
98 if (status == 0) {
99 ACE_DEBUG ((LM_DEBUG,
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);
104 if (status == 0) {
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);
110 ACE_END_TEST;
111 return status;