29 #define MAX_DATA_SIZE 1024
30 #define MAX_ENCODED_SIZE 2048
33 const char *encoded_ref)
40 printf(
"Failed: cannot encode the input data\n");
43 if (encoded_ref && strcmp(encoded, encoded_ref)) {
44 printf(
"Failed: encoded string differs from reference\n"
45 "Encoded:\n%s\nReference:\n%s\n", encoded, encoded_ref);
49 if ((data2_size =
av_base64_decode(data2, encoded, max_data2_size)) != data_size) {
50 printf(
"Failed: cannot decode the encoded string\n"
51 "Encoded:\n%s\n", encoded);
54 if ((data2_size =
av_base64_decode(data2, encoded, data_size)) != data_size) {
55 printf(
"Failed: cannot decode with minimal buffer\n"
56 "Encoded:\n%s\n", encoded);
59 if (memcmp(data2,
data, data_size)) {
60 printf(
"Failed: encoded/decoded data differs from original data\n");
64 printf(
"Failed: decode to NULL buffer\n");
67 if (data_size > 0 && (data2_size =
av_base64_decode(data2, encoded, data_size - 1)) != data_size - 1) {
68 printf(
"Failed: out of array write\n"
69 "Encoded:\n%s\n", encoded);
72 if (data_size > 1 && (data2_size =
av_base64_decode(data2, encoded, data_size - 2)) != data_size - 2) {
73 printf(
"Failed: out of array write\n"
74 "Encoded:\n%s\n", encoded);
77 if (strlen(encoded)) {
78 char *end = strchr(encoded,
'=');
80 end = encoded + strlen(encoded) - 1;
83 printf(
"Failed: error detection\n");
92 int main(
int argc,
char ** argv)
94 int i, error_count = 0;
97 const char *encoded_ref;
103 {
"4444",
"NDQ0NA=="},
104 {
"55555",
"NTU1NTU="},
105 {
"666666",
"NjY2NjY2"},
106 {
"abc:def",
"YWJjOmRlZg=="},
108 char in[1024],
out[2048];
110 printf(
"Encoding/decoding tests\n");
114 if (argc>1 && !strcmp(argv[1],
"-t")) {
115 memset(in, 123,
sizeof(in));
116 for(
i=0;
i<10000;
i++){
121 for(
i=0;
i<10000;
i++){
127 for(
i=0;
i<10000;
i++){
135 printf(
"Error Count: %d.\n", error_count);
137 return !!error_count;