33b680f2eb079d403d0280d83e196240b899088c
[gedcom-parse.git] / t / src / test_gom
1 #!/bin/sh
2 # $Id$
3 # $Name$
4
5 options="-q"
6 extra_options=
7
8 while [ $# -gt 0 ]
9 do
10   case "$1" in
11     -*) extra_options="$extra_options $1";;
12     *)  break;;
13   esac
14   shift
15 done
16
17 file=$1
18 test_name=$2
19 expected_result=$3
20 if [ -z "$test_name" ]
21 then
22   test_name=check
23 fi
24 if [ -z "$expected_result" ]
25 then
26   expected_result=0
27 fi
28
29 # For use outside Makefile
30 if [ -z "$srcdir" ]
31 then
32   testfile=$file
33   srcdir=.
34   options=$extra_options
35 else
36   testfile=$srcdir/input/$file
37   options="$options $extra_options"
38 fi
39
40 outfile=$test_name.out
41 logfile=check.out
42 reffile=$srcdir/output/$test_name.ref
43 options="$options -o $outfile"
44
45 builddir=`pwd`
46 ltcmd="$builddir/../libtool --mode=execute -dlopen $builddir/../gedcom/libgedcom.la -dlopen $builddir/../gom/libgedcom_gom.la"
47 GCONV_PATH=.:$GCONV_PATH
48 export GCONV_PATH
49 ln -s $srcdir/../data/gedcom.enc .
50 ln -s $builddir/../iconv/glibc/.libs/ANSI_Z39.47.so .
51 ln -s $srcdir/../iconv/glibc/gconv-modules .
52 rm -f core
53 echo "======================================================">> $logfile
54 echo "Performing test '$test_name'" >> $logfile
55 if [ "$GOM_DMALLOC_TEST" = "" ]
56 then
57   $ltcmd $GEDCOM_TESTENV $builddir/src/gomtest $options $testfile
58 else
59   dmalloc=`which dmalloc`
60   dmalloc_tmp=dmalloc.env
61   $dmalloc -b -l $GOM_DMALLOC_TEST -i 100 low > $dmalloc_tmp
62   . $dmalloc_tmp
63   rm $dmalloc_tmp
64   $ltcmd $GEDCOM_TESTENV $builddir/src/gomtest_static $options $testfile
65 fi
66 result=$?
67 rm gedcom.enc
68 rm ANSI_Z39.47.so
69 rm gconv-modules
70
71 echo "Result is $result (expected: $expected_result)" >> $logfile
72 if [ "$result" -ne "$expected_result" ]
73 then
74   echo "Not the expected return value!" >> $logfile
75   exit 1
76 else
77   if [ -r core ]
78   then
79     echo "Core file generated!" >> $logfile
80     exit 1
81   else
82     if diff $outfile $reffile >/dev/null 2>>$logfile
83     then
84       echo "Output agrees with reference output" >> $logfile
85       rm $outfile
86       exit 0
87     else
88       echo "Differences with reference output detected!" >> $logfile
89       exit 1
90     fi
91   fi
92 fi