dnl PSPP - a program for statistical analysis.
dnl Copyright (C) 2017 Free Software Foundation, Inc.
dnl
dnl This program is free software: you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation, either version 3 of the License, or
dnl (at your option) any later version.
dnl
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
dnl
AT_BANNER([system file reader - positive])

AT_SETUP([variable labels and missing values])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
28; dnl Nominal case size
0; dnl Not compressed
0; dnl Not weighted
1; dnl 1 case.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52";
"PSPP synthetic test file: "; i8 244; i8 245; i8 246; i8 248; s34 "";
i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Numeric variable, variable label.
2; 0; 1; 0; 0x050800 *2; s8 "NUM2";
32; "Numeric variable 2's label ("; i8 249; i8 250; i8 251; ")";

dnl Numeric variable, one missing value.
2; 0; 0; 1; 0x050800 *2; s8 "NUM3";
1.0;

dnl Numeric variable, variable label and missing value.
2; 0; 1; 1; 0x050800 *2; s8 "NUM4";
30; "Another numeric variable label"; i8 0 * 2;
1.0;

dnl Numeric variable, two missing values.
2; 0; 0; 2; 0x050800 *2; s8 "NUM5"; 1.0; 2.0;

dnl Numeric variable, three missing values.
2; 0; 0; 3; 0x050800 *2; s8 "NUM6"; 1.0; 2.0; 3.0;

dnl Numeric variable, range of missing values.
2; 0; 0; -2; 0x050800 *2; s8 "NUM7"; 1.0; 3.0;

dnl Numeric variables, range of missing values plus discrete value.
2; 0; 0; -3; 0x050800 *2; s8 "NUM8"; 1.0; 3.0; 5.0;
2; 0; 0; -3; 0x050800 *2; s8 "NUM9"; 1.0; HIGHEST; -5.0;
2; 0; 0; -3; 0x050800 *2; "NUM"; i8 192; i8 200; i8 204; i8 209; i8 210;
LOWEST; 1.0; 5.0;

dnl String variable, no label or missing values.
2; 4; 0; 0; 0x010400 *2; s8 "STR1";

dnl String variable, variable label.
2; 4; 1; 0; 0x010400 *2; s8 "STR2";
25; "String variable 2's label"; i8 0 * 3;

dnl String variable, one missing value.
2; 4; 0; 1; 0x010400 *2; s8 "STR3"; s8 "MISS";

dnl String variable, variable label and missing value.
2; 4; 1; 1; 0x010400 *2; s8 "STR4";
29; "Another string variable label"; i8 0 * 3;
s8 "OTHR";

dnl String variable, two missing values.
2; 4; 0; 2; 0x010400 *2; s8 "STR5"; s8 "MISS"; s8 "OTHR";

dnl String variable, three missing values.
2; 4; 0; 3; 0x010400 *2; s8 "STR6"; s8 "MISS"; s8 "OTHR"; s8 "MORE";

dnl Long string variable, one missing value.
dnl (This is not how SPSS represents missing values for long strings--it
dnl uses a separate record as shown later below--but old versions of PSPP
dnl did use this representation so we continue supporting it for backward
dnl compatibility.
2; 11; 0; 1; 0x010b00 *2; s8 "STR7"; "first8by";
2; -1; 0; 0; 0; 0; s8 "";

dnl Long string variables that will have missing values added with a
dnl later record.
2; 9; 0; 0; 0x010900 *2; s8 "STR8";
2; -1; 0; 0; 0; 0; s8 "";
2; 10; 0; 0; 0x010a00 *2; s8 "STR9";
2; -1; 0; 0; 0; 0; s8 "";
2; 11; 0; 0; 0x010b00 *2; s8 "STR10";
2; -1; 0; 0; 0; 0; s8 "";

dnl Long string variable, value label.
2; 25; 1; 0; 0x011900 *2; s8 "STR11"; 14; "25-byte string"; i8 0 * 2;
( 2; -1; 0; 0; 0; 0; s8 ""; ) * 2;
dnl Variable label fields on continuation records have been spotted in system
dnl files created by "SPSS Power Macintosh Release 6.1".
2; -1; 1; 0; 0; 0; s8 ""; 20; "dummy variable label";

dnl Machine integer info record.
7; 3; 4; 8; 1; 2; 3; -1; 1; 1; ENDIAN; 1252;

dnl Machine floating-point info record.
7; 4; 8; 3; SYSMIS; HIGHEST; LOWEST;

dnl Long string variable missing values record.
7; 22; 1; COUNT (
dnl One missing value for STR8.
COUNT("STR8"); i8 1; 8; "abcdefgh";

dnl Two missing values for STR9.
COUNT("STR9"); i8 2; 8; "abcdefgh"; "01234567";

dnl Three missing values for STR9.
COUNT("STR10"); i8 3; 8; "abcdefgh"; "01234567"; "0       ";
);

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;

dnl Data.
1.0; 2.0; 3.0; 4.0; 5.0; 6.0; 7.0; 8.0; 9.0; 10.0;
s8 "abcd"; s8 "efgh"; s8 "ijkl"; s8 "mnop"; s8 "qrst"; s8 "uvwx";
s16 "yzABCDEFGHI"; s16 "JKLMNOPQR"; s16 "STUVWXYZ01";
s16 "23456789abc"; s32 "defghijklmnopqstuvwxyzABC";
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY FILE LABEL.
DISPLAY DICTIONARY.
LIST.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps])
  AT_CHECK([cat pspp.csv], [0], [dnl
Table: File Label
Label,PSPP synthetic test file: ôõöø

Table: Variables
Name,Position,Label,Measurement Level,Role,Width,Alignment,Print Format,Write Format,Missing Values
num1,1,,Unknown,Input,8,Right,F8.0,F8.0,
num2,2,Numeric variable 2's label (ùúû),Unknown,Input,8,Right,F8.0,F8.0,
num3,3,,Unknown,Input,8,Right,F8.0,F8.0,1
num4,4,Another numeric variable label,Unknown,Input,8,Right,F8.0,F8.0,1
num5,5,,Unknown,Input,8,Right,F8.0,F8.0,1; 2
num6,6,,Unknown,Input,8,Right,F8.0,F8.0,1; 2; 3
num7,7,,Unknown,Input,8,Right,F8.0,F8.0,1 THRU 3
num8,8,,Unknown,Input,8,Right,F8.0,F8.0,1 THRU 3; 5
num9,9,,Unknown,Input,8,Right,F8.0,F8.0,1 THRU HIGHEST; -5
numàèìñò,10,,Unknown,Input,8,Right,F8.0,F8.0,LOWEST THRU 1; 5
str1,11,,Nominal,Input,4,Left,A4,A4,
str2,12,String variable 2's label,Nominal,Input,4,Left,A4,A4,
str3,13,,Nominal,Input,4,Left,A4,A4,"""MISS"""
str4,14,Another string variable label,Nominal,Input,4,Left,A4,A4,"""OTHR"""
str5,15,,Nominal,Input,4,Left,A4,A4,"""MISS""; ""OTHR"""
str6,16,,Nominal,Input,4,Left,A4,A4,"""MISS""; ""OTHR""; ""MORE"""
str7,17,,Nominal,Input,11,Left,A11,A11,"""first8by"""
str8,18,,Nominal,Input,9,Left,A9,A9,"""abcdefgh"""
str9,19,,Nominal,Input,10,Left,A10,A10,"""abcdefgh""; ""01234567"""
str10,20,,Nominal,Input,11,Left,A11,A11,"""abcdefgh""; ""01234567""; ""0       """
str11,21,25-byte string,Nominal,Input,25,Left,A25,A25,

Table: Data List
num1,num2,num3,num4,num5,num6,num7,num8,num9,numàèìñò,str1,str2,str3,str4,str5,str6,str7,str8,str9,str10,str11
1,2,3,4,5,6,7,8,9,10,abcd,efgh,ijkl,mnop,qrst,uvwx,yzABCDEFGHI,JKLMNOPQR,STUVWXYZ01,23456789abc,defghijklmnopqstuvwxyzABC
])
done
AT_CLEANUP

AT_SETUP([unspecified number of variable positions])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
-1; dnl Nominal case size (unspecified)
0; dnl Not compressed
0; dnl Not weighted
1; dnl 1 case.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Numeric variable, variable label.
2; 0; 1; 0; 0x050800 *2; s8 "NUM2";
26; "Numeric variable 2's label"; i8 0 *2;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;

dnl Data.
1.0; 2.0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY DICTIONARY.
LIST.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps])
  AT_CHECK([cat pspp.csv], [0], [dnl
Table: Variables
Name,Position,Label,Measurement Level,Role,Width,Alignment,Print Format,Write Format
num1,1,,Unknown,Input,8,Right,F8.0,F8.0
num2,2,Numeric variable 2's label,Unknown,Input,8,Right,F8.0,F8.0

Table: Data List
num1,num2
1,2
])
done
AT_CLEANUP

AT_SETUP([wrong number of variable positions but version 13])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
-1; dnl Nominal case size (unspecified)
0; dnl Not compressed
0; dnl Not weighted
1; dnl 1 case.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Numeric variable, variable label.
2; 0; 1; 0; 0x050800 *2; s8 "NUM2";
26; "Numeric variable 2's label"; i8 0 *2;

dnl Machine integer info record (SPSS 13).
7; 3; 4; 8; 13; 2; 3; -1; 1; 1; ENDIAN; 1252;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;

dnl Data.
1.0; 2.0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY DICTIONARY.
LIST.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps])
  AT_CHECK([cat pspp.csv], [0], [dnl
Table: Variables
Name,Position,Label,Measurement Level,Role,Width,Alignment,Print Format,Write Format
num1,1,,Unknown,Input,8,Right,F8.0,F8.0
num2,2,Numeric variable 2's label,Unknown,Input,8,Right,F8.0,F8.0

Table: Data List
num1,num2
1,2
])
done
AT_CLEANUP

AT_SETUP([value labels])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
22; dnl Nominal case size
0; dnl Not compressed
0; dnl Not weighted
1; dnl 1 case.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Numeric variables.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";
2; 0; 0; 0; 0x050800 *2; s8 "NUM2";
2; 0; 0; 0; 0x050800 *2; s8 "NUM3";
2; 0; 0; 0; 0x050800 *2; s8 "NUM4";
2; 0; 0; 0; 0x050800 *2; s8 "NUM5";

dnl String variables.
2; 1; 0; 0; 0x010100 *2; s8 "STR1"; dnl index 6
2; 2; 0; 0; 0x010200 *2; s8 "STR2"; dnl index 7
2; 3; 0; 0; 0x010300 *2; s8 "STR3"; dnl index 8
2; 4; 0; 0; 0x010400 *2; s8 "STR4"; dnl index 9
2; 4; 0; 0; 0x010400 *2; s8 "STR5"; dnl index 10
2; 6; 0; 0; 0x010600 *2; s8 "STR6"; dnl index 11
2; 7; 0; 0; 0x010700 *2; s8 "STR7"; dnl index 12
2; 8; 0; 0; 0x010800 *2; s8 "STR8"; dnl index 13
2; 9; 0; 0; 0x010900 *2; "STR9"; i8 230; s3 ""; dnl index 14
2; -1; 0; 0; 0; 0; s8 "";
2; 12; 0; 0; 0x010c00 *2; s8 "STR12"; dnl index 16
2; -1; 0; 0; 0; 0; s8 "";
2; 16; 0; 0; 0x011000 *2; s8 "STR16"; dnl index 18
2; -1; 0; 0; 0; 0; s8 "";
2; 17; 0; 0; 0x011100 *2; s8 "STR17"; dnl index 20
( 2; -1; 0; 0; 0; 0; s8 ""; ) * 2;

dnl One value label for NUM1.
3; 1; 1.0; i8 17; i8 238; i8 228; i8 232; i8 237; s19 " (in Russian)"; 4; 1; 1;

dnl Two value labels for NUM2, as a single pair of type 3 and type 4 records.
3; 2; 1.0; i8 3; s7 "one"; 2.0; i8 3; s7 "two"; 4; 1; 2;

dnl Two value labels for NUM3, as two pairs of type 3 and type 4 records.
3; 1; 3.0; i8 5; s7 "three"; 4; 1; 3;
3; 1; 4.0; i8 4; s7 "four"; 4; 1; 3;

