summaryrefslogtreecommitdiff
path: root/libmailutils/tests/strout.c
diff options
context:
space:
mode:
Diffstat (limited to 'libmailutils/tests/strout.c')
-rw-r--r--libmailutils/tests/strout.c110
1 files changed, 85 insertions, 25 deletions
diff --git a/libmailutils/tests/strout.c b/libmailutils/tests/strout.c
index f041eab66..d2a705777 100644
--- a/libmailutils/tests/strout.c
+++ b/libmailutils/tests/strout.c
@@ -1,18 +1,52 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
- Copyright (C) 2011-2019 Free Software Foundation, Inc.
+/*
+NAME
+ strout - test whether mu_strout or mu_strerr is functioning.
- GNU Mailutils is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
+DESCRIPTION
+ This test program reads data byte by byte from stdin using the stdio
+ input functions and sends them to mu_strout or mu_strerr using the
+ mu_stream_write function.
- GNU Mailutils is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ The program takes at most 30 seconds to run. If no input is arrived
+ or if EOF is not reached within that interval, the program exits with
+ code 3.
+
+ Both mu_strout and mu_strerr spring into existence the first time they
+ are used by any function of the stream family. Therefore, care is
+ taken not to call any mailutils I/O function either directly or
+ indirectly prior to the first write to the stream being tested.
+
+OPTIONS
+ -err
+ Write to mu_strerr.
+
+ -reset
+ Call mu_stdstream_setup with the appropriate MU_STDSTREAM_RESET_
+ flag explicitly.
+
+EXIT CODES
+ 0 Success
+ 1 Usage error
+ 2 I/O error
+ 3 Timeout
+
+LICENSE
+ GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2011-2024 Free Software Foundation, Inc.
+
+ GNU Mailutils is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ GNU Mailutils is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
+ You should have received a copy of the GNU General Public License
+ along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
+*/
#ifdef HAVE_CONFIG_H
# include <config.h>
@@ -20,25 +54,35 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
+#include <signal.h>
#include <mailutils/stream.h>
#include <mailutils/stdstream.h>
#include <mailutils/diag.h>
+#include <mailutils/errno.h>
+
+enum
+ {
+ EX_STROUT_OK,
+ EX_STROUT_USAGE,
+ EX_STROUT_FAIL,
+ EX_STROUT_TIMEOUT
+ };
+
+void
+sigalrm (int sig)
+{
+ fprintf (stderr, "time out\n");
+ _exit (EX_STROUT_TIMEOUT);
+}
int
main (int argc, char **argv)
{
mu_stream_t str = mu_strout;
int i;
-
- if (argc == 1)
- {
- fprintf (stderr, "usage: %s: word|option [word|option...]\n", argv[0]);
- fprintf (stderr, "options are: -out, -err, -reset\n");
- return 1;
- }
+ signed char c;
- mu_set_program_name (argv[0]);
-
for (i = 1; i < argc; i++)
{
char *arg = argv[i];
@@ -64,12 +108,28 @@ main (int argc, char **argv)
else
{
fprintf (stderr, "%s: unrecognized option %s\n", argv[0], arg);
- return 1;
+ return EX_STROUT_USAGE;
}
}
- else
- mu_stream_printf (str, "%s\n", arg);
+ }
+
+ signal(SIGALRM, sigalrm);
+ alarm (30);
+ while ((c = getchar ()) != EOF)
+ {
+ size_t n;
+ int rc = mu_stream_write (str, &c, 1, &n);
+ if (rc)
+ {
+ fprintf (stderr, "mu_stream_write: %s", mu_strerror (rc));
+ return EX_STROUT_FAIL;
+ }
+ if (n != 1)
+ {
+ fprintf (stderr, "wrote %zu bytes?\n", n);
+ return EX_STROUT_FAIL;
+ }
}
- return 0;
+ return EX_STROUT_OK;
}

Return to:

Send suggestions and report system problems to the System administrator.