Diff for /embedaddon/miniupnpc/testminiwget.sh between versions 1.1 and 1.1.1.3

version 1.1, 2012/02/21 23:16:22 version 1.1.1.3, 2023/09/27 11:21:37
Line 1 Line 1
 #!/bin/sh  #!/bin/sh
 # $Id$  # $Id$
   # vim: tabstop=4 shiftwidth=4 noexpandtab
 # project miniupnp : http://miniupnp.free.fr/  # project miniupnp : http://miniupnp.free.fr/
(c) 2011 Thomas Bernard#                    or https://miniupnp.tuxfamily.org/
 # (c) 2011-2022 Thomas Bernard
 #  #
 # test program for miniwget.c  # test program for miniwget.c
 # is usually invoked by "make check"  # is usually invoked by "make check"
 #  #
 # This test program :  # This test program :
 #  1 - launches a local HTTP server (minihttptestserver)  #  1 - launches a local HTTP server (minihttptestserver)
#  2 - uses testminiwget to retreive data from this server#  2 - uses testminiwget to retrieve data from this server
 #  3 - compares served and received data  #  3 - compares served and received data
 #  4 - kills the local HTTP server and exits  #  4 - kills the local HTTP server and exits
 #  #
   # The script was tested and works with ksh, bash
   # it should now also run with dash
   
HTTPSERVEROUT=/tmp/httpserveroutTMPD=`mktemp -d -t miniwgetXXXXXXXXXX`
EXPECTEDFILE=/tmp/expectedfileif [ -z "$TESTSERVER" ] ; then
DOWNLOADEDFILE=/tmp/downloadedfile  TESTSERVER=./build/minihttptestserver
#ADDR=localhostfi
ADDR="[::1]"if [ -z "$TESTMINIWGET" ] ; then
   TESTMINIWGET=./build/testminiwget
 fi
 HTTPSERVEROUT="${TMPD}/httpserverout"
 EXPECTEDFILE="${TMPD}/expectedfile"
 DOWNLOADEDFILE="${TMPD}/downloadedfile"
 PORT=  PORT=
 RET=0  RET=0
   IPCONFIG=$(which ifconfig)
   IP=$(which ip)
   if [ "$IP" ] ; then
       if ! $IP addr | grep inet6 ; then
           HAVE_IPV6=no
       fi
   else
       if [ -z "$IPCONFIG" ] ; then
           IPCONFIG="/sbin/ifconfig"
       fi
   
#make minihttptestserver        if ! $IPCONFIG -a | grep inet6 ; then
#make testminiwget                HAVE_IPV6=no
         fi
 fi
   
   case "$HAVE_IPV6" in
       n|no|0)
           ADDR=localhost
           SERVERARGS=""
           ;;
       *)
           ADDR="[::1]"
           SERVERARGS="-6"
           ;;
   
   esac
   
   if [ ! -x "$TESTSERVER" ] || [ ! -x "$TESTMINIWGET" ] ; then
       echo "Please build $TESTSERVER and $TESTMINIWGET"
       #make minihttptestserver
       #make testminiwget
       exit 1
   fi
   
 # launching the test HTTP server  # launching the test HTTP server
./minihttptestserver -6 -e $EXPECTEDFILE > $HTTPSERVEROUT &$TESTSERVER $SERVERARGS -e $EXPECTEDFILE > $HTTPSERVEROUT &
while [ "$PORT" == "" ]; doSERVERPID=$!
 while [ -z "$PORT" ]; do
         sleep 1
     PORT=`cat $HTTPSERVEROUT | sed 's/Listening on port \([0-9]*\)/\1/' `      PORT=`cat $HTTPSERVEROUT | sed 's/Listening on port \([0-9]*\)/\1/' `
 done  done
   if [ "$PORT" = "*** ERROR ***" ]; then
       echo "HTTP test server error"
       echo "Network config :"
       $IPCONFIG -a
       exit 2
   fi
 echo "Test HTTP server is listening on $PORT"  echo "Test HTTP server is listening on $PORT"
   
 URL1="http://$ADDR:$PORT/index.html"  URL1="http://$ADDR:$PORT/index.html"
 URL2="http://$ADDR:$PORT/chunked"  URL2="http://$ADDR:$PORT/chunked"
 URL3="http://$ADDR:$PORT/addcrap"  URL3="http://$ADDR:$PORT/addcrap"
   URL4="http://$ADDR:$PORT/malformed"
   
 echo "standard test ..."  echo "standard test ..."
./testminiwget $URL1 "${DOWNLOADEDFILE}.1"$TESTMINIWGET $URL1 "${DOWNLOADEDFILE}.1"
 if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.1" ; then  if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.1" ; then
     echo "ok"      echo "ok"
 else  else
Line 45  else Line 94  else
 fi  fi
   
 echo "chunked transfert encoding test ..."  echo "chunked transfert encoding test ..."
./testminiwget $URL2 "${DOWNLOADEDFILE}.2"$TESTMINIWGET $URL2 "${DOWNLOADEDFILE}.2"
 if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.2" ; then  if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.2" ; then
     echo "ok"      echo "ok"
 else  else
Line 54  else Line 103  else
 fi  fi
   
 echo "response too long test ..."  echo "response too long test ..."
./testminiwget $URL3 "${DOWNLOADEDFILE}.3"$TESTMINIWGET $URL3 "${DOWNLOADEDFILE}.3"
 if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.3" ; then  if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.3" ; then
     echo "ok"      echo "ok"
 else  else
Line 62  else Line 111  else
     RET=1      RET=1
 fi  fi
   
   echo "malformed response test ..."
   $TESTMINIWGET $URL4 "${DOWNLOADEDFILE}.4"
   
 # kill the test HTTP server  # kill the test HTTP server
kill %1kill $SERVERPID
wait %1wait $SERVERPID
   
 # remove temporary files (for success cases)  # remove temporary files (for success cases)
 if [ $RET -eq 0 ]; then  if [ $RET -eq 0 ]; then
Line 72  if [ $RET -eq 0 ]; then Line 124  if [ $RET -eq 0 ]; then
     rm -f "${DOWNLOADEDFILE}.2"      rm -f "${DOWNLOADEDFILE}.2"
     rm -f "${DOWNLOADEDFILE}.3"      rm -f "${DOWNLOADEDFILE}.3"
     rm -f $EXPECTEDFILE $HTTPSERVEROUT      rm -f $EXPECTEDFILE $HTTPSERVEROUT
       rmdir ${TMPD}
 else  else
     echo "at least one of the test FAILED"      echo "at least one of the test FAILED"
       echo "directory ${TMPD} is left intact"
 fi  fi
 exit $RET  exit $RET
   

Removed from v.1.1  
changed lines
  Added in v.1.1.1.3


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