Commit 5f0b1ed3 5f0b1ed3c5d5276df98b20cb4bb020915b6a064c by Sergey Poznyakoff

Fix base64 test.

* examples/base64.c (c_copy): Handle printable mode (-p).
(reset_line_length): New function.
(main): New option -lN sets the maximum length for output
lines to N (0 means unlimited).
* mailbox/testsuite/mailbox/base64.exp: Use -l0 in the
Decode test.
1 parent 8f8e01b9
......@@ -35,7 +35,28 @@ int printable = 0;
static void
c_copy (mu_stream_t out, mu_stream_t in)
{
if (printable)
{
char c;
size_t size;
while (mu_stream_read (in, &c, 1, &size) == 0 && size > 0)
{
int rc;
if (printable && !ISPRINT (c))
{
char outbuf[24];
sprintf (outbuf, "\\%03o", (unsigned char) c);
rc = mu_stream_write (out, outbuf, strlen (outbuf), NULL);
}
else
rc = mu_stream_write (out, &c, 1, NULL);
}
}
else
MU_ASSERT (mu_stream_copy (out, in, 0));
mu_stream_write (out, "\n", 1, NULL);
mu_stream_close (out);
mu_stream_close (in);
if (verbose)
......@@ -44,6 +65,23 @@ c_copy (mu_stream_t out, mu_stream_t in)
(unsigned long) mu_stream_bytes_out (out));
}
/* Set the maximum line length for the filter NAME to LENGTH.
FIXME: This is a kludge. Perhaps API should provide a function
for that. */
static void
reset_line_length (const char *name, size_t length)
{
mu_list_t list;
int status;
mu_filter_record_t frec;
mu_filter_get_list (&list);
status = mu_list_locate (list, (void*)name, (void**)&frec);
if (status == 0)
frec->max_line_length = length;
/* don't bail out, leave that to mu_filter_create */
}
int
main (int argc, char * argv [])
{
......@@ -54,8 +92,10 @@ main (int argc, char * argv [])
char *input = NULL, *output = NULL;
char *encoding = "base64";
mu_off_t shift = 0;
size_t line_length;
int line_length_option = 0;
while ((c = getopt (argc, argv, "deE:hi:o:ps:vw")) != EOF)
while ((c = getopt (argc, argv, "deE:hi:l:o:ps:vw")) != EOF)
switch (c)
{
case 'i':
......@@ -78,8 +118,13 @@ main (int argc, char * argv [])
mode = MU_FILTER_ENCODE;
break;
case 'l':
line_length = strtoul (optarg, NULL, 10);
line_length_option = 1;
break;
case 'p':
printable = 1; /* FIXME: Not implemented */
printable = 1;
break;
case 's':
......@@ -115,6 +160,9 @@ main (int argc, char * argv [])
MU_ASSERT (mu_stdio_stream_create (&out, MU_STDOUT_FD, 0));
MU_ASSERT (mu_stream_open (out));
if (line_length_option)
reset_line_length (encoding, line_length);
if (flags == MU_STREAM_READ)
{
MU_ASSERT (mu_filter_create (&flt, in, encoding, mode,
......
......@@ -29,7 +29,9 @@ mu_exec -message "encode" -arg -i${srcdir}/Encode \
## Expect chokes on binary data, so let's switch base64 to printable
## octal output.
mu_exec -message "decode" -arg -i${srcdir}/Decode -arg -dp \
## The -l0 option ensures that the output is not split by inserting
## additional newlines.
mu_exec -message "decode" -arg -i${srcdir}/Decode -arg -dpl0 \
"\\000\\001\\002\\003\\004\\005\\006\\007\\010\\011\\012\\013\\014\\015\\016\\017\\020\\021\\022\\023\\024\\025\\026\\027\\030\\031\\032\\033\\034\\035\\036\\037 !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\[\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\\177\\200\\201\\202\\203\\204\\205\\206\\207\\210\\211\\212\\213\\214\\215\\216\\217\\220\\221\\222\\223\\224\\225\\226\\227\\230\\231\\232\\233\\234\\235\\236\\237\\240\\241\\242\\243\\244\\245\\246\\247\\250\\251\\252\\253\\254\\255\\256\\257\\260\\261\\262\\263\\264\\265\\266\\267\\270\\271\\272\\273\\274\\275\\276\\277\\300\\301\\302\\303\\304\\305\\306\\307\\310\\311\\312\\313\\314\\315\\316\\317\\320\\321\\322\\323\\324\\325\\326\\327\\330\\331\\332\\333\\334\\335\\336\\337\\340\\341\\342\\343\\344\\345\\346\\347\\350\\351\\352\\353\\354\\355\\356\\357\\360\\361\\362\\363\\364\\365\\366\\367\\370\\371\\372\\373\\374\\375\\376\\377"
# End of base64.exp
......