~ubuntu-branches/ubuntu/wily/spatialite/wily-proposed

« back to all changes in this revision

Viewing changes to test/check_fdo1.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-07-14 11:57:46 UTC
  • mfrom: (16.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20150714115746-e2iljfmb5sq7o5hh
Tags: 4.3.0-1
Move from experimental to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
#include <geos_c.h>
58
58
#endif
59
59
 
60
 
int main (int argc, char *argv[])
 
60
static int
 
61
do_test (int legacy_mode)
61
62
{
62
 
#ifndef OMIT_GEOS       /* only if GEOS is supported */
 
63
#ifndef OMIT_GEOS               /* only if GEOS is supported */
63
64
    int ret;
64
65
    sqlite3 *handle;
65
66
    char *err_msg = NULL;
68
69
    char **results;
69
70
    int rows;
70
71
    int columns;
71
 
    void *cache = spatialite_alloc_connection();
72
 
 
73
 
    if (argc > 1 || argv[0] == NULL)
74
 
        argc = 1;               /* silencing stupid compiler warnings */
75
 
 
76
 
    ret = system("cp sql_stmt_tests/testFDO.sqlite testFDO.sqlite");
 
72
    void *cache = NULL;
 
73
    if (!legacy_mode)
 
74
        cache = spatialite_alloc_connection ();
 
75
    else
 
76
        spatialite_init (0);
 
77
 
 
78
    ret = system ("cp sql_stmt_tests/testFDO.sqlite testFDO.sqlite");
77
79
    if (ret != 0)
78
 
    {
79
 
        fprintf(stderr, "cannot copy testFDO.sqlite database\n");
80
 
        return -1001;
81
 
    }
82
 
 
83
 
    ret = sqlite3_open_v2 ("testFDO.sqlite", &handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
84
 
    if (ret != SQLITE_OK) {
85
 
        fprintf(stderr, "cannot open testFDO.sqlite db: %s\n", sqlite3_errmsg (handle));
86
 
        sqlite3_close(handle);
87
 
        return -1000;
88
 
    }
89
 
 
90
 
    spatialite_init_ex (handle, cache, 0);
 
80
      {
 
81
          fprintf (stderr, "cannot copy testFDO.sqlite database\n");
 
82
          return -1001;
 
83
      }
 
84
 
 
85
    ret =
 
86
        sqlite3_open_v2 ("testFDO.sqlite", &handle,
 
87
                         SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
 
88
    if (ret != SQLITE_OK)
 
89
      {
 
90
          fprintf (stderr, "cannot open testFDO.sqlite db: %s\n",
 
91
                   sqlite3_errmsg (handle));
 
92
          sqlite3_close (handle);
 
93
          return -1000;
 
94
      }
 
95
 
 
96
    if (!legacy_mode)
 
97
        spatialite_init_ex (handle, cache, 0);
91
98
 
92
99
/* FDO start-up */
93
100
    sql = "SELECT AutoFDOStart()";
94
101
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
95
 
    if (ret != SQLITE_OK) {
96
 
      fprintf (stderr, "Error: %s\n", err_msg);
97
 
      sqlite3_free (err_msg);
98
 
      return -1;
99
 
    }
 
102
    if (ret != SQLITE_OK)
 
103
      {
 
104
          fprintf (stderr, "Error: %s\n", err_msg);
 
105
          sqlite3_free (err_msg);
 
106
          return -1;
 
107
      }
100
108
 
101
109
/* testing aggregate Union() PointZ WKT "p02" */
102
110
    sql = "SELECT AsText(ST_Union(WKT_GEOMETRY)) FROM fdo_p02";
103
111
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
104
 
    if (ret != SQLITE_OK) {
105
 
      fprintf (stderr, "Error: %s\n", err_msg);
106
 
      sqlite3_free (err_msg);
107
 
      return -2;
108
 
    }
109
 
    if ((rows != 1) || (columns != 1)) {
110
 
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
111
 
      return -3;
112
 
    }
113
 
    if (results[1] == NULL) {
114
 
      fprintf (stderr, "Unexpected error: NULL result\n");
115
 
      return -4;
116
 
    } 
117
 
    if (strcmp(results[1], "MULTIPOINT Z(664350.17954 5171957.915655 314.52, 664642.363686 5169415.339218 294.37, 664964.447225 5170571.245732 318.25)") != 0) {        
118
 
          fprintf (stderr, "Unexpected error: invalid result |%s|\n", results[1]);
119
 
        return -5;
120
 
    }
 
112
    if (ret != SQLITE_OK)
 
113
      {
 
114
          fprintf (stderr, "Error: %s\n", err_msg);
 
115
          sqlite3_free (err_msg);
 
116
          return -2;
 
117
      }
 
118
    if ((rows != 1) || (columns != 1))
 
119
      {
 
120
          fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
 
121
                   columns);
 
122
          return -3;
 
123
      }
 
124
    if (results[1] == NULL)
 
125
      {
 
126
          fprintf (stderr, "Unexpected error: NULL result\n");
 
127
          return -4;
 
128
      }
 
129
    if (strcmp
 
130
        (results[1],
 
131
         "MULTIPOINT Z(664350.17954 5171957.915655 314.52, 664642.363686 5169415.339218 294.37, 664964.447225 5170571.245732 318.25)")
 
132
        != 0)
 
133
      {
 
134
          fprintf (stderr, "Unexpected error: invalid result %s\n", results[1]);
 
135
          return -5;
 
136
      }
121
137
    sqlite3_free_table (results);
122
138
 
123
139
/* testing aggregate Union() PointZ WKB "p03" */
124
 
    sql = "SELECT AsText(ST_Union(GEOMETRY)) FROM fdo_p03 WHERE text_dil IS NULL AND OGC_FID < 3";
 
140
    sql =
 
141
        "SELECT AsText(ST_Union(GEOMETRY)) FROM fdo_p03 WHERE text_dil IS NULL AND OGC_FID < 3";
125
142
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
126
 
    if (ret != SQLITE_OK) {
127
 
      fprintf (stderr, "Error: %s\n", err_msg);
128
 
      sqlite3_free (err_msg);
129
 
      return -6;
130
 
    }
131
 
    if ((rows != 1) || (columns != 1)) {
132
 
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
133
 
      return -7;
134
 
    }
135
 
    if (results[1] == NULL) {
136
 
      fprintf (stderr, "Unexpected error: NULL result\n");
137
 
      return -8;
138
 
    } 
139
 
    if (strcmp(results[1], "MULTIPOINT Z(665216.306643 5169825.707161 296.06, 665224.506512 5169827.907054 296.16)") != 0) {        
140
 
          fprintf (stderr, "Unexpected error: invalid result |%s|\n", results[1]);
141
 
        return -9;
142
 
    }
 
143
    if (ret != SQLITE_OK)
 
144
      {
 
145
          fprintf (stderr, "Error: %s\n", err_msg);
 
146
          sqlite3_free (err_msg);
 
147
          return -6;
 
148
      }
 
149
    if ((rows != 1) || (columns != 1))
 
150
      {
 
151
          fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
 
152
                   columns);
 
153
          return -7;
 
154
      }
 
155
    if (results[1] == NULL)
 
156
      {
 
157
          fprintf (stderr, "Unexpected error: NULL result\n");
 
158
          return -8;
 
159
      }
 
160
    if (strcmp
 
161
        (results[1],
 
162
         "MULTIPOINT Z(665216.306643 5169825.707161 296.06, 665224.506512 5169827.907054 296.16)")
 
163
        != 0)
 
164
      {
 
165
          fprintf (stderr, "Unexpected error: invalid result |%s|\n",
 
166
                   results[1]);
 
167
          return -9;
 
168
      }
143
169
    sqlite3_free_table (results);
144
170
 
145
171
/* testing aggregate Union() PointZ SpatiaLite "p05" */
146
 
    sql = "SELECT AsText(ST_Union(GEOMETRY)) FROM fdo_p05 WHERE text_dil IS NULL AND OGC_FID < 3";
 
172
    sql =
 
173
        "SELECT AsText(ST_Union(GEOMETRY)) FROM fdo_p05 WHERE text_dil IS NULL AND OGC_FID < 3";
147
174
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
148
 
    if (ret != SQLITE_OK) {
149
 
      fprintf (stderr, "Error: %s\n", err_msg);
150
 
      sqlite3_free (err_msg);
151
 
      return -10;
152
 
    }
153
 
    if ((rows != 1) || (columns != 1)) {
154
 
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
155
 
      return -11;
156
 
    }
157
 
    if (results[1] == NULL) {
158
 
      fprintf (stderr, "Unexpected error: NULL result |%s|\n", results[1]);
159
 
      return -12;
160
 
    }
161
 
    if (strcmp(results[1], "MULTIPOINT Z(667687.978175 5169352.045712 583.140015, 667710.008189 5169402.894615 589.849976)") != 0) {        
162
 
          fprintf (stderr, "Unexpected error: invalid result b|%s|\n", results[1]);
163
 
          return -13;
164
 
    }
 
175
    if (ret != SQLITE_OK)
 
176
      {
 
177
          fprintf (stderr, "Error: %s\n", err_msg);
 
178
          sqlite3_free (err_msg);
 
179
          return -10;
 
180
      }
 
181
    if ((rows != 1) || (columns != 1))
 
182
      {
 
183
          fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
 
184
                   columns);
 
185
          return -11;
 
186
      }
 
187
    if (results[1] == NULL)
 
188
      {
 
189
          fprintf (stderr, "Unexpected error: NULL result %s\n", results[1]);
 
190
          return -12;
 
191
      }
 
192
    if (strcmp
 
193
        (results[1],
 
194
         "MULTIPOINT Z(667687.978175 5169352.045712 583.140015, 667710.008189 5169402.894615 589.849976)")
 
195
        != 0)
 
196
      {
 
197
          fprintf (stderr, "Unexpected error: invalid result b|%s|\n",
 
198
                   results[1]);
 
199
          return -13;
 
200
      }
165
201
    sqlite3_free_table (results);
166
202
 
167
203
/* testing Sum(GLength()) LinestringZ WKT "l05" */
168
204
    sql = "SELECT Sum(GLength(WKT_GEOMETRY)) FROM fdo_l05";
169
205
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
170
 
    if (ret != SQLITE_OK) {
171
 
      fprintf (stderr, "Error: %s\n", err_msg);
172
 
      sqlite3_free (err_msg);
173
 
      return -14;
174
 
    }
175
 
    if ((rows != 1) || (columns != 1)) {
176
 
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
177
 
      return -15;
178
 
    }
179
 
    if (results[1] == NULL) {
180
 
      fprintf (stderr, "Unexpected error: NULL result\n");
181
 
      return -16;
182
 
    }
183
 
    if (strncmp(results[1], "59.417763", 9) != 0) {        
184
 
      fprintf (stderr, "Unexpected error: invalid result\n");
185
 
      return -17;
186
 
    }
 
206
    if (ret != SQLITE_OK)
 
207
      {
 
208
          fprintf (stderr, "Error: %s\n", err_msg);
 
209
          sqlite3_free (err_msg);
 
210
          return -14;
 
211
      }
 
212
    if ((rows != 1) || (columns != 1))
 
213
      {
 
214
          fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
 
215
                   columns);
 
216
          return -15;
 
217
      }
 