dnl Two common value labels for NUM4 and NUM5, plus two different ones for each.
3; 1; 5.0; i8 4; s7 "five"; 4; 1; 4;
3; 1; 6.0; i8 3; s7 "six"; 4; 1; 5;
3; 2; 7.0; i8 5; s7 "seven"; 8.0; i8 5; s7 "eight"; 4; 2; 4; 5;
3; 1; 9.0; i8 4; s7 "nine"; 4; 1; 4;
3; 1; 10.0; i8 3; s7 "ten"; 4; 1; 5;

dnl One value label for STR1.
3; 1; s8 "a"; i8 19; s23 "value label for `a'"; 4; 1; 6;

dnl Two value labels for STR2, as a single pair of type 3 and type 4 records.
3; 2;
s8 "bc"; i8 20; s23 "value label for `bc'";
s8 "de"; i8 20; s23 "value label for `de'";
4; 1; 7;

dnl Two value labels for STR3, as two pairs of type 3 and type 4 records.
3; 1; s8 "fgh"; i8 21; s23 "value label for `fgh'"; 4; 1; 8;
3; 1; s8 "ijk"; i8 21; s23 "value label for `ijk'"; 4; 1; 8;

dnl Two common value labels for STR4 and STR5, plus two different ones for each.
3; 1; s8 "lmno"; i8 22; s23 "value label for `lmno'"; 4; 1; 9;
3; 1; s8 "pqrs"; i8 22; s23 "value label for `pqrs'"; 4; 1; 10;
3; 2;
s8 "tuvw"; i8 22; s23 "value label for `tuvw'";
s8 "xyzA"; i8 22; s23 "value label for `xyzA'";
4; 2; 9; 10;
3; 1; s8 "BCDE"; i8 22; s23 "value label for `BCDE'"; 4; 1; 9;
3; 1; s8 "FGHI"; i8 22; s23 "value label for `FGHI'"; 4; 1; 10;

dnl One value label for STR6, STR7, STR8.
3; 1; s8 "JKLMNO"; i8 24; s31 "value label for `JKLMNO'"; 4; 1; 11;
3; 1; s8 "JKLMNOP"; i8 25; s31 "value label for `JKLMNOP'"; 4; 1; 12;
3; 1; s8 "JKLMNOPQ"; i8 26; s31 "value label for `JKLMNOPQ'"; 4; 1; 13;

dnl Machine integer info record.
7; 3; 4; 8; 1; 2; 3; -1; 1; 1; ENDIAN; 1251;

dnl Character encoding record.
7; 20; 1; 12; "windows-1251";

7; 21; 1; COUNT (
dnl One value label for STR9ж,
COUNT("STR9"; i8 230); 9; 1; COUNT("RSTUVWXYZ"); COUNT("value label for `RSTUVWXYZ'");

dnl Two value labels for STR12.
COUNT("STR12"); 12; 2;
COUNT("0123456789ab"); COUNT("value label for `0123456789ab'");
COUNT("cdefghijklmn"); COUNT("value label for `cdefghijklmn'");

dnl Three value labels for STR16.
COUNT("STR16"); 16; 3;
COUNT("opqrstuvwxyzABCD"); COUNT("value label for `opqrstuvwxyzABCD'");
COUNT("EFGHIJKLMNOPQRST"); COUNT("value label for `EFGHIJKLMNOPQRST'");
COUNT("UVWXYZ0123456789"); COUNT("value label for `UVWXYZ0123456789' with Cyrillic letters: `"; i8 244; i8 245; i8 246; "'");

dnl One value label for STR17.
COUNT("STR17"); 17; 1;
COUNT("abcdefghijklmnopq"); COUNT("value label for `abcdefghijklmnopq'");
);

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY DICTIONARY.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps])
  AT_CHECK([cat pspp.csv], [0], [dnl
Table: Variables
Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
num1,1,Unknown,Input,8,Right,F8.0,F8.0
num2,2,Unknown,Input,8,Right,F8.0,F8.0
num3,3,Unknown,Input,8,Right,F8.0,F8.0
num4,4,Unknown,Input,8,Right,F8.0,F8.0
num5,5,Unknown,Input,8,Right,F8.0,F8.0
str1,6,Nominal,Input,1,Left,A1,A1
str2,7,Nominal,Input,2,Left,A2,A2
str3,8,Nominal,Input,3,Left,A3,A3
str4,9,Nominal,Input,4,Left,A4,A4
str5,10,Nominal,Input,4,Left,A4,A4
str6,11,Nominal,Input,6,Left,A6,A6
str7,12,Nominal,Input,7,Left,A7,A7
str8,13,Nominal,Input,8,Left,A8,A8
str9ж,14,Nominal,Input,9,Left,A9,A9
str12,15,Nominal,Input,12,Left,A12,A12
str16,16,Nominal,Input,16,Left,A16,A16
str17,17,Nominal,Input,17,Left,A17,A17

Table: Value Labels
Variable Value,,Label
num1,1,один (in Russian)
num2,1,one
,2,two
num3,3,three
,4,four
num4,5,five
,7,seven
,8,eight
,9,nine
num5,6,six
,7,seven
,8,eight
,10,ten
str1,a,value label for `a'
str2,bc,value label for `bc'
,de,value label for `de'
str3,fgh,value label for `fgh'
,ijk,value label for `ijk'
str4,BCDE,value label for `BCDE'
,lmno,value label for `lmno'
,tuvw,value label for `tuvw'
,xyzA,value label for `xyzA'
str5,FGHI,value label for `FGHI'
,pqrs,value label for `pqrs'
,tuvw,value label for `tuvw'
,xyzA,value label for `xyzA'
str6,JKLMNO,value label for `JKLMNO'
str7,JKLMNOP,value label for `JKLMNOP'
str8,JKLMNOPQ,value label for `JKLMNOPQ'
str9ж,RSTUVWXYZ,value label for `RSTUVWXYZ'
str12,0123456789ab,value label for `0123456789ab'
,cdefghijklmn,value label for `cdefghijklmn'
str16,EFGHIJKLMNOPQRST,value label for `EFGHIJKLMNOPQRST'
,UVWXYZ0123456789,value label for `UVWXYZ0123456789' with Cyrillic letters: `фхц'
,opqrstuvwxyzABCD,value label for `opqrstuvwxyzABCD'
str17,abcdefghijklmnopq,value label for `abcdefghijklmnopq'
])
done
AT_CLEANUP

AT_SETUP([documents])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
1; dnl Nominal case size
0; dnl Not compressed
0; dnl Not weighted
1; dnl 1 case.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Machine integer info record.
7; 3; 4; 8; 1; 2; 3; -1; 1; 1; ENDIAN; 1252;

dnl Document record.
6; 5;
s80 "First line of documents";
s80 "Second line of documents";
"abb"; i8 233; " appliqu"; i8 233; " attach"; i8 233; " blas"; i8 233; " caf"; i8 233; " canap"; i8 233; " clich"; i8 233; " consomm"; i8 233;
s25 "";
s80 "";
s80 "Last line of documents";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;

dnl Data.
1.0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY DOCUMENTS.
LIST.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps])
  AT_CHECK([cat pspp.csv], [0], [dnl
Table: Documents
"First line of documents
Second line of documents
abbé appliqué attaché blasé café canapé cliché consommé

Last line of documents"

Table: Data List
num1
1
])
done
AT_CLEANUP

AT_SETUP([empty document record])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
1; dnl Nominal case size
0; dnl Not compressed
0; dnl Not weighted
1; dnl 1 case.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Machine integer info record.
7; 3; 4; 8; 1; 2; 3; -1; 1; 1; ENDIAN; 1252;

dnl Document record.
6; 0;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;

dnl Data.
1.0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
LIST.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps])
  AT_CHECK([cat pspp.csv], [0], [dnl
Table: Data List
num1
1
])
done
AT_CLEANUP

AT_SETUP([variable sets])
AT_KEYWORDS([sack synthetic system file positive set])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
10; dnl Nominal case size
0; dnl Not compressed
0; dnl Not weighted
0; dnl No cases.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Variable Set 1
2; 0; 0; 0; 0x050800 *2; i8 0x82; i8 0xa0; s6 "";
2; 0; 0; 0; 0x050800 *2; s8 "B";
2; 0; 0; 0; 0x050800 *2; s8 "C";

dnl vs2
2; 0; 0; 0; 0x050800 *2; s8 "D";
2; 0; 0; 0; 0x050800 *2; s8 "E";
2; 0; 0; 0; 0x050800 *2; s8 "F";
2; 0; 0; 0; 0x050800 *2; s8 "G";

dnl c
2; 4; 0; 0; 0x010400 *2; s8 "H";
2; 4; 0; 0; 0x010400 *2; s8 "I";
2; 4; 0; 0; 0x010400 *2; s8 "J";

dnl Machine integer info record.
7; 3; 4; 8; 1; 2; 3; -1; 1; 1; ENDIAN; 932;

7; 5; 1;
COUNT(
  "Variable Set 1= "; i8 0x82; i8 0xa0; " b c"; i8 10;
  "vs2=d e f g"; i8 10;
  "c=h i j"; i8 13; i8 10;
  "d= e g i b f"; i8 10;
  "Empty Variable Set= "; i8 10);

dnl Character encoding record.
7; 20; 1; 9; "shift_jis";

dnl Dictionary termination record.
999; 0;
])
AT_DATA([expout], [dnl
                Variables
╭────┬────────┬────────────┬────────────╮
│Name│Position│Print Format│Write Format│
├────┼────────┼────────────┼────────────┤
│あ  │       1│F8.0        │F8.0        │
│b   │       2│F8.0        │F8.0        │
│c   │       3│F8.0        │F8.0        │
│d   │       4│F8.0        │F8.0        │
│e   │       5│F8.0        │F8.0        │
│f   │       6│F8.0        │F8.0        │
│g   │       7│F8.0        │F8.0        │
│h   │       8│A4          │A4          │
│i   │       9│A4          │A4          │
│j   │      10│A4          │A4          │
╰────┴────────┴────────────┴────────────╯

            Variable Sets
╭──────────────────────────┬────────╮
│Variable Set and Position │Variable│
├──────────────────────────┼────────┤
│Variable Set 1     1      │あ      │
│                   2      │b       │
│                   3      │c       │
├──────────────────────────┼────────┤
│vs2                1      │d       │
│                   2      │e       │
│                   3      │f       │
│                   4      │g       │
├──────────────────────────┼────────┤
│c                  1      │h       │
│                   2      │i       │
│                   3      │j       │
├──────────────────────────┼────────┤
│d                  1      │e       │
│                   2      │g       │
│                   3      │i       │
│                   4      │b       │
│                   5      │f       │
├──────────────────────────┼────────┤
│Empty Variable Set n/a    │(empty) │
╰──────────────────────────┴────────╯
])
AT_DATA([sys-file-1.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY VARIABLES.
DISPLAY VARIABLE SETS.
SAVE OUTFILE='sys-file-2.sav'.
])
AT_DATA([sys-file-2.sps], [dnl
GET FILE='sys-file-2.sav'.
DISPLAY VARIABLES.
DISPLAY VARIABLE SETS.
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_CHECK([rm -f sys-file-2.sav])
  AT_CHECK([pspp --testing-mode -O box=unicode sys-file-1.sps], [0], [expout])
  AT_CHECK([pspp --testing-mode -O box=unicode sys-file-2.sps], [0], [expout])
done
AT_CLEANUP

AT_SETUP([multiple response sets])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
16; dnl Nominal case size
0; dnl Not compressed
0; dnl Not weighted
0; dnl No cases.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl $a
2; 0; 0; 0; 0x050800 *2; i8 0x82; i8 0xa0; s6 "";
2; 0; 0; 0; 0x050800 *2; s8 "B";
2; 0; 0; 0; 0x050800 *2; s8 "C";

dnl $b
2; 0; 0; 0; 0x050800 *2; s8 "D";
2; 0; 0; 0; 0x050800 *2; s8 "E";
2; 0; 0; 0; 0x050800 *2; s8 "F";
2; 0; 0; 0; 0x050800 *2; s8 "G";

dnl $c
2; 4; 0; 0; 0x010400 *2; s8 "H";
2; 4; 0; 0; 0x010400 *2; s8 "I";
2; 4; 0; 0; 0x010400 *2; s8 "J";

dnl $d
2; 0; 0; 0; 0x050800 *2; s8 "K";
2; 0; 0; 0; 0x050800 *2; s8 "L";
2; 0; 0; 0; 0x050800 *2; s8 "M";

dnl $e
2; 6; 0; 0; 0x010600 *2; s8 "N";
2; 6; 0; 0; 0x010600 *2; s8 "O";
2; 6; 0; 0; 0x010600 *2; s8 "P";

dnl Machine integer info record.
7; 3; 4; 8; 1; 2; 3; -1; 1; 1; ENDIAN; 932;

7; 7; 1;
COUNT(
  "$a=C 10 my mcgroup "; i8 0x82; i8 0xa0; " b c"; i8 10;
  "$b=D2 55 0  g e f d"; i8 10; i8 10;
  "$c=D4 "; i8 0x82; i8 0xcd; i8 0x82; i8 0xa2; " 10 mdgroup #2 h i j"; i8 10);

7; 19; 1;
COUNT(
  i8 10;
  "$d=E 1 2 34 13 third mdgroup k l m"; i8 10;
  "$e=E 11 6 choice 0  n o p"; i8 10; i8 10; i8 10; i8 10);

dnl Character encoding record.
7; 20; 1; 9; "shift_jis";

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
MRSETS /DISPLAY NAME=ALL.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps])
  AT_CHECK([cat pspp.csv], [0], [dnl
Table: Multiple Response Sets
Name,Label,Encoding,Counted Value,Member Variables
$a,my mcgroup,Categories,,"あ
b
c"
$b,,Dichotomies,55,"g
e
f
d"
$c,mdgroup #2,Dichotomies,はい,"h
i
j"
$d,third mdgroup,Dichotomies,34,"k
l
m"
$e,,Dichotomies,choice,"n
o
p"
])
done
AT_CLEANUP

