tests: Convert system file tests to Autotest framework.
[pspp-builds.git] / tests / data / sys-file.at
1 AT_BANNER([system files])
2
3 # Also tests that long variable names are preserved by SAVE and GET.
4 AT_SETUP([write and read numeric data])
5 AT_KEYWORDS([SAVE GET system file])
6 AT_DATA([sysfile.sps], [dnl
7 DATA LIST LIST NOTABLE / variable001 * variable002 * variable003 * variable004 * .
8 BEGIN DATA.
9     1.00     1.00    1.0     2.00
10     1.00     1.00    2.0    30.00
11     1.00     2.00    1.0     8.00
12     1.00     2.00    2.0    20.00
13     2.00     1.00    1.0     2.00
14     2.00     1.00    2.0    22.00
15     2.00     2.00    1.0     1.00
16     2.00     2.00    2.0     3.00
17 END DATA.
18
19 SAVE /OUTFILE='foo.sav'.
20
21 GET /FILE='foo.sav'.
22
23 LIST.
24 ])
25 AT_CHECK([pspp -o pspp.csv sysfile.sps])
26 AT_CHECK([cat pspp.csv], [0], [dnl
27 Table: Data List
28 variable001,variable002,variable003,variable004
29 1.00,1.00,1.00,2.00
30 1.00,1.00,2.00,30.00
31 1.00,2.00,1.00,8.00
32 1.00,2.00,2.00,20.00
33 2.00,1.00,1.00,2.00
34 2.00,1.00,2.00,22.00
35 2.00,2.00,1.00,1.00
36 2.00,2.00,2.00,3.00
37 ])
38 AT_CLEANUP
39
40 # Test that system files can be read properly, even when the case_size
41 # header value is -1 (Some 3rd party products do this).
42 AT_SETUP([system files with -1 case_size])
43 AT_KEYWORDS([SAVE GET])
44 AT_DATA([save.sps], [dnl
45 DATA LIST LIST NOTABLE /cont (A32) size pop count.
46 VAR LABEL
47     cont 'continents of the world'
48     size 'sq km'
49     pop 'population'
50     count 'number of countries'.
51 SAVE OUTFILE='cont.sav'.
52 BEGIN DATA.
53 Asia, 44579000, 3.7E+009, 44.00
54 Africa, 30065000, 7.8E+008, 53.00
55 "North America", 24256000, 4.8E+008, 23.00
56 "South America", 17819000, 3.4E+008, 12.00
57 Antarctica, 13209000, .00, .00
58 Europe, 9938000, 7.3E+008, 46.00
59 Australia/Oceania, 7687000, 31000000, 14.00
60 END DATA.
61 ])
62 AT_CHECK([pspp -O format=csv save.sps])
63 AT_CHECK([test -f cont.sav])
64
65 dnl case_size is a 4-byte field at offset 68.
66 dnl Make a new copy with its value changed to -1.
67 AT_CHECK(
68   [(dd if=cont.sav bs=1 count=68;
69     printf '\377\377\377\377';
70     dd if=cont.sav bs=1 skip=72) > cont2.sav], [0], [], [ignore])
71 AT_CHECK([cmp cont.sav cont2.sav], [1],
72   [cont.sav cont2.sav differ: char 69, line 1
73 ])
74
75 AT_DATA([get.sps], [dnl
76 GET FILE='cont2.sav'.
77 DISPLAY LABELS.
78 LIST.
79 ])
80 AT_CHECK([pspp -o pspp.csv get.sps])
81 AT_CHECK([cat pspp.csv], [0], [dnl
82 Variable,Label,,Position
83 cont,continents of the world,,1
84 size,sq km,,2
85 pop,population,,3
86 count,number of countries,,4
87
88 Table: Data List
89 cont,size,pop,count
90 Asia                            ,44579000,3.7E+009,44.00
91 Africa                          ,30065000,7.8E+008,53.00
92 North America                   ,24256000,4.8E+008,23.00
93 South America                   ,17819000,3.4E+008,12.00
94 Antarctica                      ,13209000,.00,.00
95 Europe                          ,9938000,7.3E+008,46.00
96 Australia/Oceania               ,7687000,31000000,14.00
97 ])
98 AT_CLEANUP
99
100 AT_SETUP([write v2 system file])
101 AT_KEYWORDS([SAVE])
102 AT_DATA([sysfile.sps], [dnl
103 DATA LIST LIST NOTABLE / X * variable001 * variable002 * variable003 * .
104 BEGIN DATA.
105     1.00     1.00    1.0     2.00
106     1.00     1.00    2.0    30.00
107     1.00     2.00    1.0     8.00
108     1.00     2.00    2.0    20.00
109     2.00     1.00    1.0     2.00
110     2.00     1.00    2.0    22.00
111     2.00     2.00    1.0     1.00
112     2.00     2.00    2.0     3.00
113 END DATA.
114
115 SAVE /OUTFILE='foo.sav'
116      /VERSION=2
117      .
118
119 GET /FILE='foo.sav'.
120
121 LIST.
122 ])
123 AT_CHECK([pspp -O format=csv sysfile.sps], [0], [dnl
124 Table: Data List
125 x,variable,variab_a,variab_b
126 1.00,1.00,1.00,2.00
127 1.00,1.00,2.00,30.00
128 1.00,2.00,1.00,8.00
129 1.00,2.00,2.00,20.00
130 2.00,1.00,1.00,2.00
131 2.00,1.00,2.00,22.00
132 2.00,2.00,1.00,1.00
133 2.00,2.00,2.00,3.00
134 ])
135 dnl Ensure that the written file has no long name table
136 AT_CHECK([grep 'X=X' foo.sav], [1], [ignore-nolog])
137 AT_CLEANUP