
m4_define([SPREADSHEET_TEST_PREP],[dnl
 m4_if($1,[GNM],[dnl
    AT_CHECK([gzip -c $top_srcdir/tests/language/data-io/Book1.gnm.unzipped > Book1.gnumeric])dnl
    m4_define([testsheet],[Book1.gnumeric])dnl
    AT_SKIP_IF([test n$GNM_SUPPORT != nyes])dnl
    ]) dnl
 m4_if($1,[ODS],[dnl
    AT_CHECK([cp $top_srcdir/tests/language/data-io/test.ods test.ods])dnl
    m4_define([testsheet],[test.ods])dnl
    AT_SKIP_IF([test n$ODF_READ_SUPPORT != nyes])dnl
    ])dnl
])

m4_define([CHECK_SPREADSHEET_READER],
 [dnl
AT_SETUP([GET DATA /TYPE=$1 with CELLRANGE])
SPREADSHEET_TEST_PREP($1)
AT_DATA([get-data.sps], [dnl
GET DATA /TYPE=$1 /FILE='testsheet'  /READNAMES=off /SHEET=name 'This' /CELLRANGE=range 'g9:i13' .
DISPLAY VARIABLES.
LIST.
])
AT_CHECK([pspp -o pspp.csv get-data.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Variable,Description,,Position
VAR001,Format: F8.2,,1
,Measure: Scale,,
,Display Alignment: Right,,
,Display Width: 8,,
VAR002,Format: A8,,2
,Measure: Nominal,,
,Display Alignment: Left,,
,Display Width: 8,,
VAR003,Format: F8.2,,3
,Measure: Scale,,
,Display Alignment: Right,,
,Display Width: 8,,

Table: Data List
VAR001,VAR002,VAR003
.00,fred    ,20.00
1.00,11      ,21.00
2.00,twelve  ,22.00
3.00,13      ,23.00
4.00,14      ,24.00
])
AT_CLEANUP

AT_SETUP([GET DATA /TYPE=$1 with CELLRANGE and READNAMES])
SPREADSHEET_TEST_PREP($1)
AT_DATA([get-data.sps], [dnl
GET DATA /TYPE=$1 /FILE='testsheet'  /READNAMES=on /SHEET=name 'This' /CELLRANGE=range 'g8:i13' .
DISPLAY VARIABLES.
LIST.
])
AT_CHECK([pspp -o pspp.csv get-data.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Variable,Description,,Position
V1,Format: F8.2,,1
,Measure: Scale,,
,Display Alignment: Right,,
,Display Width: 8,,
V2,Format: A8,,2
,Measure: Nominal,,
,Display Alignment: Left,,
,Display Width: 8,,
VAR001,Format: F8.2,,3
,Measure: Scale,,
,Display Alignment: Right,,
,Display Width: 8,,

Table: Data List
V1,V2,VAR001
.00,fred    ,20.00
1.00,11      ,21.00
2.00,twelve  ,22.00
3.00,13      ,23.00
4.00,14      ,24.00
])
AT_CLEANUP

AT_SETUP([GET DATA /TYPE=$1 without CELLRANGE])
SPREADSHEET_TEST_PREP($1)
AT_DATA([get-data.sps], [dnl
GET DATA /TYPE=$1 /FILE='testsheet' /SHEET=index 3.
DISPLAY VARIABLES.
LIST.
])
AT_CHECK([pspp -o pspp.csv get-data.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Variable,Description,,Position
name,Format: A8,,1
,Measure: Nominal,,
,Display Alignment: Left,,
,Display Width: 8,,
id,Format: F8.2,,2
,Measure: Scale,,
,Display Alignment: Right,,
,Display Width: 8,,
height,Format: F8.2,,3
,Measure: Scale,,
,Display Alignment: Right,,
,Display Width: 8,,

Table: Data List
name,id,height
fred    ,.00,23.40
bert    ,1.00,.56
charlie ,2.00,.  @&t@
dick    ,3.00,-34.09
])
AT_CLEANUP

AT_SETUP([GET DATA /TYPE=$1 with missing data])
SPREADSHEET_TEST_PREP($1)
AT_DATA([get-data.sps], [dnl
* This sheet has no data in one of its variables
GET DATA /TYPE=$1 /FILE='testsheet' /READNAMES=on /SHEET=index 5.
DISPLAY VARIABLES.
LIST.
])
AT_CHECK([pspp -o pspp.csv get-data.sps])
AT_CHECK([cat pspp.csv], [0], [dnl
Variable,Description,,Position
vone,Format: F8.2,,1
,Measure: Scale,,
,Display Alignment: Right,,
,Display Width: 8,,
vtwo,Format: F8.2,,2
,Measure: Scale,,
,Display Alignment: Right,,
,Display Width: 8,,
vthree,Format: A8,,3
,Measure: Nominal,,
,Display Alignment: Left,,
,Display Width: 8,,
v4,Format: F8.2,,4
,Measure: Scale,,
,Display Alignment: Right,,
,Display Width: 8,,

Table: Data List
vone,vtwo,vthree,v4
1.00,3.00,,5.00
2.00,4.00,,6.00
])
AT_CLEANUP

AT_SETUP([GET DATA /TYPE=$1 with empty sheet])
SPREADSHEET_TEST_PREP($1)
AT_DATA([get-data.sps], [dnl
* This sheet is empty
GET DATA /TYPE=$1 /FILE='testsheet' /SHEET=name 'Empty'.
])
AT_CHECK([pspp -o pspp.csv get-data.sps], [0], [dnl
warning: Selected sheet or range of spreadsheet `testsheet' is empty.
])
AT_CLEANUP

AT_SETUP([GET DATA /TYPE=$1 with nonexistent sheet])
SPREADSHEET_TEST_PREP($1)
AT_DATA([get-data.sps], [dnl
* This sheet doesnt exist.
GET DATA /TYPE=$1 /FILE='testsheet' /SHEET=name 'foobarxx'.
])
AT_CHECK([pspp -o pspp.csv get-data.sps], [0], [dnl
warning: Selected sheet or range of spreadsheet `testsheet' is empty.
])
AT_CLEANUP
])


AT_BANNER([GET DATA Spreadsheet /TYPE=GNM])

CHECK_SPREADSHEET_READER([GNM])

AT_BANNER([GET DATA Spreadsheet /TYPE=ODS])

CHECK_SPREADSHEET_READER([ODS])

