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; ...@@ -35,7 +35,28 @@ int printable = 0;
35 static void 35 static void
36 c_copy (mu_stream_t out, mu_stream_t in) 36 c_copy (mu_stream_t out, mu_stream_t in)
37 { 37 {
38 if (printable)
39 {
40 char c;
41 size_t size;
42
43 while (mu_stream_read (in, &c, 1, &size) == 0 && size > 0)
44 {
45 int rc;
46
47 if (printable && !ISPRINT (c))
48 {
49 char outbuf[24];
50 sprintf (outbuf, "\\%03o", (unsigned char) c);
51 rc = mu_stream_write (out, outbuf, strlen (outbuf), NULL);
52 }
53 else
54 rc = mu_stream_write (out, &c, 1, NULL);
55 }
56 }
57 else
38 MU_ASSERT (mu_stream_copy (out, in, 0)); 58 MU_ASSERT (mu_stream_copy (out, in, 0));
59 mu_stream_write (out, "\n", 1, NULL);
39 mu_stream_close (out); 60 mu_stream_close (out);
40 mu_stream_close (in); 61 mu_stream_close (in);
41 if (verbose) 62 if (verbose)
...@@ -44,6 +65,23 @@ c_copy (mu_stream_t out, mu_stream_t in) ...@@ -44,6 +65,23 @@ c_copy (mu_stream_t out, mu_stream_t in)
44 (unsigned long) mu_stream_bytes_out (out)); 65 (unsigned long) mu_stream_bytes_out (out));
45 } 66 }
46 67
68 /* Set the maximum line length for the filter NAME to LENGTH.
69 FIXME: This is a kludge. Perhaps API should provide a function
70 for that. */
71 static void
72 reset_line_length (const char *name, size_t length)
73 {
74 mu_list_t list;
75 int status;
76 mu_filter_record_t frec;
77
78 mu_filter_get_list (&list);
79 status = mu_list_locate (list, (void*)name, (void**)&frec);
80 if (status == 0)
81 frec->max_line_length = length;
82 /* don't bail out, leave that to mu_filter_create */
83 }
84
47 int 85 int
48 main (int argc, char * argv []) 86 main (int argc, char * argv [])
49 { 87 {
...@@ -54,8 +92,10 @@ main (int argc, char * argv []) ...@@ -54,8 +92,10 @@ main (int argc, char * argv [])
54 char *input = NULL, *output = NULL; 92 char *input = NULL, *output = NULL;
55 char *encoding = "base64"; 93 char *encoding = "base64";
56 mu_off_t shift = 0; 94 mu_off_t shift = 0;
95 size_t line_length;
96 int line_length_option = 0;
57 97
58 while ((c = getopt (argc, argv, "deE:hi:o:ps:vw")) != EOF) 98 while ((c = getopt (argc, argv, "deE:hi:l:o:ps:vw")) != EOF)
59 switch (c) 99 switch (c)
60 { 100 {
61 case 'i': 101 case 'i':
...@@ -78,8 +118,13 @@ main (int argc, char * argv []) ...@@ -78,8 +118,13 @@ main (int argc, char * argv [])
78 mode = MU_FILTER_ENCODE; 118 mode = MU_FILTER_ENCODE;
79 break; 119 break;
80 120
121 case 'l':
122 line_length = strtoul (optarg, NULL, 10);
123 line_length_option = 1;
124 break;
125
81 case 'p': 126 case 'p':
82 printable = 1; /* FIXME: Not implemented */ 127 printable = 1;
83 break; 128 break;
84 129
85 case 's': 130 case 's':
...@@ -115,6 +160,9 @@ main (int argc, char * argv []) ...@@ -115,6 +160,9 @@ main (int argc, char * argv [])
115 MU_ASSERT (mu_stdio_stream_create (&out, MU_STDOUT_FD, 0)); 160 MU_ASSERT (mu_stdio_stream_create (&out, MU_STDOUT_FD, 0));
116 MU_ASSERT (mu_stream_open (out)); 161 MU_ASSERT (mu_stream_open (out));
117 162
163 if (line_length_option)
164 reset_line_length (encoding, line_length);
165
118 if (flags == MU_STREAM_READ) 166 if (flags == MU_STREAM_READ)
119 { 167 {
120 MU_ASSERT (mu_filter_create (&flt, in, encoding, mode, 168 MU_ASSERT (mu_filter_create (&flt, in, encoding, mode,
......
...@@ -29,7 +29,9 @@ mu_exec -message "encode" -arg -i${srcdir}/Encode \ ...@@ -29,7 +29,9 @@ mu_exec -message "encode" -arg -i${srcdir}/Encode \
29 29
30 ## Expect chokes on binary data, so let's switch base64 to printable 30 ## Expect chokes on binary data, so let's switch base64 to printable
31 ## octal output. 31 ## octal output.
32 mu_exec -message "decode" -arg -i${srcdir}/Decode -arg -dp \ 32 ## The -l0 option ensures that the output is not split by inserting
33 ## additional newlines.
34 mu_exec -message "decode" -arg -i${srcdir}/Decode -arg -dpl0 \
33 "\\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" 35 "\\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"
34 36
35 # End of base64.exp 37 # End of base64.exp
......