dnl Also checks for handling of CR-only line ends in file label and
dnl extra product info.
AT_SETUP([extra product info])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
4; dnl Nominal case size
0; dnl Not compressed
0; dnl Not weighted
0; dnl No cases.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; "PSPP synthetic"; i8 13; s49 "test file";
i8 0 *3;

dnl Numeric variables.
2; 0; 0; 0; 0x050800 *2; s8 "A";
2; 0; 0; 0; 0x050800 *2; s8 "B";
2; 0; 0; 0; 0x050800 *2; s8 "C";
2; 0; 0; 0; 0x050800 *2; s8 "D";

dnl Extra product info.
7; 10; 1; COUNT ("Extra product info"; i8 13; "another line"; i8 13; "blah");

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;
])
for variant in be; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
SYSFILE INFO FILE='sys-file.sav'.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps])
  AT_CHECK([sed 8q pspp.csv], [0], [dnl
Table: File Information
File,sys-file.sav
Label,"PSPP synthetic
test file"
Created,01 Jan 11 20:53:52 by $(@%:@) SPSS DATA FILE PSPP synthetic test file
Product,"Extra product info
another line
blah"
])
done
AT_CLEANUP

AT_SETUP([variable display parameters, without width])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
19; dnl Nominal case size
0; dnl Not compressed
0; dnl Not weighted
0; dnl No cases.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Numeric variables.
2; 0; 0; 0; 0x050800 *2; s8 "A";
2; 0; 0; 0; 0x050800 *2; s8 "B";
2; 0; 0; 0; 0x050800 *2; s8 "C";
2; 0; 0; 0; 0x050800 *2; s8 "D";

dnl Short string variables.
2; 3; 0; 0; 0x010300 *2; s8 "H";
2; 3; 0; 0; 0x010300 *2; s8 "I";
2; 3; 0; 0; 0x010300 *2; s8 "J";
2; 3; 0; 0; 0x010300 *2; s8 "K";

dnl Long string variables.
2; 9; 0; 0; 0x010900 *2; s8 "L";
2; -1; 0; 0; 0; 0; s8 "";
2; 10; 0; 0; 0x010a00 *2; s8 "M";
2; -1; 0; 0; 0; 0; s8 "";
2; 17; 0; 0; 0x011100 *2; s8 "N";
( 2; -1; 0; 0; 0; 0; s8 "" ) * 2;
2; 25; 0; 0; 0x011900 *2; s8 "O";
( 2; -1; 0; 0; 0; 0; s8 "" ) * 3;

dnl Variable display parameters
7; 11; 4; 24;
1; 0;
2; 0;
3; 0;
1; 1;
2; 1;
3; 1;
1; 2;
2; 2;
3; 2;
0; 0;
0; 1;
0; 2;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY DICTIONARY.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps])
  AT_CHECK([cat pspp.csv], [0], [dnl
Table: Variables
Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
a,1,Nominal,Input,8,Left,F8.0,F8.0
b,2,Ordinal,Input,8,Left,F8.0,F8.0
c,3,Scale,Input,8,Left,F8.0,F8.0
d,4,Nominal,Input,8,Right,F8.0,F8.0
h,5,Ordinal,Input,3,Right,A3,A3
i,6,Scale,Input,3,Right,A3,A3
j,7,Nominal,Input,3,Center,A3,A3
k,8,Ordinal,Input,3,Center,A3,A3
l,9,Scale,Input,9,Center,A9,A9
m,10,Nominal,Input,10,Left,A10,A10
n,11,Nominal,Input,17,Right,A17,A17
o,12,Nominal,Input,25,Center,A25,A25
])
done
AT_CLEANUP

AT_SETUP([variable display parameters, with width])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
19; dnl Nominal case size
0; dnl Not compressed
0; dnl Not weighted
0; dnl No cases.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Numeric variables.
2; 0; 0; 0; 0x050800 *2; s8 "A";
2; 0; 0; 0; 0x050800 *2; s8 "B";
2; 0; 0; 0; 0x050800 *2; s8 "C";
2; 0; 0; 0; 0x050800 *2; s8 "D";

dnl Short string variables.
2; 3; 0; 0; 0x010300 *2; s8 "H";
2; 3; 0; 0; 0x010300 *2; s8 "I";
2; 3; 0; 0; 0x010300 *2; s8 "J";
2; 3; 0; 0; 0x010300 *2; s8 "K";

dnl Long string variables.
2; 9; 0; 0; 0x010900 *2; s8 "L";
2; -1; 0; 0; 0; 0; s8 "";
2; 10; 0; 0; 0x010a00 *2; s8 "M";
2; -1; 0; 0; 0; 0; s8 "";
2; 17; 0; 0; 0x011100 *2; s8 "N";
( 2; -1; 0; 0; 0; 0; s8 "" ) * 2;
2; 25; 0; 0; 0x011900 *2; s8 "O";
( 2; -1; 0; 0; 0; 0; s8 "" ) * 3;

dnl Variable display parameters
7; 11; 4; 36;
1; 1; 0;
2; 2; 0;
3; 3; 0;
1; 4; 1;
2; 5; 1;
3; 6; 1;
1; 7; 2;
2; 8; 2;
3; 9; 2;
0; 10; 0;
0; 11; 1;
0; 12; 2;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY DICTIONARY.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps])
  AT_CHECK([cat pspp.csv], [0], [dnl
Table: Variables
Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
a,1,Nominal,Input,1,Left,F8.0,F8.0
b,2,Ordinal,Input,2,Left,F8.0,F8.0
c,3,Scale,Input,3,Left,F8.0,F8.0
d,4,Nominal,Input,4,Right,F8.0,F8.0
h,5,Ordinal,Input,5,Right,A3,A3
i,6,Scale,Input,6,Right,A3,A3
j,7,Nominal,Input,7,Center,A3,A3
k,8,Ordinal,Input,8,Center,A3,A3
l,9,Scale,Input,9,Center,A9,A9
m,10,Nominal,Input,10,Left,A10,A10
n,11,Nominal,Input,11,Right,A17,A17
o,12,Nominal,Input,12,Center,A25,A25
])
done
AT_CLEANUP

AT_SETUP([long variable names])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
7; dnl Nominal case size
0; dnl Not compressed
0; dnl Not weighted
0; dnl No cases.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Numeric variables.
2; 0; 0; 0; 0x050800 *2; s8 "LONGVARI";
2; 0; 0; 0; 0x050800 *2; s8 "LONGVA_A";
2; 0; 0; 0; 0x050800 *2; s8 "LONGVA_B";
2; 0; 0; 0; 0x050800 *2; s8 "LONGVA_C";
2; 0; 0; 0; 0x050800 *2; "CO"; i8 214; "RDINA";
2; 0; 0; 0; 0x050800 *2; "CO"; i8 214; "RDI_A";
2; 0; 0; 0; 0x050800 *2; "CO"; i8 214; "RDI_B";

dnl Machine integer info record.
7; 3; 4; 8; 1; 2; 3; -1; 1; 1; ENDIAN; 1252;

dnl Machine floating-point info record.
7; 4; 8; 3; SYSMIS; HIGHEST; LOWEST;

dnl Long variable names.
7; 13; 1; COUNT (
"LONGVARI=LongVariableName1"; i8 9;
"LONGVA_A=LongVariableName2"; i8 9;
"LONGVA_B=LongVariableName3"; i8 9;
"LONGVA_C=LongVariableName4"; i8 9;
"CO"; i8 214; "RDINA=Co"; i8 246; "rdinate_X"; i8 9;
"CO"; i8 214; "RDI_A=Co"; i8 246; "rdinate_Y"; i8 9;
"CO"; i8 214; "RDI_B=Co"; i8 246; "rdinate_Z";
);

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY DICTIONARY.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps])
  AT_CHECK([cat pspp.csv], [0], [dnl
Table: Variables
Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
LongVariableName1,1,Unknown,Input,8,Right,F8.0,F8.0
LongVariableName2,2,Unknown,Input,8,Right,F8.0,F8.0
LongVariableName3,3,Unknown,Input,8,Right,F8.0,F8.0
LongVariableName4,4,Unknown,Input,8,Right,F8.0,F8.0
Coördinate_X,5,Unknown,Input,8,Right,F8.0,F8.0
Coördinate_Y,6,Unknown,Input,8,Right,F8.0,F8.0
Coördinate_Z,7,Unknown,Input,8,Right,F8.0,F8.0
])
done
AT_CLEANUP

AT_SETUP([very long strings])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
109; dnl Nominal case size
0; dnl Not compressed
0; dnl Not weighted
1; dnl No cases.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl 256-byte string.
2; 255; 0; 0; 0x01FF00 *2; "S"; i8 201; s6 "Q256";
(2; -1; 0; 0; 0; 0; s8 "") * 31;
2; 4; 0; 0; 0x010400 *2; "S"; i8 201; "Q256_1";

dnl 600-byte string.
2; 255; 0; 0; 0x01FF00 *2; s8 "STR600";
(2; -1; 0; 0; 0; 0; s8 "") * 31;
2; 255; 0; 0; 0x01FF00 *2; s8 "STR600_1";
(2; -1; 0; 0; 0; 0; s8 "") * 31;
2; 96; 0; 0; 0x016000 *2; s8 "STR600_2";
(2; -1; 0; 0; 0; 0; s8 "") * 11;

dnl Machine integer info record.
7; 3; 4; 8; 1; 2; 3; -1; 1; 1; ENDIAN; 1252;

dnl Very long string record.
7; 14; 1; COUNT (
"S"; i8 201; "Q256=00256"; i8 0; i8 9;
"STR600=00600"; i8 0; i8 9;
);

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;

dnl Data.
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#" * 4;
"abcdefgh";
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#" * 9;
"abcdefghijklmnopqrstuvwxyzABCDEF";
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY DICTIONARY.
LIST.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps])
  AT_CHECK([cat pspp.csv], [0], [dnl
Table: Variables
Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
séq256,1,Nominal,Input,32,Left,A256,A256
str600,2,Nominal,Input,32,Left,A600,A600

Table: Data List
séq256,str600
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@a,abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#abcdefghijklmnopqrstuvwxyz
])
done
AT_CLEANUP

AT_SETUP([data file and variable attributes])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
3; dnl Nominal case size
0; dnl Not compressed
0; dnl Not weighted
0; dnl 1 case.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Variables.
2; 0; 0; 0; 0x050800 *2; s8 "FIRSTVAR";
2; 0; 0; 0; 0x050800 *2; s8 "SECONDVA";
2; 0; 0; 0; 0x050800 *2; s8 "THIRDVAR";

