3
check_gpkgCreateTilesZoomLevel.c - Test case for GeoPackage Extensions
5
Author: Brad Hards <bradh@frogmouth.net>
7
------------------------------------------------------------------------------
9
Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
21
The Original Code is GeoPackage extensions
23
The Initial Developer of the Original Code is Brad Hards
25
Portions created by the Initial Developer are Copyright (C) 2011,2013
26
the Initial Developer. All Rights Reserved.
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.
50
#include <spatialite.h>
52
#include "test_helpers.h"
55
main (int argc UNUSED, char *argv[]UNUSED)
57
sqlite3 *db_handle = NULL;
60
void *cache = spatialite_alloc_connection ();
61
char *old_SPATIALITE_SECURITY_ENV = NULL;
64
#endif /* not WIN32 */
66
old_SPATIALITE_SECURITY_ENV = getenv ("SPATIALITE_SECURITY");
68
putenv ("SPATIALITE_SECURITY=relaxed");
70
setenv ("SPATIALITE_SECURITY", "relaxed", 1);
74
sqlite3_open_v2 (":memory:", &db_handle,
75
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
76
/* For debugging / testing if required */
78
ret = sqlite3_open_v2 ("check_gpkgCreateTilesZoomLevel.sqlite", &db_handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
80
spatialite_init_ex (db_handle, cache, 0);
82
if (old_SPATIALITE_SECURITY_ENV)
86
sqlite3_mprintf ("SPATIALITE_SECURITY=%s",
87
old_SPATIALITE_SECURITY_ENV);
91
setenv ("SPATIALITE_SECURITY", old_SPATIALITE_SECURITY_ENV, 1);
97
putenv ("SPATIALITE_SECURITY=");
99
unsetenv ("SPATIALITE_SECURITY");
102
if (ret != SQLITE_OK)
104
fprintf (stderr, "cannot open in-memory db: %s\n",
105
sqlite3_errmsg (db_handle));
106
sqlite3_close (db_handle);
112
sqlite3_exec (db_handle, "SELECT gpkgCreateBaseTables()", NULL, NULL,
114
if (ret != SQLITE_OK)
117
"Unexpected gpkgCreateBaseTables() result: %i, (%s)\n", ret,
119
sqlite3_free (err_msg);
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)
130
"Unexpected gpkgCreateTilesTable() result: %i, (%s)\n", ret,
132
sqlite3_free (err_msg);
136
/* create matrix level 0 */
138
sqlite3_exec (db_handle,
139
"SELECT gpkgCreateTilesZoomLevel(\"test1_matrix_tiles\", 0, 360, 180)",
140
NULL, NULL, &err_msg);
141
if (ret != SQLITE_OK)
144
"Unexpected gpkgCreateTilesZoomLevel(0) result: %i, (%s)\n",
146
sqlite3_free (err_msg);
150
/* try duplicate entry */
152
sqlite3_exec (db_handle,
153
"SELECT gpkgCreateTilesZoomLevel(\"test1_matrix_tiles\", 0, 360, 180)",
154
NULL, NULL, &err_msg);
155
if (ret != SQLITE_ERROR)
158
"Expected error for add zoom level, duplicate entry, got %i\n",
160
sqlite3_free (err_msg);
163
sqlite3_free (err_msg);
165
/* try some bad arguments */
167
sqlite3_exec (db_handle,
168
"SELECT gpkgCreateTilesZoomLevel(9.4, 4, 360, 180)", NULL,
170
if (ret != SQLITE_ERROR)
173
"Expected error for add zoom level, non-string table name, got %i\n",
175
sqlite3_free (err_msg);
180
"gpkgCreateTilesZoomLevel() error: argument 1 [table] is not of the String type")
184
"Unexpected error message for gpkgAddGeometryColumn arg 1 bad type: %s\n",
186
sqlite3_free (err_msg);
189
sqlite3_free (err_msg);
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)
198
"Expected error for add zoom level, non-integer zoom, got %i\n",
200
sqlite3_free (err_msg);
205
"gpkgCreateTilesZoomLevel() error: argument 2 [zoom level] is not of the integer type")
209
"Unexpected error message for gpkgAddGeometryColumn arg 2 bad type: %s\n",
211
sqlite3_free (err_msg);
214
sqlite3_free (err_msg);
217
sqlite3_exec (db_handle,
218
"SELECT gpkgCreateTilesZoomLevel(\"test1_matrix_tiles\", 4, \"x\", 180)",
219
NULL, NULL, &err_msg);
220
if (ret != SQLITE_ERROR)
223
"Expected error for add zoom level, non-numeric extent, got %i\n",
225
sqlite3_free (err_msg);
230
"gpkgCreateTilesZoomLevel() error: argument 3 [extent_width] is not of a numerical type")
234
"Unexpected error message for gpkgAddGeometryColumn arg 3 bad type: %s\n",
236
sqlite3_free (err_msg);
239
sqlite3_free (err_msg);
242
sqlite3_exec (db_handle,
243
"SELECT gpkgCreateTilesZoomLevel(\"test1_matrix_tiles\", 4, 360, \"y\")",
244
NULL, NULL, &err_msg);
245
if (ret != SQLITE_ERROR)
248
"Expected error for add zoom level, non-numeric height extent, got %i\n",
250
sqlite3_free (err_msg);
255
"gpkgCreateTilesZoomLevel() error: argument 4 [extent_height] is not of a numerical type")
259
"Unexpected error message for gpkgAddGeometryColumn arg 4 bad type: %s\n",
261
sqlite3_free (err_msg);
264
sqlite3_free (err_msg);
267
sqlite3_exec (db_handle,
268
"SELECT gpkgCreateTilesZoomLevel(\"test1_matrix_tiles\", -1, 360, 180)",
269
NULL, NULL, &err_msg);
270
if (ret != SQLITE_ERROR)
273
"Expected error for add zoom level, negative zoom, got %i\n",
275
sqlite3_free (err_msg);
280
"gpkgCreateTilesZoomLevel() error: argument 2 [zoom level] must be >= 0")
284
"Unexpected error message for gpkgAddGeometryColumn arg 2 bad value: %s\n",
286
sqlite3_free (err_msg);
289
sqlite3_free (err_msg);
291
/* Try float extent */
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)
299
"Unexpected gpkgCreateTilesZoomLevel(1) result: %i, (%s)\n",
301
sqlite3_free (err_msg);
305
ret = sqlite3_close (db_handle);
306
if (ret != SQLITE_OK)
308
fprintf (stderr, "sqlite3_close() error: %s\n",
309
sqlite3_errmsg (db_handle));
313
spatialite_cleanup_ex (cache);
314
spatialite_shutdown ();