1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or
4
modify it under the terms of the GNU General Public License as
5
published by the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful, but
8
WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include <my_global.h>
22
#define BASE64_LOOP_COUNT 500
23
#define BASE64_ROWS 4 /* Number of ok(..) */
29
size_t j, k, l, dst_len, needed_length;
32
plan(BASE64_LOOP_COUNT * BASE64_ROWS);
34
for (i= 0; i < BASE64_LOOP_COUNT; i++)
36
/* Create source data */
37
const size_t src_len= rand() % 1000 + 1;
39
char * src= (char *) malloc(src_len);
44
for (j= 0; j<src_len; j++)
51
needed_length= base64_needed_encoded_length(src_len);
52
str= (char *) malloc(needed_length);
53
for (k= 0; k < needed_length; k++)
54
str[k]= 0xff; /* Fill memory to check correct NUL termination */
55
ok(base64_encode(src, src_len, str) == 0,
56
"base64_encode: size %d", i);
57
ok(needed_length == strlen(str) + 1,
58
"base64_needed_encoded_length: size %d", i);
61
dst= (char *) malloc(base64_needed_decoded_length(strlen(str)));
62
dst_len= base64_decode(str, strlen(str), dst, NULL);
63
ok(dst_len == src_len, "Comparing lengths");
65
cmp= memcmp(src, dst, src_len);
66
ok(cmp == 0, "Comparing encode-decode result");
70
diag(" --------- src --------- --------- dst ---------");
71
for (k= 0; k<src_len; k+=8)
73
sprintf(buf, "%.4x ", (uint) k);
74
for (l=0; l<8 && k+l<src_len; l++)
76
unsigned char c= src[k+l];
77
sprintf(buf, "%.2x ", (unsigned)c);
82
for (l=0; l<8 && k+l<dst_len; l++)
84
unsigned char c= dst[k+l];
85
sprintf(buf, "%.2x ", (unsigned)c);
89
diag("src length: %.8x, dst length: %.8x\n",
90
(uint) src_len, (uint) dst_len);