File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / miniupnpc / testminiwget.sh
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Mon Jul 22 00:36:10 2013 UTC (10 years, 11 months ago) by misho
Branches: miniupnpc, elwix, MAIN
CVS tags: v1_8p0, v1_8, HEAD
1.8

    1: #!/bin/sh
    2: # $Id: testminiwget.sh,v 1.1.1.2 2013/07/22 00:36:10 misho Exp $
    3: # project miniupnp : http://miniupnp.free.fr/
    4: # (c) 2011-2012 Thomas Bernard
    5: #
    6: # test program for miniwget.c
    7: # is usually invoked by "make check"
    8: #
    9: # This test program :
   10: #  1 - launches a local HTTP server (minihttptestserver)
   11: #  2 - uses testminiwget to retreive data from this server
   12: #  3 - compares served and received data
   13: #  4 - kills the local HTTP server and exits
   14: #
   15: # The script was tested and works with ksh, bash
   16: # It fails to run with dash 0.5.5.1 because of "kill %1"
   17: 
   18: TMPDIR=`mktemp -d`
   19: HTTPSERVEROUT="${TMPDIR}/httpserverout"
   20: EXPECTEDFILE="${TMPDIR}/expectedfile"
   21: DOWNLOADEDFILE="${TMPDIR}/downloadedfile"
   22: PORT=
   23: RET=0
   24: 
   25: case "$HAVE_IPV6" in
   26:     n|no|0)
   27:         ADDR=localhost
   28:         SERVERARGS=""
   29:         ;;
   30:     *)
   31:         ADDR="[::1]"
   32:         SERVERARGS="-6"
   33:         ;;
   34: 
   35: esac
   36: 
   37: #make minihttptestserver
   38: #make testminiwget
   39: 
   40: # launching the test HTTP server
   41: ./minihttptestserver $SERVERARGS -e $EXPECTEDFILE > $HTTPSERVEROUT &
   42: while [ -z "$PORT" ]; do
   43: 	sleep 1
   44: 	PORT=`cat $HTTPSERVEROUT | sed 's/Listening on port \([0-9]*\)/\1/' `
   45: done
   46: echo "Test HTTP server is listening on $PORT"
   47: 
   48: URL1="http://$ADDR:$PORT/index.html"
   49: URL2="http://$ADDR:$PORT/chunked"
   50: URL3="http://$ADDR:$PORT/addcrap"
   51: 
   52: echo "standard test ..."
   53: ./testminiwget $URL1 "${DOWNLOADEDFILE}.1"
   54: if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.1" ; then
   55: 	echo "ok"
   56: else
   57: 	echo "standard test FAILED"
   58: 	RET=1
   59: fi
   60: 
   61: echo "chunked transfert encoding test ..."
   62: ./testminiwget $URL2 "${DOWNLOADEDFILE}.2"
   63: if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.2" ; then
   64: 	echo "ok"
   65: else
   66: 	echo "chunked transfert encoding test FAILED"
   67: 	RET=1
   68: fi
   69: 
   70: echo "response too long test ..."
   71: ./testminiwget $URL3 "${DOWNLOADEDFILE}.3"
   72: if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.3" ; then
   73: 	echo "ok"
   74: else
   75: 	echo "response too long test FAILED"
   76: 	RET=1
   77: fi
   78: 
   79: # kill the test HTTP server
   80: kill %1
   81: wait %1
   82: 
   83: # remove temporary files (for success cases)
   84: if [ $RET -eq 0 ]; then
   85: 	rm -f "${DOWNLOADEDFILE}.1"
   86: 	rm -f "${DOWNLOADEDFILE}.2"
   87: 	rm -f "${DOWNLOADEDFILE}.3"
   88: 	rm -f $EXPECTEDFILE $HTTPSERVEROUT
   89: 	rmdir ${TMPDIR}
   90: else
   91: 	echo "at least one of the test FAILED"
   92: 	echo "directory ${TMPDIR} is left intact"
   93: fi
   94: exit $RET
   95: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>