Fixed bug reading compressed system files.
[pspp-builds.git] / tests / bugs / compression.sh
1 #!/bin/sh
2
3 # This program tests that compressed system files can be read and written
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
7
8 # ensure that top_srcdir and top_builddir  are absolute
9 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
10 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
11 top_srcdir=`cd $top_srcdir; pwd`
12 top_builddir=`cd $top_builddir; pwd`
13
14 export STAT_CONFIG_PATH=$top_srcdir/config
15
16
17 cleanup()
18 {
19      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
20         echo "NOT cleaning $TEMPDIR"
21         return ; 
22      fi
23      rm -rf $TEMPDIR
24 }
25
26
27 fail()
28 {
29     echo $activity
30     echo FAILED
31     cleanup;
32     exit 1;
33 }
34
35
36 no_result()
37 {
38     echo $activity
39     echo NO RESULT;
40     cleanup;
41     exit 2;
42 }
43
44 pass()
45 {
46     cleanup;
47     exit 0;
48 }
49
50 mkdir -p $TEMPDIR
51
52 cd $TEMPDIR
53
54 cat > $TESTFILE <<EOF
55 DATA LIST LIST /x * y (a200).
56 BEGIN DATA.
57 1.2 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
58 .   yyyyyyyyyyyyyyy
59 0   ddddddddddddddddddddddddddddddd
60 101 z
61 END DATA.
62
63 SAVE OUTFILE='$TEMPDIR/com.sav' /COMPRESS .
64
65 GET FILE='$TEMPDIR/com.sav'.
66
67 LIST.
68
69 EOF
70 if [ $? -ne 0 ] ; then no_result ; fi
71
72
73 activity="run program"
74 $SUPERVISOR $top_builddir/src/pspp --testing-mode -o raw-ascii $TESTFILE
75 if [ $? -ne 0 ] ; then fail ; fi
76
77 # Make sure the file really was compressed
78 activity="inspect system file"
79 dd if=$TEMPDIR/com.sav bs=1 skip=72 count=1 2> /dev/null | od > $TEMPDIR/file 
80 if [ $? -ne 0 ] ; then no_result ; fi
81
82 activity="check compression byte"
83 diff $TEMPDIR/file - <<EOF
84 0000000 000001
85 0000001
86 EOF
87 if [ $? -ne 0 ] ; then fail ; fi
88
89
90 pass;