Exemplo n.º 1
0
void
test_text_to_geo_point_mixed_comma(void)
{
  gint takane_latitude, takane_longitude;

  grn_obj_reinit(&context, &dest, GRN_DB_WGS84_GEO_POINT, 0);
  cast_text("35.6954581363924,503802073");
  GRN_GEO_POINT_VALUE(&dest, takane_latitude, takane_longitude);
  cut_assert_equal_int(128503649, takane_latitude);
  cut_assert_equal_int(503802073, takane_longitude);
}
Exemplo n.º 2
0
void
test_text_to_geo_point_in_degree_comma(void)
{
  gint takane_latitude, takane_longitude;

  grn_obj_reinit(&context, &dest, GRN_DB_WGS84_GEO_POINT, 0);
  cast_text("35.6954581363924,139.564207350021");
  GRN_GEO_POINT_VALUE(&dest, takane_latitude, takane_longitude);
  cut_assert_equal_int(128503649, takane_latitude);
  cut_assert_equal_int(502431146, takane_longitude);
}
Exemplo n.º 3
0
void
test_text_to_geo_point_comma(void)
{
  gint takane_latitude, takane_longitude;

  grn_obj_reinit(&context, &dest, GRN_DB_WGS84_GEO_POINT, 0);
  cast_text("130194581,503802073");
  GRN_GEO_POINT_VALUE(&dest, takane_latitude, takane_longitude);
  cut_assert_equal_int(130194581, takane_latitude);
  cut_assert_equal_int(503802073, takane_longitude);
}
Exemplo n.º 4
0
void
test_text_to_geo_point_empty(void)
{
  gint empty_latitude, empty_longitude;

  grn_obj_reinit(&context, &dest, GRN_DB_WGS84_GEO_POINT, 0);
  cast_text("");
  GRN_GEO_POINT_VALUE(&dest, empty_latitude, empty_longitude);
  cut_assert_equal_int(0, empty_latitude);
  cut_assert_equal_int(0, empty_longitude);
}
Exemplo n.º 5
0
void
test_text_to_geo_point_garbage(void)
{
  gint takane_latitude, takane_longitude;

  grn_obj_reinit(&context, &dest, GRN_DB_WGS84_GEO_POINT, 0);
#define GEO_TEXT "130194581x503802073"
  set_text(GEO_TEXT ".0");
  cast_text(GEO_TEXT);
#undef GEO_TEXT
  GRN_GEO_POINT_VALUE(&dest, takane_latitude, takane_longitude);
  cut_assert_equal_int(130194581, takane_latitude);
  cut_assert_equal_int(503802073, takane_longitude);
}
Exemplo n.º 6
0
void
test_wgs84_geo_point_to_wgs84_geo_point(void)
{
  gint takane_latitude, takane_longitude;
  gint takane_latitude_in_wgs84 = 130194581;
  gint takane_longitude_in_wgs84 = 503802073;

  grn_obj_reinit(&context, &src, GRN_DB_WGS84_GEO_POINT, 0);
  GRN_GEO_POINT_SET(&context, &src,
                    takane_latitude_in_wgs84,
                    takane_longitude_in_wgs84);

  grn_obj_reinit(&context, &dest, GRN_DB_WGS84_GEO_POINT, 0);
  grn_test_assert(grn_obj_cast(&context, &src, &dest, GRN_FALSE));
  GRN_GEO_POINT_VALUE(&dest, takane_latitude, takane_longitude);
  cut_assert_equal_int(takane_latitude_in_wgs84,
                       takane_latitude);
  cut_assert_equal_int(takane_longitude_in_wgs84,
                       takane_longitude);
}
Exemplo n.º 7
0
void
test_tokyo_geo_point_to_tokyo_geo_point(void)
{
  gint takane_latitude, takane_longitude;
  gint takane_latitude_in_tokyo_geodetic_system = 130183139;
  gint takane_longitude_in_tokyo_geodetic_system = 503813760;

  grn_obj_reinit(&context, &src, GRN_DB_TOKYO_GEO_POINT, 0);
  GRN_GEO_POINT_SET(&context, &src,
                    takane_latitude_in_tokyo_geodetic_system,
                    takane_longitude_in_tokyo_geodetic_system);

  grn_obj_reinit(&context, &dest, GRN_DB_TOKYO_GEO_POINT, 0);
  grn_test_assert(grn_obj_cast(&context, &src, &dest, GRN_FALSE));
  GRN_GEO_POINT_VALUE(&dest, takane_latitude, takane_longitude);
  cut_assert_equal_int(takane_latitude_in_tokyo_geodetic_system,
                       takane_latitude);
  cut_assert_equal_int(takane_longitude_in_tokyo_geodetic_system,
                       takane_longitude);
}
Exemplo n.º 8
0
static VALUE
rb_grn_bulk_to_ruby_object_by_range_id (grn_ctx *context, grn_obj *bulk,
                                        grn_id range_id,
                                        VALUE related_object, VALUE *rb_value)
{
    grn_bool success = GRN_TRUE;

    switch (range_id) {
    case GRN_DB_VOID:
        *rb_value = rb_str_new(GRN_TEXT_VALUE(bulk), GRN_TEXT_LEN(bulk));
        break;
    case GRN_DB_BOOL:
        *rb_value = GRN_BOOL_VALUE(bulk) ? Qtrue : Qfalse;
        break;
    case GRN_DB_INT8:
        *rb_value = INT2NUM(GRN_INT8_VALUE(bulk));
        break;
    case GRN_DB_UINT8:
        *rb_value = UINT2NUM(GRN_UINT8_VALUE(bulk));
        break;
    case GRN_DB_INT16:
        *rb_value = INT2NUM(GRN_INT16_VALUE(bulk));
        break;
    case GRN_DB_UINT16:
        *rb_value = UINT2NUM(GRN_UINT16_VALUE(bulk));
        break;
    case GRN_DB_INT32:
        *rb_value = INT2NUM(GRN_INT32_VALUE(bulk));
        break;
    case GRN_DB_UINT32:
        *rb_value = UINT2NUM(GRN_UINT32_VALUE(bulk));
        break;
    case GRN_DB_INT64:
        *rb_value = LL2NUM(GRN_INT64_VALUE(bulk));
        break;
    case GRN_DB_UINT64:
        *rb_value = ULL2NUM(GRN_UINT64_VALUE(bulk));
        break;
    case GRN_DB_FLOAT:
        *rb_value = rb_float_new(GRN_FLOAT_VALUE(bulk));
        break;
    case GRN_DB_TIME: {
        int64_t time_value, sec, usec;

        time_value = GRN_TIME_VALUE(bulk);
        GRN_TIME_UNPACK(time_value, sec, usec);
        *rb_value = rb_funcall(rb_cTime, rb_intern("at"), 2,
                               LL2NUM(sec), LL2NUM(usec));
        break;
    }
    case GRN_DB_SHORT_TEXT:
    case GRN_DB_TEXT:
    case GRN_DB_LONG_TEXT:
        *rb_value = rb_grn_context_rb_string_new(context,
                                                 GRN_TEXT_VALUE(bulk),
                                                 GRN_TEXT_LEN(bulk));
        break;
    case GRN_DB_TOKYO_GEO_POINT: {
        int latitude, longitude;

        GRN_GEO_POINT_VALUE(bulk, latitude, longitude);
        *rb_value = rb_grn_tokyo_geo_point_new(latitude, longitude);
        break;
    }
    case GRN_DB_WGS84_GEO_POINT: {
        int latitude, longitude;

        GRN_GEO_POINT_VALUE(bulk, latitude, longitude);
        *rb_value = rb_grn_wgs84_geo_point_new(latitude, longitude);
        break;
    }
    default:
        success = GRN_FALSE;
        break;
    }

    return success;
}
Exemplo n.º 9
0
void
test_near_geo_point(gpointer data)
{
  grn_id id;
  int offset, limit;
  const GList *expected_keys;
  GList *actual_keys = NULL;
  grn_table_sort_key keys[2];
  grn_obj base, base_string, location;

  create_geo_table(cut_take_printf(" [\"%s\"],\n"
                                   " [\"%s\"],\n"
                                   " [\"%s\"],\n"
                                   " [\"%s\"],\n"
                                   " [\"%s\"],\n"
                                   " [\"%s\"],\n"
                                   " [\"%s\"],\n"
                                   " [\"%s\"],\n"
                                   " [\"%s\"],\n"
                                   " [\"%s\"],\n"
                                   " [\"%s\"],\n"
                                   " [\"%s\"],\n"
                                   " [\"%s\"],\n"
                                   " [\"%s\"],\n"
                                   " [\"%s\"]",
                                   TAKEN_POINT(0, 0, 0,
                                               180, 0, 0),
                                   TAKEN_POINT(0, 0, 0,
                                               -179, -59, -59),
                                   TAKEN_POINT(-1, -1, -1,
                                               180, 0, 0),
                                   TAKEN_POINT(2, 1, 1,
                                               180, 0, 0),
                                   TAKEN_POINT(-2, -1, -1,
                                               -179, -59, -59),
                                   TAKEN_POINT(1, 2, 1,
                                               -179, -59, -59),
                                   TAKEN_POINT(90, 0, 0,
                                               0, 0, 0),
                                   TAKEN_POINT(-90, 0, 0,
                                               1, 0, 0),
                                   TAKEN_POINT(1, 0, 0,
                                               1, 0, 0),
                                   TAKEN_POINT(1, 1, 0,
                                               1, 1, 0),
                                   TAKEN_POINT(1, 1, 1,
                                               1, 1, 1),
                                   TAKEN_POINT(-1, 0, 0,
                                               1, 1, 1),
                                   TAKEN_POINT(-1, -1, -1,
                                               0, 0, 0),
                                   TAKEN_POINT(-1, -2, -1,
                                               -1, -1, -1),
                                   TAKEN_POINT(1, 1, 10,
                                               -1, -1, -1)));

  result = grn_table_create(context, NULL, 0, NULL, GRN_TABLE_NO_KEY,
                            NULL, table);
  grn_test_assert_context(context);

  GRN_TEXT_INIT(&base_string, 0);
  GRN_TEXT_SETS(context, &base_string, gcut_data_get_string(data, "base"));
  GRN_WGS84_GEO_POINT_INIT(&base, 0);
  grn_obj_cast(context, &base_string, &base, FALSE);
  GRN_OBJ_FIN(context, &base_string);

  offset = gcut_data_get_int(data, "offset");
  if (offset > 0) {
    cut_omit("geo sort doesn't support offset yet.");
  }
  limit = gcut_data_get_int(data, "limit");
  keys[0].key = column;
  keys[0].flags = GRN_TABLE_SORT_GEO;
  keys[0].offset = 0;
  keys[1].key = &base;
  keys[1].flags = 0;
  keys[1].offset = 0;
  grn_table_sort(context, table, offset, limit, result, keys, 2);
  GRN_OBJ_FIN(context, &base);
  grn_test_assert_context(context);
  cursor = grn_table_cursor_open(context, result,
                                 NULL, 0, NULL, 0, 0, -1,
                                 GRN_CURSOR_ASCENDING);
  grn_test_assert_context(context);
  GRN_WGS84_GEO_POINT_INIT(&location, 0);
  while ((id = grn_table_cursor_next(context, cursor))) {
    gint32 *key;
    int key_size;
    gint latitude, longitude;

    key_size = grn_table_cursor_get_value(context, cursor, (void **)&key);
    GRN_BULK_REWIND(&location);
    grn_obj_get_value(context, column, *key, &location);
    GRN_GEO_POINT_VALUE(&location, latitude, longitude);
    actual_keys = g_list_append(actual_keys,
                                inspect_point(latitude, longitude));
  }
  GRN_OBJ_FIN(context, &location);
  gcut_take_list(actual_keys, g_free);

  expected_keys = gcut_data_get_pointer(data, "expected");
  gcut_assert_equal_list_string(expected_keys, actual_keys);
}