dnl Machine integer info record.
7; 3; 4; 8; 1; 2; 3; -1; 1; 1; ENDIAN; 1252;

dnl Long variable names.
7; 13; 1; COUNT (
"FIRSTVAR=FirstVariable"; i8 9;
"SECONDVA=S"; i8 233; "condVariable"; i8 9;
"THIRDVAR=ThirdVariable"; i8 9
);

dnl Data file attributes record.
7; 17; 1; COUNT (
"Attr1('Value1'"; i8 10; "''d"; i8 233; "claration''"; i8 10; ")";
"S"; i8 233; "condAttr('123'"; i8 10; "'456'"; i8 10; ")";
);

dnl Variable attributes record.
7; 18; 1; COUNT (
"FirstVariable:";
  "ad"; i8 232; "le('23'"; i8 10; "'34'"; i8 10; ")";
  "bert('123'"; i8 10; ")";
  "$@Role('1'"; i8 10; ")";
"/S"; i8 233; "condVariable:";
  "xyzzy('quux'"; i8 10; ")";
);

dnl Another variable attributes record.
dnl Only system files written by "Stata 14.1/-savespss- 1.77 by S.Radyakin"
dnl include multiple variable attributes records.
7; 18; 1; COUNT ("ThirdVariable:fizz('buzz'"; i8 10; ")";);

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY @ATTRIBUTES.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps])
  AT_CHECK([cat pspp.csv], [0],
[[Table: Variable and Dataset Attributes
Variable and Name,,Value
(dataset),Attr1[1],Value1
,Attr1[2],'déclaration'
,SécondAttr[1],123
,SécondAttr[2],456
FirstVariable,$@Role,1
,adèle[1],23
,adèle[2],34
,bert,123
SécondVariable,xyzzy,quux
ThirdVariable,fizz,buzz
]])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY DICTIONARY.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps])
  AT_CHECK([cat pspp.csv], [0],
[[Table: Variables
Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
FirstVariable,1,Unknown,Output,8,Right,F8.0,F8.0
SécondVariable,2,Unknown,Input,8,Right,F8.0,F8.0
ThirdVariable,3,Unknown,Input,8,Right,F8.0,F8.0
]])
done
AT_CLEANUP

AT_SETUP([variable roles])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
7; dnl Nominal case size
0; dnl Not compressed
0; dnl Not weighted
0; dnl 1 case.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Variables.
2; 0; 0; 0; 0x050800 *2; s8 "I";
2; 0; 0; 0; 0x050800 *2; s8 "O";
2; 0; 0; 0; 0x050800 *2; s8 "B";
2; 0; 0; 0; 0x050800 *2; s8 "N";
2; 0; 0; 0; 0x050800 *2; s8 "P";
2; 0; 0; 0; 0x050800 *2; s8 "S";
2; 0; 0; 0; 0x050800 *2; s8 "X";

dnl Machine integer info record.
7; 3; 4; 8; 1; 2; 3; -1; 1; 1; ENDIAN; 1252;

dnl Variable attributes record.
7; 18; 1; COUNT (
"I:$@Role('0'"; i8 10; ")";
"/O:$@Role('1'"; i8 10; ")";
"/B:$@Role('2'"; i8 10; ")";
"/N:$@Role('3'"; i8 10; ")";
"/P:$@Role('4'"; i8 10; ")";
"/S:$@Role('5'"; i8 10; ")";
"/X:$@Role('6'"; i8 10; ")";
);

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY DICTIONARY.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps], [0], [dnl
warning: `sys-file.sav': Invalid role for variable x.
])
  AT_CHECK([cat pspp.csv], [0], [dnl
warning: `sys-file.sav': Invalid role for variable x.

Table: Variables
Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
i,1,Unknown,Input,8,Right,F8.0,F8.0
o,2,Unknown,Output,8,Right,F8.0,F8.0
b,3,Unknown,Both,8,Right,F8.0,F8.0
n,4,Unknown,None,8,Right,F8.0,F8.0
p,5,Unknown,Partition,8,Right,F8.0,F8.0
s,6,Unknown,Split,8,Right,F8.0,F8.0
x,7,Unknown,Input,8,Right,F8.0,F8.0
])
done
AT_CLEANUP

AT_SETUP([compressed data])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
6; dnl Nominal case size
1; dnl Simple compression
0; dnl Not weighted
-1; dnl Unspecified number of cases.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Numeric variables.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";
2; 0; 0; 0; 0x050800 *2; s8 "NUM2";

dnl String variable.
2; 4; 0; 0; 0x010400 *2; s8 "STR4";
2; 8; 0; 0; 0x010800 *2; s8 "STR8";
2; 15; 0; 0; 0x010f00 *2; s8 "STR15";
2; -1; 0; 0; 0; 0; s8 "";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;

dnl Compressed data.
i8 1 100 254 253 254 253; i8 255 251; "abcdefgh"; s8 "0123";
i8 253 253 253 254; i8 101 102 253 253; s8 "jklm"; s8 "nopqrstu";
s8 "vwxyzABC"; s8 "DEFG"; s8 "HIJKLMNO";
i8 254 253 252 0 0 0 0 0; s8 "PQRSTUVW";

])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY DICTIONARY.
LIST.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps])
  AT_CHECK([cat pspp.csv], [0], [dnl
Table: Variables
Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
num1,1,Unknown,Input,8,Right,F8.0,F8.0
num2,2,Unknown,Input,8,Right,F8.0,F8.0
str4,3,Nominal,Input,4,Left,A4,A4
str8,4,Nominal,Input,8,Left,A8,A8
str15,5,Nominal,Input,15,Left,A15,A15

Table: Data List
num1,num2,str4,str8,str15
-99,0,,abcdefgh,0123
.,151,jklm,nopqrstu,vwxyzABC
1,2,DEFG,HIJKLMNO,PQRSTUV
])
done
AT_CLEANUP

AT_SETUP([compressed data, zero bias])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
6; dnl Nominal case size
1; dnl Simple compression.
0; dnl Not weighted
-1; dnl Unspecified number of cases.
0.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Numeric variables.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";
2; 0; 0; 0; 0x050800 *2; s8 "NUM2";

dnl String variable.
2; 4; 0; 0; 0x010400 *2; s8 "STR4";
2; 8; 0; 0; 0x010800 *2; s8 "STR8";
2; 15; 0; 0; 0x010f00 *2; s8 "STR15";
2; -1; 0; 0; 0; 0; s8 "";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;

dnl Compressed data.
i8 1 100 254 253 254 253; i8 255 251; "abcdefgh"; s8 "0123";
i8 253 253 253 254; i8 101 102 253 253; s8 "jklm"; s8 "nopqrstu";
s8 "vwxyzABC"; s8 "DEFG"; s8 "HIJKLMNO";
i8 254 253 252 0 0 0 0 0; s8 "PQRSTUVW";

])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY DICTIONARY.
LIST.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps], [0])
  AT_CHECK([cat pspp.csv], [0], [dnl
Table: Variables
Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
num1,1,Unknown,Input,8,Right,F8.0,F8.0
num2,2,Unknown,Input,8,Right,F8.0,F8.0
str4,3,Nominal,Input,4,Left,A4,A4
str8,4,Nominal,Input,8,Left,A8,A8
str15,5,Nominal,Input,15,Left,A15,A15

Table: Data List
num1,num2,str4,str8,str15
1,100,,abcdefgh,0123
.,251,jklm,nopqrstu,vwxyzABC
101,102,DEFG,HIJKLMNO,PQRSTUV
])
done
AT_CLEANUP

AT_SETUP([compressed data, other bias])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
6; dnl Nominal case size
1; dnl Simple compression.
0; dnl Not weighted
-1; dnl Unspecified number of cases.
50.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Numeric variables.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";
2; 0; 0; 0; 0x050800 *2; s8 "NUM2";

dnl String variable.
2; 4; 0; 0; 0x010400 *2; s8 "STR4";
2; 8; 0; 0; 0x010800 *2; s8 "STR8";
2; 15; 0; 0; 0x010f00 *2; s8 "STR15";
2; -1; 0; 0; 0; 0; s8 "";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;

dnl Compressed data.
i8 1 100 254 253 254 253; i8 255 251; "abcdefgh"; s8 "0123";
i8 253 253 253 254; i8 101 102 253 253; s8 "jklm"; s8 "nopqrstu";
s8 "vwxyzABC"; s8 "DEFG"; s8 "HIJKLMNO";
i8 254 253 252 0 0 0 0 0; s8 "PQRSTUVW";

])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY DICTIONARY.
LIST.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps], [0],
    [warning: `sys-file.sav' near offset 0x54: Compression bias is not the usual value of 100, or system file uses unrecognized floating-point format.
])
  AT_CHECK([cat pspp.csv], [0], [dnl
"warning: `sys-file.sav' near offset 0x54: Compression bias is not the usual value of 100, or system file uses unrecognized floating-point format."

Table: Variables
Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
num1,1,Unknown,Input,8,Right,F8.0,F8.0
num2,2,Unknown,Input,8,Right,F8.0,F8.0
str4,3,Nominal,Input,4,Left,A4,A4
str8,4,Nominal,Input,8,Left,A8,A8
str15,5,Nominal,Input,15,Left,A15,A15

Table: Data List
num1,num2,str4,str8,str15
-49,50,,abcdefgh,0123
.,201,jklm,nopqrstu,vwxyzABC
51,52,DEFG,HIJKLMNO,PQRSTUV
])
done
AT_CLEANUP

m4_divert_push([PREPARE_TESTS])
zcompressed_sack () {
    cat <<'EOF'
dnl File header.
"$FL3"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
6; dnl Nominal case size
2; dnl zlib compressed
0; dnl Not weighted
-1; dnl Unspecified number of cases.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Numeric variables.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";
2; 0; 0; 0; 0x050800 *2; s8 "NUM2";

dnl String variable.
2; 4; 0; 0; 0x010400 *2; s8 "STR4";
2; 8; 0; 0; 0x010800 *2; s8 "STR8";
2; 15; 0; 0; 0x010f00 *2; s8 "STR15";
2; -1; 0; 0; 0; 0; s8 "";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;

dnl ZLIB data header.
i64 0x194;    # zheader_ofs
i64 0x205;    # ztrailer_ofs
i64 48;       # ztrailer_len

dnl ZLIB data block.
dnl
dnl This is the compressed form of:
dnl
dnl 01 64 fe fd fe fd ff fb  61 62 63 64 65 66 67 68  |.d......abcdefgh|
dnl 30 31 32 33 20 20 20 20  fd fd fd fe 65 66 fd fd  |0123    ....ef..|
dnl 6a 6b 6c 6d 20 20 20 20  6e 6f 70 71 72 73 74 75  |jklm    nopqrstu|
dnl 76 77 78 79 7a 41 42 43  44 45 46 47 20 20 20 20  |vwxyzABCDEFG    |
dnl 48 49 4a 4b 4c 4d 4e 4f  fe fd fc 00 00 00 00 00  |HIJKLMNO........|
dnl 50 51 52 53 54 55 56 57                           |PQRSTUVW|
dnl
dnl which is the data from the "compressed data" test.
hex "78 01 63 4c f9 f7 f7 df  df ff bf 13 93 92 53 52";
hex "d3 d2 33 0c 0c 8d 8c 15  80 e0 ef df bf ff 52 d3";
hex "fe fe cd ca ce c9 05 f1  f3 f2 0b 0a 8b 8a 4b 4a";
hex "cb ca 2b 2a ab 1c 9d 9c  5d 5c dd dc 41 e2 1e 9e";
hex "5e de 3e be 7e fe ff fe  fe 61 00 81 80 c0 a0 e0";
hex "90 d0 b0 70 00 0f 3f 23  d7";

dnl ZLIB data trailer fixed header:
i64 -100;     # ztrailer_bias
i64 0;        # ztrailer_zero
0x3ff000;     # block_size
1;            # n_blocks

dnl ZLIB block descriptor:
i64 0x194;    # uncompressed_ofs
i64 0x1ac;    # compressed_ofs
88;           # uncompressed_size
89;           # compressed_size
EOF
}
m4_divert_pop([PREPARE_TESTS])

