null+****@clear*****
null+****@clear*****
2010年 7月 6日 (火) 14:20:43 JST
Kouhei Sutou 2010-07-06 05:20:43 +0000 (Tue, 06 Jul 2010) New Revision: a0528efa538a7b6fb27485dea066ddaa4200550b Log: add a input error check for geo point. A separator between latitude and longitude must be 'x': "LATITUDExLONGITUDE" form is valid. Modified files: lib/db.c test/unit/core/test-cast-basic.c Modified: lib/db.c (+1 -1) =================================================================== --- lib/db.c 2010-07-06 05:06:13 +0000 (52985cb) +++ lib/db.c 2010-07-06 05:20:43 +0000 (33a816f) @@ -3773,7 +3773,7 @@ grn_obj_cast(grn_ctx *ctx, grn_obj *src, grn_obj *dest, int addp) const char *cur, *str = GRN_TEXT_VALUE(src); const char *str_end = GRN_BULK_CURR(src); latitude = grn_atoi(str, str_end, &cur); - if (cur + 1 < str_end) { + if (cur[0] == 'x' && cur + 1 < str_end) { longitude = grn_atoi(cur + 1, str_end, &cur); if (cur == str_end) { GRN_GEO_POINT_SET(ctx, dest, latitude, longitude); Modified: test/unit/core/test-cast-basic.c (+31 -2) =================================================================== --- test/unit/core/test-cast-basic.c 2010-07-06 05:06:13 +0000 (5812421) +++ test/unit/core/test-cast-basic.c 2010-07-06 05:20:43 +0000 (42eb1f8) @@ -1,6 +1,6 @@ /* -*- c-basic-offset: 2; coding: utf-8 -*- */ /* - Copyright (C) 2009 Kouhei Sutou <kou****@clear*****> + Copyright (C) 2009-2010 Kouhei Sutou <kou****@clear*****> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -35,6 +35,8 @@ void test_text_to_int64(void); void test_text_to_uint64(void); void test_text_to_float(void); void test_text_to_time(void); +void test_text_to_geo_point(void); +void test_text_to_geo_point_invalid(void); void data_text_error(void); void test_text_error(gconstpointer data); @@ -114,12 +116,18 @@ cut_teardown(void) } static void -cast_text(const gchar *text) +set_text(const gchar *text) { grn_obj_reinit(&context, &src, GRN_DB_TEXT, 0); if (text) { GRN_TEXT_PUTS(&context, &src, text); } +} + +static void +cast_text(const gchar *text) +{ + set_text(text); grn_test_assert(grn_obj_cast(&context, &src, &dest, GRN_FALSE)); } @@ -236,6 +244,27 @@ test_text_to_time(void) } void +test_text_to_geo_point(void) +{ + gint takane_latitude, takane_longitude; + + grn_obj_reinit(&context, &dest, GRN_DB_WGS84_GEO_POINT, 0); + cast_text("130226900x503769900"); + GRN_GEO_POINT_VALUE(&dest, takane_latitude, takane_longitude); + cut_assert_equal_int(130226900, takane_latitude); + cut_assert_equal_int(503769900, takane_longitude); +} + +void +test_text_to_geo_point_invalid(void) +{ + grn_obj_reinit(&context, &dest, GRN_DB_WGS84_GEO_POINT, 0); + set_text("130226900?503769900"); + grn_test_assert_equal_rc(GRN_INVALID_ARGUMENT, + grn_obj_cast(&context, &src, &dest, FALSE)); +} + +void data_text_error(void) { #define ADD_DATA(label, expected, type, text) \