AT_BANNER([system files])

# Also tests that long variable names are preserved by SAVE and GET.
AT_SETUP([write and read numeric data])
AT_KEYWORDS([SAVE GET system file])
AT_DATA([sysfile.sps], [dnl
DATA LIST LIST NOTABLE / variable001 * variable002 * variable003 * variable004 * .
BEGIN DATA.
    1.00     1.00    1.0     2.00
    1.00     1.00    2.0    30.00
    1.00     2.00    1.0     8.00
    1.00     2.00    2.0    20.00
    2.00     1.00    1.0     2.00
    2.00     1.00    2.0    22.00
    2.00     2.00    1.0     1.00
    2.00     2.00    2.0     3.00
END DATA.

SAVE /OUTFILE='foo.sav'.

GET /FILE='foo.sav'.

LIST.
])
AT_CHECK([pspp -o pspp.csv sysfile.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Table: Data List
variable001,variable002,variable003,variable004
1.00,1.00,1.00,2.00
1.00,1.00,2.00,30.00
1.00,2.00,1.00,8.00
1.00,2.00,2.00,20.00
2.00,1.00,1.00,2.00
2.00,1.00,2.00,22.00
2.00,2.00,1.00,1.00
2.00,2.00,2.00,3.00
])
AT_CLEANUP

AT_SETUP([write and read compressed files])
AT_KEYWORDS([SAVE GET system file])
AT_DATA([sysfile.sps], [dnl
DATA LIST LIST NOTABLE /x * y (a200).
BEGIN DATA.
1.2 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
.   yyyyyyyyyyyyyyy
0   ddddddddddddddddddddddddddddddd
101 z
END DATA.

SAVE OUTFILE='com.sav' /COMPRESS .

GET FILE='com.sav'.

LIST.
])
AT_CHECK([pspp -o pspp.csv sysfile.sps])
dnl Make sure file really was compressd, allowing big- or little-endian format.
AT_CHECK([dd if=com.sav bs=1 skip=72 count=4 2> /dev/null > com.sav.subset])
od com.sav.subset
AT_CHECK(
  [(printf '\000\000\000\001' | cmp -l com.sav.subset -) ||
   (printf '\001\000\000\000' | cmp -l com.sav.subset -)], [0],
  [ignore])
AT_CLEANUP

AT_SETUP([overwriting system file])
AT_DATA([output.sav], [abcdef
])
cp output.sav output.sav.backup
AT_DATA([sysfile.sps], [dnl
DATA LIST NOTABLE/x 1.
BEGIN DATA.
5
END DATA.
SAVE OUTFILE='output.sav'.
])
AT_CHECK([pspp -O format=csv sysfile.sps])
AT_CHECK([cmp output.sav output.sav.backup], [1], [ignore])
AT_CLEANUP

AT_SETUP([overwriting system file atomically])
AT_DATA([output.sav], [abcdef
])
cp output.sav output.sav.backup
AT_DATA([sysfile.sps],
[[DATA LIST NOTABLE/x 1.
BEGIN DATA.
5
END DATA.
XSAVE OUTFILE='output.sav'.
HOST COMMAND=['kill -TERM $PPID'].
]])
AT_CHECK([pspp -O format=csv sysfile.sps], [143], [], [ignore])
AT_CHECK([cmp output.sav output.sav.backup])
AT_CHECK(
  [for file in *.tmp*; do if test -e $file; then echo $file; exit 1; fi; done])
AT_CLEANUP


AT_SETUP([write to same system file being read])
AT_DATA([save.sps], [dnl
DATA LIST NOTABLE/x 1.
BEGIN DATA.
3
END DATA.
SAVE OUTFILE='data.sav'.
])
AT_CHECK([pspp -O format=csv save.sps])
AT_CHECK([test -s data.sav])
AT_CHECK(
  [for file in *.tmp*; do if test -e $file; then echo $file; exit 1; fi; done])
AT_DATA([save2.sps], [dnl
GET FILE='data.sav'.
COMPUTE y = x * 3.
SAVE OUTFILE='data.sav'.
])
AT_CHECK([pspp -O format=csv save2.sps])
AT_CHECK(
  [for file in *.tmp*; do if test -e $file; then echo $file; exit 1; fi; done])
AT_DATA([save3.sps], [dnl
GET FILE='data.sav'.
LIST.
])
AT_CHECK([pspp -O format=csv save3.sps], [0], [dnl
Table: Data List
x,y
3,9.00
])
AT_CLEANUP