AT_SETUP([zcompressed data])
AT_KEYWORDS([sack synthetic system file positive zlib])
zcompressed_sack > sys-file.sack
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY DICTIONARY.
LIST.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps])
  AT_CHECK([cat pspp.csv], [0], [dnl
Table: Variables
Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
num1,1,Unknown,Input,8,Right,F8.0,F8.0
num2,2,Unknown,Input,8,Right,F8.0,F8.0
str4,3,Nominal,Input,4,Left,A4,A4
str8,4,Nominal,Input,8,Left,A8,A8
str15,5,Nominal,Input,15,Left,A15,A15

Table: Data List
num1,num2,str4,str8,str15
-99,0,,abcdefgh,0123
.,151,jklm,nopqrstu,vwxyzABC
1,2,DEFG,HIJKLMNO,PQRSTUV
])
done
AT_CLEANUP

AT_BANNER([system file reader - negative])

AT_SETUP([no variables])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
0; dnl Nominal case size (empty)
0; dnl Not compressed
0; dnl Not weighted
0; dnl 0 cases.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1], [dnl
sys-file.sps:1: error: GET: `sys-file.sav': Data file dictionary has no variables.
])

  dnl At one point pspp-convert would hang forever if there were no variables,
  dnl so check against regression.
  AT_CHECK([pspp-convert sys-file.sav sys-file.txt])
  AT_CHECK([cat sys-file.txt], [0], [
])
done
AT_CLEANUP

AT_SETUP([unspecified character encoding])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
4; dnl Nominal case size
0; dnl Not compressed
0; dnl Not weighted
0; dnl No cases.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52";
"PSPP synthetic test file: "; i8 244; i8 245; i8 246; i8 248; s34 "";
i8 0 *3;

dnl Numeric variables.
2; 0; 0; 0; 0x050800 *2; s8 "A";
2; 0; 0; 0; 0x050800 *2; s8 "B";
2; 0; 0; 0; 0x050800 *2; s8 "C";
2; 0; 0; 0; 0x050800 *2; s8 "D";

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET 'sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [stdout])
  AT_CHECK([sed 's/default encoding.*For/default encoding.  For/' stdout], [0], [dnl
"warning: `sys-file.sav': This system file does not indicate its own character encoding.  Using default encoding.  For best results, specify an encoding explicitly.  Use SYSFILE INFO with ENCODING=""DETECT"" to analyze the possible encodings."
])
done
AT_CLEANUP

AT_SETUP([misplaced type 4 record])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Type 4 record.
>>4<<;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1],
   [error: `sys-file.sav' near offset 0xd4: Misplaced type 4 record.
])
done
AT_CLEANUP

AT_SETUP([bad record type])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Type 8 record (not a valid type).
>>8<<;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1],
   [error: `sys-file.sav' near offset 0xd4: Unrecognized record type 8.
])
done
AT_CLEANUP

AT_SETUP([wrong number of variable positions])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; >>2<<; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0],
   [warning: `sys-file.sav': File header claims 2 variable positions but 1 were read from file.
])
done
AT_CLEANUP

AT_SETUP([variable name may not begin with `#'])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable.
2; 0; 0; 0; 0x050800 *2; s8 >>"$UM1"<<;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], 0,
   [warning: `sys-file.sav' near offset 0xb4: Renaming variable with invalid or duplicate name `$UM1' to `UM1'.
])
done
AT_CLEANUP

AT_SETUP([variable name may not be reserved word])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable.
2; 0; 0; 0; 0x050800 *2; s8 >>"TO"<<;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], 0,
   [warning: `sys-file.sav' near offset 0xb4: Renaming variable with invalid or duplicate name `TO' to `TO_A'.
])
done
AT_CLEANUP

AT_SETUP([variable width must be between 0 and 255])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl String variable with invalid width 256.
2; 256; 0; 0; 0x050800 *2; s8 "VAR1";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1],
   [error: `sys-file.sav' near offset 0xb4: Bad width 256 for variable VAR1.
])
done
AT_CLEANUP

dnl SPSS-generated system file can contain duplicate variable names
dnl (see bug #41475).
AT_SETUP([duplicate variable name])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variables.
2; 0; 0; 0; 0x050800 *2; s8 "VAR1";
2; 0; 0; 0; 0x050800 *2; s8 "VAR1";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
DISPLAY DICTIONARY.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0],
   [warning: `sys-file.sav' near offset 0xd4: Renaming variable with invalid or duplicate name `VAR1' to `VAR1_A'.

Table: Variables
Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
var1,1,Unknown,Input,8,Right,F8.0,F8.0
var1_a,2,Unknown,Input,8,Right,F8.0,F8.0
])
done
AT_CLEANUP

AT_SETUP([variable label indicator not 0 or 1])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable.
2; 0; >>2<<; 0; 0x050800 *2; s8 "VAR1";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1],
   [error: `sys-file.sav' near offset 0xb4: Variable label indicator field is not 0 or 1.
])
done
AT_CLEANUP

AT_SETUP([invalid numeric missing value indicator])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable.
2; 0; 0; >>-1<<; 0x050800 *2; s8 "VAR1";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1],
   ["error: `sys-file.sav' near offset 0xb4: Numeric missing value indicator field is not -3, -2, 0, 1, 2, or 3."
])
done
AT_CLEANUP

AT_SETUP([invalid string missing value indicator])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl String variable.
2; 8; 0; >>4<<; 0x010800 *2; s8 "VAR1";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1],
   ["error: `sys-file.sav' near offset 0xb4: String missing value indicator field is not 0, 1, 2, or 3."
])
done
AT_CLEANUP

AT_SETUP([missing string continuation record])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl String variable.
2; 10; 0; 0; 0x010a00 *2; s8 "VAR1";
>>2; 0; 0; 0; 0x050800 *2; s8 "VAR2";<<

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1],
   [error: `sys-file.sav' near offset 0xb4: Missing string continuation record.
])
done
AT_CLEANUP

AT_SETUP([invalid variable format])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 4; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, invalid format types.
dnl No warning is issued for type 0 because it has been observed in real
dnl system files.
2; 0; 0; 0; >>0xff0800; 0<<; s8 "NUM1";

dnl Numeric variable, string formats.
2; 0; 0; 0; >>0x010800<<; >>0x021000<<; s8 "VAR1";

dnl String variable, numeric formats.
2; 4; 0; 0; >>0x050800<<; >>0x110a01<<; s8 "STR1";

dnl String variable, wrong width formats.
2; 4; 0; 0; >>0x010800<<; >>0x020400<<; s8 "STR2";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0xc0: Variable NUM1 with width 0 has invalid print format 0xff0800.

warning: `sys-file.sav' near offset 0xe0: Variable VAR1 with width 0 has invalid print format 0x10800.

warning: `sys-file.sav' near offset 0xe4: Variable VAR1 with width 0 has invalid write format 0x21000.

warning: `sys-file.sav' near offset 0x100: Variable STR1 with width 4 has invalid print format 0x50800.

warning: `sys-file.sav' near offset 0x104: Variable STR1 with width 4 has invalid write format 0x110a01.

warning: `sys-file.sav' near offset 0x120: Variable STR2 with width 4 has invalid print format 0x10800.

warning: `sys-file.sav' near offset 0x124: Variable STR2 with width 4 has invalid write format 0x20400.
])
done
AT_CLEANUP

AT_SETUP([invalid long string missing values])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
7; dnl Nominal case size
0; dnl Not compressed
0; dnl Not weighted
1; dnl 1 case.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52";
"PSPP synthetic test file: "; i8 244; i8 245; i8 246; i8 248; s34 "";
i8 0 *3;

dnl One numeric variable.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Long string variables that will have missing values added with a
dnl later record.
2; 9; 0; 0; 0x010900 *2; s8 "STR1";
2; -1; 0; 0; 0; 0; s8 "";
2; 10; 0; 0; 0x010a00 *2; s8 "STR2";
2; -1; 0; 0; 0; 0; s8 "";
2; 11; 0; 0; 0x010b00 *2; s8 "STR3";
2; -1; 0; 0; 0; 0; s8 "";

dnl Machine integer info record.
7; 3; 4; 8; 1; 2; 3; -1; 1; 1; ENDIAN; 1252;

dnl Machine floating-point info record.
7; 4; 8; 3; SYSMIS; HIGHEST; LOWEST;

dnl Long string variable missing values record.
7; 22; 1; COUNT (
dnl Zero missing values (not allowed) for STR1 .
COUNT("STR1"); i8 >>0<<; 8;

dnl Four missing values (not allowed) for STR2.
COUNT("STR2"); i8 4; 8;
"abcdefgh"; "ijklmnop"; "qrstuvwx"; "yz012345";

dnl Missing values for unknown variable
COUNT(>>"Nonexistent"<<); i8 1; 8; "abcdefgh";

dnl Missing values for numeric variable
COUNT(>>"NUM1"<<); i8 1; 8; "abcdefgh";

dnl Too long missing value
COUNT("STR3"); i8 1; >>COUNT("abcdefghijkl")<<;

dnl Buggy way that this was written in old PSPP, with a length
dnl before each missing value instead of just once.
COUNT("STR3"); i8 2; 8; "ABCDEFGH"; >>8<<; "IJKLMNOP";
);

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;
s8 "abcd"; s8 "efgh"; s8 "ijkl"; s8 "mnop"; s8 "qrst"; s8 "uvwx";
s16 "yzABCDEFGHI"; s16 "JKLMNOPQR"; s16 "STUVWXYZ01";
s16 "23456789abc"; s32 "defghijklmnopqstuvwxyzABC";
])

for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY DICTIONARY.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0],
   ["warning: `sys-file.sav' near offset 0x1f8: Long string missing values record says variable STR1 has 0 missing values, but only 1 to 3 missing values are allowed."

"warning: `sys-file.sav' near offset 0x205: Long string missing values record says variable STR2 has 4 missing values, but only 1 to 3 missing values are allowed."

warning: `sys-file.sav' near offset 0x23a: Ignoring long string missing value record for unknown variable Nonexistent.

warning: `sys-file.sav' near offset 0x24f: Ignoring long string missing value record for numeric variable NUM1.

"warning: `sys-file.sav' near offset 0x268: Ignoring long string missing value 0 for variable str3, with width 11, that has bad value width 12."

"warning: `sys-file.sav' near offset 0x289: This file has corrupted metadata written by a buggy version of PSPP.  To fix it, save a new copy of the file."

Table: Variables
Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format,Missing Values
num1,1,Unknown,Input,8,Right,F8.0,F8.0,
str1,2,Nominal,Input,9,Left,A9,A9,
str2,3,Nominal,Input,10,Left,A10,A10,"""abcdefgh""; ""ijklmnop""; ""qrstuvwx"""
str3,4,Nominal,Input,11,Left,A11,A11,"""ABCDEFGH""; ""IJKLMNOP"""
])
done
AT_CLEANUP

AT_SETUP([weighting variable must be numeric])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 1; >>2<<; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl String variable.
2; 4; 0; 0; 0x010400 *2; s8 "STR1";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
DISPLAY DICTIONARY.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0],
   [warning: `sys-file.sav' near offset 0x4c: Ignoring string variable `STR1' set as weighting variable.

Table: Variables
Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
num1,1,Unknown,Input,8,Right,F8.0,F8.0
str1,2,Nominal,Input,4,Left,A4,A4
])
done
AT_CLEANUP

AT_SETUP([bad weighting variable index])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 1; >>3<<; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl String variable.
2; 4; 0; 0; 0x010400 *2; s8 "STR1";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], 0,
   [warning: `sys-file.sav' near offset 0x4c: Weight variable index 3 not in valid range 1...2.  Treating file as unweighted.
])
done
AT_CLEANUP

AT_SETUP([variable index is long string continuation])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 3; 1; >>3<<; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Long string variable.
2; 9; 0; 0; 0x010900 *2; s8 "STR1";
(2; -1; 0; 0; 0; 0; s8 "");

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], 0,
   [warning: `sys-file.sav' near offset 0x4c: Weight variable index 3 refers to long string continuation.  Treating file as unweighted.
])
done
AT_CLEANUP

AT_SETUP([multiple documents records])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variables, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";
2; 0; 0; 0; 0x050800 *2; s8 "NUM2";

dnl Two document records.
(6; 1; s80 "One line of documents") >>* 2<<;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;