218
    if (results[1] == NULL)
 
219
      {
 
220
          fprintf (stderr, "Unexpected error: NULL result\n");
 
221
          return -16;
 
222
      }
 
223
    if (strncmp (results[1], "59.417763", 9) != 0)
 
224
      {
 
225
          fprintf (stderr, "Unexpected error: invalid result\n");
 
226
          return -17;
 
227
      }
187
228
    sqlite3_free_table (results);
188
229
 
189
230
/* testing Sum(GLength()) LinestringZ WKB "l06" */
190
231
    sql = "SELECT Sum(GLength(GEOMETRY)) FROM fdo_l06";
191
232
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
192
 
    if (ret != SQLITE_OK) {
193
 
      fprintf (stderr, "Error: %s\n", err_msg);
194
 
      sqlite3_free (err_msg);
195
 
      return -18;
196
 
    }
197
 
    if ((rows != 1) || (columns != 1)) {
198
 
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
199
 
      return -19;
200
 
    }
201
 
    if (results[1] == NULL) {
202
 
      fprintf (stderr, "Unexpected error: NULL result\n");
203
 
      return -20;
204
 
    }
205
 
    if (strncmp(results[1], "273.076064", 10) != 0) {        
206
 
      fprintf (stderr, "Unexpected error: invalid result\n");
207
 
      return -21;
208
 
    }
 
