Use override/default for RTPortableServer
[ACE_TAO.git] / ACE / tests / Codecs_Test.cpp
blob24b65cb9c9ff96382128565b60666b64be5223dd
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"
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";
27 int
28 encode_decode_stream (const ACE_Byte* stream, size_t length)
30 size_t encode_len = 0;
32 ACE_DEBUG ((LM_DEBUG,
33 ACE_TEXT ("Input stream = %C\n"),
34 stream));
36 ACE_Byte* encodeBuf = ACE_Base64::encode (stream, length,
37 &encode_len);
38 if (encodeBuf == 0)
40 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error in encoding stream\n")));
41 return -1;
44 ACE_DEBUG ((LM_DEBUG,
45 ACE_TEXT ("Base64 encoded stream = %C\n"),
46 encodeBuf));
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);
54 if (decodeBuf == 0)
56 ACE_ERROR ((LM_ERROR,
57 ACE_TEXT ("Error in decoding encoded stream\n")));
58 return -1;
61 ACE_Auto_Basic_Array_Ptr<ACE_Byte> cleanup_decodeBuf (decodeBuf);
63 ACE_DEBUG ((LM_DEBUG,
64 ACE_TEXT ("Decoded Base64 encoded stream = %C\n"),
65 decodeBuf));
67 for (size_t i = 0; i < length; ++i)
68 if (decodeBuf[i] != stream[i])
70 ACE_ERROR ((LM_ERROR,
71 ACE_TEXT ("Encoded->Decoded stream differs from original stream\n")));
72 return -1;
74 return 0;
77 int
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"));
84 int status = 0;
86 ACE_DEBUG ((LM_DEBUG,
87 ACE_TEXT ("This is ACE Version %u.%u.%u\n\n"),
88 ACE::major_version (),
89 ACE::minor_version(),
90 ACE::micro_version()));
92 ACE_DEBUG ((LM_DEBUG,
93 ACE_TEXT ("Testing ACE Base64 - normal stream\n\n")));
95 status = encode_decode_stream (normal_stream, sizeof (normal_stream) - 1);
97 if (status == 0) {
98 ACE_DEBUG ((LM_DEBUG,
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);
103 if (status == 0) {
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);
109 ACE_END_TEST;
110 return status;