dnl Data.
1.0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], 0, [dnl
warning: `sys-file.sav' near offset 0x14c: Duplicate type 6 (document) record.
])
done
AT_CLEANUP


AT_SETUP([extension record too large])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Too-large extension record.
7; 3; >>0xfffff000 * 2<<;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1], [dnl
error: `sys-file.sav' near offset 0xd8: Record type 7 subtype 3 too large.
])
done
AT_CLEANUP

AT_SETUP([unknown extension record])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Unknown extension record type.
7; 30; 1; 1; i8 0;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK_UNQUOTED([pspp -O format=csv sys-file.sps], [0], [dnl
"warning: \`sys-file.sav' near offset 0xd8: Unrecognized record type 7, subtype 30.  For help, please send this file to ${PACKAGE_BUGREPORT} and mention that you were using ${PACKAGE_STRING}."
])
done
AT_CLEANUP

AT_SETUP([bad machine integer info size])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Machine integer info record.
7; 3; 4; >>9<<; 1; 2; 3; -1; 1; 1; ENDIAN; 1252; >>1234<<;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
"warning: `sys-file.sav' near offset 0xd8: Record type 7, subtype 3 has bad count 9 (expected 8)."
])
done
AT_CLEANUP

AT_SETUP([bad machine integer info float format])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Machine integer info record.
7; 3; 4; 8; 1; 2; 3; -1; >>2<<; 1; ENDIAN; 1252;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1], [dnl
error: `sys-file.sav' near offset 0xd8: Floating-point representation indicated by system file (2) differs from expected (1).
])
done
AT_CLEANUP

AT_SETUP([bad machine integer info endianness])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Machine integer info record.
7; 3; 4; 8; 1; 2; 3; -1; 1; 1; >>3<<; 1252;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in "be 1" "le 2"; do
  set $variant
  AT_CHECK([sack --$[1] sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY DICTIONARY.
])
  AT_CHECK_UNQUOTED([pspp -O format=csv sys-file.sps], [0], [dnl
warning: \`sys-file.sav' near offset 0xd8: Integer format indicated by system file (3) differs from expected ($[2]).

Table: Variables
Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
num1,1,Unknown,Input,8,Right,F8.0,F8.0
])
done
AT_CLEANUP


AT_SETUP([bad machine floating-point info size])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Machine floating-point info record.
7; 4; 8; >>4<<; SYSMIS; HIGHEST; LOWEST; 0.0;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
"warning: `sys-file.sav' near offset 0xd8: Record type 7, subtype 4 has bad count 4 (expected 3)."
])
done
AT_CLEANUP

AT_SETUP([wrong special floating point values])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Machine floating-point info record.
7; 4; 8; 3; >>0.0<<; >>1.0<<; >>2.0<<;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps | sed 's/ [(].*/.../'], [0], [dnl
"warning: `sys-file.sav' near offset 0xd8: File specifies unexpected value 0...

"warning: `sys-file.sav' near offset 0xd8: File specifies unexpected value 1...

"warning: `sys-file.sav' near offset 0xd8: File specifies unexpected value 2...
])
done
AT_CLEANUP

AT_SETUP([unknown variables in variable sets])
AT_KEYWORDS([sack synthetic system file negative set])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
10; dnl Nominal case size
0; dnl Not compressed
0; dnl Not weighted
0; dnl No cases.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Variable Set 1
2; 0; 0; 0; 0x050800 *2; i8 0x82; i8 0xa0; s6 "";
2; 0; 0; 0; 0x050800 *2; s8 "B";
2; 0; 0; 0; 0x050800 *2; s8 "C";

dnl vs2
2; 0; 0; 0; 0x050800 *2; s8 "D";
2; 0; 0; 0; 0x050800 *2; s8 "E";
2; 0; 0; 0; 0x050800 *2; s8 "F";
2; 0; 0; 0; 0x050800 *2; s8 "G";

dnl c
2; 4; 0; 0; 0x010400 *2; s8 "H";
2; 4; 0; 0; 0x010400 *2; s8 "I";
2; 4; 0; 0; 0x010400 *2; s8 "J";

dnl Machine integer info record.
7; 3; 4; 8; 1; 2; 3; -1; 1; 1; ENDIAN; 932;

7; 5; 1;
COUNT(
  "Variable Set 1= "; i8 0x82; i8 0xa0; " "; >>"xyzzy"<<; " b c"; i8 10;
  "vs2=d "; >>"foo"<<; " e f g"; i8 10;);

dnl Character encoding record.
7; 20; 1; 9; "shift_jis";

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
DISPLAY VARIABLES.
DISPLAY VARIABLE SETS.
])
  AT_CHECK([pspp --testing-mode -O box=unicode sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0x228: Variable set Variable Set 1 contains
unknown variable xyzzy.

warning: `sys-file.sav' near offset 0x228: Variable set vs2 contains unknown
variable foo.

                Variables
╭────┬────────┬────────────┬────────────╮
│Name│Position│Print Format│Write Format│
├────┼────────┼────────────┼────────────┤
│あ  │       1│F8.0        │F8.0        │
│b   │       2│F8.0        │F8.0        │
│c   │       3│F8.0        │F8.0        │
│d   │       4│F8.0        │F8.0        │
│e   │       5│F8.0        │F8.0        │
│f   │       6│F8.0        │F8.0        │
│g   │       7│F8.0        │F8.0        │
│h   │       8│A4          │A4          │
│i   │       9│A4          │A4          │
│j   │      10│A4          │A4          │
╰────┴────────┴────────────┴────────────╯

            Variable Sets
╭──────────────────────────┬────────╮
│Variable Set and Position │Variable│
├──────────────────────────┼────────┤
│Variable Set 1     1      │あ      │
│                   2      │b       │
│                   3      │c       │
├──────────────────────────┼────────┤
│vs2                1      │d       │
│                   2      │e       │
│                   3      │f       │
│                   4      │g       │
╰──────────────────────────┴────────╯
])
done
AT_CLEANUP

AT_SETUP([bad mrsets name])
AT_KEYWORDS([sack synthetic system file negative multiple response])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
16; dnl Nominal case size
0; dnl Not compressed
0; dnl Not weighted
0; dnl No cases.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl $a
2; 0; 0; 0; 0x050800 *2; i8 0x82; i8 0xa0; s6 "";
2; 0; 0; 0; 0x050800 *2; s8 "B";
2; 0; 0; 0; 0x050800 *2; s8 "C";

dnl $b
2; 0; 0; 0; 0x050800 *2; s8 "D";
2; 0; 0; 0; 0x050800 *2; s8 "E";
2; 0; 0; 0; 0x050800 *2; s8 "F";
2; 0; 0; 0; 0x050800 *2; s8 "G";

dnl $c
2; 4; 0; 0; 0x010400 *2; s8 "H";
2; 4; 0; 0; 0x010400 *2; s8 "I";
2; 4; 0; 0; 0x010400 *2; s8 "J";

dnl $d
2; 0; 0; 0; 0x050800 *2; s8 "K";
2; 0; 0; 0; 0x050800 *2; s8 "L";
2; 0; 0; 0; 0x050800 *2; s8 "M";

dnl $e
2; 6; 0; 0; 0x010600 *2; s8 "N";
2; 6; 0; 0; 0x010600 *2; s8 "O";
2; 6; 0; 0; 0x010600 *2; s8 "P";

dnl Machine integer info record.
7; 3; 4; 8; 1; 2; 3; -1; 1; 1; ENDIAN; 932;

7; 7; 1;
COUNT(
  "$a=C 10 my mcgroup "; i8 0x82; i8 0xa0; " b c"; i8 10;
  "b=D2 55 0  g e f d"; i8 10;
  "$c=D4 "; i8 0x82; i8 0xcd; i8 0x82; i8 0xa2; " 10 mdgroup #2 h i j"; i8 10);

7; 19; 1;
COUNT(
  "$d=E 1 2 34 13 third mdgroup k l m"; i8 10;
  "e=E 11 6 choice 0  n o p"; i8 10);

dnl Character encoding record.
7; 20; 1; 9; "shift_jis";

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
MRSETS /DISPLAY NAME=ALL.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav': Invalid multiple response set name `b'.

warning: `sys-file.sav': Invalid multiple response set name `e'.

Table: Multiple Response Sets
Name,Label,Encoding,Counted Value,Member Variables
$a,my mcgroup,Categories,,"あ
b
c"
$c,mdgroup #2,Dichotomies,はい,"h
i
j"
$d,third mdgroup,Dichotomies,34,"k
l
m"
])
done
AT_CLEANUP

AT_SETUP([missing space after C in mrsets])
AT_KEYWORDS([sack synthetic system file negative multiple response])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Multiple response sets.
7; 7; 1; COUNT("$a=Cx");

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0xd8: Missing space following `C' at offset 4 in MRSETS record.
])
done
AT_CLEANUP

AT_SETUP([missing space after E in mrsets])
AT_KEYWORDS([sack synthetic system file negative multiple response])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Multiple response sets.
7; 7; 1; COUNT("$a=Ex");

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0xd8: Missing space following `E' at offset 4 in MRSETS record.
])
done
AT_CLEANUP

AT_SETUP([missing label source in mrsets])
AT_KEYWORDS([sack synthetic system file negative multiple response])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Multiple response sets.
7; 7; 1; COUNT("$a=E ");

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0xd8: Missing label source value following `E' at offset 5 in MRSETS record.

warning: `sys-file.sav' near offset 0xd8: Expecting digit at offset 5 in MRSETS record.
])
done
AT_CLEANUP

AT_SETUP([unexpected label source in mrsets])
AT_KEYWORDS([sack synthetic system file negative multiple response])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Multiple response sets.
7; 7; 1; COUNT("$a=E 2");

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0xd8: Unexpected label source value following `E' at offset 7 in MRSETS record.

warning: `sys-file.sav' near offset 0xd8: Expecting digit at offset 7 in MRSETS record.
])
done
AT_CLEANUP

AT_SETUP([bad type character in mrsets])
AT_KEYWORDS([sack synthetic system file negative multiple response])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Multiple response sets.
7; 7; 1; COUNT("$a=");

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
"warning: `sys-file.sav' near offset 0xd8: Missing `C', `D', or `E' at offset 3 in MRSETS record."
])
done
AT_CLEANUP

AT_SETUP([bad counted string length in mrsets])
AT_KEYWORDS([sack synthetic system file negative multiple response])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Multiple response sets.
7; 7; 1; COUNT("$a=Dx");

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0xd8: Expecting digit at offset 4 in MRSETS record.
])
done
AT_CLEANUP

AT_SETUP([missing space in counted string in mrsets])
AT_KEYWORDS([sack synthetic system file negative multiple response])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Multiple response sets.
7; 7; 1; COUNT("$a=D1x");

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0xd8: Expecting space at offset 5 in MRSETS record.
])
done
AT_CLEANUP

AT_SETUP([counted string too long in mrsets])
AT_KEYWORDS([sack synthetic system file negative multiple response])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Multiple response sets.
7; 7; 1; COUNT("$a=D4 abc");

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0xd8: 4-byte string starting at offset 6 exceeds record length 9.
])
done
AT_CLEANUP

AT_SETUP([missing space after counted string in mrsets])
AT_KEYWORDS([sack synthetic system file negative multiple response])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Multiple response sets.
7; 7; 1; COUNT("$a=D3 abcx");

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0xd8: Expecting space at offset 9 following 3-byte string.
])
done
AT_CLEANUP

AT_SETUP([missing newline after variable name in mrsets])
AT_KEYWORDS([sack synthetic system file negative multiple response])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Multiple response sets.
7; 7; 1; COUNT("$a=C 0  NUM1");

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0xd8: Missing new-line parsing variable names at offset 13 in MRSETS record.

warning: `sys-file.sav': MRSET $a has only one variable.
])
done
AT_CLEANUP

AT_SETUP([duplicate variable name in mrsets])
AT_KEYWORDS([sack synthetic system file negative multiple response])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Multiple response sets.
7; 7; 1; COUNT("$a=C 0  NUM1 NUM1"; i8 10);

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav': MRSET $a contains duplicate variable name NUM1.

warning: `sys-file.sav': MRSET $a has only one variable.
])
done
AT_CLEANUP

AT_SETUP([mixed variable types in mrsets])
AT_KEYWORDS([sack synthetic system file negative multiple response])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Variables.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";
2; 8; 0; 0; 0x010800 *2; s8 "STR1";