233
    if (ret != SQLITE_OK)
 
234
      {
 
235
          fprintf (stderr, "Error: %s\n", err_msg);
 
236
          sqlite3_free (err_msg);
 
237
          return -18;
 
238
      }
 
239
    if ((rows != 1) || (columns != 1))
 
240
      {
 
241
          fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
 
242
                   columns);
 
243
          return -19;
 
244
      }
 
245
    if (results[1] == NULL)
 
246
      {
 
247
          fprintf (stderr, "Unexpected error: NULL result\n");
 
248
          return -20;
 
249
      }
 
250
    if (strncmp (results[1], "273.076064", 10) != 0)
 
251
      {
 
252
          fprintf (stderr, "Unexpected error: invalid result\n");
 
253
          return -21;
 
254
      }
209
255
    sqlite3_free_table (results);
210
256
 
211
257
/* testing Sum(GLength()) LinestringZ SpatiaLite "l07" */
212
258
    sql = "SELECT Sum(GLength(GEOMETRY)) FROM fdo_l07";
213
259
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
214
 
    if (ret != SQLITE_OK) {
215
 
      fprintf (stderr, "Error: %s\n", err_msg);
216
 
      sqlite3_free (err_msg);
217
 
      return -22;
218
 
    }
219
 
    if ((rows != 1) || (columns != 1)) {
220
 
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
221
 
      return -23;
222
 
    }
