eca194a02dde0508735b318a1191a7ebc675fd54
[pspp] / tests / language / data-io / get-data-spreadsheet.at
1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
3 dnl 
4 dnl This program is free software: you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation, either version 3 of the License, or
7 dnl (at your option) any later version.
8 dnl 
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl GNU General Public License for more details.
13 dnl 
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 dnl 
17 m4_define([SPREADSHEET_TEST_PREP],[dnl
18  m4_if($1,[GNM],[dnl
19     AT_CHECK([gzip -c $top_srcdir/tests/language/data-io/Book1.gnm.unzipped > Book1.gnumeric])dnl
20     m4_define([testsheet],[Book1.gnumeric])dnl
21     ]) dnl
22  m4_if($1,[ODS],[dnl
23     AT_CHECK([cp $top_srcdir/tests/language/data-io/test.ods test.ods])dnl
24     m4_define([testsheet],[test.ods])dnl
25     ])dnl
26 ])
27
28 m4_define([CHECK_SPREADSHEET_READER],
29  [dnl
30 AT_SETUP([GET DATA /TYPE=$1 with CELLRANGE])
31 SPREADSHEET_TEST_PREP($1)
32 AT_DATA([get-data.sps], [dnl
33 GET DATA /TYPE=$1 /FILE='testsheet'  /READNAMES=off /SHEET=name 'This' /CELLRANGE=range 'g9:i13' .
34 DISPLAY VARIABLES.
35 LIST.
36 ])
37 AT_CHECK([pspp -o pspp.csv get-data.sps])
38 AT_CHECK([cat pspp.csv], [0], [dnl
39 Variable,Description,Position
40 VAR001,Format: F8.2,1
41 VAR002,Format: A8,2
42 VAR003,Format: F8.2,3
43
44 Table: Data List
45 VAR001,VAR002,VAR003
46 .00,fred    ,20.00
47 1.00,11      ,21.00
48 2.00,twelve  ,22.00
49 3.00,13      ,23.00
50 4.00,14      ,24.00
51 ])
52 AT_CLEANUP
53
54 AT_SETUP([GET DATA /TYPE=$1 with CELLRANGE and READNAMES])
55 SPREADSHEET_TEST_PREP($1)
56 AT_DATA([get-data.sps], [dnl
57 GET DATA /TYPE=$1 /FILE='testsheet'  /READNAMES=on /SHEET=name 'This' /CELLRANGE=range 'g8:i13' .
58 DISPLAY VARIABLES.
59 LIST.
60 ])
61 AT_CHECK([pspp -o pspp.csv get-data.sps])
62 AT_CHECK([cat pspp.csv], [0], [dnl
63 Variable,Description,Position
64 V1,Format: F8.2,1
65 V2,Format: A8,2
66 VAR001,Format: F8.2,3
67
68 Table: Data List
69 V1,V2,VAR001
70 .00,fred    ,20.00
71 1.00,11      ,21.00
72 2.00,twelve  ,22.00
73 3.00,13      ,23.00
74 4.00,14      ,24.00
75 ])
76 AT_CLEANUP
77
78 AT_SETUP([GET DATA /TYPE=$1 without CELLRANGE])
79 SPREADSHEET_TEST_PREP($1)
80 AT_DATA([get-data.sps], [dnl
81 GET DATA /TYPE=$1 /FILE='testsheet' /SHEET=index 3.
82 DISPLAY VARIABLES.
83 LIST.
84 ])
85 AT_CHECK([pspp -O format=csv get-data.sps], [0], [dnl
86 Variable,Description,Position
87 name,Format: A8,1
88 id,Format: F8.2,2
89 height,Format: F8.2,3
90
91 warning: Cannot convert the value in the spreadsheet cell C4 to format (F8.2): Field contents are not numeric.
92
93 Table: Data List
94 name,id,height
95 fred    ,.00,23.40
96 bert    ,1.00,.56
97 charlie ,2.00,.  @&t@
98 dick    ,3.00,-34.09
99 ])
100 AT_CLEANUP
101
102 AT_SETUP([GET DATA /TYPE=$1 with missing data])
103 SPREADSHEET_TEST_PREP($1)
104 AT_DATA([get-data.sps], [dnl
105 * This sheet has no data in one of its variables
106 GET DATA /TYPE=$1 /FILE='testsheet' /READNAMES=on /SHEET=index 5.
107 DISPLAY VARIABLES.
108 LIST.
109 ])
110 AT_CHECK([pspp -o pspp.csv get-data.sps])
111 AT_CHECK([cat pspp.csv], [0], [dnl
112 Variable,Description,Position
113 vone,Format: F8.2,1
114 vtwo,Format: F8.2,2
115 vthree,Format: A8,3
116 v4,Format: F8.2,4
117
118 Table: Data List
119 vone,vtwo,vthree,v4
120 1.00,3.00,,5.00
121 2.00,4.00,,6.00
122 ])
123 AT_CLEANUP
124
125 dnl This syntax doesn't do anything particularly useful.
126 dnl It has been seen to cause a few crashes, so we check here that it
127 dnl doesn't do anthing bad.
128 AT_SETUP([GET DATA /TYPE=$1 with no options])
129 SPREADSHEET_TEST_PREP($1)
130 AT_DATA([get-data.sps], [dnl
131 * This sheet is empty
132 GET DATA /TYPE=$1 /FILE='testsheet'.
133 DISPLAY DICTIONARY.
134 LIST.
135 ])
136 AT_CHECK([pspp -o pspp.csv get-data.sps], [0], [ignore])
137 AT_CLEANUP
138
139
140
141 AT_SETUP([GET DATA /TYPE=$1 with empty sheet])
142 SPREADSHEET_TEST_PREP($1)
143 AT_DATA([get-data.sps], [dnl
144 * This sheet is empty
145 GET DATA /TYPE=$1 /FILE='testsheet' /SHEET=name 'Empty'.
146 ])
147 AT_CHECK([pspp -o pspp.csv get-data.sps], [0], [dnl
148 warning: Selected sheet or range of spreadsheet `testsheet' is empty.
149 ])
150 AT_CLEANUP
151
152 AT_SETUP([GET DATA /TYPE=$1 with nonexistent sheet])
153 SPREADSHEET_TEST_PREP($1)
154 AT_DATA([get-data.sps], [dnl
155 * This sheet doesnt exist.
156 GET DATA /TYPE=$1 /FILE='testsheet' /SHEET=name 'foobarxx'.
157 ])
158 AT_CHECK([pspp -o pspp.csv get-data.sps], [0], [dnl
159 warning: Selected sheet or range of spreadsheet `testsheet' is empty.
160 ])
161 AT_CLEANUP
162 ])
163
164
165 AT_BANNER([GET DATA Spreadsheet /TYPE=GNM])
166
167 CHECK_SPREADSHEET_READER([GNM])
168
169 dnl Check for a bug where gnumeric files were interpreted incorrectly
170 AT_SETUP([GET DATA /TYPE=GNM sheet index bug])
171 AT_DATA([minimal3.gnumeric],[dnl
172 <?xml version="1.0" encoding="UTF-8"?>
173 <gnm:Workbook xmlns:gnm="http://www.gnumeric.org/v10.dtd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.gnumeric.org/v9.xsd">
174   <gnm:Version Epoch="1" Major="10" Minor="8" Full="1.10.8"/>
175   <gnm:SheetNameIndex>
176     <gnm:SheetName gnm:Cols="256" gnm:Rows="65536">Sheet1</gnm:SheetName>
177     <gnm:SheetName gnm:Cols="256" gnm:Rows="65536">Sheet2</gnm:SheetName>
178     <gnm:SheetName gnm:Cols="256" gnm:Rows="65536">Sheet3</gnm:SheetName>
179   </gnm:SheetNameIndex>
180   <gnm:Sheets>
181     <gnm:Sheet DisplayFormulas="0" HideZero="0" HideGrid="0" HideColHeader="0" HideRowHeader="0" DisplayOutlines="1" OutlineSymbolsBelow="1" OutlineSymbolsRight="1" Visibility="GNM_SHEET_VISIBILITY_VISIBLE" GridColor="0:0:0">
182       <gnm:Name>Sheet1</gnm:Name>
183       <gnm:MaxCol>2</gnm:MaxCol>
184       <gnm:MaxRow>3</gnm:MaxRow>
185       <gnm:Names>
186         <gnm:Name>
187           <gnm:name>Print_Area</gnm:name>
188           <gnm:value>#REF!</gnm:value>
189           <gnm:position>A1</gnm:position>
190         </gnm:Name>
191         <gnm:Name>
192           <gnm:name>Sheet_Title</gnm:name>
193           <gnm:value>&quot;Sheet1&quot;</gnm:value>
194           <gnm:position>A1</gnm:position>
195         </gnm:Name>
196       </gnm:Names>
197       <gnm:Cols DefaultSizePts="48">
198         <gnm:ColInfo No="0" Unit="94.5" HardSize="1"/>
199         <gnm:ColInfo No="1" Unit="48" Count="2"/>
200       </gnm:Cols>
201       <gnm:Rows DefaultSizePts="12.75">
202         <gnm:RowInfo No="0" Unit="13.5" Count="4"/>
203       </gnm:Rows>
204       <gnm:Cells>
205         <gnm:Cell Row="0" Col="0" ValueType="60">Name</gnm:Cell>
206         <gnm:Cell Row="0" Col="1" ValueType="60">x</gnm:Cell>
207         <gnm:Cell Row="0" Col="2" ValueType="60">y</gnm:Cell>
208         <gnm:Cell Row="1" Col="0" ValueType="60">Sheet One</gnm:Cell>
209         <gnm:Cell Row="1" Col="1" ValueType="40">1</gnm:Cell>
210         <gnm:Cell Row="1" Col="2" ValueType="40">2</gnm:Cell>
211         <gnm:Cell Row="2" Col="0" ValueType="60">foo</gnm:Cell>
212         <gnm:Cell Row="2" Col="1" ValueType="40">3</gnm:Cell>
213         <gnm:Cell Row="2" Col="2" ValueType="40">4</gnm:Cell>
214         <gnm:Cell Row="3" Col="0" ValueType="60">bar</gnm:Cell>
215         <gnm:Cell Row="3" Col="1" ValueType="40">5</gnm:Cell>
216         <gnm:Cell Row="3" Col="2" ValueType="40">6</gnm:Cell>
217       </gnm:Cells>
218     </gnm:Sheet>
219     <gnm:Sheet DisplayFormulas="0" HideZero="0" HideGrid="0" HideColHeader="0" HideRowHeader="0" DisplayOutlines="1" OutlineSymbolsBelow="1" OutlineSymbolsRight="1" Visibility="GNM_SHEET_VISIBILITY_VISIBLE" GridColor="0:0:0">
220       <gnm:Name>Sheet2</gnm:Name>
221       <gnm:MaxCol>2</gnm:MaxCol>
222       <gnm:MaxRow>2</gnm:MaxRow>
223       <gnm:Names>
224         <gnm:Name>
225           <gnm:name>Print_Area</gnm:name>
226           <gnm:value>#REF!</gnm:value>
227           <gnm:position>A1</gnm:position>
228         </gnm:Name>
229         <gnm:Name>
230           <gnm:name>Sheet_Title</gnm:name>
231           <gnm:value>&quot;Sheet2&quot;</gnm:value>
232           <gnm:position>A1</gnm:position>
233         </gnm:Name>
234       </gnm:Names>
235       <gnm:Cols DefaultSizePts="48">
236         <gnm:ColInfo No="0" Unit="48"/>
237         <gnm:ColInfo No="1" Unit="57.75"/>
238         <gnm:ColInfo No="2" Unit="54.75"/>
239       </gnm:Cols>
240       <gnm:Rows DefaultSizePts="12.75">
241         <gnm:RowInfo No="0" Unit="13.5" Count="3"/>
242       </gnm:Rows>
243       <gnm:Cells>
244         <gnm:Cell Row="0" Col="0" ValueType="60">Comment</gnm:Cell>
245         <gnm:Cell Row="0" Col="1" ValueType="60">DOB</gnm:Cell>
246         <gnm:Cell Row="0" Col="2" ValueType="60">wealth</gnm:Cell>
247         <gnm:Cell Row="1" Col="0" ValueType="60">Sheet Two</gnm:Cell>
248         <gnm:Cell Row="1" Col="1" ValueType="60">24/5/1966</gnm:Cell>
249         <gnm:Cell Row="1" Col="2" ValueType="40" ValueFormat="_($* 0.00_);_($* (0.00);_($* &quot;-&quot;??_);_(@_)">0.02</gnm:Cell>
250         <gnm:Cell Row="2" Col="0" ValueType="60">wee</gnm:Cell>
251         <gnm:Cell Row="2" Col="1" ValueType="40" ValueFormat="dd/mm/yyyy">37145</gnm:Cell>
252         <gnm:Cell Row="2" Col="2" ValueType="40" ValueFormat="_($* 0.00_);_($* (0.00);_($* &quot;-&quot;??_);_(@_)">3000</gnm:Cell>
253       </gnm:Cells>
254     </gnm:Sheet>
255     <gnm:Sheet DisplayFormulas="0" HideZero="0" HideGrid="0" HideColHeader="0" HideRowHeader="0" DisplayOutlines="1" OutlineSymbolsBelow="1" OutlineSymbolsRight="1" Visibility="GNM_SHEET_VISIBILITY_VISIBLE" GridColor="0:0:0">
256       <gnm:Name>Sheet3</gnm:Name>
257       <gnm:MaxCol>2</gnm:MaxCol>
258       <gnm:MaxRow>2</gnm:MaxRow>
259       <gnm:Names>
260         <gnm:Name>
261           <gnm:name>Print_Area</gnm:name>
262           <gnm:value>#REF!</gnm:value>
263           <gnm:position>A1</gnm:position>
264         </gnm:Name>
265         <gnm:Name>
266           <gnm:name>Sheet_Title</gnm:name>
267           <gnm:value>&quot;Sheet3&quot;</gnm:value>
268           <gnm:position>A1</gnm:position>
269         </gnm:Name>
270       </gnm:Names>
271       <gnm:Cols DefaultSizePts="48">
272         <gnm:ColInfo No="0" Unit="48" Count="3"/>
273       </gnm:Cols>
274       <gnm:Rows DefaultSizePts="12.75">
275         <gnm:RowInfo No="0" Unit="13.5"/>
276         <gnm:RowInfo No="1" Unit="12.75" Count="2"/>
277       </gnm:Rows>
278       <gnm:Cells>
279         <gnm:Cell Row="0" Col="0" ValueType="40">3</gnm:Cell>
280         <gnm:Cell Row="0" Col="1" ValueType="40">4</gnm:Cell>
281         <gnm:Cell Row="0" Col="2" ValueType="40">5</gnm:Cell>
282         <gnm:Cell Row="1" Col="0" ValueType="40">6</gnm:Cell>
283         <gnm:Cell Row="1" Col="1" ValueType="40">7</gnm:Cell>
284         <gnm:Cell Row="1" Col="2" ValueType="40">8</gnm:Cell>
285         <gnm:Cell Row="2" Col="0" ValueType="40">9</gnm:Cell>
286         <gnm:Cell Row="2" Col="1" ValueType="40">10</gnm:Cell>
287         <gnm:Cell Row="2" Col="2" ValueType="40">11</gnm:Cell>
288       </gnm:Cells>
289     </gnm:Sheet>
290   </gnm:Sheets>
291 </gnm:Workbook>
292 ])
293
294 AT_DATA([gnum.sps], [dnl
295 GET DATA        
296         /TYPE=GNM
297         /FILE='minimal3.gnumeric'
298         /SHEET=index 3
299         /READNAMES=off
300         .
301
302 LIST.
303 ])
304
305 AT_CHECK([pspp -O format=csv gnum.sps], [0], [dnl
306 Table: Data List
307 VAR001,VAR002,VAR003
308 3       ,4.00,5.00
309 6       ,7.00,8.00
310 9       ,10.00,11.00
311 ])
312
313
314 AT_CLEANUP
315
316
317 dnl Check for a bug where certain gnumeric files failed an assertion
318 AT_SETUP([GET DATA /TYPE=GNM assert-fail])
319 AT_DATA([read.sps],[dnl
320 GET DATA 
321         /TYPE=GNM
322         /FILE='crash.gnumeric' 
323         .
324 list.
325 ])
326
327
328 AT_DATA([crash.gnumeric],[dnl
329 <?xml version="1.0" encoding="UTF-8"?>
330 <gnm:Workbook xmlns:gnm="http://www.gnumeric.org/v10.dtd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.gnumeric.org/v9.xsd">
331   <office:document-meta xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:ooo="http://openoffice.org/2004/office" office:version="1.1">
332   </office:document-meta>
333   <gnm:SheetNameIndex>
334     <gnm:SheetName gnm:Cols="256" gnm:Rows="65536">Sheet1</gnm:SheetName>
335   </gnm:SheetNameIndex>
336   <gnm:Sheets>
337     <gnm:Sheet DisplayFormulas="0" HideZero="0" HideGrid="0" HideColHeader="0" HideRowHeader="0" DisplayOutlines="1" OutlineSymbolsBelow="1" OutlineSymbolsRight="1" Visibility="GNM_SHEET_VISIBILITY_VISIBLE" GridColor="0:0:0">
338       <gnm:Name>Sheet1</gnm:Name>
339       <gnm:MaxCol>2</gnm:MaxCol>
340       <gnm:MaxRow>4</gnm:MaxRow>
341       <gnm:Styles>
342         <gnm:StyleRegion startCol="0" startRow="0" endCol="255" endRow="65535">
343           <gnm:Style HAlign="1" VAlign="2" WrapText="0" ShrinkToFit="0" Rotation="0" Shade="0" Indent="0" Locked="1" Hidden="0" Fore="0:0:0" Back="FFFF:FFFF:FFFF" PatternColor="0:0:0" Format="General">
344           </gnm:Style>
345         </gnm:StyleRegion>
346       </gnm:Styles>
347       <gnm:Cells>
348         <gnm:Cell Row="1" Col="1" ValueType="60">one</gnm:Cell>
349         <gnm:Cell Row="1" Col="2" ValueType="60">two</gnm:Cell>
350         <gnm:Cell Row="2" Col="1" ValueType="40">1</gnm:Cell>
351         <gnm:Cell Row="2" Col="2" ValueType="40">2</gnm:Cell>
352         <gnm:Cell Row="3" Col="1" ValueType="40">1</gnm:Cell>
353         <gnm:Cell Row="3" Col="2" ValueType="40">2</gnm:Cell>
354         <gnm:Cell Row="4" Col="1" ValueType="40">1</gnm:Cell>
355         <gnm:Cell Row="4" Col="2" ValueType="40">2</gnm:Cell>
356       </gnm:Cells>
357     </gnm:Sheet>
358   </gnm:Sheets>
359 </gnm:Workbook>
360 ])
361
362 AT_CHECK([pspp -O format=csv read.sps], [0], [ignore])
363
364
365 AT_CLEANUP
366
367
368
369 AT_BANNER([GET DATA Spreadsheet /TYPE=ODS])
370
371 CHECK_SPREADSHEET_READER([ODS])
372
373
374 AT_SETUP([GET DATA /TYPE=ODS crash])
375
376                      
377 AT_CHECK([cp $top_srcdir/tests/language/data-io/newone.ods this.ods])dnl
378
379 AT_DATA([crash.sps],[dnl
380 GET DATA /TYPE=ODS /FILE='this.ods' /CELLRANGE=RANGE 'A1:C8'  /READNAMES=ON
381 LIST.
382 ])
383
384 AT_CHECK([pspp -O format=csv crash.sps], [0], [ignore])
385
386 AT_CLEANUP
387
388
389 AT_SETUP([GET DATA /TYPE=ODS readnames])
390
391 dnl Check for a bug where in the ODS reader /READNAMES incorrectly
392 dnl dealt with repeated names.
393 AT_CHECK([cp $top_srcdir/tests/language/data-io/readnames.ods this.ods])dnl
394
395 AT_DATA([readnames.sps],[dnl
396 GET DATA /TYPE=ODS /FILE='this.ods' /CELLRANGE=RANGE 'A1:H8' /READNAMES=ON
397 DISPLAY DICTIONARY.
398 LIST.
399 ])
400
401
402 AT_CHECK([pspp -O format=csv readnames.sps], [0],
403 [Variable,Description,Position
404 freda,Format: F8.2,1
405 fred,Format: F8.2,2
406 fred_A,Format: F8.2,3
407 fred_B,Format: F8.2,4
408 fred_C,Format: F8.2,5
409 fred_D,Format: F8.2,6
410 fred_E,Format: F8.2,7
411
412 Table: Data List
413 freda,fred,fred_A,fred_B,fred_C,fred_D,fred_E
414 1.00,2.00,3.00,4.00,5.00,6.00,7.00
415 8.00,9.00,10.00,11.00,12.00,13.00,14.00
416 ])
417
418 AT_CLEANUP
419