dnl Multiple response sets.
7; 7; 1; COUNT("$a=C 0  NUM1 STR1"; i8 10);

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav': MRSET $a contains both string and numeric variables.

warning: `sys-file.sav': MRSET $a has only one variable.
])
done
AT_CLEANUP

AT_SETUP([missing newline after variable name in mrsets])
AT_KEYWORDS([sack synthetic system file negative multiple response])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Multiple response sets.
7; 7; 1; COUNT("$a=C 0  NUM1"; i8 10);

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav': MRSET $a has only one variable.
])
done
AT_CLEANUP

AT_SETUP([zero or one variable in mrset])
AT_KEYWORDS([sack synthetic system file negative multiple response])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Multiple response sets.
7; 7; 1; COUNT("$a=C 0  NUM1"; i8 10; "$b=C 0  "; i8 10);

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav': MRSET $a has only one variable.

warning: `sys-file.sav': MRSET $b has no variables.
])
done
AT_CLEANUP

AT_SETUP([wrong display parameter size])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Display parameters record.
7; 11; >>8<<; 2; 1.0; 1.0;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
"warning: `sys-file.sav' near offset 0xd8: Record type 7, subtype 11 has bad size 8 (expected 4)."
])
done
AT_CLEANUP

AT_SETUP([wrong display parameter count])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Display parameters record.
7; 11; 4; >>4<<; 1; 1; 2; 2;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0xd8: Extension 11 has bad count 4 (for 1 variables).
])
done
AT_CLEANUP

AT_SETUP([wrong display measurement level])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Display parameters record.
7; 11; 4; 2; >>4<<; 0;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0xd8: Invalid variable display parameters for variable 0 (NUM1).  Default parameters substituted.
])
done
AT_CLEANUP

AT_SETUP([wrong display alignment])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable, no label or missing values.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Display parameters record.
7; 11; 4; 2; 1; >>-1<<;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0xd8: Invalid variable display parameters for variable 0 (NUM1).  Default parameters substituted.
])
done
AT_CLEANUP

AT_SETUP([bad variable name in variable/value pair])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variables.
2; 0; 0; 0; 0x050800 *2; s8 "LONGVARI";

dnl Long variable names.
7; 13; 1; COUNT (>>"xyzzy"<<);

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0xde: Dictionary record refers to unknown variable xyzzy.
])
done
AT_CLEANUP

AT_SETUP([duplicate long variable name])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 4; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variables.
2; 0; 0; 0; 0x050800 *2; s8 "LONGVARI";
2; 0; 0; 0; 0x050800 *2; s8 "LONGVA_A";
2; 0; 0; 0; 0x050800 *2; s8 "LONGVA_B";
2; 0; 0; 0; 0x050800 *2; s8 "LONGVA_C";

dnl Long variable names.
7; 13; 1; COUNT (
"LONGVARI=_Invalid"; i8 9;
"LONGVARI=$Invalid"; i8 9;
"LONGVARI=#Invalid"; i8 9;
"LONGVA_A=LongVariableName"; i8 9;
"LONGVA_B=LONGVARIABLENAME"; i8 9;
);

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0x138: Long variable mapping from LONGVARI to invalid variable name `_Invalid'.

warning: `sys-file.sav' near offset 0x138: Long variable mapping from LONGVARI to invalid variable name `$Invalid'.

warning: `sys-file.sav' near offset 0x138: Long variable mapping from LONGVARI to invalid variable name `#Invalid'.

warning: `sys-file.sav' near offset 0x138: Duplicate long variable name `LONGVARIABLENAME'.
])
done
AT_CLEANUP

AT_SETUP([bad very long string length])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Very long string map.
7; 14; 1; COUNT (
"NUM1=00000"; i8 0; i8 9;
"NUM1=00255"; i8 0; i8 9;
"NUM1=00256"; i8 0; i8 9;
);

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1], [dnl
warning: `sys-file.sav' near offset 0xd8: NUM1 listed as string of invalid length 00000 in very long string record.

"warning: `sys-file.sav' near offset 0xd8: NUM1 listed in very long string record with width 00255, which requires only one segment."

error: `sys-file.sav' near offset 0xd8: Very long string NUM1 overflows dictionary.
])
done
AT_CLEANUP

AT_SETUP([bad very long string segment width])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Variables.
2; 255; 0; 0; 0x01ff00 *2; s8 "STR1";
(2; -1; 0; 0; 0; 0; s8 "") * 31;
2; >>9<<; 0; 0; 0x010900 *2; s8 "STR1_A";
>>2; -1; 0; 0; 0; 0; s8 "";<<

dnl Very long string map.
7; 14; 1; COUNT (
"STR1=00256"; i8 0; i8 9;
);

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1], [dnl
error: `sys-file.sav' near offset 0x4f8: Very long string with width 256 has segment 1 of width 9 (expected 4).
])
done
AT_CLEANUP

AT_SETUP([too many value labels])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";
3; >>0x7fffffff<<;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1], [dnl
error: `sys-file.sav' near offset 0xd4: Invalid number of labels 2147483647.
])
done
AT_CLEANUP

AT_SETUP([missing type 4 record])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Value label with missing type 4 record.
3; 1; 1.0; i8 3; s7 "one";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
>>999; 0<<;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1], [dnl
error: `sys-file.sav' near offset 0xe8: Variable index record (type 4) does not immediately follow value label record (type 3) as it should.
])
done
AT_CLEANUP

AT_SETUP([value label with no associated variables])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variable.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Value label with no variables.
3; 1; 1.0; i8 3; s7 "one"; 4; >>0<<;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1], [dnl
error: `sys-file.sav' near offset 0xec: Number of variables associated with a value label (0) is not between 1 and the number of variables (1).
])
done
AT_CLEANUP

AT_SETUP([type 4 record names long string variable])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Long string variable.
2; 9; 0; 0; 0x010900 *2; s8 "STR1";
2; -1; 0; 0; 0; 0; s8 "";

dnl Value label that names long string variable.
3; 1; s8 "xyzzy"; i8 3; s7 "one"; 4; 1; >>1<<;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], 0, [dnl
warning: `sys-file.sav' near offset 0xf4: Value labels may not be added to long string variables (e.g. STR1) using records types 3 and 4.
])
done
AT_CLEANUP

AT_SETUP([value label variable indexes must be in correct range])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Variables.
2; 6; 0; 0; 0x010600 *2; s8 "STR1";
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Value labels with bad variable indexes.
3; 1; s8 "xyzzy"; i8 3; s7 "one"; 4; 2; >>3; 4;<<
3; 1; s8 "xyzzy"; i8 3; s7 "one"; 4; 2; >>5; 6;<<
3; 1; s8 "xyzzy"; i8 3; s7 "one"; 4; 2; >>7; 8;<<

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], 0, [dnl
warning: `sys-file.sav' near offset 0xf4: Value label variable index 3 not in valid range 1...2.

warning: `sys-file.sav' near offset 0xf4: Value label variable index 4 not in valid range 1...2.

warning: `sys-file.sav' near offset 0x11c: Value label variable index 5 not in valid range 1...2.

warning: `sys-file.sav' near offset 0x11c: Value label variable index 6 not in valid range 1...2.

warning: `sys-file.sav' near offset 0x144: Value label variable index 7 not in valid range 1...2.

warning: `sys-file.sav': Suppressed 1 additional warnings for value labels.
])
done
AT_CLEANUP

AT_SETUP([value label variable indexes must not be long string continuation])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Long string variable.
2; 9; 0; 0; 0x010900 *2; s8 "STR1";
(2; -1; 0; 0; 0; 0; s8 "");

dnl Value label with long string indexes.
3; 1; s8 "xyzzy"; i8 3; s7 "one"; 4; 1; >>2;<<

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], 0, [dnl
warning: `sys-file.sav' near offset 0xf4: Value label variable index 2 refers to long string continuation.
])
done
AT_CLEANUP

AT_SETUP([variables for value label must all be same type])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Variables.
2; 6; 0; 0; 0x010600 *2; s8 "STR1";
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Value label that names numeric and string variables.
3; 1; s8 "xyzzy"; i8 3; s7 "one"; 4; 2; >>1; 2<<;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], 0, [dnl
"warning: `sys-file.sav' near offset 0xf4: Variables associated with value label are not all of identical type.  Variable STR1 is string, but variable NUM1 is numeric."
])
done
AT_CLEANUP

AT_SETUP([duplicate value labels type])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Variables.
2; 6; 0; 0; 0x010600 *2; s8 "STR1";
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";

dnl Duplicate value labels.
3; 1; s8 "xyzzy"; i8 3; s7 "one"; 4; 2; >>1; 1<<;
3; 1; 1.0; i8 3; s7 "one"; 4; 2; >>2; 2<<;

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl End of dictionary.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0xf4: Duplicate value label for `xyzzy ' on STR1.

warning: `sys-file.sav' near offset 0x11c: Duplicate value label for 1 on NUM1.
])
done
AT_CLEANUP

AT_SETUP([missing attribute value])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Variables.
2; 0; 0; 0; 0x050800 *2; s8 "FIRSTVAR";

dnl Data file attributes record.
7; 17; 1; COUNT (
"Attr1("
);

dnl Variable attributes record.
7; 18; 1; COUNT (
"FIRSTVAR:";
  "fred('23'"; i8 10
);

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0xde: Error parsing attribute value Attr1[[1]].

warning: `sys-file.sav' near offset 0x101: Error parsing attribute value fred[[2]].
])
done
AT_CLEANUP

AT_SETUP([unquoted attribute value])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Variables.
2; 0; 0; 0; 0x050800 *2; s8 "FIRSTVAR";

dnl Data file attributes record.
7; 17; 1; COUNT (
"Attr1(value"; i8 10;
")"
);

dnl Variable attributes record.
7; 18; 1; COUNT (
"FIRSTVAR:";
  "fred(23"; i8 10; ")"
);

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0xe4: Attribute value Attr1[[1]] is not quoted: value.

warning: `sys-file.sav' near offset 0x106: Attribute value fred[[1]] is not quoted: 23.
])
done
AT_CLEANUP

AT_SETUP([duplicate attribute name])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 1; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Variables.
2; 0; 0; 0; 0x050800 *2; s8 "FIRSTVAR";

dnl Data file attributes record.
7; 17; 1; COUNT (
"Attr1('value'"; i8 10; ")";
"Attr1('value'"; i8 10; ")";
);

dnl Variable attributes record.
7; 18; 1; COUNT (
"FIRSTVAR:";
  "fred('23'"; i8 10; ")";
  "fred('23'"; i8 10; ")";
);

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [dnl
GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0xf6: Duplicate attribute Attr1.

warning: `sys-file.sav' near offset 0x125: Duplicate attribute fred.
])
done
AT_CLEANUP

AT_SETUP([bad variable name in long string value label])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 3; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Variables.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";
2; 14; 0; 0; 0x010e00 *2; s8 "STR14";
2; -1; 0; 0; 0; 0; s8 "";

7; 21; 1; COUNT (
dnl No variable named STR9.
COUNT(>>"STR9"<<); 9;
1; COUNT("RSTUVWXYZ"); COUNT("value label for `RSTUVWXYZ'");

dnl NUM1 is numeric.
COUNT(>>"NUM1"<<); 0;
1; COUNT("xyz"); COUNT("value label for 1.0");

dnl Wrong width for STR14.
COUNT("STR14"); >>9<<;
1; COUNT("RSTUVWXYZ"); COUNT("value label for `RSTUVWXYZ'");

dnl Wrong width for value.
COUNT("STR14"); 14;
1; COUNT(>>"RSTUVWXYZ"<<); COUNT("value label for `RSTUVWXYZ'");

dnl Duplicate value label.
COUNT("STR14"); 14; 2;
COUNT("abcdefghijklmn"); COUNT("value label for `abcdefghijklmn'");
>>COUNT("abcdefghijklmn"); COUNT("another value label for `abcdefghijklmn'")<<;
);

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [0], [dnl
warning: `sys-file.sav' near offset 0x128: Ignoring long string value label record for unknown variable STR9.

warning: `sys-file.sav' near offset 0x164: Ignoring long string value label record for numeric variable NUM1.

warning: `sys-file.sav' near offset 0x193: Ignoring long string value label record for variable STR14 because the record's width (9) does not match the variable's width (14).

"warning: `sys-file.sav' near offset 0x1d4: Ignoring long string value label 0 for variable str14, with width 14, that has bad value width 9."

warning: `sys-file.sav' near offset 0x259: Duplicate value label for `abcdefghijklmn' on str14.
])
done
AT_CLEANUP

