From: Ken Hornstein Date: Wed, 15 Feb 2012 20:54:47 +0000 (-0500) Subject: Create test cases for the new format functions for local address writing. X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=23af631076209b31fb28feb90a779ff8dcc153a2;p=mmh Create test cases for the new format functions for local address writing. --- diff --git a/.gitignore b/.gitignore index b65e540..87e31cb 100644 --- a/.gitignore +++ b/.gitignore @@ -96,6 +96,7 @@ a.out.DSYM/ /uip/whatnow /uip/whom /uip/*.exe +/test/getfullname # Removed by mostlyclean: *.o diff --git a/Makefile.am b/Makefile.am index 84bf58f..5b473c3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -42,7 +42,10 @@ TESTS_ENVIRONMENT = MH_TEST_DIR=`pwd`/test/testdir \ ## Important note: the "cleanup" test should always be last ## TESTS = test/bad-input/test-header test/folder/test-create \ - test/folder/test-total test/inc/test-deb359167 test/inc/test-eom-align \ + test/folder/test-total test/format/test-localmbox \ + test/format/test-myname test/format/test-myhost \ + test/format/test-mymbox \ + test/inc/test-deb359167 test/inc/test-eom-align \ test/manpages/test-manpages test/mhbuild/test-forw \ test/mhshow/test-cte-binary test/mhshow/test-qp \ test/mhshow/test-subpart test/new/test-basic test/pick/test-stderr \ @@ -51,6 +54,7 @@ TESTS = test/bad-input/test-header test/folder/test-create \ test/whatnow/test-ls test/cleanup check_SCRIPTS = test/common.sh +check_PROGRAMS = test/getfullname ## ## Stuff that should be cleaned via "make clean" @@ -341,6 +345,9 @@ uip_spost_SOURCES = uip/spost.c uip/aliasbr.c uip_viamail_SOURCES = uip/viamail.c uip/mhmisc.c uip/mhoutsbr.c uip/sendsbr.c \ uip/annosbr.c uip/distsbr.c +test_getfullname_SOURCES = test/getfullname.c +test_getfullname_LDADD = + ## ## Our rebuild rules for files that aren't built via the normal mechanisms ## diff --git a/test/common.sh.in b/test/common.sh.in index 34767f4..d5a9d7e 100644 --- a/test/common.sh.in +++ b/test/common.sh.in @@ -64,6 +64,7 @@ setup_test () export MH_INST_DIR=${MH_TEST_DIR}/inst export MHMTSCONF=${MH_INST_DIR}${sysconfdir}/mts.conf export PATH=${MH_INST_DIR}${bindir}:${PATH} + export MH_LIB_DIR=${MH_INST_DIR}${auxexecdir} if [ -z "${srcdir}" ]; then echo "srcdir not set; aborting" @@ -84,7 +85,7 @@ setup_test () mkdir $MH_TEST_DIR/Mail || exit 1 cat > $MH <> ${MH} + +# We can use "ap" to get the output of format commands + +testoutput=$(${MH_LIB_DIR}/ap -format "%(profile Local-Mailbox)" ignore) + +if [ x"${testname}" != x"${testoutput}" ]; then + echo "Expected ${testname}, got ${testoutput}" + exit 1 +fi + +exit 0 diff --git a/test/format/test-myhost b/test/format/test-myhost new file mode 100755 index 0000000..d303a8f --- /dev/null +++ b/test/format/test-myhost @@ -0,0 +1,34 @@ +#!/bin/sh +# +# Test that the %(myhost) function returns the local hostname and +# the localname entry out of the mts configuration file. +# + +if [ -z "${MH_TEST_COMMON}" ]; then + echo "MH_TEST_COMMON not set; try running via 'make check'" +fi + +. ${MH_TEST_COMMON} + +setup_test + +runtest() +{ + testoutput=$(${MH_LIB_DIR}/ap -format "%(myhost)" ignore) + + if [ x"$1" != x"${testoutput}" ]; then + echo "For $2, expected $1 but got ${testoutput}" + exit 1 + fi +} + +runtest "$(hostname)" "local hostname test" + +cp ${MHMTSCONF} ${MH_TEST_DIR}/Mail/mts.conf || exit 1 +export MHMTSCONF="${MH_TEST_DIR}/Mail/mts.conf" + +echo "localname: some.random.name" >> ${MHMTSCONF} + +runtest "some.random.name" "mts.conf localname test" + +exit 0 diff --git a/test/format/test-mymbox b/test/format/test-mymbox new file mode 100755 index 0000000..82f0879 --- /dev/null +++ b/test/format/test-mymbox @@ -0,0 +1,44 @@ +#!/bin/sh +# +# Test that the %(mymbox) function correctly determines whether or not +# a particular email address is "mine" or not +# + +if [ -z "${MH_TEST_COMMON}" ]; then + echo "MH_TEST_COMMON not set; try running via 'make check'" +fi + +. ${MH_TEST_COMMON} + +setup_test + +runtest() +{ + testoutput=$(${MH_LIB_DIR}/ap -format "%(mymbox{text})" "$1") + + if [ -z "${testoutput}" ]; then + echo "Test program did not return anything for $3" + exit 1 + fi + + if [ "${testoutput}" -ne $2 ]; then + echo "Did not get expected output for $3" + exit 1 + fi +} + +user="$(id -un)" +host="$(hostname)" + +runtest "${user}" 1 "Basic user test" +runtest "${user}@${host}" 1 "Basic user@host test" +runtest "nosuchuser@nosuchhost.blah" 0 "Basic non-matching test" + +myname="Random User " + +echo "Local-Mailbox: ${myname}" >> ${MH} + +runtest "${myname}" 1 "Local-Mailbox test" +runtest "${user}@${host}" 0 "Local-mailbox overriding user@host test" + +exit 0 diff --git a/test/format/test-myname b/test/format/test-myname new file mode 100755 index 0000000..4e1dfaa --- /dev/null +++ b/test/format/test-myname @@ -0,0 +1,37 @@ +#!/bin/sh +# +# Test that we can retrieve the local username via the passwd file, +# the Signature profile entry, and via SIGNATURE environment variable. +# + +if [ -z "${MH_TEST_COMMON}" ]; then + echo "MH_TEST_COMMON not set; try running via 'make check'" +fi + +. ${MH_TEST_COMMON} + +setup_test + +unset SIGNATURE + +runtest() +{ + testoutput=$(${MH_LIB_DIR}/ap -format "%(myname)" ignore) + + if [ x"$1" != x"${testoutput}" ]; then + echo "For $2, expected $1 but got ${testoutput}" + exit 1 + fi +} + +runtest "$(${MH_OBJ_DIR}/test/getfullname)" "GECOS field test" + +echo "Signature: Some Random Name 1" >> ${MH} + +runtest "Some Random Name 1" "MH Profile Signature test" + +export SIGNATURE="Some Random Name 2" + +runtest "${SIGNATURE}" "SIGNATURE Environment test" + +exit 0 diff --git a/test/getfullname.c b/test/getfullname.c new file mode 100644 index 0000000..3afa00f --- /dev/null +++ b/test/getfullname.c @@ -0,0 +1,32 @@ +/* + * getfullname.c - Extract a user's name out of the GECOS field in + * the password file. + * + * This code is Copyright (c) 2012, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. + */ + +#include +#include +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + struct passwd *pwd; + + pwd = getpwuid(getuid()); + + if (! pwd) { + fprintf(stderr, "Unable to retrieve user info for " + "userid %d\n", getuid()); + exit(1); + } + + printf("%s\n", pwd->pw_gecos); + + exit(0); +}