Commit 5aa2c0a3 5aa2c0a36b26f096b50f8d674e8626e59b4dcc1c by Sergey Poznyakoff

Optimize libmailutils testsuite.

* libmailutils/tests/testsuite.at (MU_TEST_GROUP)
(MU_TEST_KEYWORDS, MU_TEST_COMMAND): New defines.
(mu_trimstr, mu_firstline): New macros.
(MU_GENERIC_TEST): New macro.
* libmailutils/tests/addr.c: Accept addresses from stdin.
* libmailutils/tests/address.at (TESTADDR): If the address
contains single quotes, pass it to the program via stdin.
Uncomment all such tests.
* libmailutils/tests/argcv.at (TESTARGS): Rewrite as a wrapper
over MU_GENERIC_TEST.
* libmailutils/tests/decode2047.at (TESTDEC2047): Likewise.
* libmailutils/tests/mailcap.at (MAILCAP): Likewise.
* libmailutils/tests/url.at (TESTURL): Likewise.
* libmailutils/tests/mailcap.c: Accept data from stdin.
1 parent 0ae3a52e
......@@ -20,6 +20,7 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
......@@ -28,13 +29,14 @@
#include <mailutils/errno.h>
#include <mailutils/kwd.h>
#include <mailutils/mutil.h>
#include <mailutils/cstr.h>
#include <mailutils/cctype.h>
#define EPARSE MU_ERR_NOENT
int
main (int argc, char *argv[])
parse (const char *str)
{
char *str;
size_t i;
size_t pcount = 0;
int status;
......@@ -42,13 +44,6 @@ main (int argc, char *argv[])
mu_address_t address = NULL;
struct mu_address hint;
if (argc != 2)
{
fprintf (stderr, "usage: %s address\n", argv[0]);
return 2;
}
str = argv[1];
hint.domain = "localhost";
status = mu_address_create_hint (&address, str, &hint, MU_ADDR_HINT_DOMAIN);
mu_address_get_count (address, &pcount);
......@@ -101,3 +96,25 @@ main (int argc, char *argv[])
mu_address_destroy (&address);
return 0;
}
int
main (int argc, char *argv[])
{
char buf[256];
if (argc > 2)
{
fprintf (stderr, "usage: %s [address]\n", argv[0]);
return 2;
}
if (argc == 2)
exit (parse (argv[1]));
while (fgets (buf, sizeof buf, stdin))
{
mu_rtrim_class (buf, MU_CTYPE_SPACE);
parse (buf);
}
return 0;
}
......
......@@ -22,7 +22,10 @@ dnl
m4_define([TESTADDR],[
AT_SETUP([Address: [$1]])
AT_KEYWORDS([address $2])
AT_CHECK([addr '[$1]'],m4_shift(m4_shift($@)))
AT_CHECK([m4_if(m4_index([$1],[']),-1,[addr '[$1]'],
[AT_DATA([input],[$1
])
addr < input])],m4_shift(m4_shift($@)))
AT_CLEANUP
])
......@@ -320,9 +323,7 @@ personal <#369>
local-part <guug-bugs-closed> domain <guug.de>
])
dnl --------------------------------------------------------------------------
dnl FIXME:
m4_if([TESTADDR(["'Aernoudt Bottemanne'" <Aernoudt.Bottemanne@Informix.com>],[],
TESTADDR(["'Aernoudt Bottemanne'" <Aernoudt.Bottemanne@Informix.com>],[],
[0],
[naddr: 1
1. email <Aernoudt.Bottemanne@Informix.com>:
......@@ -369,12 +370,12 @@ local-part <paul> domain <pitbull-productions.com>
])
TESTADDR(["'sam@cogent.ca'" <sam@cogent.ca>, "'sroberts@uniserve.com'"],[],
[1],
[0],
[],
[MU_ERR_BAD_822_FORMAT
])
TESTADDR(["'sroberts\@certicom\.ca'" <sroberts@certicom.ca>],[]
TESTADDR(["'sroberts\@certicom\.ca'" <sroberts@certicom.ca>],[],
[0],
[naddr: 1
1. email <sroberts@certicom.ca>:
......@@ -382,9 +383,6 @@ personal <'sroberts@certicom.ca'>
local-part <sroberts> domain <certicom.ca>
])
])
dnl --------------------------------------------------------------------------
TESTADDR(["=?iso-8859-1?Q?Juan_Carlos_Marcos_Rodr=EDguez?=" <jcmarcos@datavoice.es>],[],
[0],
[naddr: 1
......@@ -477,8 +475,6 @@ local-part <jpalme> domain <dsv.su.se>
local-part <drums> domain <cs.utk.edu>
])
dnl FIXME
m4_if([
TESTADDR(["Jakob 'sparky' Kaivo" <jkaivo@elijah.nodomainname.net>],[],
[0],
[naddr: 1
......@@ -486,7 +482,6 @@ TESTADDR(["Jakob 'sparky' Kaivo" <jkaivo@elijah.nodomainname.net>],[],
personal <Jakob 'sparky' Kaivo>
local-part <jkaivo> domain <elijah.nodomainname.net>
])
])
TESTADDR(["Lee R. Copp" <Lee.R.Copp@MichiganScientific.com>],[],
[0],
......@@ -528,8 +523,6 @@ personal <fmartens-2000>
local-part <fmartens-2000> domain <planet.nl>
])
dnl FIXME
m4_if([
TESTADDR(["g'o'tz ohnesorge" <gohnesorge@lh-computertechnik.de>],[],
[0],
[naddr: 1
......@@ -538,8 +531,6 @@ personal <g'o'tz ohnesorge>
local-part <gohnesorge> domain <lh-computertechnik.de>
])
])
TESTADDR(["gao jie" <jiegi@public.wh.hb.cn>],[],
[0],
[naddr: 1
......@@ -607,16 +598,12 @@ personal <zwk@f36.n480.z2.fidonet.org>
local-part <zwk%f36.n480.z2.fidonet.org> domain <f36.n480.z2.fidonet.org>
])
dnl FIXME
m4_if([
TESTADDR(['Dan Dall'Acqua' <ddallacqua@noetic.ab.ca>, 'Dave Shyong'],[],
[1],
[0],
[],
[MU_ERR_BAD_822_FORMAT
])
])
TESTADDR([0xdeadbeef-request@petting-zoo.net],[],
[0],
[naddr: 1
......@@ -914,15 +901,13 @@ personal <Jose C. Garcia Sogo>
local-part <jose> domain <jaimedelamo.eu.org>
])
dnl FIXME
m4_if([
TESTADDR([Marco d'Itri <md@Linux.IT>,[],
TESTADDR([Marco d'Itri <md@Linux.IT>],[],
[0],
[naddr: 1
1. email <md@Linux.IT>:
personal <Marco d'Itri>
local-part <md> domain <Linux.IT>
])
])
TESTADDR([No_Reply-To@mapquest.com],[],
[0],
......@@ -1007,8 +992,6 @@ personal <ktb>
local-part <x.y.f> domain <home.com>
])
dnl FIXME
m4_if([
TESTADDR([mcaustin@eudoramail.com, aposner@usaid.gov, Kieran.O'Leary@anpost.ie],[],
[0],
[naddr: 3
......@@ -1019,7 +1002,6 @@ local-part <aposner> domain <usaid.gov>
3. email <Kieran.O'Leary@anpost.ie>:
local-part <Kieran.O'Leary> domain <anpost.ie>
])
])
TESTADDR([rfunk@wks.uts.ohio-state.eduofflinemailer-bounce@dikke.penguin.nl],[],
[1],
......@@ -1034,8 +1016,6 @@ TESTADDR([root],[],
local-part <root> domain <localhost>
])
dnl FIXME srr <sam@localhost>=> error MU_ERR_BAD_822_FORMAT
TESTADDR([whom it may concern: ;;whom.it.may.concern: ;],[],
[1],
[],
......
......@@ -19,14 +19,14 @@ dnl ------------------------------------------------------------
dnl TESTARGS([NAME], [KW = `'], [INPUT], [STDOUT = `'],
dnl [STDERR = `'], [RUN-IF-FAIL], [RUN-IF-PASS])
dnl
m4_define([TESTARGS],[
AT_SETUP([Argcv: $1])
AT_KEYWORDS([argcv $2])
AT_CHECK([
AT_DATA([input],[$3
])
argcv < input],[0],m4_shift(m4_shift(m4_shift($@))))
AT_CLEANUP
m4_pushdef([TESTARGS],[
m4_pushdef([MU_TEST_GROUP],[Argcv])
m4_pushdef([MU_TEST_KEYWORDS],[argcv])
m4_pushdef([MU_TEST_COMMAND],[argcv])
MU_GENERIC_TEST([$1],[$2],[$3],[],[$4],[$5])
m4_popdef([MU_TEST_COMMAND])
m4_popdef([MU_TEST_KEYWORDS])
m4_popdef([MU_TEST_GROUP])
])
dnl ------------------------------------------------------------
......@@ -84,6 +84,7 @@ TESTARG([unbalanced quote 3],[],
[1: "\""
])
m4_popdef([TESTARGS])
......
......@@ -19,14 +19,14 @@ dnl ------------------------------------------------------------
dnl TESTDEC2047([NAME], [KW = `'], [INPUT], [STDOUT = `'],
dnl [STDERR = `'], [RUN-IF-FAIL], [RUN-IF-PASS])
dnl
m4_define([TESTDEC2047],[
AT_SETUP([Decode 2047: m4_if([$1],[],[$3],[$1])])
AT_KEYWORDS([decode2047 decode $2])
AT_CHECK([
AT_DATA([input],[$3
])
decode2047 -p < input],[0],m4_shift(m4_shift(m4_shift($@))))
AT_CLEANUP
m4_pushdef([TESTDEC2047],[
m4_pushdef([MU_TEST_GROUP],[Decode 2047])
m4_pushdef([MU_TEST_KEYWORDS],[decode2047 decode])
m4_pushdef([MU_TEST_COMMAND],[decode2047 -p])
MU_GENERIC_TEST([$1],[$2],[$3],[],[$4],[$5])
m4_popdef([MU_TEST_COMMAND])
m4_popdef([MU_TEST_KEYWORDS])
m4_popdef([MU_TEST_GROUP])
])
dnl ------------------------------------------------------------
......@@ -56,5 +56,6 @@ TESTDEC2047([malformed input],[decode05],
[Fwd: \322\305\307\311\323\324\322\301\303\311\321 \304\317\315\305
])
m4_popdef([TESTDEC2047])
......
......@@ -19,14 +19,15 @@ dnl ------------------------------------------------------------
dnl MAILCAP([NAME], [KW = `'], [INPUT], [STDOUT = `'],
dnl [STDERR = `'], [RUN-IF-FAIL], [RUN-IF-PASS])
dnl
m4_define([MAILCAP],[
AT_SETUP([Mailcap: [$1]])
AT_KEYWORDS([mailcap $2])
AT_CHECK([
AT_DATA([input],[$3
])
mailcap input],[0],m4_shift(m4_shift(m4_shift($@))))
AT_CLEANUP
m4_pushdef([MAILCAP],[
m4_pushdef([MU_TEST_GROUP],[Mailcap])
m4_pushdef([MU_TEST_KEYWORDS],[mailcap])
m4_pushdef([MU_TEST_COMMAND],[mailcap])
MU_GENERIC_TEST([$1],[$2],[$3],[],[$4],[$5])
m4_popdef([MU_TEST_COMMAND])
m4_popdef([MU_TEST_KEYWORDS])
m4_popdef([MU_TEST_GROUP])
])
dnl ------------------------------------------------------------
......@@ -277,3 +278,5 @@ nametemplate=%s.au],
fields[2]: nametemplate=%s.au
]])
m4_popdef([MAILCAP])
......
......@@ -31,22 +31,22 @@ main (int argc, char **argv)
{
mu_stream_t stream = NULL;
int status = 0;
char *file = argc == 1 ? "/etc/mailcap" : argv[1];
mu_mailcap_t mailcap = NULL;
status = mu_file_stream_create (&stream, file, MU_STREAM_READ);
status = mu_stdio_stream_create (&stream, MU_STDIN_FD,
MU_STREAM_READ|MU_STREAM_SEEK);
if (status)
{
mu_error ("cannot create file stream %s: %s",
file, mu_strerror (status));
mu_error ("cannot create input stream: %s",
mu_strerror (status));
exit (1);
}
status = mu_stream_open (stream);
if (status)
{
mu_error ("cannot open file stream %s: %s",
file, mu_strerror (status));
mu_error ("cannot open input stream: %s",
mu_strerror (status));
exit (1);
}
......
......@@ -17,6 +17,41 @@
m4_include([testsuite.inc])
dnl ------------------------------------------------------------
m4_define([MU_TEST_GROUP],[generic])
dnl ------------------------------------------------------------
m4_define([MU_TEST_KEYWORDS])
dnl ------------------------------------------------------------
m4_define([MU_TEST_COMMAND])
m4_define([mu_trimstr],[m4_if([$2],-1,[$1],[m4_substr($1,0,$2)...])])
m4_define([mu_firstline],[mu_trimstr([$1],m4_index([$1],[
]))])
dnl ------------------------------------------------------------
dnl MU_GENERIC_TEST([NAME], [KW = `'], [INPUT],
dnl [CODE], [STDOUT = `'], [STDERR = `'],
dnl [RUN-IF-FAIL], [RUN-IF-PASS])
dnl
dnl NAME $1
dnl KW $2
dnl INPUT $3
dnl CODE $4
dnl STDOUT $5
dnl STDERR $6
dnl RUN-IF-FAIL $7
dnl RUN-IF-PASS $8
dnl
m4_define([MU_GENERIC_TEST],[
AT_SETUP([m4_if(MU_TEST_GROUP,[],,MU_TEST_GROUP: )m4_if([$1],[],mu_firstline([$3]),[$1])])
AT_KEYWORDS([MU_TEST_KEYWORDS $2])
AT_CHECK([
AT_DATA([input],[$3
])
MU_TEST_COMMAND < input],[$4],[$5],[$6],[$7],[$8])
AT_CLEANUP
])
AT_INIT
m4_include([address.at])
......
......@@ -19,14 +19,15 @@ dnl ------------------------------------------------------------
dnl TESTURL([NAME], [KW = `'], [INPUT], [STDOUT = `'],
dnl [STDERR = `'], [RUN-IF-FAIL], [RUN-IF-PASS])
dnl
m4_define([TESTURL],[
AT_SETUP([URL: m4_if([$1],[],[$3],[$1])])
AT_KEYWORDS([url $2])
AT_CHECK([
AT_DATA([input],[$3
])
url-parse < input],[0],m4_shift(m4_shift(m4_shift($@))))
AT_CLEANUP
m4_pushdef([TESTURL],[
m4_pushdef([MU_TEST_GROUP],[Url])
m4_pushdef([MU_TEST_KEYWORDS],[url])
m4_pushdef([MU_TEST_COMMAND],[url-parse])
MU_GENERIC_TEST([$1],[$2],[$3],[],[$4],[$5])
m4_popdef([MU_TEST_COMMAND])
m4_popdef([MU_TEST_KEYWORDS])
m4_popdef([MU_TEST_GROUP])
])
dnl ------------------------------------------------------------
......@@ -773,4 +774,4 @@ query[1] <arg 1>
query[2] <arg 2>
]])
m4_popdef([TESTURL])
......