2011-09-27 20:25:35 +00:00
|
|
|
#!/bin/sh
|
2018-01-16 01:06:46 +00:00
|
|
|
# $Id: testminiwget.sh,v 1.15 2017/11/02 17:36:26 nanard Exp $
|
|
|
|
# vim: tabstop=4 shiftwidth=4 noexpandtab
|
2011-09-27 20:25:35 +00:00
|
|
|
# project miniupnp : http://miniupnp.free.fr/
|
2018-01-16 01:06:46 +00:00
|
|
|
# (c) 2011-2018 Thomas Bernard
|
2011-09-27 20:25:35 +00:00
|
|
|
#
|
|
|
|
# test program for miniwget.c
|
|
|
|
# is usually invoked by "make check"
|
|
|
|
#
|
|
|
|
# This test program :
|
|
|
|
# 1 - launches a local HTTP server (minihttptestserver)
|
2018-01-09 01:32:39 +00:00
|
|
|
# 2 - uses testminiwget to retrieve data from this server
|
2011-09-27 20:25:35 +00:00
|
|
|
# 3 - compares served and received data
|
|
|
|
# 4 - kills the local HTTP server and exits
|
|
|
|
#
|
2012-06-20 21:11:36 +00:00
|
|
|
# The script was tested and works with ksh, bash
|
2013-12-09 08:30:18 +00:00
|
|
|
# it should now also run with dash
|
2011-09-27 20:25:35 +00:00
|
|
|
|
2015-09-04 15:47:11 +00:00
|
|
|
TMPD=`mktemp -d -t miniwgetXXXXXXXXXX`
|
2013-04-27 15:50:02 +00:00
|
|
|
HTTPSERVEROUT="${TMPD}/httpserverout"
|
|
|
|
EXPECTEDFILE="${TMPD}/expectedfile"
|
|
|
|
DOWNLOADEDFILE="${TMPD}/downloadedfile"
|
2011-09-27 20:25:35 +00:00
|
|
|
PORT=
|
|
|
|
RET=0
|
2017-11-02 17:11:29 +00:00
|
|
|
IPCONFIG=$(which ifconfig)
|
|
|
|
if [ -z "$IPCONFIG" ] ; then
|
|
|
|
IPCONFIG="/sbin/ifconfig"
|
|
|
|
fi
|
2011-09-27 20:25:35 +00:00
|
|
|
|
2017-11-02 17:24:08 +00:00
|
|
|
if ! $IPCONFIG -a | grep inet6 ; then
|
|
|
|
HAVE_IPV6=no
|
|
|
|
fi
|
|
|
|
|
2012-10-16 04:59:05 +00:00
|
|
|
case "$HAVE_IPV6" in
|
|
|
|
n|no|0)
|
|
|
|
ADDR=localhost
|
|
|
|
SERVERARGS=""
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
ADDR="[::1]"
|
|
|
|
SERVERARGS="-6"
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
|
2011-09-27 20:25:35 +00:00
|
|
|
#make minihttptestserver
|
|
|
|
#make testminiwget
|
|
|
|
|
|
|
|
# launching the test HTTP server
|
2012-10-16 04:59:05 +00:00
|
|
|
./minihttptestserver $SERVERARGS -e $EXPECTEDFILE > $HTTPSERVEROUT &
|
2013-02-11 09:59:36 +00:00
|
|
|
SERVERPID=$!
|
2012-06-20 21:11:36 +00:00
|
|
|
while [ -z "$PORT" ]; do
|
|
|
|
sleep 1
|
2011-09-27 20:25:35 +00:00
|
|
|
PORT=`cat $HTTPSERVEROUT | sed 's/Listening on port \([0-9]*\)/\1/' `
|
|
|
|
done
|
2017-11-02 16:53:33 +00:00
|
|
|
if [ "$PORT" = "*** ERROR ***" ]; then
|
|
|
|
echo "HTTP test server error"
|
2017-11-02 17:11:29 +00:00
|
|
|
echo "Network config :"
|
|
|
|
$IPCONFIG -a
|
2017-11-02 16:53:33 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
2011-09-27 20:25:35 +00:00
|
|
|
echo "Test HTTP server is listening on $PORT"
|
|
|
|
|
|
|
|
URL1="http://$ADDR:$PORT/index.html"
|
|
|
|
URL2="http://$ADDR:$PORT/chunked"
|
|
|
|
URL3="http://$ADDR:$PORT/addcrap"
|
|
|
|
|
|
|
|
echo "standard test ..."
|
|
|
|
./testminiwget $URL1 "${DOWNLOADEDFILE}.1"
|
|
|
|
if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.1" ; then
|
|
|
|
echo "ok"
|
|
|
|
else
|
|
|
|
echo "standard test FAILED"
|
|
|
|
RET=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "chunked transfert encoding test ..."
|
|
|
|
./testminiwget $URL2 "${DOWNLOADEDFILE}.2"
|
|
|
|
if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.2" ; then
|
|
|
|
echo "ok"
|
|
|
|
else
|
|
|
|
echo "chunked transfert encoding test FAILED"
|
|
|
|
RET=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "response too long test ..."
|
|
|
|
./testminiwget $URL3 "${DOWNLOADEDFILE}.3"
|
|
|
|
if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.3" ; then
|
|
|
|
echo "ok"
|
|
|
|
else
|
|
|
|
echo "response too long test FAILED"
|
|
|
|
RET=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# kill the test HTTP server
|
2013-02-11 09:59:36 +00:00
|
|
|
kill $SERVERPID
|
|
|
|
wait $SERVERPID
|
2011-09-27 20:25:35 +00:00
|
|
|
|
|
|
|
# remove temporary files (for success cases)
|
|
|
|
if [ $RET -eq 0 ]; then
|
|
|
|
rm -f "${DOWNLOADEDFILE}.1"
|
|
|
|
rm -f "${DOWNLOADEDFILE}.2"
|
|
|
|
rm -f "${DOWNLOADEDFILE}.3"
|
|
|
|
rm -f $EXPECTEDFILE $HTTPSERVEROUT
|
2013-04-27 15:50:02 +00:00
|
|
|
rmdir ${TMPD}
|
2011-09-27 20:25:35 +00:00
|
|
|
else
|
|
|
|
echo "at least one of the test FAILED"
|
2013-04-27 15:50:02 +00:00
|
|
|
echo "directory ${TMPD} is left intact"
|
2011-09-27 20:25:35 +00:00
|
|
|
fi
|
|
|
|
exit $RET
|
|
|
|
|