223
 
    if (results[1] == NULL) {
224
 
      fprintf (stderr, "Unexpected error: NULL result\n");
225
 
      return -24;
226
 
    }
227
 
    if (strncmp(results[1], "219.459808", 10) != 0) {        
228
 
      fprintf (stderr, "Unexpected error: invalid result\n");
229
 
      return -25;
230
 
    }
 
260
    if (ret != SQLITE_OK)
 
261
      {
 
262
          fprintf (stderr, "Error: %s\n", err_msg);
 
263
          sqlite3_free (err_msg);
 
264
          return -22;
 
265
      }
 
266
    if ((rows != 1) || (columns != 1))
 
267
      {
 
268
          fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
 
269
                   columns);
 
270
          return -23;
 
271
      }
 
272
    if (results[1] == NULL)
 
273
      {
 
274
          fprintf (stderr, "Unexpected error: NULL result\n");
 
275
          return -24;
 
276
      }
 
277
    if (strncmp (results[1], "219.459808", 10) != 0)
 
278
      {
 
279
          fprintf (stderr, "Unexpected error: invalid result\n");
 
280
          return -25;
 
281
      }
231
282
    sqlite3_free_table (results);
232
283
 
233
284
/* testing Sum(Area()) PolygonZ WKT "f04" */
234
285
    sql = "SELECT Sum(Area(WKT_GEOMETRY)) FROM fdo_f04";
235
286
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
236
 
    if (ret != SQLITE_OK) {
237
 
      fprintf (stderr, "Error: %s\n", err_msg);
238
 
      sqlite3_free (err_msg);
239
 
      return -26;
240
 
    }
241
 
    if ((rows != 1) || (columns != 1)) {
242
 
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
243
 
      return -27;
244
 
    }
245
 
    if (results[1] == NULL) {
246
 
      fprintf (stderr, "Unexpected error: NULL result\n");
247
 
      return -28;
248
 
    }
249
 
    if (strncmp(results[1], "9960.931239", 11) != 0) {        
250
 
      fprintf (stderr, "Unexpected error: invalid result\n");
251
 
      return -29;
252
 
    }
 
287
    if (ret != SQLITE_OK)
 
288
      {
 
289
          fprintf (stderr, "Error: %s\n", err_msg);
 
290
          sqlite3_free (err_msg);
 
291
          return -26;
 
292
      }
 
293
    if ((rows != 1) || (columns != 1))
 
294
      {
 
295
          fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
 
296
                   columns);
 
297
          return -27;
 
298
      }
 
299
    if (results[1] == NULL)
 
300
      {
 
301
          fprintf (stderr, "Unexpected error: NULL result\n");
 
302
          return -28;
 
303
      }
 
