diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-08-18 17:38:10 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-08-18 17:38:10 +0300 |
commit | d2eb03a3b9db683418cc0bd084915468e4968854 (patch) | |
tree | ec40bc0c8e9f9f53acb9cb0b7d76ee197410c85c | |
parent | 37713b42a501892469234b90454731d8d8b7a3e6 (diff) | |
download | mailutils-d2eb03a3b9db683418cc0bd084915468e4968854.tar.gz mailutils-d2eb03a3b9db683418cc0bd084915468e4968854.tar.bz2 |
libmailutils/tests tools: use mu_cli_simple for option handling
-rw-r--r-- | libmailutils/tests/cidr.c | 43 | ||||
-rw-r--r-- | libmailutils/tests/debugspec.c | 54 | ||||
-rw-r--r-- | libmailutils/tests/decode2047.c | 36 | ||||
-rw-r--r-- | libmailutils/tests/encode2047.c | 43 | ||||
-rw-r--r-- | libmailutils/tests/fsfolder.c | 60 | ||||
-rw-r--r-- | libmailutils/tests/globtest.c | 55 | ||||
-rw-r--r-- | libmailutils/tests/imapio.at | 2 | ||||
-rw-r--r-- | libmailutils/tests/imapio.c | 56 | ||||
-rw-r--r-- | libmailutils/tests/mailcap.c | 61 | ||||
-rw-r--r-- | libmailutils/tests/mcf.c | 49 | ||||
-rw-r--r-- | libmailutils/tests/modmesg.c | 134 | ||||
-rw-r--r-- | libmailutils/tests/msgset.c | 187 | ||||
-rw-r--r-- | libmailutils/tests/scantime.c | 39 | ||||
-rw-r--r-- | libmailutils/tests/stream-getdelim.c | 6 | ||||
-rw-r--r-- | libmailutils/tests/strerr.at | 22 | ||||
-rw-r--r-- | libmailutils/tests/strftime.c | 62 | ||||
-rw-r--r-- | libmailutils/tests/strin.c | 74 | ||||
-rw-r--r-- | libmailutils/tests/strout.at | 22 | ||||
-rw-r--r-- | libmailutils/tests/strout.c | 77 | ||||
-rw-r--r-- | libmailutils/tests/t-streamshift.c | 336 | ||||
-rw-r--r-- | libmailutils/tests/t0-stream.c | 2 | ||||
-rw-r--r-- | libmailutils/tests/temp_stream.c | 50 | ||||
-rw-r--r-- | libmailutils/tests/tempfile.c | 130 |
23 files changed, 858 insertions, 742 deletions
diff --git a/libmailutils/tests/cidr.c b/libmailutils/tests/cidr.c index 20e18b0fc..febf92f08 100644 --- a/libmailutils/tests/cidr.c +++ b/libmailutils/tests/cidr.c | |||
@@ -30,36 +30,40 @@ print_bytes (unsigned char *b, size_t l) | |||
30 | printf ("\n"); | 30 | printf ("\n"); |
31 | } | 31 | } |
32 | 32 | ||
33 | static int ipv6_simplify; | ||
34 | |||
35 | struct mu_option options[] = { | ||
36 | { "simplify", 's', NULL, MU_OPTION_DEFAULT, | ||
37 | "simplify IPv6 addresses", mu_c_bool, &ipv6_simplify }, | ||
38 | MU_OPTION_END | ||
39 | }; | ||
40 | |||
33 | int | 41 | int |
34 | main (int argc, char **argv) | 42 | main (int argc, char **argv) |
35 | { | 43 | { |
36 | int flags = 0; | ||
37 | |||
38 | mu_set_program_name (argv[0]); | 44 | mu_set_program_name (argv[0]); |
39 | if (argc < 2) | 45 | mu_cli_simple (argc, argv, |
46 | MU_CLI_OPTION_OPTIONS, options, | ||
47 | MU_CLI_OPTION_PROG_DOC, "cidr test tool", | ||
48 | MU_CLI_OPTION_PROG_ARGS, "CIDR [CIDR...]", | ||
49 | MU_CLI_OPTION_RETURN_ARGC, &argc, | ||
50 | MU_CLI_OPTION_RETURN_ARGV, &argv, | ||
51 | MU_CLI_OPTION_END); | ||
52 | |||
53 | if (argc == 0) | ||
40 | { | 54 | { |
41 | mu_error ("usage: %s [-sS] CIDR [CIDR...]", argv[0]); | 55 | mu_error ("required argument missing; try %s --help for more info", |
56 | mu_program_name); | ||
42 | return 1; | 57 | return 1; |
43 | } | 58 | } |
44 | 59 | ||
45 | while (--argc) | 60 | while (argc--) |
46 | { | 61 | { |
47 | char *arg = *++argv; | 62 | char *arg = *argv++; |
48 | struct mu_cidr cidr; | 63 | struct mu_cidr cidr; |
49 | int rc; | 64 | int rc; |
50 | char *str; | 65 | char *str; |
51 | 66 | ||
52 | if (strcmp (arg, "-s") == 0) | ||
53 | { | ||
54 | flags |= MU_CIDR_FMT_SIMPLIFY; | ||
55 | continue; | ||
56 | } | ||
57 | else if (strcmp (arg, "-S") == 0) | ||
58 | { | ||
59 | flags &= ~MU_CIDR_FMT_SIMPLIFY; | ||
60 | continue; | ||
61 | } | ||
62 | |||
63 | rc = mu_cidr_from_string (&cidr, arg); | 67 | rc = mu_cidr_from_string (&cidr, arg); |
64 | if (rc) | 68 | if (rc) |
65 | { | 69 | { |
@@ -74,10 +78,11 @@ main (int argc, char **argv) | |||
74 | print_bytes (cidr.address, cidr.len); | 78 | print_bytes (cidr.address, cidr.len); |
75 | printf ("netmask ="); | 79 | printf ("netmask ="); |
76 | print_bytes (cidr.netmask, cidr.len); | 80 | print_bytes (cidr.netmask, cidr.len); |
77 | rc = mu_cidr_format (&cidr, flags, &str); | 81 | rc = mu_cidr_format (&cidr, ipv6_simplify ? MU_CIDR_FMT_SIMPLIFY : 0, |
82 | &str); | ||
78 | if (rc) | 83 | if (rc) |
79 | { | 84 | { |
80 | mu_error ("cannot covert to string: %s", mu_strerror (rc)); | 85 | mu_error ("cannot convert to string: %s", mu_strerror (rc)); |
81 | return 2; | 86 | return 2; |
82 | } | 87 | } |
83 | 88 | ||
diff --git a/libmailutils/tests/debugspec.c b/libmailutils/tests/debugspec.c index 9c6feaabc..f99b720dd 100644 --- a/libmailutils/tests/debugspec.c +++ b/libmailutils/tests/debugspec.c | |||
@@ -29,47 +29,35 @@ main (int argc, char **argv) | |||
29 | { | 29 | { |
30 | char *names = NULL; | 30 | char *names = NULL; |
31 | int showunset = 0; | 31 | int showunset = 0; |
32 | char *arg; | 32 | struct mu_option options[] = { |
33 | { "names", 0, "NAME[;NAME...]", MU_OPTION_DEFAULT, | ||
34 | "show only selected categories", mu_c_string, &names }, | ||
35 | { "showunset", 0, NULL, MU_OPTION_DEFAULT, | ||
36 | "show unset debug categories as well", mu_c_incr, &showunset }, | ||
37 | MU_OPTION_END | ||
38 | }; | ||
33 | 39 | ||
34 | mu_set_program_name (argv[0]); | 40 | mu_set_program_name (argv[0]); |
35 | mu_stdstream_setup (MU_STDSTREAM_RESET_NONE); | 41 | mu_stdstream_setup (MU_STDSTREAM_RESET_NONE); |
36 | 42 | ||
37 | if (argc == 1) | 43 | mu_cli_simple (argc, argv, |
44 | MU_CLI_OPTION_SINGLE_DASH, | ||
45 | MU_CLI_OPTION_OPTIONS, options, | ||
46 | MU_CLI_OPTION_PROG_DOC, "Mailutils debug specification test tool", | ||
47 | MU_CLI_OPTION_PROG_ARGS, "SPEC", | ||
48 | MU_CLI_OPTION_RETURN_ARGC, &argc, | ||
49 | MU_CLI_OPTION_RETURN_ARGV, &argv, | ||
50 | MU_CLI_OPTION_END); | ||
51 | |||
52 | |||
53 | if (argc != 1) | ||
38 | { | 54 | { |
39 | mu_printf ("usage: %s spec\n", argv[0]); | 55 | mu_error ("exactly one argument expected; try %s -help for more info", |
56 | mu_program_name); | ||
40 | return 0; | 57 | return 0; |
41 | } | 58 | } |
42 | 59 | ||
43 | while (argc--) | 60 | mu_debug_parse_spec (argv[0]); |
44 | { | ||
45 | arg = *++argv; | ||
46 | |||
47 | if (strncmp (arg, "-names=", 7) == 0) | ||
48 | names = arg + 7; | ||
49 | else if (strcmp (arg, "-showunset") == 0) | ||
50 | showunset = 1; | ||
51 | else if (arg[0] == '-') | ||
52 | { | ||
53 | if (arg[1] == '-' && arg[2] == 0) | ||
54 | { | ||
55 | argc--; | ||
56 | argv++; | ||
57 | break; | ||
58 | } | ||
59 | mu_error ("unrecognised argument: %s", arg); | ||
60 | return 1; | ||
61 | } | ||
62 | else | ||
63 | break; | ||
64 | } | ||
65 | |||
66 | if (argc != 1) | ||
67 | { | ||
68 | mu_error ("usage: %s spec", mu_program_name); | ||
69 | return 1; | ||
70 | } | ||
71 | |||
72 | mu_debug_parse_spec (arg); | ||
73 | 61 | ||
74 | mu_debug_format_spec (mu_strout, names, showunset); | 62 | mu_debug_format_spec (mu_strout, names, showunset); |
75 | mu_printf ("\n"); | 63 | mu_printf ("\n"); |
diff --git a/libmailutils/tests/decode2047.c b/libmailutils/tests/decode2047.c index 2e3c13325..d2cf185aa 100644 --- a/libmailutils/tests/decode2047.c +++ b/libmailutils/tests/decode2047.c | |||
@@ -20,19 +20,14 @@ | |||
20 | #include <stdio.h> | 20 | #include <stdio.h> |
21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | #include <errno.h> | 22 | #include <errno.h> |
23 | #include <string.h> | ||
24 | |||
25 | #include <mailutils/mailutils.h> | 23 | #include <mailutils/mailutils.h> |
26 | 24 | ||
27 | #define ISPRINT(c) ((c)=='\t'||(c)==' '||(c)=='\n'||\ | ||
28 | ((unsigned char)(c)>' '&&(unsigned char)(c)<128)) | ||
29 | |||
30 | void | 25 | void |
31 | print (char *p, int printable) | 26 | print (char *p, int printable) |
32 | { | 27 | { |
33 | for (; *p; p++) | 28 | for (; *p; p++) |
34 | { | 29 | { |
35 | if (printable && *p != '\n' && !ISPRINT (*p)) | 30 | if (printable && *p != '\n' && !mu_isprint (*p)) |
36 | printf ("\\%03o", *(unsigned char *) p); | 31 | printf ("\\%03o", *(unsigned char *) p); |
37 | else | 32 | else |
38 | putchar (*p); | 33 | putchar (*p); |
@@ -43,23 +38,22 @@ int | |||
43 | main (int argc, char *argv[]) | 38 | main (int argc, char *argv[]) |