Exemple #1
0
void
test_null(gconstpointer data)
{
    assert_send_command("table_create Students TABLE_HASH_KEY ShortText");
    assert_send_command("column_create Students nick COLUMN_SCALAR ShortText");
    assert_send_command("column_create Students scores COLUMN_VECTOR Int32");

    cut_assert_equal_string("1",
                            send_command("load --table Students\n"
                                         "[{\"_key\": \"Daijiro MORI\", "
                                         "\"nick\": \"morita\", "
                                         "\"scores\": [5, 5, 5]}]"));
    cut_assert_equal_string("1",
                            send_command(gcut_data_get_string(data, "load")));
    cut_assert_equal_string(gcut_data_get_string(data, "expected"),
                            send_command("select Students"));
}
Exemple #2
0
void
test_text_error(gconstpointer data)
{
  grn_obj_reinit(&context, &dest, gcut_data_get_uint(data, "type"), 0);
  grn_obj_reinit(&context, &src, GRN_DB_TEXT, 0);
  GRN_TEXT_PUTS(&context, &src, gcut_data_get_string(data, "text"));
  grn_test_assert_equal_rc(gcut_data_get_uint(data, "expected"),
                           grn_obj_cast(&context, &src, &dest, GRN_FALSE));
}
Exemple #3
0
void
test_is_builtin(gconstpointer data)
{
  const gchar *name;
  grn_obj *object;

  assert_send_command("register suggest/suggest");
  assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
  assert_send_command("column_create Users name COLUMN_SCALAR ShortText");

  name = gcut_data_get_string(data, "name");
  object = grn_ctx_get(context, name, strlen(name));
  if (gcut_data_get_string(data, "expected")) {
    cut_assert_true(grn_obj_is_builtin(context, object));
  } else {
    cut_assert_false(grn_obj_is_builtin(context, object));
  }
}
Exemple #4
0
void
test_id_is_number_family(gconstpointer data)
{
  const gchar *name;
  grn_obj *object;
  grn_id id;

  assert_send_command("table_create Users TABLE_HASH_KEY ShortText");

  name = gcut_data_get_string(data, "name");
  object = grn_ctx_get(context, name, strlen(name));
  id = grn_obj_id(context, object);
  if (gcut_data_get_string(data, "expected")) {
    cut_assert_true(grn_type_id_is_number_family(context, id));
  } else {
    cut_assert_false(grn_type_id_is_number_family(context, id));
  }
}
Exemple #5
0
void
test_is_reference_column(gconstpointer data)
{
  const gchar *name;
  grn_obj *object;

  assert_send_command("table_create Names TABLE_PAT_KEY ShortText");
  assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
  assert_send_command("column_create Users age COLUMN_SCALAR UInt8");
  assert_send_command("column_create Users name COLUMN_SCALAR Names");

  name = gcut_data_get_string(data, "name");
  object = grn_ctx_get(context, name, strlen(name));
  if (gcut_data_get_string(data, "expected")) {
    cut_assert_true(grn_obj_is_reference_column(context, object));
  } else {
    cut_assert_false(grn_obj_is_reference_column(context, object));
  }
}
void
test_invalid(gconstpointer data)
{
  unsigned nkeys;
  const char *str = gcut_data_get_string(data, "keys");
  grn_table_sort_key *keys = grn_table_sort_key_from_str(context, str, strlen(str),
                                                         table, &nkeys);
  cut_assert_null(keys);
  cut_assert_equal_uint(0, nkeys);
}
Exemple #7
0
void
test_uvector_column(gconstpointer data)
{
  const gchar *expected;
  grn_id id, type_id;
  grn_obj uvector;
  grn_obj *elements;
  grn_obj *table, *column;
  const gchar *type_name;
  type_name = gcut_data_get_string(data, "type_name");
  type_id = grn_obj_id(context, get_object(type_name));

  table = table_create("Table", GRN_OBJ_TABLE_NO_KEY, NULL, NULL);
  grn_test_assert_context(context);
  column = column_create("Table", "Column", GRN_OBJ_COLUMN_VECTOR,
                         type_name, NULL);
  grn_test_assert_context(context);
  id = grn_table_add(context, table, NULL, 0, NULL);
  grn_test_assert_context(context);
  cut_assert_equal_int(1, id);
  elements = construct_elements(data);

  GRN_OBJ_INIT(&uvector, GRN_UVECTOR, 0, type_id);
  grn_bulk_write(context, &uvector,
                 GRN_BULK_HEAD(&elements[0]), GRN_BULK_VSIZE(&elements[0]));
  grn_bulk_write(context, &uvector,
                 GRN_BULK_HEAD(&elements[1]), GRN_BULK_VSIZE(&elements[1]));
  grn_bulk_write(context, &uvector,
                 GRN_BULK_HEAD(&elements[2]), GRN_BULK_VSIZE(&elements[2]));
  grn_obj_set_value(context, column, id, &uvector, GRN_OBJ_SET);

  expected = cut_take_printf("table_create Table TABLE_NO_KEY\n"
                             "column_create Table Column COLUMN_VECTOR %s\n"
                             "load --table Table\n"
                             "[\n"
                             "[\"_id\",\"Column\"],\n"
                             "[1,%s]\n"
                             "]",
                             type_name,
                             gcut_data_get_string(data, "expected"));
  cut_assert_equal_string(expected, send_command("dump"));
  GRN_OBJ_FIN(context, &uvector);
}
Exemple #8
0
void
test_text_to_table(gconstpointer data)
{
  gsize expected_size;

  grn_obj_reinit(&context, &dest, users, 0);
  expected_size = gcut_data_get_size(data, "expected-size");
  if (expected_size == 0) {
    cast_text(GRN_INVALID_ARGUMENT, gcut_data_get_string(data, "text"));
    cut_assert_equal_uint(0, GRN_BULK_VSIZE(&dest));
  } else {
    cast_text(GRN_SUCCESS, gcut_data_get_string(data, "text"));
    grn_test_assert_equal_record_id(&context,
                                    grn_ctx_at(&context, users),
                                    gcut_data_get_uint(data, "expected"),
                                    GRN_RECORD_VALUE(&dest));
    cut_assert_equal_uint(expected_size, GRN_BULK_VSIZE(&dest));
  }
}
Exemple #9
0
void
test_type_to_string(gconstpointer data)
{
  const gchar *expected;
  guint type;

  expected = gcut_data_get_string(data, "expected");
  type = gcut_data_get_uint(data, "type");
  cut_assert_equal_string(expected,
                          grn_obj_type_to_string(type));
}
Exemple #10
0
void
test_create(gconstpointer data)
{
  const gchar *name, *path;
  grn_obj_flags flags = GRN_OBJ_TABLE_VIEW;

  name = gcut_data_get_string(data, "name");
  path = gcut_data_get_string(data, "path");

  if (name || path) {
    flags |= GRN_OBJ_PERSISTENT;
  }

  view = grn_table_create(context,
                          name, name ? strlen(name) : 0,
                          path,
                          flags,
                          NULL, NULL);
  grn_test_assert_not_null(context, view);
}
Exemple #11
0
void
test_create_with_valid_name(gpointer data)
{
  grn_obj *table;
  const gchar *table_name;

  table_name = gcut_data_get_string(data, "name");
  table = grn_table_create(context, table_name, strlen(table_name),
                           NULL,
                           GRN_OBJ_TABLE_NO_KEY | GRN_OBJ_PERSISTENT,
                           NULL, NULL);
  grn_test_assert_context(context);
}
Exemple #12
0
void
test_urlenc(gconstpointer data)
{
  grn_obj buffer;
  const gchar *expected, *input;
  gint input_length;

  expected = gcut_data_get_string(data, "expected");
  input = gcut_data_get_string(data, "input");
  input_length = gcut_data_get_int(data, "input-length");

  if (input_length < 0) {
    input_length = strchr(input, '\0') - input;
  }

  GRN_TEXT_INIT(&buffer, 0);
  grn_text_urlenc(&context, &buffer, input, input_length);
  cut_assert_equal_substring(expected,
                             GRN_TEXT_VALUE(&buffer),
                             GRN_TEXT_LEN(&buffer));
  GRN_OBJ_FIN(&context, &buffer);
}
Exemple #13
0
void
test_atoull(gconstpointer data)
{
  const gchar *input, *input_end, *rest;
  uint64_t value;

  input = gcut_data_get_string(data, "input");
  input_end = strchr(input, '\0');
  value = grn_atoull(input, input_end, &rest);
  cut_assert_equal_string(input_end, rest);
  gcut_assert_equal_uint64(gcut_data_get_uint64(data, "expected"),
                           value);
}
void
test_valid(gconstpointer data)
{
  unsigned i, nkeys;
  const char *str = gcut_data_get_string(data, "keys");
  grn_table_sort_key *keys = grn_table_sort_key_from_str(context, str, strlen(str),
                                                         table, &nkeys);
  cut_assert_not_null(keys);
  cut_assert_equal_uint(gcut_data_get_uint(data, "count"), nkeys);
  for (i = 0; i < nkeys; ++i) {
    cut_assert_not_null(keys[i].key);
  }
}
void
test_not_tokenize_by_full_width_space(gconstpointer data)
{
  const gchar *error_message;
  const gchar *command;

  error_message = gcut_data_get_string(data, "error-message");
  command = gcut_data_get_string(data, "command");

  assert_send_command("table_create Sites TABLE_HASH_KEY ShortText");
  cut_assert_equal_string(
    "3",
    send_command("load --table Sites --columns '_key' \n"
                 "[\n"
                 " [\"groonga.org\"],\n"
                 " [\"ruby-lang.org\"],\n"
                 " [\"qwik.jp/senna/\"]\n"
                 "]"));

  assert_send_command_error(GRN_INVALID_ARGUMENT,
                            error_message,
                            command);
}
void
test_not_expand_OR_with_leading_space(gconstpointer data)
{
  cut_assert_equal_string(
    "[[[0],"
     "[[\"_id\",\"UInt32\"],"
      "[\"_key\",\"Time\"],"
      "[\"content\",\"Text\"]]]]",
    send_command(
      cut_take_printf("select Diaries --sortby _id "
                      "--match_columns content --query '\"OR \"' "
                      "--query_expansion Synonyms.%s",
                      gcut_data_get_string(data, "column-name"))));
}
void
test_expand_prefix(gconstpointer data)
{
  cut_assert_equal_string(
    "[[[1],"
     "[[\"_id\",\"UInt32\"],"
      "[\"_key\",\"Time\"],"
      "[\"content\",\"Text\"]],"
      "[10,1316444400.0,\"明日は日本語あるいは中国語を勉強します。\"]]]",
    send_command(
      cut_take_printf("select Diaries --sortby _id "
                      "--match_columns content --query 'Japan*' "
                      "--query_expansion Synonyms.%s",
                      gcut_data_get_string(data, "column-name"))));
}
Exemple #18
0
void
test_normalize(gconstpointer data)
{
  const gchar *utf8_expected, *encoded_expected;
  const gchar *utf8_input, *encoded_input;
  grn_obj *string;
  const gchar *normalized_text;
  guint normalized_text_length;
  guint normalized_text_n_characters;
  int flags;
  grn_encoding encoding;

  encoding = gcut_data_get_int(data, "encoding");
  GRN_CTX_SET_ENCODING(&context, encoding);
  flags = GRN_STRING_WITH_CHECKS | GRN_STRING_WITH_TYPES;
  utf8_input = gcut_data_get_string(data, "input");
  encoded_input = convert_encoding(utf8_input, encoding);
  string = grn_string_open(&context,
                           encoded_input,
                           strlen(encoded_input),
                           GRN_NORMALIZER_AUTO,
                           flags);
  grn_string_get_normalized(&context, string,
                            &normalized_text,
                            &normalized_text_length,
                            &normalized_text_n_characters);
  normalized_text = cut_take_strndup(normalized_text, normalized_text_length);
  grn_obj_unlink(&context, string);

  utf8_expected = gcut_data_get_string(data, "expected");
  encoded_expected = convert_encoding(utf8_expected, encoding);
  cut_assert_equal_string(encoded_expected, normalized_text);
  cut_assert_equal_uint(strlen(encoded_expected), normalized_text_length);
  cut_assert_equal_uint(g_utf8_strlen(utf8_expected, -1),
                        normalized_text_n_characters);
}
void
test_no_expand_word_with_space(gconstpointer data)
{
  cut_assert_equal_string(
    "[[[1],"
     "[[\"_id\",\"UInt32\"],"
      "[\"_key\",\"Time\"],"
      "[\"content\",\"Text\"]],"
     "[9,1316358000.0,\"Learning Ruby and groonga...\"]]]",
    send_command(
      cut_take_printf("select Diaries "
                      "--match_columns content --query '\"Ruby and groonga\"' "
                      "--query_expansion Synonyms.%s",
                      gcut_data_get_string(data, "column-name"))));
}
Exemple #20
0
void
test_str_len(gconstpointer data)
{
  size_t result, expected;
  const gchar *input;
  const char *input_end;
  grn_encoding encoding;

  input = gcut_data_get_string(data, "input");
  input_end = strchr(input, '\0');
  encoding = gcut_data_get_int(data, "encoding");
  result = grn_str_len(&context, input, encoding, &input_end);
  expected = gcut_data_get_size(data, "expected");
  cut_assert_equal_size(expected, result);
}
Exemple #21
0
void
test_cgidec(gconstpointer data)
{
  grn_obj buffer;
  const gchar *expected, *input;
  gint input_length;
  gchar end_char;

  expected = gcut_data_get_string(data, "expected");
  input = gcut_data_get_string(data, "input");
  input_length = gcut_data_get_int(data, "input-length");
  end_char = gcut_data_get_char(data, "end-char");

  if (input_length < 0) {
    input_length = strchr(input, '\0') - input;
  }

  GRN_TEXT_INIT(&buffer, 0);
  grn_text_cgidec(&context, &buffer, input, input + input_length, end_char);
  cut_assert_equal_substring(expected,
                             GRN_TEXT_VALUE(&buffer),
                             GRN_TEXT_LEN(&buffer));
  grn_obj_unlink(&context, &buffer);
}
void
test_expand_equal(gconstpointer data)
{
  cut_assert_equal_string(
    "[[[1],"
     "[[\"_id\",\"UInt32\"],"
      "[\"_key\",\"Time\"],"
      "[\"content\",\"Text\"]],"
      "[3,1315839600.0,\"Start rroonga!\"]]]",
    send_command(
      cut_take_printf(
        "select Diaries --sortby _id "
        "--match_columns content --query 'content:=start-rroonga' "
        "--query_expansion Synonyms.%s",
        gcut_data_get_string(data, "column-name"))));
}
void
test_not_expand_paren(gconstpointer data)
{
  cut_assert_equal_string(
    "[[[2],"
     "[[\"_id\",\"UInt32\"],"
      "[\"_key\",\"Time\"],"
      "[\"content\",\"Text\"]],"
      "[4,1315926000.0,\"Start Ruby!\"],"
      "[9,1316358000.0,\"Learning Ruby and groonga...\"]]]",
    send_command(
      cut_take_printf("select Diaries --sortby _id "
                      "--match_columns content --query '(Ruby)' "
                      "--query_expansion Synonyms.%s",
                      gcut_data_get_string(data, "column-name"))));
}
Exemple #24
0
void
test_level_from_string (gconstpointer data)
{
    const gchar *level_string;
    CutLogLevelFlags expected, actual;
    GError *error = NULL;

    expected = gcut_data_get_flags(data, "/expected");
    level_string = gcut_data_get_string(data, "/level-string");
    actual = cut_log_level_flags_from_string(level_string,
                                             CUT_LOG_LEVEL_DEFAULT,
                                             &error);
    gcut_assert_error(error);
    gcut_assert_equal_flags(CUT_TYPE_LOG_LEVEL_FLAGS,
                            expected,
                            actual);
}
void
test_expand_column_value_with_space(gconstpointer data)
{
  cut_assert_equal_string(
    "[[[2],"
     "[[\"_id\",\"UInt32\"],"
      "[\"_key\",\"Time\"],"
      "[\"content\",\"Text\"]],"
     "[2,1315753200.0,\"Start mroonga!\"],"
     "[6,1316098800.0,\"Setup groonga storage engine!\"]]]",
    send_command(
      cut_take_printf("select Diaries --sortby _id "
                      "--match_columns content "
                      "--query 'content:@\"groonga storage engine\"' "
                      "--query_expansion Synonyms.%s",
                      gcut_data_get_string(data, "column-name"))));
}
Exemple #26
0
void
test_itoh(gconstpointer data)
{
  const gchar *expected;
  gchar *actual;
  guint input;
  guint length;

  input = gcut_data_get_uint(data, "input");
  length = gcut_data_get_uint(data, "length");
  expected = gcut_data_get_string(data, "expected");

  actual = g_new0(gchar, length);
  cut_take(actual, g_free);
  grn_itoh(input, actual, length);
  cut_assert_equal_substring(expected, actual, length);
}
Exemple #27
0
void
test_create_with_invalid_name(gpointer data)
{
  grn_obj *table;
  const gchar *table_name;

  table_name = gcut_data_get_string(data, "name");
  table = grn_table_create(context, table_name, strlen(table_name),
                           NULL,
                           GRN_OBJ_TABLE_NO_KEY | GRN_OBJ_PERSISTENT,
                           NULL, NULL);
  grn_test_assert_error(
    GRN_INVALID_ARGUMENT,
    cut_take_printf("[table][create] name can't start with '_' and "
                    "contains only 0-9, A-Z, a-z, #, @, - or _: <%s>",
                    table_name),
    context);
}
Exemple #28
0
void
test_bool(gconstpointer data)
{
    assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
    assert_send_command("column_create Users enabled COLUMN_SCALAR Bool");
    cut_assert_equal_string("2",
                            send_command(gcut_data_get_string(data,
                                         "load-command")));
    cut_assert_equal_string("[[[2],"
                            "["
                            "[\"_id\",\"UInt32\"],"
                            "[\"_key\",\"ShortText\"],"
                            "[\"enabled\",\"Bool\"]"
                            "],"
                            "[1,\"mori\",true],"
                            "[2,\"tapo\",false]"
                            "]]",
                            send_command("select Users"));
}
Exemple #29
0
void
test_text_otoj(gconstpointer data)
{
  grn_obj object, json;
  grn_builtin_type type;
  const gchar *expected, *actual;

  GRN_TEXT_INIT(&json, 0);

  expected = gcut_data_get_string(data, "expected");
  type = gcut_data_get_int(data, "type");
  cut_trace(construct_object(data, type, &object));
  grn_text_otoj(&context, &json, &object, NULL);
  grn_obj_unlink(&context, &object);
  actual = cut_take_printf("%.*s",
                           (int)GRN_TEXT_LEN(&json), GRN_TEXT_VALUE(&json));
  grn_obj_unlink(&context, &json);
  cut_assert_equal_string(expected, actual);
}
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);
}