885846eebbc98d936620f439eec74d6d298820c5
[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 PSPP=$top_builddir/src/ui/terminal/pspp
14
15 STAT_CONFIG_PATH=$top_srcdir/config
16 export STAT_CONFIG_PATH
17
18
19 cleanup()
20 {
21      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
22         echo "NOT cleaning $TEMPDIR"
23         return ; 
24      fi
25      rm -rf $TEMPDIR
26 }
27
28
29 fail()
30 {
31     echo $activity
32     echo FAILED
33     cleanup;
34     exit 1;
35 }
36
37
38 no_result()
39 {
40     echo $activity
41     echo NO RESULT;
42     cleanup;
43     exit 2;
44 }
45
46 pass()
47 {
48     cleanup;
49     exit 0;
50 }
51
52 mkdir -p $TEMPDIR
53
54 cd $TEMPDIR
55
56 cat > $TESTFILE <<EOF
57 DATA LIST LIST /x * y (a200).
58 BEGIN DATA.
59 1.2 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
60 .   yyyyyyyyyyyyyyy
61 0   ddddddddddddddddddddddddddddddd
62 101 z
63 END DATA.
64
65 SAVE OUTFILE='$TEMPDIR/com.sav' /COMPRESS .
66
67 GET FILE='$TEMPDIR/com.sav'.
68
69 LIST.
70
71 EOF
72 if [ $? -ne 0 ] ; then no_result ; fi
73
74
75 activity="run program"
76 $SUPERVISOR $PSPP --testing-mode $TESTFILE
77 if [ $? -ne 0 ] ; then fail ; fi
78
79 # Make sure the file really was compressed
80 activity="inspect system file"
81 dd if=$TEMPDIR/com.sav bs=1 skip=72 count=4 2> /dev/null | od > $TEMPDIR/file
82 if [ $? -ne 0 ] ; then no_result ; fi
83
84 activity="check compression setting"
85 # Big-endian?
86 diff -b $TEMPDIR/file - > /dev/null <<EOF
87 0000000 000000 000001
88 0000004
89 EOF
90 if [ $? -ne 0 ] ; then pass ; fi
91 # Little-endian?
92 diff -b $TEMPDIR/file - > /dev/null <<EOF
93 0000000 000001 000000
94 0000004
95 EOF
96 if [ $? -ne 0 ] ; then pass ; fi
97 # Otherwise error.
98 cat $TEMPDIR/file
99 fail