304
    if (strncmp (results[1], "9960.931239", 11) != 0)
 
305
      {
 
306
          fprintf (stderr, "Unexpected error: invalid result\n");
 
307
          return -29;
 
308
      }
253
309
    sqlite3_free_table (results);
254
310
 
255
311
/* testing Sum(Area()) PolygonZ WKB "f05" */
256
312
    sql = "SELECT Sum(Area(GEOMETRY)) FROM fdo_f05";
257
313
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
258
 
    if (ret != SQLITE_OK) {
259
 
      fprintf (stderr, "Error: %s\n", err_msg);
260
 
      sqlite3_free (err_msg);
261
 
      return -30;
262
 
    }
263
 
    if ((rows != 1) || (columns != 1)) {
264
 
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
265
 
      return -31;
266
 
    }
267
 
    if (results[1] == NULL) {
268
 
      fprintf (stderr, "Unexpected error: NULL result\n");
269
 
      return -32;
270
 
    }
271
 
    if (strncmp(results[1], "69972.113393", 12) != 0) {        
272
 
      fprintf (stderr, "Unexpected error: invalid result\n");
273
 
      return -33;
274
 
    }
 
314
    if (ret != SQLITE_OK)
 
315
      {
 
316
          fprintf (stderr, "Error: %s\n", err_msg);
 
317
          sqlite3_free (err_msg);
 
318
          return -30;
 
319
      }
 
320
    if ((rows != 1) || (columns != 1))
 
321
      {
 
322
          fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
 
323
                   columns);
 
324
          return -31;
 
325
      }
 
326
    if (results[1] == NULL)
 
327
      {
 
328
          fprintf (stderr, "Unexpected error: NULL result\n");
 
329
          return -32;
 
330
      }
 
331
    if (strncmp (results[1], "69972.113393", 12) != 0)
 
332
      {
 
333
          fprintf (stderr, "Unexpected error: invalid result\n");
 
334
          return -33;
 
335
      }
275
336
    sqlite3_free_table (results);
276
337
 
277
338
/* testing Sum(Area()) PolygonZ SpatiaLite "f06" */
278
339
    sql = "SELECT Sum(Area(GEOMETRY)) FROM fdo_f06";
279
340
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
280
 
    if (ret != SQLITE_OK) {
281
 
      fprintf (stderr, "Error: %s\n", err_msg);
282
 
      sqlite3_free (err_msg);
283
 
      return -34;
284
 
    }
285
 
    if ((rows != 1) || (columns != 1)) {
286
 
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
287
 
      return -35;
288
 
    }
289
 
    if (results[1] == NULL) {
290
 
      fprintf (stderr, "Unexpected error: NULL result\n");
291
 
      return -36;
292
 
    }
293
 
    if (strncmp(results[1], "1125.064396", 11) != 0) {        
294
 
      fprintf (stderr, "Unexpected error: invalid result\n");
295
 
      return -37;
296
 
    }
 
341
    if (ret != SQLITE_OK)
 
342
      {
 
343
          fprintf (stderr, "Error: %s\n", err_msg);
 
344
          sqlite3_free (err_msg);
 
345
          return -34;
 
346
      }
 
347
    if ((rows != 1) || (columns != 1))
 
348
      {
 
349
          fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
 
350
                   columns);
 
351
          return -35;
 
352
      }
 
353
    if (results[1] == NULL)
 
354
      {
 
355
          fprintf (stderr, "Unexpected error: NULL result\n");
 
356
          return -36;
 
357
      }
 
358
    if (strncmp (results[1], "1125.064396", 11) != 0)
 
359
      {
 
360
          fprintf (stderr, "Unexpected error: invalid result\n");
 
361
          return -37;
 
362
      }
297
363
    sqlite3_free_table (results);
298
364
 
299
365
/* testing IsValid() LinestringZ WKB "l06" */
300
366
    sql = "SELECT IsValid(GEOMETRY) FROM fdo_l06";
301
367
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
302
 
    if (ret != SQLITE_OK) {
303
 
      fprintf (stderr, "Error: %s\n", err_msg);
304
 
      sqlite3_free (err_msg);
305
 
      return -38;
306
 
    }
307
 
    if ((rows != 12) || (columns != 1)) {
308
 
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
309
 
      return -39;
310
 
    }
 
