Fixed bug reading compressed system files.
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 4 Mar 2006 05:01:06 +0000 (05:01 +0000)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 4 Mar 2006 05:01:06 +0000 (05:01 +0000)
src/data/ChangeLog
src/data/sys-file-reader.c
tests/automake.mk
tests/bugs/compression.sh [new file with mode: 0755]
tests/test_template

index c80710ca38ab2613bd2976439ba7e36fbc75ed1b..e873a3945c323b5c28ca9d49b7468c058ed6bce7 100644 (file)
@@ -1,3 +1,7 @@
+Sat Mar  4 12:50:48 WST 2006 John Darrington <john@darrington.wattle.id.au>
+
+       * sys-file-reader.c: Fixed bug reading compressed files.
+
 Thu Mar  2 08:40:33 WST 2006 John Darrington <john@darrington.wattle.id.au>
 
        * Numerous renames.  See src/ChangeLog for details.
index c8c70342c957f421f6503bbce331665dad4aee1b..9a3faf6a7d2722cdb36b741a6f06e023cb58f518 100644 (file)
@@ -1399,9 +1399,13 @@ read_compressed_data (struct sfm_reader *r, flt64 *buf)
       if (r->ptr == NULL || r->ptr >= r->end) 
         {
           if (!buffer_input (r))
-            if (buf_beg != buf)
-              lose ((ME, _("%s: Unexpected end of file."),
-                     fh_get_filename (r->fh))); 
+           {
+             if (buf_beg != buf)
+               lose ((ME, _("%s: Unexpected end of file."),
+                      fh_get_filename (r->fh))); 
+             else
+               return 0;
+           }
         }
       memcpy (r->x, r->ptr++, sizeof *buf);
       p = r->x;
index 64a2b712181721e6861b9521b12fefd6941b19de..cfe41fa1451dddea00c1d7e378d27dc1f5e1610e 100644 (file)
@@ -59,6 +59,7 @@ TESTS = \
        tests/bugs/big-input-2.sh \
        tests/bugs/comment-at-eof.sh \
        tests/bugs/compute-fmt.sh \
+       tests/bugs/compression.sh \
        tests/bugs/crosstabs.sh \
        tests/bugs/crosstabs-crash.sh \
        tests/bugs/curtailed.sh \
diff --git a/tests/bugs/compression.sh b/tests/bugs/compression.sh
new file mode 100755 (executable)
index 0000000..e705480
--- /dev/null
@@ -0,0 +1,90 @@
+#!/bin/sh
+
+# This program tests that compressed system files can be read and written
+
+TEMPDIR=/tmp/pspp-tst-$$
+TESTFILE=$TEMPDIR/`basename $0`.sps
+
+# ensure that top_srcdir and top_builddir  are absolute
+if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
+if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
+top_srcdir=`cd $top_srcdir; pwd`
+top_builddir=`cd $top_builddir; pwd`
+
+export STAT_CONFIG_PATH=$top_srcdir/config
+
+
+cleanup()
+{
+     if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
+       echo "NOT cleaning $TEMPDIR"
+       return ; 
+     fi
+     rm -rf $TEMPDIR
+}
+
+
+fail()
+{
+    echo $activity
+    echo FAILED
+    cleanup;
+    exit 1;
+}
+
+
+no_result()
+{
+    echo $activity
+    echo NO RESULT;
+    cleanup;
+    exit 2;
+}
+
+pass()
+{
+    cleanup;
+    exit 0;
+}
+
+mkdir -p $TEMPDIR
+
+cd $TEMPDIR
+
+cat > $TESTFILE <<EOF
+DATA LIST LIST /x * y (a200).
+BEGIN DATA.
+1.2 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+.   yyyyyyyyyyyyyyy
+0   ddddddddddddddddddddddddddddddd
+101 z
+END DATA.
+
+SAVE OUTFILE='$TEMPDIR/com.sav' /COMPRESS .
+
+GET FILE='$TEMPDIR/com.sav'.
+
+LIST.
+
+EOF
+if [ $? -ne 0 ] ; then no_result ; fi
+
+
+activity="run program"
+$SUPERVISOR $top_builddir/src/pspp --testing-mode -o raw-ascii $TESTFILE
+if [ $? -ne 0 ] ; then fail ; fi
+
+# Make sure the file really was compressed
+activity="inspect system file"
+dd if=$TEMPDIR/com.sav bs=1 skip=72 count=1 2> /dev/null | od > $TEMPDIR/file 
+if [ $? -ne 0 ] ; then no_result ; fi
+
+activity="check compression byte"
+diff $TEMPDIR/file - <<EOF
+0000000 000001
+0000001
+EOF
+if [ $? -ne 0 ] ; then fail ; fi
+
+
+pass;
index 5f30158ad1baaf89630cc9221124666904ad5090..bb862fefd892b40eea8f6a597507f5e5e6498f60 100755 (executable)
@@ -9,7 +9,7 @@ TESTFILE=$TEMPDIR/`basename $0`.sps
 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
 top_srcdir=`cd $top_srcdir; pwd`
-top_buiddir=`cd $top_builddir; pwd`
+top_builddir=`cd $top_builddir; pwd`
 
 export STAT_CONFIG_PATH=$top_srcdir/config