23 #include <glib/gstdio.h>
25 #include "../lib/grn-assertions.h"
27 #define COORDINATE(hours, minutes, seconds) \
28 ((hours) * 3600 + (minutes) * 60 + (seconds)) * 1000
30 #define POINT(latitude_hours, latitude_minutes, latitude_seconds, \
31 longitude_hours, longitude_minutes, longitude_seconds) \
34 COORDINATE(latitude_hours, latitude_minutes, latitude_seconds), \
35 COORDINATE(longitude_hours, longitude_minutes, longitude_seconds))
37 #define TAKEN_POINT(latitude_hours, latitude_minutes, latitude_seconds, \
38 longitude_hours, longitude_minutes, longitude_seconds) \
39 cut_take_string(POINT(latitude_hours, latitude_minutes, latitude_seconds, \
40 longitude_hours, longitude_minutes, longitude_seconds))
42 #define INSPECTED_POINT(latitude_hours, latitude_minutes, latitude_seconds, \
43 longitude_hours, longitude_minutes, longitude_seconds) \
45 COORDINATE(latitude_hours, latitude_minutes, latitude_seconds), \
46 COORDINATE(longitude_hours, longitude_minutes, longitude_seconds))
48 #define TAKEN_INSPECTED_POINT(latitude_hours, \
54 cut_take_string(INSPECTED_POINT(latitude_hours, \
64 static gchar *tmp_directory;
74 "table-patricia-trie-sort",
81 g_free(tmp_directory);
85 remove_tmp_directory(
void)
87 cut_remove_path(tmp_directory, NULL);
93 const gchar *database_path;
95 remove_tmp_directory();
96 g_mkdir_with_parents(tmp_directory, 0700);
101 database_path = cut_build_path(tmp_directory,
"database.groonga", NULL);
132 remove_tmp_directory();
136 create_geo_table(
const gchar *load_data)
138 const char *table_name =
"Data";
139 const char *column_name =
"location";
142 cut_take_printf(
"table_create %s TABLE_NO_KEY", table_name));
144 cut_take_printf(
"column_create %s %s COLUMN_SCALAR WGS84GeoPoint",
145 table_name, column_name));
148 cut_take_printf(
"column_create Index %s_%s COLUMN_INDEX %s %s",
149 table_name, column_name,
150 table_name, column_name));
152 cut_take_printf(
"load --table %s\n"
161 table =
grn_ctx_get(context, table_name, strlen(table_name));
162 column =
grn_obj_column(context, table, column_name, strlen(column_name));
166 inspect_point (gint latitude, gint longitude)
168 return g_strdup_printf(
"((%d, %d, %d), (%d, %d, %d))",
169 latitude / 1000 / 3600 % 3600,
170 latitude / 1000 / 60 % 60,
171 latitude / 1000 % 60,
172 longitude / 1000 / 3600 % 3600,
173 longitude / 1000 / 60 % 60,
174 longitude / 1000 % 60);
180 #define ADD_DATA(label, expected, base, offset, limit) \
181 gcut_add_datum(label, \
182 "expected", G_TYPE_POINTER, \
183 expected, g_list_free, \
184 "base", G_TYPE_INT, base, \
185 "offset", G_TYPE_INT, offset, \
186 "limit", G_TYPE_INT, limit, \
257 const GList *expected_keys;
258 GList *actual_keys = NULL;
260 grn_obj base, base_string, location;
262 create_geo_table(cut_take_printf(
" [\"%s\"],\n"
313 GRN_TEXT_SETS(context, &base_string, gcut_data_get_string(data,
"base"));
318 offset = gcut_data_get_int(data,
"offset");
320 cut_omit(
"geo sort doesn't support offset yet.");
322 limit = gcut_data_get_int(data,
"limit");
323 keys[0].
key = column;
333 NULL, 0, NULL, 0, 0, -1,
340 gint latitude, longitude;
346 actual_keys = g_list_append(actual_keys,
347 inspect_point(latitude, longitude));
350 gcut_take_list(actual_keys, g_free);
352 expected_keys = gcut_data_get_pointer(data,
"expected");
353 gcut_assert_equal_list_string(expected_keys, actual_keys);