368
    if (ret != SQLITE_OK)
 
369
      {
 
370
          fprintf (stderr, "Error: %s\n", err_msg);
 
371
          sqlite3_free (err_msg);
 
372
          return -38;
 
373
      }
 
374
    if ((rows != 12) || (columns != 1))
 
375
      {
 
376
          fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
 
377
                   columns);
 
378
          return -39;
 
379
      }
311
380
    for (i = 1; i <= rows; i++)
312
 
    {
313
 
      if (results[i] == NULL) {
314
 
        fprintf (stderr, "Unexpected error: NULL result\n");
315
 
        return -40;
316
 
      }
317
 
      if (strcmp(results[i], "0") == 0) {
318
 
        const char *geos_msg = gaiaGetGeosErrorMsg();
319
 
        if (geos_msg == NULL)
320
 
          geos_msg = gaiaGetGeosWarningMsg();
321
 
        if (geos_msg == NULL) {
322
 
          fprintf (stderr, "Unexpected error: invalid result\n");
323
 
          return -41;
324
 
        }
325
 
      }
326
 
    }
 
381
      {
 
382
          if (results[i] == NULL)
 
383
            {
 
384
                fprintf (stderr, "Unexpected error: NULL result\n");
 
385
                return -40;
 
386
            }
 
387
          if (strcmp (results[i], "0") == 0)
 
388
            {
 
389
                const char *geos_msg;
 
390
                if (legacy_mode)
 
391
                    geos_msg = gaiaGetGeosErrorMsg ();
 
392
                else
 
393
                    geos_msg = gaiaGetGeosErrorMsg_r (cache);
 
394
                if (geos_msg == NULL)
 
395
                  {
 
396
                      if (legacy_mode)
 
397
                          geos_msg = gaiaGetGeosWarningMsg ();
 
398
                      else
 
399
                          geos_msg = gaiaGetGeosWarningMsg_r (cache);
 
400
                  }
 
401
                if (geos_msg == NULL)
 
402
                  {
 
403
                      fprintf (stderr, "Unexpected error: invalid result\n");
 
404
                      return -41;
 
405
                  }
 
406
            }
 
407
      }
327
408
    sqlite3_free_table (results);
328
409
 
329
410
/* testing IsValid() PolygonZ WKT "f04" */
330
411
    sql = "SELECT IsValid(WKT_GEOMETRY) FROM fdo_f04";
331
412
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
332
 
    if (ret != SQLITE_OK) {
333
 
      fprintf (stderr, "Error: %s\n", err_msg);
334
 
      sqlite3_free (err_msg);
335
 
      return -42;
336
 
    }
337
 
    if ((rows != 16) || (columns != 1)) {
338
 
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
339
 
      return -43;
340
 
    }
 
413
    if (ret != SQLITE_OK)
 
414
      {
 
415
          fprintf (stderr, "Error: %s\n", err_msg);
 
416
          sqlite3_free (err_msg);
 
417
          return -42;
 
418
      }
 
419
    if ((rows != 16) || (columns != 1))
 
420
      {
 
421
          fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
 
422
                   columns);
 
423
          return -43;
 
424
      }
341
425
    for (i = 1; i <= rows; i++)
342
 
    {
343
 
      if (results[i] == NULL) {
344
 
        fprintf (stderr, "Unexpected error: NULL result\n");
345
 
        return -44;
346
 
      }
347
 
      if (strcmp(results[i], "0") == 0) {
348
 
        const char *geos_msg = gaiaGetGeosErrorMsg();
349
 
        if (geos_msg == NULL)
350
 
          geos_msg = gaiaGetGeosWarningMsg();
351
 
        if (geos_msg == NULL) {
352
 
          fprintf (stderr, "Unexpected error: invalid result\n");
353
 
          return -45;
354
 
        }
355
 
      }
356
 
    }
 