AT_SETUP([fewer data records than indicated by file header])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 0; 0; >>5<<; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variables.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";
2; 0; 0; 0; 0x050800 *2; s8 "NUM2";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Data.
999; 0;
1.0; 2.0;
3.0; 4.0;
5.0; 6.0;
7.0; 8.0;
dnl Missing record here.
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
LIST.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1],
   [error: Error reading case from file `sys-file.sav'.

Table: Data List
num1,num2
1,2
3,4
5,6
7,8
])
done
AT_CLEANUP

AT_SETUP([partial data record between variables])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 0; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variables.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";
2; 0; 0; 0; 0x050800 *2; s8 "NUM2";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Data.
999; 0;
1.0; 2.0;
3.0;
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
LIST.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1],
   [error: `sys-file.sav' near offset 0x12c: File ends in partial case.

Table: Data List
num1,num2
1,2
])
done
AT_CLEANUP

AT_SETUP([partial data record within long string])
AT_KEYWORDS([sack synthetic system file negative])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; 2; 0; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3;

dnl Numeric variables.
2; 14; 0; 0; 0x010e00 *2; s8 "STR14";
2; -1; 0; 0; 0; 0; s8 "";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Data.
999; 0;
s14 "one data item";
s8 "partial";
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
LIST.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1],
   [error: `sys-file.sav' near offset 0x12a: Unexpected end of file.

Table: Data List
str14
one data item
])
done
AT_CLEANUP

AT_SETUP([partial compressed data record])
AT_KEYWORDS([sack synthetic system file positive])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
6; dnl Nominal case size
1; dnl Compressed
0; dnl Not weighted
-1; dnl Unspecified number of cases.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Numeric variables.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";
2; 0; 0; 0; 0x050800 *2; s8 "NUM2";

dnl String variable.
2; 4; 0; 0; 0x010400 *2; s8 "STR4";
2; 8; 0; 0; 0x010800 *2; s8 "STR8";
2; 15; 0; 0; 0x010f00 *2; s8 "STR15";
2; -1; 0; 0; 0; 0; s8 "";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;

dnl Compressed data.
i8 1 100 254 253 254 253; i8 255 251; "abcdefgh"; s8 "0123";
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
LIST.
])
  AT_CHECK([pspp -O format=csv sys-file.sps], [1],
   [error: `sys-file.sav' near offset 0x1ac: File ends in partial case.

Table: Data List
num1,num2,str4,str8,str15
-99,0,,abcdefgh,0123
])
done
AT_CLEANUP

AT_SETUP([zcompressed data - bad zheader_ofs])
AT_KEYWORDS([sack synthetic system file negative zlib])
zcompressed_sack | sed 's/.*zheader_ofs.*/>>i64 0<<;/' > sys-file.sack
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps], [1], [error: `sys-file.sav' near offset 0x194: Wrong ZLIB data header offset 0 (expected 0x194).
])
done
AT_CLEANUP

AT_SETUP([zcompressed data - bad ztrailer_ofs])
AT_KEYWORDS([sack synthetic system file negative zlib])
zcompressed_sack | sed 's/.*ztrailer_ofs.*/>>i64 0<<;/' > sys-file.sack
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps], [1], [error: `sys-file.sav' near offset 0x194: Impossible ZLIB trailer offset 0x0.
])
done
AT_CLEANUP

# ztrailer_len must be a multiple of 24 and at least 48,
# so a value of 12 is impossible.
AT_SETUP([zcompressed data - invalid ztrailer_len])
AT_KEYWORDS([sack synthetic system file negative zlib])
zcompressed_sack | sed 's/.*ztrailer_len.*/>>i64 12<<;/' > sys-file.sack
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps], [1], [error: `sys-file.sav' near offset 0x194: Invalid ZLIB trailer length 12.
])
done
AT_CLEANUP

# ztrailer_ofs + ztrailer_len must be the file size.
AT_SETUP([zcompressed data - wrong ztrailer_len])
AT_KEYWORDS([sack synthetic system file negative zlib])
zcompressed_sack | sed 's/.*ztrailer_len.*/>>i64 72<<;/' > sys-file.sack
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps], [1], [warning: `sys-file.sav' near offset 0x1ac: End of ZLIB trailer (0x24d) is not file size (0x235).
error: `sys-file.sav' near offset 0x21d: 72-byte ZLIB trailer specifies 1 data blocks (expected 2).
])
done
AT_CLEANUP

AT_SETUP([zcompressed data - wrong ztrailer_bias])
AT_KEYWORDS([sack synthetic system file negative zlib])
zcompressed_sack | sed 's/.*ztrailer_bias.*/>>i64 0<<;/' > sys-file.sack
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps], [1], [error: `sys-file.sav' near offset 0x20d: ZLIB trailer bias (0) differs from file header bias (100.00).
])
done
AT_CLEANUP

AT_SETUP([zcompressed data - wrong ztrailer_zero])
AT_KEYWORDS([sack synthetic system file negative zlib])
zcompressed_sack | sed 's/.*ztrailer_zero.*/>>i64 100<<;/' > sys-file.sack
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps], [0], [warning: `sys-file.sav' near offset 0x215: ZLIB trailer "zero" field has nonzero value 100.
])
done
AT_CLEANUP

AT_SETUP([zcompressed data - wrong block_size])
AT_KEYWORDS([sack synthetic system file negative zlib])
zcompressed_sack | sed 's/.*block_size.*/>>0x1000<<;/' > sys-file.sack
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps], [0], [warning: `sys-file.sav' near offset 0x219: ZLIB trailer specifies unexpected 4096-byte block size.
])
done
AT_CLEANUP

AT_SETUP([zcompressed data - wrong n_blocks])
AT_KEYWORDS([sack synthetic system file negative zlib])
zcompressed_sack | sed 's/.*n_blocks.*/>>2<<;/' > sys-file.sack
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps], [1], [error: `sys-file.sav' near offset 0x21d: 48-byte ZLIB trailer specifies 2 data blocks (expected 1).
])
done
AT_CLEANUP

AT_SETUP([zcompressed data - wrong uncompressed_ofs])
AT_KEYWORDS([sack synthetic system file negative zlib])
zcompressed_sack | sed 's/.*uncompressed_ofs.*/i64 >>0x177<<;/' > sys-file.sack
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps], [1], [error: `sys-file.sav' near offset 0x21d: ZLIB block descriptor 0 reported uncompressed data offset 0x177, when 0x194 was expected.
])
done
AT_CLEANUP

AT_SETUP([zcompressed data - wrong compressed_ofs])
AT_KEYWORDS([sack synthetic system file negative zlib])
zcompressed_sack | sed 's/.*@%:@ compressed_ofs.*/i64 >>0x191<<;/' > sys-file.sack
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps], [1], [error: `sys-file.sav' near offset 0x21d: ZLIB block descriptor 0 reported compressed data offset 0x191, when 0x1ac was expected.
])
done
AT_CLEANUP

AT_SETUP([zcompressed data - compressed sizes don't add up])
AT_KEYWORDS([sack synthetic system file negative zlib])
AT_DATA([sys-file.sack], [dnl
dnl File header.
"$FL3"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file";
2; dnl Layout code
6; dnl Nominal case size
2; dnl zlib compressed
0; dnl Not weighted
-1; dnl Unspecified number of cases.
100.0; dnl Bias.
"01 Jan 11"; "20:53:52"; s64 "PSPP synthetic test file";
i8 0 *3;

dnl Numeric variables.
2; 0; 0; 0; 0x050800 *2; s8 "NUM1";
2; 0; 0; 0; 0x050800 *2; s8 "NUM2";

dnl String variable.
2; 4; 0; 0; 0x010400 *2; s8 "STR4";
2; 8; 0; 0; 0x010800 *2; s8 "STR8";
2; 15; 0; 0; 0x010f00 *2; s8 "STR15";
2; -1; 0; 0; 0; 0; s8 "";

dnl Character encoding record.
7; 20; 1; 12; "windows-1252";

dnl Dictionary termination record.
999; 0;

dnl ZLIB data header.
i64 0x194;    # zheader_ofs
i64 0x1ac;    # ztrailer_ofs
i64 72;       # ztrailer_len

dnl This is where the ZLIB data blocks would go, but we don't need any to
dnl provoke this message so we omit them.

dnl ZLIB data trailer fixed header:
i64 -100;     # ztrailer_bias
i64 0;        # ztrailer_zero
0x3ff000;     # block_size
2;            # n_blocks

dnl ZLIB block descriptor 1:
i64 0x194;    # uncompressed_ofs
i64 0x1ac;    # compressed_ofs
0x100000;     # uncompressed_size
0x12345;      # compressed_size

dnl ZLIB block descriptor 2:
i64 0x100194; # uncompressed_ofs
i64 0x12421;  # compressed_ofs
0x100000;     # uncompressed_size
0x12345;      # compressed_size
])
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps], [1], [warning: `sys-file.sav' near offset 0x1c4: ZLIB block descriptor 0 reported block size 0x100000, when 0x3ff000 was expected.
error: `sys-file.sav' near offset 0x1dc: ZLIB block descriptor 1 reported compressed data offset 0x12421, when 0x124f1 was expected.
])
done
AT_CLEANUP

AT_SETUP([zcompressed data - uncompressed_size > block_size])
AT_KEYWORDS([sack synthetic system file negative zlib])
zcompressed_sack | sed 's/.*uncompressed_size.*/>>0x400000<<;/' > sys-file.sack
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps], [0], [warning: `sys-file.sav' near offset 0x21d: ZLIB block descriptor 0 reported block size 0x400000, when at most 0x3ff000 was expected.
])
done
AT_CLEANUP

AT_SETUP([zcompressed data - compression expands data too much])
AT_KEYWORDS([sack synthetic system file negative zlib])
zcompressed_sack | sed 's/.*uncompressed_size.*/>>50<<;/
s/.*@%:@ compressed_size.*/>>100<<;/' > sys-file.sack
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps], [1], [error: `sys-file.sav' near offset 0x21d: ZLIB block descriptor 0 reports compressed size 100 and uncompressed size 50.
])
done
AT_CLEANUP

AT_SETUP([zcompressed data - compressed sizes don't add up])
AT_KEYWORDS([sack synthetic system file negative zlib])
zcompressed_sack | sed 's/.*@%:@ compressed_size.*/>>88<<;/' > sys-file.sack
for variant in be le; do
  AT_CHECK([sack --$variant sys-file.sack > sys-file.sav])
  AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
])
  AT_CHECK([pspp -o pspp.csv sys-file.sps], [1], [error: `sys-file.sav' near offset 0x235: ZLIB trailer is at offset 0x205 but 0x204 would be expected from block descriptors.
])
done
AT_CLEANUP

# CVE-2017-10791.
# See also https://bugzilla.redhat.com/show_bug.cgi?id=1467004.
# See also https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=866890.
# See also https://security-tracker.debian.org/tracker/CVE-2017-10791.
# Found by team OWL337, using the collAFL fuzzer.
AT_SETUP([integer overflows in long string missing values])
AT_KEYWORDS([system file negative])
cp $top_srcdir/tests/data/CVE-2017-10791.sav .
AT_CHECK([pspp-convert -O csv -e ASCII CVE-2017-10791.sav -], [0], [], [dnl
`CVE-2017-10791.sav' near offset 0x217: Extension record subtype 21 ends unexpectedly.
])
AT_CLEANUP

# CVE-2017-10792.
# See also https://bugzilla.redhat.com/show_bug.cgi?id=1467005.
# See also https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=866890.
# See also https://security-tracker.debian.org/tracker/CVE-2017-10792.
# Reported by team OWL337, with fuzzer collAFL.
AT_SETUP([null dereference skipping bad extension record 18])
AT_KEYWORDS([system file negative])
cp $top_srcdir/tests/data/CVE-2017-10792.sav .
AT_CHECK([pspp-convert -O csv -e ASCII CVE-2017-10792.sav -], [0], [], [dnl
`CVE-2017-10792.sav' near offset 0x1c0: Record type 7, subtype 18 has bad size 4 (expected 1).
])
AT_CLEANUP