AT_SETUP([nonempty case_map doesn't crash])
AT_KEYWORDS([SAVE system file])
AT_DATA([save.sps], [dnl
INPUT PROGRAM.
    COMPUTE #I = 1.
    COMPUTE X = #I + 1.
    END CASE.
    END FILE.
END INPUT PROGRAM.

SAVE OUTFILE='tiny.sav'.
])
AT_CHECK([pspp -O format=csv save.sps])
AT_DATA([get.sps], [dnl
GET FILE='tiny.sav'.
LIST.
])
AT_CHECK([pspp -O format=csv get.sps], [0], [dnl
Table: Data List
X
2.00
])
AT_CLEANUP

# Test that system files can be read properly, even when the case_size
# header value is -1 (Some 3rd party products do this).
AT_SETUP([system files with -1 case_size])
AT_KEYWORDS([SAVE GET])
AT_DATA([save.sps], [dnl
DATA LIST LIST NOTABLE /cont (A32) size pop count.
VAR LABEL
    cont 'continents of the world'
    size 'sq km'
    pop 'population'
    count 'number of countries'.
SAVE OUTFILE='cont.sav'.
BEGIN DATA.
Asia, 44579000, 3.7E+009, 44.00
Africa, 30065000, 7.8E+008, 53.00
"North America", 24256000, 4.8E+008, 23.00
"South America", 17819000, 3.4E+008, 12.00
Antarctica, 13209000, .00, .00
Europe, 9938000, 7.3E+008, 46.00
Australia/Oceania, 7687000, 31000000, 14.00
END DATA.
])
AT_CHECK([pspp -O format=csv save.sps])
AT_CHECK([test -f cont.sav])

dnl case_size is a 4-byte field at offset 68.
dnl Make a new copy with its value changed to -1.
AT_CHECK(
  [(dd if=cont.sav bs=1 count=68;
    printf '\377\377\377\377';
    dd if=cont.sav bs=1 skip=72) > cont2.sav], [0], [], [ignore])
AT_CHECK([cmp cont.sav cont2.sav], [1],
  [cont.sav cont2.sav differ: char 69, line 1
])

AT_DATA([get.sps], [dnl
GET FILE='cont2.sav'.
DISPLAY LABELS.
LIST.
])
AT_CHECK([pspp -o pspp.csv get.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Variable,Label,,Position
cont,continents of the world,,1
size,sq km,,2
pop,population,,3
count,number of countries,,4

Table: Data List
cont,size,pop,count
Asia                            ,44579000,3.7E+009,44.00
Africa                          ,30065000,7.8E+008,53.00
North America                   ,24256000,4.8E+008,23.00
South America                   ,17819000,3.4E+008,12.00
Antarctica                      ,13209000,.00,.00
Europe                          ,9938000,7.3E+008,46.00
Australia/Oceania               ,7687000,31000000,14.00
])
AT_CLEANUP

AT_SETUP([write v2 system file])
AT_KEYWORDS([SAVE])
AT_DATA([sysfile.sps], [dnl
DATA LIST LIST NOTABLE / X * variable001 * variable002 * variable003 * .
BEGIN DATA.
    1.00     1.00    1.0     2.00
    1.00     1.00    2.0    30.00
    1.00     2.00    1.0     8.00
    1.00     2.00    2.0    20.00
    2.00     1.00    1.0     2.00
    2.00     1.00    2.0    22.00
    2.00     2.00    1.0     1.00
    2.00     2.00    2.0     3.00
END DATA.

SAVE /OUTFILE='foo.sav'
     /VERSION=2
     .

GET /FILE='foo.sav'.

LIST.
])
AT_CHECK([pspp -O format=csv sysfile.sps], [0], [dnl
Table: Data List
x,variable,variab_a,variab_b
1.00,1.00,1.00,2.00
1.00,1.00,2.00,30.00
1.00,2.00,1.00,8.00
1.00,2.00,2.00,20.00
2.00,1.00,1.00,2.00
2.00,1.00,2.00,22.00
2.00,2.00,1.00,1.00
2.00,2.00,2.00,3.00
])
dnl Ensure that the written file has no long name table
AT_CHECK([grep 'X=X' foo.sav], [1], [ignore-nolog])
AT_CLEANUP

AT_BANNER([system files -- very long strings])

AT_SETUP([read very long strings written by SPSS 13])
AT_CHECK([cp $top_srcdir/tests/data/v13.sav .])
AT_DATA([sys-file.sps], [dnl
GET FILE='v13.sav'.
DISPLAY VARIABLES.
LIST.
])
AT_CHECK([pspp -o pspp.csv sys-file.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Variable,Description,,Position
N,Format: F8.2,,1
,Measure: Scale,,
,Display Alignment: Right,,
,Display Width: 10,,
A255,Format: A255,,2
,Measure: Nominal,,
,Display Alignment: Left,,
,Display Width: 32,,
A258,Format: A258,,3
,Measure: Nominal,,
,Display Alignment: Left,,
,Display Width: 32,,
A2000,Format: A2000,,4
,Measure: Nominal,,
,Display Alignment: Left,,
,Display Width: 32,,

Table: Data List
N,A255,A258,A2000
1.00,a1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
])
AT_CLEANUP

AT_SETUP([read very long strings written by SPSS 14])
AT_CHECK([cp $top_srcdir/tests/data/v14.sav .])
AT_DATA([sys-file.sps], [dnl
GET FILE='v14.sav'.
DISPLAY VARIABLES.
LIST.
])
AT_CHECK([pspp -o pspp.csv sys-file.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Variable,Description,,Position
vl255,Format: A255,,1
,Measure: Nominal,,
,Display Alignment: Left,,
,Display Width: 26,,
vl256,Format: A256,,2
,Measure: Nominal,,
,Display Alignment: Left,,
,Display Width: 26,,
vl1335,Format: A1335,,3
,Measure: Nominal,,
,Display Alignment: Left,,
,Display Width: 26,,
vl2000,Format: A2000,,4
,Measure: Nominal,,
,Display Alignment: Left,,
,Display Width: 26,,

Table: Data List
vl255,vl256,vl1335,vl2000
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM,MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM,MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM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txt <<EOF
[encoded data, 66470 characters]
EOF
}
m4_divert_pop([PREPARE_TESTS])

m4_define([VLS_WRITE],
  [AT_SETUP([save very long string -- m4_tolower([$1])])
   vls_gen_data
   AT_DATA([save.sps], [dnl
DATA LIST FIXED NOTABLE FILE='data.txt'
    /a 2-11 (a) 
     b (a256) 
     c (a200) 
     d (a32767).

SAVE OUTFILE='foo.sav' /$1.
])
   AT_CHECK([pspp -O format=csv save.sps])
   AT_DATA([get.sps], [dnl
GET FILE='foo.sav'.

DISPLAY VARIABLES.

PRINT OUTFILE='out.txt'
	/a (a10) b (a256) c (a200) 
	d (a32767)
	.

EXECUTE.
])
   AT_CHECK([pspp -o pspp.csv get.sps])
   AT_CHECK([cat pspp.csv], [0], [dnl
Variable,Description,,Position
a,Format: A10,,1
,Measure: Nominal,,
,Display Alignment: Left,,
,Display Width: 10,,
b,Format: A256,,2
,Measure: Nominal,,
,Display Alignment: Left,,
,Display Width: 32,,
c,Format: A200,,3
,Measure: Nominal,,
,Display Alignment: Left,,
,Display Width: 32,,
d,Format: A32767,,4
,Measure: Nominal,,
,Display Alignment: Left,,
,Display Width: 32,,
])
   AT_CLEANUP])

VLS_WRITE([UNCOMPRESSED])
VLS_WRITE([COMPRESSED])

dnl This test writes non-ASCII characters to most of the string fields in
dnl a .sav file and demonstrates that they are properly read back in.
dnl XXX mrsets tests are missing.
AT_SETUP([system file character encoding])
AT_CHECK([i18n-test supports_encodings windows-1252])
AT_DATA([save.sps], [dnl
SET LOCALE='windows-1252'.
DATA LIST LIST NOTABLE /àéîöçxyzabc * roué (A9) croûton (A1000).
FILE LABEL 'clientèle confrère cortège crèche'.
DOCUMENT coördinate smörgåsbord
épée séance soufflé soirée
jalapeño vicuña.
VALUE LABEL
      /àéîöçxyzabc 1 'éclair élan'
      /roué 'abcdefghi' 'sauté précis'.
VARIABLE LABEL
      roué 'Provençal soupçon'.
DATAFILE ATTRIBUTE
      ATTRIBUTE=Furtwängler('kindergärtner').
VARIABLE ATTRIBUTE
      VARIABLES=àéîöçxyzabc
      ATTRIBUTE=Atatürk('Düsseldorf Gewürztraminer').
BEGIN DATA.
1 a x
2 b y
3 c z
END DATA.
SAVE OUTFILE='foo.sav'.
])
AT_CHECK([pspp -O format=csv save.sps])
AT_DATA([get.sps], [dnl
GET FILE='foo.sav'.
DISPLAY FILE LABEL.
DISPLAY DOCUMENTS.
DISPLAY DICTIONARY.
])
AT_CHECK([pspp -o pspp.csv get.sps])
AT_CHECK([[sed 's/(Entered [^)]*)/(Entered <date>)/' pspp.csv]], [0], [dnl
File label: clientèle confrère cortège crèche

Documents in the active dataset:

DOCUMENT coördinate smörgåsbord

épée séance soufflé soirée

jalapeño vicuña.

(Entered <date>)

Variable,Description,,Position
àéîöçxyzabc,Format: F8.2,,1
,Measure: Scale,,
,Display Alignment: Right,,
,Display Width: 8,,
,1.00,éclair élan,
,Custom attributes:,,
,Atatürk,Düsseldorf Gewürztraminer,
roué,Provençal soupçon,,2
,Format: A9,,
,Measure: Nominal,,
,Display Alignment: Left,,
,Display Width: 9,,
,abcdefghi,sauté précis,
croûton,Format: A1000,,3
,Measure: Nominal,,
,Display Alignment: Left,,
,Display Width: 32,,

Table: Custom data file attributes.
Attribute,Value
Furtwängler,kindergärtner
])
AT_CLEANUP