426
      {
 
427
          if (results[i] == NULL)
 
428
            {
 
429
                fprintf (stderr, "Unexpected error: NULL result\n");
 
430
                return -44;
 
431
            }
 
432
          if (strcmp (results[i], "0") == 0)
 
433
            {
 
434
                const char *geos_msg;
 
435
                if (legacy_mode)
 
436
                    geos_msg = gaiaGetGeosErrorMsg ();
 
437
                else
 
438
                    geos_msg = gaiaGetGeosErrorMsg_r (cache);
 
439
                if (geos_msg == NULL)
 
440
                  {
 
441
                      if (legacy_mode)
 
442
                          geos_msg = gaiaGetGeosWarningMsg ();
 
443
                      else
 
444
                          geos_msg = gaiaGetGeosWarningMsg_r (cache);
 
445
                  }
 
446
                if (geos_msg == NULL)
 
447
                  {
 
448
                      fprintf (stderr, "Unexpected error: invalid result\n");
 
449
                      return -45;
 
450
                  }
 
451
            }
 
452
      }
357
453
    sqlite3_free_table (results);
358
454
 
359
455
/* testing IsValid() PolygonZ WKB "f05" */
360
456
    sql = "SELECT IsValid(GEOMETRY) FROM fdo_f05";
361
457
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
362
 
    if (ret != SQLITE_OK) {
363
 
      fprintf (stderr, "Error: %s\n", err_msg);
364
 
      sqlite3_free (err_msg);
365
 
      return -46;
366
 
    }
367
 
    if ((rows != 13) || (columns != 1)) {
368
 
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
369
 
      return -47;
370
 
    }
 
458
    if (ret != SQLITE_OK)
 
459
      {
 
460
          fprintf (stderr, "Error: %s\n", err_msg);
 
461
          sqlite3_free (err_msg);
 
462
          return -46;
 
463
      }
 
464
    if ((rows != 13) || (columns != 1))
 
465
      {
 
466
          fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
 
467
                   columns);
 
468
          return -47;
 
469
      }
371
470
    for (i = 1; i <= rows; i++)
372
 
    {
373
 
      if (results[i] == NULL) {
374
 
        fprintf (stderr, "Unexpected error: NULL result\n");
375
 
        return -48;
376
 
      }
377
 
      if (strcmp(results[i], "0") == 0) {
378
 
        const char *geos_msg = gaiaGetGeosErrorMsg();
379
 
        if (geos_msg == NULL)
380
 
          geos_msg = gaiaGetGeosWarningMsg();
381
 
        if (geos_msg == NULL) {
382
 
          fprintf (stderr, "Unexpected error: invalid result\n");
383
 
          return -49;
384
 
        }
385
 
      }
386
 
    }
 
471
      {
 
472
          if (results[i] == NULL)
 
473
            {
 
474
                fprintf (stderr, "Unexpected error: NULL result\n");
 
475
                return -48;
 
476
            }
 
477
          if (strcmp (results[i], "0") == 0)
 
478
            {
 
479
                const char *geos_msg;
 
480
                if (legacy_mode)
 
481
                    geos_msg = gaiaGetGeosErrorMsg ();
 
482
                else
 
483
                    geos_msg = gaiaGetGeosErrorMsg_r (cache);
 
484
                if (geos_msg == NULL)
 
485
                  {
 
486
                      if (legacy_mode)
 
487
                          geos_msg = gaiaGetGeosWarningMsg ();
 
488
                      else
 
489
                          geos_msg = gaiaGetGeosWarningMsg_r (cache);
 
490
                  }
 
491
                if (geos_msg == NULL)
 
492
                  {
 
493
                      fprintf (stderr, "Unexpected error: invalid result\n");
 
494
                      return -49;
 
495
                  }
 
496
            }
 
497
      }
387
498
    sqlite3_free_table (results);
388
499
 
389
500
/* testing DOUBLE and TEXT columns */
390
501
    sql = "SELECT datum, hoehe FROM fdo_p05 WHERE OGC_FID = 5";
391
502
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
392
 
    if (ret != SQLITE_OK) {
393
 
      fprintf (stderr, "Error: %s\n", err_msg);
394
 
      sqlite3_free (err_msg);
395
 
      return -50;
396
 
    }
397
 
    if ((rows != 1) || (columns != 2)) {
398
 
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
399
 
      return -51;
400
 
    }
401
 
    if (results[2] == NULL) {
402
 
      fprintf (stderr, "Unexpected error: NULL result\n");
403
 
      return -52;
404
 
    }
