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

« back to all changes in this revision

Viewing changes to test/check_point_to_tile_wrong_arg_type.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_point_to_tile_wrong_arg_type.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) 2012
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 main (int argc UNUSED, char *argv[] UNUSED)
55
 
{
56
 
    sqlite3 *db_handle = NULL;
57
 
    int ret;
58
 
    void *cache = spatialite_alloc_connection();
59
 
    char *err_msg = NULL;
60
 
    
61
 
    ret = sqlite3_open_v2 (":memory:", &db_handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
62
 
    // For debugging / testing if required
63
 
    // ret = sqlite3_open_v2 ("check_point_to_tile_wrong_arg_type.sqlite", &db_handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
64
 
    spatialite_init_ex(db_handle, cache, 0);
65
 
    if (ret != SQLITE_OK) {
66
 
      fprintf (stderr, "cannot open in-memory db: %s\n", sqlite3_errmsg (db_handle));
67
 
      sqlite3_close (db_handle);
68
 
      db_handle = NULL;
69
 
      return -1;
70
 
    }
71
 
 
72
 
    /* try gpkgPointToTile with the wrong argument types */
73
 
    ret = sqlite3_exec (db_handle, "SELECT gpkgPointToTile(1, 2, 3, 4, 5)", NULL, NULL, &err_msg);
74
 
    if (ret != SQLITE_ERROR) {
75
 
        fprintf(stderr, "Expected error for bad arg 1, got %i\n", ret);
76
 
        sqlite3_free (err_msg);
77
 
        return -4;
78
 
    }
79
 
    if (strcmp(err_msg, "gpkgPointToTile() error: argument 1 [table] is not of the String type") != 0)
80
 
    {
81
 
        fprintf (stderr, "Unexpected error message for bad arg 1: %s\n", err_msg);
82
 
        sqlite3_free(err_msg);
83
 
        return -5;
84
 
    }
85
 
    sqlite3_free(err_msg);
86
 
    
87
 
    ret = sqlite3_exec (db_handle, "SELECT gpkgPointToTile('test1_tiles', 2.3, 3, 4, 5)", NULL, NULL, &err_msg);
88
 
    if (ret != SQLITE_ERROR) {
89
 
        fprintf(stderr, "Expected error for bad arg 2, got %i\n", ret);
90
 
        sqlite3_free (err_msg);
91
 
        return -6;
92
 
    }
93
 
    if (strcmp(err_msg, "gpkgPointToTile() error: argument 2 [srid] is not of the integer type") != 0)
94
 
    {
95
 
        fprintf (stderr, "Unexpected error message for bad arg 2: %s\n", err_msg);
96
 
        sqlite3_free(err_msg);
97
 
        return -7;
98
 
    }
99
 
    sqlite3_free(err_msg);
100
 
 
101
 
    ret = sqlite3_exec (db_handle, "SELECT gpkgPointToTile('test1_tiles', 4326, 'hello', 4, 5)", NULL, NULL, &err_msg);
102
 
    if (ret != SQLITE_ERROR) {
103
 
        fprintf(stderr, "Expected error for bad arg 3, got %i\n", ret);
104
 
        sqlite3_free (err_msg);
105
 
        return -8;
106
 
    }
107
 
    if (strcmp(err_msg, "gpkgPointToTile() error: argument 3 [x coordinate] is not of a numerical type") != 0)
108
 
    {
109
 
        fprintf (stderr, "Unexpected error message for bad arg 3: %s\n", err_msg);
110
 
        sqlite3_free(err_msg);
111
 
        return -9;
112
 
    }
113
 
    sqlite3_free(err_msg);
114
 
    
115
 
    ret = sqlite3_exec (db_handle, "SELECT gpkgPointToTile('test1_tiles', 4326, 3.2, 'bye', 5)", NULL, NULL, &err_msg);
116
 
    if (ret != SQLITE_ERROR) {
117
 
        fprintf(stderr, "Expected error for bad arg 4, got %i\n", ret);
118
 
        sqlite3_free (err_msg);
119
 
        return -10;
120
 
    }
121
 
    if (strcmp(err_msg, "gpkgPointToTile() error: argument 4 [y coordinate] is not of a numerical type") != 0)
122
 
    {
123
 
        fprintf (stderr, "Unexpected error message for bad arg 4: %s\n", err_msg);
124
 
        sqlite3_free(err_msg);
125
 
        return -11;
126
 
    }
127
 
    sqlite3_free(err_msg);
128
 
    
129
 
    ret = sqlite3_exec (db_handle, "SELECT gpkgPointToTile('test1_tiles', 4326, 3.2, 5.2, 1.9)", NULL, NULL, &err_msg);
130
 
    if (ret != SQLITE_ERROR) {
131
 
        fprintf(stderr, "Expected error for bad arg 5, got %i\n", ret);
132
 
        sqlite3_free (err_msg);
133
 
        return -12;
134
 
    }
135
 
    if (strcmp(err_msg, "gpkgPointToTile() error: argument 5 [zoom level] is not of the integer type") != 0)
136
 
    {
137
 
        fprintf (stderr, "Unexpected error message for bad arg 5: %s\n", err_msg);
138
 
        sqlite3_free(err_msg);
139
 
        return -13;
140
 
    }
141
 
    sqlite3_free(err_msg);
142
 
    
143
 
    ret = sqlite3_close (db_handle);
144
 
    if (ret != SQLITE_OK) {
145
 
        fprintf (stderr, "sqlite3_close() error: %s\n", sqlite3_errmsg (db_handle));
146
 
        return -100;
147
 
    }
148
 
    
149
 
    spatialite_cleanup_ex(cache);
150
 
 
151
 
    return 0;
152
 
}