void
test_private (void)
{
    const gchar *packet;
    gsize packet_size;

    create_negotiate_packet(&packet, &packet_size);
    gcut_assert_equal_list_string(NULL, private_data_list);
    gcut_assert_error(feed(packet, packet_size));
    cut_assert_equal_int(1, n_negotiates);
    append_expected_private_data("option negotiation");
    gcut_assert_equal_list_string(expected_private_data_list,
                                  private_data_list);

    create_connect_packet_ipv4(&packet, &packet_size);
    gcut_assert_error(feed(packet, packet_size));
    cut_assert_equal_int(1, n_connects);
    append_expected_private_data("connect");
    gcut_assert_equal_list_string(expected_private_data_list,
                                  private_data_list);

    create_helo_packet(&packet, &packet_size);
    gcut_assert_error(feed(packet, packet_size));
    cut_assert_equal_int(1, n_helos);
    append_expected_private_data("helo");
    gcut_assert_equal_list_string(expected_private_data_list,
                                  private_data_list);
}
void
test_temporary_failed_recipients (void)
{
    gcut_assert_equal_list_string(
        NULL,
        milter_message_result_get_temporary_failed_recipients(result));

    milter_message_result_add_temporary_failed_recipient(
        result, "*****@*****.**");
    milter_message_result_add_temporary_failed_recipient(
        result, "*****@*****.**");
    milter_message_result_add_temporary_failed_recipient(
        result, "*****@*****.**");
    gcut_assert_equal_list_string(
        gcut_take_new_list_string("*****@*****.**",
                                  "*****@*****.**",
                                  "*****@*****.**",
                                  NULL),
        milter_message_result_get_temporary_failed_recipients(result));

    milter_message_result_set_temporary_failed_recipients(
        result,
        gcut_take_new_list_string("*****@*****.**",
                                  "*****@*****.**",
                                  NULL));
    gcut_assert_equal_list_string(
        gcut_take_new_list_string("*****@*****.**",
                                  "*****@*****.**",
                                  NULL),
        milter_message_result_get_temporary_failed_recipients(result));
}
void
test_load_paths (void)
{
    const gchar *config_dir;

    config_dir = g_getenv("MILTER_MANAGER_CONFIG_DIR");
    if (config_dir)
        expected_load_paths = g_list_append(expected_load_paths,
                                            g_strdup(config_dir));
    expected_load_paths = g_list_append(expected_load_paths,
                                        g_strdup(CONFIG_DIR));
    gcut_assert_equal_list_string(
        expected_load_paths,
        milter_manager_configuration_get_load_paths(config));

    expected_load_paths = g_list_append(expected_load_paths,
                                        g_strdup("append/XXX"));
    milter_manager_configuration_append_load_path(config, "append/XXX");
    gcut_assert_equal_list_string(
        expected_load_paths,
        milter_manager_configuration_get_load_paths(config));

    expected_load_paths = g_list_prepend(expected_load_paths,
                                         g_strdup("prepend/XXX"));
    milter_manager_configuration_prepend_load_path(config, "prepend/XXX");
    gcut_assert_equal_list_string(
        expected_load_paths,
        milter_manager_configuration_get_load_paths(config));


    milter_manager_configuration_clear_load_paths(config);
    gcut_assert_equal_list_string(
        NULL,
        milter_manager_configuration_get_load_paths(config));
}
Exemplo n.º 4
0
static void
stub_equal_list_string (void)
{
    need_to_free_list_contents = TRUE;

    list1 = g_list_append(list1, g_strdup("abc"));
    list1 = g_list_append(list1, g_strdup("def"));
    list2 = g_list_append(list2, g_strdup("zyx"));
    list2 = g_list_append(list2, g_strdup("wvu"));

    gcut_assert_equal_list_string(list1, list1);
    gcut_assert_equal_list_string(list2, list2);

    MARK_FAIL(gcut_assert_equal_list_string(list1, list2));
}
Exemplo n.º 5
0
void
test_suffix_search(gconstpointer data)
{
  const grn_trie_test_data *test_data = data;
  const gchar key1[] = "セナ";
  const gchar key2[] = "ナセナセ";
  const gchar key3[] = "Groonga";
  const gchar key4[] = "セナ + Ruby";
  const gchar key5[] = "セナセナ";

  trie_test_data_set_parameters(test_data);

  cut_assert_create_trie();

  cut_assert_lookup_add(key1);
  cut_assert_lookup_add(key2);
  cut_assert_lookup_add(key3);
  cut_assert_lookup_add(key4);
  cut_assert_lookup_add(key5);

  cut_assert_create_hash();
  grn_test_assert_equal_rc(test_data->expected_rc,
                           grn_pat_suffix_search(context, trie,
                                                 test_data->search_key,
                                                 strlen(test_data->search_key),
                                                 hash));
  gcut_assert_equal_list_string(test_data->expected_strings,
                                retrieve_all_keys());
}
Exemplo n.º 6
0
void
grn_test_assert_select_helper (grn_ctx *context,
                               const GList *expected,
                               grn_obj *select_result,
                               const gchar *text_column_name,
                               const gchar *expected_expression,
                               const gchar *select_result_expression,
                               const gchar *text_column_name_expression)
{
  const GList *records;
  GList *sorted_records, *sorted_expected;

  records = grn_test_table_collect_string(context,
                                          select_result,
                                          text_column_name);

  sorted_expected = g_list_copy((GList *)expected);
  sorted_expected = g_list_sort(sorted_expected, (GCompareFunc)g_utf8_collate);
  gcut_take_list(sorted_expected, NULL);

  sorted_records = g_list_copy((GList *)records);
  sorted_records = g_list_sort(sorted_records, (GCompareFunc)g_utf8_collate);
  gcut_take_list(sorted_records, NULL);

  gcut_assert_equal_list_string(sorted_expected, sorted_records);
}
Exemplo n.º 7
0
void
test_font (void)
{
  PopplerFontInfo *font_info;
  PopplerFontsIter *iter;
  gint n_pages;

  document = load_document ("slide.pdf");
  n_pages = poppler_document_get_n_pages (document);
  font_info = poppler_font_info_new (document);
  while (poppler_font_info_scan (font_info, n_pages, &iter))
    {
      if (iter)
        {
          do
            {
              actual_font_names =
                g_list_append (actual_font_names,
                               g_strdup (poppler_fonts_iter_get_name (iter)));
            } while (poppler_fonts_iter_next (iter));
          poppler_fonts_iter_free (iter);
        }
    }
  g_object_unref (font_info);

  expected_font_names = gcut_list_string_new ("IPAPMincho",
                                              "LiberationSans-Regular",
                                              NULL);
  gcut_assert_equal_list_string (expected_font_names,
                                 actual_font_names);
}
Exemplo n.º 8
0
void
test_cursor(gconstpointer data)
{
  GList *expected, *records = NULL;
  gint offset, limit;
  grn_obj *geo_cursor;
  grn_posting *posting;

  offset = gcut_data_get_int(data, "offset");
  limit = gcut_data_get_int(data, "limit");
  geo_cursor = grn_geo_cursor_open_in_rectangle(context,
                                                location_index,
                                                nerima_wgs84, tokyo_wgs84,
                                                offset, limit);
  while ((posting = grn_geo_cursor_next(context, geo_cursor))) {
    grn_id shop_id = posting->rid;
    gchar key[GRN_TABLE_MAX_KEY_SIZE];
    gint key_size;

    key_size = grn_table_get_key(context, shops, shop_id,
                                 &key, GRN_TABLE_MAX_KEY_SIZE);
    records = g_list_append(records, g_strndup(key, key_size));
  }
  grn_obj_unlink(context, geo_cursor);

  expected = (GList *)gcut_data_get_pointer(data, "expected");
  gcut_take_list(records, g_free);
  gcut_assert_equal_list_string(expected, records);
}
Exemplo n.º 9
0
static void
stub_equal_list_string_both_null (void)
{
    need_to_free_list_contents = TRUE;

    list1 = g_list_append(list1, g_strdup("abc"));
    list1 = g_list_append(list1, NULL);
    list1 = g_list_append(list1, g_strdup("def"));
    list2 = g_list_append(list2, g_strdup("abc"));
    list2 = g_list_append(list2, NULL);
    list2 = g_list_append(list2, g_strdup("def"));

    gcut_assert_equal_list_string(list1, list1);
    gcut_assert_equal_list_string(list2, list2);

    gcut_assert_equal_list_string(list1, list2);
}
Exemplo n.º 10
0
void
milter_assert_equal_header_helper (MilterHeader *expected,
                                   MilterHeader *actual,
                                   const gchar *expression_expected,
                                   const gchar *expression_actual)
{
    gcut_assert_equal_list_string(
        gcut_take_new_list_string(expected->name, expected->value, NULL),
        gcut_take_new_list_string(actual->name, actual->value, NULL));
}
static void
milter_assert_equal_location_keys_helper (const GList *expected)
{
    GHashTable *locations;
    GList *keys;

    locations = milter_manager_configuration_get_locations(config);
    keys = g_list_sort(g_hash_table_get_keys(locations), (GCompareFunc)strcmp);
    gcut_assert_equal_list_string(expected, gcut_take_list(keys, NULL));
}
Exemplo n.º 12
0
void
test_next_with_no_entry(gconstpointer data)
{
  const grn_trie_test_data *test_data = data;

  trie_test_data_set_parameters(test_data);

  cut_assert_create_trie();
  cut_assert_open_cursor();
  gcut_assert_equal_list_string(NULL, retrieve_all_keys());
}
Exemplo n.º 13
0
void
test_by_id_over_offset(void)
{
  default_cursor_flags |= GRN_CURSOR_BY_ID;
  default_cursor_offset = 1;

  cut_assert_create_trie();

  cut_assert_open_cursor();
  gcut_assert_equal_list_string(NULL,
                                retrieve_all_keys());
}
Exemplo n.º 14
0
void
grn_test_assert_open_hash_helper(grn_hash **hash, GrnTestHashFactory *factory)
{
  GError *error = NULL;
  grn_logger_info *logger;

  logger = grn_test_hash_factory_get_logger(factory);
  cut_assert_not_null(logger);
  grn_collect_logger_clear_messages(logger);
  *hash = grn_test_hash_factory_open(factory, &error);
  gcut_assert_error(error);
  cut_assert_not_null(*hash);
  gcut_assert_equal_list_string(NULL, grn_collect_logger_get_messages(logger));
}
Exemplo n.º 15
0
void
grn_test_assert_equal_table_helper (grn_ctx *context,
                                    const GList *expected,
                                    grn_obj *table,
                                    const gchar *text_column_name,
                                    const gchar *expected_expression,
                                    const gchar *select_result_expression,
                                    const gchar *text_column_name_expression)
{
  const GList *records;

  records = grn_test_table_collect_string(context, table, text_column_name);
  gcut_assert_equal_list_string(expected, records);
}
Exemplo n.º 16
0
void
grn_test_assert_equal_view_helper (grn_ctx *context,
                                   const GList *expected,
                                   grn_obj *view,
                                   const gchar *text_column_name,
                                   const gchar *expected_expression,
                                   const gchar *view_expression,
                                   const gchar *text_column_name_expression)
{
  const GList *records;

  records = grn_test_view_collect_string(context, view, text_column_name);
  gcut_assert_equal_list_string(expected, records);
}
Exemplo n.º 17
0
void
test_value(gconstpointer data)
{
  const grn_trie_test_data *test_data = data;
  const gchar key1[] = "セナ";
  const gchar key2[] = "ナセナセ";
  const gchar key3[] = "Groonga";
  const gchar key4[] = "セナ + Ruby";
  const gchar key5[] = "セナセナ";
  gchar value2[] = "VALUE2";
  gchar value4_1[] = "Groonga";
  gchar value4_2[] = "るびい";
  gchar value5_1[] = "上書きされる値 - overridden value";
  gchar value5_2[] = "上書きされた値 - override value";

  trie_test_data_set_parameters(test_data);

  cut_assert_create_trie();

  cut_assert_lookup_add(key1);
  cut_assert_lookup_add(key2);
  cut_assert_lookup_add(key3);
  cut_assert_lookup_add(key4);
  cut_assert_lookup_add(key5);

  cut_assert_open_cursor();
  while (grn_pat_cursor_next(context, cursor) != GRN_ID_NIL) {
    void *key;
    gchar *null_terminated_key;
    int size;

    size = grn_pat_cursor_get_key(context, cursor, &key);
    null_terminated_key = g_string_free(g_string_new_len(key, size), FALSE);
    if (g_str_equal(null_terminated_key, key2)) {
      grn_pat_cursor_set_value(context, cursor, value2, GRN_OBJ_SET);
    } else if (g_str_equal(null_terminated_key, key4)) {
      grn_pat_cursor_set_value(context, cursor, value4_1, GRN_OBJ_INCR);
      grn_pat_cursor_set_value(context, cursor, value4_2, GRN_OBJ_INCR);
    } else if (g_str_equal(null_terminated_key, key5)) {
      grn_pat_cursor_set_value(context, cursor, value5_1, GRN_OBJ_SET);
      grn_pat_cursor_set_value(context, cursor, value5_2, GRN_OBJ_SET);
    }
  }
  cursor_free();

  cut_assert_open_cursor();
  gcut_assert_equal_list_string(test_data->expected_strings,
                                retrieve_all_keys_and_values());
}
Exemplo n.º 18
0
void
test_next_with_one_entry(gconstpointer data)
{
  const grn_trie_test_data *test_data = data;
  const gchar key[] = "セナ";

  trie_test_data_set_parameters(test_data);

  cut_assert_create_trie();

  cut_assert_lookup_add(key);

  cut_assert_open_cursor();
  gcut_assert_equal_list_string(test_data->expected_strings,
                                retrieve_all_keys());
}
Exemplo n.º 19
0
void
test_select(void)
{
  grn_test_assert(grn_geo_select_in_rectangle(context,
                                              location_index,
                                              nerima_wgs84, tokyo_wgs84,
                                              result, GRN_OP_OR));
  gcut_assert_equal_list_string(
    gcut_take_new_list_string("soba-taiyaki-ku",
                              "sazare",
                              "hirose-ya",
                              "taiyaki-kataoka",
                              "kuruma",
                              "nezu-no-taiyaki",
                              NULL),
    result_to_list());
}
Exemplo n.º 20
0
void
test_cursor(gconstpointer data)
{
  GList *expected, *records = NULL;
  gint offset = 0;
  gint limit = -1;
  grn_obj top_left, bottom_right;
  grn_obj *geo_cursor;
  grn_posting *posting;
  grn_obj short_degree;

  set_geo_point(&top_left,
                gcut_data_get_int(data, "top"),
                gcut_data_get_int(data, "left"));
  set_geo_point(&bottom_right,
                gcut_data_get_int(data, "bottom"),
                gcut_data_get_int(data, "right"));
  geo_cursor = grn_geo_cursor_open_in_rectangle(context,
                                                location_index_column,
                                                &top_left,
                                                &bottom_right,
                                                offset, limit);
  grn_obj_unlink(context, &top_left);
  grn_obj_unlink(context, &bottom_right);

  GRN_TEXT_INIT(&short_degree, 0);
  while ((posting = grn_geo_cursor_next(context, geo_cursor))) {
    grn_id point_id = posting->rid;

    GRN_BULK_REWIND(&short_degree);
    grn_obj_get_value(context, short_degree_column, point_id, &short_degree);
    records = g_list_append(records,
                            g_strndup(GRN_TEXT_VALUE(&short_degree),
                                      GRN_TEXT_LEN(&short_degree)));
  }
  grn_obj_unlink(context, &short_degree);
  grn_obj_unlink(context, geo_cursor);

  records = g_list_sort(records, (GCompareFunc)strcmp);
  gcut_take_list(records, g_free);

  expected = (GList *)gcut_data_get_pointer(data, "expected");
  gcut_assert_equal_list_string(expected, records);
}
void
test_common_prefix_search(gpointer data)
{
  grn_id id;
  const gchar *max;
  int min_size, offset, limit, flags;
  const GList *expected_keys;
  GList *actual_keys = NULL;

  cut_omit("crashed. Is it right usage?");
  create_short_text_table(gcut_take_new_list_string("abra",
                                                    "abracada",
                                                    "abracadabra",
                                                    "abubu",
                                                    "あ",
                                                    "ああ",
                                                    "あああ",
                                                    "い",
                                                    NULL));

  min_size = gcut_data_get_int(data, "min-size");
  max = gcut_data_get_string(data, "max");
  offset = gcut_data_get_int(data, "offset");
  limit = gcut_data_get_int(data, "limit");
  flags = gcut_data_get_int(data, "flags");
  cursor = grn_table_cursor_open(context, table,
                                 NULL, min_size,
                                 max, strlen(max),
                                 offset, limit,
                                 flags | GRN_CURSOR_PREFIX);
  grn_test_assert_context(context);
  while ((id = grn_table_cursor_next(context, cursor))) {
    gchar *key;
    int key_size;

    key_size = grn_table_cursor_get_key(context, cursor, (void **)&key);
    actual_keys = g_list_append(actual_keys, g_strndup(key, key_size));
  }
  gcut_take_list(actual_keys, g_free);

  expected_keys = gcut_data_get_pointer(data, "expected");
  gcut_assert_equal_list_string(expected_keys, actual_keys);
}
Exemplo n.º 22
0
void
test_by_key_descending_max(void)
{
  default_cursor_min = g_strdup("0");
  default_cursor_min_size = strlen(default_cursor_min);
  default_cursor_max = g_strdup("9989");
  default_cursor_max_size = strlen(default_cursor_max);
  default_cursor_flags |= GRN_CURSOR_DESCENDING;

  cut_assert_create_trie();

  cut_assert_lookup_add("997");
  cut_assert_lookup_add("999");
  cut_assert_lookup_add("9998");

  cut_assert_open_cursor();
  gcut_assert_equal_list_string(gcut_take_new_list_string("997", NULL),
                                retrieve_all_keys());
}
Exemplo n.º 23
0
void
test_delete(gconstpointer data)
{
  const grn_trie_test_data *test_data = data;
  const gchar key1[] = "セナ";
  const gchar key2[] = "ナセナセ";
  const gchar key3[] = "Groonga";
  const gchar key4[] = "セナ + Ruby";
  const gchar key5[] = "セナセナ";

  trie_test_data_set_parameters(test_data);

  cut_assert_create_trie();

  cut_assert_lookup_add(key1);
  cut_assert_lookup_add(key2);
  cut_assert_lookup_add(key3);
  cut_assert_lookup_add(key4);
  cut_assert_lookup_add(key5);

  cut_assert_open_cursor();
  while (grn_pat_cursor_next(context, cursor) != GRN_ID_NIL) {
    void *key;
    gchar *null_terminated_key;
    int size;

    size = grn_pat_cursor_get_key(context, cursor, &key);
    null_terminated_key = g_string_free(g_string_new_len(key, size), FALSE);
    if (g_str_equal(null_terminated_key, key1) ||
        g_str_equal(null_terminated_key, key5)) {
      grn_pat_cursor_delete(context, cursor, NULL);
    }
  }
  cursor_free();

  cut_assert_open_cursor();
  gcut_assert_equal_list_string(test_data->expected_strings,
                                retrieve_all_keys());
}
Exemplo n.º 24
0
void
test_next_with_multi_entries(gconstpointer data)
{
  const grn_trie_test_data *test_data = data;
  const gchar key1[] = "セナ";
  const gchar key2[] = "ナセナセ";
  const gchar key3[] = "Groonga";
  const gchar key4[] = "セナ + Ruby";
  const gchar key5[] = "セナセナ";

  trie_test_data_set_parameters(test_data);

  cut_assert_create_trie();

  cut_assert_lookup_add(key1);
  cut_assert_lookup_add(key2);
  cut_assert_lookup_add(key3);
  cut_assert_lookup_add(key4);
  cut_assert_lookup_add(key5);

  cut_assert_open_cursor();
  gcut_assert_equal_list_string(test_data->expected_strings,
                                retrieve_all_keys());
}
Exemplo n.º 25
0
void
test_crud(void)
{
    cut_assert_create();

    add_data(1, 1, "API.JA");
    add_data(2, 1, "CHECKINSTALL.JA");
    add_data(3, 1, "FUTUREWORKS.JA");
    add_data(4, 1, "INSTALL.JA");
    gcut_assert_equal_list_string(gcut_take_new_list_string("1", "2", "3", NULL),
                                  retrieve_record_ids("検索"));

    remove_data(1, 1, "API.JA");
    gcut_assert_equal_list_string(gcut_take_new_list_string("2", "3", NULL),
                                  retrieve_record_ids("検索"));

    update_data(3, 1, "FUTUREWORKS.JA", "Makefile.am");
    gcut_assert_equal_list_string(gcut_take_new_list_string("2", NULL),
                                  retrieve_record_ids("検索"));

    remove_data(2, 1, "CHECKINSTALL.JA");
    add_data(3, 2, "FUTUREWORKS.JA");
    gcut_assert_equal_list_string(gcut_take_new_list_string("3", NULL),
                                  retrieve_record_ids("検索"));

    update_data(4, 1, "INSTALL.JA", "README.JA");
    gcut_assert_equal_list_string(gcut_take_new_list_string("3", "4", NULL),
                                  retrieve_record_ids("検索"));

    remove_data(4, 1, "README.JA");
    gcut_assert_equal_list_string(gcut_take_new_list_string("3", NULL),
                                  retrieve_record_ids("検索"));

    remove_data(3, 2, "FUTUREWORKS.JA");
    cut_set_message("this assertion is wrong?");
    gcut_assert_equal_list_string(NULL, retrieve_record_ids("検索"));
}
void
test_near_geo_point(gpointer data)
{
  grn_id id;
  int min_size, offset, limit, flags;
  grn_obj max_string, max;
  const GList *expected_keys;
  GList *actual_keys = NULL;

  create_geo_point_table(
    cut_take_printf(" [\"%s\"],"
                    " [\"%s\"],"
                    " [\"%s\"],"
                    " [\"%s\"],"
                    " [\"%s\"],"
                    " [\"%s\"],"
                    " [\"%s\"],"
                    " [\"%s\"],"
                    " [\"%s\"]",
                    TAKEN_POINT(1, 2, 3,
                                4, 5, 6),
                    TAKEN_POINT(1, 2, 3,
                                7, 8, 9),
                    TAKEN_POINT(7, 8, 9,
                                4, 5, 6),
                    TAKEN_POINT(89, 59, 59,
                                179, 59, 59),
                    TAKEN_POINT(89, 59, 59,
                                179, -59, -59),
                    TAKEN_POINT(88, 58, 58,
                                178, 58, 58),
                    TAKEN_POINT(-89, -59, -59,
                                -179, -59, -59),
                    TAKEN_POINT(-89, -59, -59,
                                179, 59, 59),
                    TAKEN_POINT(-88, -58, -58,
                                -178, -58, -58)));

  min_size = gcut_data_get_int(data, "min-size");
  GRN_TEXT_INIT(&max_string, 0);
  GRN_TEXT_PUTS(context, &max_string, gcut_data_get_string(data, "max"));
  GRN_WGS84_GEO_POINT_INIT(&max, 0);
  grn_obj_cast(context, &max_string, &max, FALSE);
  grn_obj_unlink(context, &max_string);
  offset = gcut_data_get_int(data, "offset");
  limit = gcut_data_get_int(data, "limit");
  flags = gcut_data_get_int(data, "flags");
  cursor = grn_table_cursor_open(context, table,
                                 NULL, min_size,
                                 GRN_BULK_HEAD(&max), GRN_BULK_VSIZE(&max),
                                 offset, limit,
                                 flags | GRN_CURSOR_PREFIX);
  grn_obj_unlink(context, &max);
  grn_test_assert_context(context);
  while ((id = grn_table_cursor_next(context, cursor))) {
    grn_geo_point *key;
    int key_size;

    key_size = grn_table_cursor_get_key(context, cursor, (void **)&key);
    actual_keys = g_list_append(actual_keys,
                                g_strdup_printf("%dx%d",
                                                key->latitude,
                                                key->longitude));
  }
  gcut_take_list(actual_keys, g_free);

  expected_keys = gcut_data_get_pointer(data, "expected");
  gcut_assert_equal_list_string(expected_keys, actual_keys);
}
void
test_prefix_geo_point(gpointer data)
{
  grn_id id;
  grn_obj min, min_string;
  int offset, limit, flags;
  unsigned min_size;
  const GList *expected_keys;
  GList *actual_keys = NULL;

  create_geo_point_table(
    geo_byte_load_data(
      "00000000 00111111 01010000 00110000 01001010 01011100 01101010 00010001",
      "00000000 00111111 01010000 00001101 01011101 01011011 01011001 01010011",
      "00000000 00111111 01010000 00000001 00011110 01010001 01101001 00110000",
      "00000000 00111111 01010000 00011000 01110000 00001011 00101110 01001010",
      "00000000 00111111 01010000 00010010 00110001 00110111 01111000 01110000",
      "00000000 00111111 01010000 00010010 00110001 00001000 00001010 00110011",
      "00000000 00111111 01010000 00101110 01110010 00111001 00011011 01101010",
      "00000000 00111111 01010000 00101101 00101000 00111111 01010110 00010110",
      "00000000 00111111 01010000 00101111 01001010 01101000 01000100 01100011",
      "00000000 00111111 01010000 00101111 00011000 01000110 00100101 01011110",
      "00000000 00111111 01000101 01011001 01010110 00000111 00110100 01111111",
      "00000000 00111111 01000101 01010010 01100101 01100110 00010111 01111110",
      "00000000 00111111 01000101 01111111 01011011 01111101 00001001 01100001",
      "00000000 00111111 01010000 00100011 00001010 00000000 00001101 00111010",
      "00000000 00111111 01010000 00101110 01010011 00101001 00101001 00100011",
      "00000000 00111111 01010000 00111010 01011111 00000010 00101001 01010000",
      "00000000 00111111 01010000 00111001 00111101 00001001 00001011 01010011",
      "00000000 00111111 01000101 01011100 00001100 01000001 01011010 00010011",
      "00000000 00111111 01010000 00100011 00000001 00000111 01011100 01110011",
      "00000000 00111111 01010000 00100011 01100100 01011000 00000111 01110010",
      "00000000 00111111 01010000 00111000 01100100 01101011 01111100 01111011",
      "00000000 00111111 01010000 00001111 00101011 00011111 00110011 00001001",
      "00000000 00111111 01000101 01111011 01001011 01101011 00001001 00000001",
      "00000000 00111111 01000101 01011010 00110100 00000010 01111010 00000000",
      "00000000 00111111 01000101 01011011 00011010 00010111 00011000 00100000",
      "00000000 00111111 01010000 00100000 00010111 01000111 00110100 00101010",
      "00000000 00111111 01010000 00000000 01111101 00010000 00011101 00001111",
      "00000000 00111111 01000101 01000100 01010010 00100100 01100011 00111011",
      "00000000 00111111 01000101 01010001 00011100 01010110 00100110 00000110",
      "00000000 00111111 01010000 00101101 01111100 01101100 00111000 01111001",
      "00000000 00111111 01000101 01001101 00111110 00000101 00101010 01000101",
      "00000000 00111111 01000101 01000100 01111100 01101011 01101111 00010101",
      "00000000 00111111 01000101 01110111 01010100 01110100 01111000 01111000",
      "00000000 00111111 01010000 00100010 00111011 01000000 00111000 01100100",
      "00000000 00111111 01010000 00100010 00100111 01000011 00000010 01101001",
      "00000000 00111111 01000101 01011100 00110110 00100010 00111000 01100001",
      "00000000 00111101 01010101 00111101 01110000 01001011 01110011 00101100",
      "00000000 00111101 00000101 00111101 01110000 01001011 01110011 00101100",
      NULL));

  GRN_TEXT_INIT(&min_string, 0);
  GRN_TEXT_PUTS(context, &min_string,
                geo_byte_parse(gcut_data_get_string(data, "min")));
  GRN_WGS84_GEO_POINT_INIT(&min, 0);
  grn_obj_cast(context, &min_string, &min, FALSE);
  grn_obj_unlink(context, &min_string);

  min_size = gcut_data_get_uint(data, "min-size");
  offset = gcut_data_get_int(data, "offset");
  limit = gcut_data_get_int(data, "limit");
  flags = gcut_data_get_int(data, "flags");
  cursor = grn_table_cursor_open(context, table,
                                 GRN_BULK_HEAD(&min), min_size,
                                 NULL, 0,
                                 offset, limit,
                                 flags | GRN_CURSOR_PREFIX);
  grn_obj_unlink(context, &min);
  grn_test_assert_context(context);
  while ((id = grn_table_cursor_next(context, cursor))) {
    grn_geo_point *key;
    int i, j, key_size;
    uint8_t encoded_key[sizeof(grn_geo_point)];
    GString *geo_byte;

    key_size = grn_table_cursor_get_key(context, cursor, (void **)&key);
    grn_gton(encoded_key, key, key_size);
    geo_byte = g_string_new(NULL);
    for (i = 0; i < sizeof(grn_geo_point); i++) {
      if (i != 0) {
        g_string_append(geo_byte, " ");
      }
      for (j = 0; j < 8; j++) {
        g_string_append_printf(geo_byte, "%d", (encoded_key[i] >> (7 - j)) & 1);
      }
    }
    actual_keys = g_list_append(actual_keys, g_string_free(geo_byte, FALSE));
  }
  gcut_take_list(actual_keys, g_free);

  expected_keys = gcut_data_get_pointer(data, "expected");
  gcut_assert_equal_list_string(expected_keys, actual_keys);
}
Exemplo n.º 28
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);
}
void
test_prefix_rk(gpointer data)
{
  grn_id id;
  const gchar *min;
  int offset, limit;
  const GList *expected_keys;
  GList *actual_keys = NULL;

  create_short_text_table(
    gcut_take_new_list_string("インデックス",
                              "エヌグラム",
                              "エンジン",
                              "カネソナエタ",
                              "カノウ",
                              "キノウ",
                              "キョウカ",
                              "クミコミ",
                              "クミコム",
                              "グルンガ",
                              "ケンサク",
                              "ケンサクヨウキュウ",
                              "ゲンゴ",
                              "コウセイド",
                              "コウソク",
                              "コンパクト",
                              "サクセイ",
                              "ショリ",
                              "ショリケイ",
                              "ジッソウ",
                              "ジュンスイ",
                              "スクリプト",
                              "セッケイ",
                              "ゼンブン",
                              "タイプ",
                              "タンゴ",
                              "ダイキボ",
                              "テンチ",
                              "ディービーエムエス",
                              "トウ",
                              "トクチョウ",
                              "ブンショリョウ",
                              "ヨウキュウ",
                              NULL));

  min = gcut_data_get_string(data, "min");
  offset = gcut_data_get_int(data, "offset");
  limit = gcut_data_get_int(data, "limit");
  cursor = grn_table_cursor_open(context, table,
                                 min, strlen(min),
                                 NULL, 0,
                                 offset, limit,
                                 GRN_CURSOR_PREFIX | GRN_CURSOR_RK);
  grn_test_assert_context(context);
  while ((id = grn_table_cursor_next(context, cursor))) {
    gchar *key;
    int key_size;

    key_size = grn_table_cursor_get_key(context, cursor, (void **)&key);
    actual_keys = g_list_append(actual_keys, g_strndup(key, key_size));
  }
  actual_keys = g_list_sort(actual_keys, (GCompareFunc)strcmp);
  gcut_take_list(actual_keys, g_free);

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