Commit ec989a56 ec989a562f5a64f36909dc0a151fc24b50a733be by Sergey Poznyakoff

libmailutils/tests: test list and iterator operations.

* examples/listop.c: Move to libmailutils/tests.
* examples/Makefile.am (noinst_PROGRAMS): Remove listop.
* libmailutils/tests/Makefile.am (noinst_PROGRAMS): Add listop.
(TESTSUITE_AT): Add list.at.
* libmailutils/tests/.gitignore: New file.
* libmailutils/tests/list.at: New file.
* libmailutils/tests/testsuite.at: Include list.at.

* libmailutils/list.c (list_itrctl): Fix mu_itrctl_replace.
1 parent 5aa2c0a3
......@@ -40,7 +40,6 @@ noinst_PROGRAMS = \
header\
http\
iconv\
listop\
lsf\
msg-send\
mta\
......
......@@ -599,6 +599,7 @@ list_itrctl (void *owner, enum mu_itrctl_req req, void *arg)
/* Replace current element */
if (!arg)
return EINVAL;
ptr = itr->cur;
if (req == mu_itrctl_replace)
DESTROY_ITEM (list, ptr);
ptr = itr->cur;
......
atconfig
atlocal
package.m4
testsuite
testsuite.dir
testsuite.log
addr
argcv
decode2047
encode2047
fltst
listop
mailcap
mimetest
url-parse
......@@ -45,6 +45,7 @@ noinst_PROGRAMS = \
decode2047\
encode2047\
fltst\
listop\
mailcap\
mimetest\
url-parse
......@@ -71,6 +72,7 @@ TESTSUITE_AT = \
base64e.at\
decode2047.at\
encode2047.at\
list.at\
mailcap.at\
mime.at\
testsuite.at\
......
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2007, 2008, 2009, 2010 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.
#
# This program 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/>.
# This file is part of Mailfromd testsuite.
dnl ------------------------------------------------------------
dnl TESTLIST([NAME], [KW = `'], [INPUT], [STDOUT = `'],
dnl [STDERR = `'], [RUN-IF-FAIL], [RUN-IF-PASS])
dnl
m4_pushdef([TESTLIST],[
m4_pushdef([MU_TEST_KEYWORDS],[list])
m4_pushdef([MU_TEST_COMMAND],[listop])
MU_GENERIC_TEST([$1],[$2],[$3],[],[$4],[$5])
m4_popdef([MU_TEST_COMMAND])
m4_popdef([MU_TEST_KEYWORDS])
])
# ------------------------------------------------------------
# Lists
# ------------------------------------------------------------
m4_pushdef([MU_TEST_GROUP],[List])
TESTLIST([build],[],
[add en to tre fire fem
print],
[# items: 5
en
to
tre
fire
fem
])
TESTLIST([insert after],[],
[add en tre fire fem
ins after en to
print],
[# items: 5
en
to
tre
fire
fem
])
TESTLIST([insert before],[],
[add en tre fire fem
ins before tre to
print],
[# items: 5
en
to
tre
fire
fem
])
TESTLIST([prepend],[],
[add en to tre fire fem
prep null jeden dwa trzy
print],
[# items: 9
trzy
dwa
jeden
null
en
to
tre
fire
fem
])
TESTLIST([delete],[],
[add en to tre fire fem
del to fire
print],
[# items: 3
en
tre
fem
])
TESTLIST([get],[],
[add en to tre fire fem
3],
[fire
])
# ------------------------------------------------------------
# Iterators
# ------------------------------------------------------------
m4_define([MU_TEST_GROUP],[Iterator])
m4_define([MU_TEST_KEYWORDS],MU_TEST_KEYWORDS[ iterator itr])
TESTLIST([forward],[],
[add en to tre fire fem
first
cur
next 3
cur],
[0:0:en
0:3:fire
])
TESTLIST([locate],[],
[add en to tre fire fem
find tre
cur],
[0:2:tre
])
TESTLIST([backward],[],
[add en to tre fire fem
ictl dir backwards
find fem
cur
next
cur
next 2
cur
],
[0:4:fem
0:3:fire
0:1:to
])
TESTLIST([delete],[],
[add en to tre fire fem
find tre
cur
ictl del
cur
print
],
[0:2:tre
0:2:fire
# items: 4
en
to
fire
fem
])
TESTLIST([insert],[],
[add en to fire
find to
cur
ictl ins tre
cur
next
cur
next
cur
print
],
[0:1:to
0:1:to
0:2:tre
0:3:fire
# items: 4
en
to
tre
fire
])
TESTLIST([replace],[],
[add en to tre fire fem
find tre
cur
ictl repl trzy
cur
print
],
[0:2:tre
0:2:trzy
# items: 5
en
to
trzy
fire
fem
])
TESTLIST([interaction],[],
[add en to tre fire fem
first
iter 1
find tre
cur
iter 0
cur
],
[1:2:tre
0:0:en
])
TESTLIST([interaction: moves],[],
[add en to tre fire fem
first
iter 1
find tre
iter 0
next
iter 1
next
iter 0
cur
iter 1
cur
],
[0:1:to
1:3:fire
])
TESTLIST([interaction: deletes],[],
[add en to tre fire fem
find tre
iter 1
find tre
ictl del
cur
iter 0
cur
],
[1:2:fire
0:2:fire
])
dnl ------------------------------------------------------------
dnl Cleanup
m4_popdef([TESTLIST])
m4_popdef([MU_TEST_GROUP])
......@@ -26,12 +26,7 @@
#include <mailutils/argcv.h>
#include <mailutils/mailutils.h>
void
usage(int code)
{
printf ("usage: listop [item..]\n");
exit (code);
}
static int interactive;
void
lperror (char *text, int rc)
......@@ -413,9 +408,34 @@ find (mu_iterator_t itr, char *arg)
}
void
cur (int num, mu_iterator_t itr)
{
char *text;
size_t pos;
int rc;
printf ("%lu:", (unsigned long) num);
rc = mu_iterator_ctl (itr, mu_itrctl_tell, &pos);
if (rc == MU_ERR_NOENT)
{
printf ("iterator not initialized\n");
return;
}
if (rc)
lperror ("mu_iterator_ctl", rc);
printf ("%lu:", (unsigned long) pos);
rc = mu_iterator_current (itr, (void**) &text);
if (rc)
lperror ("mu_iterator_current", rc);
printf ("%s\n", text);
}
void
help ()
{
printf ("count\n");
printf ("cur\n");
printf ("next [count]\n");
printf ("first\n");
printf ("find item\n");
......@@ -447,7 +467,7 @@ shell (mu_list_t list)
num = 0;
while (1)
{
char *text;
char *text = NULL;
char buf[80];
int argc;
char **argv;
......@@ -464,7 +484,8 @@ shell (mu_list_t list)
if (rc)
lperror ("mu_iterator_current", rc);
printf ("%d:(%s)> ", num, text ? text : "NULL");
if (interactive)
printf ("%d:(%s)> ", num, text ? text : "NULL");
if (fgets (buf, sizeof buf, stdin) == NULL)
return;
......@@ -494,6 +515,8 @@ shell (mu_list_t list)
ictl (itr[num], argc, argv);
else if (strcmp (argv[0], "print") == 0)
print (list);
else if (strcmp (argv[0], "cur") == 0)
cur (num, itr[num]);
else if (strcmp (argv[0], "quit") == 0)
return;
else if (strcmp (argv[0], "iter") == 0)
......@@ -555,25 +578,16 @@ main (int argc, char **argv)
{
mu_list_t list;
int rc;
while ((rc = getopt (argc, argv, "h")) != EOF)
switch (rc)
{
case 'h':
usage (0);
default:
usage (1);
}
argc -= optind;
argv += optind;
interactive = isatty (0);
rc = mu_list_create (&list);
if (rc)
lperror ("mu_list_create", rc);
mu_list_set_comparator (list, string_comp);
mu_list_set_destroy_item (list, mu_list_free_item);
argc--;
argv++;
while (argc--)
{
......
......@@ -54,6 +54,7 @@ AT_CLEANUP
AT_INIT
m4_include([list.at])
m4_include([address.at])
m4_include([argcv.at])
m4_include([mime.at])
......