20 #include <glib/gstdio.h>
22 #include "../lib/grn-assertions.h"
27 #define get(name) grn_ctx_get(context, name, strlen(name))
32 static gchar *tmp_directory;
36 static grn_obj *location_index_column, *result;
42 "geo-in-rectangle-border",
49 g_free(tmp_directory);
53 remove_tmp_directory(
void)
55 cut_remove_path(tmp_directory, NULL);
68 const gchar *database_path;
75 remove_tmp_directory();
76 g_mkdir_with_parents(tmp_directory, 0700);
81 database_path = cut_build_path(tmp_directory,
"database.groonga", NULL);
86 points =
get(
"Points");
87 short_degree_column =
get(
"Points.short_degree");
88 location_index_column =
get(
"Locations.point");
108 remove_tmp_directory();
111 #define ADD_DATA(label, expected, top, left, bottom, right) \
112 gcut_add_datum(label, \
113 "expected", G_TYPE_POINTER, expected, gcut_list_string_free, \
114 "top", G_TYPE_INT, top, \
115 "left", G_TYPE_INT, left, \
116 "bottom", G_TYPE_INT, bottom, \
117 "right", G_TYPE_INT, right, \
121 data_cursor_all_bottom_left(
void)
123 ADD_DATA(
"all - bottom left - bottom left",
124 gcut_list_string_new(
125 "(03,03)",
"(03,04)",
"(03,05)",
"(03,06)",
"(03,07)",
"(03,08)",
126 "(04,03)",
"(04,04)",
"(04,05)",
"(04,06)",
"(04,07)",
"(04,08)",
127 "(05,03)",
"(05,04)",
"(05,05)",
"(05,06)",
"(05,07)",
"(05,08)",
128 "(06,03)",
"(06,04)",
"(06,05)",
"(06,06)",
"(06,07)",
"(06,08)",
129 "(07,03)",
"(07,04)",
"(07,05)",
"(07,06)",
"(07,07)",
"(07,08)",
130 "(08,03)",
"(08,04)",
"(08,05)",
"(08,06)",
"(08,07)",
"(08,08)",
135 ADD_DATA(
"all - bottom left - top left",
136 gcut_list_string_new(
137 "(07,03)",
"(07,04)",
"(07,05)",
"(07,06)",
"(07,07)",
"(07,08)",
138 "(08,03)",
"(08,04)",
"(08,05)",
"(08,06)",
"(08,07)",
"(08,08)",
143 ADD_DATA(
"all - bottom left - bottom right",
144 gcut_list_string_new(
"(03,07)",
"(03,08)",
145 "(04,07)",
"(04,08)",
146 "(05,07)",
"(05,08)",
147 "(06,07)",
"(06,08)",
148 "(07,07)",
"(07,08)",
149 "(08,07)",
"(08,08)",
156 data_cursor_all_top_left(
void)
158 ADD_DATA(
"all - top left - top left",
159 gcut_list_string_new(
160 "(07,03)",
"(07,04)",
"(07,05)",
"(07,06)",
"(07,07)",
"(07,08)",
161 "(08,03)",
"(08,04)",
"(08,05)",
"(08,06)",
"(08,07)",
"(08,08)",
162 "(09,03)",
"(09,04)",
"(09,05)",
"(09,06)",
"(09,07)",
"(09,08)",
163 "(10,03)",
"(10,04)",
"(10,05)",
"(10,06)",
"(10,07)",
"(10,08)",
164 "(11,03)",
"(11,04)",
"(11,05)",
"(11,06)",
"(11,07)",
"(11,08)",
165 "(12,03)",
"(12,04)",
"(12,05)",
"(12,06)",
"(12,07)",
"(12,08)",
170 ADD_DATA(
"all - top left - top right",
171 gcut_list_string_new(
"(07,07)",
"(07,08)",
172 "(08,07)",
"(08,08)",
173 "(09,07)",
"(09,08)",
174 "(10,07)",
"(10,08)",
175 "(11,07)",
"(11,08)",
176 "(12,07)",
"(12,08)",
183 data_cursor_all_bottom_right(
void)
185 ADD_DATA(
"all - bottom right - bottom right",
186 gcut_list_string_new(
187 "(03,07)",
"(03,08)",
"(03,09)",
"(03,10)",
"(03,11)",
"(03,12)",
188 "(04,07)",
"(04,08)",
"(04,09)",
"(04,10)",
"(04,11)",
"(04,12)",
189 "(05,07)",
"(05,08)",
"(05,09)",
"(05,10)",
"(05,11)",
"(05,12)",
190 "(06,07)",
"(06,08)",
"(06,09)",
"(06,10)",
"(06,11)",
"(06,12)",
191 "(07,07)",
"(07,08)",
"(07,09)",
"(07,10)",
"(07,11)",
"(07,12)",
192 "(08,07)",
"(08,08)",
"(08,09)",
"(08,10)",
"(08,11)",
"(08,12)",
197 ADD_DATA(
"all - bottom right - top right",
198 gcut_list_string_new(
199 "(07,07)",
"(07,08)",
"(07,09)",
"(07,10)",
"(07,11)",
"(07,12)",
200 "(08,07)",
"(08,08)",
"(08,09)",
"(08,10)",
"(08,11)",
"(08,12)",
207 data_cursor_all_top_right(
void)
209 ADD_DATA(
"all - bottom right - top right",
210 gcut_list_string_new(
211 "(07,07)",
"(07,08)",
"(07,09)",
"(07,10)",
"(07,11)",
"(07,12)",
212 "(08,07)",
"(08,08)",
"(08,09)",
"(08,10)",
"(08,11)",
"(08,12)",
213 "(09,07)",
"(09,08)",
"(09,09)",
"(09,10)",
"(09,11)",
"(09,12)",
214 "(10,07)",
"(10,08)",
"(10,09)",
"(10,10)",
"(10,11)",
"(10,12)",
215 "(11,07)",
"(11,08)",
"(11,09)",
"(11,10)",
"(11,11)",
"(11,12)",
216 "(12,07)",
"(12,08)",
"(12,09)",
"(12,10)",
"(12,11)",
"(12,12)",
223 data_cursor_all(
void)
226 gcut_list_string_new(
"(07,07)",
"(07,08)",
227 "(08,07)",
"(08,08)",
232 #define ALL_LONGITUDES(latitude) \
233 "(" latitude ",00)", "(" latitude ",01)", \
234 "(" latitude ",02)", "(" latitude ",03)", \
235 "(" latitude ",04)", "(" latitude ",05)", \
236 "(" latitude ",06)", "(" latitude ",07)", \
237 "(" latitude ",08)", "(" latitude ",09)", \
238 "(" latitude ",10)", "(" latitude ",11)", \
239 "(" latitude ",12)", "(" latitude ",13)", \
240 "(" latitude ",14)", "(" latitude ",15)"
243 gcut_list_string_new(
254 #undef ALL_LONGITUDES
256 data_cursor_all_bottom_left();
257 data_cursor_all_top_left();
258 data_cursor_all_bottom_right();
259 data_cursor_all_top_right();
263 data_cursor_bottom(
void)
266 gcut_list_string_new(
"(03,07)",
"(03,08)",
267 "(04,07)",
"(04,08)",
273 gcut_list_string_new(
274 "(03,03)",
"(03,04)",
"(03,05)",
"(03,06)",
"(03,07)",
"(03,08)",
275 "(04,03)",
"(04,04)",
"(04,05)",
"(04,06)",
"(04,07)",
"(04,08)",
281 gcut_list_string_new(
282 "(03,07)",
"(03,08)",
"(03,09)",
"(03,10)",
"(03,11)",
"(03,12)",
283 "(04,07)",
"(04,08)",
"(04,09)",
"(04,10)",
"(04,11)",
"(04,12)",
290 data_cursor_top(
void)
293 gcut_list_string_new(
"(11,07)",
"(11,08)",
294 "(12,07)",
"(12,08)",
300 gcut_list_string_new(
301 "(11,03)",
"(11,04)",
"(11,05)",
"(11,06)",
"(11,07)",
"(11,08)",
302 "(12,03)",
"(12,04)",
"(12,05)",
"(12,06)",
"(12,07)",
"(12,08)",
308 gcut_list_string_new(
309 "(11,07)",
"(11,08)",
"(11,09)",
"(11,10)",
"(11,11)",
"(11,12)",
310 "(12,07)",
"(12,08)",
"(12,09)",
"(12,10)",
"(12,11)",
"(12,12)",
317 data_cursor_left(
void)
320 gcut_list_string_new(
"(07,03)",
"(07,04)",
321 "(08,03)",
"(08,04)",
327 gcut_list_string_new(
"(03,03)",
"(03,04)",
328 "(04,03)",
"(04,04)",
329 "(05,03)",
"(05,04)",
330 "(06,03)",
"(06,04)",
331 "(07,03)",
"(07,04)",
332 "(08,03)",
"(08,04)",
338 gcut_list_string_new(
"(07,03)",
"(07,04)",
339 "(08,03)",
"(08,04)",
340 "(09,03)",
"(09,04)",
341 "(10,03)",
"(10,04)",
342 "(11,03)",
"(11,04)",
343 "(12,03)",
"(12,04)",
350 data_cursor_right(
void)
353 gcut_list_string_new(
"(07,11)",
"(07,12)",
354 "(08,11)",
"(08,12)",
360 gcut_list_string_new(
"(03,11)",
"(03,12)",
361 "(04,11)",
"(04,12)",
362 "(05,11)",
"(05,12)",
363 "(06,11)",
"(06,12)",
364 "(07,11)",
"(07,12)",
365 "(08,11)",
"(08,12)",
371 gcut_list_string_new(
"(07,11)",
"(07,12)",
372 "(08,11)",
"(08,12)",
373 "(09,11)",
"(09,12)",
374 "(10,11)",
"(10,12)",
375 "(11,11)",
"(11,12)",
376 "(12,11)",
"(12,12)",
386 data_cursor_bottom();
395 set_geo_point(
grn_obj *geo_point,
396 gint relative_latitude, gint relative_longitude)
398 gint latitude, longitude;
399 gint base_latitude = (45 * 60 * 60 + 0 * 60) * 1000;
400 gint base_longitude = (90 * 60 * 60 + 0 * 60) * 1000;
403 latitude = base_latitude + relative_latitude;
404 longitude = base_longitude + relative_longitude;
411 GList *expected, *records = NULL;
414 grn_obj top_left, bottom_right;
419 set_geo_point(&top_left,
420 gcut_data_get_int(data,
"top"),
421 gcut_data_get_int(data,
"left"));
422 set_geo_point(&bottom_right,
423 gcut_data_get_int(data,
"bottom"),
424 gcut_data_get_int(data,
"right"));
426 location_index_column,
439 records = g_list_append(records,
446 records = g_list_sort(records, (GCompareFunc)strcmp);
447 gcut_take_list(records, g_free);
449 expected = (GList *)gcut_data_get_pointer(data,
"expected");
450 gcut_assert_equal_list_string(expected, records);