Added support for reading Gnumeric spreadsheet files.
[pspp-builds.git] / tests / command / get-data-gnm.sh
1 #!/bin/sh
2
3 # This program tests that pspp can read gnumeric files
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
7
8 # ensure that top_srcdir and top_builddir  are absolute
9 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
10 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
11 top_srcdir=`cd $top_srcdir; pwd`
12 top_builddir=`cd $top_builddir; pwd`
13
14 PSPP=$top_builddir/src/ui/terminal/pspp
15
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
18
19 LANG=C
20 export LANG
21
22
23 cleanup()
24 {
25      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
26         echo "NOT cleaning $TEMPDIR"
27         return ; 
28      fi
29      rm -rf $TEMPDIR
30 }
31
32
33 fail()
34 {
35     echo $activity
36     echo FAILED
37     cleanup;
38     exit 1;
39 }
40
41
42 no_result()
43 {
44     echo $activity
45     echo NO RESULT;
46     cleanup;
47     exit 2;
48 }
49
50 pass()
51 {
52     cleanup;
53     exit 0;
54 }
55
56 mkdir -p $TEMPDIR
57
58 cd $TEMPDIR
59
60 activity="zip the gnm file and place it in the test directory"
61 gzip -c $top_srcdir/tests/Book1.gnm.unzipped > $TEMPDIR/Book1.gnumeric
62 if [ $? -ne 0 ] ; then no_result ; fi
63
64 activity="create program 1"
65 cat > $TESTFILE <<EOF
66 GET DATA /TYPE=gnm /FILE='$TEMPDIR/Book1.gnumeric'  /READNAMES=off /SHEET=name 'This' /CELLRANGE=range 'g9:i13' .
67 DISPLAY VARIABLES.
68 LIST.
69
70
71 GET DATA /TYPE=gnm /FILE='$TEMPDIR/Book1.gnumeric'  /READNAMES=on /SHEET=name 'This' /CELLRANGE=range 'g8:i13' .
72 DISPLAY VARIABLES.
73 LIST.
74
75
76 GET DATA /TYPE=gnm /FILE='$TEMPDIR/Book1.gnumeric' /SHEET=index 3.
77 DISPLAY VARIABLES.
78 LIST.
79
80 * This sheet has no data in one of its variables
81 GET DATA /TYPE=gnm /FILE='$TEMPDIR/Book1.gnumeric' /READNAMES=on /SHEET=index 5.
82 DISPLAY VARIABLES.
83 LIST.
84
85 EOF
86 if [ $? -ne 0 ] ; then no_result ; fi
87
88 activity="run program 1"
89 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
90 if [ $? -ne 0 ] ; then no_result ; fi
91
92
93 activity="compare output 1"
94 diff $TEMPDIR/pspp.list - <<EOF
95 1.1 DISPLAY.  
96 +--------+-------------------------------------------+--------+
97 |Variable|Description                                |Position|
98 #========#===========================================#========#
99 |var1    |Format: F8.2                               |       1|
100 |        |Measure: Scale                             |        |
101 |        |Display Alignment: Right                   |        |
102 |        |Display Width: 8                           |        |
103 +--------+-------------------------------------------+--------+
104 |var2    |Format: A8                                 |       2|
105 |        |Measure: Nominal                           |        |
106 |        |Display Alignment: Left                    |        |
107 |        |Display Width: 8                           |        |
108 +--------+-------------------------------------------+--------+
109 |var3    |Format: F8.2                               |       3|
110 |        |Measure: Scale                             |        |
111 |        |Display Alignment: Right                   |        |
112 |        |Display Width: 8                           |        |
113 +--------+-------------------------------------------+--------+
114
115     var1     var2     var3
116 -------- -------- --------
117      .00 fred        20.00 
118     1.00 11          21.00 
119     2.00 twelve      22.00 
120     3.00 13          23.00 
121     4.00 14          24.00 
122
123 2.1 DISPLAY.  
124 +--------+-------------------------------------------+--------+
125 |Variable|Description                                |Position|
126 #========#===========================================#========#
127 |V1      |Format: F8.2                               |       1|
128 |        |Measure: Scale                             |        |
129 |        |Display Alignment: Right                   |        |
130 |        |Display Width: 8                           |        |
131 +--------+-------------------------------------------+--------+
132 |V2      |Format: A8                                 |       2|
133 |        |Measure: Nominal                           |        |
134 |        |Display Alignment: Left                    |        |
135 |        |Display Width: 8                           |        |
136 +--------+-------------------------------------------+--------+
137 |var1    |Format: F8.2                               |       3|
138 |        |Measure: Scale                             |        |
139 |        |Display Alignment: Right                   |        |
140 |        |Display Width: 8                           |        |
141 +--------+-------------------------------------------+--------+
142
143       V1       V2     var1
144 -------- -------- --------
145      .00 fred        20.00 
146     1.00 11          21.00 
147     2.00 twelve      22.00 
148     3.00 13          23.00 
149     4.00 14          24.00 
150
151 3.1 DISPLAY.  
152 +--------+-------------------------------------------+--------+
153 |Variable|Description                                |Position|
154 #========#===========================================#========#
155 |name    |Format: A8                                 |       1|
156 |        |Measure: Nominal                           |        |
157 |        |Display Alignment: Left                    |        |
158 |        |Display Width: 8                           |        |
159 +--------+-------------------------------------------+--------+
160 |id      |Format: F8.2                               |       2|
161 |        |Measure: Scale                             |        |
162 |        |Display Alignment: Right                   |        |
163 |        |Display Width: 8                           |        |
164 +--------+-------------------------------------------+--------+
165 |height  |Format: F8.2                               |       3|
166 |        |Measure: Scale                             |        |
167 |        |Display Alignment: Right                   |        |
168 |        |Display Width: 8                           |        |
169 +--------+-------------------------------------------+--------+
170
171     name       id   height
172 -------- -------- --------
173 fred          .00    23.40 
174 bert         1.00      .56 
175 charlie      2.00      .   
176 dick         3.00   -34.09 
177
178 4.1 DISPLAY.  
179 +--------+-------------------------------------------+--------+
180 |Variable|Description                                |Position|
181 #========#===========================================#========#
182 |vone    |Format: F8.2                               |       1|
183 |        |Measure: Scale                             |        |
184 |        |Display Alignment: Right                   |        |
185 |        |Display Width: 8                           |        |
186 +--------+-------------------------------------------+--------+
187 |vtwo    |Format: F8.2                               |       2|
188 |        |Measure: Scale                             |        |
189 |        |Display Alignment: Right                   |        |
190 |        |Display Width: 8                           |        |
191 +--------+-------------------------------------------+--------+
192 |vthree  |Format: A8                                 |       3|
193 |        |Measure: Nominal                           |        |
194 |        |Display Alignment: Left                    |        |
195 |        |Display Width: 8                           |        |
196 +--------+-------------------------------------------+--------+
197 |v4      |Format: F8.2                               |       4|
198 |        |Measure: Scale                             |        |
199 |        |Display Alignment: Right                   |        |
200 |        |Display Width: 8                           |        |
201 +--------+-------------------------------------------+--------+
202
203     vone     vtwo   vthree       v4
204 -------- -------- -------- --------
205     1.00     3.00              5.00 
206     2.00     4.00              6.00 
207
208 EOF
209 if [ $? -ne 0 ] ; then fail ; fi
210
211
212 activity="create program 2"
213 cat > $TESTFILE <<EOF
214 * This sheet is empty
215 GET DATA /TYPE=gnm /FILE='$TEMPDIR/Book1.gnumeric' /SHEET=name 'Empty'.
216
217
218 * This sheet doesnt exist
219 GET DATA /TYPE=gnm /FILE='$TEMPDIR/Book1.gnumeric' /SHEET=name 'foobarxx'.
220
221 EOF
222 if [ $? -ne 0 ] ; then no_result ; fi
223
224 activity="run program 2"
225 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE > /dev/null
226 if [ $? -ne 0 ] ; then fail ; fi
227
228 activity="compare output 2"
229 diff $TEMPDIR/pspp.list - <<EOF
230 warning: Selected sheet or range of spreadsheet "$TEMPDIR/Book1.gnumeric" is empty.
231 warning: Selected sheet or range of spreadsheet "$TEMPDIR/Book1.gnumeric" is empty.
232
233 EOF
234 if [ $? -ne 0 ] ; then fail ; fi
235
236 pass;