WFDB Software Package 10.6.2

File: <base>/checkpkg/libcheck (3,405 bytes)
#!/bin/sh
# file: libcheck		G. Moody       8 September 2001
#                               Last revised:    8 March 2019
#
# This script checks the functionality of the WFDB library by comparing the
# outputs of 'lcheck' with expected outputs.  See 'lcheck.c' for details of
# the tests performed, or examine the output of 'lcheck -v'.  Note that
# 'lcheck' must be run within this directory to ensure that its local input
# files (in ../data) are available.
#
# 'make check' invokes this script with DBDIR as a command-line argument;
# this is used to edit the expected lcheck.log to reflect the installation
# directory.
#
# Suggestions for additional checks are welcome;  please send them to the
# author (wfdb@physionet.org).

cp -pr ../data .

if [ \! -s ../data/100s.hea ]
then
  echo "Run this program from the 'checkpkg' directory of the WFDB sources."
  echo "The 'data' directory, including record 100s, must also be present."
  exit
fi

case $# in
  0) VERBOSE=0 ;;
  *) VERBOSE=1 ;;
esac

DBDIR=$1
LIBDIR=$2
DBURL=http://physionet.org/physiobank/database

# If not using DESTDIR, test the built-in path used by the WFDB library.
# If using DESTDIR or WFDB_NO_NET_CHECK, set the WFDB path explicitly.
if [ "x$DESTDIR" = x ] && [ "x$WFDB_NO_NET_CHECK" = x ]
then
    unset WFDB
else
    if [ "x$WFDB_NO_NET_CHECK" != x ]
    then
        mkdir data/www
        mkdir data/www/udb
        cp -p data/100s.* data/www/udb/
        DBURL=file://`pwd`/data/www
    fi
    WFDB=". $DBDIR $DBURL"
    export WFDB
fi

## Darwin
if [ "x$DYLD_LIBRARY_PATH" != x ]
then
    DYLD_LIBRARY_PATH=$LIBDIR:$DYLD_LIBRARY_PATH
else
    DYLD_LIBRARY_PATH=$LIBDIR
fi
export DYLD_LIBRARY_PATH

## Windows (Cygwin/MinGW) and Wine
PATH=.:$LIBDIR/../bin:$PATH
export PATH
WINEPATH=$LIBDIR/../bin\;$WINEPATH
export WINEPATH

## Other *nix
if [ "x$LD_LIBRARY_PATH" != x ]
then
    LD_LIBRARY_PATH=$LIBDIR:$LD_LIBRARY_PATH
else
    LD_LIBRARY_PATH=$LIBDIR
fi
export LD_LIBRARY_PATH

test -s Makefile || ( cd ..; ./configure )
test -s lcheck || make lcheck
./lcheck -v >lcheck.log
cp ../data/100s.atr expected/100s.chk
cp ../data/100s.dat expected/100z.dat
CF="lcheck.log lcheck_cal 100s.chk 100z.dat 100z.hea"
if grep "WFDB supports NETFILES" lcheck.log >/dev/null 2>&1
then
  CF="$CF udb/100s.chk udb/100z.dat udb/100z.hea"
  cp ../data/100s.atr expected/udb/100s.chk
  cp ../data/100s.dat expected/udb/100z.dat
  sed "s|/usr/database|$DBDIR|" <expected/lcheck.log-NETFILES | \
    sed "s|http://physionet.org/physiobank/database|$DBURL|" \
      >expected/lcheck.log
else
  sed "s|/usr/database|$DBDIR|" <expected/lcheck.log-no-NETFILES | \
    sed "s|http://physionet.org/physiobank/database|$DBURL|" \
      >expected/lcheck.log
fi

PASS=0
FAIL=0
TESTS=0

for i in $CF
do
    if ( ./checkfile $i )
    then
	PASS=`expr $PASS + 1`
	case $i in
	    *.hea) rm -f $i ;;
	    lcheck_cal) rm -f $i ;;
	    *)     rm -f $i expected/$i ;;
	esac
    else
	FAIL=`expr $FAIL + 1`
    fi
    TESTS=`expr $TESTS + 1`
done

rm -rf data

if [ $PASS = $TESTS ]
then
    echo "`basename $0`: all $TESTS tests passed."
else
    if [ $FAIL = 1 ]
    then
	echo "`basename $0`: $PASS of $TESTS tests passed, $FAIL test failed."
    else
	echo "`basename $0`: $PASS of $TESTS tests passed, $FAIL tests failed."
    fi
fi

# rmdir will fail if 'udb' is not empty.  This is a *feature*, not a bug --
# don't fix it!
test -d udb && rmdir udb