Commit fcdbdbe2 fcdbdbe218624d26166f502da3d918165bf30da8 by Sergey Poznyakoff

Test transcript streams

* libmailutils/tests/.gitignore: Update.
* libmailutils/tests/xscript.at: New file.
* libmailutils/tests/xscript.c: New file.
* libmailutils/tests/Makefile.am: Add new files.
* libmailutils/tests/testsuite.at: Include new testcase.
1 parent 86c9e64b
...@@ -39,3 +39,4 @@ vexp ...@@ -39,3 +39,4 @@ vexp
39 wicket 39 wicket
40 wordwrap 40 wordwrap
41 wsp 41 wsp
42 xscript
......
...@@ -73,7 +73,8 @@ noinst_PROGRAMS = \ ...@@ -73,7 +73,8 @@ noinst_PROGRAMS = \
73 vexp\ 73 vexp\
74 wicket\ 74 wicket\
75 wordwrap\ 75 wordwrap\
76 wsp 76 wsp\
77 xscript
77 78
78 LDADD = ${MU_LIB_MAILUTILS} 79 LDADD = ${MU_LIB_MAILUTILS}
79 80
...@@ -169,7 +170,8 @@ TESTSUITE_AT = \ ...@@ -169,7 +170,8 @@ TESTSUITE_AT = \
169 wordwrap00.at\ 170 wordwrap00.at\
170 wordwrap01.at\ 171 wordwrap01.at\
171 wordwrap02.at\ 172 wordwrap02.at\
172 wordwrap03.at 173 wordwrap03.at\
174 xscript.at
173 175
174 TESTSUITE = $(srcdir)/testsuite 176 TESTSUITE = $(srcdir)/testsuite
175 M4=m4 177 M4=m4
......
...@@ -207,3 +207,5 @@ m4_include([mimehdr.at]) ...@@ -207,3 +207,5 @@ m4_include([mimehdr.at])
207 m4_include([msgset.at]) 207 m4_include([msgset.at])
208 208
209 m4_include([globtest.at]) 209 m4_include([globtest.at])
210
211 m4_include([xscript.at])
......
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2016-2017 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_BANNER([Transcript stream])
18 AT_SETUP([Transcript stream])
19 AT_KEYWORDS([stream xscript])
20 AT_DATA([input],[first line
21 second line
22 login ty coon
23 login "ty" "coon"
24 pass guessme
25 \s
26 login ty coon
27 login "ty" "coon"
28 pass guessme
29 \p
30 GNU Mailutils is free software; you can redistribute it and/or
31 modify it under the terms of the GNU General Public License as
32 \n
33 published by the Free Software Foundation; either version 3, or (at
34 your option) any later version.
35 ])
36
37 AT_CHECK([xscript < input],
38 [0],
39 [0001: first line
40 0002: second line
41 0003: login ty coon
42 0004: login "ty" "coon"
43 0005: pass guessme
44 // n
45 0007: login ty coon
46 0008: login "ty" "coon"
47 0009: pass guessme
48 // s
49 0011: GNU Mailutils is free software; you can redistribute it and/or
50 0012: modify it under the terms of the GNU General Public License as
51 // p
52 0014: published by the Free Software Foundation; either version 3, or (at
53 0015: your option) any later version.
54 ],
55 [C: first line
56 S: 0001: first line
57 C: second line
58 S: 0002: second line
59 C: login ty coon
60 S: 0003: login ty coon
61 C: login "ty" "coon"
62 S: 0004: login "ty" "coon"
63 C: pass guessme
64 S: 0005: pass guessme
65 C: \s
66 S: // n
67 C: login ty coon
68 S: 0007: login ty "***"
69 C: login "ty" "coon"
70 S: 0008: login "ty" "***"
71 C: PASS ***
72 S: 0009: pass guessme
73 C: \p
74 S: (data...)
75 C: (data...)
76 S: // p
77 C: published by the Free Software Foundation; either version 3, or (at
78 S: 0014: published by the Free Software Foundation; either version 3, or (at
79 C: your option) any later version.
80 S: 0015: your option) any later version.
81 ])
82 AT_CLEANUP
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2005, 2007, 2009-2012, 2014-2017 Free Software
3 Foundation, Inc.
4
5 GNU Mailutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3, or (at your option)
8 any later version.
9
10 GNU Mailutils is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
17
18 /* A simple echo server for testing transcript streams.
19 Each input line is prefixed with the input line number and echoed on
20 stdout.
21
22 Input starting with '\\' is a command request. It must contain a string
23 consisting of one of the following letters:
24 n toggle normal transcript mode;
25 s toggle secure transcript mode (passwords are not displayed);
26 p toggle payload transcript mode.
27
28 Several letters can be passed in a single request, although that doesn't
29 have much sense.
30
31 The server responds to the command request with a "// " followed by
32 the letters describing previous transcript mode.
33
34 Transcript of the session goes to stderr.
35 */
36
37 #include <mailutils/mailutils.h>
38
39 mu_stream_t
40 create_transcript (void)
41 {
42 mu_stream_t iostr;
43 mu_stream_t xstr;
44 mu_stream_t dstr;
45
46 mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
47 MU_ASSERT (mu_iostream_create (&iostr, mu_strin, mu_strout));
48 mu_stream_set_buffer (iostr, mu_buffer_line, 0);
49
50 MU_ASSERT (mu_dbgstream_create (&dstr, MU_DIAG_DEBUG));
51
52 MU_ASSERT (mu_xscript_stream_create (&xstr, iostr, dstr, NULL));
53 mu_stream_unref (dstr);
54 mu_stream_unref (iostr);
55 return xstr;
56 }
57
58 static int
59 xstream_setopt (mu_stream_t str, char const *buf)
60 {
61 int flag = MU_XSCRIPT_NORMAL;
62 for (; *buf; buf++)
63 {
64 switch (*buf)
65 {
66 case 'n':
67 case 'N':
68 flag |= MU_XSCRIPT_NORMAL;
69 break;
70 case 's':
71 case 'S':
72 flag |= MU_XSCRIPT_SECURE;
73 break;
74 case 'p':
75 case 'P':
76 flag |= MU_XSCRIPT_PAYLOAD;
77 break;
78 case '\n':
79 break;
80 default:
81 mu_error ("unrecognized flag: %c", *buf);
82 return -1;
83 }
84 }
85 MU_ASSERT (mu_stream_ioctl (str, MU_IOCTL_XSCRIPTSTREAM,
86 MU_IOCTL_XSCRIPTSTREAM_LEVEL, &flag));
87 mu_stream_printf (str, "// ");
88 if (flag == MU_XSCRIPT_NORMAL)
89 mu_stream_printf (str, "n");
90 else
91 {
92 if (flag & MU_XSCRIPT_SECURE)
93 mu_stream_printf (str, "s");
94 if (flag & MU_XSCRIPT_PAYLOAD)
95 mu_stream_printf (str, "p");
96 }
97 mu_stream_printf (str, "\n");
98 return 0;
99 }
100
101 int
102 main (int argc, char **argv)
103 {
104 int rc;
105 char *buf = NULL;
106 size_t size = 0, n;
107 unsigned line = 0;
108 mu_stream_t str = create_transcript ();
109
110 while ((rc = mu_stream_getline (str, &buf, &size, &n)) == 0 && n > 0)
111 {
112 line++;
113 if (buf[0] == '\\')
114 {
115 xstream_setopt (str, buf + 1);
116 continue;
117 }
118 mu_stream_printf (str, "%04u: %s", line, buf);
119 }
120 mu_stream_destroy (&str);
121 exit (0);
122 }
123
124