Added echo statement, but commented out
[yaz-moved-to-github.git] / test / tstmarc.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 binmarc_convert() {  
17     OUTPUT_FORMAT="$1"
18     REVERT_FORMAT="$2"
19     PREFIX="$3"
20     for f in ${srcdir}/marc[0-9].marc; do
21         fb=`basename ${f} .marc`
22         CHR=`cat ${srcdir}/${fb}.chr`
23         NEW=${PREFIX}${fb}.new.xml
24         OLD=${srcdir}/${PREFIX}${fb}.xml
25         DIFF=`basename ${f}`.diff
26         #echo "../util/yaz-marcdump -f $CHR -t utf-8 -i marc -o ${OUTPUT_FORMAT} $f > $NEW"
27         ../util/yaz-marcdump -f $CHR -t utf-8 -i marc -o ${OUTPUT_FORMAT} $f > $NEW
28         if test $? != "0"; then
29             echo "$f: yaz-marcdump returned error"
30             ecode=1
31         elif test -f $OLD; then
32             if diff $OLD $NEW >$DIFF; then
33                 rm $DIFF
34                 rm $NEW
35             else
36                 echo "$f: $NEW and $OLD differ"
37                 ecode=1
38             fi
39         else
40             echo "$f: Making test result $OLD for the first time"
41             if test -x /usr/bin/xmllint; then
42                 if xmllint --noout $NEW >out 2>stderr; then
43                     echo "$f: $NEW is well-formed"
44                     mv $NEW $OLD
45                 else
46                     echo "$f: $NEW not well-formed"
47                     ecode=1
48                 fi
49             else
50                 echo "xmllint not found. install libxml2-utils"
51                 ecode=1
52             fi
53         fi
54         
55         if test -z "$noxml"; then
56             ORIGINAL=${f}
57             f=$OLD
58             # compare with original (binary) marc record.
59             OLD=${f}.marc
60             NEW=`basename ${f}`.new.marc
61             DIFF=`basename ${f}`.diff
62             #echo "../util/yaz-marcdump -f utf-8 -t utf-8 -i ${REVERT_FORMAT} -o marc $f > $NEW" 
63             ../util/yaz-marcdump -f utf-8 -t utf-8 -i ${REVERT_FORMAT} -o marc $f > $NEW
64             if test $? != "0"; then
65                 echo "Failed decode of $f"
66                 ecode=1
67             elif test -f $OLD; then
68                 if diff $OLD $NEW >$DIFF; then
69                     rm $DIFF
70                     rm $NEW
71                 else
72                     echo "$f: $NEW and $OLD Differ"
73                     ecode=1
74                 fi
75             else
76                 echo "$f: Making test result $OLD for the first time"
77                 mv $NEW $OLD
78             fi
79             # check with original
80             REVERT=`basename ${f}`.marc.revert
81             #../util/yaz-marcdump -f utf-8 -t $CHR  -i ${REVERT_FORMAT} -o marc $f > $REVERT
82             #hexdump -cx $REVERT   > $REVERT.hex  
83             #hexdump -cx $ORIGINAL > $ORIGINAL.hex
84             #diff $REVERT.hex $ORIGINAL.hex > $REVERT.diff
85         fi
86     done
87     return $ecode
88 }
89
90 binmarc_convert "marcxml"  "marcxml" "" 
91 echo "binmarc -> marcxml: $?" 
92
93 binmarc_convert "xml,marcxml" "marcxml" "xml2" 
94 echo "binmarc -> marcxml(libxml2): $?" 
95
96 binmarc_convert "tmarcxml"  "tmarcxml" "t" 
97 echo "binmarc -> tmarcxml: $?" 
98
99 binmarc_convert "xml,tmarcxml"  "tmarcxml" "xml2t" 
100 echo "binmarc -> tmarcxml(libxml2): $?" 
101
102 exit $ecode
103
104 # Local Variables:
105 # mode:shell-script
106 # sh-indentation: 2
107 # sh-basic-offset: 4
108 # End: