Remove member soap_handler from statserv_options_block
[yaz-moved-to-github.git] / test / test_marc.sh
1 #!/bin/sh
2 # Tests reading of ISO2709 and checks that we get identical MARCXML
3
4 # Reads marc?.marc files , Generates marc*.xml files
5 # If Libxml2 is present, also turbomarc*xml. 
6 # as well as reverse transformation from *marc*.xml files are parsed again.. 
7
8 srcdir=${srcdir:-.}
9 ecode=0
10
11 ../util/yaz-marcdump -i marcxml >/dev/null 2>&1
12 if test $? = "3"; then
13     noxml=1
14 fi
15
16 ../util/yaz-marcdump -o xml,marcxml >/dev/null 2>&1
17 if test $? = "4"; then
18     noxmlwrite=1
19 fi
20
21 binmarc_convert() {  
22     OUTPUT_FORMAT="$1"
23     REVERT_FORMAT="$2"
24     PREFIX="$3"
25     for f in ${srcdir}/marc[0-9].marc; do
26         fb=`basename ${f} .marc`
27         CHR=`cat ${srcdir}/${fb}.chr`
28         NEW=${PREFIX}${fb}.new.xml
29         OLD=${srcdir}/${PREFIX}${fb}.xml
30         DIFF=`basename ${f}`.diff
31         #echo "../util/yaz-marcdump -f $CHR -t utf-8 -i marc -o ${OUTPUT_FORMAT} $f > $NEW"
32         ../util/yaz-marcdump -f $CHR -t utf-8 -i marc -o ${OUTPUT_FORMAT} $f > $NEW
33         if test $? != "0"; then
34             echo "$f: yaz-marcdump returned error"
35             ecode=1
36         elif test -f $OLD; then
37             if diff $OLD $NEW >$DIFF; then
38                 rm $DIFF
39                 rm $NEW
40             else
41                 echo "$f: $NEW and $OLD differ"
42                 ecode=1
43             fi
44         else
45             echo "$f: Making test result $OLD for the first time"
46             if test -x /usr/bin/xmllint; then
47                 if xmllint --noout $NEW >out 2>stderr; then
48                     echo "$f: $NEW is well-formed"
49                     mv $NEW $OLD
50                 else
51                     echo "$f: $NEW not well-formed"
52                     ecode=1
53                 fi
54             else
55                 echo "xmllint not found. install libxml2-utils"
56                 ecode=1
57             fi
58         fi
59         
60         if test -z "$noxml"; then
61             ORIGINAL=${f}
62             f=$OLD
63             # compare with original (binary) marc record.
64             OLD=${f}.marc
65             NEW=`basename ${f}`.new.marc
66             DIFF=`basename ${f}`.diff
67             #echo "../util/yaz-marcdump -f utf-8 -t utf-8 -i ${REVERT_FORMAT} -o marc $f > $NEW" 
68             ../util/yaz-marcdump -f utf-8 -t utf-8 -i ${REVERT_FORMAT} -o marc $f > $NEW
69             if test $? != "0"; then
70                 echo "Failed decode of $f"
71                 ecode=1
72             elif test -f $OLD; then
73                 if diff $OLD $NEW >$DIFF; then
74                     rm $DIFF
75                     rm $NEW
76                 else
77                     echo "$f: $NEW and $OLD Differ"
78                     ecode=1
79                 fi
80             else
81                 echo "$f: Making test result $OLD for the first time"
82                 mv $NEW $OLD
83             fi
84             # check with original
85             REVERT=`basename ${f}`.marc.revert
86             #../util/yaz-marcdump -f utf-8 -t $CHR  -i ${REVERT_FORMAT} -o marc $f > $REVERT
87             #hexdump -cx $REVERT   > $REVERT.hex  
88             #hexdump -cx $ORIGINAL > $ORIGINAL.hex
89             #diff $REVERT.hex $ORIGINAL.hex > $REVERT.diff
90         fi
91     done
92     return $ecode
93 }
94
95 binmarc_convert "marcxml"  "marcxml" "" 
96 echo "binmarc -> marcxml: $?" 
97
98
99 if test -z "$noxmlwrite"; then
100 binmarc_convert "xml,marcxml" "marcxml" "xml2" 
101 echo "binmarc -> marcxml(libxml2): $?" 
102 fi
103
104 binmarc_convert "turbomarc"  "turbomarc" "t" 
105 echo "binmarc -> turbomarc: $?" 
106
107 if test -z "$noxmlwrite"; then
108 binmarc_convert "xml,turbomarc"  "turbomarc" "xml2t" 
109 echo "binmarc -> turbomarc(libxml2): $?" 
110 fi
111
112 exit $ecode
113
114 # Local Variables:
115 # mode:shell-script
116 # sh-indentation: 2
117 # sh-basic-offset: 4
118 # End: