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

« back to all changes in this revision

Viewing changes to test/check_gpkgCreateTilesZoomLevel.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:
 
1
/*
 
2
 
 
3
 check_gpkgCreateTilesZoomLevel.c - Test case for GeoPackage Extensions
 
4
 
 
5
 Author: Brad Hards <bradh@frogmouth.net>
 
6
 
 
7
 ------------------------------------------------------------------------------
 
8
 
 
9
 Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
10
 
 
11
 The contents of this file are subject to the Mozilla Public License Version
 
12
 1.1 (the "License"); you may not use this file except in compliance with
 
13
 the License. You may obtain a copy of the License at
 
14
 http://www.mozilla.org/MPL/
 
15
 
 
16
Software distributed under the License is distributed on an "AS IS" basis,
 
17
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
18
for the specific language governing rights and limitations under the
 
19
License.
 
20
 
 
21
The Original Code is GeoPackage extensions
 
22
 
 
23
The Initial Developer of the Original Code is Brad Hards
 
24
 
 
25
Portions created by the Initial Developer are Copyright (C) 2011,2013
 
26
the Initial Developer. All Rights Reserved.
 
27
 
 
28
Contributor(s):
 
29
 
 
30
 
 
31
Alternatively, the contents of this file may be used under the terms of
 
32
either the GNU General Public License Version 2 or later (the "GPL"), or
 
33
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
34
in which case the provisions of the GPL or the LGPL are applicable instead
 
35
of those above. If you wish to allow use of your version of this file only
 
36
under the terms of either the GPL or the LGPL, and not to allow others to
 
37
use your version of this file under the terms of the MPL, indicate your
 
38
decision by deleting the provisions above and replace them with the notice
 
39
and other provisions required by the GPL or the LGPL. If you do not delete
 
40
the provisions above, a recipient may use your version of this file under
 
41
the terms of any one of the MPL, the GPL or the LGPL.
 
42
 
 
43
*/
 
44
 
 
45
#include <stdlib.h>
 
46
#include <stdio.h>
 
47
#include <string.h>
 
48
 
 
49
#include <sqlite3.h>
 
50
#include <spatialite.h>
 
51
 
 
52
#include "test_helpers.h"
 
53
 
 
54
int
 
55
main (int argc UNUSED, char *argv[]UNUSED)
 
56
{
 
57
    sqlite3 *db_handle = NULL;
 
58
    int ret;
 
59
    char *err_msg = NULL;
 
60
    void *cache = spatialite_alloc_connection ();
 
61
    char *old_SPATIALITE_SECURITY_ENV = NULL;
 
62
#ifdef _WIN32
 
63
    char *env;
 
64
#endif /* not WIN32 */
 
65
 
 
66
    old_SPATIALITE_SECURITY_ENV = getenv ("SPATIALITE_SECURITY");
 
67
#ifdef _WIN32
 
68
    putenv ("SPATIALITE_SECURITY=relaxed");
 
69
#else /* not WIN32 */
 
70
    setenv ("SPATIALITE_SECURITY", "relaxed", 1);
 
71
#endif
 
72
 
 
73
    ret =
 
74
        sqlite3_open_v2 (":memory:", &db_handle,
 
75
                         SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
 
76
    /* For debugging / testing if required */
 
77
    /*
 
78
       ret = sqlite3_open_v2 ("check_gpkgCreateTilesZoomLevel.sqlite", &db_handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
 
79
     */
 
80
    spatialite_init_ex (db_handle, cache, 0);
 
81
 
 
82
    if (old_SPATIALITE_SECURITY_ENV)
 
83
      {
 
84
#ifdef _WIN32
 
85
          env =
 
86
              sqlite3_mprintf ("SPATIALITE_SECURITY=%s",
 
87
                               old_SPATIALITE_SECURITY_ENV);
 
88
          putenv (env);
 
89
          sqlite3_free (env);
 
90
#else /* not WIN32 */
 
91
          setenv ("SPATIALITE_SECURITY", old_SPATIALITE_SECURITY_ENV, 1);
 
92
#endif
 
93
      }
 
94
    else
 
95
      {
 
96
#ifdef _WIN32
 
97
          putenv ("SPATIALITE_SECURITY=");
 
98
#else /* not WIN32 */
 
99
          unsetenv ("SPATIALITE_SECURITY");
 
100
#endif
 
101
      }
 
102
    if (ret != SQLITE_OK)
 
103
      {
 
104
          fprintf (stderr, "cannot open in-memory db: %s\n",
 
105
                   sqlite3_errmsg (db_handle));
 
106
          sqlite3_close (db_handle);
 
107
          db_handle = NULL;
 
108
          return -1;
 
109
      }
 
110
 
 
111
    ret =
 
112
        sqlite3_exec (db_handle, "SELECT gpkgCreateBaseTables()", NULL, NULL,
 
113
                      &err_msg);
 
114
    if (ret != SQLITE_OK)
 
115
      {
 
116
          fprintf (stderr,
 
117
                   "Unexpected gpkgCreateBaseTables() result: %i, (%s)\n", ret,
 
118
                   err_msg);
 
119
          sqlite3_free (err_msg);
 
120
          return -2;
 
121
      }
 
122
 
 
123
    ret =
 
124
        sqlite3_exec (db_handle,
 
125
                      "SELECT gpkgCreateTilesTable(\"test1_matrix_tiles\", 4326, -180.0, -90.0, 180.0, 90.0)",
 
126
                      NULL, NULL, &err_msg);
 
127
    if (ret != SQLITE_OK)
 
128
      {
 
129
          fprintf (stderr,
 
130
                   "Unexpected gpkgCreateTilesTable() result: %i, (%s)\n", ret,
 
131
                   err_msg);
 
132
          sqlite3_free (err_msg);
 
133
          return -3;
 
134
      }
 
135
 
 
136
    /* create matrix level 0 */
 
137
    ret =
 
138
        sqlite3_exec (db_handle,
 
139
                      "SELECT gpkgCreateTilesZoomLevel(\"test1_matrix_tiles\", 0, 360, 180)",
 
140
                      NULL, NULL, &err_msg);
 
141
    if (ret != SQLITE_OK)
 
142
      {
 
143
          fprintf (stderr,
 
144
                   "Unexpected gpkgCreateTilesZoomLevel(0) result: %i, (%s)\n",
 
145
                   ret, err_msg);
 
146
          sqlite3_free (err_msg);
 
147
          return -6;
 
148
      }
 
149
 
 
150
    /* try duplicate entry */
 
151
    ret =
 
152
        sqlite3_exec (db_handle,
 
153
                      "SELECT gpkgCreateTilesZoomLevel(\"test1_matrix_tiles\", 0, 360, 180)",
 
154
                      NULL, NULL, &err_msg);
 
155
    if (ret != SQLITE_ERROR)
 
156
      {
 
157
          fprintf (stderr,
 
158
                   "Expected error for add zoom level, duplicate entry, got %i\n",
 
159
                   ret);
 
160
          sqlite3_free (err_msg);
 
161
          return -10;
 
162
      }
 
163
    sqlite3_free (err_msg);
 
164
 
 
165
    /*  try some bad arguments */
 
166
    ret =
 
167
        sqlite3_exec (db_handle,
 
168
                      "SELECT gpkgCreateTilesZoomLevel(9.4, 4, 360, 180)", NULL,
 
169
                      NULL, &err_msg);
 
170
    if (ret != SQLITE_ERROR)
 
171
      {
 
172
          fprintf (stderr,
 
173
                   "Expected error for add zoom level, non-string table name, got %i\n",
 
174
                   ret);
 
175
          sqlite3_free (err_msg);
 
176
          return -18;
 
177
      }
 
178
    if (strcmp
 
179
        (err_msg,
 
180
         "gpkgCreateTilesZoomLevel() error: argument 1 [table] is not of the String type")
 
181
        != 0)
 
182
      {
 
183
          fprintf (stderr,
 
184
                   "Unexpected error message for gpkgAddGeometryColumn arg 1 bad type: %s\n",
 
185
                   err_msg);
 
186
          sqlite3_free (err_msg);
 
187
          return -21;
 
188
      }
 
189
    sqlite3_free (err_msg);
 
190
 
 
191
    ret =
 
192
        sqlite3_exec (db_handle,
 
193
                      "SELECT gpkgCreateTilesZoomLevel(\"test1_matrix_tiles\", 4.2, 360, 180)",
 
194
                      NULL, NULL, &err_msg);
 
195
    if (ret != SQLITE_ERROR)
 
196
      {
 
197
          fprintf (stderr,
 
198
                   "Expected error for add zoom level, non-integer zoom, got %i\n",
 
199
                   ret);
 
200
          sqlite3_free (err_msg);
 
201
          return -20;
 
202
      }
 
203
    if (strcmp
 
204
        (err_msg,
 
205
         "gpkgCreateTilesZoomLevel() error: argument 2 [zoom level] is not of the integer type")
 
206
        != 0)
 
207
      {
 
208
          fprintf (stderr,
 
209
                   "Unexpected error message for gpkgAddGeometryColumn arg 2 bad type: %s\n",
 
210
                   err_msg);
 
211
          sqlite3_free (err_msg);
 
212
          return -21;
 
213
      }
 
214
    sqlite3_free (err_msg);
 
215
 
 
216
    ret =
 
217
        sqlite3_exec (db_handle,
 
218
                      "SELECT gpkgCreateTilesZoomLevel(\"test1_matrix_tiles\", 4, \"x\", 180)",
 
219
                      NULL, NULL, &err_msg);
 
220
    if (ret != SQLITE_ERROR)
 
221
      {
 
222
          fprintf (stderr,
 
223
                   "Expected error for add zoom level, non-numeric extent, got %i\n",
 
224
                   ret);
 
225
          sqlite3_free (err_msg);
 
226
          return -22;
 
227
      }
 
228
    if (strcmp
 
229
        (err_msg,
 
230
         "gpkgCreateTilesZoomLevel() error: argument 3 [extent_width] is not of a numerical type")
 
231
        != 0)
 
232
      {
 
233
          fprintf (stderr,
 
234
                   "Unexpected error message for gpkgAddGeometryColumn arg 3 bad type: %s\n",
 
235
                   err_msg);
 
236
          sqlite3_free (err_msg);
 
237
          return -23;
 
238
      }
 
239
    sqlite3_free (err_msg);
 
240
 
 
241
    ret =
 
242
        sqlite3_exec (db_handle,
 
243
                      "SELECT gpkgCreateTilesZoomLevel(\"test1_matrix_tiles\", 4, 360, \"y\")",
 
244
                      NULL, NULL, &err_msg);
 
245
    if (ret != SQLITE_ERROR)
 
246
      {
 
247
          fprintf (stderr,
 
248
                   "Expected error for add zoom level, non-numeric height extent, got %i\n",
 
249
                   ret);
 
250
          sqlite3_free (err_msg);
 
251
          return -24;
 
252
      }
 
253
    if (strcmp
 
254
        (err_msg,
 
255
         "gpkgCreateTilesZoomLevel() error: argument 4 [extent_height] is not of a numerical type")
 
256
        != 0)
 
257
      {
 
258
          fprintf (stderr,
 
259
                   "Unexpected error message for gpkgAddGeometryColumn arg 4 bad type: %s\n",
 
260
                   err_msg);
 
261
          sqlite3_free (err_msg);
 
262
          return -25;
 
263
      }
 
264
    sqlite3_free (err_msg);
 
265
 
 
266
    ret =
 
267
        sqlite3_exec (db_handle,
 
268
                      "SELECT gpkgCreateTilesZoomLevel(\"test1_matrix_tiles\", -1, 360, 180)",
 
269
                      NULL, NULL, &err_msg);
 
270
    if (ret != SQLITE_ERROR)
 
271
      {
 
272
          fprintf (stderr,
 
273
                   "Expected error for add zoom level, negative zoom, got %i\n",
 
274
                   ret);
 
275
          sqlite3_free (err_msg);
 
276
          return -26;
 
277
      }
 
278
    if (strcmp
 
279
        (err_msg,
 
280
         "gpkgCreateTilesZoomLevel() error: argument 2 [zoom level] must be >= 0")
 
281
        != 0)
 
282
      {
 
283
          fprintf (stderr,
 
284
                   "Unexpected error message for gpkgAddGeometryColumn arg 2 bad value: %s\n",
 
285
                   err_msg);
 
286
          sqlite3_free (err_msg);
 
287
          return -27;
 
288
      }
 
289
    sqlite3_free (err_msg);
 
290
 
 
291
    /* Try float extent */
 
292
    ret =
 
293
        sqlite3_exec (db_handle,
 
294
                      "SELECT gpkgCreateTilesZoomLevel(\"test1_matrix_tiles\", 1, 360.0, 180.0)",
 
295
                      NULL, NULL, &err_msg);
 
296
    if (ret != SQLITE_OK)
 
297
      {
 
298
          fprintf (stderr,
 
299
                   "Unexpected gpkgCreateTilesZoomLevel(1) result: %i, (%s)\n",
 
300
                   ret, err_msg);
 
301
          sqlite3_free (err_msg);
 
302
          return -30;
 
303
      }
 
304
 
 
305
    ret = sqlite3_close (db_handle);
 
306
    if (ret != SQLITE_OK)
 
307
      {
 
308
          fprintf (stderr, "sqlite3_close() error: %s\n",
 
309
                   sqlite3_errmsg (db_handle));
 
310
          return -200;
 
311
      }
 
312
 
 
313
    spatialite_cleanup_ex (cache);
 
314
    spatialite_shutdown ();
 
315
 
 
316
    return 0;
 
317
}