3 # Tests BINARY and 360 data file formats.
5 TEMPDIR=/tmp/pspp-tst-$$
7 # ensure that top_builddir are absolute
8 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
9 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
10 top_builddir=`cd $top_builddir; pwd`
11 PSPP=$top_builddir/src/ui/terminal/pspp
14 # ensure that top_srcdir is absolute
15 top_srcdir=`cd $top_srcdir; pwd`
17 STAT_CONFIG_PATH=$top_srcdir/config
18 export STAT_CONFIG_PATH
57 activity="create data file"
58 cat > $TEMPDIR/input.data <<EOF
69 if [ $? -ne 0 ] ; then no_result ; fi
71 activity="create program to transform data into 360 formats"
72 cat > $TEMPDIR/make-360.pl <<'EOF'
76 # ASCII to EBCDIC translation table
77 our ($ascii2ebcdic) = ""
78 . "\x00\x01\x02\x03\x37\x2d\x2e\x2f"
79 . "\x16\x05\x25\x0b\x0c\x0d\x0e\x0f"
80 . "\x10\x11\x12\x13\x3c\x3d\x32\x26"
81 . "\x18\x19\x3f\x27\x1c\x1d\x1e\x1f"
82 . "\x40\x5a\x7f\x7b\x5b\x6c\x50\x7d"
83 . "\x4d\x5d\x5c\x4e\x6b\x60\x4b\x61"
84 . "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7"
85 . "\xf8\xf9\x7a\x5e\x4c\x7e\x6e\x6f"
86 . "\x7c\xc1\xc2\xc3\xc4\xc5\xc6\xc7"
87 . "\xc8\xc9\xd1\xd2\xd3\xd4\xd5\xd6"
88 . "\xd7\xd8\xd9\xe2\xe3\xe4\xe5\xe6"
89 . "\xe7\xe8\xe9\xad\xe0\xbd\x9a\x6d"
90 . "\x79\x81\x82\x83\x84\x85\x86\x87"
91 . "\x88\x89\x91\x92\x93\x94\x95\x96"
92 . "\x97\x98\x99\xa2\xa3\xa4\xa5\xa6"
93 . "\xa7\xa8\xa9\xc0\x4f\xd0\x5f\x07"
94 . "\x20\x21\x22\x23\x24\x15\x06\x17"
95 . "\x28\x29\x2a\x2b\x2c\x09\x0a\x1b"
96 . "\x30\x31\x1a\x33\x34\x35\x36\x08"
97 . "\x38\x39\x3a\x3b\x04\x14\x3e\xe1"
98 . "\x41\x42\x43\x44\x45\x46\x47\x48"
99 . "\x49\x51\x52\x53\x54\x55\x56\x57"
100 . "\x58\x59\x62\x63\x64\x65\x66\x67"
101 . "\x68\x69\x70\x71\x72\x73\x74\x75"
102 . "\x76\x77\x78\x80\x8a\x8b\x8c\x8d"
103 . "\x8e\x8f\x90\x6a\x9b\x9c\x9d\x9e"
104 . "\x9f\xa0\xaa\xab\xac\x4a\xae\xaf"
105 . "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7"
106 . "\xb8\xb9\xba\xbb\xbc\xa1\xbe\xbf"
107 . "\xca\xcb\xcc\xcd\xce\xcf\xda\xdb"
108 . "\xdc\xdd\xde\xdf\xea\xeb\xec\xed"
109 . "\xee\xef\xfa\xfb\xfc\xfd\xfe\xff";
110 length ($ascii2ebcdic) == 256 || die;
112 open (INPUT, '<', 'input.data') or die "input.data: open: $!\n";
113 my (@data) = <INPUT> or die;
114 close (INPUT) or die;
115 chomp $_ foreach @data;
118 open (OUTPUT, '>', 'binary.bin') or die "binary.bin: create: $!\n";
120 my ($reclen) = pack ("V", length);
121 print OUTPUT $reclen, $_, $reclen;
123 close (OUTPUT) or die;
126 open (OUTPUT, '>', 'fixed.bin') or die "fixed.bin: create: $!\n";
129 my ($out) = substr ($_, 0, $lrecl);
130 $out .= ' ' x ($lrecl - length ($out));
131 length ($out) == 32 or die;
132 print OUTPUT a2e ($out);
134 close (OUTPUT) or die;
137 open (OUTPUT, '>', 'variable.bin') or die "variable.bin: create: $!\n";
140 push (@records, pack ("n xx", length ($_) + 4) . a2e ($_));
143 close (OUTPUT) or die;
146 open (OUTPUT, '>', 'spanned.bin') or die "spanned.bin: create: $!\n";
147 for my $line (@data) {
151 my ($n) = min (int (rand (5)), length);
152 push (@r, substr ($_, 0, $n, ''));
154 foreach my $i (0...$#r) {
155 my $scc = ($#r == 0 ? 0
160 pack ("nCx", length ($r[$i]) + 4, $scc) . a2e ($r[$i]));
164 close (OUTPUT) or die;
169 foreach (split (//)) {
170 $s .= substr ($ascii2ebcdic, ord, 1);
177 return $a < $b ? $a : $b
182 my ($n) = min (int (rand (5)) + 1, scalar (@records));
183 my (@r) = splice (@records, 0, $n);
185 $len += length foreach @r;
186 print OUTPUT pack ("n xx", $len + 4);
187 print OUTPUT foreach @r;
191 if [ $? -ne 0 ] ; then no_result ; fi
193 activity="running make-360.pl"
195 if [ $? -ne 0 ] ; then no_result ; fi
197 binary_fh='mode=binary'
198 fixed_fh='mode=360 /recform=fixed /lrecl=32'
199 variable_fh='mode=360 /recform=variable'
200 spanned_fh='mode=360 /recform=spanned'
202 for type in binary fixed variable spanned; do
203 activity="create $type.pspp"
205 cat > $type.pspp <<EOF
206 * Read the original file and list its data, to test reading these formats.
207 file handle input/name='$type.bin'/$fh.
208 data list fixed file=input notable
209 /1 start 1-10 (adate)
214 * Output the data to a new file in the same format.
215 file handle output/name='${type}2.bin'/$fh.
216 compute count=count + 1.
217 print outfile=output/start end count.
220 * Re-read the new data and list it, to verify that it was written correctly.
221 data list fixed file=output notable/
228 if [ $? -ne 0 ] ; then no_result ; fi
230 # Make sure that pspp.list isn't left over from another run.
233 activity="run $type.pspp"
234 $SUPERVISOR $PSPP --testing-mode $type.pspp
235 if [ $? -ne 0 ] ; then fail ; fi
237 activity="compare $type.pspp output"
238 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
239 diff -b $TEMPDIR/pspp.list - << EOF
241 ---------- ---------- -----
242 07/22/2007 10/06/2007 321
243 07/14/1789 08/26/1789 4
244 01/01/1972 12/31/1999 682
246 ---------- ---------- -----
247 07/22/2007 10/06/2007 322
248 07/14/1789 08/26/1789 5
249 01/01/1972 12/31/1999 683
251 if [ $? -ne 0 ] ; then fail ; fi