405
 
    if (strcmp(results[2], "1997/03/07") != 0) {
406
 
      fprintf (stderr, "Unexpected error: invalid result\n");
407
 
      return -53;
408
 
    }
409
 
    if (results[3] == NULL) {
410
 
      fprintf (stderr, "Unexpected error: NULL result\n");
411
 
      return -54;
412
 
    }
413
 
    if (strcmp(results[3], "277.55") != 0) {
414
 
      fprintf (stderr, "Unexpected error: invalid result\n");
415
 
      return -54;
416
 
    }
 
503
    if (ret != SQLITE_OK)
 
504
      {
 
505
          fprintf (stderr, "Error: %s\n", err_msg);
 
506
          sqlite3_free (err_msg);
 
507
          return -50;
 
508
      }
 
509
    if ((rows != 1) || (columns != 2))
 
510
      {
 
511
          fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
 
512
                   columns);
 
513
          return -51;
 
514
      }
 
515
    if (results[2] == NULL)
 
516
      {
 
517
          fprintf (stderr, "Unexpected error: NULL result\n");
 
518
          return -52;
 
519
      }
 
520
    if (strcmp (results[2], "1997/03/07") != 0)
 
521
      {
 
522
          fprintf (stderr, "Unexpected error: invalid result\n");
 
523
          return -53;
 
524
      }
 
525
    if (results[3] == NULL)
 
526
      {
 
527
          fprintf (stderr, "Unexpected error: NULL result\n");
 
528
          return -54;
 
529
      }
 
530
    if (strcmp (results[3], "277.55") != 0)
 
531
      {
 
532
          fprintf (stderr, "Unexpected error: invalid result\n");
 
533
          return -54;
 
534
      }
417
535
    sqlite3_free_table (results);
418
536
 
419
537
/* FDO shut-down */
420
538
    sql = "SELECT AutoFDOStop()";
421
539
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
422
 
    if (ret != SQLITE_OK) {
423
 
      fprintf (stderr, "Error: %s\n", err_msg);
424
 
      sqlite3_free (err_msg);
425
 
      return -55;
426
 
    }
 
540
    if (ret != SQLITE_OK)
 
541
      {
 
542
          fprintf (stderr, "Error: %s\n", err_msg);
 
543
          sqlite3_free (err_msg);
 
544
          return -55;
 
545
      }
427
546
 
428
547
    ret = sqlite3_close (handle);
429
 
    if (ret != SQLITE_OK) {
430
 
        fprintf (stderr, "sqlite3_close() error: %s\n", sqlite3_errmsg (handle));
431
 
        return -56;
432
 
    }
433
 
    
 
548
    if (ret != SQLITE_OK)
 
549
      {
 
550
          fprintf (stderr, "sqlite3_close() error: %s\n",
 
551
                   sqlite3_errmsg (handle));
 
552
          return -56;
 
553
      }
 
554
 
434
555
    spatialite_cleanup_ex (cache);
435
 
    ret = unlink("testFDO.sqlite");
436
 
    if (ret != 0)
437
 
    {
438
 
        fprintf(stderr, "cannot remove testFDO database\n");
439
 
        return -57;
440
 
    }
441
 
#endif  /* end GEOS conditional */
442
 
    
 
556
    ret = unlink ("testFDO.sqlite");
 
557
    if (ret != 0)
 
558
      {
 
559
          fprintf (stderr, "cannot remove testFDO database\n");
 
560
          return -57;
 
561
      }
 
562
#endif /* end GEOS conditional */
 
563
 
 
564
    return 0;
 
565
}
 
566
 
 
567
int
 
568
main (int argc, char *argv[])
 
569
{
 
570
    int ret;
 
571
 
 
572
    if (argc > 1 || argv[0] == NULL)
 
573
        argc = 1;               /* silencing stupid compiler warnings */
 
574
 
 
575
    fprintf (stderr, "********* testing in current mode\n");
 
576
    ret = do_test (0);
 
577
    if (ret != 0)
 
578
        return ret;
 
579
 
 
580
    fprintf (stderr, "********* testing in legacy mode\n");
 
581
    ret = do_test (1);
 
582
    if (ret != 0)
 
583
        return ret;
 
584
 
 
585
    spatialite_shutdown ();
443
586
    return 0;
444
587
}