Annotation of embedaddon/miniupnpc/testminiwget.sh, revision 1.1.1.2

1.1       misho       1: #!/bin/sh
1.1.1.2 ! misho       2: # $Id: testminiwget.sh,v 1.7 2012/10/16 16:49:40 nanard Exp $
1.1       misho       3: # project miniupnp : http://miniupnp.free.fr/
1.1.1.2 ! misho       4: # (c) 2011-2012 Thomas Bernard
1.1       misho       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: #
1.1.1.2 ! misho      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"
1.1       misho      17: 
1.1.1.2 ! misho      18: TMPDIR=`mktemp -d`
        !            19: HTTPSERVEROUT="${TMPDIR}/httpserverout"
        !            20: EXPECTEDFILE="${TMPDIR}/expectedfile"
        !            21: DOWNLOADEDFILE="${TMPDIR}/downloadedfile"
1.1       misho      22: PORT=
                     23: RET=0
                     24: 
1.1.1.2 ! misho      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: 
1.1       misho      37: #make minihttptestserver
                     38: #make testminiwget
                     39: 
                     40: # launching the test HTTP server
1.1.1.2 ! misho      41: ./minihttptestserver $SERVERARGS -e $EXPECTEDFILE > $HTTPSERVEROUT &
        !            42: while [ -z "$PORT" ]; do
        !            43:        sleep 1
1.1       misho      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
1.1.1.2 ! misho      89:        rmdir ${TMPDIR}
1.1       misho      90: else
                     91:        echo "at least one of the test FAILED"
1.1.1.2 ! misho      92:        echo "directory ${TMPDIR} is left intact"
1.1       misho      93: fi
                     94: exit $RET
                     95: 

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